/// <summary> /// Download a web stream to a file. /// </summary> /// <param name="urlVariable">Url to access</param> /// <param name="destinationFileVariable">Destination file name.</param> /// <param name="nextCommand"></param> /// <returns></returns> public static IScriptCommand DownloadFile(string urlVariable = "{Url}", string destinationProfileVariable = "{Profile}", string destinationFileVariable = "{DestinationFile}", IScriptCommand nextCommand = null) { return(CoreScriptCommands.Download(urlVariable, "{DownloadStream}", CoreScriptCommands.DiskParseOrCreateFile(destinationProfileVariable, destinationFileVariable, "{Destination}", CoreScriptCommands.DiskOpenStream("{Destination}", "{DestinationStream}", FileExplorer.Defines.FileAccess.Write, CoreScriptCommands.CopyStream("{DownloadStream}", "{DestinationStream}", ScriptCommands.Reset(nextCommand, "{DownloadStream}", "{Destination}")))))); }
/// <summary> /// Serializable, Copy contents from file1 to file2 /// </summary> /// <param name="sourceFileVariable">Filepath of source</param> /// <param name="destinationFileVariable">Filepath of destination</param> /// <param name="nextCommand"></param> /// <returns></returns> public static IScriptCommand DiskCopyFile(string sourceProfileVariable = "{SourceProfile}", string sourceFileVariable = "{SourceFile}", string destinationProfileVariable = "{DestinationProfile}", string destinationFileVariable = "{DestinationFile}", IScriptCommand nextCommand = null) { return(CoreScriptCommands.ParsePath(sourceProfileVariable, sourceFileVariable, dcSourceVariable, CoreScriptCommands.DiskParseOrCreateFile(destinationProfileVariable, destinationFileVariable, dcDestVariable, CoreScriptCommands.DiskOpenStream(dcSourceVariable, "{SourceStream}", FileExplorer.Defines.FileAccess.Read, CoreScriptCommands.DiskOpenStream(dcDestVariable, "{DestinationStream}", FileExplorer.Defines.FileAccess.Write, CoreScriptCommands.CopyStream("{SourceStream}", "{DestinationStream}", CoreScriptCommands.NotifyEntryChanged(ChangeType.Created, null, dcSourceVariable, null, dcDestVariable, ScriptCommands.Reset(nextCommand, dcSourceVariable, dcDestVariable)))))), ResultCommand.Error(new FileNotFoundException(sourceFileVariable)))); }
private async Task <IScriptCommand> transferScriptCommandAsync(ParameterDic pm, IEntryModel[] srcEntries, IEntryModel destEntry, string destinationKey) { var progress = pm.GetProgress() ?? NullTransferProgress.Instance; var srcProfile = srcEntries.First().Profile as IDiskProfile; var destProfile = destEntry.Profile as IDiskProfile; var srcMapper = srcProfile.DiskIO.Mapper; var destMapping = destProfile.DiskIO.Mapper[destEntry]; List <IScriptCommand> notifyChangeCommands = new List <IScriptCommand>(); List <string> changedPath = new List <string>(); progress.Report(TransferProgress.IncrementTotalEntries(srcEntries.Count())); foreach (var srcEntry in srcEntries) { var srcMapping = srcMapper[srcEntry]; string destName = PathFE.GetFileName(srcMapping.IOPath); string destFullName = destProfile.Path.Combine(destEntry.FullPath, destName); progress.Report(TransferProgress.From(srcEntry.FullPath, destEntry.FullPath)); if (srcEntry.IsDirectory) { await ScriptRunner.RunScriptAsync(pm, ScriptCommands.Assign("{DT-SrcDirectory}", srcEntry, false, ScriptCommands.Assign("{DT-DestProfile}", destEntry.Profile, false, CoreScriptCommands.DiskParseOrCreateFolder("{DT-DestProfile}", destFullName, "{DT-DestDirectory}", IOScriptCommands.DiskTransferChild("{DT-SrcDirectory}", "{DT-DestDirectory}", RemoveOriginal, AllowCustomImplementation, ScriptCommands.Reset(ResultCommand.NoError, "{DT-DestDirectory}", "{DT-SrcDirectory}")))))); } else { await ScriptRunner.RunScriptAsync(pm, ScriptCommands.Assign("{DT-SrcFile}", srcEntry, false, ScriptCommands.Assign("{DT-SrcProfile}", srcEntry.Profile, false, ScriptCommands.Assign("{DT-DestProfile}", destEntry.Profile, false, CoreScriptCommands.DiskParseOrCreateFile("{DT-DestProfile}", destFullName, "{DT-DestFile}", CoreScriptCommands.DiskCopyFile("{DT-SrcProfile}", "{DT-SrcFile}", "{DT-DestProfile}", "{DT-DestFile}", ScriptCommands.Reset(ResultCommand.NoError, "{DT-SrcFile}", "{DT-DestFile}"))))))); } progress.Report(TransferProgress.IncrementProcessedEntries()); } logger.Info(String.Format("{0} {1} -> {2} using ScriptCommand", RemoveOriginal ? "Move" : "Copy", srcEntries.GetDescription(), destEntry.Name)); return(await GetAssignDestinationCommandAsync(pm, srcEntries, destEntry, destinationKey, NextCommand)); }