Пример #1
0
        private void HandleModuleDownloaded(DownloadCompletedEventArgs e)
        {
            string            uri         = (string)e.UserState;
            List <ModuleInfo> moduleInfos = this.GetDownloadingModules(uri);

            Exception error = e.Error;

            if (error == null)
            {
                try
                {
                    if (e.Result == null)
                    {
                        throw new Exception("ModuleDownloaded Failed");
                    }

                    //记录已经下载的模块
                    this.RecordDownloadComplete(uri);

                    Debug.Assert(!e.Cancelled, "Download should not be cancelled");

                    XapAnalysis analysis = new XapAnalysis();
                    analysis.Analysis(e.Result);

                    this.RecordDownloadSuccess(uri);

                    SaveLocalXapFile(e.Result, moduleInfos[0]);

                    Debug.WriteLine("Load Xap From WCF : " + moduleInfos[0].FileName);
                }
                catch (Exception ex)
                {
                    error = ex;
                }
                finally
                {
                    if (e.Result != null)
                    {
                        e.Result.Close();
                    }
                }
            }

            foreach (ModuleInfo moduleInfo in moduleInfos)
            {
                this.RaiseLoadModuleCompleted(moduleInfo, error);
            }
        }
Пример #2
0
        public void LoadModuleType(ModuleInfo moduleInfo)
        {
            if (moduleInfo == null)
            {
                throw new System.ArgumentNullException("moduleInfo");
            }

            try
            {
                //  Uri key = new Uri(moduleInfo.Ref, UriKind.RelativeOrAbsolute);
                string key = string.IsNullOrEmpty(moduleInfo.Ref) ? moduleInfo.FileName : moduleInfo.Ref;

                //检测模块是否包含需要下载文件,没有直接跳过。
                if (string.IsNullOrEmpty(key))
                {
                    this.RaiseLoadModuleCompleted(moduleInfo, null);

                    return;
                }

                #region 检测版本

                var localAppInfo = GetLocalVersion(string.Format("{0}/{1}", moduleInfo.FileName, moduleInfo.FileName + VERSION));
                if (moduleInfo.Version == localAppInfo.Version)
                {
                    XapAnalysis analysis = new XapAnalysis();
                    analysis.Analysis(GetLocalXapFile(moduleInfo.FileName));
                    this.RecordDownloadSuccess(key);
                    this.RaiseLoadModuleCompleted(moduleInfo, null);

                    Debug.WriteLine("Load Xap From Local : " + moduleInfo.FileName);
                }
                else
                {
                    #region  载XAP文件.
                    //判断将要下载的子系统是否已经被下载过,
                    //若已经被下载,则触发子系统加载完成事件。
                    if (this.IsSuccessfullyDownloaded(key))
                    {
                        this.RaiseLoadModuleCompleted(moduleInfo, null);
                    }
                    else
                    {
                        //判断是否正处在下载中,下载中的URI将不提供下次处理程序。
                        bool needToStartDownload = !this.IsDownloading(key);

                        //记录子系统的信息以及其URI信息,标识为下载中。
                        //用于控制重复下载请求。
                        this.RecordDownloading(key, moduleInfo);

                        if (needToStartDownload)
                        {
                            //初始化一个下载器,下载器分为从WCF下载和WEB下载两种方式,其均实现了IFileDownloader接口
                            //若直接通过WEB下载则创建的类型为WebFileDownloader
                            //若需要通过WCF下载则创建类型为FileDownloader
                            //通过下载后对获取的文件流(基本为XAP)进行解析。
                            IFileDownloader downloader = this.CreateDownloader(moduleInfo.IsOnWeb);
                            downloader.DownloadProgressChanged += this.IFileDownloader_DownloadProgressChanged;
                            //重要的事件
                            downloader.DownloadCompleted += this.IFileDownloader_DownloadCompleted;
                            downloader.DownloadAsync(moduleInfo.FileName, moduleInfo.FileName);
                        }
                    }

                    #endregion
                }
                #endregion
            }
            catch (Exception ex)
            {
                this.RaiseLoadModuleCompleted(moduleInfo, ex);
            }
        }
Пример #3
0
        public void LoadModuleType(ModuleInfo moduleInfo)
        {
            if (moduleInfo == null)
            {
                throw new System.ArgumentNullException("moduleInfo");
            }

            try
            {
                //  Uri key = new Uri(moduleInfo.Ref, UriKind.RelativeOrAbsolute);
                string key = string.IsNullOrEmpty(moduleInfo.Ref) ? moduleInfo.FileName : moduleInfo.Ref;

                //检测模块是否包含需要下载文件,没有直接跳过。
                if (string.IsNullOrEmpty(key))
                {
                    this.RaiseLoadModuleCompleted(moduleInfo,null);

                    return;
                }

                #region 检测版本

                var localAppInfo = GetLocalVersion(string.Format("{0}/{1}", moduleInfo.FileName, moduleInfo.FileName + VERSION));
                if (moduleInfo.Version == localAppInfo.Version)
                {
                    XapAnalysis analysis = new XapAnalysis();
                    analysis.Analysis(GetLocalXapFile(moduleInfo.FileName));
                    this.RecordDownloadSuccess(key);
                    this.RaiseLoadModuleCompleted(moduleInfo, null);

                    Debug.WriteLine("Load Xap From Local : " + moduleInfo.FileName);
                }
                else
                {
                    #region 下载XAP文件.
                    //判断将要下载的子系统是否已经被下载过,
                    //若已经被下载,则触发子系统加载完成事件。
                    if (this.IsSuccessfullyDownloaded(key))
                    {
                        this.RaiseLoadModuleCompleted(moduleInfo, null);
                    }
                    else
                    {
                        //判断是否正处在下载中,下载中的URI将不提供下次处理程序。
                        bool needToStartDownload =!this.IsDownloading(key);
 
                        //记录子系统的信息以及其URI信息,标识为下载中。
                        //用于控制重复下载请求。
                        this.RecordDownloading(key, moduleInfo);

                        if (needToStartDownload)
                        {
                            //初始化一个下载器,下载器分为从WCF下载和WEB下载两种方式,其均实现了IFileDownloader接口
                            //若直接通过WEB下载则创建的类型为WebFileDownloader
                            //若需要通过WCF下载则创建类型为FileDownloader
                            //通过下载后对获取的文件流(基本为XAP)进行解析。
                            IFileDownloader downloader = this.CreateDownloader(moduleInfo.IsOnWeb);
                            downloader.DownloadProgressChanged += this.IFileDownloader_DownloadProgressChanged;
                            //重要的事件
                            downloader.DownloadCompleted += this.IFileDownloader_DownloadCompleted;
                            downloader.DownloadAsync(moduleInfo.FileName, moduleInfo.FileName);
                        }
                    }

                    #endregion
                }
                #endregion
            }
            catch (Exception ex)
            {
                this.RaiseLoadModuleCompleted(moduleInfo, ex);
            }
        }
Пример #4
0
        private void HandleModuleDownloaded(DownloadCompletedEventArgs e)
        {
            string uri = (string)e.UserState;
            List<ModuleInfo> moduleInfos = this.GetDownloadingModules(uri);

            Exception error = e.Error;
            if (error == null)
            {
                try
                {
                    if (e.Result == null)
                        throw new Exception("ModuleDownloaded Failed");

                    //记录已经下载的模块
                    this.RecordDownloadComplete(uri);

                    Debug.Assert(!e.Cancelled, "Download should not be cancelled");

                    XapAnalysis analysis = new XapAnalysis();
                    analysis.Analysis(e.Result);

                    this.RecordDownloadSuccess(uri);

                    SaveLocalXapFile(e.Result, moduleInfos[0]);

                    Debug.WriteLine("Load Xap From WCF : " + moduleInfos[0].FileName);
                }
                catch (Exception ex)
                {
                    error = ex;
                }
                finally
                {
                    if (e.Result != null)
                        e.Result.Close();
                }
            }

            foreach (ModuleInfo moduleInfo in moduleInfos)
            {
                this.RaiseLoadModuleCompleted(moduleInfo, error);
            }
        }