I need to do localization in WinRT. I have a resource file named resource.resw and I have given name, value and comment. I tried using the resource loader to call the localization, but it didn't work. What is the proper syntax?
var loader = new Windows.ApplicationModel.Resources.ResourceLoader();
var str = loader.GetString("farewell");
Looks like you are missing GetForCurrentView() on your first line.
var loader = new Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
var text = loader.GetString("Farewell");
Related
I have a use case in an application I'm writing where I have logic in an external DLL that is loaded dynamically. Now I need to add the ability to display shared views inside the ASP.NET MVC view that resides in the external DLL.
What I've done so far is to add the following in my ConfigureServices method:
UriBuilder uri = new UriBuilder(Assembly.GetEntryAssembly().CodeBase);
string fullPath = Uri.UnescapeDataString(uri.Path);
var mainDirectory = Path.GetDirectoryName(fullPath);
var assemblyFilePath = Path.Combine(mainDirectory, "MyLogic.dll");
var asmStream = File.OpenRead(assemblyFilePath);
var assembly = AssemblyLoadContext.Default.LoadFromStream(asmStream);
var part = new AssemblyPart(assembly);
services.AddControllersWithViews().ConfigureApplicationPartManager(apm => apm.ApplicationParts.Add(part));
This works fine as long as the DLL is added as a reference to the project. If I remove the reference then I'm getting an error in my application when I try to load the partial view:
InvalidOperationException: The partial view 'MyView' was not found. The following locations were searched: /Views/Consent/MyView.cshtml /Views/Shared/MyView.cshtml
What I tried doing is to list all known view of the application using the following code:
var feature = new ViewsFeature();
applicationPartManager.PopulateFeature(feature);
var views = feature.ViewDescriptors.Select(x => x.RelativePath).ToList();
What I see is that when I add the DLL as a reference in the project I see MyView.cshtml in the list, and if not then I don't see it - and the above error makes sense.
But my use case dictates that the loaded DLL is not referenced. Is there a way to add the views from it when it's not a reference?
Mystery solved... instead of ConfigureApplicationPartManager need to use AddApplicationPart like this:
UriBuilder uri = new UriBuilder(Assembly.GetEntryAssembly().CodeBase);
string fullPath = Uri.UnescapeDataString(uri.Path);
var mainDirectory = Path.GetDirectoryName(fullPath);
var assemblyFilePath = Path.Combine(mainDirectory, "Risco.Auth.Demo.Bridge.dll");
var asmStream = File.OpenRead(assemblyFilePath);
var assembly = AssemblyLoadContext.Default.LoadFromStream(asmStream);
services.AddControllersWithViews().AddApplicationPart(assembly);
I'm trying to link a c# application to a sharepoint directory, so I can create folders, download and upload files. However I am strugling with connecting to the correct folder.
I can retrieve the content from allitems.aspx, but I am not sure how to actually get the content from folder.
I have tried using the ClientContext - something like this:
ClientContext cxt = new ClientContext("https://xx.sharepoint.com/sites/");
cxt.Credentials = GetCredentials();
List list = cxt.Web.Lists.GetByTitle("Kontrakter");
var test = list.Views;
var test1 = cxt.Web.Lists;
cxt.Load(test1);
cxt.Load(list);
cxt.Load(test);
var a = 4;
var fullUri = new Uri("https://xx.sharepoint.com/sites/yy/Kontrakter/AllItems.aspx");
//var folder = cxt.Web.GetFolderByServerRelativeUrl(fullUri.AbsolutePath);
using (var rootCtx = new ClientContext(fullUri.GetLeftPart(UriPartial.Authority)))
{
rootCtx.Credentials = GetCredentials();
Uri webUri = Web.WebUrlFromPageUrlDirect(rootCtx, fullUri);
using (var ctx1 = new ClientContext(webUri))
{
ctx1.Credentials = GetCredentials();
var list1 = ctx1.Web.GetList(fullUri.AbsolutePath);
ctx1.Load(list1.RootFolder.Files);
ctx1.ExecuteQuery();
Console.WriteLine(list.RootFolder.Files.Count);
}
}
or via normal api calls like this:
https://xx.sharepoint.com/_api/Web/GetFolderByServerRelativeUrl('Kontrakter/Forms')/Files
The only way I can find some data is if I look into 'Shared documents/Forms'
I'm having problems understanding the directory structure and how I can actually find the content of files/folders.
Thanks in advance :)
Turned out I was missing a /sites in one of my uris.
When loading Resources through reflection, how can I be sure I am using the correct Resource Name when I call DLLAssembly.GetManifestResourceNames()
The result of that call is a String[] containing 2 elements.
SDKSetupTool.MainForm.resources
SDKSetupTool.Properties.Resources.resources
If I make the same call to a VB Assembly, it returns 2 elements as well.
SDKSetupTool.MainForm.resources
SDKSetupTool.Resources.resources
The Last element has always been the correct Location containing the Resources from my tests. However, why must I have to parse out ".resources" in order for the ResourceManager to be able to load the Resources
//Load the DLL Assembly from the path that was passed in
var DLLAssembly = Assembly.LoadFrom(SelectedToolPath);
//Load the resource String so that we can bootstrap our Plugin
String RawResourceLocation = DLLAssembly.GetManifestResourceNames()[1];
String ResourceLocation = RawResourceLocation.Substring(0, RawResourceLocation.LastIndexOf('.'));
//Load the resources into a Resource Manager
System.Resources.ResourceManager rman = new System.Resources.ResourceManager(ResourceLocation, DLLAssembly);
//Plugin Name
String PluginName = rman.GetString("PluginName");
//Plugin Description
String PluginDesc = rman.GetString("PluginDescription");
//Plugin Language (Currently only C# and VB.NET Supported)
tring PluginLang = rman.GetString("PluginLanguage");
//Plugin's Entry Point (Because it is a DLL there is no Predefined Entry point. This is an alternative to that)
String PluginEntryPoint = rman.GetString("PluginEntryPoint");
//Discover our entry-point
var EntryPoint = DLLExtension.GetType(PluginEntryPoint);
//Grab the main method of the application
var MainMethod = EntryPoint.GetMethod("Main", new Type[] { });
MainMethod.Invoke(null, null);
If I can consistently be able to load the Resources of an Assembly I will be able to load the plugin based on the String contained in the resources.
I am trying to do highlighting on the search results. Here is the relevant part of my code.
QueryScorer scorer = new QueryScorer(q);
Lucene.Net.Search.Highlight.IFormatter formatter = new SimpleHTMLFormatter("<b>", "</b>");
Lucene.Net.Search.Highlight.Highlighter highlighter = new Highlighter(formatter, scorer);
highlighter.TextFragmenter = new SimpleFragmenter(800);
Lucene.Net.Util.Version vers = new Lucene.Net.Util.Version();
vers = Lucene.Net.Util.Version.LUCENE_30;
TokenStream stream = new StandardAnalyzer(vers).TokenStream(string.Empty, new StringReader(text));
string s = string.Empty;
try
{
s = highlighter.GetBestFragments(stream, text, 10, "...");
}
Here, GetBestFragments method throws a System.MissingMethodException.
I have tried to replace the original Lucene.net dll with Lucene.Net.Contrib but this time, I dont know what I should write instead of TokenStream. It doesnt exist in Lucene.Net.Contrib.* dlls.
I am working on existing code and I need to find out how I can rewrite TokenStream class and GetBestFragments method.
Thanx
The problem was something about deployment, that the new compatible Lucene.dll was replaced by the incompatible Sitecore7 dll.
So, if both lucene.net and lucene.net.contrib dll are referenced, it should work.
Not directly the solution to my question, but this source is worth mentioning again. (About lucene.dll versions) : http://laubplusco.net/sitecore-7-lucen-3-0-highlighted-results/
I already figured out how to load another assembly from my C# application, and extract the resources embedded to that assembly. My problem is that I'd like to filter the resources by type, i.e. I want to get only text resources, but not icons and other stuff.
The code I use at the moment looks like this:
string[] list = target.GetManifestResourceNames();
foreach (var listentry in list)
{
Stream resourceStream = target.GetManifestResourceStream(listentry);
var rr = new ResourceReader(resourceStream);
IDictionaryEnumerator dict = rr.GetEnumerator();
int ctr = 0;
while (dict.MoveNext())
{
ctr++;
string entry = dict.Value; //I'd like to know what kind of resource this is, how can I do that?
}
rr.Close();
}
How can I determine which kind of resource entry I currently get, i.e. if it's an icon, a text resource, or something else?
Thanks a lot.