Exemple #1
0
        public static bool Update(FileUpdateInfo model)
        {
            IWCFService.ISeatManageService service = new WcfServiceForSeatManage.SeatManageDateService();
            bool isError = false;

            try
            {
                return(service.UpdateFileInfo(model));
            }
            catch (Exception ex)
            {
                isError = true;
                WriteLog.Write(string.Format("添加出错,异常信息:{0}", ex.Message));
                throw ex;
            }
            finally
            {
                ICommunicationObject ICommObjectService = service as ICommunicationObject;
                try
                {
                    if (ICommObjectService.State == CommunicationState.Faulted)
                    {
                        ICommObjectService.Abort();
                    }
                    else
                    {
                        ICommObjectService.Close();
                    }
                }
                catch
                {
                    ICommObjectService.Abort();
                }
            }
        }
Exemple #2
0
        public bool Update(FileUpdateInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("UPDATE  [dbo].[AutoUpdater]  SET ");
            strSql.Append("[AutoUpdaterXml] =@AutoUpdaterXml, ");
            strSql.Append("[UpdateLog] =@Remart, ");
            strSql.Append("[ReleaseDate] =@ReleaseDate ");
            strSql.Append(" WHERE Application=@Application ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@AutoUpdaterXml", model.ToString()),
                new SqlParameter("@Remart",         model.UpdateLog),
                new SqlParameter("@ReleaseDate",    model.ReleaseDate),
                new SqlParameter("@Application",    (int)model.SubsystemType)
            };
            try
            {
                int i = DBUtility.DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
                if (i > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private bool NeedUpdate(FileUpdateInfo fileUpdateInfo)
        {
            FilePath localPath = fileUpdateInfo.LocalFilePath;

            if (localPath.GetFileExt() == @".zip")
            {
                FilePath zipMd5Path = localPath.GetDirPath() + localPath.GetFileNameWithoutExtension() + @".md5";
                if (!File.Exists(zipMd5Path))
                {
                    // ReSharper disable once AssignNullToNotNullAttribute
                    Directory.CreateDirectory(Path.GetDirectoryName(fileUpdateInfo.LocalFilePath));
                    return(true);
                }

                var localZipMd5  = zipMd5Path.ReadAsString();
                var remoteZipMd5 = fileUpdateInfo.RemoteMD5.Trim().ToLower();
                return(localZipMd5 != remoteZipMd5);
            }

            if (!File.Exists(fileUpdateInfo.LocalFilePath))
            {
                // ReSharper disable once AssignNullToNotNullAttribute
                Directory.CreateDirectory(Path.GetDirectoryName(fileUpdateInfo.LocalFilePath));
                return(true);
            }

            var localMd5  = Md5Util.CaculateFileMd5(fileUpdateInfo.LocalFilePath).ToLower();
            var remoteMd5 = fileUpdateInfo.RemoteMD5.Trim().ToLower();

            return(localMd5 != remoteMd5);
        }
Exemple #4
0
        /// <summary>
        /// 添加一条新的纪录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>

        public bool Add(FileUpdateInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into AutoUpdater ([Application]  ,[AutoUpdaterXml] ,[UpdateLog]  ,[ReleaseDate] )");
            strSql.Append(" values (@Application ,@AutoUpdaterXml  ,@UpdateLog ,@ReleaseDate )");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Application",    (int)model.SubsystemType),
                new SqlParameter("@AutoUpdaterXml", model.ToString()),
                new SqlParameter("@UpdateLog",      model.UpdateLog),
                new SqlParameter("@ReleaseDate",    model.ReleaseDate.ToString())
            };
            try
            {
                int i = DBUtility.DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
                if (i > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private FileUpdateInfo DataRowToFileUpdaterInfo(DataRow dr)
        {
            string         updateFileXml = dr["AutoUpdaterXml"].ToString();
            FileUpdateInfo fileUpdate    = FileUpdateInfo.Convert(updateFileXml);;

            return(fileUpdate);
        }
 /// <summary>
 /// 添加自动更新信息
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool AddUpdaterFileInfo(FileUpdateInfo model)
 {
     try
     {
         return(updaterDal.Add(model));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public void BuildUpdateConfigFile(string path)
        {
            system = new FileUpdateInfo(path);
            FileNodeItems.Clear();
            FileNodeItem fnItem = BuildUpdateConfigFile(system.Files);

            if (fnItem != null)
            {
                FileNodeItems.Add(fnItem);
            }
        }
        private bool NeedUpdate(FileUpdateInfo fileUpdateInfo)
        {
            if (!File.Exists(fileUpdateInfo.LocalFilePath))
            {
                // ReSharper disable once AssignNullToNotNullAttribute
                Directory.CreateDirectory(Path.GetDirectoryName(fileUpdateInfo.LocalFilePath));
                return(true);
            }
            string localMd5  = Md5Util.CaculateFileMd5(fileUpdateInfo.LocalFilePath).ToLower();
            string remoteMd5 = fileUpdateInfo.RemoteMD5.Trim().ToLower();

            return(localMd5 != remoteMd5);
        }
 /// <summary>
 /// 获取选中的系统类型
 /// </summary>
 public void FindSystemMessage()
 {
     AdvertManage.Model.ProgramUpgradeModel program = AdvertManage.BLL.ProgramUpgradeBLL.GetProgramInfoByProgramType((AdvertManage.Model.Enum.SeatManageSubsystem)(int) SystemType);
     if (program == null)
     {
         return;
     }
     oldSystem = FileUpdateInfo.Convert(program.AutoUpdaterXml);
     if (oldSystem != null)
     {
         Version = oldSystem.Version;
     }
     else
     {
     }
 }
 /// <summary>
 /// 构建文件路径,上传。
 /// </summary>
 public string BuildUpdateFile()
 {
     AdvertManage.Model.ProgramUpgradeModel program = AdvertManage.BLL.ProgramUpgradeBLL.GetProgramInfoByProgramType((AdvertManage.Model.Enum.SeatManageSubsystem)(int) SystemType);
     if (program != null)
     {
         oldSystem = FileUpdateInfo.Convert(program.AutoUpdaterXml);
         if (oldSystem != null && Version == oldSystem.Version)
         {
             return("版本号重复");
         }
         filePaths = system.BuildUpdateFilePaths();
         return("");
     }
     else
     {
         return("");
     }
 }
        /// <summary>
        /// 获取更新信息
        /// </summary>
        /// <returns></returns>
        public static FileUpdateInfo GetUpdateInfo(SeatManageSubsystem system)
        {
            IWCFService.ISeatManageService seatService = WcfAccessProxy.ServiceProxy.CreateChannelSeatManageService();
            bool isError = false;

            try
            {
                WriteLog.Write("获取更新文件");
                FileUpdateInfo ret = seatService.GetUpdateInfo(system);
                return(ret);
            }
            catch (Exception ex)
            {
                isError = true;
                WriteLog.Write(string.Format("更新出错,获取更新信息失败:{0}", ex.Message));
                throw ex;
            }
            finally
            {
                ICommunicationObject ICommObjectService = seatService as ICommunicationObject;
                try
                {
                    if (ICommObjectService.State == CommunicationState.Faulted)
                    {
                        ICommObjectService.Abort();
                    }
                    else
                    {
                        ICommObjectService.Close();
                    }
                }
                catch
                {
                    ICommObjectService.Abort();
                }
            }
        }
Exemple #12
0
        ///// <summary>
        ///// 获取本地的文件更新信息
        ///// </summary>
        ///// <param name="system">系统名称</param>
        ///// <returns></returns>
        //private FileUpdateInfo GetLocalUpdateInfo(SeatManage.EnumType.SeatManageSubsystem system)
        //{
        //    string sysDirectory = string.Format(@"{0}{1}\updater.xml", baseDirectory, system.ToString());
        //    if (File.Exists(sysDirectory))
        //    {
        //        FileStream fs = new FileStream(sysDirectory, FileMode.Open);

        //        StreamReader streamReader = new StreamReader(fs);
        //        streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
        //        string arry = "";
        //        string strLine = streamReader.ReadLine();
        //        strLine = streamReader.ReadToEnd();
        //        streamReader.Close();
        //        streamReader.Dispose();
        //        fs.Close();
        //        fs.Dispose();
        //        Console.Write(arry);
        //        Console.ReadLine();
        //        if (strLine != null)
        //        {
        //            FileUpdateInfo updateInfo = FileUpdateInfo.Convert(strLine);
        //            return updateInfo;
        //        }
        //        else
        //        {
        //            return null;
        //        }
        //    }
        //    else
        //    {
        //        return null;
        //    }
        //}

        public void DownloadUpdateFiles()
        {
            SeatManage.EnumType.SeatManageSubsystem mysystem = SeatManage.EnumType.SeatManageSubsystem.Mediaplayer;

            FileUpdateInfo        serviceUpateInfo = SeatManage.Bll.FileTransportBll.GetUpdateInfo(mysystem);
            List <FileSimpleInfo> isUpdateFiles    = null;

            if (serviceUpateInfo != null)
            {
                //下载所有Xml中包含的文件,不对比本地文件版本
                isUpdateFiles = serviceUpateInfo.BuildSystemFileSilmpleList();// GetNewVerFiles(serviceUpateInfo, mysystem);//下载播放器
                for (int i = 0; i < isUpdateFiles.Count; i++)
                {
                    //TODO:把文件先下载到临时文件夹中,下载无误,再移动到指定目录中。 (以后优化)

                    string sysDirectory = string.Format(@"{0}{1}\{2}", baseDirectory, mysystem.ToString(), isUpdateFiles[i].Name);
                    if (!downloadFile.FileDownLoad(sysDirectory, isUpdateFiles[i].Name, mysystem))
                    {
                        break;
                    }
                }
            }
            string StartProgram = "";

            if (serviceUpateInfo != null)
            {
                StartProgram = serviceUpateInfo.StartProgram;
            }
            else
            {
                StartProgram = ConfigurationManager.AppSettings["MediaPlayerProgram"];
            }
            if (string.IsNullOrEmpty(StartProgram))
            {
                HandlerError("播放器启动失败,没有配置媒体播放器启动程序。");
            }
            else
            {
                string mediaplayerStartPath = string.Format(@"{0}{1}\{2}", baseDirectory, mysystem.ToString(), StartProgram);
                if (File.Exists(mediaplayerStartPath))
                {
                    System.Diagnostics.Process.Start(mediaplayerStartPath);
                }
                else
                {
                    if (HandlerError != null)
                    {
                        HandlerError(string.Format("播放器启动失败,文件{0}不存在。", mediaplayerStartPath));
                    }
                }
            }
            StartProgram = "";


            mysystem         = SeatManage.EnumType.SeatManageSubsystem.SeatClient;
            serviceUpateInfo = SeatManage.Bll.FileTransportBll.GetUpdateInfo(mysystem);
            if (serviceUpateInfo != null)
            {
                //下载所有Xml中包含的文件,不对比本地文件版本
                isUpdateFiles = serviceUpateInfo.BuildSystemFileSilmpleList();// GetNewVerFiles(serviceUpateInfo, mysystem); //播放器下载完成下载选座终端。
                for (int i = 0; i < isUpdateFiles.Count; i++)
                {
                    string sysDirectory = string.Format(@"{0}{1}\{2}", baseDirectory, mysystem.ToString(), isUpdateFiles[i].Name);
                    if (!downloadFile.FileDownLoad(sysDirectory, isUpdateFiles[i].Name, mysystem))
                    {
                        break;
                    }
                }
                serviceUpateInfo.Save(string.Format(@"{0}{1}\updater.xml", baseDirectory, mysystem.ToString()));//下载完成,保存信息
            }

            if (serviceUpateInfo != null)
            {
                StartProgram = serviceUpateInfo.StartProgram;
            }
            else
            {
                StartProgram = ConfigurationManager.AppSettings["SeatClientProgram"];
            }
            if (string.IsNullOrEmpty(StartProgram))
            {
                HandlerError("选座终端启动失败,没有配置选座终端启动程序。");
            }
            else
            {
                string seatClient = string.Format(@"{0}{1}\{2}", baseDirectory, mysystem.ToString(), StartProgram);
                if (File.Exists(seatClient))
                {
                    System.Diagnostics.Process.Start(seatClient);
                }
                else
                {
                    HandlerError(string.Format("选座终端启动失败,文件{0}不存在。", seatClient));
                }
            }
            if (Downloaded != null)//通知终端下载已经完成
            {
                Downloaded(this, new EventArgs());
            }
        }
 public void BuildUpdateConfigFile(string path)
 {
     system = new FileUpdateInfo(path);
     _Nodes.Clear();
     _Nodes.Add(BuildUpdateConfigFile(system.Files));
 }
Exemple #14
0
        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="subsystemType"></param>
        public bool DownloadUpdateFiles()
        {
            List <string> startPrograms = new List <string>();
            XmlDocument   doc           = new XmlDocument();
            string        path          = string.Format(@"{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "ClientLauncher.exe.config");

            if (!File.Exists(path))
            {
                ShowMessage = "找不到配置文件请查看配置文件是否存在。";
                return(false);
            }
            doc.Load(path);
            XmlNodeList nodes = doc.SelectNodes("//configuration/appSettings/add");

            foreach (XmlNode node in nodes)
            {
                if (node.Attributes["key"] != null && node.Attributes["key"].Value == "StartUpProgram")
                {
                    startPrograms.Add(node.Attributes["value"].Value);
                }
            }
            if (startPrograms.Count < 1)
            {
                ShowMessage = "找不到配置的启动项,请检查配置文件是否正确。";
                return(false);
            }
            programs = new List <StartProgram_ViewModel>();
            foreach (string s in startPrograms)
            {
                StartProgram_ViewModel p = StartProgram_ViewModel.Parse(s);
                if (p == null)
                {
                    ShowMessage = "配置的启动项查找失败,请检查配置文件是否正确。";
                    return(false);
                }
                programs.Add(p);
            }
            foreach (StartProgram_ViewModel vm in programs)
            {
                if (vm.SubsystemType == SeatManage.EnumType.SeatManageSubsystem.None)
                {
                    continue;
                }
                string savedri = AppDomain.CurrentDomain.BaseDirectory + vm.DrictortyPath;
                if (!Directory.Exists(savedri))
                {
                    ShowMessage = "文件路径不存在,请检查配置。";
                    return(false);
                }
                FileReadOnly.RemovingReadOnly(savedri);
                ShowMessage = "查找文件更新。";
                FileUpdateInfo serviceUpateInfo = FileTransportBll.GetUpdateInfo(vm.SubsystemType);
                // System.Windows.MessageBox.Show(vm.SubsystemType.ToString());
                if (serviceUpateInfo == null)
                {
                    //System.Windows.MessageBox.Show("找不到要更新的东西");
                    continue;
                }
                ShowMessage = "开始更新文件。";
                List <FileSimpleInfo> isUpdateFiles = serviceUpateInfo.BuildSystemFileSilmpleList();
                foreach (FileSimpleInfo Fsi in isUpdateFiles)
                {
                    string sysDirectory = string.Format(@"{0}\\{1}", savedri, Fsi.Name);
                    if (!DownloadFile.FileDownLoad(sysDirectory, Fsi.Name, vm.SubsystemType))
                    {
                        break;
                    }
                }
            }
            foreach (StartProgram_ViewModel vm in programs)
            {
                string filepath = AppDomain.CurrentDomain.BaseDirectory + vm.DrictortyPath + "\\" + vm.StartProgramClient;
                if (!File.Exists(filepath))
                {
                    ShowMessage = "启动文件不存在,请检查配置。";
                    return(false);
                }
                ShowMessage = "程序启动。";
                System.Diagnostics.Process.Start(filepath);
            }
            return(true);
        }
Exemple #15
0
 private void BackupProgram(SeatManage.EnumType.SeatManageSubsystem systemType)
 {
     try
     {
         string programDir = "";
         //根据类型设置要上传的程序路径
         if (systemType == EnumType.SeatManageSubsystem.Mediaplayer)
         {
             programDir = string.Format("{0}MediaPlayer", AppDomain.CurrentDomain.BaseDirectory);
         }
         else if (systemType == EnumType.SeatManageSubsystem.SeatClient)
         {
             programDir = string.Format("{0}SeatClient", AppDomain.CurrentDomain.BaseDirectory);
         }
         //判断路径是否存在
         if (!Directory.Exists(programDir))
         {
             if (BackupFiled != null)
             {
                 string errorMessage = string.Format("路径{0}不存在,请检查终端配置是否有误", programDir);
                 BackupFiled(new BackupProgressInfo()
                 {
                     Message = errorMessage
                 });
             }
             return;
         }
         //去除文件只读属性
         SetReadOnly(programDir);
         //构造系统文件结构
         FileUpdateInfo files = new FileUpdateInfo(programDir);
         files.SubsystemType = systemType;
         files.UpdateLog     = "初始版本";
         files.ReleaseDate   = DateTime.Now;
         //设置文件启动程序
         if (systemType == EnumType.SeatManageSubsystem.Mediaplayer)
         {
             files.StartProgram = "MediaPlayerClient.exe";
         }
         else if (systemType == EnumType.SeatManageSubsystem.SeatClient)
         {
             files.StartProgram = "SeatClient.exe";
         }
         //删除Log,Video和SlipImage
         for (int i = 0; i < files.Files.Directories.Count; i++)
         {
             if (files.Files.Directories[i].Name == "Caputre" || files.Files.Directories[i].Name == "Log" || files.Files.Directories[i].Name == "SlipImage")
             {
                 files.Files.Directories.Remove(files.Files.Directories[i]);
             }
         }
         //删除配置文件
         for (int i = 0; i < files.Files.Files.Count; i++)
         {
             string exName = files.Files.Files[i].Name.Substring(files.Files.Files[i].Name.LastIndexOf(".") + 1);
             if (exName == "config")
             {
                 files.Files.Files.Remove(files.Files.Files[i]);
             }
         }
         SeatManage.Bll.FileOperate fileUpload = new Bll.FileOperate();
         List <string> filesPathList           = files.BuildUpdateFilePaths();
         for (int i = 0; i < filesPathList.Count; i++)
         {
             string fileFullName = string.Format("{0}{1}", programDir, filesPathList[i]);
             if (Progress != null)
             {//注册上传的消息
                 BackupProgressInfo arge = new BackupProgressInfo();
                 arge.ProgramName    = systemType.ToString();
                 arge.UpdateFileName = filesPathList[i];
                 arge.Progress       = (int)(((double)i / (filesPathList.Count - 1)) * 100);
                 Progress(arge);
             }
             if (!fileUpload.UpdateFile(fileFullName, filesPathList[i], systemType))
             {
                 if (BackupFiled != null)
                 {
                     BackupProgressInfo arge = new BackupProgressInfo();
                     arge.Message = string.Format("文件{0}上传失败", filesPathList[i]);
                     BackupFiled(arge);
                 }
             }
         }
         FileUpdateInfo oldFile = SeatManage.Bll.FileTransportBll.GetUpdateInfo(systemType);
         if (oldFile == null)
         {
             SeatManage.Bll.FileTransportBll.Add(files);
         }
         else
         {
             SeatManage.Bll.FileTransportBll.Update(files);
         }
     }
     catch (Exception ex)
     {
         if (BackupFiled != null)
         {
             BackupProgressInfo arge = new BackupProgressInfo();
             arge.Message = string.Format("备份失败,请检查是否缺失了“座位管理系统终端设置程序.exe.config”文件");
             BackupFiled(arge);
         }
     }
 }