Exemplo n.º 1
0
        private FrameworkElement findLogicalAncestor(ParameterDic pm, FrameworkElement sender)
        {
            switch (FindMethod)
            {
            case UIEventHub.FindMethodType.Name:
                string name = pm.ReplaceVariableInsideBracketed(FindParameterKey) ?? "";
                return(UITools.FindLogicalAncestor <FrameworkElement>(sender, ele => name.Equals(ele.Name)));

            case UIEventHub.FindMethodType.Type:
                string type = pm.ReplaceVariableInsideBracketed(FindParameterKey) ?? "";
                return(UITools.FindLogicalAncestor <FrameworkElement>(sender, ele => ele.GetType().Name.Equals(type, StringComparison.CurrentCultureIgnoreCase)));

            case UIEventHub.FindMethodType.Level:
                int level = pm.GetValue <int>(FindParameterKey, -1);
                if (level == -1)
                {
                    return(null);
                }
                FrameworkElement current = sender;
                for (int i = 0; i < level; i++)
                {
                    if (current != null)
                    {
                        current = LogicalTreeHelper.GetParent(current) as FrameworkElement;
                    }
                }
                return(current);

            default: throw new NotSupportedException(FindMethod.ToString());
            }
        }
Exemplo n.º 2
0
        public override IScriptCommand Execute(ParameterDic pm)
        {
            System.Diagnostics.Process          process   = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.WindowStyle = WindowStyle;
            startInfo.FileName    = pm.ReplaceVariableInsideBracketed(ExecutableKey);

            string workingDirectory = pm.ReplaceVariableInsideBracketed(WorkingDirectoryKey);

            if (!String.IsNullOrEmpty(workingDirectory))
            {
                startInfo.WorkingDirectory = workingDirectory;
            }
            startInfo.Arguments = pm.ReplaceVariableInsideBracketed(ArgumentKey);

            process.StartInfo = startInfo;

            if (ResultCodeKey != null)
            {
                process.WaitForExit();
            }
            process.Start();

            if (ResultCodeKey != null)
            {
                pm.SetValue(ResultCodeKey, process.ExitCode);
            }

            return(NextCommand);
        }
Exemplo n.º 3
0
        private FrameworkElement findLogicalChild(ParameterDic pm, FrameworkElement sender)
        {
            switch (FindMethod)
            {
            case UIEventHub.FindMethodType.Name:
                string name = pm.ReplaceVariableInsideBracketed(FindParameterKey) ?? "";
                return(UITools.FindLogicalChild <FrameworkElement>(sender, ele => name.Equals(ele.Name)));

            case UIEventHub.FindMethodType.Type:
                string type = pm.ReplaceVariableInsideBracketed(FindParameterKey) ?? "";
                return(UITools.FindLogicalChild <FrameworkElement>(sender, ele => ele.GetType().Name.Equals(type, StringComparison.CurrentCultureIgnoreCase)));

            default: throw new NotSupportedException(FindMethod.ToString());
            }
        }
Exemplo n.º 4
0
        public override IScriptCommand Execute(ParameterDic pm)
        {
            string variable = pm.ReplaceVariableInsideBracketed(VariableKey);

            print(variable);
            return(NextCommand);
        }
Exemplo n.º 5
0
        public override IScriptCommand Execute(ParameterDic pm)
        {
            string path = pm.ReplaceVariableInsideBracketed(PathKey);
            string ext  = (path.Contains(".") ? PathFE.GetExtension(path) : path).TrimStart('.');

            pm.SetValue(DestinationKey, SevenZipWrapper.GetArchiveBytes(ext));
            return(NextCommand);
        }
Exemplo n.º 6
0
        public override IScriptCommand Execute(ParameterDic pm)
        {
            MessageBoxButton buttons;

            if (!Enum.TryParse <MessageBoxButton>(Buttons, out buttons))
            {
                buttons = MessageBoxButton.OK;
            }

            logger.Debug(String.Format("Showing {0} {1} {2}", buttons, CaptionKey, ContentKey));
            string content = pm.ReplaceVariableInsideBracketed(ContentKey);
            string caption = pm.ReplaceVariableInsideBracketed(CaptionKey);

            var result = MessageBox.Show(content, caption, buttons);

            pm.SetValue(DestinationKey, result.ToString());

            return(NextCommand);
        }
Exemplo n.º 7
0
        public override IScriptCommand Execute(ParameterDic pm)
        {
            string path = pm.ReplaceVariableInsideBracketed(PathKey);

            switch (FilePartType)
            {
            case Script.FilePartType.FileName: pm.SetValue(DestinationKey, PathFE.GetFileName(path)); break;

            case Script.FilePartType.DirectoryName: pm.SetValue(DestinationKey, PathFE.GetDirectoryName(path)); break;

            default: throw new NotSupportedException("FilePartType=" + FilePartType.ToString());
            }

            return(NextCommand);
        }
Exemplo n.º 8
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.º 9
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            string path = pm.ReplaceVariableInsideBracketed(PathKey);

            if (path == null)
            {
                return(ResultCommand.Error(new ArgumentException("Path not specified.")));
            }

            IDiskProfile profile = pm.GetValue <IDiskProfile>(ProfileKey);

            if (profile == null)
            {
                return(ResultCommand.Error(new ArgumentException(ProfileKey + " is not assigned or not IDiskProfile.")));
            }

            string             parentPath     = profile.Path.GetDirectoryName(path);
            IFileNameGenerator fNameGenerator = FileNameGenerator.FromNameGenerationMode(NameGenerationMode,
                                                                                         profile.Path.GetFileName(path));

            string fileName = fNameGenerator.Generate();

            while (fileName != null &&
                   await profile.ParseAsync(profile.Path.Combine(parentPath, fileName)) != null)
            {
                fileName = fNameGenerator.Generate();
            }

            if (fileName == null)
            {
                return(ResultCommand.Error(new ArgumentException("Already exists.")));
            }

            string newEntryPath  = profile.Path.Combine(parentPath, fileName);
            var    createddModel = await profile.DiskIO.CreateAsync(newEntryPath, IsFolder, pm.CancellationToken);

            logger.Info(String.Format("{0} = {1} ({2})", DestinationKey, createddModel.FullPath, IsFolder ? "Folder" : "File"));
            pm.SetValue(DestinationKey, createddModel);

            return(CoreScriptCommands.NotifyEntryChanged(ChangeType.Created, null, DestinationKey, NextCommand));
        }
Exemplo n.º 10
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            IEntryModel[] entryModel;
            try
            {
                entryModel = await pm.GetValueAsEntryModelArrayAsync(EntryKey);
            }
            catch
            {
                return(ResultCommand.Error(new ArgumentException(EntryKey + " is not found or not a directory IEntryModel or IEntryModel[]")));
            }
            string masks  = pm.ReplaceVariableInsideBracketed(MaskKey);
            var    filter = createFilter(ListOptions, masks);


            IEntryModel[] listItems = (await EntryUtils.ListAsync(entryModel, pm.CancellationToken, filter, false)).ToArray();

            logger.Debug(String.Format("{0} = IEntryModel[{1}]", DestinationKey, listItems.Length));
            pm.SetValue(DestinationKey, listItems);

            return(NextCommand);
        }
Exemplo n.º 11
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            string path = pm.ReplaceVariableInsideBracketed(PathKey);

            IProfile profile = pm.GetValue <IProfile>(ProfileKey, null);

            IProfile[] profiles = profile != null ? new IProfile[] { profile } :
            pm.GetValue <IProfile[]>(ProfileKey, null);
            if (profiles == null)
            {
                return(ResultCommand.Error(new ArgumentException("Profile/s not specified.")));
            }

            pm.SetValue <IEntryModel>(DestinationKey, null);
            foreach (var p in profiles)
            {
                if (p.MatchPathPattern(path))
                {
                    var retVal = await p.ParseAsync(path);

                    if (retVal != null)
                    {
                        logger.Debug(String.Format("{0} = {1}", DestinationKey, retVal));
                        pm.SetValue <IEntryModel>(DestinationKey, retVal);
                        break;
                    }
                }
            }

            if (pm.GetValue(DestinationKey) == null)
            {
                logger.Warn(String.Format("{0} = null", path));
                return(NotFoundCommand ?? ResultCommand.Error(new FileNotFoundException(path + " is not found.")));
            }

            return(NextCommand);
        }
Exemplo n.º 12
0
        private async Task <IScriptCommand> setParameterAsync(ParameterDic pm, IExplorerViewModel evm)
        {
            object value = ValueKey is string && (ValueKey as string).StartsWith("{") ? pm.GetValue <object>(ValueKey as string) : ValueKey;

            switch (ParameterType)
            {
            case ExplorerParameterType.EnableContextMenu:
                if (value is bool)
                {
                    evm.FileList.EnableContextMenu = evm.DirectoryTree.EnableContextMenu = true.Equals(value);
                }
                break;

            case ExplorerParameterType.EnableDrag:
                if (value is bool)
                {
                    evm.FileList.EnableDrag = evm.DirectoryTree.EnableDrag = true.Equals(value);
                }
                break;

            case ExplorerParameterType.EnableDrop:
                if (value is bool)
                {
                    evm.FileList.EnableDrop = evm.DirectoryTree.EnableDrop = true.Equals(value);
                }
                break;

            case ExplorerParameterType.EnableMultiSelect:
                if (value is bool)
                {
                    evm.FileList.EnableMultiSelect = true.Equals(value);
                }
                break;

            case ExplorerParameterType.ExplorerWidth:
                if (value is int)
                {
                    evm.Parameters.Width = (int)value;
                }
                break;

            case ExplorerParameterType.ExplorerHeight:
                if (value is int)
                {
                    evm.Parameters.Height = (int)value;
                }
                break;

            case ExplorerParameterType.ExplorerPosition:
                if (value is Point)
                {
                    evm.Parameters.Position = (Point)value;
                }
                break;

            case ExplorerParameterType.RootModels:
                if (ValueKey == null)
                {
                    return(ResultCommand.Error(new ArgumentNullException("ValueKey")));
                }

                IEntryModel[] rootModels = ValueKey is string?
                                           await pm.GetValueAsEntryModelArrayAsync(ValueKey as string, null) :
                                               ValueKey as IEntryModel[];

                if (rootModels == null)
                {
                    return(ResultCommand.Error(new KeyNotFoundException(ValueKey.ToString())));
                }
                evm.RootModels = rootModels;

                break;

            case ExplorerParameterType.FileName:
                if (evm is FilePickerViewModel)
                {
                    (evm as FilePickerViewModel).FileName = value as string;
                }
                break;

            case ExplorerParameterType.FilePickerMode:
                var            mode = pm.GetValue(ValueKey as string);
                FilePickerMode pickerMode;
                if (mode is FilePickerMode)
                {
                    pickerMode = (FilePickerMode)mode;
                }
                else if (mode is string)
                {
                    Enum.TryParse <FilePickerMode>(mode as string, out pickerMode);
                }
                else
                {
                    break;
                }
                if (evm is FilePickerViewModel)
                {
                    (evm as FilePickerViewModel).PickerMode = pickerMode;
                }
                break;

            case ExplorerParameterType.FilterString:
                string filterStr = pm.ReplaceVariableInsideBracketed(ValueKey as string);
                if (filterStr != null)
                {
                    evm.FilterStr = filterStr;
                }
                break;

            case ExplorerParameterType.ColumnList:
                ColumnInfo[] columnInfo = pm.GetValue <ColumnInfo[]>(ValueKey as string);
                if (columnInfo != null)
                {
                    evm.FileList.Columns.ColumnList = columnInfo;
                }
                break;

            case ExplorerParameterType.ColumnFilters:
                ColumnFilter[] columnfilters = pm.GetValue <ColumnFilter[]>(ValueKey as string);
                if (columnfilters != null)
                {
                    evm.FileList.Columns.ColumnFilters = columnfilters;
                }
                break;

            case ExplorerParameterType.ViewMode:
                if (value is string)
                {
                    evm.FileList.Parameters.ViewMode = value as string;
                }
                break;

            case ExplorerParameterType.ItemSize:

                if (value is int)
                {
                    evm.FileList.Parameters.ItemSize = (int)value;
                }
                break;

            case ExplorerParameterType.ShowToolbar:
                if (value is bool)
                {
                    evm.FileList.ShowToolbar = true.Equals(value);
                }
                break;

            case ExplorerParameterType.ShowSidebar:
                if (value is bool)
                {
                    evm.FileList.ShowSidebar = true.Equals(value);
                }
                break;

            case ExplorerParameterType.ShowGridHeader:
                if (value is bool)
                {
                    evm.FileList.ShowGridHeader = true.Equals(value);
                }
                break;

            case ExplorerParameterType.EnableBookmark:
                if (value is bool)
                {
                    evm.Breadcrumb.EnableBookmark = true.Equals(value);
                }
                break;

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

            logger.Debug(String.Format("Set {0} to {1} ({2})", ParameterType, ValueKey, value));

            return(NextCommand);
        }
Exemplo n.º 13
0
        public override bool CanExecute(ParameterDic pm)
        {
            string path = pm.ReplaceVariableInsideBracketed(PathKey);

            return(!String.IsNullOrEmpty(path) && !path.StartsWith("::{")); //Cannot execute if GuidPath
        }