Exemplo n.º 1
0
        void DownUpdateConfig()
        {
            System.Threading.WaitCallback callBack = (state) =>
            {
                //Uri url = new Uri(System.Windows.Application.Current.Host.Source, "slupdate.xml");
                Uri       url    = new Uri("slupdate.xml", UriKind.Relative);
                WebClient client = new WebClient();
                System.Threading.Tasks.Task <Stream> task = client.OpenReadTaskAsync(url);
                task.Wait();

                if (task.Exception != null)
                {
                    Dispatcher.BeginInvoke(() =>
                    {
                        MessageBox.Show("读升级参数出错:" + task.Exception, "错误", MessageBoxButton.OK);
                        return;
                    });
                }

                using (var sw = new System.IO.StreamReader(task.Result))
                {
                    string xml = sw.ReadToEnd();
                    task.Result.Close();

                    try
                    {
                        SLContext.Instance.UpdateXml = SmartConfig.LoadXML(xml);
                    }
                    catch { }
                }

                Dispatcher.BeginInvoke(() =>
                {
                    this.loaderControl.Initialize();
                });
            };

            //X.线程同步。
            System.Threading.ThreadPool.QueueUserWorkItem(callBack);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 读本地配置。
        /// </summary>
        /// <returns></returns>
        SmartConfig GetLocalUpdateXml()
        {
            using (IsolatedStorageFile storeFile = IsolatedStorageFile.GetUserStoreForApplication())
            {
                //string fileName = "config\\slupdate.xml";
                string fileName = "slupdate.xml";

                if (storeFile.FileExists(fileName))
                {
                    IsolatedStorageFileStream fileStream = storeFile.OpenFile(fileName, FileMode.Open, FileAccess.Read);
                    using (StreamReader reader = new StreamReader(fileStream))
                    {
                        string xml = reader.ReadToEnd();
                        return(SmartConfig.LoadXML(xml));
                    }
                }
                else
                {
                    return(null);
                }
            }
        }