Umbraco 7.2.8 site. We have managed to create a CI process, which includes migration of added fields, properties types etc.
We have not done Languages and I'm wondering if its possible.
So what I would like to know is if there is a way in code to add a new language to the Languages tab within Settings from code?
Thanks
I haven't used or tested this myself but according to the source code it should be possible through the LocalizationService
var languageSE = new Language("sv-SE") { CultureName = "sv-SE" };
Services.LocalizationService.Save(languageSE);
Related
I have a custom .NET application to query and managing data on a Microsoft Dynamics CRM instance.
This application is multilingual and the user can change via a language switch the language of the application.
For the connection and actions I'm using the OrganizationService and CRMServiceClient from Microsoft.Xrm.Sdk. This is combined with dependency injection to pass the connection to our different classes.
With Ninject this bindings look like
Bind().To().WithConstructArgument("crmConnectionString","the connection string");
Querying and updating the data in Dynamics is working but we are not able to retrieve the OptionSet values and Formatted values in the language the visitor have selected in the custom app. This is always in the same language even when we change the culture for the Thread before we call Dynamics.
How can we pass the current language / culture to the OrganizationService so that it knows in what language it have to retrieve the fields?
Someone told me that this is based on the account used to connect to the CRM. So if that's indeed the case then it means that if we have 5 languages that we need to have 5 connection strings and 5 OrgnaizationService instances that need to be called. How should I handle this in a good way in that case?
Thanks for your answers
The solution I implemented was to use CallerId.
Before returning the client I fill the CallerId with a Guid.
The Guid is from a user configured with a specific language in Dynamics.
Based on the language I take a different user.
I don't know if you can pass a culture to the OrganizationService, and I think having different connection strings would work if you want to go this route.
However, you can query the CRM to retrieve the localized labels for the option set you want, as described here.
To sum it up, it's using a RetrieveAttributeRequest, passing the entity logical name and field name and looping trough the result to get the labels.
var request = new RetrieveAttributeRequest
{
EntityLogicalName = "incident",
LogicalName = "casetypecode"
};
var response = organizationService.Execute(request) as RetrieveAttributeResponse;
var optionSetAttributeMetadata = response.AttributeMetadata as EnumAttributeMetadata;
foreach (var option in optionSetAttributeMetadata.OptionSet.Options)
{
Console.WriteLine($"Localized labels for option {option.Value}:");
foreach (var locLabel in option.Label.LocalizedLabels)
{
Console.WriteLine($"Language {locLabel.LanguageCode}: {locLabel.Label}");
}
Console.WriteLine($"Localized description for option {option.Value}:");
foreach (var locLabel in option.Description.LocalizedLabels)
{
Console.WriteLine($"Language {locLabel.LanguageCode}: {locLabel.Label}");
}
}
The code in the link also add caching of already retrieved values, so that you only query the CRM once per option set.
In Umbraco 7, i am trying to get the Id of a Image on the page. I am using;
#Umbraco.Field("myImage")
But, it does not return the mediaId. Instead it returns;
Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedMediaCache+DictionaryPublishedContent
What am i doing wrong?
There are basically 3 ways:
#CurrentPage.myImage
#Model.Content.GetPropertyValue<int>("myImage")
Using ModelsBuilders you can access it as #Model.myImage
The first method should be avoided because Umbraco will be dropping support for Dynamics (see https://our.umbraco.org/Documentation/Reference/Common-Pitfalls/#dynamics).
ModelsBuilder is my preferred way for accessing published content properties as it provides a strongly typed model based on your Document Type. But it requires some setup. See https://24days.in/umbraco-cms/2016/getting-started-with-modelsbuilder/ for a great intro.
The final option is accessing the properties from #Model.Content (IPublishedContent and unlike the Dyanamics method, will continue to be supported in the next version of Umbraco.
In Umbraco 7 you can use #CurrentPage. You just need to use:
#CurrentPage.myImage
instead of #Umbraco.Field("myImage") and it will return mediaId
I have just upgraded to version 7.6.12 and there are some updates with the media picker. To use it as you done you should select the obsolete mediapicker in the backoffice otherwise Model.Content.GetPropertyValue<IPublishedContent>("myImage").Url should work. If you using the UmbracoHelper, you could write UmbracoHelper.AssignedContentItem.GetPropertyValue<IPublishedContent>(propertyName, recursive).Url
https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/
All,
I have read up on the way SS uses Func to wire registrations. My current issue is that I am still not seeing how to call a specific instance from runtime.
What I would like to do is set up two different repository classes representing two different database systems, say SQLDB and MongoDB, both of which inherit from IDB, then be able to determine which database to use based on an app setting in the config file.
What I have right now in my Configure method is just
container.Register("SQLDB", new TestSQLDB("connectionName"));
container.Register("MongoDB", new TestMongoDB("mongoURL"));
If anyone can help me fill in the blanks I'd appreciate it. I already managed this with Ninject, but I would prefer not to have to add it if I don't need to.
Thanks,
Bs
Register via concrete type (or interface if you prefer):
container.Register<SQLDB>(new TestSQLDB("connectionName"));
container.Register<MongoDB>(new TestMongoDB("mongoURL"));
When you want one back:
var mySqlDB = container.Resolve<SQLDB>();
var myMongoDB = container.Resolve<MongoDB>();
Thanks for your help Gavin. You got me on the right track. Here is what worked.
1) In the config:
container.Register<ITest>("SQLDB", new TestSQLDB("xxxx"));
container.Register<ITest>("MongoDB", new TestMongoDB("mongo://127.0.0.1"));
2) In the service:
IAppHost appHost = base.GetAppHost();
var repository = appHost.GetContainer().ResolveNamed<ITest>("MongoDB");
List<Test> testlist = repository.LoadAll();
This way I can just replace "MongoDB" with something from the config file and I don't need to recompile to change data sources.
I'm working on mvc.net and I want to create view pages at run time. Is it possible? If yes then how can I do it?
We actually store NVelocity snippets in a database that we pull together at runtime and marry with ViewData objects to get an output HTML string that we just return via Content() instead of View().
It boils down to something like this (pseudo-code, not actual code):
var _viewDataObject = Products.All();
var _view = PageTemplate.Single(template=>template.Slug == PageTemplateEnums.HomePage);
var _outputHtml = nvelocityMemoryEngine.Transform(_view,_viewDataObject);
return Content(_outputHtml);
While we do some caching for performance reasons, this means you can change views without ever touching Visual Studio or deploying anything at the filesystem level.
It didn't take too much to add things like MimeType handling etc. and we can have people outside of the development team editing the views.
I am building an Internal social networking website on SharePoint. Since its a networking intranet, I want it to be Open and non moderated. However, I also dont want people to use abusive / Foul or bad language words in the portal.
I tried Googling and wasnt really sucessfull in finding a solution.
Microsoft Forefront will do that for me, but it only does for Documents. But I also want to do that on Lists since Discussion forum on the SharePoint is in a list format.
You may create site solution/list definition for your site using Visual studio Sharepoint Site Solution Genarator. Create a custom list and name it as you wish. I would name it "AbusiveWordList" in the following code example.
After creating site solution/list definition, Add below code in Item Adding function, which will iterate through all column in the list and will check from the custom list that is created named "AbusiveWordList". This list contains abusive words.
The chkbody function which will reference list item from custom list named "AbusiveWordList" and check if the bodytext contains item from AbusiveWordList.If yes, then it will throw an error.
*base.ItemAdding(properties);
foreach (DictionaryEntry
dictionaryEntry in
properties.AfterProperties) { string
bodytext = "";
bodytext = bodytext +
dictionaryEntry.Value;
finalwordcount = finalwordcount +
chkbody(bodytext, properties); }
if (finalwordcount > 0) {
properties.ErrorMessage = "Abusive /
Foul / Illicit information
found.Kindly refer to the terms and
conditions.";
properties.Cancel = true;
}
You will probably need to override any controls that display text to avoid this issue. As this would be a lot of work, perhaps an HTTP Module would be a better solution.
I've worked on a module that used regular expressions to make SharePoint's output XHTML compliant. Similarly, you could use regular expressions to strip out offensive words when a page is rendered. It wouldn't stop people typing them but as no-one would be able to see them this wouldn't matter. You could use a basic SharePoint custom list to store the offensive words you don't want displayed.