Пример #1
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);
                }
            }
        }
        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);
        }
        protected override IScriptCommand executeInner(ParameterDic pm, ItemsControl ic,
                                                       RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs)
        {
            Point         posRelToScp    = pm.GetValue <Point>(CurrentRelativePositionKey);
            var           startSelected  = UIEventHubProperties.GetStartSelectedItem(ic);
            List <object> selectedList   = new List <object>();
            List <int>    selectedIdList = new List <int>();
            var           scp            = ControlUtils.GetScrollContentPresenter(ic);

            var currentSelected = UITools.GetSelectedListBoxItem(scp, posRelToScp);

            if (startSelected != null && currentSelected != null)
            {
                int startIdx = ic.ItemContainerGenerator.IndexFromContainer(startSelected);
                int endIdx   = ic.ItemContainerGenerator.IndexFromContainer(currentSelected);

                for (int i = Math.Min(startIdx, endIdx); i <= Math.Max(startIdx, endIdx); i++)
                {
                    selectedList.Add(ic.Items[i]);
                    selectedIdList.Add(i);
                }
            }

            //UpdateStartSelectedItems, or clear it if no longer selecting.
            if (UIEventHubProperties.GetIsSelecting(ic))
            {
                if (UIEventHubProperties.GetStartSelectedItem(ic) == null)
                {
                    var itemUnderMouse = UITools.GetSelectedListBoxItem(scp, posRelToScp);
                    UIEventHubProperties.SetStartSelectedItem(ic, itemUnderMouse);
                }
            }
            else
            {
                UIEventHubProperties.SetStartSelectedItem(ic, null);
            }

            if (UIEventHubProperties.GetIsSelecting(ic))
            {
                if (UIEventHubProperties.GetStartSelectedItem(ic) == null)
                {
                    UITools.SetItemUnderMouseToAttachedProperty(ic, posRelToScp,
                                                                UIEventHubProperties.StartSelectedItemProperty);
                }
            }

            pm.SetValue(SelectedListKey, selectedList);
            pm.SetValue(SelectedIdListKey, selectedIdList);
            logger.Debug(String.Format("Selected = {0}", selectedIdList.Count()));
            return(NextCommand);
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
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);
        }
        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);
        }
Пример #8
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);
            }
        }
Пример #9
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);
        }
Пример #10
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            DestinationKey = DestinationKey ?? "{Explorer}";
            var tevm = pm.GetValue <ITabbedExplorerViewModel>(TabbedExplorerKey);

            if (tevm == null)
            {
                return(ResultCommand.Error(new ArgumentNullException(TabbedExplorerKey)));
            }

            var dm = DirectoryEntryKey == null ? null :
                     (await pm.GetValueAsEntryModelArrayAsync(DirectoryEntryKey)).FirstOrDefault();

            if (dm != null && !dm.IsDirectory)
            {
                dm = null;
            }

            var destTab = tevm.OpenTab(dm);

            logger.Info(String.Format("New Tab #{0}", tevm.GetTabIndex(destTab)));
            logger.Debug(String.Format("{0} = {1}", DestinationKey, destTab));
            pm.SetValue(DestinationKey, destTab);
            return(NextCommand);
        }
Пример #11
0
        public override IScriptCommand Execute(ParameterDic pm)
        {
            object source = pm.GetValue <object>(SourceVariableKey);

            if (source == null)
            {
                logger.Error("Source not found.");
            }

            if (ValueConverterKey != null)
            {
                object valueConverter = pm.GetValue <object>(ValueConverterKey);

                if (valueConverter is Func <object, object> ) //GetProperty, ExecuteMethod, GetArrayItem
                {
                    Func <object, object> valueConverterFunc = valueConverter as Func <object, object>;
                    object value = valueConverterFunc(source);
                    pm.SetValue(DestinationVariableKey, value, SkipIfExists);
                }
                else
                if (valueConverter is Action <object, object> )   //SetProperty
                {
                    Action <object, object> valueConverterAct = valueConverter as Action <object, object>;
                    object value = pm.GetValue <object>(DestinationVariableKey);
                    valueConverterAct(source, value);
                }
            }

            return(NextCommand);
        }
        public ParameterDic Convert(object sender, object parameter, params object[] additionalParameters)
        {
            var retVal = new ParameterDic();

            retVal.SetValue(_variableName, sender);
            return(retVal);
        }
Пример #13
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);
        }
Пример #14
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);
        }
Пример #15
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);
        }
        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);
        }
Пример #17
0
        public override IScriptCommand Execute(ParameterDic pm)
        {
            Point pos = pm.GetValue <Point>(PositionKey);

            pm.SetValue(DestinationKey, Point.Multiply(pos, new System.Windows.Media.Matrix(-1, 0, 0, -1, 0, 0)));

            return(NextCommand);
        }
Пример #18
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);
        }
Пример #19
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            var    pdv = pm.GetValue <IProgress <TransferProgress> >("{Progress}", NullTransferProgress.Instance);
            string url = pm.GetValue <string>(UrlKey);

            if (url == null)
            {
                return(ResultCommand.Error(new ArgumentException("Unspecified Url.")));
            }

            try
            {
                using (var httpClient =
                           pm.ContainsKey(HttpClientKey) && pm[HttpClientKey] is Func <HttpClient>?((Func <HttpClient>)pm[HttpClientKey])() :
                               new HttpClient())
                {
                    var response = await httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, pm.CancellationToken);

                    if (!response.IsSuccessStatusCode)
                    {
                        throw new WebException(String.Format("{0} when downloading {1}", response.StatusCode, url));
                    }

                    MemoryStream destStream = new MemoryStream();
                    logger.Info(String.Format("{0} = Stream of {1}", DestinationKey, url));
                    using (Stream srcStream = await response.Content.ReadAsStreamAsync())
                    {
                        pdv.Report(TransferProgress.From(url));
                        byte[] buffer         = new byte[1024];
                        ulong  totalBytesRead = 0;
                        ulong  totalBytes     = 0;
                        try { totalBytes = (ulong)srcStream.Length; }
                        catch (NotSupportedException) { }

                        int byteRead = await srcStream.ReadAsync(buffer, 0, buffer.Length, pm.CancellationToken);

                        while (byteRead > 0)
                        {
                            await destStream.WriteAsync(buffer, 0, byteRead, pm.CancellationToken);

                            totalBytesRead = totalBytesRead + (uint)byteRead;
                            short percentCompleted = (short)((float)totalBytesRead / (float)totalBytes * 100.0f);
                            pdv.Report(TransferProgress.UpdateCurrentProgress(percentCompleted));

                            byteRead = await srcStream.ReadAsync(buffer, 0, buffer.Length, pm.CancellationToken);
                        }
                        await destStream.FlushAsync();
                    }

                    pm.SetValue(DestinationKey, destStream.ToByteArray());
                    return(NextCommand);
                }
            }
            catch (Exception ex)
            {
                return(ResultCommand.Error(ex));
            }
        }
Пример #20
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            IEnumerable e = pm.GetValue <IEnumerable>(ItemsKey);

            if (e == null)
            {
                return(ResultCommand.Error(new ArgumentException(ItemsKey)));
            }

            IProgress <TransferProgress> progress = NullTransferProgress.Instance;

            if (IsProgressEnabled)
            {
                List <object> list;
                e        = list = e.Cast <object>().ToList();
                progress = pm.GetProgress();
                progress.Report(TransferProgress.IncrementTotalEntries(list.Count));
            }

            uint counter = 0;

            pm.SetValue <bool>(BreakKey, false);
            foreach (var item in e)
            {
                if (pm.GetValue <bool>(BreakKey))
                {
                    break;
                }

                counter++;
                pm.SetValue(CurrentItemKey, item);
                await ScriptRunner.RunScriptAsync(pm, NextCommand);

                progress.Report(TransferProgress.IncrementProcessedEntries());
                if (pm.Error != null)
                {
                    pm.SetValue <Object>(CurrentItemKey, null);
                    return(ResultCommand.Error(pm.Error));
                }
            }
            logger.Info("Looped {0} items", counter);
            pm.SetValue <Object>(CurrentItemKey, null);

            return(ThenCommand);
        }
Пример #21
0
        public override IScriptCommand Execute(ParameterDic pm)
        {
            Point pos       = pm.GetValue <Point>(PositionKey);
            Point offsetpos = pm.GetValue <Point>(OffsetKey);

            pm.SetValue(DestinationKey, new Point(pos.X + offsetpos.X, pos.Y + offsetpos.Y));

            return(NextCommand);
        }
Пример #22
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();

            IExplorerInitializer initializer = new ScriptCommandInitializer()
            {
                StartupParameters = pm,
                WindowManager     = wm,
                Events            = events,
                OnModelCreated    = ScriptCommands.Run(OnModelCreatedKey),
                OnViewAttached    = ScriptCommands.Run(OnViewAttachedKey)
            };

            ExplorerViewModel evm = null;

            switch (ExplorerMode)
            {
            case Script.ExplorerMode.Normal:
                evm = new ExplorerViewModel(wm, events)
                {
                    Initializer = initializer
                };
                break;

            case Script.ExplorerMode.FileOpen:
                evm = new FilePickerViewModel(wm, events)
                {
                    Initializer = initializer,
                    PickerMode  = FilePickerMode.Open
                };
                break;

            case Script.ExplorerMode.FileSave:
                evm = new FilePickerViewModel(wm, events)
                {
                    Initializer = initializer,
                    PickerMode  = FilePickerMode.Save
                };
                break;

            case Script.ExplorerMode.DirectoryOpen:
                evm = new DirectoryPickerViewModel(wm, events)
                {
                    Initializer = initializer
                };
                break;

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

            logger.Info(String.Format("Creating {0}", evm));
            pm.SetValue(DestinationKey, evm, false);

            return(NextCommand);
        }
Пример #23
0
 private void dragEnd(ParameterDic pm)
 {
     pm.SetValue <object>(DragDropModeKey, null);
     pm.SetValue <object>(DragDropDeviceKey, null);
     pm.SetValue <object>(DragDropDraggingItemsKey, null);
     pm.SetValue <object>(DragDropEffectsKey, null);
     pm.SetValue(ParameterDic.CombineVariable(DragDropDragSourceKey, ".IsDraggingFrom", false), false);
     pm.SetValue <object>(DragDropDragSourceKey, null);
     pm.SetValue <object>(DragDropDropTargetKey, null);
     pm.SetValue <object>(DragDropStartPositionKey, null);
 }
        public ParameterDic Convert(params object[] parameters)
        {
            var retVal = new ParameterDic();

            if (_getterFunc != null)
            {
                retVal.SetValue(_variableName, _getterFunc(parameters));
            }
            return(retVal);
        }
        public ParameterDic Convert(params object[] parameters)
        {
            var retVal = new ParameterDic();

            if (parameters.Length > _idx)
            {
                retVal.SetValue(_variableName, parameters[_idx]);
            }
            return(retVal);
        }
Пример #26
0
        private void execute_Click(object sender, RoutedEventArgs e)
        {
            MemoryStream ms = new MemoryStream();
            var          sw = new StreamWriter(ms);

            sw.Write(tbCommand.Text);
            sw.Flush();
            ms.Seek(0, SeekOrigin.Begin);

            IScriptCommand cmd = _serializer.DeserializeScriptCommand(ms);
            ParameterDic   pd1 = new ParameterDic();

            pd1.SetValue("{tbDirectory}", tbDirectory);
            pd1.SetValue("{Now}", DateTime.Now);
            if (cmd != null)
            {
                explorer.ViewModel.Commands.ExecuteAsync(cmd, pd1);
            }
        }
Пример #27
0
        public override Script.IScriptCommand Execute(ParameterDic pm)
        {
            FrameworkElement sender = pm.GetValue <FrameworkElement>(SenderKey);

            FrameworkElement ele = (FindDirection == FindDirectionType.Parent) ?
                                   findAncestor(pm, sender) : findChild(pm, sender);

            pm.SetValue(DestinationKey, ele, false);

            return(NextCommand);
        }
Пример #28
0
        public override IScriptCommand Execute(ParameterDic pm)
        {
            FrameworkElement origSource = pm.GetValue <FrameworkElement>(SourceElementKey);

            Value = null;
            FrameworkElement ele = null;

            if (origSource != null)
            {
                switch (DataContextType)
                {
                case UIEventHub.DataContextType.Any:
                    Value = origSource.DataContext;
                    ele   = origSource;
                    break;

                case UIEventHub.DataContextType.SupportDrag:
                    Value = DataContextFinder.GetDataContext(origSource, out ele, DataContextFinder.SupportDrag);
                    break;

                case UIEventHub.DataContextType.SupportShellDrag:
                    Value = DataContextFinder.GetDataContext(origSource, out ele, DataContextFinder.SupportShellDrag);
                    break;

                case UIEventHub.DataContextType.SupportShellDrop:
                    Value = DataContextFinder.GetDataContext(origSource, out ele, DataContextFinder.SupportShellDrop);
                    break;

                case UIEventHub.DataContextType.SupportDrop:
                    Value = DataContextFinder.GetDataContext(origSource, out ele, DataContextFinder.SupportDrop);
                    break;

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

            pm.SetValue(VariableKey, Value, SkipIfExists);
            pm.SetValue(DataContextElementKey, ele, SkipIfExists);
            return(NextCommand);
        }
        protected override IScriptCommand executeInner(ParameterDic pm, UIElement sender, RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs)
        {
            var adornerLayer = pm.GetValue <AdornerLayer>(AdornerLayerKey);

            DragAdorner adorner = new DragAdorner(adornerLayer)
            {
                IsHitTestVisible     = false,
                DraggingItemTemplate = UIEventHubProperties.GetDragItemTemplate(sender)
            };

            pm.SetValue(AdornerKey, adorner);
            return(NextCommand);
        }
Пример #30
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);
        }