示例#1
0
        public void Launch_FileItem()
        {
            Launchable launchable = _actionRegistry.Launch(new IIndexable[] { new FileItem(Assembly.GetExecutingAssembly().Location) });

            launchable.Action.ShouldBeType <OpenAction>();
            launchable.Target.ShouldBeType <FileItem>();
        }
示例#2
0
        private void OpenSelected(string search, Action afterOpenAction)
        {
            if (!_mainListModel.Items.Any())
            {
                return;
            }

            var searchItemModel  = _mainListModel.Items[_mainListModel.SelectedIndex];
            var targetItem       = searchItemModel.TargetItem;
            var standaloneAction = targetItem as IStandaloneAction;

            if (standaloneAction != null)
            {
                Log.Information("Launching {@TargetItem} with {ActionType}", targetItem, standaloneAction.GetType());

                try
                {
                    _frecencyStorage.AddUse(targetItem.BoostIdentifier, search, _mainListModel.SelectedIndex);
                    standaloneAction.Run();
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Exception launching {@TargetItem} with {ActionType}", targetItem, standaloneAction.GetType());
                }

                afterOpenAction();
                return;
            }

            var launchable = _actionRegistry.Launch(_selectedIndexables.Reverse().Concat(new[] { targetItem }).ToArray());

            if (launchable?.Action == null)
            {
                throw new Exception("Unable to find action.");
            }

            if (launchable.Target == null)
            {
                if (PushStack())
                {
                    return;
                }

                throw new Exception("Unable to find target.");
            }

            try
            {
                _frecencyStorage.AddUse(launchable.Action.BoostIdentifier, search, _mainListModel.SelectedIndex);
                _frecencyStorage.AddUse(launchable.Target.BoostIdentifier, search, _mainListModel.SelectedIndex);


                Log.Information("Launching {@TargetItem} with {ActionType}", launchable.Target, launchable.Action);

                launchable.Action.GetType()
                .GetMethod("Run", new[] { launchable.Target.GetType() })
                .Invoke(launchable.Action, new[] { launchable.Target });
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Exception launching {@TargetItem} with {ActionType}", launchable.Target, launchable.Action);
            }

            afterOpenAction();
            Reset();
        }