Exemple #1
0
        /// <summary>
        /// 获取更新程序
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool GetUpgrade(int id)
        {
            Model.ProgramUpgradeModel programModel = BLL.ProgramUpgradeBLL.GetProgramInfoById(id);
            if (programModel != null)
            {
                FileOperate advertfileOperate = new FileOperate();
                SeatManage.EnumType.SeatManageSubsystem systemType = (SeatManage.EnumType.SeatManageSubsystem)(int) programModel.Application;

                SeatManage.Bll.FileOperate           seatmanagefileOperate = new SeatManage.Bll.FileOperate();
                SeatManage.ClassModel.FileUpdateInfo programInfo           = SeatManage.ClassModel.FileUpdateInfo.Convert(programModel.AutoUpdaterXml);
                List <string> filePath = programInfo.BuildUpdateFilePaths();
                foreach (string path in filePath)
                {
                    string fullPath = string.Format("{0}{1}", ServiceSet.TempFilePath, path);
                    //文件下载
                    if (!advertfileOperate.FileDownLoad(fullPath, path, systemType))
                    {
                        return(false);
                    }
                    if (!seatmanagefileOperate.UpdateFile(fullPath, path, systemType))
                    {
                        return(false);
                    }
                }
                //执行完成,不需要更新数据库。
                //上传完毕删除本地的文件以及文件夹。
                SeatManage.ClassModel.FileUpdateInfo.DelDirectorys(ServiceSet.TempFilePath);
                return(true);
            }
            return(true);
        }
Exemple #2
0
 /// <summary>
 /// 导出离线版本
 /// </summary>
 public bool DownloadPlaylist(string downloadpath)
 {
     try
     {
         downloadpath = downloadpath + "\\MediaPlaylist_" + ServerDateTime.Now.Value.ToShortDateString();
         DirectoryInfo dir = new DirectoryInfo(downloadpath);
         if (!dir.Exists)
         {
             dir.Create();
         }
         else
         {
             throw new Exception("存在相同的文件夹,请重新选择目录!");
         }
         AMS_PlayListMd5Model model = AMS_PlayListMd5Model.Parse(ToModel().ToXml());
         model.Id          = _id;
         model.ReleaseDate = _SubmitDate;
         if (!string.IsNullOrEmpty(_Number) && _ItemList.Count > 0 && (_BeginDate < _EndDate))
         {
             foreach (AMS_VideoMd5Item item in model.VideoFiles)
             {
                 if (item.RelativeUrl == item.Name)
                 {
                     FileOperate fo = new FileOperate();
                     if (!fo.FileDownLoad(downloadpath + "\\" + item.RelativeUrl, item.RelativeUrl, SeatManage.EnumType.SeatManageSubsystem.MediaFiles))
                     {
                         throw new Exception("文件" + item.Name + "离线保存失败!");
                     }
                 }
                 else
                 {
                     File.Copy(item.RelativeUrl, downloadpath + "\\" + item.Name);
                 }
                 foreach (AMS_VideoMd5Item videoitem in model.PlayVideoItems)
                 {
                     videoitem.RelativeUrl = videoitem.Name;
                     videoitem.md5value    = videoitem.md5value;
                 }
             }
             string xml     = model.ToXml();
             string xmlpath = downloadpath + "\\playList.xml";
             //写入文件
             FileStream   fs = new FileStream(xmlpath, FileMode.Create, FileAccess.Write);
             StreamWriter sw = new StreamWriter(fs);
             sw.Write(xml);
             sw.Close();
             fs.Close();
             return(true);
         }
         else
         {
             throw new Exception("信息填写错误!请仔细检查!");
         }
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show(ex.Message);
         return(false);
     }
 }
Exemple #3
0
        /// <summary>
        /// 载入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(_Device.Caputrepath))
            {
                label.Visibility = Visibility.Collapsed;
                try
                {
                    string        appdri = AppDomain.CurrentDomain.BaseDirectory;
                    DirectoryInfo dir    = new DirectoryInfo(appdri + "\\" + "DeviceCaputre");
                    if (!dir.Exists)
                    {
                        dir.Create();
                    }
                    FileOperate fo = new FileOperate();
                    if (fo.FileDownLoad(dir.FullName + "\\" + _Device.Caputrepath, _Device.Caputrepath, SeatManage.EnumType.SeatManageSubsystem.Caputre))
                    {
                        BinaryReader binReader = new BinaryReader(File.Open(dir.FullName + "\\" + _Device.Caputrepath, FileMode.Open));
                        FileInfo     fileInfo  = new FileInfo(dir.FullName + "\\" + _Device.Caputrepath);
                        byte[]       bytes     = binReader.ReadBytes((int)fileInfo.Length);
                        binReader.Close();

                        BitmapImage bitmap = new BitmapImage();
                        bitmap.BeginInit();
                        bitmap.StreamSource = new MemoryStream(bytes);
                        bitmap.EndInit();

                        deviceimage.Source = bitmap;
                    }
                    else
                    {
                        label.Content    = "图片载入失败!";
                        label.Visibility = Visibility.Visible;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    label.Content    = "图片载入失败!";
                    label.Visibility = Visibility.Visible;
                }
            }
        }
        /// <summary>
        /// 下载图片并且获取本地图片路径
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        Image imageLocation(string imageName)
        {
            /**
             *  判断图片在临时文件夹中是否存在。如果存在则不下载。
             *  修改时间:2013-9-5 王随
             */
            string filePath = string.Format(@"{0}temp\{1}", base.DirectoryPath, imageName);

            if (!File.Exists(filePath))
            {//如果本地文件不存在,则下载
                SeatManage.Bll.FileOperate fileDownload = new FileOperate();
                if (!fileDownload.FileDownLoad(filePath, imageName, SeatManage.EnumType.SeatManageSubsystem.PrintReceiptAd))
                {
                    return
                        (null);
                }
            }
            Image img = Image.FromFile(filePath);

            return(img);
        }
Exemple #5
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 #6
0
        /// <summary>
        /// 获取播放列表,下载列表中的文件,并执行上传。
        /// 往数据库中添加,如果已存在,则执行更新
        ///
        ///  开始下载文件之前先判断文件在缓存中是否存在,已经存在则跳过,不再下载。
        ///  下载中某个文件下载错误,则返回下载失败的信息。
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool GetPlaylist(int id)
        {
            try
            {
                FileOperate advertfileOperate = new FileOperate();
                SeatManage.Bll.FileOperate seatmanagefileOperate = new SeatManage.Bll.FileOperate();
                seatmanagefileOperate.Downloaded += new SeatManage.Bll.EventHandleFileTransport(seatmanagefileOperate_Downloaded);
                advertfileOperate.DownloadError  += new EventHandleFileOperateError(fileOperate_DownloadError);
                Model.AMS_PlayListMd5Model model = AdvertManage.BLL.AMS_PlayListBLL.GetMd5PlaylistById(id);

                foreach (Model.AMS_VideoMd5Item video in model.VideoFiles)
                {
                    string fileFullName = string.Format(@"{0}{1}", ServiceSet.TempFilePath, video.RelativeUrl);
                    //开始下载文件
                    if (!File.Exists(fileFullName))
                    {
                        bool downloadResult = advertfileOperate.FileDownLoad(fileFullName, video.RelativeUrl, SeatManage.EnumType.SeatManageSubsystem.MediaFiles);
                        if (!downloadResult)
                        {
                            //下载失败,直接返回false
                            return(false);
                        }
                    }
                }

                foreach (Model.AMS_VideoMd5Item video in model.VideoFiles)
                {
                    string fileFullName = string.Format(@"{0}{1}", ServiceSet.TempFilePath, video.RelativeUrl);
                    //文件下载完成,执行上传操作
                    bool uploadResult = seatmanagefileOperate.UpdateFile(fileFullName, video.RelativeUrl, SeatManage.EnumType.SeatManageSubsystem.MediaFiles);
                    if (!uploadResult)
                    {
                        //上传失败,直接返回false,不再尝试其他操作
                        return(false);
                    }
                }

                //判断播放列表是否存在
                SeatManage.ClassModel.AMS_PlayListMd5 seatPlayList = SeatManage.Bll.AMS_PlayList.GetMd5PlayListByNum(model.PlayListNo);
                if (seatPlayList != null)
                {
                    //播放列表存在,执行更新操作
                    SeatManage.ClassModel.AMS_PlayListMd5 playlist = SeatManage.ClassModel.AMS_PlayListMd5.Parse(model.ToXml());
                    seatPlayList.PlayListNo = model.PlayListNo;
                    playlist.ReleaseDate    = model.ReleaseDate;
                    SeatManage.Bll.AMS_PlayList.UpdateMd5Playlist(playlist);
                    //执行完成通知终端更新播放列表
                    List <SeatManage.ClassModel.TerminalInfo> terminalList = SeatManage.Bll.ClientConfigOperate.GetTerminalsInfo();
                    foreach (SeatManage.ClassModel.TerminalInfo terminal in terminalList)
                    {
                        terminal.IsUpdatePlayList = true;
                        SeatManage.Bll.ClientConfigOperate.UpdateTerminal(terminal);
                    }
                }
                else
                {
                    SeatManage.ClassModel.AMS_PlayListMd5 playlist = SeatManage.ClassModel.AMS_PlayListMd5.Parse(model.ToXml());
                    playlist.ReleaseDate = model.ReleaseDate;
                    SeatManage.Bll.AMS_PlayList.AddMd5Playlist(playlist);
                }
                foreach (Model.AMS_VideoMd5Item video in model.VideoFiles)
                {
                    string fileFullName = string.Format(@"{0}{1}", ServiceSet.TempFilePath, video.RelativeUrl);
                    if (File.Exists(fileFullName))
                    {
                        File.Delete(fileFullName);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }