我有这个隔离存储功能可以写入存储:
public static void WriteIsolatedStorage(object ObjectToStore, StorageType Key)
{
using (var storage = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
using (var storageFile = storage.CreateFile(Key.ToString()))
{
var xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(string));
switch (Key)
{
case StorageType.UserCredentials:
xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(dmWFUserCredentials));
break;
case StorageType.BackgroundAgentUserCredentials:
xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(dmWFUserCredentials));
break;
case StorageType.UserProfile:
xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(dmWFUser));
break;
case StorageType.InboxItems:
xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(ObservableCollection<dmWFInboxItem>));
break;
case StorageType.InboxTileItems:
xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(ObservableCollection<dmInboxTileInfo>));
break;
case StorageType.DocumentHeaders:
xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(ObservableCollection<dmWFDocumentHeader>));
break;
case StorageType.SearchCache:
xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(List<List<dmWFDocumentHeader>>));
break;
case StorageType.FacebookProfile:
xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(dmFBUserProfile));
break;
case
StorageType.BaseUrl:
xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(dmWFURLSetting));
break;
default:
break;
}
xmlSerializer.Serialize(storageFile, ObjectToStore);
}
}
然后这是我从这个存储中获取的功能:
public static dmWFURLSetting GetBaseUrl(StorageType Key)
{
try
{
using (var storage = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
{
using (var storageFile = storage.OpenFile(Key.ToString(), System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite))
{
dmWFURLSetting result = new dmWFURLSetting();
var xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(dmWFURLSetting));
return (dmWFURLSetting)xmlSerializer.Deserialize(storageFile);
}
}
}
catch (Exception)
{
return null;
}
}
好的,然后这是我如何从前端调用这些方法,然后是 viemodel,我正在使用 mvvm fr 这个手机应用程序。前端调用:
public string URL = (WorkflowBase.BaseURL != null ? WorkflowBase.BaseURL.ToString() : "");
这是后端的公共财产:
public static string BaseURL = AccTech.WP8.Helpers.IsolatedStorage.GetBaseUrl(Helpers.IsolatedStorage.StorageType.BaseUrl).BaseUrl.ToString();
好的,所以奇怪的部分来了,我知道当我在完全关闭后启动模拟器时,隔离的存储(缓存)是完全干净的,所以如果调用这个函数,我将得到一个 Null 返回......正如你在我的前端看到的如果我得到一个空值,则调用我进行内联,然后将其设为“”。所以这是我运行时遇到的错误。PS:如果我将 URL 设为静态,则应用程序可以工作
好的,这是我尝试逐步完成整个过程时遇到的错误:
我身体上无法正常工作我已经尝试了谷歌提供的所有东西......但没有任何反应,如果有人可以请给我一个答案,我会很高兴。
如果您需要更多数据或信息,请告诉我