Ejemplo n.º 1
0
        protected override IScriptCommand executeInner(ParameterDic pm, ItemsControl ic, RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs)
        {
            if (!_update)
            {
                var selectedIdList = pm.ContainsKey("SelectedIdList") ? pm["SelectedIdList"] as List <int>
                    : new List <int>();

                logger.Debug(String.Format("Highlighting {0} items", selectedIdList.Count()));

                for (int i = 0; i < ic.Items.Count; i++)
                {
                    DependencyObject item = ic.ItemContainerGenerator.ContainerFromIndex(i);
                    if (item != null)
                    {
                        bool isSelecting = selectedIdList.Contains(i);
                        //UIEventHubProperties.SetIsSelecting(item, isSelecting);
                        var selectable = (item as FrameworkElement).DataContext as ISelectable;
                        if (selectable != null)
                        {
                            selectable.IsSelecting = isSelecting;
                        }
                    }
                }
            }
            else
            {
                List <object> unselectedList   = pm["UnselectedList"] as List <object>;
                List <int>    unselectedIdList = pm["UnselectedIdList"] as List <int>;

                List <object> selectedList   = pm["SelectedList"] as List <object>;
                List <int>    selectedIdList = pm["SelectedIdList"] as List <int>;

                logger.Debug(String.Format("Highlighting {0} items", selectedIdList.Count()));
                logger.Debug(String.Format("De-highlighting {0} items", unselectedIdList.Count()));

                for (int i = 0; i < ic.Items.Count; i++)
                {
                    DependencyObject ele  = ic.ItemContainerGenerator.ContainerFromIndex(i);
                    ISelectable      item = ic.Items[i] as ISelectable;


                    if (ele != null)
                    {
                        bool isSelecting = UIEventHubProperties.GetIsSelecting(ele);
                        if (isSelecting && unselectedList.Contains(ele))
                        {
                            item.IsSelecting = false;
                        }
                        //AttachedProperties.SetIsSelecting(item, false);
                        else if (!isSelecting && selectedList.Contains(ele))
                        {
                            item.IsSelecting = true;
                        }
                        //AttachedProperties.SetIsSelecting(ele, true);
                    }
                }
            }

            return(NextCommand);
        }
Ejemplo n.º 2
0
        public override IScriptCommand Execute(ParameterDic pm)
        {
            IProfile[] rootProfiles = pm.GetValue <IProfile[]>(ProfilesKey);
            if (rootProfiles == null || rootProfiles.Length == 0)
            {
                return(ResultCommand.Error(new ArgumentException(ProfilesKey)));
            }

            if (rootProfiles.Length == 1)
            {
                pm.SetValue(DestinationKey, rootProfiles[0]);
                return(NextCommand);
            }
            else
            {
                IWindowManager wm = pm.GetValue <IWindowManager>(WindowManagerKey) ?? new WindowManager();
                logger.Debug("Showing");
                SelectProfileViewModel spvm = new SelectProfileViewModel(rootProfiles);
                if (wm.ShowDialog(spvm).Value)
                {
                    logger.Info(String.Format("Selected {0}", spvm.SelectedRootProfile));
                    pm.SetValue(DestinationKey, spvm.SelectedRootProfile);
                    return(NextCommand);
                }
                else
                {
                    logger.Debug("Cancelled");
                    return(CancelCommand);
                }
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public override IScriptCommand Execute(ParameterDic pm)
        {
            object value = Value;

            if (ValueFunc != null)
            {
                value = ValueFunc();
            }
            if (value is string)
            {
                string valueString = (string)value;
                if (valueString.StartsWith("{") && valueString.EndsWith("}"))
                {
                    value = pm.GetValue(valueString);
                }
            }

            if (pm.SetValue <Object>(VariableKey, value, SkipIfExists))
            {
                logger.Debug(String.Format("{0} = {1}", VariableKey, value));
            }
            // else logger.Debug(String.Format("Skipped {0}, already exists.", VariableKey));

            return(NextCommand);
        }
Ejemplo n.º 5
0
 public static T RunScript <T>(string resultVariable = "{Result}", ParameterDic initialParameters = null,
                               params IScriptCommand[] commands)
 {
     initialParameters = initialParameters ?? new ParameterDic();
     RunScript(initialParameters, false, commands);
     return(initialParameters.GetValue(resultVariable, default(T)));
 }
Ejemplo n.º 6
0
        public static async Task Test_CopyStream()
        {
            //Prepare
            MemoryStream msSource = new MemoryStream();
            StreamWriter swSource = new StreamWriter(msSource);

            swSource.Write(dummyPath);
            swSource.Flush();
            msSource.Seek(0, SeekOrigin.Begin);
            MemoryStream msDest = new MemoryStream();
            StreamReader reader = new StreamReader(msDest);

            CopyStream   copyStream = new CopyStream();
            ParameterDic pd         = new ParameterDic()
            {
                { copyStream.SourceKey, msSource },
                { copyStream.DestinationKey, msDest }
            };

            //Action
            IScriptCommand retCmd = await copyStream.ExecuteAsync(pd);

            msDest.Seek(0, SeekOrigin.Begin);
            string read = reader.ReadToEnd();

            //Assert
            Assert.AreEqual(dummyPath, read);
        }
Ejemplo n.º 7
0
        private bool dragStart(ParameterDic pm, IUIInput input, string mode)
        {
            ISupportDrag isd = pm.GetValue <ISupportDrag>(DragSourceKey);

            if (pm.GetValue <string>(DragDropModeKey) == null && isd != null)
            {
                var         draggables = isd.GetDraggables();
                IDataObject dataObj    = isd is ISupportShellDrag ?
                                         (isd as ISupportShellDrag).GetDataObject(draggables) : null;
                DragDropEffectsEx effect = isd.QueryDrag(draggables);

                pm.SetValue(DragDropModeKey, mode);
                pm.SetValue(DragDropDeviceKey, input.InputType);
                pm.SetValue(DragDropDraggingItemsKey, draggables);
                pm.SetValue(DragDropEffectsKey, effect);
                pm.SetValue(DragDropDragSourceKey, isd);
                pm.SetValue(ParameterDic.CombineVariable(DragDropDragSourceKey, ".IsDraggingFrom", false), true);
                pm.SetValue(DragDropStartPositionKey, pm.GetValue <Point>(CurrentPositionAdjustedKey));
                pm.SetValue(InputKey, new DragInput(input, dataObj, DragDropEffectsEx.Copy, (eff) => { }));

                return(true);
            }

            return(false);
        }
Ejemplo n.º 8
0
        public override IScriptCommand Execute(ParameterDic pm)
        {
            KeyEventArgs keyEvent = pm.GetValue <KeyEventArgs>(RoutedEventArgsKey);

            if (keyEvent == null)
            {
                return(OtherwiseCommand);
            }

            object     keygestureObject = !KeyGestureKey.StartsWith("{") ? KeyGestureKey : pm.GetValue(KeyGestureKey);
            KeyGesture gesture          = null;

            if (keygestureObject is KeyGesture)
            {
                gesture = (KeyGesture)keygestureObject;
            }

            if (keygestureObject is string)
            {
                gesture = (KeyGesture)converter.ConvertFrom(keygestureObject);
            }


            return(gesture != null &&
                   keyEvent.Key == gesture.Key &&
                   keyEvent.KeyboardDevice.Modifiers == gesture.Modifiers ?
                   NextCommand : OtherwiseCommand);
        }
        public override IScriptCommand Execute(ParameterDic pm)
        {
            if (SkipIfExists && pm.HasValue(DestinationKey))
            {
                return(NextCommand);
            }

            IEnumerable <IDraggable> value = new List <IDraggable>();

            ISupportShellDrop issd    = pm.GetValue <ISupportShellDrop>(ISupportDropKey);
            IDataObject       dataObj = pm.GetValue <IDataObject>(DataObjectKey);

            if (dataObj.GetDataPresent(typeof(ISupportDrag)))
            {
                ISupportDrag isd = (ISupportDrag)dataObj.GetData(typeof(ISupportDrag));
                value = isd.GetDraggables();
            }
            else
            if (issd != null && dataObj != null)
            {
                value = (issd.QueryDropDraggables(dataObj) ?? new List <IDraggable>());
            }

            pm.SetValue(DestinationKey, value, SkipIfExists);
            return(NextCommand);
        }
Ejemplo n.º 10
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            IEntryModel entryModel = pm.GetValue <IEntryModel>(EntryKey);

            if (entryModel == null)
            {
                return(ResultCommand.Error(new ArgumentException(EntryKey + " is not found or not IEntryModel")));
            }

            IDiskProfile profile = entryModel.Profile as IDiskProfile;

            if (profile == null)
            {
                return(ResultCommand.Error(new NotSupportedException(EntryKey + "'s Profile is not IDiskProfile")));
            }

            using (var stream = await profile.DiskIO.OpenStreamAsync(entryModel, Access, pm.CancellationToken))
            {
                ParameterDic pmClone = pm.Clone();
                pmClone.SetValue(StreamKey, stream);
                logger.Debug(String.Format("{0} = Stream of {1}", StreamKey, EntryKey));
                await ScriptRunner.RunScriptAsync(pmClone, NextCommand);
            }

            if (Access == FileAccess.ReadWrite || Access == FileAccess.Write)
            {
                return(CoreScriptCommands.NotifyEntryChangedProfile(ChangeType.Changed, null, EntryKey, ThenCommand));
            }
            else
            {
                return(ThenCommand);
            }
        }
Ejemplo n.º 11
0
        protected override IScriptCommand executeInner(ParameterDic pm, ItemsControl ic, RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs)
        {
            var        scp    = ControlUtils.GetScrollContentPresenter(ic);
            IChildInfo icInfo = UITools.FindVisualChild <Panel>(scp) as IChildInfo;

            if (icInfo == null)
            {
                return(ResultCommand.Error(new NotSupportedException()));
            }

            Rect          selectionBound = pm.GetValue <Rect>(SelectionBoundAdjustedKey);
            List <object> selectedList   = new List <object>();
            List <int>    selectedIdList = new List <int>();

            for (int i = 0; i < ic.Items.Count; i++)
            {
                if (icInfo.GetChildRect(i).IntersectsWith(selectionBound))
                {
                    selectedList.Add(ic.Items[i]);
                    selectedIdList.Add(i);
                }
            }

            pm.SetValue(SelectedListKey, selectedList);
            pm.SetValue(SelectedIdListKey, selectedIdList);
            logger.Debug(String.Format("Selected = {0}", selectedIdList.Count()));

            return(NextCommand);
        }
Ejemplo n.º 12
0
        private void setVMProperty <T>(ExplorerParameterType property, T value)
        {
            ParameterDic pd = new ParameterDic();

            pd.SetValue("{PropertyValue}", value, false);
            _evm.Commands.Execute(UIScriptCommands.ExplorerSetParameter(property, "{PropertyValue}"), pd);
        }
Ejemplo n.º 13
0
        private T getVMProperty <T>(ExplorerParameterType property)
        {
            ParameterDic pd = new ParameterDic();

            _evm.Commands.Execute(UIScriptCommands.ExplorerGetParameter(property, "{OutputValue}"), pd);
            return(pd.GetValue <T>("{OutputValue}"));
        }
Ejemplo n.º 14
0
        protected override IScriptCommand executeInner(ParameterDic pm, UIElement sender, RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs)
        {
            Point position = input.Position;

            //Console.WriteLine(input.IsDragging.ToString() +  position.ToString());
            switch (PositionRelativeTo)
            {
            case PositionRelativeToType.Sender:
                position = input.PositionRelativeTo(sender);
                break;

            case PositionRelativeToType.Scp:
                var scp = ControlUtils.GetScrollContentPresenter(sender is Control ? (Control)sender : UITools.FindAncestor <Control>(sender));
                position = input.PositionRelativeTo(scp);
                break;

            case PositionRelativeToType.Panel:
                var parentPanel = UITools.FindAncestor <Panel>(sender);
                position = input.PositionRelativeTo(parentPanel);
                break;

            case PositionRelativeToType.Window:
                var parentWindow = Window.GetWindow(sender);
                position = input.PositionRelativeTo(parentWindow);
                break;
            }

            //Console.WriteLine(position);
            return(ScriptCommands.Assign(DestinationKey, position, SkipIfExists, NextCommand));
        }
        public ParameterDic Convert(object sender, object parameter, params object[] additionalParameters)
        {
            var retVal = new ParameterDic();

            retVal.SetValue(_variableName, sender);
            return(retVal);
        }
Ejemplo n.º 16
0
        protected override IScriptCommand executeInner(ParameterDic pm, UIElement sender, RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs)
        {
            DragEventArgs            devnt          = evnt as DragEventArgs;
            ISupportDrop             dropTarget     = pm.GetValue <ISupportDrop>(DropTargetKey);
            IEnumerable <IDraggable> draggables     = pm.GetValue <IEnumerable <IDraggable> >(DraggablesKey);
            DragDropEffectsEx        allowedEffects = pm.HasValue(AllowedEffectsKey) ? pm.GetValue <DragDropEffectsEx>(AllowedEffectsKey)
                : devnt != null ? (DragDropEffectsEx)devnt.AllowedEffects : DragDropEffectsEx.All;

            if (dropTarget != null && draggables != null)
            {
                QueryDropEffects queryDropEffect = QueryDropEffects.None;
                if (devnt != null)
                {
                    queryDropEffect = dropTarget.QueryDrop(draggables, allowedEffects);
                    devnt.Effects   = (DragDropEffects)queryDropEffect.SupportedEffects;
                }
                else
                {
                    queryDropEffect = dropTarget.QueryDrop(draggables, allowedEffects);
                }

                pm.SetValue(DestinationKey, queryDropEffect, SkipIfExists);
            }
            return(NextCommand);
        }
Ejemplo n.º 17
0
        protected override IScriptCommand executeInner(ParameterDic pm, UIElement sender, RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs)
        {
            if (evnt is GiveFeedbackEventArgs)
            {
                GiveFeedbackEventArgs gevnt = evnt as GiveFeedbackEventArgs;
                if (CursorType != null)
                {
                    gevnt.UseDefaultCursors = false;
                    Mouse.SetCursor(CursorType);
                    gevnt.Handled = true;
                }
                else
                {
                    gevnt.UseDefaultCursors = true;
                }
            }
            else if (evnt is QueryCursorEventArgs)
            {
                QueryCursorEventArgs qevnt = evnt as QueryCursorEventArgs;
                if (CursorType != null)
                {
                    qevnt.Cursor  = CursorType;
                    qevnt.Handled = true;
                }
            }

            return(NextCommand);
        }
Ejemplo n.º 18
0
        public override IScriptCommand Execute(ParameterDic pm)
        {
            switch (Mode)
            {
            case RunMode.Parallel:
            case RunMode.Queue:
                ScriptRunner.RunScript(pm, ScriptCommands);
                break;

            case RunMode.Sequence:
                foreach (var cmd in ScriptCommands)
                {
                    ScriptRunner.RunScript(pm, cmd);
                    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);
            }
        }
Ejemplo n.º 19
0
        public static async Task Test_DiskCreatePath()
        {
            //Prepare
            DiskCreatePath cmd         = new DiskCreatePath();
            var            mockProfile = new Mock <IDiskProfile>();
            var            mockModel   = new Mock <IEntryModel>();

            mockProfile.Setup(p => p.Path).Returns(PathHelper.Disk);
            mockProfile.Setup(p => p.DiskIO.CreateAsync(dummyPath, false, It.IsAny <System.Threading.CancellationToken>()))
            .Returns(() => Task.FromResult(mockModel.Object))
            .Verifiable();

            ParameterDic pd = new ParameterDic()
            {
                { cmd.ProfileKey, mockProfile.Object },
                { cmd.PathKey, dummyPath }
            };

            //Action
            await cmd.ExecuteAsync(pd);

            //Assert
            Assert.IsTrue(pd.ContainsKey(cmd.DestinationKey));
            Assert.AreEqual(mockModel.Object, pd[cmd.DestinationKey]);
            mockProfile.Verify();
        }
Ejemplo n.º 20
0
        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)));
            }

            IEntryModel[] value = new IEntryModel[] { };
            switch (AssignType)
            {
            case FileListAssignType.All:
                value = flvm.ProcessedEntries.EntriesHelper.AllNonBindable
                        .Select(evm => evm.EntryModel).ToArray();
                break;

            case FileListAssignType.Selected:
                value = flvm.Selection.SelectedItems.Select(evm => evm.EntryModel).ToArray();
                break;

            default:
                return(ResultCommand.Error(new NotSupportedException("AssignType")));
            }

            return(ScriptCommands.Assign(DestinationKey, value, false, NextCommand));
        }
        public override IScriptCommand Execute(ParameterDic pm)
        {
            IExplorerViewModel evm = pm.GetValue <IExplorerViewModel>(ExplorerKey);

            if (evm == null)
            {
                return(ResultCommand.Error(new KeyNotFoundException(ExplorerKey)));
            }

            ParameterDic startupParameters = new ParameterDic();

            foreach (var key in VariableKeys.Split(','))
            {
                var val = pm.GetValue(key);
                startupParameters.SetValue(key, val);
            }

            addStartupParameters(evm.Commands, startupParameters);
            addStartupParameters(evm.FileList.Commands, startupParameters);
            addStartupParameters(evm.DirectoryTree.Commands, startupParameters);
            addStartupParameters(evm.Navigation.Commands, startupParameters);
            addStartupParameters(evm.Breadcrumb.Commands, startupParameters);

            return(NextCommand);
        }
Ejemplo n.º 22
0
        private bool parseEntryAndProfile(ParameterDic pm, string key, string profileKey,
                                          out string[] entryPath, out IProfile profile)
        {
            object value = pm.GetValue(key);

            if (value is string)
            {
                value = new string[] { value as string }
            }
            ;
            if (value is string[])
            {
                entryPath = value as string[];
                profile   = pm.GetValue <IProfile>(profileKey);
                return(true);
            }

            if (value is IEntryModel)
            {
                value = new IEntryModel[] { value as IEntryModel }
            }
            ;

            if (value is IEntryModel[])
            {
                IEntryModel[] ems = value as IEntryModel[];
                entryPath = ems.Select(em => em.FullPath).ToArray();
                profile   = ems.First().Profile;
                return(true);
            }

            entryPath = null;
            profile   = null;
            return(false);
        }
Ejemplo n.º 23
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            IWindowManager   wm     = pm.GetValue <IWindowManager>(WindowManagerKey) ?? new WindowManager();
            IEventAggregator events = pm.GetValue <IEventAggregator>(EventAggregatorKey) ?? new EventAggregator();


            TabbedExplorerViewModel tevm = new TabbedExplorerViewModel(wm, events);

            pm.SetValue(DestinationKey, tevm);
            tevm.Initializer = new ScriptCommandInitializer()
            {
                StartupParameters = pm,
                WindowManager     = wm,
                Events            = events,
                OnModelCreated    = ScriptCommands.Run(OnModelCreatedKey),
                OnViewAttached    = ScriptCommands.Run(OnViewAttachedKey)
            };

            if (pm.HasValue(OnTabExplorerCreatedKey))
            {
                await tevm.Commands.ExecuteAsync(pm.GetValue <IScriptCommand>(OnTabExplorerCreatedKey));
            }
            tevm.OnTabExplorerAttachedKey = OnTabExplorerAttachedKey;

            object enableTabsWhenOneTab = pm.GetValue("{EnableTabsWhenOneTab}");

            tevm.EnableTabsWhenOneTab = !(enableTabsWhenOneTab is bool) || (bool)enableTabsWhenOneTab;
            logger.Info(String.Format("Showing {0}", tevm));
            wm.ShowWindow(tevm);


            return(NextCommand);
        }
Ejemplo n.º 24
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            string[] sourcePaths, destinationPaths;
            IProfile sourceProfile, destinationProfile;

            parseEntryAndProfile(pm, SourceEntryKey, SourceProfileKey, out sourcePaths, out sourceProfile);


            if (!parseEntryAndProfile(pm, DestinationEntryKey, DestinationProfileKey, out destinationPaths, out destinationProfile))
            {
                logger.Error(String.Format("Failed to parse {0} or {1}", DestinationEntryKey, DestinationProfileKey));
                return(NextCommand);
            }


            logger.Info(String.Format("({0}) {1} -> {2}", ChangeType, sourcePaths, destinationPaths));
            if (ChangeType == ChangeType.Moved && sourceProfile != null && destinationProfile != null && sourcePaths != null)
            {
                if (sourceProfile != destinationProfile)
                {
                    sourceProfile.Events.PublishOnCurrentThread(new EntryChangedEvent(ChangeType.Deleted, sourcePaths));
                    destinationProfile.Events.PublishOnCurrentThread(new EntryChangedEvent(ChangeType.Created, destinationPaths));
                }
                else
                {
                    destinationProfile.Events.PublishOnCurrentThread(new EntryChangedEvent(destinationPaths.FirstOrDefault(), sourcePaths.FirstOrDefault()));
                }
            }
            else
            {
                destinationProfile.Events.PublishOnCurrentThread(new EntryChangedEvent(ChangeType, destinationPaths));
            }

            return(NextCommand);
        }
Ejemplo n.º 25
0
        public override IScriptCommand Execute(ParameterDic pm)
        {
            string variable = pm.ReplaceVariableInsideBracketed(VariableKey);

            print(variable);
            return(NextCommand);
        }
Ejemplo n.º 26
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            var evm = pm.GetValue <IExplorerViewModel>(ExplorerKey);
            var dm  = DirectoryEntryKey == null ? null :
                      (await pm.GetValueAsEntryModelArrayAsync(DirectoryEntryKey)).FirstOrDefault();

            if (evm == null)
            {
                var events = pm.GetValue <IEventAggregator>(EventsKey);
                if (events != null)
                {
                    events.PublishOnUIThread(new DirectoryChangedEvent(this, dm, null));
                }
                else
                {
                    return(ResultCommand.Error(new ArgumentNullException(ExplorerKey)));
                }
            }
            else
            {
                await evm.GoAsync(dm);
            }

            logger.Info("Path = " + dm.FullPath);
            return(NextCommand);
        }
Ejemplo n.º 27
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            try
            {
                var srcProfile  = _srcModel.Profile as IDiskProfile;
                var destProfile = _destDirModel.Profile as IDiskProfile;
                var progress    = pm.ContainsKey("Progress") ? pm["Progress"] as IProgress <TransferProgress> : NullTransferProgress.Instance;

                var    destMapping  = (_destDirModel.Profile as IDiskProfile).DiskIO.Mapper[_destDirModel];
                var    srcMapping   = (_srcModel.Profile as IDiskProfile).DiskIO.Mapper[_srcModel];
                string destName     = PathFE.GetFileName(srcMapping.IOPath);
                string destFullName = destProfile.Path.Combine(_destDirModel.FullPath, destName); //PathFE.Combine(destMapping.IOPath, destName);


                if (_srcModel.IsDirectory)
                {
                    Func <IEntryModel, bool> filter       = em => !em.IsDirectory || (em is SzsRootModel);
                    Func <IEntryModel, bool> lookupFilter = em => em.IsDirectory && !(em is SzsRootModel);
                    return(WPFScriptCommands.List(_srcModel, filter, lookupFilter, true, ems =>
                                                  new SimpleScriptCommandAsync("BatchTransfer", pd => transferAsync(pm, ems, progress,
                                                                                                                    new NotifyChangedCommand(_destDirModel.Profile, destFullName,
                                                                                                                                             _srcModel.Profile, _srcModel.FullPath, Defines.ChangeType.Changed)))));
                }
                else
                {
                    return(IOScriptCommands.DiskTransfer(_srcModel, _destDirModel, _removeOriginal));
                }

                return(ResultCommand.NoError);
            }
            catch (Exception ex)
            {
                return(ResultCommand.Error(ex));
            }
        }
Ejemplo n.º 28
0
        public void Test_MultiLevel_Variable_Names()
        {
            IParameterDic dic = new ParameterDic();
            IParameterDic subDic1, subDic2;
            int dictionaryCount, subDic1Count, subDic2Count, 
                property1Value, property3Value, property5Value;

            dic.Set("{SubDic1.Property1}", 1);
            dic.Set("{SubDic1.SubDic2.Property3}", 3);
            dic.Set("{SubDic1.SubDic2.Property5}", 3);
            dic.Add("{SubDic1.SubDic2.Property5}", 2);

            subDic1 = dic.Get<ParameterDic>("{SubDic1}");
            property1Value = dic.Get("{SubDic1.Property1}", -1);
            subDic2 = dic.Get<ParameterDic>("{SubDic1.SubDic2}");
            property3Value = dic.Get("{SubDic1.SubDic2.Property3}", -1);
            property5Value = dic.Get("{SubDic1.SubDic2.Property5}", -1);

            dictionaryCount = dic.List().Count();
            subDic1Count = subDic1.List().Count();
            subDic2Count = subDic2.List().Count();

            Assert.AreEqual(1, dictionaryCount, "dictionaryCount");
            Assert.IsNotNull(subDic1, "subDic1");
            Assert.IsNotNull(subDic2, "subDic2");
            Assert.AreEqual(2, subDic1Count, "subDic1Count");
            Assert.AreEqual(2, subDic2Count, "subDic2Count");

            Assert.AreEqual(1, property1Value, "property1Value");
            Assert.AreEqual(3, property3Value, "property3Value");
            Assert.AreEqual(5, property5Value, "property5Value");



        }
Ejemplo n.º 29
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());
            }
        }
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            Func <IEntryModel, bool> filter;

            if (pm.ContainsKey("Mask"))
            {
                string mask = pm["Mask"] as string;
                filter = (em => _filter(em) && PathFE.MatchFileMask(em.Name, mask));
            }
            else
            {
                filter = _filter;
            }
            _lookupFilter = _lookupFilter ?? (em => em.IsDirectory);

            bool refresh = pm.ContainsKey("Refresh") && (bool)pm["Refresh"];

            List <IEntryModel> result = new List <IEntryModel>();

            foreach (var directory in _directories)
            {
                result.AddRange(await listAsync(directory, pm.CancellationToken, filter, _lookupFilter, refresh));
            }

            return(_nextCommandFunc(result.ToArray()));
        }