Beispiel #1
0
        public void Drop(IResource targetResource, IDataObject data, DragDropEffects allowedEffect, int keyState)
        {
            if (data.GetDataPresent(typeof(IResourceList)))
            {
                // The resources we're dragging
                IResourceList dragResources = (IResourceList)data.GetData(typeof(IResourceList));

                // Currently, only the Deleted Resources view has a drop handler
                if (FilterRegistry.IsDeletedResourcesView(targetResource))
                {
                    // Delete the resources dropped onto the deleted items view
                    foreach (IResource res in dragResources)
                    {
                        IResourceDeleter deleter = Core.PluginLoader.GetResourceDeleter(res.Type);
                        if (deleter != null)
                        {
                            try
                            {
                                Core.ResourceAP.RunJob(new ResourceDelegate(deleter.DeleteResource), res);
//								deleter.DeleteResource( res );
                            }
                            catch (NotImplementedException)
                            {
                            }
                        }
                    }
                }
                else
                {
                    return;
                }
            }
        }
Beispiel #2
0
        public void  RenameRule(IResource rule, string newName)
        {
            #region Preconditions
            if (rule == null)
            {
                throw new ArgumentNullException("rule", "ExpirationRuleManager -- Input rule resource is null.");
            }

            if (rule.Type != FilterManagerProps.RuleResName || !rule.HasProp("IsExpirationFilter"))
            {
                throw new InvalidOperationException("ExpirationRuleManager -- input resource is not a TrayIcon rule.");
            }

            if (String.IsNullOrEmpty(newName))
            {
                throw new ArgumentNullException("newName", "ExpirationRuleManager -- New name for a rule is null or empty.");
            }
            #endregion Preconditions

            if (FilterRegistry.FindRuleByName(newName, "IsExpirationFilter") != null)
            {
                throw new ArgumentException("ExpirationRuleManager -- An action rule with new name already exists.");
            }

            new ResourceProxy(rule).SetProp(Core.Props.Name, newName);
        }
Beispiel #3
0
        private static IResource CloneActionRule(string newName, IResource from)
        {
            #region Preconditions
            IResource res = Core.ResourceStore.FindUniqueResource(FilterManagerProps.RuleResName, "Name", newName);
            if (res != null)
            {
                throw new AmbiguousMatchException("Can not assigned a name which is already in use for a cloned rule.");
            }
            #endregion Preconditions

            IResource[][] conditionGroups;
            IResource[]   exceptions;
            FilterRegistry.CloneConditionTypeLinks(from, out conditionGroups, out exceptions);

            IResourceList actionsList = FMan.GetActions(from);
            IResource[]   actions     = new IResource[actionsList.Count];
            for (int i = 0; i < actionsList.Count; i++)
            {
                actions[i] = FMan.CloneAction(actionsList[i]);
            }

            string[]  formTypes = FilterRegistry.CompoundType(from);
            string    eventName = from.GetStringProp("EventName");
            IResource newRule   = FMan.RegisterRule(eventName, newName, formTypes, conditionGroups, exceptions, actions);
            return(newRule);
        }
Beispiel #4
0
        public void CanFetchAndExecuteFilter()
        {
            string source = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\Plugins\bin\Debug\Plugins.dll";

            var filterRegistry = new FilterRegistry<Step>();
            filterRegistry.LoadPlugIn(source);

            var filters = filterRegistry.GetFilters("Plugins.CaptainUnfitForCommandFilter")
                                        .ToList();

            Assert.AreEqual(1, filters.Count);

            var parameters = new Dictionary<string, object>();
            parameters.Add("KirkInfected", true);

            var step = new Step("12w", "231a", "CaptainApproval", "FirstOfficeReview",
                                "Deny", DateTime.Now, "Kirk", "Kirk",
                                parameters);
            step.CanProcess = true;

            step = filters[0].Execute(step);

            Assert.AreEqual(false, step.CanProcess);
            Assert.AreEqual(1, step.ErrorList.Count);
            Assert.IsTrue((bool)step.Parameters["MedicalOverride"]);
            Console.WriteLine(step.ErrorList[0]);
        }
        public void CanConfigureProcessorWithPipelineAndRegistry()
        {
            string preFilterNames = "FetchDataFilter;ValidParticipantFilter;";
            string postFilterNames = "SaveDataFilter";

            var parameters = new Dictionary<string, object>();
            parameters.Add("FilterOrder", string.Empty);
            parameters.Add("FetchDataFired", false);
            parameters.Add("SaveDataFired", false);
            parameters.Add("ValidFired", false);

            var step = new Step("13", "12", "Manager Approve", "Request Promotion",
                                    "Approve", DateTime.Now, "Spock", "Spock;Kirk",
                                    parameters);
            step.CanProcess = true;

            var filterRegistry = new FilterRegistry<Step>();
            var processor = new WorkflowProcessor(step, filterRegistry, new Workflow());
            processor.ConfigurePipeline(preFilterNames, postFilterNames);

            var filterNames = processor.GetFilterNames();
            filterNames.ForEach(x => Console.WriteLine(x));

            Assert.AreEqual(4, filterNames.Count);
        }
Beispiel #6
0
 public IResource  ReregisterTrayIconRule(IResource rule, string name, string[] types,
                                          IResource[] conditions, IResource[] exceptions,
                                          Icon icon)
 {
     IResource[][] group = FilterRegistry.Convert2Group(conditions);
     return(ReregisterTrayIconRule(rule, name, types, group, exceptions, icon));
 }
 protected override void Register(FilterRegistry registry)
 {
     registry.RegisterOnAction<HomeController, TestActionFilterAttribute>(c => c.Index(), a => { a.A = "a"; a.B = "b"; })
             //.RegisterOnAction<HomeController, NVelocityViewAttribute>(c => c.Velocity(), a => a.ViewPath = "/Views/Home/template.htm")
             .RegisterOnAction<HomeController, AutoMapperAttribute>(c => c.Velocity(), a => { a.SrcType = typeof(User[]); a.DestType = typeof(TestViewModel[]); })
             .RegisterOnGlobal<TestExceptionFilterAttribute>()
     ;
 }
        public WorkflowProcessor(Step theStep, FilterRegistry<Step> registry, Workflow workflow)
        {
            this.step = theStep;
            this.filterRegistry = registry;
            this.workflow = workflow;

            this.pipeline = new Pipeline<Step>();
        }
Beispiel #9
0
 protected override void Register(FilterRegistry registry)
 {
     registry.RegisterOnAction <HomeController, TestActionFilterAttribute>(c => c.Index(), a => { a.A = "a"; a.B = "b"; })
     //.RegisterOnAction<HomeController, NVelocityViewAttribute>(c => c.Velocity(), a => a.ViewPath = "/Views/Home/template.htm")
     .RegisterOnAction <HomeController, AutoMapperAttribute>(c => c.Velocity(), a => { a.SrcType = typeof(User[]); a.DestType = typeof(TestViewModel[]); })
     .RegisterOnGlobal <TestExceptionFilterAttribute>()
     ;
 }
Beispiel #10
0
 public bool DecorateNode(IResource res, RichText nodeText)
 {
     if (res.Type == FilterManagerProps.ViewResName && FilterRegistry.HasQueryCondition(res))
     {
         bool ready = Core.TextIndexManager.IsIndexPresent();
         nodeText.SetStyle(ready ? _normalStyle : _notReadyStyle, 0, nodeText.Length);
         return(true);
     }
     return(false);
 }
Beispiel #11
0
        public void CanLoadMultiplePluginAssemblies()
        {
            string source = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\TestSuite\TestPlugins";

            var filterRegistry = new FilterRegistry<Step>();
            filterRegistry.LoadPlugInsFromShare(source);

            Console.WriteLine(filterRegistry.GetFilterNames());
            Assert.AreEqual(7, filterRegistry.GetFilterCount());
        }
Beispiel #12
0
        public void CanRegisterPlugins()
        {
            string source = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\Plugins\bin\Debug\Plugins.dll";

            var filterRegistry = new FilterRegistry<Step>();
            filterRegistry.LoadPlugIn(source);

            //  We should have 4 standard filters and one from the plugin
            Assert.AreEqual(5, filterRegistry.GetFilterCount());
            Console.WriteLine(filterRegistry.GetFilterNames());
        }
 /// <summary>
 /// Do not pay attention to the queries which could have been deleted - their
 /// memory consumtion is too small to be accounted for.
 /// </summary>
 private void ReloadQueryResults()
 {
     foreach (IResource res in _allTextConditions)
     {
         string query = FilterRegistry.ConstructQuery(res);
         if (!_activeQueries.Contains(query))
         {
             _activeQueries.Add(query);
         }
     }
 }
Beispiel #14
0
        public void Execute(IActionContext context)
        {
            IResource view = context.SelectedResources[0];

            IResource[][] conditions;
            IResource[]   exceptions;
            FilterRegistry.CloneConditionTypeLinks(view, out conditions, out exceptions);

            string[] types = FilterRegistry.CompoundType(view);
            Core.FilteringFormsManager.ShowEditActionRuleForm(view.GetStringProp(Core.Props.Name), types,
                                                              conditions, exceptions, null);
        }
Beispiel #15
0
        public IResource RegisterRule(string name, string[] types, IResource[] conditions, IResource[] exceptions,
                                      bool isBold, bool isItalic, bool isUnderlined, bool isStrikeout,
                                      string foreColor, string backColor)
        {
            IResource     rule  = FindRule(name);
            ResourceProxy proxy = GetRuleProxy(rule);

            FilterRegistry.InitializeView(proxy, name, types, conditions, exceptions);
            AddSpecificParams(proxy.Resource, name, isBold, isItalic, isUnderlined, isStrikeout, foreColor, backColor);
            CheckRuleInvisiblity(proxy.Resource, conditions);
            return(proxy.Resource);
        }
Beispiel #16
0
        public IResource ReregisterRule(IResource baseRes, string name, string[] types,
                                        IResource[] conditions, IResource[] exceptions,
                                        bool isBold, bool isItalic, bool isUnderlined, bool isStrikeout,
                                        string foreColor, string backColor)
        {
            ResourceProxy proxy = new ResourceProxy(baseRes);

            proxy.BeginUpdate();
            FilterRegistry.InitializeView(proxy, name, types, conditions, exceptions);
            AddSpecificParams(baseRes, name, isBold, isItalic, isUnderlined, isStrikeout, foreColor, backColor);
            return(baseRes);
        }
Beispiel #17
0
        public void It_Should_Register_A_Filter()
        {
            // Arrange
            const string   key            = "upcase";
            FilterRegistry filterRegistry = new FilterRegistry();

            // Act
            filterRegistry.Register <UpCaseFilter>(key);
            var filterType = filterRegistry.Find(key);

            // Assert
            Assert.Equal(typeof(UpCaseFilter), filterType);
        }
Beispiel #18
0
        public DragDropEffects DragOver(IResource targetResource, IDataObject data, DragDropEffects allowedEffect, int keyState)
        {
            if (data.GetDataPresent(typeof(IResourceList)))
            {
                // The resources we're dragging
                IResourceList dragResources = (IResourceList)data.GetData(typeof(IResourceList));

                // Currently, only the Deleted Resources view has a drop handler
                if (!FilterRegistry.IsDeletedResourcesView(targetResource))
                {
                    return(DragDropEffects.None);
                }

                // Collect all the direct and indirect parents of the droptarget; then we'll check to avoid dropping parent on its children
                IntArrayList parentList = IntArrayListPool.Alloc();
                try
                {
                    IResource parent = targetResource;
                    while (parent != null)
                    {
                        parentList.Add(parent.Id);
                        parent = parent.GetLinkProp(Core.Props.Parent);
                    }

                    // Check
                    foreach (IResource res in dragResources)
                    {
                        // Dropping parent over its child?
                        if (parentList.IndexOf(res.Id) >= 0)
                        {
                            return(DragDropEffects.None);
                        }
                        // Cannot delete resource containers this way
                        if ((Core.ResourceStore.ResourceTypes[res.Type].Flags & ResourceTypeFlags.ResourceContainer) != 0)
                        {
                            return(DragDropEffects.None); // Cannot delete containers
                        }
                    }
                    return(DragDropEffects.Move);
                }
                finally
                {
                    IntArrayListPool.Dispose(parentList);
                }
            }
            else
            {
                return(DragDropEffects.None);
            }
        }
Beispiel #19
0
        public void CanSerializeFilterDefinitions()
        {
            string source = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\TestSuite\TestPlugins";
            string outputSource = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\TestSuite\TestData\output.json";

            var filterRegistry = new FilterRegistry<Step>();
            filterRegistry.LoadPlugInsFromShare(source);
            string json = filterRegistry.SerializeFilterDefinitions();

            Assert.AreEqual(7, filterRegistry.GetFilterCount());

            Assert.IsTrue(json.Length > 0);
            WriteFile(json, outputSource);
        }
Beispiel #20
0
        public IResource  ReregisterTrayIconRule(IResource rule, string name, string[] types,
                                                 IResource[][] conditions, IResource[] exceptions,
                                                 Icon icon)
        {
            UnregisterIconWatcherImpl(rule.DisplayName, false);
            ResourceProxy proxy = new ResourceProxy(rule);

            proxy.BeginUpdate();
            FilterRegistry.InitializeView(proxy, name, types, conditions, exceptions);

            Core.ResourceAP.RunUniqueJob(new AssignmentDelegate(AddSpecificParams), rule, name, icon);
            InitializeWatcher(rule, name, icon);
            return(rule);
        }
Beispiel #21
0
        private void TextIndexLoaded(object sender, System.EventArgs e)
        {
            Core.TextIndexManager.IndexLoaded -= TextIndexLoaded;

            IResourceList allViews = Core.FilterRegistry.GetViews();

            foreach (IResource view in allViews)
            {
                if (FilterRegistry.HasQueryCondition(view))
                {
                    DecorateResource(view);
                }
            }
        }
Beispiel #22
0
        [SetUp] public void SetUp()
        {
            _core = new TestCore();
            _storage = _core.ResourceStore;

            CreateNecessaryResources();

            _registry = _core.FilterRegistry as FilterRegistry;
            _engine = _core.FilterEngine as FilterEngine;
            _wsManager = _core.WorkspaceManager;
            _unreads = _core.UnreadManager as UnreadManager;
            _mockResourceTabProvider = _core.GetComponentInstanceOfType( typeof(MockResourceTabProvider) ) as MockResourceTabProvider;
            _unreads.RegisterUnreadCountProvider( FilterManagerProps.ViewResName, new ViewUnreadCountProvider() );
        }
        public void It_Should_Register_A_Filter()
        {
            // Arrange
            const string key = "upcase";
            FilterRegistry filterRegistry = new FilterRegistry();

            // Act
            filterRegistry.Register<UpCaseFilter>(key);
            var filterType = filterRegistry.Find(key);

            // Assert
            Assert.That(filterType, Is.EqualTo(typeof(UpCaseFilter)));

        }
Beispiel #24
0
 public SymbolTable(
     IDictionary <string, Option <ILiquidValue> > variableDictionary = null,
     FilterRegistry filterRegistry = null,
     Registry <ICustomTagRenderer> customTagRendererRegistry           = null,
     Registry <ICustomBlockTagRenderer> customBlockTagRendererRegistry = null,
     IDictionary <String, Object> localRegistry = null)
 {
     _customBlockTagRendererRegistry = customBlockTagRendererRegistry ?? new Registry <ICustomBlockTagRenderer>();
     _customTagRendererRegistry      = customTagRendererRegistry ?? new Registry <ICustomTagRenderer>();
     _variableDictionary             = variableDictionary ?? new Dictionary <string, Option <ILiquidValue> >();
     _localRegistry  = localRegistry ?? new Dictionary <string, Object>();
     _filterRegistry = filterRegistry ?? new FilterRegistry();
     _macroRegistry  = new Dictionary <string, MacroBlockTag>();
 }
Beispiel #25
0
        public static IResource Template2Action(IResource template, object param, string representation)
        {
            if (template.Type != FilterManagerProps.RuleActionTemplateResName)
            {
                throw new ArgumentException("FilterRegistry -- Invalid type of parameter - RuleActionTemplate is expected");
            }

            IResource   action;
            ConditionOp op = (ConditionOp)template.GetProp("ConditionOp");

            if (op == ConditionOp.In)
            {
                if (param is IResourceList)
                {
                    action = FilterRegistry.RegisterRuleActionProxy(template, (IResourceList)param);
                }
                else
                if (param is string)
                {
                    action = FilterRegistry.RegisterRuleActionProxy(template, (string)param);
                }
                else
                {
                    throw new ArgumentException("Illegal parameter type for the operation - string or Resource List expected");
                }
            }
            else
            if (op == ConditionOp.Eq)
            {
                if (param is string)
                {
                    action = FilterRegistry.RegisterRuleActionProxy(template, (string)param);
                }
                else
                {
                    throw new ArgumentException("Illegal parameter type for the operation - string expected");
                }
            }
            else
            {
                throw new InvalidOperationException("Not all Operations are supported now");
            }

            if (!String.IsNullOrEmpty(representation))
            {
                new ResourceProxy(action).SetProp("SurfaceConditionVal", representation);
            }
            return(action);
        }
        public void CanConfigureProcessorStateMachine()
        {
            string source = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\TestSuite\TestData\RequestPromotion.json";
            var workflow = DeserializeWorkflow(source);

            var step = new Step("13", "12", "Manager Approve", "Request Promotion",
                                    "Approve", DateTime.Now, "Spock", "Spock;Kirk",
                                    new Dictionary<string, object>());
            var filterRegistry = new FilterRegistry<Step>();

            var processor = new WorkflowProcessor(step, filterRegistry, workflow);
            processor.ConfigureStateMachine();

            Assert.AreEqual("Manager Approve", processor.GetCurrentState());
        }
Beispiel #27
0
        private static void ExecSearchViewLate()
        {
            //  All this extra checks are the protection around the possibility
            //  to run in the "non-friendly" environment.
            if (Core.LeftSidebar != null && Core.LeftSidebar.DefaultViewPane != null)
            {
                IResource view = Core.LeftSidebar.DefaultViewPane.SelectedNode;
                if (view != null && FilterRegistry.IsSearchResultsView(view))

                {
                    new ResourceProxy(view).SetProp("ForceExec", true);
                    Core.LeftSidebar.DefaultViewPane.SelectResource(view);
                }
            }
        }
Beispiel #28
0
        public DragDropEffects DragOver(IResource targetResource, IDataObject data, DragDropEffects allowedEffect, int keyState)
        {
            if (data.GetDataPresent(typeof(IResourceList)))
            {
                // The resources we're dragging
                IResourceList dragResources = (IResourceList)data.GetData(typeof(IResourceList));

                // Check if really dropping over a view-folder
                if (!(targetResource.Type == FilterManagerProps.ViewFolderResName))
                {
                    return(DragDropEffects.None);
                }

                // Collect all the direct and indirect parents of the droptarget; then we'll check to avoid dropping parent on its children
                IntArrayList parentList = IntArrayListPool.Alloc();
                try
                {
                    IResource parent = targetResource;
                    while (parent != null)
                    {
                        parentList.Add(parent.Id);
                        parent = parent.GetLinkProp(Core.Props.Parent);
                    }

                    // Check
                    foreach (IResource res in dragResources)
                    {
                        // Dropping parent over its child?
                        if (parentList.IndexOf(res.Id) >= 0)
                        {
                            return(DragDropEffects.None);
                        }
                        // Can drop only views and view-folders on view-folders
                        if (!FilterRegistry.IsViewOrFolder(res))
                        {
                            return(DragDropEffects.None);
                        }
                    }
                    return(DragDropEffects.Move);
                }
                finally
                {
                    IntArrayListPool.Dispose(parentList);
                }
            }
            return(DragDropEffects.None);
        }
Beispiel #29
0
        public void ResourceNodeSelected(IResource res)
        {
            #region Preconditions

            if (res == null)
            {
                throw new ArgumentNullException("res", "FilterRegistry -- Input resource in node selection processing can not be NULL");
            }

            if (!FilterRegistry.IsViewOrFolder(res))
            {
                throw new ArgumentException("FilterRegistry -- IResourceTreeHandler is called with the resource of inappropriate type [" + res.Type + "]");
            }

            #endregion Preconditions

            //  Selecting a tree node (view) in the Shutdown mode is NOP.
            if (Core.State == CoreState.ShuttingDown)
            {
                return;
            }

            string viewName = res.GetPropText(Core.Props.Name);
            if (res.Type == FilterManagerProps.ViewResName)
            {
                if ((res == _lastSelectedView) && (_lastSelectedResult != null) &&
                    (Core.WorkspaceManager.ActiveWorkspace == _lastSelectedWorkspace) &&
                    (res.GetStringProp("DeepName") != FilterManagerProps.ViewUnreadDeepName) &&
                    (!res.HasProp("ForceExec")))
                {
                    Core.ResourceBrowser.DisplayConfigurableResourceList(res, _lastSelectedResult, _displayOptions);
                }
                else
                {
                    _lastSelectedResult = Core.FilterEngine.ExecView(res, viewName);
                    ConfigureDisplayOptions(res, viewName, _lastSelectedResult);
                    Core.ResourceBrowser.DisplayConfigurableResourceList(res, _lastSelectedResult, _displayOptions);
                }
                _lastSelectedView      = res;
                _lastSelectedWorkspace = Core.WorkspaceManager.ActiveWorkspace;
                new ResourceProxy(res).DeletePropAsync("ForceExec");
            }
            else
            {
                Core.ResourceBrowser.DisplayResourceList(res, Core.ResourceStore.EmptyResourceList, viewName, null);
            }
        }
Beispiel #30
0
        public DragDropEffects DragOver(IResource targetResource, IDataObject data, DragDropEffects allowedEffect, int keyState)
        {
            if (data.GetDataPresent(typeof(IResourceList)))
            {
                // The resources we're dragging
                IResourceList dragResources = (IResourceList)data.GetData(typeof(IResourceList));

                // Check if really dropping over our resource (resource tree root for Views'n'Cats)
                if (!(targetResource == Core.ResourceTreeManager.ResourceTreeRoot))
                {
                    return(DragDropEffects.None);
                }

                // Collect all the direct and indirect parents of the droptarget; then we'll check to avoid dropping parent on its children
                List <int> parentList = new List <int>();
                IResource  parent     = targetResource;
                while (parent != null)
                {
                    parentList.Add(parent.Id);
                    parent = parent.GetLinkProp(Core.Props.Parent);
                }

                // Check
                foreach (IResource res in dragResources)
                {
                    // Dropping parent over its child?
                    if (parentList.IndexOf(res.Id) >= 0)
                    {
                        return(DragDropEffects.None);
                    }
                    // Can drop only views, view-folders, and category-tree-roots on the views'n'cats tree root
                    if (!(
                            (FilterRegistry.IsViewOrFolder(res)) ||
                            ((res.Type == "ResourceTreeRoot") && (res.HasProp("RootResourceType")) && (res.GetStringProp("RootResourceType").StartsWith("Category")))
                            ))
                    {
                        return(DragDropEffects.None);
                    }
                }
                return(DragDropEffects.Move);
            }

            return(DragDropEffects.None);
        }
Beispiel #31
0
        public IResource  RegisterTrayIconRule(string name, string[] types,
                                               IResource[][] conditions, IResource[] exceptions,
                                               Icon icon)
        {
            IResource rule = FindRule(name);

            if (!WatchedLists.ContainsKey(name))
            {
                Trace.WriteLine("TrayIconManager -- Registering publicly rule [" + name + "].");

                ResourceProxy proxy = GetRuleProxy(rule);
                FilterRegistry.InitializeView(proxy, name, types, conditions, exceptions);   // proxy.EndUpdate inside
                Core.ResourceAP.RunJob(new AssignmentDelegate(AddSpecificParams), proxy.Resource, name, icon);
                InitializeWatcher(proxy.Resource, name, icon);
                return(proxy.Resource);
            }

            Trace.WriteLine("TrayIconManager -- rule [" + name + "] is already registered.");
            return(rule);
        }
Beispiel #32
0
        private void UpdateViews()
        {
            #region Preconditions
            if (_unreadResourcesToView.Count != 0 || _viewToUnreadResources.Count != 0)
            {
                throw new ApplicationException("ViewsUnreadCountProvider -- Contract violation - list are not disposed.");
            }
            #endregion Preconditions

            //  By default, we initially only account for non-trextindex views,
            //  since text index ones requre handling of the "text index ready" event.
            foreach (IResource view in _allViews)
            {
                if (ViewCanBeUnread(view) && !FilterRegistry.HasQueryCondition(view))
                {
                    IResourceList resList = ComputeList(view);
                    CrossRefItems(view, resList);
                    AttachToList(resList);
                }
            }
        }
        public void AddThenGetMatchesOneFilterOfOneType()
        {
            FakeUnityContainer container = new FakeUnityContainer();

            container.Add(new FakeActionFilter());

            FilterRegistry registry = new FilterRegistry(container);

            registry.Add(new[] { new FakeFilterCriteria()
                                 {
                                     IsMatch = true
                                 } }, typeof(FakeActionFilter));

            FilterInfo filters = registry.GetFilters(this.GetFakeContext());

            Assert.Equal(1, filters.ActionFilters.Count);
            Assert.IsType <FakeActionFilter>(filters.ActionFilters[0]);
            Assert.Equal(0, filters.AuthorizationFilters.Count);
            Assert.Equal(0, filters.ExceptionFilters.Count);
            Assert.Equal(0, filters.ResultFilters.Count);
        }
Beispiel #34
0
        public IResource  CloneRule(IResource sourceRule, string newName)
        {
            #region Preconditions
            if (!sourceRule.HasProp("IsFormattingFilter"))
            {
                throw new InvalidOperationException("FormattingRuleManager -- input resource is not a Formatting rule.");
            }

            IResource res = FindRule(newName);
            if (res != null)
            {
                throw new AmbiguousMatchException("FormattingRuleManager -- A Formatting rule with such name already exists.");
            }
            #endregion Preconditions

            ResourceProxy newRule = ResourceProxy.BeginNewResource(FilterManagerProps.ViewCompositeResName);
            FilterRegistry.CloneView(sourceRule, newRule, newName);
            CloneFormatting(sourceRule, newRule.Resource);

            return(newRule.Resource);
        }
Beispiel #35
0
        public IResource  CloneRule(IResource source, string newName)
        {
            #region Preconditions
            if (!source.HasProp("IsTrayIconFilter"))
            {
                throw new InvalidOperationException("TrayIconManager -- input resource is not a TrayIcon rule.");
            }

            IResource res = FindRule(newName);
            if (res != null)
            {
                throw new AmbiguousMatchException("TrayIconManager -- TrayIcon rule with such name already exists.");
            }
            #endregion Preconditions

            ResourceProxy newRule = GetRuleProxy(null);
            FilterRegistry.CloneView(source, newRule, newName);
            CloneStaticInfo(source, newRule.Resource);
            RegisterIconWatcher(newRule.Resource);

            return(newRule.Resource);
        }
        public void CanExecutePipeline()
        {
            var parameters = new Dictionary<string, object>();
            parameters.Add("FilterOrder", string.Empty);

            var step = new Step("13", "12", "Manager Approve", "Request Promotion",
                                    "Approve", DateTime.Now, "Spock", "Spock;Kirk",
                                    parameters);
            step.CanProcess = true;

            string filterNames = "ValidParticipantFilter;SaveDataFilter;FetchDataFilter;";
            string reverseOrderFilterNames = "FetchDataFilter;SaveDataFilter;ValidParticipantFilter;";

            var filterRegistry = new FilterRegistry<Step>();
            var pipeline = new Pipeline<Step>();
            pipeline.RegisterFromList(filterNames, filterRegistry)
                        .Execute(step);

            Assert.IsTrue((bool)step.Parameters["ValidFired"]);
            Assert.IsTrue((bool)step.Parameters["SaveDataFired"]);
            Assert.IsTrue((bool)step.Parameters["FetchDataFired"]);

            Assert.AreEqual(filterNames, step.Parameters["FilterOrder"].ToString());

            //  Change up order
            step.Parameters.Clear();
            step.Parameters.Add("FilterOrder", string.Empty);

            var revPipeline = new Pipeline<Step>();
            revPipeline.RegisterFromList(reverseOrderFilterNames, filterRegistry)
                                .Execute(step);

            Assert.IsTrue((bool)step.Parameters["ValidFired"]);
            Assert.IsTrue((bool)step.Parameters["SaveDataFired"]);
            Assert.IsTrue((bool)step.Parameters["FetchDataFired"]);

            Assert.AreEqual(reverseOrderFilterNames,
                            step.Parameters["FilterOrder"].ToString());
        }
Beispiel #37
0
        private void PerformSearch()
        {
            string query = _editHeading.Text.Trim();

            IResource[][] conditions = Controls2Resources(panelConditions.Controls);
            if (query.Length > 0)
            {
                IResource queryCondition = ((FilterRegistry)FMgr).CreateQueryConditionAux(null, query, comboSection.Text);
                FilterRegistry.ReferCondition2Template(queryCondition, FMgr.Std.BodyMatchesSearchQueryXName);

                //  Copy query condition to every subgroup or create the single one.
                if (conditions != null && conditions.Length > 0)
                {
                    for (int i = 0; i < conditions.Length; i++)
                    {
                        IResource[] group    = conditions[i];
                        IResource[] newGroup = new IResource[group.Length + 1];

                        for (int j = 0; j < group.Length; j++)
                        {
                            newGroup[j] = group[j];
                        }
                        newGroup[newGroup.Length - 1] = queryCondition;

                        conditions[i] = newGroup;
                    }
                }
                else
                {
                    conditions = FilterRegistry.Convert2Group(queryCondition);
                }
                UpdateStoredQueriesList(query);
            }

            IResource[] exceptions = ConvertTemplates2Conditions(panelExceptions.Controls);

            //-----------------------------------------------------------------
            //  need to remove existing basic View?
            //  NB: it removes all underlying AUX conditions including query search
            //-----------------------------------------------------------------
            IResource view = RStore.FindUniqueResource(FilterManagerProps.ViewResName, "DeepName", FMgr.ViewNameForSearchResults);

            string[] formTypes = ReformatTypes(CurrentResTypeDeep);
            if (view != null)
            {
                BaseResource = view;
                FMgr.ReregisterView(view, FMgr.ViewNameForSearchResults, formTypes, conditions, exceptions);
            }
            else
            {
                BaseResource = FMgr.RegisterView(FMgr.ViewNameForSearchResults, formTypes, conditions, exceptions);
            }

            //-----------------------------------------------------------------
            bool          showContext = (query.Length > 0) && Core.SettingStore.ReadBool("Resources", "ShowSearchContext", true);
            ResourceProxy proxy       = new ResourceProxy(BaseResource);

            proxy.BeginUpdate();
            proxy.SetProp(Core.Props.Name, SearchViewPrefix + query);
            proxy.SetProp(Core.Props.ShowDeletedItems, true);
            proxy.SetProp("ForceExec", true);
            proxy.SetProp("ShowContexts", showContext);
            if (BaseResource.HasProp(Core.Props.ContentType) || BaseResource.HasProp("ContentLinks"))
            {
                proxy.DeleteProp("ShowInAllTabs");
            }
            else
            {
                proxy.SetProp("ShowInAllTabs", true);
            }
            proxy.EndUpdate();

            //  if search is done specifically for the particular resource
            //  type - set the focus onto that tab.
            Core.ResourceTreeManager.LinkToResourceRoot(BaseResource, 1);
            if ((CurrentResTypeDeep != null) &&
                (CurrentResTypeDeep.IndexOf('|') == -1) && (CurrentResTypeDeep.IndexOf('#') == -1))
            {
                Core.TabManager.SelectResourceTypeTab(CurrentResTypeDeep);
            }
            else
            {
                Core.TabManager.SelectResourceTypeTab("");
            }

            Core.UIManager.BeginUpdateSidebar();
            Core.LeftSidebar.ActivateViewPane(StandardViewPanes.ViewsCategories);
            Core.UIManager.EndUpdateSidebar();
            Core.LeftSidebar.DefaultViewPane.SelectResource(BaseResource);
            BringToFront();
        }
        public void CanPreventMcCoyFromOverridingKirk()
        {
            string source = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\TestSuite\TestData\RedShirtPromotion.json";
            string preFilterNames = "FetchDataFilter;ValidParticipantFilter;";
            string postFilterNames = "SaveDataFilter";

            var workflow = DeserializeWorkflow(source);

            var parameters = new Dictionary<string, object>();
            parameters.Add("FilterOrder", string.Empty);
            parameters.Add("FetchDataFired", false);
            parameters.Add("SaveDataFired", false);
            parameters.Add("ValidFired", false);

            var step = new Step("13", "12", "RequestPromotionForm", "",
                                    "Complete", DateTime.Now, "RedShirtGuy", "Data;RedShirtGuy",
                                    parameters);
            step.CanProcess = true;

            var filterRegistry = new FilterRegistry<Step>();

            var processor = new WorkflowProcessor(step, filterRegistry, workflow);
            string newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            Assert.AreEqual("FirstOfficerReview", newState);

            step.Answer = "Approve";
            step.AnsweredBy = "Spock";
            step.Participants = "Spock;Kirk";
            step.State = newState;

            processor = new WorkflowProcessor(step, filterRegistry, workflow);
            newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            Assert.AreEqual("CaptainApproval", newState);

            //  Workflow will not process the trigger because
            //  the ValidParticipant filter will set setp.CanProcess to false
            step.Answer = "Approve";
            step.AnsweredBy = "McCoy";
            step.Participants = "Kirk";
            step.State = newState;

            processor = new WorkflowProcessor(step, filterRegistry, workflow);
            newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            Assert.AreEqual("CaptainApproval", newState);
            Assert.IsFalse(step.CanProcess);
            Assert.AreEqual(1, processor.GetErrorList().Count);
            Console.WriteLine(processor.GetErrorList()[0]);
        }
        public void CanPromoteRedShirtOffLandingParty()
        {
            string source = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\TestSuite\TestData\RedShirtPromotion.json";
            string preFilterNames = "FetchDataFilter;ValidParticipantFilter;";
            string postFilterNames = "SaveDataFilter";

            var workflow = DeserializeWorkflow(source);

            var parameters = new Dictionary<string, object>();
            parameters.Add("FilterOrder", string.Empty);
            parameters.Add("FetchDataFired", false);
            parameters.Add("SaveDataFired", false);
            parameters.Add("ValidFired", false);

            var step = new Step("13", "12", "RequestPromotionForm", "",
                                    "Complete", DateTime.Now, "RedShirtGuy", "Data;RedShirtGuy",
                                    parameters);
            step.CanProcess = true;

            var filterRegistry = new FilterRegistry<Step>();

            var processor = new WorkflowProcessor(step, filterRegistry, workflow);
            string newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            Assert.AreEqual("FirstOfficerReview", newState);

            step.Answer = "Approve";
            step.AnsweredBy = "Spock";
            step.Participants = "Spock;Kirk";
            step.State = newState;

            processor = new WorkflowProcessor(step, filterRegistry, workflow);
            newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            Assert.AreEqual("CaptainApproval", newState);

            step.Answer = "Approve";
            step.AnsweredBy = "Kirk";
            step.Participants = "Kirk";
            step.State = newState;

            processor = new WorkflowProcessor(step, filterRegistry, workflow);
            newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            Assert.AreEqual("PromotedOffLandingParty", newState);
        }
        public void CanAllowMcCoyToIssueUnfitForDuty()
        {
            string source = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\TestSuite\TestData\RedShirtPromotion.json";
            string pluginSource = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\TestSuite\TestPlugins";
            string preFilterNames = "FetchDataFilter;MorePlugins.TransporterDiagnosisFilter;ValidParticipantFilter;";
            string postFilterNames = "MorePlugins.TransporterRepairFilter;Plugins.CaptainUnfitForCommandFilter;SaveDataFilter;";

            var workflow = DeserializeWorkflow(source);

            var parameters = new Dictionary<string, object>();
            parameters.Add("FilterOrder", string.Empty);
            parameters.Add("FetchDataFired", false);
            parameters.Add("SaveDataFired", false);
            parameters.Add("ValidFired", false);

            //  Mission to beam down issue and the red shirt wants off
            var step = new Step("13", "12", "RequestPromotionForm", "",
                                    "Complete", DateTime.Now, "RedShirtGuy", "Data;RedShirtGuy",
                                    parameters);
            step.CanProcess = true;

            var filterRegistry = new FilterRegistry<Step>();
            filterRegistry.LoadPlugInsFromShare(pluginSource);

            var processor = new WorkflowProcessor(step, filterRegistry, workflow);
            string newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            //  Spock says he'll evaluate request
            Assert.AreEqual("FirstOfficerReview", newState);

            step.Answer = "Approve";
            step.AnsweredBy = "Spock";
            step.Participants = "Spock;Kirk";
            step.State = newState;

            processor = new WorkflowProcessor(step, filterRegistry, workflow);
            newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            Assert.AreEqual("CaptainApproval", newState);

            //  Captain Kirt denies request, but McCoy issues unfit for command
            parameters.Add("KirkInfected", true);

            step.Answer = "Deny";
            step.AnsweredBy = "Kirk";
            step.Participants = "Kirk";
            step.State = newState;

            processor = new WorkflowProcessor(step, filterRegistry, workflow);
            newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            //  Medical override issued and email to Starfleet generated
            bool medicalOverride = (bool)parameters["MedicalOverride"];
            bool emailSent = (bool)parameters["StarfleetEmail"];

            Assert.IsTrue(medicalOverride);
            Assert.IsTrue(emailSent);
        }
Beispiel #41
0
 public void  ShowAdvancedSearchForm(string query, string[] resTypes,
                                     IResource[] conditions, IResource[] exceptions)
 {
     IResource[][] group = FilterRegistry.Convert2Group(conditions);
     ShowAdvancedSearchForm(query, resTypes, group, exceptions);
 }
 private void RegisterInternal(FilterRegistry registry)
 {
 }
Beispiel #43
0
        public static IResource InstantiateTemplate(IResource template, object param,
                                                    string representation, string[] resTypes)
        {
            #region Preconditions
            if (template.Type != FilterManagerProps.ConditionTemplateResName)
            {
                throw new InvalidOperationException("Input parameter must be of ConditionTemplate resource type");
            }
            #endregion Preconditions

            string      propName = template.GetStringProp("ApplicableToProp");
            ConditionOp op       = (ConditionOp)template.GetProp("ConditionOp");

            //-----------------------------------------------------------------
            IResource condition;
            if (op == ConditionOp.Eq && ResourceTypeHelper.IsDateProperty(propName))
            {
                condition = TimeSpan2Condition((string)param, propName, resTypes);
            }
            else
            if (op == ConditionOp.QueryMatch)
            {
                string sectionName = null;
                if (template.HasProp("SectionOrder"))
                {
                    sectionName = DocSectionHelper.FullNameByOrder((uint)template.GetIntProp("SectionOrder"));
                }

                condition = fMgr.CreateQueryConditionAux(resTypes, (string)param, sectionName);
            }
            else
            if (op == ConditionOp.Eq || op == ConditionOp.Has)
            {
                condition = fMgr.CreateStandardConditionAux(resTypes, propName, op, (string)param);
            }
            else
            if (op == ConditionOp.In)
            {
                condition = fMgr.CreateStandardConditionAux(resTypes, propName, op, (IResourceList)param);
            }
            else
            if (op == ConditionOp.InRange)
            {
                condition = IntRange2Condition((string)param, propName);
            }
            else
            {
                throw new InvalidOperationException("Not all Operations are supported now");
            }

            FilterRegistry.ReferCondition2Template(condition, template);

            //-----------------------------------------------------------------
            //  Do not forget to set additional parameters from the template
            //  and representation, e.g. if the template has "custom" style,
            //  propagate it to the aux condition.
            //-----------------------------------------------------------------
            ResourceProxy proxy = new ResourceProxy(condition);
            proxy.BeginUpdate();

            if (template.GetStringProp("ConditionType") == "custom")
            {
                proxy.SetProp("ConditionType", "custom");
            }

            if (!String.IsNullOrEmpty(representation))
            {
                proxy.SetProp("SurfaceConditionVal", representation);
            }
            proxy.EndUpdate();

            return(condition);
        }
Beispiel #44
0
 private static bool CanUpdateTextView(IResource view)
 {
     return(ViewCanBeUnread(view) &&
            Core.TextIndexManager.IsIndexPresent() &&
            FilterRegistry.HasQueryCondition(view));
 }
        public void CanRegisterFilters()
        {
            var filterRegistry = new FilterRegistry<Step>();

            Assert.AreEqual(4, filterRegistry.GetFilterCount());
            Console.WriteLine(filterRegistry.GetFilterNames());
        }
        public void CanReportErrorsWithProcessor()
        {
            string source = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\TestSuite\TestData\RequestPromotion.json";
            string preFilterNames = "FetchDataFilter;ValidParticipantFilter;";
            string postFilterNames = "SaveDataFilter";

            var workflow = DeserializeWorkflow(source);

            var parameters = new Dictionary<string, object>();
            parameters.Add("FilterOrder", string.Empty);
            parameters.Add("FetchDataFired", false);
            parameters.Add("SaveDataFired", false);
            parameters.Add("ValidFired", false);

            var step = new Step("13", "12", "ManagerReview", "RequestPromotionForm",
                                    "Approve", DateTime.Now, "Data", "Spock;Kirk",
                                    parameters);
            step.CanProcess = true;

            var filterRegistry = new FilterRegistry<Step>();

            var processor = new WorkflowProcessor(step, filterRegistry, workflow);
            string newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            Assert.AreEqual("ManagerReview", newState);
            Assert.AreEqual(1, processor.GetErrorList().Count);
        }
 protected abstract void Register(FilterRegistry registry);
        public void CanRegisterFiltersWithRegistry()
        {
            string filterNames = "ValidParticipantFilter;SaveDataFilter;TriggerStateFilter";

            var filterRegistry = new FilterRegistry<Step>();
            var pipeline = new Pipeline<Step>();
            pipeline.RegisterFromList(filterNames, filterRegistry);

            Assert.AreEqual(3, pipeline.GetCount());
            Console.WriteLine(pipeline.GetNames());
        }
        public void CanIssueSpecialOrdersWithPlugin()
        {
            string source = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\TestSuite\TestData\RedShirtPromotion.json";
            string pluginSource = @"F:\vs10dev\ApprovaFlowSimpleWorkflowProcessor\TestSuite\TestPlugins";
            string preFilterNames = "FetchDataFilter;MorePlugins.TransporterDiagnosisFilter;ValidParticipantFilter;";
            string postFilterNames = "MorePlugins.TransporterRepairFilter;SaveDataFilter;";

            var workflow = DeserializeWorkflow(source);

            var parameters = new Dictionary<string, object>();
            parameters.Add("FilterOrder", string.Empty);
            parameters.Add("FetchDataFired", false);
            parameters.Add("SaveDataFired", false);
            parameters.Add("ValidFired", false);

            var step = new Step("13", "12", "RequestPromotionForm", "",
                                    "Complete", DateTime.Now, "RedShirtGuy", "Data;RedShirtGuy",
                                    parameters);
            step.CanProcess = true;

            var filterRegistry = new FilterRegistry<Step>();
            filterRegistry.LoadPlugInsFromShare(pluginSource);

            var processor = new WorkflowProcessor(step, filterRegistry, workflow);
            string newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            Assert.AreEqual("FirstOfficerReview", newState);

            step.Answer = "Approve";
            step.AnsweredBy = "Spock";
            step.Participants = "Spock;Kirk";
            step.State = newState;

            processor = new WorkflowProcessor(step, filterRegistry, workflow);
            newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            Assert.AreEqual("CaptainApproval", newState);

            //  Captain Kirt denies request, special order issued
            step.Answer = "Deny";
            step.AnsweredBy = "Kirk";
            step.Participants = "Kirk";
            step.State = newState;

            processor = new WorkflowProcessor(step, filterRegistry, workflow);
            newState = processor.ConfigurePipeline(preFilterNames, postFilterNames)
                        .ConfigureStateMachine()
                        .ProcessAnswer()
                        .GetCurrentState();

            Assert.AreEqual("Report to Shuttle Bay", step.Parameters["SpecialOrders"].ToString());
        }