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); }
/// <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); } } }
/// <summary> /// 下载清单。 /// </summary> /// <returns></returns> public IList <SmartFile> GetDownList() { //如果为测试程序,下载所有文件 string debug = Config.GetValue("Debug"); SLContext.Instance.Debug = string.Compare(debug, "true", StringComparison.CurrentCultureIgnoreCase) == 0; if (SLContext.Instance.Debug) { SLContext.Instance.Assembly = Config.GetValue("Assembly"); } string m_urlHost = string.Empty; try { m_urlHost = System.Windows.Application.Current.Host.Source.ToString(); } catch { System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { m_urlHost = System.Windows.Application.Current.Host.Source.ToString(); }); while (m_urlHost == string.Empty) { System.Threading.Thread.Sleep(50); } } //如果不是第一次执行。2012-07-11 if (this.files.Count > 0) { return(this.files); } this.files.Clear(); if (SLContext.Instance.UpdateXml == null) { return(files); } SmartConfig sc1 = SLContext.Instance.UpdateXml; if (sc1.Files.Count == 0) { return(files); } if (m_urlHost.ToLower().StartsWith("http://localhost") || m_urlHost.ToLower().StartsWith("http://127.0.0.1")) { return(sc1.Files); } SmartConfig sc2 = null; try { sc2 = this.GetLocalUpdateXml(); } catch { } if (sc2 == null) { return(sc1.Files); } //Debug状态。 if (SLContext.Instance.Debug) { return(sc1.Files); } // foreach (SmartFile item in sc1.Files) { var v = from c in sc2.Files where c.FileName == item.FileName select c; SmartFile item2 = v.FirstOrDefault(); if (item2 == null) { files.Add(item); } else { if (item.Time > item2.Time) { files.Add(item); } } } return(files); }