private void DownloadFiles(string machine, TaskInfo task) { Logger.AddTrace("Downloading Files"); if (string.IsNullOrEmpty(task.GetSharedPath())) { return; } DownloadOptionsForm form = new DownloadOptionsForm(); form.Owner = Application.Current.MainWindow; form.ShowDialog(); DownloadAction action = form.SelectedAction; switch (action) { case DownloadAction.Overwrite: this.OverwriteFiles(machine, task); break; case DownloadAction.Merge: this.MergeFiles(machine, task); break; default: break; } }
/// <summary> /// 下载文件调用 /// </summary> public void DownloadFile() { if (DownloadAction != null) { DownloadAction.Invoke(); } }
private static void DownloadEventAction(DownloadEventArgs args, DownloadAction action) { if (args.DownloadInfo != null) { lock (downloads.SyncRoot) { action(args.DownloadInfo); } } else if (args.Downloads != null) { lock (downloads.SyncRoot) { foreach (DownloadInfo dif in args.Downloads) { if (dif != null) { action(dif); } } } } source.Update(); }
/// <summary> /// Download all items recursively /// </summary> private void DownloadRecursive(ShareFileClient client, int downloadId, Models.Item source, DirectoryInfo target, ActionType actionType) { if (source is Models.Folder) { var subdir = CreateLocalFolder(target, source as Folder); var children = client.Items.GetChildren(source.url).Execute(); if (children != null) { ActionManager actionManager = new ActionManager(); foreach (var child in children.Feed) { if (child is Models.Folder && Recursive) { DownloadRecursive(client, downloadId, child, subdir, actionType); } else if (child is Models.File) { DownloadAction downloadAction = new DownloadAction(FileSupport, client, downloadId, (Models.File)child, subdir, actionType); actionManager.AddAction(downloadAction); } } actionManager.Execute(); } } }
private async void DownloadButton_Click(object sender, RoutedEventArgs e) { if (downloadInfo == null) { return; } this.Close(); DownloadAction Action = LocalAudioOption.IsChecked == true ? DownloadAction.DownloadVideo : LocalVideoOption.IsChecked == true ? DownloadAction.DownloadAudio : DownloadAction.Download; await SessionCore.Instance.Business.DownloadManager.DownloadVideoAsync(video, -1, null, Action, options); }
/// <summary> /// Returns the list of available CSV files in the specified repository folder /// </summary> /// <param name="data">The download parameters</param> /// <returns> /// The list of files /// </returns> public async Task <IEnumerable <CsvFile> > GetList(DownloadAction data) { // get the content of the JSON file that lists the possible CSV files and their descriptions var descriptor = await DownloadFile <CsvFilesList>(data.repository, data.details); // list the actual files in the folder var files = await ListFiles(data.repository, data.folder); // return the files that match in both lists return(descriptor.files.Where(d => files.Tree.Any((f) => f.Path == d.filename))); }
internal void StartDownload(DownloadAction action) { if (trackedDownloadStates.ContainsKey(action.Uri.ToString())) { // This content is already being downloaded. Do nothing. return; } trackedDownloadStates[action.Uri.ToString()] = action; HandleTrackedDownloadStatesChanged(); StartServiceWithAction(action); }
public void ToggleDownload(Activity activity, string name, android.Net.Uri uri, string extension) { if (IsDownloaded(uri)) { DownloadAction removeAction = GetDownloadHelper(uri, extension).GetRemoveAction(Utils.GetUtf8Bytes(name)); StartServiceWithAction(removeAction); } else { StartDownloadDialogHelper helper = new StartDownloadDialogHelper(activity, GetDownloadHelper(uri, extension), this, name); helper.Prepare(); } }
public void OnTaskStateChanged(Offline.DownloadManager downloadManager, TaskState taskState) { DownloadAction action = taskState.Action; android.Net.Uri uri = action.Uri; if ((action.IsRemoveAction && taskState.State == TaskState.StateCompleted) || (!action.IsRemoveAction && taskState.State == TaskState.StateFailed)) { // A download has been removed, or has failed. Stop tracking it. if (trackedDownloadStates.Remove(uri.ToString()) != false) { HandleTrackedDownloadStatesChanged(); } } }
static void InitializeChoiceService() { var downloadAction = new DownloadAction(); var exitAction = new ExitAction(); ChoiceService.Instance .Register(downloadAction.Handle, downloadAction.Name) .Register(exitAction.Handle, exitAction.Name) .PrintChoice() .Selecting() .Action .Invoke(null); Console.WriteLine("..."); Console.ReadLine(); }
private async Task DownloadFile(VideoListItem item, DownloadAction action) { if (Manager != null && item != null && item.MediaId != null) { Media ItemData = PlayerAccess.GetVideoById(item.MediaId.Value); if (ItemData != null) { SetStatus(item, VideoListItemStatusEnum.Downloading, null); await Manager.DownloadVideoAsync(ItemData, -1, (sender, e) => { SetStatus(item, e.DownloadInfo.IsCompleted ? VideoListItemStatusEnum.Done : VideoListItemStatusEnum.Failed); }, action, null); } } }
private void RecursiveDownload(ShareFileClient client, int downloadId, Models.Item source, DirectoryInfo target) { if (source is Models.Folder) { var children = client.Items.GetChildren(source.url).Execute(); var subdirCheck = new DirectoryInfo(System.IO.Path.Combine(target.FullName, source.FileName)); if (subdirCheck.Exists && !Force && !ResumeSupport.IsPending) { throw new IOException("Path " + subdirCheck.FullName + " already exists. Use -Force to ignore"); } var subdir = target.CreateSubdirectory(source.FileName); if (children != null) { ActionManager actionManager = new ActionManager(this, source.FileName); foreach (var child in children.Feed) { if (child is Models.Folder) { RecursiveDownload(client, downloadId, child, subdir); } else if (child is Models.File) { if (!ResumeSupport.IsPending || !ResumeSupport.CheckFileStatus(child.FileName)) { ActionType actionType = Force || ResumeSupport.IsPending ? ActionType.Force : ActionType.None; DownloadAction downloadAction = new DownloadAction(FileSupport, client, downloadId, (Models.File)child, subdir, actionType); actionManager.AddAction(downloadAction); } } } actionManager.Execute(); } } else if (source is Models.File) { ActionManager actionManager = new ActionManager(this, source.FileName); if (!ResumeSupport.IsPending || !ResumeSupport.CheckFileStatus(source.FileName)) { ActionType actionType = Force || ResumeSupport.IsPending ? ActionType.Force : ActionType.None; DownloadAction downloadAction = new DownloadAction(FileSupport, client, downloadId, (Models.File)source, target, actionType); actionManager.AddAction(downloadAction); } actionManager.Execute(); } }
private void btnOk_Click(object sender, RoutedEventArgs e) { if (radNone.IsChecked.GetValueOrDefault( )) { this.SelectedAction = DownloadAction.None; } else if (radOverwrite.IsChecked.GetValueOrDefault( )) { this.SelectedAction = DownloadAction.Overwrite; } else if (radMerge.IsChecked.GetValueOrDefault( )) { this.SelectedAction = DownloadAction.Merge; } this.Close( ); }
public List <object> GetOfflineStreamKeys(android.Net.Uri uri) { if (!trackedDownloadStates.ContainsKey(uri.ToString())) { return(new List <object>()); } DownloadAction action = trackedDownloadStates[uri.ToString()]; if (action is SegmentDownloadAction) { List <object> objs = new List <object>(((SegmentDownloadAction)action).Keys.ToArray()); return(objs); } return(new List <object>()); }
public void OnClick(IDialogInterface dialog, int which) { Java.Util.ArrayList selectedTrackKeys = new Java.Util.ArrayList(); for (int i = 0; i < representationList.ChildCount; i++) { if (representationList.IsItemChecked(i)) { selectedTrackKeys.Add(trackKeys[i]); } } if (!selectedTrackKeys.IsEmpty || trackKeys.Count == 0) { // We have selected keys, or we're dealing with single stream content. DownloadAction downloadAction = downloadHelper.GetDownloadAction(Utils.GetUtf8Bytes(name), selectedTrackKeys); downloadTracker.StartDownload(downloadAction); } }
public override async Task <object> Fetch() { return(await DownloadAction.Action(new Uri(uri), new BaseQuery(this), x => { switch (x.Type) { case BaseResourceType.File: { WriteVerboseLine($"Start downloading {x.Name}, size {x.Size}."); break; } case BaseResourceType.Folder: { WriteVerboseLine($"Enter folder {x.Name}."); break; } } })); }
private void StartServiceWithAction(DownloadAction action) { DownloadService.StartWithAction(context, Java.Lang.Class.FromType(typeof(DemoDownloadService)), action, false); }
/// <summary> /// Downloads specified video. /// </summary> /// <param name="video">The video to download.</param> /// <param name="queuePos">The position in the queue to auto-play, or -1.</param> /// <param name="upgradeAudio">If true, only the audio will be downloaded and it will be merged with the local video file.</param> /// <param name="callback">The method to call once download is completed.</param> public async Task DownloadVideoAsync(Media video, int queuePos, EventHandler <DownloadCompletedEventArgs> callback, DownloadAction action, DownloadOptions options) { if (video == null || string.IsNullOrEmpty(video.DownloadUrl)) { throw new ArgumentException("Video object is null or doesn't contain a valid YouTube URL."); } // Store in the Temp folder. DefaultMediaPath PathCalc = new DefaultMediaPath(PathManager.TempFilesPath.Substring(Settings.NaturalGroundingFolder.Length)); string Destination = Settings.NaturalGroundingFolder + PathCalc.GetDefaultFileName(video.Artist, video.Title, null, (MediaType)video.MediaTypeId); string DownloadDesc = Path.GetFileName(Destination); Directory.CreateDirectory(PathManager.TempFilesPath); await DownloadVideoAsync(video.DownloadUrl, Destination, DownloadDesc, callback, action, options ?? Options, new DownloadItemData(video, queuePos)).ConfigureAwait(false); }
/// <summary> /// Start download process /// </summary> private void StartDownload(ShareFileClient client, PSDriveInfo driveInfo, ICollection<string> resolvedPaths, ActionType actionType) { int transactionId = new Random((int)DateTime.Now.Ticks).Next(); ActionManager actionManager = new ActionManager(this, string.Empty); bool firstIteration = true; var shareFileItems = new List<Item>(); foreach (string path in resolvedPaths) { var item = Utility.ResolveShareFilePath(driveInfo, path); if (item == null) { throw new FileNotFoundException(string.Format("Source path '{0}' not found on ShareFile server.", path)); } var target = new DirectoryInfo(LocalPath); if (!target.Exists) { throw new Exception(string.Format("Destination '{0}' path not found on local drive.", LocalPath)); } // if create root folder flag is specified then create a container folder first // KA - Fix. When CreateRoot is used and the source item is a folder we should NOT create the parent of that folder. // This possibly fixes another unknown scenario when the root folder is specified as the source. if (firstIteration && CreateRoot && !(item is Models.Folder)) { Models.Folder parentFolder = client.Items.GetParent(item.url).Execute() as Folder; target = CreateLocalFolder(target, parentFolder); firstIteration = false; } if (item is Models.Folder) { // if user downloading the root drive then download its root folders // KA - Fix. We should also process only subfolders and files if CreateRoot is not used and source is a folder. // This prevents DownloadRecursive from creating the parent folder in conditions where CreateRoot is not specified. // Code adapted from DownloadRecursive function and processes both file sources and folder sources appropriately now. // if ((item as Folder).Info.IsAccountRoot.GetValueOrDefault()) if ((item as Folder).Info.IsAccountRoot.GetValueOrDefault() || !CreateRoot) { var children = client.Items.GetChildren(item.url) .Select("Id") .Select("url") .Select("FileName") .Select("FileSizeBytes") .Select("Hash") .Select("Info") .Execute(); if (children != null) { (item as Folder).Children = children.Feed; foreach (var child in children.Feed) { child.Parent = item; if (child is Models.Folder && ((item as Folder).Info.IsAccountRoot.GetValueOrDefault() || Recursive)) { DownloadRecursive(client, transactionId, child, target, actionType); shareFileItems.Add(child); } else if (child is Models.File) { DownloadAction downloadAction = new DownloadAction(FileSupport, client, transactionId, (Models.File)child, target, actionType); actionManager.AddAction(downloadAction); } } if (!(item as Folder).Info.IsAccountRoot.GetValueOrDefault()) { shareFileItems.Add(item); } } } else { DownloadRecursive(client, transactionId, item, target, actionType); shareFileItems.Add(item); } } else if (item is Models.File) { DownloadAction downloadAction = new DownloadAction(FileSupport, client, transactionId, (Models.File)item, target, actionType); actionManager.AddAction(downloadAction); shareFileItems.Add(item); } } actionManager.Execute(); // if strict flag is specified then also clean the target files which are not in source if (Strict) { var target = new DirectoryInfo(LocalPath); var directories = target.GetDirectories(); foreach (string path in resolvedPaths) { var item = Utility.ResolveShareFilePath(driveInfo, path); if (item is Folder) { foreach (DirectoryInfo directory in directories) { if (directory.Name.Equals(item.Name)) { DeleteLocalStrictRecursive(client, item, directory); break; } } } } } // on move remove source files if (Move) { foreach(var item in shareFileItems) { // KA - Fix. Replaced 'Recursive' with '!KeepFolders'. This prevents "Move" from deleting folders even when KeepFolders is specified. // This fixes the bug that causes the source folder to be deleted in all scenarios where "Move" is specified and it does not contain children. // DeleteShareFileItemRecursive(client, item, Recursive); DeleteShareFileItemRecursive(client, item, !KeepFolders); } } }
public DownloadOptionsForm( ) { InitializeComponent( ); this.SelectedAction = DownloadAction.None; }
private static void DownloadEventAction(DownloadEventArgs args, DownloadAction action) { if (args.DownloadInfo != null) { lock (downloads.SyncRoot) { action (args.DownloadInfo); } } else if (args.Downloads != null) { lock (downloads.SyncRoot) { foreach (DownloadInfo dif in args.Downloads) { if (dif != null) { action (dif); } } } } source.Update (); }
/// <summary> /// Creates a successful result. /// </summary> /// <param name="plugin">The plugin that was successfully downloaded.</param> /// <param name="action">The action that was performed.</param> /// <returns>The result.</returns> public static DownloadResult FromSuccess(IdeaPlugin plugin, DownloadAction action) { return(new DownloadResult(plugin, action)); }
public void GivenDownloadFileAction() { downloadFile = new DownloadAction(); }
/// <summary> /// Initializes a new instance of the <see cref="DownloadResult"/> class. /// </summary> /// <param name="plugin">The plugin that was downloaded.</param> /// <param name="action">The action that was performed.</param> private DownloadResult(IdeaPlugin plugin, DownloadAction action) { this.Plugin = plugin; this.Action = action; }
/// <summary> /// Start download process /// </summary> private void StartDownload(ShareFileClient client, PSDriveInfo driveInfo, ICollection <string> resolvedPaths, ActionType actionType) { int transactionId = new Random((int)DateTime.Now.Ticks).Next(); Logger.Instance.Info("Downloading files from ShareFile server."); ActionManager actionManager = new ActionManager(); bool firstIteration = true; foreach (string path in resolvedPaths) { var item = ShareFileProvider.GetShareFileItem((ShareFileDriveInfo)driveInfo, path, null, null); // if user didn't specify the Sharefile HomeFolder in path then append in path // e.g. if user tries sf:/Folder1 as sharefile source then resolve this path to sf:/My Files & Folders/Folder1 if (item == null && !path.StartsWith(String.Format(@"\{0}\", DefaultSharefileFolder))) { string updatedPath = String.Format(@"\{0}\{1}", DefaultSharefileFolder, path); item = ShareFileProvider.GetShareFileItem((ShareFileDriveInfo)driveInfo, updatedPath, null, null); } var target = new DirectoryInfo(LocalPath); // if create root folder flag is specified then create a container folder first if (firstIteration && CreateRoot) { Models.Folder parentFolder = client.Items.GetParent(item.url).Execute() as Folder; target = CreateLocalFolder(target, parentFolder); firstIteration = false; } if (item is Models.Folder) { // if user downloading the root drive then download its root folders if ((item as Folder).Info.IsAccountRoot == true) { var children = client.Items.GetChildren(item.url).Execute(); foreach (var child in children.Feed) { if (child is Models.Folder) { DownloadRecursive(client, transactionId, child, target, actionType); } } } else { DownloadRecursive(client, transactionId, item, target, actionType); } } else if (item is Models.File) { DownloadAction downloadAction = new DownloadAction(FileSupport, client, transactionId, (Models.File)item, target, actionType); actionManager.AddAction(downloadAction); } } actionManager.Execute(); // on move remove source files if (Move) { foreach (string path in resolvedPaths) { var item = ShareFileProvider.GetShareFileItem((ShareFileDriveInfo)driveInfo, path, null, null); var target = new DirectoryInfo(LocalPath); // if strict flag is specified then also clean the target files which are not in source if (Strict) { DeleteLocalStrictRecursive(client, item, target); } DeleteShareFileItemRecursive(client, item, CreateRoot && Recursive); } } }
public DownloadItem(string url, string destination, string destinationNoExt, string title, DownloadAction action, EventHandler <DownloadCompletedEventArgs> callback, DownloadOptions options, object data) { this.Url = url; this.Status = DownloadStatus.Waiting; this.Destination = destination; this.DestinationNoExt = destinationNoExt; this.Title = title; this.Status = DownloadStatus.Waiting; UpdateProgress(); this.Action = action; this.Callback = callback; this.Options = options; this.Data = data; this.Files = new List <FileProgress>(); }
/// <summary> /// Start download process /// </summary> private void StartDownload(ShareFileClient client, PSDriveInfo driveInfo, ICollection <string> resolvedPaths, ActionType actionType) { int transactionId = new Random((int)DateTime.Now.Ticks).Next(); ActionManager actionManager = new ActionManager(this, string.Empty); bool firstIteration = true; var shareFileItems = new List <Item>(); foreach (string path in resolvedPaths) { var item = Utility.ResolveShareFilePath(driveInfo, path); if (item == null) { throw new FileNotFoundException(string.Format("Source path '{0}' not found on ShareFile server.", path)); } var target = new DirectoryInfo(LocalPath); if (!target.Exists) { throw new Exception(string.Format("Destination '{0}' path not found on local drive.", LocalPath)); } // if create root folder flag is specified then create a container folder first if (firstIteration && CreateRoot) { Models.Folder parentFolder = client.Items.GetParent(item.url).Execute() as Folder; target = CreateLocalFolder(target, parentFolder); firstIteration = false; } if (item is Models.Folder) { // if user downloading the root drive then download its root folders if ((item as Folder).Info.IsAccountRoot.GetValueOrDefault()) { var children = client.Items.GetChildren(item.url) .Select("Id") .Select("url") .Select("FileName") .Select("FileSizeBytes") .Select("Hash") .Select("Info") .Execute(); foreach (var child in children.Feed) { if (child is Models.Folder) { DownloadRecursive(client, transactionId, child, target, actionType); shareFileItems.Add(child); } } } else { DownloadRecursive(client, transactionId, item, target, actionType); shareFileItems.Add(item); } } else if (item is Models.File) { DownloadAction downloadAction = new DownloadAction(FileSupport, client, transactionId, (Models.File)item, target, actionType); actionManager.AddAction(downloadAction); shareFileItems.Add(item); } } actionManager.Execute(); // if strict flag is specified then also clean the target files which are not in source if (Strict) { var target = new DirectoryInfo(LocalPath); var directories = target.GetDirectories(); foreach (string path in resolvedPaths) { var item = Utility.ResolveShareFilePath(driveInfo, path); if (item is Folder) { foreach (DirectoryInfo directory in directories) { if (directory.Name.Equals(item.Name)) { DeleteLocalStrictRecursive(client, item, directory); break; } } } } } // on move remove source files if (Move) { foreach (var item in shareFileItems) { DeleteShareFileItemRecursive(client, item, Recursive); } } }
/// <summary> /// Downloads specified video. /// </summary> /// <param name="video">The video to download.</param> /// <param name="upgradeAudio">If true, only the audio will be downloaded and it will be merged with the local video file.</param> /// <param name="callback">The method to call once download is completed.</param> public async Task DownloadVideoAsync(string url, string destination, string description, EventHandler <DownloadCompletedEventArgs> callback, DownloadAction action, DownloadOptions options, object data) { if (IsDownloadDuplicate(url)) { return; } Directory.CreateDirectory(Path.GetDirectoryName(destination)); // Add DownloadItem right away before doing any async work. string DestinationNoExt = Path.Combine(Path.GetDirectoryName(destination), Path.GetFileNameWithoutExtension(destination)); DownloadItem DownloadInfo = new DownloadItem(url, destination, DestinationNoExt, description, action, callback, options, data); Application.Current.Dispatcher.Invoke(() => { downloadsList.Insert(0, DownloadInfo); // Notify UI of new download to show window. DownloadAdded?.Invoke(this, new EventArgs()); }); if (downloadsList.Where(d => d.Status == DownloadStatus.Downloading || d.Status == DownloadStatus.Initializing).Count() < Options.SimultaneousDownloads) { await StartDownloadAsync(DownloadInfo).ConfigureAwait(false); } }