Esempio n. 1
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());
            }
        }
Esempio n. 2
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);
        }