private static DownloadableIllustration CreateDownloadableIllustration(Illustration downloadContent, string downloadPath) { var model = new DownloadableIllustration(downloadContent, downloadPath ?? DownloadPathMacros.FormatDownloadPath(Settings.Global.DownloadPath, downloadContent)); model.State.ValueChanged += (sender, args) => Application.Current.Dispatcher.Invoke(() => { switch (args.NewValue) { case DownloadState.Finished: model.Freeze(); Downloading.Remove(model); if (Downloaded.All(i => model.DownloadContent.GetDownloadUrl() != i.DownloadContent.GetDownloadUrl())) { Downloaded.Add(model); } break; case DownloadState.Downloading: Downloaded.Remove(model); Downloading.Add(model); break; case DownloadState.Canceled: Downloading.Remove(model); break; case DownloadState.Queue: case DownloadState.Exceptional: break; default: throw new ArgumentOutOfRangeException(); } }); return(model); }
static DownloadableIllustration CreateDownloadableIllustration(Illustration downloadContent, bool isFromMange, int index = -1) { var model = new DownloadableIllustration(downloadContent, isFromMange, index); model.DownloadStat.ValueChanged += (sender, args) => Application.Current.Dispatcher.Invoke(() => { switch (args.NewValue) { case DownloadStatEnum.Finished: model.Freeze(); Downloading.Remove(model); if (Downloaded.All(i => model.DownloadContent.GetDownloadUrl() != i.DownloadContent.GetDownloadUrl())) { Downloaded.Add(model); } break; case DownloadStatEnum.Downloading: Downloaded.Remove(model); Downloading.Add(model); break; case var stat when stat == DownloadStatEnum.Canceled || stat == DownloadStatEnum.Queue || stat == DownloadStatEnum.Exceptional: if (stat == DownloadStatEnum.Canceled) { Downloading.Remove(model); } break; default: throw new ArgumentOutOfRangeException(); } }); return(model); }
static DownloadableIllustration CreateDownloadableIllustration(Illustration downloadContent, bool isFromMange, DownloadOption option, int index = -1) { var filePathProvider = option.CreateNewWhenFromUser ? new CreateNewFolderForUserDownloadPathProvider(downloadContent.UserName) : (IDownloadPathProvider) new DefaultDownloadPathProvider(); var fileNameFormatter = new DefaultIllustrationFileNameFormatter(); var model = new DownloadableIllustration(downloadContent, fileNameFormatter, filePathProvider, isFromMange, index) { Option = option }; model.DownloadState.ValueChanged += (sender, args) => Application.Current.Dispatcher.Invoke(() => { switch (args.NewValue) { case DownloadStateEnum.Finished: model.Freeze(); Downloading.Remove(model); if (Downloaded.All(i => model.DownloadContent.GetDownloadUrl() != i.DownloadContent.GetDownloadUrl())) { Downloaded.Add(model); } break; case DownloadStateEnum.Downloading: Downloaded.Remove(model); Downloading.Add(model); break; case var stat when stat == DownloadStateEnum.Canceled || stat == DownloadStateEnum.Queue || stat == DownloadStateEnum.Exceptional: if (stat == DownloadStateEnum.Canceled) { Downloading.Remove(model); } break; default: throw new ArgumentOutOfRangeException(); } }); return(model); }