【问题标题】:Programmatically clear Silverlight Application Storage?以编程方式清除 Silverlight 应用程序存储?
【发布时间】:2012-09-07 12:49:17
【问题描述】:

我为一些客户发布了 Silverlight 应用程序。我在发布更新时遇到问题。

我希望当用户最初加载网页时,如果他们的应用程序存储比上次更新站点时更旧,那么 this 会发生。这将使我的应用程序工作。

那么,两个问题:

  • 如何检查用户存储的应用程序存储是否早于 Silverlight 网站的最后一次更新?

  • 如何删除站点的应用程序存储?

我试过打电话:

using( var store = IsolatedStorageFile.GetUserStoreForApplication() ) {
  store.Remove();
}
using( var store = IsolatedStorageFile.GetUserStoreForSite()) {
  store.Remove();
}

App.xaml.cs 文件中,但这些似乎对显示的页面没有影响 - 应用程序存储未完全清除。

【问题讨论】:

    标签: c# .net web-services silverlight web-applications


    【解决方案1】:

    您可以将 xap 文件的文件创建日期写入 Silverlight 对象的 initParams。

    <object id="xaml" data="data:application/x-silverlight-2," type="application/x-silverlight-2">
       <param name="initParams" value="<%= GetInitParams() %>" />
    

    在文件后面的代码中你可以这样写:

    protected string GetInitParams()
    {
        string xappath = HttpContext.Current.Server.MapPath(@"~/ClientBin/YourXapFile.xap");
        DateTime xapCreationDate = System.IO.File.GetLastWriteTime(xappath);
        return string.Format("lastUpdateDate={0:d}, xapCreationDate);
    }
    

    在 Silverlight 客户端中,您可以将此日期与应用程序存储的上次更新进行比较。您可以使用 IsolatedStorageFile 对象上的方法 GetLastWriteTime() 找到上次更新的日期和时间。

    然后您比较这两个日期并根据需要删除带有Deletefile 的文件。

    【讨论】:

      【解决方案2】:

      •如何检查用户存储的应用程序存储是否早于 Silverlight 站点的上次更新?

      此代码进入应用程序以检查是否存在并更新您的 SL 应用程序>

      Application.Current.CheckAndDownloadUpdateAsync();
      Application.Current.CheckAndDownloadUpdateCompleted += new CheckAndDownloadUpdateCompletedEventHandler(Current_CheckAndDownloadUpdateCompleted);
      
      private void Current_CheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)
      {   
         if (e.UpdateAvailable) 
         { 
      
         } 
      }
      

      •如何删除站点的应用程序存储?

      IsolatedStorageFile store  = IsolatedStorageFile.GetUserStoreForApplication();
      if(store.FileExists(FileName))
      {
        store.DeleteFile(FileName);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多