How to read in other class from isolated storage? - windows-phone-7

How can I read a setting in MainPage.xaml/.cs ?
I use this setting sample but I dont have accces to/from other class.
For example: In MainPage.xaml we have TextBlock, in SettingsWithoutConfirmation.xaml we have TextBox, How TextBlock can read this string from TextBox (and also save this to isolated storage) ?
I am newbie, please be gentle ;)

I'm not sure I completely understood your question.
In any xaml page, you can use the following to access settings that have been stored in isolated storage:
var settings = IsolatedStorageSettings.ApplicationSettings;
if( settings.Contains("name") ) {
//the value is available here
}
//to store a value permanently
settings["name"] = "New Name"

Try this:
Save data to settings:
var settings = IsolatedStorageSettings.ApplicationSettings;
settings.Add("myemail", "support#gmail.com");
Get data from settings:
var location = settings["myemail"].ToString();
settings["myemail"] = "support#gmail.com";

Related

Blazor localization do not load resource translations

I have a .NET 6 Bloazor PWA application where i want to let the customer choose the language for the UI of the app.
I have prepared resource .resx files and set the Default language in Program.cs and set the AddLocalization service, but when i chose the language from the combo element the localized text on the page do not change at all.
Moreover i always see the 'keys' instead their corresponding strings in resurces file; it looks like the system do to find resource files at all.
where am i wrong ?
I used:
(.csproj file)
<PropertyGroup>
<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
</PropertyGroup>
(Program.cs):
builder.Services.AddLocalization(Options => Options.ResourcesPath= "ResourceFiles");
var host = builder.Build(); CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("it-IT");
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("it-IT");
await host.RunAsync();
then i defined the ResourceFiles directory
with inside Resource.resx , Resources.it.resx with two text records with
(Resources.it.resx and Resources.resx)
Name="intro1" value="Benvenuto!"
Name="intro2" value="Grazie per utilizzare la nostra app" `
(Resources.en.resx)
Name="intro1" value="Welcome!"
Name="intro2" value="Thank you for using our app" `
and in addition an empty Resources class to collect resx files and assign later it to IStringLocalizer in the razor page
namespace BlazorAppPWAalone.ResourceFiles
{
public class Resources
{
}
}
in my page:
#using System.Globalization
#using Microsoft.Extensions.Localization
#inject IStringLocalizer<Resources> Loc
<h1>Language change:</h1>
<select name="lingue" id="idlingua" #bind="sceltaLingua">
<option value="it-IT">Italiano</option>
<option value="en-US">Inglese</option>
</select>
<p>
<b>CurrentCulture</b>: #CultureInfo.CurrentCulture
<b>CurrentUICulture</b>: #CultureInfo.CurrentUICulture
</p>
<p>#Loc["intro1"], #Loc["intro2"]</p>
#code {
private string _sceltaLingua;
public string sceltaLingua
{
get
{
return _sceltaLingua;
}
set
{
_sceltaLingua = value;
CambiaLingua(_sceltaLingua);
}
}
private void CambiaLingua(string newlang)
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(newlang);
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(newlang);
StateHasChanged();
}
}
When i choose the language the #CurrentCulture and #CurrentUICulture variables show correctly the selected language but #Loc["intro1"], #Loc["intro2"] never change, it always displays default (italian) resource values.
Why ? where is my code 'bug' ?
I´ve not done this in WASM yet but in the documentation the CultureSelector does not actually set CurrentCulture to change the language but sets a key value pair in the browsers local storage and triggers a reload which causes DefaultThreadCurrentCulture and
DefaultThreadCurrentUICulture to be set to the culture specified in local storage.
And judging from this:
Always set DefaultThreadCurrentCulture and DefaultThreadCurrentUICulture to the same culture in order to use IStringLocalizer and IStringLocalizer.
just setting CurrentCulture and CurrentUICulture will probably not work.
I don´t know if you can just set DefaultThreadCurrentCulture and DefaultThreadCurrentUICulture from the component and reload or if you need to follow the documentations exact approach but that should be easy for you to try out.

Define download path dotnetbrowser

I use dotnetbrowser to display a web browser on a old windows framework.
have you an idea to define the download path ?
My dotnetbroser is enable, i can show my webpage but i don't found in documentation or exemple how define this simple download path.
The only exemple that i've found is about the download event detection.
I use WPF in C#
Thanks.
The DotNetBrowser.DownloadItem.DestinationFile property is writable and can be used to configure the path to store the file.
To set this property in your application, you need to subclass the DotNetBrowser.DefaultDownloadHandler and implement its AllowDownload(DownloadItem) method. Then you need to configure your download handler as shown in the documentation article: File Download
You can also configure and use DotNetBrowser.WPF.WPFDefaultDownloadHandler instance to show file chooser and select the path to store the file.
This is a solution
Défine your browser like variable :
BrowserView myBrowserView;
Browser myBrowser;
Create the browser properly :
this.myBrowser = BrowserFactory.Create();
this.myBrowserView = new WPFBrowserView(this.myBrowser);
Create event detection for download
this.myDowloadHandler = new SampleDownloadHandler();
this.myBrowser.DownloadHandler = myDowloadHandler;
Add it to a container, here, a grid
grid_navigateur.Children.Add((UIElement)myBrowserView.GetComponent());
Now we are going to use our "SampleDownloadHandler" class
class SampleDownloadHandler : DownloadHandler
{
public bool AllowDownload(DownloadItem download)
{
download.DestinationFile = "exemple\of\path\whith\file\name";
download.DownloadEvent += delegate(object sender, DownloadEventArgs e)
{
DownloadItem downloadItem = e.Item;
if (downloadItem.Completed)
{
System.Windows.MessageBox.Show("Download complete");
}
};
return true;
}
My personalisated class define path and name of the file who is download and pop a message when is over.
(to found the file name, you do to cut the string download.DestinationFile after the last )

How to read web.config appsetting key value in Type Script of Service Class

I am developing angular 2 application using visual studio 2015, In my current project I want to get the app setting value from web.config in typescript file(service.ts)
Before posting this question into this, I did google it and read some links but I did not get it. This is the link I read earlier but I did not get a result: https://forums.asp.net/t/2071477.aspx?How+to+read+web+config+appsetting+key+value+in+Type+Script
Please tell me how to solve this problem.
As any xml file you can do something like :
let url : string = path_to_your_file;
let observableResult: Observable<any>
= this.http.get(url)
.map(res => res.text())
.subscribe((xml : any) => {
let parser = new DOMParser();
let webConfig= parser.parseFromString(xml, 'text/xml');
let nodes = webConfig.getElementsByTagName('add');
for (let i = 0; i < nodes.length; i++) {
parse_property(nodes.item(i));
}, ...)
}
You cannot access a web.config file directly from TypeScript. You have to write it into your html document first with some type of ServerSide code. You can store the setting either in a hidden html text field or inside a javascript variable. Then you can read that text field or javascript variable in Typescript.
This has been answered before here: Reading web.config from JavaScript

Dnn 8: caching module settings

I put some module settings via
var moduleController = new ModuleController();
moduleController.UpdateModuleSetting(moduleId, "key", value);
Later if I try to access the setting using
var rcModule = ModuleController.Instance.GetModuleByDefinition(PortalSettings.PortalId, "MyModule");
var value = rcModule.ModuleSettings["value"]?.ToString() ?? string.Empty;
the same value is returned (even if I resave the setting) until I clear the app cache. The value is correct after every saving settings in the database but not in the module. I also tried to add ModuleController.SynchronizeModule(moduleId); to my save settings method but it didn't help. Module and page cache both disabled.
What's wrong?
You are creating a new instance of moduleController, not getting the existing one from memory.
You can clear the cache programmatically.
DotNetNuke.Common.Utilities.DataCache.ClearModuleCache(TabId);
DotNetNuke.Common.Utilities.DataCache.ClearTabsCache(PortalId);
DotNetNuke.Common.Utilities.DataCache.ClearPortalCache(PortalId, false);
Or get the correct instance and edit the properties.
ModuleInfo moduleInfo = ModuleController.Instance.GetModule(ModuleId, TabId, false);
moduleInfo.ModuleTitle = "New Title";
ModuleController.Instance.UpdateModule(moduleInfo);

DataBound controls loading images and avoiding image cache in WP7

I want to load images into a Pivot header to substitute the lack of a Gallery control in WP7. I'm trying to populate them from a URL, and want to make sure that the image is not kept in the cache (by setting UriSource = null) to make sure that they don't take too much resources.
There's no way to do this in the XAML itself, can someone give me sample code to handle this from code-behind. my attempts have been unsuccessful. what am I doing wrong here?
public class PhotoGalleryVM
{
public ObservableCollection<BitmapImage> Images
{
get
{
ObservableCollection<BitmapImage> list = new ObservableCollection<BitmapImage>();
foreach (RoomImage r in App.appData.currentChoices.roomImages)
{
BitmapImage img = new BitmapImage(new Uri(Uri.UnescapeDataString(r.largeUri)));
img.UriSource = null;
list.Add(img);
}
return list;
}
}
}
There is an option that enables to ignore image cache:
bitmapImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
Read more at msdn

Categories

Resources