Ejemplo n.º 1
0
        public Updater()
        {
            string localXmlPath = Path.Combine(Application.StartupPath, DataModel.XmlFileName);

            if (!File.Exists(localXmlPath))
            {
                throw new FileNotFoundException(localXmlPath);
            }
            _localXmlFile = new UpdateXmlFile(localXmlPath);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tempXmlName"></param>
        /// <param name="serverXmlUrl"></param>
        /// <returns></returns>
        private UpdateXmlFile GetServerXmlFile(string tempXmlName, string serverXmlUrl)
        {
            if (File.Exists(tempXmlName))
            {
                File.Delete(tempXmlName);
            }
            WebFile.DownLoadFile(tempXmlName, serverXmlUrl);
            UpdateXmlFile serverXmlFile = new UpdateXmlFile(tempXmlName);

            return(serverXmlFile);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 检查更新,并返回可以更新的文件数据
        /// </summary>
        /// <returns>List<UpdateFile></returns>
        internal IEnumerable <UpdateFileInfo> CheckUpdateFile()
        {
            string tempXmlName = Path.Combine(TempDirectory, DataModel.XmlFileName);

            CreateTempDirectory(TempDirectory);//创建临时目录

            UpdateXmlFile serverXmlFile = GetUpdateXmlFile(tempXmlName);

            if (serverXmlFile == null || _localXmlFile.EntryPoint != serverXmlFile.EntryPoint || _localXmlFile.ApplicationId != serverXmlFile.ApplicationId)
            {
                return(new UpdateFileInfo[] { });
            }
            IEnumerable <UpdateFileInfo> newFile = serverXmlFile.FileInfos.Join(_localXmlFile.FileInfos, server => server.Name, local => local.Name, (server, local) => GetUpdateFileInfo(server, local)).Where(p => p != null);
            IEnumerable <UpdateFileInfo> addFile = serverXmlFile.FileInfos.Except(_localXmlFile.FileInfos, UpdateXmlFile.ComparerFileInfo.Comparer).Select(p => new UpdateFileInfo {
                CurrentVersion = "无", UpdateVersion = p.Version, FileName = p.Name
            });

            return(newFile.Union(addFile));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 从服务器上下载更新文件xml
        /// </summary>
        /// <param name="tempXmlName">从服务器上下载下来的本地临时更新文件全名</param>
        /// <returns></returns>
        UpdateXmlFile GetUpdateXmlFile(string tempXmlName)
        {
            UpdateXmlFile serverXmlFile = null;

            if (UpdateUrlList.Count == 0)
            {
                return(serverXmlFile);
            }

            DateTime beginDateTime = DateTime.Now;//开始下载时间

            int i = 0;

            foreach (var url in UpdateUrlList)
            {
                Task.Factory.StartNew(() =>
                {
                    string xmlUpdateUrl          = string.Format("{0}/{1}", url.TrimEnd('/'), DataModel.XmlFileName);
                    string tempInTempXmlFileName = Path.Combine(Path.GetDirectoryName(tempXmlName), string.Format("{0}{1}{2}", Path.GetFileNameWithoutExtension(tempXmlName), i, Path.GetExtension(tempXmlName)));
                    UpdateXmlFile tempVar        = GetServerXmlFile(tempInTempXmlFileName, xmlUpdateUrl);//服务器上下下来的xml
                    lock (LockObj)
                    {
                        if (string.IsNullOrWhiteSpace(ServerUrl))
                        {
                            ServerUrl       = url;
                            serverXmlFile   = tempVar;
                            TempXmlFileName = tempInTempXmlFileName;
                        }
                    }
                });
                ++i;
            }

            do
            {
                Thread.Sleep(64);
            } while (string.IsNullOrWhiteSpace(ServerUrl) && DateTime.Now.Subtract(beginDateTime).TotalMilliseconds < DownDuration);

            return(serverXmlFile);
        }