示例#1
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);
     }
 }
示例#2
0
 /// <summary>
 /// 媒体文件转换为VM
 /// </summary>
 /// <param name="itemlist"></param>
 /// <returns></returns>
 public void ViewModelParse(AMS_PlayListMd5Model playlist)
 {
     _id         = playlist.Id;
     _Number     = playlist.PlayListNo;
     _SubmitDate = playlist.ReleaseDate;
     _BeginDate  = playlist.EffectDate;
     _EndDate    = playlist.EndDate;
     _BeginTime  = DateTime.Parse(playlist.PlayVideoItems[0].PlayTime);
     _ItemList.Clear();
     for (int i = 0; i < playlist.PlayVideoItems.Count; i++)
     {
         PlaylistItemViewModel itemvm = new PlaylistItemViewModel();
         itemvm.Name     = playlist.PlayVideoItems[i].Name;
         itemvm.FilePath = playlist.PlayVideoItems[i].RelativeUrl;
         itemvm.Md5Value = playlist.PlayVideoItems[i].md5value;
         if (i + 1 >= playlist.PlayVideoItems.Count)
         {
             itemvm.SunTime = playlist.PlayElapsed;
         }
         else
         {
             itemvm.SunTime = int.Parse((DateTime.Parse(playlist.PlayVideoItems[i + 1].PlayTime) - DateTime.Parse(playlist.PlayVideoItems[i].PlayTime)).TotalSeconds.ToString().Split('.')[0]);
         }
         _ItemList.Add(itemvm);
     }
 }
        /// <summary>
        /// 增加一条包含MD5值的数据
        /// </summary>
        public int AddMd5(AMS_PlayListMd5Model model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into AMS_PlayList(");
            strSql.Append("Number,PlayList,ReleaseDate,EffectDate,EndDate)");
            strSql.Append(" values (");
            strSql.Append("@Number,@PlayList,@ReleaseDate,@EffectDate,@EndDate)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Number",      SqlDbType.NVarChar,  50),
                new SqlParameter("@PlayList",    SqlDbType.Text),
                new SqlParameter("@ReleaseDate", SqlDbType.DateTime),
                new SqlParameter("@EffectDate",  SqlDbType.DateTime),
                new SqlParameter("@EndDate",     SqlDbType.DateTime)
            };
            parameters[0].Value = model.PlayListNo;
            parameters[1].Value = model.ToXml();
            parameters[2].Value = model.ReleaseDate;
            parameters[3].Value = model.EffectDate;
            parameters[4].Value = model.EndDate;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
示例#4
0
        /// <summary>
        /// 更新播放列表
        /// </summary>
        public bool UpdatePlaylist()
        {
            AMS_PlayListMd5Model model = AMS_PlayListMd5Model.Parse(ToModel().ToXml());

            model.Id          = _id;
            model.ReleaseDate = _SubmitDate;
            try
            {
                if (!string.IsNullOrEmpty(_Number) && _ItemList.Count > 0 && (_BeginDate < _EndDate))
                {
                    AMS_PlayListMd5Model samemodel = AMS_PlayListBLL.GetMd5PlaylistByNum(_Number);
                    if (samemodel == null || samemodel.Id == _id)
                    {
                        foreach (AMS_VideoMd5Item item in model.VideoFiles)
                        {
                            if (item.RelativeUrl != item.Name)
                            {
                                FileOperate fo = new FileOperate();
                                if (!fo.UpdateFile(item.RelativeUrl, item.Name, SeatManage.EnumType.SeatManageSubsystem.MediaFiles))
                                {
                                    throw new Exception("文件" + item.Name + "上传失败!");
                                }
                            }
                        }
                        foreach (AMS_VideoMd5Item videoitem in model.PlayVideoItems)
                        {
                            videoitem.RelativeUrl = videoitem.Name;
                            videoitem.md5value    = videoitem.md5value;
                        }
                        if (AMS_PlayListBLL.UpdateMd5PlayList(model) == AdvertManage.Model.Enum.HandleResult.Failed)
                        {
                            throw new Exception("更新播放列表失败,具体详情请查看错误日志!");
                        }
                        return(true);
                    }
                    else
                    {
                        throw new Exception("已存在重复的编号!");
                    }
                }
                else
                {
                    throw new Exception("信息填写错误!请仔细检查!");
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                return(false);
            }
        }
        /// <summary>
        /// 更新一条包含MD5值的数据
        /// </summary>
        public bool UpdateMd5(AMS_PlayListMd5Model model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update AMS_PlayList set ");
            strSql.Append("Number=@Number,");
            strSql.Append("PlayList=@PlayList,");
            strSql.Append("ReleaseDate=@ReleaseDate,");
            strSql.Append("EffectDate=@EffectDate,");
            strSql.Append("EndDate=@EndDate");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Number",      SqlDbType.NVarChar,  50),
                new SqlParameter("@PlayList",    SqlDbType.Text),
                new SqlParameter("@ReleaseDate", SqlDbType.DateTime),
                new SqlParameter("@EffectDate",  SqlDbType.DateTime),
                new SqlParameter("@EndDate",     SqlDbType.DateTime),
                new SqlParameter("@Id",          SqlDbType.Int, 4)
            };
            parameters[0].Value = model.PlayListNo;
            parameters[1].Value = model.ToXml();
            parameters[2].Value = model.ReleaseDate;
            parameters[3].Value = model.EffectDate;
            parameters[4].Value = model.EndDate;
            parameters[5].Value = model.Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#6
0
        /// <summary>
        /// VM转换为文件列表
        /// </summary>
        /// <param name="itemlist"></param>
        /// <returns></returns>
        public AMS_PlayListMd5Model ToModel()
        {
            AMS_PlayListMd5Model model = new AMS_PlayListMd5Model();

            model.Id          = _id;
            model.PlayListNo  = _Number;
            model.ReleaseDate = ServerDateTime.Now.Value;
            model.EffectDate  = _BeginDate;
            model.EndDate     = _EndDate;
            model.PlayVideoItems.Clear();
            model.PlayElapsed = _ItemList[_ItemList.Count - 1].SunTime;
            for (int i = 0; i < _ItemList.Count; i++)
            {
                AMS_VideoMd5Item item = new AMS_VideoMd5Item();
                if (i == 0)
                {
                    item.PlayTime = _BeginTime.ToLongTimeString();
                }
                else
                {
                    item.PlayTime = (DateTime.Parse(model.PlayVideoItems[i - 1].PlayTime).AddSeconds(_ItemList[i - 1].SunTime)).ToLongTimeString();
                }
                if (_ItemList[i].FilePath != _ItemList[i].Name)
                {
                    item.Name        = _Number + _ItemList[i].Name;
                    item.RelativeUrl = _ItemList[i].FilePath;
                }
                else
                {
                    item.Name        = _ItemList[i].Name;
                    item.RelativeUrl = _ItemList[i].FilePath;
                }
                item.md5value = _ItemList[i].Md5Value;
                model.PlayVideoItems.Add(item);
            }
            return(model);
        }