Ejemplo n.º 1
0
        private async Task <ActionResult> Show(string domain, string apiToken)
        {
            var apiUri = new UriBuilder("https", domain, 443, "api/v2").Uri;

            var apiClient = new ManagementApiClient(apiToken, apiUri);

            var appsTask  = apiClient.Clients.GetAllAsync(fields: "name,client_id,global");
            var rulesTask = apiClient.Rules.GetAllAsync(fields: "name,script,id,enabled,order");

            // if we want rules for all stages:
            //var rulesStages = new[] { "login_success", "login_failure", "pre_authorize", "user_registration", "user_blocked" };
            //var rulesTask =
            //    Task.WhenAll(
            //        rulesStages.Select(
            //            stage => apiClient.Rules.GetAllAsync(fields: "name,script,id,enabled,order", stage: stage)))
            //        .ContinueWith(t => t.Result.SelectMany(r => r));
            await Task.WhenAll(appsTask, rulesTask);

            var apps = appsTask.Result
                       // "All Applications" is a special client app, not meant to be managed by the user.
                       .Where(a => a.Name != "All Applications");
            var rules = rulesTask.Result;

            var matches = RulesMatcher.FindMatches(rules, apps);

            var model = new AppsViewModel()
            {
                Clients = apps.Select(
                    c => new ClientToRulesViewModel()
                {
                    Client = c,
                    Rules  =
                        matches.Where(
                            p => p.Value == null || p.Value.MatchedClients.Contains(c))
                        .Select(
                            p => new RelatedRuleViewModel(p.Key)
                    {
                        SpecificForApp = p.Value != null
                    })
                }),
                Rules = matches
            };

            this.ViewBag.Domain = domain;

            return(this.View("Index", model));
        }
Ejemplo n.º 2
0
 public void SetUp()
 {
     containingObject = new GameObject();
     subject          = containingObject.AddComponent <RulesMatcher>();
 }
Ejemplo n.º 3
0
        protected virtual void CreateComponent(OptionType selectedOption)
        {
            GameObject componentContainer = new GameObject(componentName);

            if (selectedObject != null && nestInSelectedObject)
            {
                componentContainer.transform.SetParent(selectedObject.transform);
            }

            GameObject listContainer = new GameObject("ListContainer");

            listContainer.transform.SetParent(componentContainer.transform);

            switch (selectedOption)
            {
            case OptionType.AllRule:
                AllRule allRule = componentContainer.AddComponent <AllRule>();
                RuleContainerObservableList allList = listContainer.AddComponent <RuleContainerObservableList>();
                allRule.Rules = allList;
                break;

            case OptionType.AnyRule:
                AnyRule anyRule = componentContainer.AddComponent <AnyRule>();
                RuleContainerObservableList anyList = listContainer.AddComponent <RuleContainerObservableList>();
                anyRule.Rules = anyList;
                break;

            case OptionType.AnyBehaviourEnabledRule:
                AnyBehaviourEnabledRule behaviourRule = componentContainer.AddComponent <AnyBehaviourEnabledRule>();
                SerializableTypeBehaviourObservableList behaviourList = listContainer.AddComponent <SerializableTypeBehaviourObservableList>();
                behaviourRule.BehaviourTypes = behaviourList;
                break;

            case OptionType.AnyComponentTypeRule:
                AnyComponentTypeRule componentRule = componentContainer.AddComponent <AnyComponentTypeRule>();
                SerializableTypeComponentObservableList componentList = listContainer.AddComponent <SerializableTypeComponentObservableList>();
                componentRule.ComponentTypes = componentList;
                break;

            case OptionType.AnyTagRule:
                AnyTagRule           tagRule = componentContainer.AddComponent <AnyTagRule>();
                StringObservableList tagList = listContainer.AddComponent <StringObservableList>();
                tagRule.Tags = tagList;
                break;

            case OptionType.BehaviourEnabledObserver:
                BehaviourEnabledObserver behaviourEnabledObserver = componentContainer.AddComponent <BehaviourEnabledObserver>();
                BehaviourObservableList  behaviourObservableList  = listContainer.AddComponent <BehaviourObservableList>();
                behaviourEnabledObserver.Behaviours = behaviourObservableList;
                break;

            case OptionType.ListContainsRule:
                ListContainsRule          listRule = componentContainer.AddComponent <ListContainsRule>();
                UnityObjectObservableList listList = listContainer.AddComponent <UnityObjectObservableList>();
                listRule.Objects = listList;
                break;

            case OptionType.RulesMatcher:
                RulesMatcher matcherRule = componentContainer.AddComponent <RulesMatcher>();
                RulesMatcherElementObservableList matcherList = listContainer.AddComponent <RulesMatcherElementObservableList>();
                matcherRule.Elements = matcherList;
                break;

            case OptionType.ActionRegistrar:
                ActionRegistrar actionRegistrar = componentContainer.AddComponent <ActionRegistrar>();
                ActionRegistrarSourceObservableList registrarList = listContainer.AddComponent <ActionRegistrarSourceObservableList>();
                GameObjectObservableList            limitsList    = listContainer.AddComponent <GameObjectObservableList>();
                actionRegistrar.Sources      = registrarList;
                actionRegistrar.SourceLimits = limitsList;
                break;

            case OptionType.AllAction:
                AllAction            allAction     = componentContainer.AddComponent <AllAction>();
                ActionObservableList allActionList = listContainer.AddComponent <ActionObservableList>();
                allAction.Actions = allActionList;
                break;

            case OptionType.AnyAction:
                AnyAction            anyAction     = componentContainer.AddComponent <AnyAction>();
                ActionObservableList anyActionList = listContainer.AddComponent <ActionObservableList>();
                anyAction.Actions = anyActionList;
                break;

            case OptionType.GameObjectsAssociationActivator:
                GameObjectsAssociationActivator      gameObjectsAssociationActivator = componentContainer.AddComponent <GameObjectsAssociationActivator>();
                GameObjectsAssociationObservableList gameObjectsAssociationList      = listContainer.AddComponent <GameObjectsAssociationObservableList>();
                gameObjectsAssociationActivator.Associations = gameObjectsAssociationList;
                break;

            case OptionType.GameObjectRelations:
                GameObjectRelations gameObjectRelations = componentContainer.AddComponent <GameObjectRelations>();
                GameObjectRelationObservableList gameObjectsRelationsList = listContainer.AddComponent <GameObjectRelationObservableList>();
                gameObjectRelations.Relations = gameObjectsRelationsList;
                break;

            case OptionType.GameObjectStateSwitcher:
                GameObjectStateSwitcher  gameObjectStateSwitcher = componentContainer.AddComponent <GameObjectStateSwitcher>();
                GameObjectObservableList gameObjectsList         = listContainer.AddComponent <GameObjectObservableList>();
                gameObjectStateSwitcher.Targets = gameObjectsList;
                break;

            case OptionType.PlatformDeviceAssociation:
                PlatformDeviceAssociation platformDeviceAssociation = componentContainer.AddComponent <PlatformDeviceAssociation>();
                GameObjectObservableList  platformGameObjectsList   = listContainer.AddComponent <GameObjectObservableList>();
                platformDeviceAssociation.GameObjects = platformGameObjectsList;
                break;

            case OptionType.HapticProcessor:
                HapticProcessor             hapticProcessor = componentContainer.AddComponent <HapticProcessor>();
                HapticProcessObservableList hapticList      = listContainer.AddComponent <HapticProcessObservableList>();
                hapticProcessor.HapticProcesses = hapticList;
                break;

            case OptionType.MeshStateModifier:
                MeshStateModifier meshStateModifier = componentContainer.AddComponent <MeshStateModifier>();
                GameObjectMultiRelationObservableList gameObjectMultiRelationList = listContainer.AddComponent <GameObjectMultiRelationObservableList>();
                meshStateModifier.MeshCollections = gameObjectMultiRelationList;
                break;

            case OptionType.MomentProcessor:
                MomentProcessor             momentProcessor     = componentContainer.AddComponent <MomentProcessor>();
                MomentProcessObservableList momentProcessorList = listContainer.AddComponent <MomentProcessObservableList>();
                momentProcessor.Processes = momentProcessorList;
                break;

            case OptionType.CompositeProcess:
                CompositeProcess            compositeProcessor     = componentContainer.AddComponent <CompositeProcess>();
                MomentProcessObservableList compositeProcessorList = listContainer.AddComponent <MomentProcessObservableList>();
                compositeProcessor.Processes = compositeProcessorList;
                break;

            case OptionType.VelocityTrackerProcessor:
                VelocityTrackerProcessor      velocityTrackerProcessor = componentContainer.AddComponent <VelocityTrackerProcessor>();
                VelocityTrackerObservableList velocityTrackerList      = listContainer.AddComponent <VelocityTrackerObservableList>();
                velocityTrackerProcessor.VelocityTrackers = velocityTrackerList;
                break;

            case OptionType.FloatAdder:
                FloatAdder          floatAdder = componentContainer.AddComponent <FloatAdder>();
                FloatObservableList floatList  = listContainer.AddComponent <FloatObservableList>();
                floatAdder.Collection = floatList;
                break;

            case OptionType.FloatMaxFinder:
                FloatMaxFinder      floatMaxFinder     = componentContainer.AddComponent <FloatMaxFinder>();
                FloatObservableList floatMaxFinderList = listContainer.AddComponent <FloatObservableList>();
                floatMaxFinder.Collection = floatMaxFinderList;
                break;

            case OptionType.FloatMeanFinder:
                FloatMeanFinder     floatMeanFinder     = componentContainer.AddComponent <FloatMeanFinder>();
                FloatObservableList floatMeanFinderList = listContainer.AddComponent <FloatObservableList>();
                floatMeanFinder.Collection = floatMeanFinderList;
                break;

            case OptionType.FloatMedianFinder:
                FloatMedianFinder   floatMedianFinder     = componentContainer.AddComponent <FloatMedianFinder>();
                FloatObservableList floatMedianFinderList = listContainer.AddComponent <FloatObservableList>();
                floatMedianFinder.Collection = floatMedianFinderList;
                break;

            case OptionType.FloatMinFinder:
                FloatMinFinder      floatMinFinder     = componentContainer.AddComponent <FloatMinFinder>();
                FloatObservableList floatMinFinderList = listContainer.AddComponent <FloatObservableList>();
                floatMinFinder.Collection = floatMinFinderList;
                break;

            case OptionType.FloatModeFinder:
                FloatModeFinder     floatModeFinder     = componentContainer.AddComponent <FloatModeFinder>();
                FloatObservableList floatModeFinderList = listContainer.AddComponent <FloatObservableList>();
                floatModeFinder.Collection = floatModeFinderList;
                break;

            case OptionType.FloatMultiplier:
                FloatMultiplier     floatMultiplier     = componentContainer.AddComponent <FloatMultiplier>();
                FloatObservableList floatMultiplierList = listContainer.AddComponent <FloatObservableList>();
                floatMultiplier.Collection = floatMultiplierList;
                break;

            case OptionType.FloatRangeFinder:
                FloatRangeFinder    floatRangeFinder     = componentContainer.AddComponent <FloatRangeFinder>();
                FloatObservableList floatRangeFinderList = listContainer.AddComponent <FloatObservableList>();
                floatRangeFinder.Collection = floatRangeFinderList;
                break;

            case OptionType.Vector2Multiplier:
                Vector2Multiplier     vector2Multiplier     = componentContainer.AddComponent <Vector2Multiplier>();
                Vector2ObservableList vector2MultiplierList = listContainer.AddComponent <Vector2ObservableList>();
                vector2Multiplier.Collection = vector2MultiplierList;
                break;

            case OptionType.Vector3Multiplier:
                Vector3Multiplier     vector3Multiplier     = componentContainer.AddComponent <Vector3Multiplier>();
                Vector3ObservableList vector3MultiplierList = listContainer.AddComponent <Vector3ObservableList>();
                vector3Multiplier.Collection = vector3MultiplierList;
                break;

            case OptionType.Vector3Subtractor:
                Vector3Subtractor     vector3Subtractor     = componentContainer.AddComponent <Vector3Subtractor>();
                Vector3ObservableList vector3SubtractorList = listContainer.AddComponent <Vector3ObservableList>();
                vector3Subtractor.Collection = vector3SubtractorList;
                break;
            }
        }
        public void FindsMatches()
        {
            var apps = new[]
            {
                new Client()
                {
                    ClientId = "Id0", Name = "Name0"
                },
                new Client()
                {
                    ClientId = "Id1", Name = "Name1"
                },
                new Client()
                {
                    ClientId = "Id2", Name = "Name2"
                },
                new Client()
                {
                    ClientId = "Id3", Name = "RepeatedName"
                },
                new Client()
                {
                    ClientId = "Id4", Name = "RepeatedName"
                }
            };

            var rules = new[]
            {
                new Rule()
                {
                    Id = "r0", Script = "xxxx if (context.clientId === 'Id0') xxx"
                },
                new Rule()
                {
                    Id = "r1", Script = "xxx if (context.clientId === 'Id1') xxx"
                },
                new Rule()
                {
                    Id = "r2", Script = "xxx if (context.clientId !== 'Id0') xxx"
                },
                new Rule()
                {
                    Id = "r3", Script = "xxx if (context.clientName === 'Name0') xxx"
                },
                new Rule()
                {
                    Id = "r4", Script = "xxx NoAppReference xxx"
                },
                new Rule()
                {
                    Id = "r5", Script = "xxx if (context.clientId === 'Id9') xxx"
                },
                new Rule()
                {
                    Id = "r6", Script = "xxx if (context.clientName === 'RepeatedName') xxx"
                }
            };

            var result = RulesMatcher.FindMatches(rules, apps);

            Assert.IsTrue(result[rules[0]].MatchedClients.Contains(apps[0]));
            Assert.IsTrue(result[rules[2]].MatchedClients.Contains(apps[0]));
            Assert.IsTrue(result[rules[3]].MatchedClients.Contains(apps[0]));
            Assert.IsTrue(result[rules[1]].MatchedClients.Contains(apps[1]));
            Assert.IsTrue(result[rules[5]].Reference.ClientId == "Id9" && !result[rules[5]].MatchedClients.Any(),
                          "There should be a mention to Rule 5, even if the client reference doesn't match any client.");
            Assert.IsNull(result[rules[4]], "Rule 4 should have a null value because it has no reference.");
            Assert.IsTrue(result[rules[6]].MatchedClients.Contains(apps[3]) && result[rules[6]].MatchedClients.Contains(apps[4]),
                          "Rule 6 should contain reference to both applications that have the same name.");
            Assert.AreEqual(rules.Length, result.Count);
        }