I need help with Client resource importing, According to the documentation I have created ClientResourceProvider and QbankClientResourceRegister. Kindly check the following.
QbankClientResourceRegister :
[ClientResourceRegistrator]
public class QbankClientResourceRegister : IClientResourceRegistrator
{
public void RegisterResources(IRequiredClientResourceList requiredResources)
{
requiredResources.Require("epi-cms.widgets.base").AtHeader();
requiredResources.Require("qbank.picker").AtFooter();
}
}
ClientResourceProvider :
[ClientResourceProvider]
public class ClientResourceProvider : IClientResourceProvider
{
public IEnumerable<ClientResource> GetClientResources()
{
return new[]
{
new ClientResource
{
Name = "epi-cms.widgets.base",
Path = Paths.ToClientResource("QbankModule", "ClientResources/Scripts/Editors/QBankMediaPicker.js"),
ResourceType = ClientResourceType.Script
},
new ClientResource
{
Name = "qbank.picker",
Path = Paths.ToClientResource("QbankModule", "ClientResources/Scripts/qbank-connector.js"),
ResourceType = ClientResourceType.Script
}
};
}
}
module.config file in the moduel folder :
<?xml version="1.0" encoding="utf-8"?>
<module name="QbankModule" loadFromBin="false" clientResourceRelativePath="" viewEngine="Razor" authorizationPolicy="episerver:cmsadmin"
moduleJsonSerializerType="None" preferredUiJsonSerializerType="Net">
<assemblies>
<add assembly="Qbank.Connector.EpiServerModule5" />
<add assembly="Qbank.Connector.EpiCore11" />
<add assembly="Qbank.Connector.EpiCore" />
<add assembly="Qbank.Connector.Core" />
</assemblies>
<clientResources>
<add name="epi-cms.widgets.base" path="ClientResources/Styles/qbankplugin.css" resourceType="Style"/>
<add name="qbank.picker" path="ClientResources/scripts/editors/QbankMediaPicker.js" resourceType="Script"/>
</clientResources>
<dojo>
<paths>
<add name="qbank" path="ClientResources/scripts" />
</paths>
</dojo>
</module>
I need to load QbankMediaPicker.js when loading the following specific block :
[ContentType(
DisplayName = "Banner",
GUID = "0d1c8743-4d48-470f-8afb-7e62d84f6092",
GroupName = SystemTabNames.Content)]
public class BannerBlock : BlockData
{
[Display(
Name = "Header",
Description = "Enter a header for the block",
GroupName = SystemTabNames.Content,
Order = 1
)]
[Required]
public virtual string Header { get; set; }
[Display(
Name = "Description",
Description = "Enter a Description for the block",
GroupName = SystemTabNames.Content,
Order = 2
)]
[Required]
public virtual XhtmlString Description { get; set; }
[Display(
Name = "QBankSampleImage",
Description = "QBankSampleImage for the block",
GroupName = SystemTabNames.Content,
Order = 3)]
//[Qbank.Connector.EpiCore.DataAnnotations.MediaFormat("#310")]
[UIHint(Qbank.Connector.Core.Web.UIHint.QBankMedia)]
public virtual ContentReference QBankSampleImage { get; set; }
Also got this form a forum:
Requiring resources from a partial view/compontent has stopped working in CMS12. The fix will be released in 12.4.0. See forum thread here: https://world.optimizely.com/forum/developer-forum/cms-12/thread-container/2022/2/require-client-resources-only-when-specific-block-type-is-rendered/
Actually, I upgraded EPiServer.Framework and EPiServer.CMS.Core packages to the latest version (12.4.0). But it seems the EPiServer.CMS package does not have version 12.4.* yet. But still, I can't get the client resources imported when I'm creating my custom block.
Regarding the versions, I noticed that fixes will be released on version 12.4.0, so is it on EPiServer.CMS package? or in EPiServer.Framework / EPiServer.CMS.Core packages?
if it is EPiServer.CMS package, does it means that we need to wait for the next release (12.4.0) with the fix? Or do you know any workaround for this?
Your should have something like the following to tell the CMS which client resources your component requires:
public class MyBlockViewComponent : ViewComponent
{
public MyBlockViewComponent(IRequiredClientResourceList requiredClientResourceList)
{
requiredClientResourceList.RequireScript("/scripts/some-script.js, "someName", new[] { "someDependency" }).AtFooter();
}
// ...
}
Also, you need to make sure Footer and/or Header sections are rendered somewhere, for example in your shared layout view, like #Html.RequiredClientResources("Footer").
Edit: Note that you can use slightly different syntax to load a named resource instead of an explicit path, above was just from some sample code.
Related
So I'm trying to deploy a database on Azure using EF code first. I have one model:
public class User
{
[Key]
public int PersonID { get; set; }
[Required(ErrorMessage = "A first name is required.")]
[StringLength(20, MinimumLength = 2, ErrorMessage = "Your firstname needs to be atleast 2 letters long")]
[RegularExpression(#"^[a-zA-Z]*$", ErrorMessage = "Your firstname can only contain letters")]
[Display(Name = "First Name:")]
public string FirstName { get; set; }
}
DataContext-class:
public class DataContext : DbContext
{
public DataContext() : base("DataContext")
{
}
public DbSet<User> User { get; set; }
}
DataContextInitalizer-class:
public class DataContextInitializer : DropCreateDatabaseIfModelChanges<DataContext>
{
}
In the global.asax-file to initalize the datacontext:
Database.SetInitializer(new DataContextInitializer());
And then finally the string to connect to the database in the web.config:
<connectionStrings>
<add name="DataContext" connectionString="Data Source=tcp:*.database.windows.net,1433;Initial Catalog=TestApi20180311012458_db;User ID=usernamehere;Password=passwordhere" providerName="System.Data.SqlClient" />
Thou no tables are created when building the solution. I dont know where I'm missing out. Can you see whats wrong?
Thou no tables are created when building the solution. I dont know where I'm missing out. Can you see whats wrong?
Your code just to connect Azure sql in your local project. And the data initialization just uses to initialize data in table. But your tables have not created yet. If you want to create table in Azure sql, you could use Migrations.
Azure sql connection string in web.config:
<connectionStrings>
<add name="ConnectionStringName" providerName="System.Data.SqlClient" connectionString="Data Source=tcp:[databasename].database.windows.net,1433;Initial Catalog=[databasename];Integrated Security=False;User Id=[username];Password=[password];Encrypt=True;TrustServerCertificate=False;MultipleActiveResultSets=True" />
</connectionStrings>
Open Tools> Nuget Mackage Manager>Package Manager Console. Then enter the following code:
Enable-migrations
Add-migration initial
update-database
After that, you could see the tables are created in Azure Sql.
For another way, you could use publish tool to connect to Azure sql and use Code First Migrations automatically. Do not need to use code to configure manually. Open Publish settings to configure Azure sql. Or you could read this article to learn more details.
I am creating a portable MockGeoLocationWatcher that one can substitute in place of the concrete implementations of IMvxGeoLocationWatcher until one has an actual device. This should facilitate development and testing of applications that require geo location.
The PluginLoader class for this plugin currently looks like this:
namespace Pidac.MvvmCross.Plugins.Location
{
public class PluginLoader : IMvxConfigurablePluginLoader
{
private bool _loaded;
public static readonly PluginLoader Instance = new PluginLoader();
public void EnsureLoaded()
{
if (_loaded)
return;
_loaded = true;
var locationWatcher = new MockGeoLocationWatcher();
var data = #"<?xml version='1.0' encoding='utf-8'?>
<WindowsPhoneEmulator xmlns='http://schemas.microsoft.com/WindowsPhoneEmulator/2009/08/SensorData'>
<SensorData>
<Header version='1' />
<GpsData latitude='48.619934106826' longitude='-84.5247359841114' />
<GpsData latitude='48.6852544862377' longitude='-83.9864059059864' />
<GpsData latitude='48.8445703681025' longitude='-83.7337203591114' />
<GpsData latitude='48.8662561090809' longitude='-83.2393355934864' />
<GpsData latitude='49.0825970371386' longitude='-83.0415816872364' />
<GpsData latitude='49.2621642999055' longitude='-82.7229781716114' />
<GpsData latitude='49.2621642999055' longitude='-82.6021285622364' />
<GpsData latitude='49.2047736379815' longitude='-82.3054977028614' />
</SensorData>
</WindowsPhoneEmulator>";
locationWatcher.SensorLocationData = data;
Mvx.RegisterSingleton(typeof(IMvxGeoLocationWatcher), locationWatcher);
}
public void Configure(IMvxPluginConfiguration configuration)
{
}
}
public class MockLocationWatcherConfiguration : IMvxPluginConfiguration
{
public static readonly MockLocationWatcherConfiguration Default = new MockLocationWatcherConfiguration();
// ideally, we should use this property to point to a file or string containing location data
// this should be configurable outside of code base.
public string SensorLocationData { get; set; }
}
}
I will like to pass the sensor data, currently hardcoded into the variable called "data" through an instance of MockLocationWatcherConfiguration but do not know where the MvvmCross framework is expecting to load the configuration for this plugin before IMvxConfigurablePluginLoader.Configure(configuration) is invoked. Ideally, I should specify this through configuration.
I looked at the Json plugin's implementation of PluginLoaded but still could not figure out where the configuration was retrieved before a cast was attempted in IMvxConfigurablePluginLoader.Configure.
Any ideas or pointers will be greatly appreciated.
TIA.
This is covered in the draft wiki page https://github.com/slodge/MvvmCross/wiki/MvvmCross-plugins - see "writing a configurable plugin"
I have created a database using EF code-first like there http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-code-first-walkthrough.aspx. But when I input data to db by add() and then call savechanges() I don't see new database in SQL Server databases folder and there no exceptions. Is it right? Where can I find my database and how to put it in databases folder?
I work with this code:
public class Name
{
public long NameId { get; set; }
public string FullName { get; set; }
}
public class InfoContext : DbContext
{
public DbSet<Name> Names { get; set; }
}
Then I call it:
var db = new InfoContext();
var Names = new Name
{
NameId = 1,
FullName = "test"
};
db.Names.Add(Name);
db.SaveChanges();
var test = db.Names.Find(1);//there I get correct value
I have connectionString in web.config like this:
<connectionStrings>
<add name="InfoName" providerName="System.Data.SqlClient"
connectionString="Server = .\MYINSTANCE; Initial Catalog=mydbname;" />
</connectionStrings>
Based on your comments you need to modify the web.config file in your project root (not the one in your Views folder. In there you can add a section as follows:
<connectionStrings>
<add name="EFDbContext" connectionString="Data Source = .; Initial Catalog = ITSDB; Integrated Security = true" providerName="System.Data.SqlClient"/>
</connectionStrings>
The name property of the element is the DbContext name of your Data model, so if your class is defined as:
public class SomeContext : DbContext
{
...
}
Then your config should be:
<connectionStrings>
<add name="SomeContext" connectionString="Data Source = .; Initial Catalog = ITSDB; Integrated Security = true" providerName="System.Data.SqlClient"/>
</connectionStrings>
As for the connection string, its dependent on your database.
Check the defaultConnectionFactory type in your config. I expect it is set to LocalConnectionFactory, as this seems to be default.
Change it to the following and your SQL instance will be used.
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=.; Integrated Security=True; MultipleActiveResultSets=True;" />
</parameters>
</defaultConnectionFactory>
Your DB should appear in SQL Management Studio (SQLMS) with a name that matches the namespace and DbContext.
Or you can just put in "Data Source = " value your server's name which selected in you SQL Management Studio.
<connectionStrings>
<add name="SomeContext" connectionString="Data Source = **Server'sName**; Initial Catalog = ITSDB; Integrated Security = true" providerName="System.Data.SqlClient"/>
I've been trying to write a simple little Cmdlet to allow me to Set/Get/Remove cache items. The problem I have is that I cannot figure out how to connect to the local cache cluster.
I've tried adding in the usual app.config stuff, but that doesn't seem to get picked up ...
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection, Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" allowLocation="true" allowDefinition="Everywhere" />
</configSections>
<dataCacheClient>
<hosts>
<host name="localhost" cachePort="22233" />
</hosts>
</dataCacheClient>
</configuration>
I'd rather not have that config at all. So what I am really asking is what the equivalent C# code is for the following powershell...
Use-CacheCluster
From what I can gather Use-CacheCluster connect to the local cluster if no parameters are supplied
I've just done some spelunking into the AppFabric Powershell code with Reflector to see how it works under the covers. If you call Use-CacheCluster with no parameters e.g. for the local cluster, the code reads the connection string and provider name from the Registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\AppFabric\V1.0\Configuration. Unfortunately, it then uses those values to build a series of classes (ClusterConfigElement, CacheAdmin and ClusterHandler) which are all marked as internal, so you can't use them to pick up the current cluster context (for want of a better word) that Powershell is working with.
To make your Cmdlet work, then, I think you need to pass in a hostname (which would be one of the servers in your cluster, and perhaps you could default this to the local machine name) and a port number (which you could default to 22233), and use those values to build a DataCacheServerEndpoint to pass to your DataCacheFactory e.g.
[Cmdlet(VerbsCommon.Set,"Value")]
public class SetValueCommand : Cmdlet
{
[Parameter]
public string Hostname { get; set; }
[Parameter]
public int PortNumber { get; set; }
[Parameter(Mandatory = true)]
public string CacheName { get; set; }
protected override void ProcessRecord()
{
base.ProcessRecord();
// Read the incoming parameters and default to the local machine and port 22233
string host = string.IsNullOrWhiteSpace(Hostname) ? Environment.MachineName : Hostname;
int port = PortNumber == 0 ? 22233 : PortNumber;
// Create an endpoint based on the parameters
DataCacheServerEndpoint endpoint = new DataCacheServerEndpoint(host, port);
// Create a config using the endpoint
DataCacheFactoryConfiguration config = new DataCacheFactoryConfiguration();
config.Servers = new List<DataCacheServerEndpoint> { endpoint };
// Create a factory using the config
DataCacheFactory factory = new DataCacheFactory(config);
// Get a reference to the cache so we can now start doing useful work...
DataCache cache = factory.GetCache(CacheName);
...
}
}
The problem is that the call:
DataCacheFactoryConfiguration config = new DataCacheFactoryConfiguration();
inside Cmdlet mothods produces an error sounding like "Cannot initialize DataCacheFactoryConfiguration".
I have been trying to use the configurable provider model for handling my MEF imports and exports from MEF Contrib (link). I've read the Codeplex documentation and Code Junkie's blog post (link); however, I can't seem to get the container to create the parts. Where am I going wrong?
Program.cs
namespace MEFTest
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.Run();
}
// [ImportMany("command", typeof(IHelp))]
public IEnumerable<IHelp> Commands { get; set; }
void Run()
{
Compose();
foreach(IHelp cmd in Commands)
{
Console.WriteLine(cmd.HelpText);
}
Console.ReadKey();
}
void Compose()
{
var provider = new ConfigurableDefinitionProvider("mef.configuration");
var catalog = new DefinitionProviderPartCatalog<ConfigurableDefinitionProvider>(provider);
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
}
}
TestCommand.cs
namespace MEFTest
{
//[Export("command", typeof(IHelp))]
public class TestCommand : IHelp
{
private string _helpText = "This is a test.";
public string CommandName
{
get { return "Test"; }
}
public string HelpText
{
get { return _helpText; }
}
}
}
App.Config section:
<mef.configuration>
<parts>
<part type="MEFTest.TestCommand, MEFTest">
<exports>
<export contract="IHelp" />
</exports>
</part>
<part type="MEFTest.Program, MEFTest">
<imports>
<import member="Commands" contract="IHelp" />
</imports>
</part>
</parts>
</mef.configuration>
I don't get any build errors and it runs fine if I switch to the typical attribute-based system that is part of the MEF core (with the appropriate catalog too). Program.Commands is always NULL in the above example. I tried to just use a singular property instead of a collection and get the same results.
When I debug I can get the provider.Parts collection so I know it's accessing the configuration information correctly; however, I get an InvalidOperationException whenever I debug and try to drill into catalog.Parts.
Anyone have any experience as to where I'm going wrong here?
As documented here, you also need this in your config file:
<configSections>
<section
name="mef.configuration"
type="MefContrib.Models.Provider.Definitions.Configurable.PartCatalogConfigurationSection, MefContrib.Models.Provider" />
</configSections>
If you already have that, then it might be interesting to show us the stack trace of the InvalidOperationException that you get when accessing provider.Parts.
I had the same problems and could not get it to work, but here are some details:
It seems that ComposeParts() does not work as expected (at least in the version I used) because it uses static methods, based on Reflection to find all required Imports (so it seems that this part cannot be changed from outside of MEF). Unfortunately we want to use xml configuration and not the MEF attributes.
It works if you add [Import] attributes to the members of the class you you use with ComposeParts(). In your case this would be "Programm". In this case all exports defined in the configuration file will be found.
I could not find any documentation or examples on the MEF Contrib page relating to that problem. Also there is no unittest in the MEF contrib projekt that uses ComposeParts().
A workaround would be to use container.GetExportedValues() to retrieve the values, but in this case you have to set the classes members manually.
Hope that helps.