protected override async void RelayMethod(object obj) { string command = obj.ToString(); // Do:应用 if (command == "Button.Click.Edit") { this.ImageCollection.Clear(); EditDialog detial = new EditDialog() { DataContext = this }; MessageService.ShowWithLayer(detial); var model = await await MessageService.ShowWaittingResultMessge(() => { string id = this.SelectedItem?.ID; return(this.Respository.GetMovieWIthDetial(id)); }); this.ImageCollection = model.Item2?.ToObservable(); } // Do:取消 else if (command == "Button.Click.Load") { if (this.SelectCase == null) { MessageService.ShowSnackMessageWithNotice("请先选择案例!"); return; } var from = await MessageService.ShowWaittingResultMessge(() => { return(this.Respository.GetListAsync(l => l.CaseType == this.SelectCase.ID).Result); }); if (from == null) { MessageService.ShowSnackMessageWithNotice("没有视频数据,请先生成视频数据"); return; } #pragma warning disable CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法 Task.Run(() => { this.ObservableSource.Clear(); foreach (var item in from) { MovieModelViewModel viewModel = new MovieModelViewModel(item); this.ObservableSource.Add(viewModel); Thread.Sleep(2); } MessageService.ShowSnackMessageWithNotice("加载完成..."); }); #pragma warning restore CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法 } else if (command == "ListBox.SelectionChanged.Filter") { var tags = this.SelectTag.ToList(); Func <MovieModelViewModel, bool> expression = l => { if (tags == null || tags.Count == 0) { return(true); } if (string.IsNullOrEmpty(l.TagTypes)) { return(false); } return(tags.TrueForAll(k => l.TagTypes.Trim().Split(',').ToList().Exists(m => m == k.Name))); }; this.ObservableSource.Fileter = l => expression(l); } else if (command == "ListBox.SelectionChanged.OrderBy") { if (this.OrderBy == "按名称排序") { this.ObservableSource.Sort(l => l.Name, this.Desc); } else if (this.OrderBy == "按大小") { this.ObservableSource.Sort(l => l.Size, this.Desc); } else if (this.OrderBy == "按评分") { this.ObservableSource.Sort(l => l.Score, this.Desc); } else if (this.OrderBy == "按总时间") { this.ObservableSource.Sort(l => l.Duration, this.Desc); } else if (this.OrderBy == "按播放次数") { this.ObservableSource.Sort(l => l.PlayCount, this.Desc); } else if (this.OrderBy == "按清晰度") { this.ObservableSource.Sort(l => l.ArticulationType, this.Desc); } else if (this.OrderBy == "按缩略图") { this.ObservableSource.Sort(l => l.Image, this.Desc); } } else if (command == "Button.Click.Set") { SetControl detial = new SetControl() { DataContext = this }; MessageService.ShowWithLayer(detial); } else if (command == "ListBox.SelectionChanged.TagEdit") { Application.Current.Dispatcher.Invoke(() => { if (this.SelectedItem == null) { return; } if (this.EditSelectTag == null || this.EditSelectTag.Count == 0) { return; } this.SelectedItem.TagTypes = this.EditSelectTag?.Select(l => l.Name).Aggregate((l, k) => l + "," + k); }); } else if (command == "Button.Click.SetUpdate") { string message; if (!this.ModelState(this.SelectedItem.Model, out message)) { MessageService.ShowSnackMessage(message); return; } await this.Respository.UpdateAsync(this.SelectedItem.Model); MessageService.CloseWithLayer(); MessageService.ShowSnackMessage("保存成功!"); } else if (command == "Button.Click.DeleteDeep") { if (this.SelectedItem == null) { return; } var result = await MessageService.ShowResultMessge("确定要彻底删除文件?"); if (result) { if (File.Exists(this.SelectedItem.Url)) { File.Delete(this.SelectedItem.Url); MessageService.ShowSnackMessage("文件已删除:" + this.SelectedItem?.Url); this.RelayMethod("Button.Click.Remove"); } } } else if (command == "Button.Click.Remove") { if (this.SelectedItem == null) { return; } await this.Respository.DeleteAsync(this.SelectedItem.Model.ID); this.Invoke(() => this.ObservableSource.Remove(this.SelectedItem)); } else if (command == "BulletCheckBox.CheckedChanged.Click") { { if (!this.IsEditting) { this.Service3.ClipBoardChanged = null; return; } this.Service3.ClipBoardChanged = async() => { //Todo :复制的图片 BitmapSource bit = Clipboard.GetImage(); if (bit != null) { mbc_dv_movieimage image = new mbc_dv_movieimage(); image.MovieID = this.SelectedItem.ID; image.Text = DateTime.Now.ToDateTimeString(); image.TimeSpan = DateTime.Now.ToDateTimeString(); image.Image = ImageService.BitmapSourceToString(bit); await this.Respository.AddMovieImage(image); this.ImageCollection.Add(image); } }; } } else if (command == "Button.Click.DeleteImage") { await this.Service4.DeleteAsync(this.SelectImage); this.ImageCollection.Remove(this.SelectImage); MessageService.ShowSnackMessageWithNotice("删除成功!"); } else if (command == "Button.Click.SetImage") { Application.Current.Dispatcher.Invoke(() => { this.SelectedItem.Image = this.SelectImage?.Image; }); await this.Respository.SaveAsync(); } else if (command == "ListBox.SelectionChanged.SelectedtemChanged") { if (this.SelectedItem == null) { return; } var from = this.SelectedItem.TagTypes?.Split(',').ToList(); if (from == null) { this.EditSelectTag = new ObservableCollection <mbc_db_tagtype>(); return; } var result = this.TagCollection.Where(l => from.Exists(k => k == l.Name)); this.EditSelectTag.Clear(); ObservableCollection <mbc_db_tagtype> collection = new ObservableCollection <mbc_db_tagtype>(); foreach (var item in result) { collection.Add(item); } this.EditSelectTag = collection; } else if (command == "Button.Click.Play") { if (this.SelectedItem == null) { return; } PlayerDialog player = new PlayerDialog(); player.Source = new Uri(this.SelectedItem.Url, UriKind.Absolute); List <TimeFlagViewModel> times = new List <TimeFlagViewModel>(); var model = await await MessageService.ShowWaittingResultMessge(() => { string id = this.SelectedItem?.ID; return(this.Respository.GetMovieWIthDetial(id)); }); if (model.Item2 != null) { foreach (var item in model.Item2) { bool b = TimeSpan.TryParse(item.TimeSpan, out TimeSpan span); if (!b) { continue; } times.Add(new TimeFlagViewModel() { DisPlay = item.Text, TimeSpan = span }); } player.Times = times.ToObservable(); } player.FlagClick += async(l, k) => { TimeSpan time = player.GetTime(); var flag = new TimeFlagViewModel() { TimeSpan = time }; mbc_dv_movieimage image = new mbc_dv_movieimage(); string imageFile = await player.BeginShootCut(); if (!File.Exists(imageFile)) { return; } image.Image = ImageService.BitmapSourceToString(new BitmapImage(new Uri(imageFile, UriKind.Absolute))); bool r = await MessageService.ShowObjectWithPropertyForm(flag, null, "请输入标记信息", 1); if (!r) { return; } image.MovieID = this.SelectedItem.ID; image.Text = flag.DisPlay; image.TimeSpan = time.ToString(); await this.Respository.AddMovieImage(image); times = new List <TimeFlagViewModel>(); model = await await MessageService.ShowWaittingResultMessge(() => { string id = this.SelectedItem?.ID; return(this.Respository.GetMovieWIthDetial(id)); }); if (model.Item2 != null) { foreach (var item in model.Item2) { times.Add(new TimeFlagViewModel() { DisPlay = item.Text, TimeSpan = TimeSpan.Parse(item.TimeSpan) }); } player.Times = times.ToObservable(); } }; MessageService.ShowWithLayer(player); } }
public async Task ConvertMovie(mbc_dv_movie movie, bool isbatshutcut = false) { // Message:ffmpeg数据 var detial = FFmpegService.Instance.GetMediaEntity(movie.Url); if (detial != null) { movie.Duration = detial.Duration; movie.Bitrate = detial.Bitrate; movie.MediaCode = detial.MediaCode; movie.VedioType = detial.MediaType; movie.Resoluction = detial.Resoluction; movie.Aspect = detial.Aspect; movie.Rate = detial.Rate; } int duration = (int)TimeSpan.Parse(detial.Duration).TotalSeconds; int span = (int)(duration / 10); System.Console.WriteLine("加载缩略图:" + movie.Url); string shootcutpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "HeBianGu", Assembly.GetEntryAssembly().GetName().Name, "Shootcut", Path.GetFileNameWithoutExtension(movie.Url)); // Message:缩略图和预览图 string shootcutfile = Path.Combine(shootcutpath, Path.GetFileNameWithoutExtension(movie.Url) + "_shootcut.png"); // Message:默认一分钟图片作为缩略图 FFmpegService.Instance.ShootCut(movie.Url, shootcutfile, TimeSpan.FromSeconds(span).ToString()); if (File.Exists(shootcutfile)) { movie.Image = EncodeImageToString(shootcutfile); } if (isbatshutcut) { //string shootcutbatpath = Path.Combine(Path.GetDirectoryName(movie.Url), Path.GetFileNameWithoutExtension(movie.Url) + "_shootcut"); string shootcutbatpath = Path.Combine(shootcutpath, Path.GetFileNameWithoutExtension(movie.Url) + "_shootcut"); // Message:默认一分钟图片作为缩略图 var images = FFmpegService.Instance.ShootCutBat(movie.Url, shootcutbatpath, span, duration); var current = await this._dataContext.mbc_dv_movieimages.Where(l => l.MovieID == movie.ID)?.ToListAsync(); this._dataContext.mbc_dv_movieimages.RemoveRange(current); foreach (var m in images) { if (!File.Exists(m)) { continue; } mbc_dv_movieimage image = new mbc_dv_movieimage(); image.MovieID = movie.ID; image.Image = EncodeImageToString(m); image.Text = Path.GetFileName(m); _dataContext.mbc_dv_movieimages.Add(image); //// Message:保存完删除图片 //File.Delete(m); } } await this.SaveAsync(); }
public async Task AddMovieImage(mbc_dv_movieimage image) { this._dataContext.mbc_dv_movieimages.Add(image); await this._dbContext.SaveChangesAsync(); }
static void Main(string[] args) { //Console.WriteLine("Hello World!"); ConsoleContext context = new ConsoleContext("server=localhost;userid=root;pwd=123456;port=3306;database=test;sslmode=none;"); foreach (var item in context.mbc_dc_cases.Where(l => l.ISENBLED == 1)) { System.Console.WriteLine("正在生成案例:" + item.Name + "-" + item.BaseUrl); var extends = context.mbc_db_extendtypes; List <string> allextends = new List <string>(); if (extends != null) { foreach (var item1 in extends) { allextends.AddRange(item1.Value.Trim().ToLower().Split('/')); } } Predicate <FileInfo> match = l => { if (allextends.Count == 0) { return(true); } return(allextends.Exists(k => k == l.Extension)); }; if (!Directory.Exists(item.BaseUrl)) { Directory.CreateDirectory(item.BaseUrl); } var movies = context.mbc_dv_movies.Where(l => l.CaseType == item.ID).ToList(); Action <FileInfo> action = l => { if (movies != null) { if (movies.Exists(k => k.Url == l.FullName)) { return; } } if (!match(l)) { return; } System.Console.WriteLine("正在加载文件:" + l.FullName); mbc_dv_movie movie = new mbc_dv_movie(); // Message:基础数据 movie.Name = l.Name; movie.Url = l.FullName; movie.ExtendType = l.Extension; movie.CaseType = item.ID; movie.Size = l.Length; movie.FromType = "local"; var tags = context.mbc_db_tagtypes.Where(k => l.Name.Contains(k.Value)); var list = tags.ToList(); if (list != null && list.Count > 0) { movie.TagTypes = list.Select(k => k.Value).Aggregate((m, k) => m + "," + k); } System.Console.WriteLine("加载文件详情:" + l.FullName); try { // Message:ffmpeg数据 var detial = FFmpegService.Instance.GetMediaEntity(l.FullName); if (detial != null) { movie.Duration = detial.Duration; movie.Bitrate = detial.Bitrate; movie.MediaCode = detial.MediaCode; movie.VedioType = detial.MediaType; movie.Resoluction = detial.Resoluction; movie.Aspect = detial.Aspect; movie.Rate = detial.Rate; } } catch (Exception ex) { System.Console.WriteLine("获取ffmpeg详情信息错误:" + ex); } System.Console.WriteLine("加载缩略图:" + l.FullName); // Message:缩略图和预览图 string shootcutpath = Path.Combine(Path.GetDirectoryName(movie.Url), Path.GetFileNameWithoutExtension(movie.Url) + "_shootcut.png"); //Action<int> exitAction = k => // { // if (k != 0) return; // if (!File.Exists(shootcutpath)) return; // movie.Image = "data:image/jpeg;base64," + EncodeImageToString(shootcutpath); // context.mbc_dv_movies.Add(movie); // }; // Message:默认一分钟图片作为缩略图 FFmpegService.Instance.ShootCut(movie.Url, shootcutpath, "00:01:00"); if (File.Exists(shootcutpath)) { movie.Image = "data:image/jpeg;base64," + EncodeImageToString(shootcutpath); File.Delete(shootcutpath); } context.mbc_dv_movies.Add(movie); System.Console.WriteLine("加载预览图:" + l.FullName); string shootcutbatpath = Path.Combine(Path.GetDirectoryName(movie.Url), Path.GetFileNameWithoutExtension(movie.Url) + "_shootcut"); // Message:默认一分钟图片作为缩略图 var images = FFmpegService.Instance.ShootCutBat(movie.Url, shootcutbatpath); foreach (var m in images) { if (!File.Exists(m)) { continue; } mbc_dv_movieimage image = new mbc_dv_movieimage(); image.MovieID = movie.ID; image.Image = "data:image/jpeg;base64," + EncodeImageToString(m); image.Text = Path.GetFileName(m); context.mbc_dv_movieimages.Add(image); // Message:保存完删除图片 File.Delete(m); } // Message:一个文件一保存 context.SaveChanges(); System.Console.WriteLine("完成加载文件:" + l.FullName); }; DoAllFiles(item.BaseUrl, action); context.SaveChangesAsync(); System.Console.WriteLine("完成生成案例:" + item.Name + "-" + item.BaseUrl); } System.Console.WriteLine("全部完成"); System.Console.Read(); }