Exemplo n.º 1
0
        public static IScriptCommand MessageBoxYesNo(string captionVariable    = "Header",
                                                     string contentVariable    = "Content",
                                                     IScriptCommand yesCommand = null, IScriptCommand noCommand = null)
        {
            string destinationVariable = "{MessageBoxResult}";

            return(MessageBoxShow("YesNo", captionVariable, contentVariable, destinationVariable,
                                  ScriptCommands.IfEquals(destinationVariable, "Yes", yesCommand, noCommand)));
        }
Exemplo n.º 2
0
        public static IScriptCommand RunICommand(ICommand command,
                                                 string parameterVariable,
                                                 bool throwIfError = false, IScriptCommand nextCommand = null)
        {
            string commandVariable = "{" + string.Format("Command{0}", new Random().Next()) + "}";

            return(ScriptCommands.Assign(commandVariable, command, false,
                                         ScriptCommands.RunICommand(commandVariable, parameterVariable, throwIfError, nextCommand)));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Serializable, shortcut method for [AssignValueConverter], which a specific item from an array from a variable and assign to another variable.
        /// </summary>
        /// <param name="arrayVariable"></param>
        /// <param name="id"></param>
        /// <param name="destinationVariable"></param>
        /// <param name="nextCommand"></param>
        /// <returns></returns>
        public static IScriptCommand AssignArrayItem(string arrayVariable       = "{Array}", int id = 0,
                                                     string destinationVariable = "{Destination}", IScriptCommand nextCommand = null)
        {
            string valueConverterVariable = ParameterDic.CombineVariable(arrayVariable, "Converter");

            return(AssignValueConverter(ValueConverterType.GetArrayItem, valueConverterVariable,
                                        ScriptCommands.Reassign(arrayVariable, valueConverterVariable,
                                                                destinationVariable, false, nextCommand), id));
        }
Exemplo n.º 4
0
 public static IScriptCommand List(IEntryModel directoryEntry, string destVariable = "{Destination}",
                                   string maskVariable        = "*",
                                   ListOptions options        = ListOptions.File | ListOptions.Folder,
                                   IScriptCommand nextCommand = null)
 {
     return(ScriptCommands.Assign("{List-DirectoryEntry}", directoryEntry, false,
                                  List("{List-DirectoryEntry}", destVariable, maskVariable, options,
                                       ScriptCommands.Reset(nextCommand, "{List-DirectoryEntry}"))));
 }
Exemplo n.º 5
0
        public static IScriptCommand IfEquals <T>(string variable = "{variable}", T value = default(T), IScriptCommand trueCommand = null,
                                                  IScriptCommand otherwiseCommand = null)
        {
            string ifEqualValueProperty = "{IfEquals-Value}";

            return
                (ScriptCommands.Assign(ifEqualValueProperty, value, false,
                                       IfValue(ComparsionOperator.Equals, variable, ifEqualValueProperty, trueCommand, otherwiseCommand)));
        }
Exemplo n.º 6
0
        public static IScriptCommand FileListIfSelectionLength(string fileListVariable    = "{FileList}",
                                                               ComparsionOperator op      = ComparsionOperator.Equals, int value  = 1,
                                                               IScriptCommand thenCommand = null, IScriptCommand otherwiseCommand = null)
        {
            string fileListSelectionVariable = ParameterDic.CombineVariable(fileListVariable, "Selection");

            return(UIScriptCommands.FileListAssignSelection(fileListSelectionVariable,
                                                            ScriptCommands.IfArrayLength(op, fileListSelectionVariable, value, thenCommand, otherwiseCommand)));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Set property of an object in ParameterDic to another object in ParameterDic.
        /// <example>
        /// ScriptCommands.SetProperty("{PSI}", "FileName", "{Value}")
        /// </example>
        /// </summary>
        /// <param name="sourceObjectVariable"></param>
        /// <param name="propertyName"></param>
        /// <param name="valueVariable"></param>
        /// <param name="nextCommand"></param>
        /// <returns></returns>
        public static IScriptCommand SetProperty(string sourceObjectVariable = "{Source}",
                                                 string propertyName         = "Property",
                                                 string valueVariable        = "{Value}", IScriptCommand nextCommand = null)
        {
            string valueConverterVariable = ParameterDic.CombineVariable(sourceObjectVariable, "Converter");

            return(AssignValueConverter(ValueConverterType.SetProperty, valueConverterVariable,
                                        ScriptCommands.Reassign(sourceObjectVariable, valueConverterVariable,
                                                                valueVariable, false, nextCommand), propertyName));
        }
Exemplo n.º 8
0
        ///// <summary>
        ///// Add variables (using Expression) to destination.
        ///// </summary>
        ///// <param name="sourceObjectVariable"></param>
        ///// <param name="addValues"></param>
        ///// <param name="destinationVariable"></param>
        ///// <param name="nextCommand"></param>
        ///// <returns></returns>
        //public static IScriptCommand Add(string sourceObjectVariable = "{Source}",
        //    object[] addValues = null,
        //    string destinationVariable = "{Destination}", IScriptCommand nextCommand = null)
        //{
        //    string valueConverterVariable = ParameterDic.CombineVariable(sourceObjectVariable, "Converter");
        //    return AssignValueConverter(ValueConverterType.AddValue, valueConverterVariable,
        //        ScriptCommands.Reassign(sourceObjectVariable, valueConverterVariable,
        //            destinationVariable, false, nextCommand), addValues);
        //}


        /// <summary>
        /// Concat array to destination
        /// </summary>
        /// <param name="sourceObjectVariable"></param>
        /// <param name="addValues"></param>
        /// <param name="destinationVariable"></param>
        /// <param name="nextCommand"></param>
        /// <returns></returns>
        public static IScriptCommand ConcatArray(string sourceObjectVariable = "{Source}",
                                                 object[] addValues          = null,
                                                 string destinationVariable  = "{Destination}", IScriptCommand nextCommand = null)
        {
            string valueConverterVariable = ParameterDic.CombineVariable(sourceObjectVariable, "Converter");

            return(AssignValueConverter(ValueConverterType.ConcatArray, valueConverterVariable,
                                        ScriptCommands.Reassign(sourceObjectVariable, valueConverterVariable,
                                                                destinationVariable, false, nextCommand), addValues));
        }
Exemplo n.º 9
0
        public static IScriptCommand AddValue <T>(string value1Variable      = "{Value1}",
                                                  T[] value2                 = null,
                                                  string destinationVariable = "{Destination}", IScriptCommand nextCommand = null)
        {
            value2 = value2 ?? new T[] {};
            string value2Variable = ParameterDic.RandomVariable();

            return(ScriptCommands.Assign(value2Variable, value2, false,
                                         Add(value1Variable, value2Variable, destinationVariable, nextCommand)));
        }
Exemplo n.º 10
0
 /// <summary>
 /// Not serializable, Copy contents from srcFile to destFile.
 /// </summary>
 /// <param name="srcFile"></param>
 /// <param name="destFile"></param>
 /// <param name="nextCommand"></param>
 /// <returns></returns>
 public static IScriptCommand DiskCopyFile(IEntryModel srcFile, IEntryModel destFile, IScriptCommand nextCommand = null)
 {
     return(ScriptCommands.Assign("{DiskCopyFile-Source}", srcFile, false,
                                  ScriptCommands.Assign("{DiskCopyFile-Dest}", destFile, false,
                                                        CoreScriptCommands.DiskOpenStream(dcSourceVariable, "{SourceStream}", FileExplorer.Defines.FileAccess.Read,
                                                                                          CoreScriptCommands.DiskOpenStream(dcDestVariable, "{DestinationStream}", FileExplorer.Defines.FileAccess.Write,
                                                                                                                            CoreScriptCommands.CopyStream("{CopyStream-Source}", "{CopyStream-Dest}",
                                                                                                                                                          CoreScriptCommands.NotifyEntryChanged(ChangeType.Created, null, dcSourceVariable, null, dcDestVariable,
                                                                                                                                                                                                ScriptCommands.Reset(nextCommand, dcSourceVariable, dcDestVariable))))))));
 }
Exemplo n.º 11
0
 public static IScriptCommand DiskTransferChild(string srcDirectoryVariable  = "{Source}",
                                                string destDirectoryVariable = "{DestinationDirectory}",
                                                string mask         = "*", ListOptions listOptions = ListOptions.File | ListOptions.Folder,
                                                bool removeOriginal = false, bool allowCustomImplementation = true, IScriptCommand nextCommand = null)
 {
     return(CoreScriptCommands.List(srcDirectoryVariable, "{DTC-ItemToTransfer}", mask, listOptions,
                                    ScriptCommands.ForEach("{DTC-ItemToTransfer}", "{DTC-CurrentItem}",
                                                           IOScriptCommands.DiskTransfer("{DTC-CurrentItem}", destDirectoryVariable, null, removeOriginal, allowCustomImplementation),
                                                           ScriptCommands.Reset(nextCommand, "{DTC-DestDirectory}", "{DTC-SrcDirectory}"))));
 }
Exemplo n.º 12
0
 public static IScriptCommand TransferChild(IEntryModel srcModel, IEntryModel destDirModel,
                                            Func <IEntryModel, bool> filterFunc = null, bool recrusive = false, IScriptCommand nextCommand = null)
 {
     return(WPFScriptCommands.List(srcModel, filterFunc, null, recrusive, ems =>
                                   WPFScriptCommands.ReportProgress(TransferProgress.IncrementTotalEntries(ems.Length),
                                                                    ScriptCommands.ForEach(ems, em =>
                                                                                           ScriptCommands.RunInSequence(
                                                                                               IOScriptCommands.Transfer(em, destDirModel),
                                                                                               WPFScriptCommands.ReportProgress(TransferProgress.IncrementProcessedEntries())),
                                                                                           nextCommand))));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Serializable, Run IfValue comparsion based on the length of an array in ParameterDic.
 /// </summary>
 /// <param name="op"></param>
 /// <param name="arrayVariable"></param>
 /// <param name="valueVariable"></param>
 /// <param name="trueCommand"></param>
 /// <param name="otherwiseCommand"></param>
 /// <returns></returns>
 public static IScriptCommand IfArrayLength(ComparsionOperator op, string arrayVariable = "{array}",
                                            string valueVariable       = "{value}",
                                            IScriptCommand trueCommand = null, IScriptCommand otherwiseCommand = null)
 {
     return
         (ScriptCommands.IfAssigned(arrayVariable,
                                    ScriptCommands.AssignValueConverter(ValueConverterType.GetProperty, "{GetPropertyConverter}",
                                                                        ScriptCommands.Reassign(arrayVariable, "{GetPropertyConverter}", "{ArrayLength}", false,
                                                                                                ScriptCommands.PrintLogger(MetroLog.LogLevel.Debug, "Length of array is {ArrayLength}",
                                                                                                                           ScriptCommands.IfValue(op, "{ArrayLength}", valueVariable, trueCommand, otherwiseCommand))), "Length"),
                                    otherwiseCommand));
 }
Exemplo n.º 14
0
        public static IScriptCommand NotifyEntryChangedPath(
            ChangeType changeType, IProfile sourceProfile, string[] sourceEntryPaths,
            IProfile destinationProfile, string[] destinationEntryPaths, IScriptCommand nextCommand = null)
        {
            string sourceEntriesKey      = "{SourceEntriesKey}";
            string destinationEntriesKey = "{DestinationEntriesKey}";

            return(ScriptCommands.Assign(sourceEntriesKey, sourceEntryPaths, false,
                                         ScriptCommands.Assign(destinationEntriesKey, destinationEntryPaths, false,
                                                               NotifyEntryChangedProfile(changeType, sourceProfile, sourceEntriesKey,
                                                                                         destinationProfile, destinationEntriesKey, nextCommand))));
        }
Exemplo n.º 15
0
 public override IScriptCommand Execute(ParameterDic pm)
 {
     return(ScriptCommands.Assign(new Dictionary <string, object>()
     {
         { "{ColumnList}", IOInitializeHelpers.FileList_ColumList_For_DiskBased_Items },
         { "{ColumnFilters}", IOInitializeHelpers.FileList_ColumnFilter_For_DiskBased_Items },
         { "{FileListOpenCommand}", IOInitializeHelpers.FileList_Open_For_DiskBased_Items },
         { "{FileListDeleteCommand}", IOInitializeHelpers.FileList_Delete },
         { "{FileListNewFolderCommand}", IOInitializeHelpers.FileList_NewFolder },
         { "{FileListCutCommand}", IOInitializeHelpers.FileList_Cut_For_DiskBased_Items },
         { "{FileListCopyCommand}", IOInitializeHelpers.FileList_Copy_For_DiskBased_Items },
         { "{FileListPasteCommand}", IOInitializeHelpers.FileList_Paste_For_DiskBased_Items },
         { "{FileListNewWindowCommand}", IOInitializeHelpers.FileList_NewWindow },
         { "{DirectoryTreeMapCommand}", IOInitializeHelpers.DirectoryTree_Map_From_Profiles },
         { "{DirectoryTreeUnmapCommand}", IOInitializeHelpers.DirectoryTree_Unmap },
         { "{DirectoryTreeNewWindowCommand}", IOInitializeHelpers.DirectoryTree_NewWindow },
     }, true,
                                  ScriptCommands.RunSequence(NextCommand,
                                                             UIScriptCommands.ExplorerAssignScriptParameters(ExplorerKey, "{Profiles}"),
                                                             UIScriptCommands.ExplorerSetParameter(ExplorerKey, ExplorerParameterType.RootModels, "{RootDirectories}"),
                                                             UIScriptCommands.ExplorerSetParameter(ExplorerKey, ExplorerParameterType.FileName, "{FileName}"),
                                                             UIScriptCommands.ExplorerSetParameter(ExplorerKey, ExplorerParameterType.EnableContextMenu, "{EnableContextMenu}"),
                                                             UIScriptCommands.ExplorerSetParameter(ExplorerKey, ExplorerParameterType.EnableDrag, "{EnableDrag}"),
                                                             UIScriptCommands.ExplorerSetParameter(ExplorerKey, ExplorerParameterType.EnableDrop, "{EnableDrop}"),
                                                             UIScriptCommands.ExplorerSetParameter(ExplorerKey, ExplorerParameterType.EnableMultiSelect, "{EnableMultiSelect}"),
                                                             UIScriptCommands.ExplorerSetParameter(ExplorerKey, ExplorerParameterType.ColumnList, "{ColumnList}"),
                                                             UIScriptCommands.ExplorerSetParameter(ExplorerKey, ExplorerParameterType.ColumnFilters, "{ColumnFilters}"),
                                                             UIScriptCommands.ExplorerSetParameter(ExplorerKey, ExplorerParameterType.FilterString, "{FilterString}"),
                                                             UIScriptCommands.ExplorerSetParameter(ExplorerKey, ExplorerParameterType.ViewMode, "{ViewMode}"),
                                                             UIScriptCommands.ExplorerSetParameter(ExplorerKey, ExplorerParameterType.ItemSize, "{ItemSize}"),
                                                             UIScriptCommands.ExplorerSetParameter(ExplorerKey, ExplorerParameterType.ShowToolbar, "{ShowToolbar}"),
                                                             UIScriptCommands.ExplorerSetParameter(ExplorerKey, ExplorerParameterType.ShowSidebar, "{ShowSidebar}"),
                                                             UIScriptCommands.ExplorerSetParameter(ExplorerKey, ExplorerParameterType.ShowGridHeader, "{ShowGridHeader}"),
                                                             UIScriptCommands.ExplorerSetParameter(ExplorerKey, ExplorerParameterType.ExplorerWidth, "{ExplorerWidth}"),
                                                             UIScriptCommands.ExplorerSetParameter(ExplorerKey, ExplorerParameterType.ExplorerHeight, "{ExplorerHeight}"),
                                                             UIScriptCommands.ExplorerSetParameter(ExplorerKey, ExplorerParameterType.ExplorerPosition, "{ExplorerPosition}"),
                                                             UIScriptCommands.ExplorerSetParameter(ExplorerKey, ExplorerParameterType.EnableBookmark, "{EnableBookmark}"),
                                                             UIScriptCommands.SetScriptCommand(FileListKey, "Open", "{FileListOpenCommand}"),
                                                             UIScriptCommands.SetScriptCommand(FileListKey, "Delete", "{FileListDeleteCommand}"),
                                                             UIScriptCommands.SetScriptCommand(FileListKey, "NewFolder", "{FileListNewFolderCommand}"),
                                                             UIScriptCommands.SetScriptCommand(FileListKey, "OpenTab", "{FileListOpenTabCommand}"),
                                                             UIScriptCommands.SetScriptCommand(FileListKey, "Cut", "{FileListCutCommand}"),
                                                             UIScriptCommands.SetScriptCommand(FileListKey, "Copy", "{FileListCopyCommand}"),
                                                             UIScriptCommands.SetScriptCommand(FileListKey, "Paste", "{FileListPasteCommand}"),
                                                             UIScriptCommands.SetScriptCommand(FileListKey, "NewWindow", "{FileListNewWindowCommand}"),
                                                             UIScriptCommands.SetScriptCommand(DirectoryTreeKey, "OpenTab", "{DirectoryTreeOpenTabCommand}"),
                                                             UIScriptCommands.SetScriptCommand(DirectoryTreeKey, "NewWindow", "{DirectoryTreeNewWindowCommand}"),
                                                             UIScriptCommands.SetScriptCommand(DirectoryTreeKey, "Map", "{DirectoryTreeMapCommand}"),
                                                             UIScriptCommands.SetScriptCommand(DirectoryTreeKey, "Unmap", "{DirectoryTreeUnmapCommand}")
                                                             )
                                  ));
 }
Exemplo n.º 16
0
        public override IScriptCommand Execute(ParameterDic pm)
        {
            IScriptCommand command = pm.GetValue <IScriptCommand>(CommandKey);

            if (command == null && ThrowIfError)
            {
                return(ResultCommand.Error(new ArgumentNullException(CommandKey)));
            }
            command = command ?? ResultCommand.NoError;

            logger.Info("Running " + CommandKey);
            return(ScriptCommands.RunQueue(NextCommand, command));
        }
Exemplo n.º 17
0
 public static IScriptCommand ExplorerNewWindow(IProfile[] profiles, IEntryModel[] rootDirectories,
                                                string explorerVariable = "{Explorer}", IScriptCommand nextCommand = null)
 {
     return(ScriptCommands.Assign(new Dictionary <string, object>()
     {
         { "{Profiles}", profiles },
         { "{RootDirectories}", rootDirectories },
         { "{OnModelCreated}", IOInitializeHelpers.Explorer_Initialize_Default },
         { "{OnViewAttached}", UIScriptCommands.ExplorerGotoStartupPathOrFirstRoot() }
     }, false,
                                  UIScriptCommands.ExplorerNewWindow("{OnModelCreated}", "{OnViewAttached}", "{WindowManager}",
                                                                     "{GlobalEvents}", explorerVariable, nextCommand)));
 }
Exemplo n.º 18
0
        /// <summary>
        /// Serializable, If {StartupPath} is defined, goto the path, otherwise go to first root directory and expand it.
        /// Used to initialize Explorer onViewAttached.
        /// </summary>
        /// <param name="explorerVariable"></param>
        /// <param name="profilesVariable"></param>
        /// <param name="rootDirectoriesVariable"></param>
        /// <param name="startupPathVariable"></param>
        /// <param name="nextCommand"></param>
        /// <returns></returns>
        public static IScriptCommand ExplorerGotoStartupPathOrFirstRoot(string explorerVariable        = "{Explorer}",
                                                                        string profilesVariable        = "{Profiles}",
                                                                        string rootDirectoriesVariable = "{RootDirectories}",
                                                                        string startupPathVariable     = "{StartupPath}", IScriptCommand nextCommand = null)
        {
            string firstRootDirectoriesVariable = ParameterDic.CombineVariable(rootDirectoriesVariable, "[0]");

            return
                (ScriptCommands.RunSequence(nextCommand,
                                            ScriptCommands.IfAssignedAndNotEmptyString(startupPathVariable,
                                                                                       UIScriptCommands.ExplorerParseAndGoTo(explorerVariable, profilesVariable, startupPathVariable),
                                                                                       UIScriptCommands.ExplorerGoTo(explorerVariable, firstRootDirectoriesVariable,
                                                                                                                     UIScriptCommands.DirectoryTreeToggleExpand(firstRootDirectoriesVariable)))));
        }
Exemplo n.º 19
0
        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));
        }
Exemplo n.º 20
0
        /// <summary>
        /// Serializable, Create a new directory or file picker explorer window (IExplorerViewModel), and show it.
        /// </summary>
        /// <param name="mode"></param>
        /// <param name="onModelCreatedVariable"></param>
        /// <param name="onViewAttachedVariable"></param>
        /// <param name="windowManagerVariable"></param>
        /// <param name="eventAggregatorVariable"></param>
        /// <param name="selectionVariable"></param>
        /// <param name="selectionPathsVariable"></param>
        /// <param name="nextCommand"></param>
        /// <param name="cancelCommand"></param>
        /// <returns></returns>
        public static IScriptCommand ExplorerPick(ExplorerMode mode             = ExplorerMode.FileSave, string onModelCreatedVariable = "{OnModelCreated}", string onViewAttachedVariable = "{OnViewAttached}",
                                                  string windowManagerVariable  = "{WindowManager}", string eventAggregatorVariable    = "{GlobalEvents}",
                                                  string selectionVariable      = null,
                                                  string selectionPathsVariable = "{SelectionPaths}",
                                                  IScriptCommand nextCommand    = null, IScriptCommand cancelCommand = null)
        {
            string dialogResultVariable = "{ExplorerPick-DialogResult}";
            string explorerVariable     = "{ExplorerPick-Explorer}";

            return(ExplorerCreate(mode, onModelCreatedVariable, onViewAttachedVariable,
                                  windowManagerVariable, eventAggregatorVariable, explorerVariable,
                                  UIScriptCommands.explorerShow(windowManagerVariable, explorerVariable, dialogResultVariable, selectionVariable,
                                                                selectionPathsVariable,
                                                                ScriptCommands.IfTrue(dialogResultVariable, nextCommand, cancelCommand))));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Serializable, do switch...case code by using multiple IfValue.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="variable"></param>
        /// <param name="caseLookup"></param>
        /// <param name="otherwiseCommand"></param>
        /// <returns></returns>
        public static IScriptCommand Switch <T>(string variable = "{variable}",
                                                Dictionary <T, IScriptCommand> caseLookup = null,
                                                IScriptCommand otherwiseCommand           = null, IScriptCommand nextCommnad = null)
        {
            IScriptCommand cmd = null;

            foreach (var key in caseLookup.Keys)
            {
                cmd =
                    cmd == null?IfEquals <T>(variable, key, caseLookup[key], otherwiseCommand) :
                        IfEquals <T>(variable, key, caseLookup[key], cmd);
            }

            return(ScriptCommands.RunSequence(nextCommnad, cmd));
        }
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            var flValue             = pm.GetValue(FileListKey);
            IFileListViewModel flvm = flValue is IExplorerViewModel ?
                                      (flValue as IExplorerViewModel).FileList :
                                      flValue as IFileListViewModel;

            if (flvm == null)
            {
                return(ResultCommand.Error(new KeyNotFoundException(FileListKey)));
            }

            return(ScriptCommands.Assign(DestinationKey,
                                         flvm.Selection.SelectedItems.Select(evm => evm.EntryModel).ToArray(), false, NextCommand));
        }
Exemplo n.º 23
0
 public static IScriptCommand DirectoryPick(IProfile[] profiles, IEntryModel[] rootDirectories,
                                            string selectionVariable   = "{Selection}", string selectionPathVariable = "{SelectionPaths}",
                                            IScriptCommand nextCommand = null, IScriptCommand cancelCommand          = null)
 {
     return(ScriptCommands.Assign(new Dictionary <string, object>()
     {
         { "{Profiles}", profiles },
         { "{RootDirectories}", rootDirectories },
         { "{EnableDrag}", false },
         { "{EnableDrop}", false },
         { "{EnableMultiSelect}", false },
         { "{FileListNewWindowCommand}", NullScriptCommand.Instance },
         { "{OnModelCreated}", IOInitializeHelpers.Explorer_Initialize_Default },
         { "{OnViewAttached}", UIScriptCommands.ExplorerGotoStartupPathOrFirstRoot() }
     }, false,
                                  UIScriptCommands.ExplorerPick(ExplorerMode.DirectoryOpen, "{OnModelCreated}", "{OnViewAttached}", "{WindowManager}",
                                                                "{GlobalEvents}", selectionVariable, selectionPathVariable, nextCommand, cancelCommand)));
 }
Exemplo n.º 24
0
 public static IScriptCommand FileSave(
     string filterString           = "All files (*.*)|*.*",
     string selectionPathsVariable = "{Selection}",
     IScriptCommand nextCommand    = null, IScriptCommand cancelCommand = null)
 {
     return(ScriptCommands.Assign(new Dictionary <string, object>()
     {
         { "{EnableDrag}", false },
         { "{EnableDrop}", false },
         { "{FilterString}", filterString },
         { "{EnableMultiSelect}", false },
         { "{FileListNewWindowCommand}", NullScriptCommand.Instance },
         { "{OnModelCreated}", IOInitializeHelpers.Explorer_Initialize_Default },
         { "{OnViewAttached}", UIScriptCommands.ExplorerGotoStartupPathOrFirstRoot() }
     }, false,
                                  UIScriptCommands.ExplorerPick(ExplorerMode.FileSave, "{OnModelCreated}", "{OnViewAttached}", "{WindowManager}",
                                                                "{GlobalEvents}", null, selectionPathsVariable, nextCommand, cancelCommand)));
 }
Exemplo n.º 25
0
        /// <summary>
        /// Serializable, shortcut method for [AssignValueConverter], which obtains method result of a property from a variable and assign to another variable.
        /// </summary>
        /// <param name="sourceObjectVariable"></param>
        /// <param name="methodName"></param>
        /// <param name="parameters"></param>
        /// <param name="destinationVariable"></param>
        /// <param name="nextCommand"></param>
        /// <returns></returns>
        public static IScriptCommand ExecuteFunc(string sourceObjectVariable = "{Source}",
                                                 string methodName           = "Method", object[] parameters = null,
                                                 string destinationVariable  = "{Destination}", IScriptCommand nextCommand = null)
        {
            string valueConverterVariable = ParameterDic.CombineVariable(sourceObjectVariable, "Converter");

            List <object> methodParams = new List <object>();

            methodParams.Add(methodName);
            if (parameters != null)
            {
                methodParams.AddRange(parameters);
            }

            return(AssignValueConverter(ValueConverterType.ExecuteMethod, valueConverterVariable,
                                        ScriptCommands.Reassign(sourceObjectVariable, valueConverterVariable,
                                                                destinationVariable, false, nextCommand), methodParams.ToArray()));
        }
Exemplo n.º 26
0
 private async Task <IScriptCommand> GetAssignDestinationCommandAsync(ParameterDic pm, IEntryModel[] srcEntries,
                                                                      IEntryModel destEntry, string destinationKey, IScriptCommand nextCommand)
 {
     if (DestinationKey != null)
     {
         string[]      srcEntryNames      = srcEntries.Select(e => e.Name).ToArray();
         IEntryModel[] destinationEntries = (await destEntry.Profile.ListAsync(destEntry, pm.CancellationToken,
                                                                               e => srcEntryNames.Contains(e.Name, StringComparer.CurrentCultureIgnoreCase), true)).ToArray();
         if (destinationEntries.Length != srcEntries.Length)
         {
             logger.Warn(String.Format("Transfer count different : sorce = {0}, actual = {1}", srcEntries.Length, destinationEntries.Length));
         }
         return(ScriptCommands.Assign(DestinationKey, destinationEntries, false, nextCommand));
     }
     else
     {
         return(nextCommand);
     }
 }
Exemplo n.º 27
0
        public override IScriptCommand Execute(ParameterDic pm)
        {
            object value = Value;

            if (ValueFunc != null)
            {
                value = ValueFunc();
            }

            if (!(value is string))
            {
                value = value.ToString();
            }
            else
            {
                value = pm.ReplaceVariableInsideBracketed((string)value);
            }

            return(ScriptCommands.Assign(VariableKey, value, SkipIfExists, NextCommand));
        }
Exemplo n.º 28
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            switch (Mode)
            {
            case RunMode.Parallel:
                await Task.WhenAll(ScriptCommands.Select(cmd => ScriptRunner.RunScriptAsync(pm.Clone(), cmd)));

                break;

            case RunMode.Queue:
                await ScriptRunner.RunScriptAsync(pm, ScriptCommands)
                .ConfigureAwait(this.ContinueOnCaptureContext);

                break;

            case RunMode.Sequence:
                foreach (var cmd in ScriptCommands)
                {
                    await ScriptRunner.RunScriptAsync(pm, cmd)
                    .ConfigureAwait(this.ContinueOnCaptureContext);

                    if (pm.Error != null)
                    {
                        return(ResultCommand.Error(pm.Error));
                    }
                }
                break;

            default:
                return(ResultCommand.Error(new NotSupportedException(Mode.ToString())));
            }

            if (pm.Error != null)
            {
                return(ResultCommand.Error(pm.Error));
            }
            else
            {
                return(NextCommand);
            }
        }
Exemplo n.º 29
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            switch (Operation)
            {
            case ClipboardOperation.Copy:
            case ClipboardOperation.Cut:
                var _srcModels = await pm.GetValueAsEntryModelArrayAsync(EntriesKey);

                var          da         = _srcModels.First().Profile.DragDrop.GetDataObject(_srcModels);
                byte[]       moveEffect = Operation == ClipboardOperation.Cut ? preferCut : preferCopy;
                MemoryStream dropEffect = new MemoryStream();
                dropEffect.Write(moveEffect, 0, moveEffect.Length);
                da.SetData("Preferred DropEffect", dropEffect);

                Clipboard.Clear();
                Clipboard.SetDataObject(da, true);
                break;

            case ClipboardOperation.Paste:
                var currentDirectory = await pm.GetValueAsEntryModelAsync(CurrentDirectoryEntryKey);

                if (currentDirectory != null)
                {
                    IDataObject da1 = Clipboard.GetDataObject();
                    if (da1 != null)
                    {
                        IEntryModel[] srcModels      = currentDirectory.Profile.DragDrop.GetEntryModels(da1).ToArray();
                        string        sourceModelKey = "{Clipboard-SourceModels}";
                        return(ScriptCommands.Assign(sourceModelKey, srcModels, false,
                                                     IOScriptCommands.DiskTransfer(sourceModelKey, CurrentDirectoryEntryKey, DestinationKey, false, true, NextCommand)));
                    }
                }
                break;
            }

            return(NextCommand);
        }
Exemplo n.º 30
0
 /// <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}"))))));
 }