public ActionResult DownLoadFile(string id, string fileNum, string name) { Member member = m_SessionHelper.WebMember; if (member == null) { return(Redirect(Url.Action("Index", "Member"))); } new MemberModel().AddDownloadRecord(name, "1", member.MemberId.ToString()); EntityCounter(id, "Downer"); DownloadModel entityModel = new DownloadModel(id); switch (fileNum) { case ("1"): return(Redirect(new HomeShowModel().GetFile(entityModel.AFile1, string.IsNullOrWhiteSpace(entityModel.AFile1Name) ? entityModel.Name : entityModel.AFile1Name))); case ("2"): return(Redirect(new HomeShowModel().GetFile(entityModel.AFile2, string.IsNullOrWhiteSpace(entityModel.AFile2Name) ? entityModel.Name : entityModel.AFile1Name))); case ("3"): return(Redirect(new HomeShowModel().GetFile(entityModel.AFile3, string.IsNullOrWhiteSpace(entityModel.AFile3Name) ? entityModel.Name : entityModel.AFile1Name))); } return(new EmptyResult()); }
public DownloadViewModel() { _model = new DownloadModel(this); CancelButtonCommand = new DelegateCommand(OnCancel, CanCanel); _model.InitializationCompleteEvent += OnInitializationCompleteEvent; }
private static async Task <bool> Download(DownloadModel model, int c = 0) { ProgressBar.Init(false); Downloader downloader = new Downloader(model.DestinationPath, model.Url); downloader.DownloadChanged += Downloader_DownloadChanged; ProgressBar.Start(); bool ok = await downloader.StartSync(); downloader.DownloadChanged -= Downloader_DownloadChanged; ProgressBar.Stop(); if (ok && model.PostAction != null) { ProgressBar.Init(true, model.PostActionDescription); await Task.Run(() => model.PostAction.Invoke()); } if (!ok && c < MaxTries) { return(await Download(model, ++c)); } return(ok); }
public static async Task <ObservableCollection <DownloadModel> > GetDownload(DownloadType type) { var group = ""; switch (type) { case DownloadType.song: group = "song"; break; case DownloadType.mv: group = "mv"; break; case DownloadType.other: group = "other"; break; default: break; } var downs = await BackgroundDownloader.GetCurrentDownloadsForTransferGroupAsync(BackgroundTransferGroup.CreateGroup(group)); var downlist = new ObservableCollection <DownloadModel>(); if (downs.Count > 0) { foreach (var down in downs) { var model = new DownloadModel(); downlist.Add(model); } } return(downlist); }
public async Task <ActionResult> DownloadFiles(string downloadData, int degreeOfParallelism) { ResponseMessage response = new ResponseMessage { Success = true, Message = "Download Cancelled!" }; if (!string.IsNullOrEmpty(downloadData)) { var fileData = new DownloadModel { DataUrl = JsonConvert.DeserializeObject <List <DataUrl> >(downloadData), PathToDownload = FilesData.MapPathFolder(FilesData.DownloadFiles), degreeOfParallelism = degreeOfParallelism, }; FilesData.CreateDirectoryIfNotExists(FilesData.DownloadFiles); if (fileData.DataUrl.Any()) { response = (ResponseMessage)await _fileServices.DownloadFiles(fileData); } } return(Json(new { data = JsonConvertExtensions.GetJsonConvert(response) }, JsonRequestBehavior.AllowGet)); }
public async Task <IHttpActionResult> Put(int id, [FromBody] DownloadModel download) { if (download == null) { return(BadRequest("Required data was not supplied.")); } if (!await Exists(id)) { return(NotFound()); } var record = await db.Downloads.FindAsync(id); if (download.FileName != null && record.FileName != download.FileName) { record.FileName = download.FileName; } if (record.AllowDownload != download.AllowDownload) { record.AllowDownload = download.AllowDownload; } if (download.UploadedBy != null && record.UploadedBy != download.UploadedBy) { record.UploadedBy = download.UploadedBy; } return(await SaveChanges(record, ActionType.Put)); }
public async Task <DownloadModel> DownloadFile(string blobName) { if (!String.IsNullOrEmpty(blobName)) { var container = Helper.GetBlobContainer(); var blob = container.GetBlockBlobReference(blobName); var ms = new MemoryStream(); await blob.DownloadToStreamAsync(ms); var lastPos = blob.Name.LastIndexOf('/'); var fileName = blob.Name.Substring(lastPos + 1, blob.Name.Length - lastPos - 1); var download = new DownloadModel { BlobStream = ms, BlobFileName = fileName, BlobLength = blob.Properties.Length, BlobContentType = blob.Properties.ContentType }; return(download); } return(null); }
private void downloadAdapterThreadStart() { DownloadModel expr_06 = new DownloadModel(this); expr_06.setDownloadCallback(this); expr_06.DownloadFile(this.adapterUrl, Constants.updateAdapterFilePath, "adapter"); }
private void downloadSoftwareThreadStart() { DownloadModel expr_06 = new DownloadModel(this); expr_06.setDownloadCallback(this); expr_06.DownloadFile(this.softwareUrl, Constants.updateSoftwareFilePath, "software"); }
public static async Task<ObservableCollection<DownloadModel>> GetDownload(DownloadType type) { var group= ""; switch (type) { case DownloadType.song: group = "song"; break; case DownloadType.mv: group = "mv"; break; case DownloadType.other: group = "other"; break; default: break; } var downs = await BackgroundDownloader.GetCurrentDownloadsForTransferGroupAsync(BackgroundTransferGroup.CreateGroup(group)); var downlist = new ObservableCollection<DownloadModel>(); if(downs.Count>0) { foreach (var down in downs) { var model = new DownloadModel(); downlist.Add(model); } } return downlist; }
public IHttpActionResult GenerateChart(DownloadModel selection) { var tripsController = new TripsController(); var vehicleTrips = tripsController.GetTripsByDates(selection.VehicleId, selection.FromDate, selection.ToDate); return(Ok(vehicleTrips)); }
public async Task <IActionResult> Multi([Bind("Url")] DownloadModel model) { if (!ModelState.IsValid) { return(View(model)); } List <string> urls = model.Url.Split("\r\n").ToList(); try { List <DownloadResultModel> results = new List <DownloadResultModel>(); Parallel.ForEach(urls, async(url) => { DownloadResultModel result = new DownloadResultModel(); result.Url = url; result.VideoUrl = await RushDownloader.GetVidDownloadLink(url) ?? "None"; result.Title = RushDownloader.GetVideoTitle(url) ?? "None"; results.Add(result); }); return(View("Results", results)); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); return(View(model)); } }
private void customeVideoExtensionType(bool custome) { ProgressExtensionType = 0; ProgressPercentage = "0 %"; VideoDetails.ToList().ForEach(a => { a.VideoExtensionType = new ObservableCollection <VideoExtensionType>(); a.SelectedVideoExtensionType = null; if (custome) { Task task = new Task(() => { ObservableCollection <VideoExtensionType> listVideoExtension = new ObservableCollection <VideoExtensionType>(); listVideoExtension = Helper.CustomVideoInfo.getVideoExtensionType(a.Url, custome); //Clear befor fill System.Windows.Application.Current.Dispatcher.Invoke(() => // <--- HERE { listVideoExtension.ToList().ForEach(q => { if (a.VideoExtensionType == null) { a.VideoExtensionType = new ObservableCollection <VideoExtensionType>(); } a.VideoExtensionType.Add(q); a.IsCustome = custome; }); // if (a.VideoExtensionType != null && a.VideoExtensionType.Any()) { a.SelectedVideoExtensionType = a.VideoExtensionType[0]; } // ProgressExtensionType++; ProgressPercentage = VideoDetails.Count == 0 ? "0" : string.Concat(((ProgressExtensionType * 100) / VideoDetails.Count).ToString(), " %"); if (ProgressExtensionType == VideoDetails.Count) { ListVideoExtensionTypeCustom = DownloadModel.GetListVideoDetailsCustom(VideoDetails); } }); }, cts.Token); //{ // IsBackground = true //}; task.Start(); } else { a.IsCustome = custome; ListVideoExtensionTypeCustom = new ObservableCollection <VideoExtensionType>(); VideoExtensionTypeCustome = null; } }); }
void startDownload(bool isDownloadAll = false) { var push = DownloadModel.GetListVideoDownload(VideoDetails, isDownloadAll); push.ForEach(a => { VideoDownloader(a.Url, a.SelectedVideoExtensionType, a.VideoPath); }); }
public PartialViewResult RefreshDownloadButton(int Id) { var model = new DownloadModel { DocumentID = Id }; return(PartialView("_Download", model)); }
private async void btn_Download_Click(object sender, RoutedEventArgs e) { if (gv_Play.Items != null) { if (gv_Play.Items.Count == 1) { var info = gv_Play.SelectedItem as episodesModel; List <PlayerModel> ls = new List <PlayerModel>(); // int i = 1; foreach (episodesModel item in gv_Play.Items) { if (item.IsDowned == Visibility.Collapsed) { ls.Add(new PlayerModel() { Aid = _banId, Mid = item.danmaku.ToString(), Mode = PlayMode.Video, No = item.index, VideoTitle = item.index_title, Title = (this.DataContext as BangumiInfoModel).title }); } // i++; } DownloadModel m = new DownloadModel(); m.folderinfo = new FolderListModel() { id = _banId, desc = txt_desc.Text, title = txt_Name.Text, isbangumi = true, thumb = (this.DataContext as BangumiInfoModel).cover }; m.videoinfo = new VideoListModel() { id = _banId, mid = ls[0].Mid, part = Convert.ToInt32(ls[0].No), partTitle = ls[0].VideoTitle, videoUrl = await ApiHelper.GetVideoUrl(ls[0], cb_Qu.SelectedIndex + 1), title = txt_Name.Text }; DownloadHelper.StartDownload(m); messShow.Show("任务已加入下载", 3000); } else { gv_Play.SelectionMode = ListViewSelectionMode.Multiple; gv_Play.IsItemClickEnabled = false; messShow.Show("请选中要下载的分P视频,点击确定", 3000); Down_ComBar.Visibility = Visibility.Visible; com_bar.Visibility = Visibility.Collapsed; } //players.LoadPlayer(ls, gv_Play.SelectedIndex); } }
public void Start(String url, String title, DownloadType type) { DownloadModel model = new DownloadModel(new Uri(url), String.Empty, title, type); Items.Add(model); this.downloadQueue.Enqueue(model); DownloadCount++; Download(); }
private void Init() { model = new DownloadModel(); RootMain.Dependencies.Cache(model); list = RootMain.CreateChild <ResultList>("list", 0); { list.Size = new Vector2(1280f, 500f); } }
public string Run(DownloadModel model)//string url, ArchiveType archiveType) { Guard.AssertNotNull(model, "Source code repository URL is required."); Guard.AssertNotNullOrEmpty(model.Url, "Source code repository URL is required."); _targetUrl = new Uri(model.Url); RepositoryType repositoryType = RepositoryHelper.GetRepositoryTypeFromUrl(_targetUrl); RepositoryBase repositoryBase; Arguments args = new Arguments { Url = _targetUrl.ToString(), Revision = null }; Results?results = null; if (repositoryType == RepositoryType.GOOGLECODE_HG) { //hack - https://code.google.com/r/steverauny-treeview/ - https://steverauny-treeview.googlecode.com/hg/ string segment = _targetUrl.Segments[2].Replace("/", ""); string newUrl = string.Format("{0}://{1}.{2}", _targetUrl.Scheme, segment, "googlecode.com/hg/"); _targetUrl = new Uri(newUrl); repositoryBase = new SvnHttpManager(); results = repositoryBase.Run(args); } else if (repositoryType == RepositoryType.CODEPLEX_SVN || repositoryType == RepositoryType.GOOGLECODE_SVN) { repositoryBase = new SvnHttpManager(); results = repositoryBase.Run(args); } else if (repositoryType == RepositoryType.GITHUB) { repositoryBase = new GithubHttpManager(); results = repositoryBase.Run(args); } if (results.HasValue) { TargetFolder = results.Value.Path; } ArchiveType archive = model.ArchiveType == ".tar.gz" ? ArchiveType.TAR_GZ : ArchiveType.ZIP; string archivePath = new ArchiveHelper().CreateArchive(TargetFolder, archive); try { IOHelper.DeleteDirectory(TargetFolder); } catch (Exception) { throw; } return(archivePath); }
public async Task <byte[]> DownloadAsync(DownloadModel model, CancellationToken cancellationToken) { Link link = await GetAsync <DownloadModel, Link>(model).ConfigureAwait(false); using (var response = await client.GetAsync(link.Href, cancellationToken).ConfigureAwait(false)) { await ThrowIfIsNotExpectedResponseCode(response, HttpStatusCode.OK).ConfigureAwait(false); return(await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false)); } }
public static async Task <bool> DownloadFile(string destinationPath, string url, Action action, string postActionDescription) { DownloadModel model = new DownloadModel(url, destinationPath, action, postActionDescription); lock (sync) Downloads.Enqueue(model); while (!model.Performed) { await Task.Delay(500); } return(model.Success); }
public static string GetVehicleTripsPdfUrl(DownloadModel downloadModel) { var tripsController = new TripsController(); var vehicleController = new VehicleController(); var vehicleTrips = tripsController.GetTripsByVehicleId(downloadModel.VehicleId); var vehicle = vehicleController.GetVehicle().FirstOrDefault(x => x.Id == downloadModel.VehicleId); var url = BuildPdfAndReturnUrl(vehicleTrips, vehicle, downloadModel.FromDate, downloadModel.ToDate); return(url); }
/// 监视指定的后台下载任务 /// </summary> /// <param name="download">后台下载任务</param> private async Task HandleDownloadAsync(DownloadModel model) { try { DownloadProgress(model.handel.downOp); //进度监控 Progress <DownloadOperation> progressCallback = new Progress <DownloadOperation>(DownloadProgress); await model.handel.downOp.AttachAsync().AsTask(model.handel.cts.Token, progressCallback); model.videoinfo.downstatus = true; var PartFolder = await StorageFolder.GetFolderFromPathAsync(model.videoinfo.folderPath); StorageFile sefile = await PartFolder.CreateFileAsync(model.videoinfo.mid + ".json", CreationCollisionOption.OpenIfExists); await FileIO.WriteTextAsync(sefile, JsonConvert.SerializeObject(model.videoinfo)); ////保存任务信息 //// StorageFolder folder = ApplicationData.Current.LocalFolder; //StorageFolder DowFolder = await KnownFolders.VideosLibrary.CreateFolderAsync("Bili-Down", CreationCollisionOption.OpenIfExists); //StorageFile file = await DowFolder.GetFileAsync(model.Guid + ".bili"); ////用Url编码是因为不支持读取中文名 ////含会出现:在多字节的目标代码页中,没有此 Unicode 字符可以映射到的字符。错误 //string path = WebUtility.UrlDecode(await FileIO.ReadTextAsync(file)); //StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(path); //StorageFile files = await folder.CreateFileAsync(model.Guid + ".json", CreationCollisionOption.OpenIfExists); //await StorageFile.GetFileFromPathAsync(path+@"\" + model.Guid + ".json"); //string json = await FileIO.ReadTextAsync(files); //DownloadManage.DownModel info = JsonConvert.DeserializeObject<DownloadManage.DownModel>(json); //info.downloaded = true; //string jsonInfo = JsonConvert.SerializeObject(info); //StorageFile fileWrite = await folder.CreateFileAsync(info.Guid + ".json", CreationCollisionOption.ReplaceExisting); //await FileIO.WriteTextAsync(fileWrite, jsonInfo); ////移除正在监控 SendToast("《" + model.videoinfo.title + " " + model.videoinfo.partTitle + "》下载完成"); HandleList.Remove(model.videoinfo.downGUID); list_Downing.Items.Remove(model); //GetDownOk_New(); GetDownOk(); // list_Downing.Items.Remove(model); } catch (TaskCanceledException) { //取消通知 SendToast("取消任务《" + model.videoinfo.title + " " + model.videoinfo.partTitle + "》"); list_Downing.Items.Remove(model); GetDownOk(); } catch (Exception ex) { WebErrorStatus error = BackgroundTransferError.GetStatus(ex.HResult); return; } }
private async Task GetIterationsAsync() { Iterations.Clear(); var iterations = await _training.GetTrainedIterationsAysnc(); foreach (var i in iterations) { Iterations.Add(i); } SelectedIteration = (Iterations.Count > 0) ? Iterations[0] : null; DownloadModel.RaiseCanExecuteChanged(); }
public ActionResult DownloadFile(DownloadModel model) { // read form value via model System.Diagnostics.Debug.WriteLine(model.InputA); System.Diagnostics.Debug.WriteLine(model.InputB); // assume we create an an excel stream... MemoryStream excelStream = new MemoryStream(); return(new FileStreamResult(excelStream, "application/vnd.ms-excel") { FileDownloadName = "myfile.xslx" }); }
private void configRelayCommand_DownloadPush() { DownloadPush = new RelayCommand(o => { IsDownloadAll = true; Task task = new Task(() => { startDownload(IsDownloadAll); }); //{ IsBackground = true }; task.Start(); }, o => DownloadModel.ValidDownloadAll(VideoDetails)); }
public ActionResult Download(IndexModel model) { BenefitSetting benefitSetting = BenefitSettingsRepository.GetByToken(model.BenefitSettingToken); Employee employee = EmployeeRepository.GetByAccessCode(model.EmployeeAccessCode); DownloadModel downloadModel = new DownloadModel(benefitSetting, employee, model.Dependents, model.FullName, model.AnnualSalary); Response.Clear(); Response.ContentType = "application/force-download"; Response.AddHeader("content-disposition", "attachment; filename=Benefits" + DateTime.Now.Ticks + ".pdf"); Response.BinaryWrite(downloadModel.Generate()); Response.End(); return(null); }
private async void btn_Ok_Click(object sender, RoutedEventArgs e) { if (gv_Play.SelectedItems.Count == 0) { return; } var info = gv_Play.SelectedItem as episodesModel; int i = 1; foreach (episodesModel item in gv_Play.SelectedItems) { if (item.IsDowned == Visibility.Collapsed) { var vitem = new PlayerModel() { Aid = _banId, Mid = item.danmaku.ToString(), Mode = PlayMode.Video, No = item.index, VideoTitle = item.index_title, Title = (this.DataContext as BangumiInfoModel).title }; DownloadModel m = new DownloadModel(); m.folderinfo = new FolderListModel() { id = _banId, desc = txt_desc.Text, title = txt_Name.Text, isbangumi = true, thumb = (this.DataContext as BangumiInfoModel).cover }; m.videoinfo = new VideoListModel() { id = _banId, mid = vitem.Mid, part = Convert.ToInt32(vitem.No), partTitle = vitem.No + " " + vitem.VideoTitle, videoUrl = await ApiHelper.GetVideoUrl(vitem, cb_Qu.SelectedIndex + 1), title = txt_Name.Text }; DownloadHelper.StartDownload(m); } i++; } messShow.Show("任务已加入下载", 3000); gv_Play.SelectionMode = ListViewSelectionMode.None; gv_Play.IsItemClickEnabled = true; Down_ComBar.Visibility = Visibility.Collapsed; com_bar.Visibility = Visibility.Visible; }
/// <summary> /// Get Download Model /// </summary> /// <returns></returns> public DownloadModel GetDownloadModelTest() { var downloadModel = new DownloadModel(); var dataFiles = _fileServices.GetListOfFiles(); foreach (var item in dataFiles) { downloadModel.DataUrl.Add(new DataUrl { AbsoluteUri = item.AbsoluteUri }); } downloadModel.degreeOfParallelism = Convert.ToInt32(ConfigurationHelper.degreeOfParallelism); downloadModel.PathToDownload = ConfigurationHelper.PathToDownload; return(downloadModel); }
public ActionResult Index() { FirmaBilgileri firm = _firmsData.GetFirstActiveFirm(); List <DownloadLink> downloadLinks = _downloadLinkData.GetDownloadLinks(); var downloadModel = new DownloadModel { Downloads = downloadLinks, }; var layoutModel = new LayoutModel <DownloadModel>(downloadModel, firm); return(View(layoutModel)); }
public async Task <Dictionary <string, byte[]> > DownloadFile(DownloadModel model) { string uri; int count = 0; var result = new Dictionary <string, byte[]>(); foreach (var fileName in model.FileNames) { count++; uri = $"FTP://{model.ServerIp}/{model.DirectoryPath}/{fileName}"; var ftp = (FtpWebRequest)WebRequest.Create(uri); //建立FTP連線 ftp.Credentials = new NetworkCredential(model.UserName, model.Passwrod); //帳密驗證 ftp.Timeout = 2000; //等待時間 ftp.UseBinary = true; //傳輸資料型別 二進位/文字 ftp.UsePassive = false; //通訊埠接聽並等待連接 ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile; //下傳檔案 ftp.KeepAlive = count == model.FileNames.Count ? false : true; try { using (var response = (FtpWebResponse)ftp.GetResponse()) { // //資料串流設為接收FTP回應下載 using (var responseStream = response.GetResponseStream()) { using (var reader = new StreamReader(responseStream)) { var buffer = Encoding.UTF8.GetBytes(await reader.ReadToEndAsync()); result.Add(fileName, buffer); } //傳輸位元初始化 //byte[] buffer = new byte[8]; int iRead = 0; //do //{ // iRead = await responseStream.ReadAsync(buffer, 0, buffer.Length); //接收資料串流 //} while (!(iRead == 0)); } } } catch (Exception ex) { throw ex; } } return(result); }
public void FullResolutionDownload(DownloadModel model) { //need to access photos and names on main thread List<string> fileNames = new List<string>(); string[] ids = model.PhotoIds.Split(','); foreach (var id in ids) { long photoID = Convert.ToInt32(id); Photo photo = PhotoEntityRepository.Single(p => p.ID == photoID, p => p.Site); if (photo != null) { fileNames.Add(photo.FileName); } } string email = UserRepository.First(u => u.ProviderID == this.User.Identity.Name).EmailAddress; List<string> downloadLinks = new List<string>(); // For all groups of photosPerZip, save zip int photosPerZip = 500; int photoCount = fileNames.Count(); var fileCount = Math.Ceiling((Double)photoCount / (Double)photosPerZip); for (int i = 0; i < fileCount; i++) { string FileName = string.Format("{0}.{1}.zip", (DateTime.Now.ToString("MM-dd-yyyy-hh-mm-ss")), Convert.ToString(i + 1)); string downloadURL = string.Format("{0}://{1}{2}", Request.RequestUri.Scheme, Request.RequestUri.Authority, string.Format(@"/Photo/Download?fileName={0}", FileName)); downloadLinks.Add(downloadURL); var startIndex = i * photosPerZip; var endIndex = (i + 1) * photosPerZip; List<string> subsetFileNames = new List<string>(); if (photoCount > endIndex) { subsetFileNames = fileNames.GetRange(startIndex, photosPerZip); } else { var remainingCount = photoCount - startIndex; subsetFileNames = fileNames.GetRange(startIndex, remainingCount); } DownloadImages(subsetFileNames, FileName); } var emailText = ""; if (fileCount > 1) { emailText = string.Format("The images you requested for download were saved to {0} zip files. Please visit the links below to download the zip files. <br>{1}", Convert.ToString(fileCount), String.Join("<br>", downloadLinks)); } else { emailText = "Please visit " + downloadLinks[0] + " to download the images."; } //after all saved, send email EmailService.SendMail(email, "Phocalstream Download", emailText); }