Exemplo n.º 1
0
        public override IGate Simplify()
        {
            IGate result = this;

            result = SimplifyNormalize(result);

            if (result.Type.IsFixed())
            {
                return(result);
            }

            if (IsProductOfInputs)
            {
                result = SimplifyProductOfInputs(result.GetProduct());
            }
            else
            {
                result = SimplifyMultiplicate(result);
                result = Gate.Simplify(result);
            }


            Gate.TraceSimplify(this, result, "simplify AND");

            return(result);
        }
Exemplo n.º 2
0
        private IGate SimplifyNormalize(IGate gate)
        {
            var list   = new List <IGate>();
            var inputs = gate.GetInputs();

            foreach (var e in gate.GetInputs())
            {
                if (e.Type == GateType.AND)
                {
                    list.AddRange(e.GetInputs());
                }
                else if (e.Type.IsFixed())
                {
                    if (e is FalseGate)
                    {
                        return(e);
                    }
                }
                else
                {
                    list.Add(e);
                }
            }

            var and = new ANDGate();

            and.AddInputRange(list);

            return(and);
        }
Exemplo n.º 3
0
        public static IGate SimplifyMultiplicate(IGate g)
        {
            Debug.Assert(g.Type == GateType.AND);

            var or = new ORGate();

            or.AddInput(new TrueGate());

            IGate r = or;

            foreach (var e in g.GetInputs())
            {
                if (e.Type == GateType.OR)
                {
                    r = Gate.Multiply(r.GetInputs(), e.GetInputs());
                }
                else
                {
                    r = Gate.Multiply(r.GetInputs(), e);
                }
            }

            r = Gate.Simplify(r);

            TraceSimplify(g, r, "simplify AND");

            return(r);
        }
Exemplo n.º 4
0
 public MembershipController(ISecurityUserReader securityUserReader, IGate gate, IAuthenticationService authenticationService, IDinnerReader dinnerReader)
 {
     _securityUserReader = securityUserReader;
     _gate = gate;
     _authenticationService = authenticationService;
     _dinnerReader          = dinnerReader;
 }
Exemplo n.º 5
0
 public DinnerController(IGate gate, IDinnerReader dinnerReader, IProfileReader profileReader, ISecurityUserReader securityUserReader)
 {
     _gate = gate;
     _dinnerReader = dinnerReader;
     _profileReader = profileReader;
     _securityUserReader = securityUserReader;
 }
Exemplo n.º 6
0
        //Check of er een loop in zit
        private bool IsComponentLoop(IGate toCheck)
        {
            //Een lijst van nodes die al gecheked zijn
            List <IGate> checkedNodes = new List <IGate>();
            //De inputs van de nodes die gechecked moeten worden
            Stack <IGate> toCheckStack = new Stack <IGate>(toCheck.GetInputs());

            //Zolang er inputs zijn die gechecked moeten worden
            while (toCheckStack.Count() > 0)
            {
                //Krijg de eerstvolgende input
                IGate current = toCheckStack.Pop();
                checkedNodes.Add(current);

                //Als er een loop is, return true
                if (current.GetInputs().Contains(toCheck))
                {
                    return(true);
                }

                foreach (IGate n in current.GetInputs())
                {
                    if (!checkedNodes.Contains(n))
                    {
                        toCheckStack.Push(n);
                    }
                }
            }

            //Alles is goed
            return(false);
        }
Exemplo n.º 7
0
        private IGate EvaluateRecurse(ICodeLabelEvaluator cg, IGate g)
        {
            if (g.Type == GateType.Input)
            {
                if (g is LabelGate)
                {
                    var lg = (LabelGate)g;
                    lg.Label.Evaluate(cg);
                }
            }
            else
            {
                var list = new List <IGate>();
                foreach (var i in g.GetInputs())
                {
                    var u = i;
                    var l = _gc.GetScheduledLabel(u);
                    if (null != l)
                    {
                        u = l;
                    }
                    else
                    {
                        u = EvaluateRecurse(cg, u);
                    }

                    list.Add(u);
                }

                g = SMG.Common.Gate.Compose(g.Type, list);
            }

            return(g);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Is the gate applicable for the current context
        /// </summary>
        /// <param name="gate">gate to check</param>
        /// <returns>true if applicable, false otherwise</returns>
        private bool IsGateApplicableInternal(IGate gate)
        {
            bool grantAccess = gate.IsGateEnabled;

            // If the gate is disabled but has been asked to be enabled through settings.
            if (m_settings?.GatesToggleEnabled?.Contains(gate.Name) ?? false)
            {
                grantAccess = true;
                ULSLogging.LogTraceTag(0x2382104e /* tag_967bo */, Categories.GateSelection, Levels.Verbose, "Enabling gate '{0}' through BRS that was disabled using gate toggle setting",
                                       gate.Name);
            }

            grantAccess = grantAccess && DoesHostEnvironmentHaveAccess(gate);
            grantAccess = grantAccess && DoesServiceHaveAccess(gate);
            grantAccess = grantAccess && DoesIPAddressHaveAccess(gate);
            grantAccess = grantAccess && DoesMarketHaveAccess(gate);
            grantAccess = grantAccess && DoesEnvironmentHaveAccess(gate);
            grantAccess = grantAccess && DoesBrowserHaveAccess(gate);
            grantAccess = grantAccess && DoesClientHaveAccess(gate);
            grantAccess = grantAccess && DoesUserHaveAccess(gate);
            grantAccess = grantAccess && IsCurrentDateEnabled(gate);
            grantAccess = grantAccess && DoQueryParametersHaveAccess(gate);
            grantAccess = grantAccess && DoesCloudContextHaveAccess(gate);

            if (gate.ExperimentInfo != null)
            {
                grantAccess = grantAccess && ExperimentContext.IsExperimentalGateApplicable(gate);
            }

            return(grantAccess);
        }
Exemplo n.º 9
0
 public static void TraceCompose(IGate a, IGate r, string format, params object[] args)
 {
     if (TraceFlags.ShowCompose)
     {
         Log.TraceGateOp2(a, r, format, args);
     }
 }
Exemplo n.º 10
0
 public static void TraceGuard(IGate gate1, IGate gate2, string p)
 {
     if (TraceFlags.ShowGuard)
     {
         TraceGateOp2(gate1, gate2, p);
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Sets the alias for an expression to an existing label.
        /// </summary>
        /// <param name="stage">The stage where to evaluate the gate.</param>
        /// <param name="e">The gate.</param>
        /// <param name="label">The label to refer to.</param>
        /// <param name="pstage"></param>
        public void SetAlias(int stage, IGate e, IGate r, int pstage)
        {
            e = e.Simplify();

            var id = GetCodeLabelIdentifier(stage, e);

            Debug.Assert(_gatemap.ContainsKey(r.ID));

            CodeLabel label;

            if (!_gatemap.TryGetValue(r.ID, out label))
            {
                throw new InvalidOperationException("label for gate not found.");
            }

            if (!_labels.ContainsKey(id))
            {
                _labels[id] = label;

                Gate.TraceLabel(e, label.Gate, stage + " alias");
            }
            else
            {
                //throw new Exception("label already defined.");
                Trace("label {0} already defined {0}, {1}", e, label.Gate);
            }


            AddToGateMap(e, label);
        }
Exemplo n.º 12
0
 public static void TraceDependencies(IGate a, IGate r, string format, params object[] args)
 {
     if (TraceFlags.ShowDepencencyAnalysis)
     {
         Log.TraceGateOp2(a, r, format, args);
     }
 }
Exemplo n.º 13
0
        public static void TraceGateOp3(IGate a, IGate b, IGate r, string format, params object[] args)
        {
            var text = string.Format(format, args);
            var line = a.ToString().PadRight(21) + " || " + b.ToString().PadRight(21) + " " + text.PadRight(20) + " ==> " + r.ToString();

            Trace("    {0}", line);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Replaces all variables not found in a guard with one.
        /// </summary>
        /// <param name="gate"></param>
        /// <param name="monitor"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private IGate ReplaceNonGuardVariables(IGate gate, Guard monitor)
        {
            // get variables referenced in the condition
            var variables = monitor.PreCondition
                            .SelectAll(e => e is IVariableCondition)
                            .OfType <IVariableCondition>()
                            .Select(u => u.Variable)
                            .Distinct();

            var vset = new HashSet <Variable>(variables);

            // TraceDependencies("monitor variables: {0}", variables.ToSeparatorList());

            IGate r = gate
                      .Replace(g =>
            {
                if (g is IVariableCondition)
                {
                    var vc = (IVariableCondition)g;
                    if (!vset.Contains(vc.Variable))
                    {
                        g = Gate.Constant(true);
                    }
                }

                return(g);
            })
                      .Simplify();

            return(r);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Replacer function for gate to code replacement.
        /// </summary>
        /// <param name="stage"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        private IGate ReplaceWithCodeLabel(int stage, IGate e)
        {
            if (e is LabelGate)
            {
                return(e);
            }

            var e0 = e;

            e = e.Simplify();

            int maxstage = stage;

            var children = e.SelectAll().OfType <LabelGate>();

            if (children.Any())
            {
                maxstage = children.Max(u => u.Label.Stage);
            }

            var label = AddCodeLabel(maxstage, e, false);

            if (e.Type == GateType.Input)
            {
                // leaf level of replacement, just refer to the new variable.
                e = label.Gate;
                // Gate.TraceLabel(e0, e, stage + " replace");
            }
            else
            {
                // guaranteed to contain only code labels, add to gatemap
            }

            return(e);
        }
Exemplo n.º 16
0
 public Connection(IGate outputee, int outputPin, IGate inputee, int inputPin)
 {
     Outputee  = outputee;
     Inputee   = inputee;
     OutputPin = outputPin;
     InputPin  = inputPin;
 }
Exemplo n.º 17
0
        public IGate AddGate(IGate g)
        {
            if (g.Type.IsFixed())
            {
                return(g);
            }
            else
            {
                var key = g.CacheKey;

                // try to find, including parents
                IGate r = Lookup(key);

                if (null == r)
                {
                    // add to cache
                    var gateid = "#" + _seed++;
                    g.Freeze(gateid);

                    _map[key] = r = g;
                    _list.Add(r);
                }

                return(r);
            }
        }
Exemplo n.º 18
0
 public MembershipController(ISecurityUserReader securityUserReader, IGate gate, IAuthenticationService authenticationService, IDinnerReader dinnerReader)
 {
     _securityUserReader = securityUserReader;
     _gate = gate;
     _authenticationService = authenticationService;
     _dinnerReader = dinnerReader;
 }
Exemplo n.º 19
0
        public IEnumerable <Transition> Match(IGate genter, IGate gleave)
        {
            var f1 = genter.GetProduct();
            var f2 = gleave.GetProduct();

            foreach (var f in f1.Factors)
            {
                // must exist ...
                var   t = GetTransitions(f.Variable).First();
                int[] indexes;
                if (f.Variable.Type.IsBoolean)
                {
                    indexes = new int[] { f.Inputs.First().IsInverted ? 0 : 1 };
                }
                else
                {
                    indexes = f.Inputs.Select(i => i.Address - i.Group).ToArray();
                }

                var q = t.PreStateIndexes.Intersect(indexes);

                if (!q.Any())
                {
                    // transition is not contained
                    yield break;
                }

                yield return(t);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Are any of the current query parameters blocked by the gate critera?
        /// </summary>
        /// <param name="gate">gate</param>
        /// <returns>true if no blocked query parameters match the requests query parmeters</returns>
        private bool DoQueryParametersHaveAccess(IGate gate)
        {
            bool grantAccess = true;
            IDictionary <string, HashSet <string> > blockedQueryParameters = gate.BlockedQueryParameters;

            if (blockedQueryParameters != null && blockedQueryParameters.Count > 0)
            {
                IDictionary <string, HashSet <string> > requestsQueryParameters = Request?.QueryParameters;
                //if no params exist on the request, then we grant access by default.
                if (requestsQueryParameters == null || requestsQueryParameters.Count == 0)
                {
                    ULSLogging.LogTraceTag(0x23821053 /* tag_967bt */, Categories.GateSelection, Levels.Verbose,
                                           "Allowing access to gate '{0}' as the GatedRequest has no query parameters.",
                                           gate.Name ?? "<NULL>");
                    return(grantAccess);
                }

                //if any request query param matches a blocked query param, we should not grant access.
                foreach (string requestParameterName in requestsQueryParameters.Keys)
                {
                    if (blockedQueryParameters.ContainsKey(requestParameterName))
                    {
                        //if the wild card '*' is specified as a value for a blocked param, then we restrict access
                        if (blockedQueryParameters[requestParameterName].Contains(Gate.BlockedQueryParameterValueWildCard))
                        {
                            grantAccess = false;

                            ULSLogging.LogTraceTag(0x23821054 /* tag_967bu */, Categories.GateSelection, Levels.Verbose,
                                                   "Not allowing access to gate '{0}' with the query parameter(s) '{1}'='{2}' as all parameters with name '{3}' are blocked by the wildcard '*'.",
                                                   gate.Name ?? "<NULL>",
                                                   requestParameterName,
                                                   requestsQueryParameters[requestParameterName],
                                                   requestParameterName);

                            break;
                        }

                        //if there's corresponding parameters in the request and the list of blocked, we do not grant access
                        IEnumerable <string> intersection = blockedQueryParameters[requestParameterName]
                                                            .Intersect(requestsQueryParameters[requestParameterName], StringComparer.OrdinalIgnoreCase);

                        if (intersection.Count() > 0)
                        {
                            grantAccess = false;

                            ULSLogging.LogTraceTag(0x23821055 /* tag_967bv */, Categories.GateSelection, Levels.Verbose,
                                                   "Not allowing access to gate '{0}' as the query parameter(s) '{1}'='{2}' is in the set of blocked query parameters '{3}'.",
                                                   gate.Name ?? "<NULL>",
                                                   requestParameterName,
                                                   string.Join(",", intersection),
                                                   string.Join(", ", blockedQueryParameters.Select(parameter => string.Format("'{0}={1}'", parameter.Key, parameter.Value))));

                            break;
                        }
                    }
                }
            }

            return(grantAccess);
        }
Exemplo n.º 21
0
 public static void TraceGuard(IGate gate1, IGate gate2, string p)
 {
     if (TraceFlags.ShowGuard)
     {
         TraceGateOp2(gate1, gate2, p);
     }
 }
Exemplo n.º 22
0
        /// <summary>
        /// Is the ip address of the request part of the gate criteria
        /// </summary>
        /// <param name="gate">gate</param>
        /// <returns>true if the ip address of the request matches the gate criteria, false otherwise</returns>
        private bool DoesIPAddressHaveAccess(IGate gate)
        {
            bool             grantAccess = true;
            HashSet <string> ipRanges    = gate.KnownIPRanges;

            if (ipRanges != null)
            {
                grantAccess = false;

                foreach (string ipRange in ipRanges)
                {
                    if (Request != null && Request.IsPartOfKnownIPRange(KnownIpAddresses, ipRange))
                    {
                        grantAccess = true;
                        break;
                    }
                }

                if (!grantAccess)
                {
                    ULSLogging.LogTraceTag(0x23821058 /* tag_967by */, Categories.GateSelection, Levels.Verbose,
                                           "Not allowing access to gate '{0}' as the ip address of the request is not in the set of allowed known ip ranges '{1}'.",
                                           gate.Name ?? "<NULL>", string.Join(", ", ipRanges));
                }
            }

            return(grantAccess);
        }
Exemplo n.º 23
0
 protected static void TraceSimplify(IGate a, IGate r, string format, params object[] args)
 {
     if (TraceFlags.ShowSimplify)
     {
         Log.TraceGateOp2(a, r, format, args);
     }
 }
Exemplo n.º 24
0
        public static IGate SimplifyMultiplicate(IGate g)
        {
            Debug.Assert(g.Type == GateType.AND);

            var or = new ORGate();
            or.AddInput(new TrueGate());

            IGate r = or;

            foreach (var e in g.GetInputs())
            {
                if (e.Type == GateType.OR)
                {
                    r = Gate.Multiply(r.GetInputs(), e.GetInputs());
                }
                else
                {
                    r = Gate.Multiply(r.GetInputs(), e);
                }
            }

            r = Gate.Simplify(r);

            TraceSimplify(g, r, "simplify AND");

            return r;
        }
Exemplo n.º 25
0
        /// <summary>
        /// Is the gate applicable for the current context
        /// </summary>
        /// <param name="gate">gate to check</param>
        /// <returns>true if applicable, false otherwise</returns>
        public bool IsGateApplicable(IGate gate)
        {
            if (!Code.ValidateArgument(gate, nameof(gate), TaggingUtilities.ReserveTag(0x2382104a /* tag_967bk */)) ||
                !Code.ValidateNotNullOrWhiteSpaceArgument(gate.Name, nameof(gate.Name), TaggingUtilities.ReserveTag(0x2382104b /* tag_967bl */)))
            {
                return(false);
            }

            if (IsKnownApplicableGate(gate.Name))
            {
                return(true);
            }

            if (IsKnownBlockedGate(gate.Name))
            {
                return(false);
            }

            bool grantAccess = IsGateApplicableInternal(gate);

            if (grantAccess)
            {
                KnownApplicableGates.AddOrUpdate(gate.Name, _ => 0, (_, __) => 0);
            }
            else
            {
                KnownBlockedGates.AddOrUpdate(gate.Name, _ => 0, (_, __) => 0);
            }

            return(grantAccess);
        }
Exemplo n.º 26
0
 private void CheckGate(IGate gate, bool[] results)
 {
     this.CheckGate(gate, false, false, results[0]);
     this.CheckGate(gate, false, true,  results[1]);
     this.CheckGate(gate, true,  false, results[2]);
     this.CheckGate(gate, true,  true,  results[3]);
 }
Exemplo n.º 27
0
 public DinnerController(IGate gate, IDinnerReader dinnerReader, IProfileReader profileReader, ISecurityUserReader securityUserReader)
 {
     _gate               = gate;
     _dinnerReader       = dinnerReader;
     _profileReader      = profileReader;
     _securityUserReader = securityUserReader;
 }
Exemplo n.º 28
0
        public IGate NewGate()
        {
            IGate g = null;

            if (!Selected)
            {
                return(g);
            }

            Type          t      = nameToType[group.SelectedButton.ID];
            List <Iinput> inputs = Inputs[Containers[group.SelectedButton.ID]];

            int             length = 0;
            ConstructorInfo ctor   = null;

            foreach (var cs in t.GetConstructors())
            {
                if (length <= cs.GetParameters().Length)
                {
                    length = cs.GetParameters().Length;
                    ctor   = cs;
                }
            }

            object[] param = new object[inputs.Count];

            for (int i = 0; i < inputs.Count; i++)
            {
                param[i] = GetInputValue(inputs[i]);
            }

            g = ctor.Invoke(param) as IGate;

            return(g);
        }
Exemplo n.º 29
0
 private void AssertGate(IGate expected,
                         IGate actual)
 {
     Console.WriteLine("Comparing Gate with id {0} and {1}...",
                       expected.Id,
                       actual.Id);
 }
Exemplo n.º 30
0
        public static void Connect(IGate output, int outputPin, IGate input, int inputPin)
        {
            Connection connection = new Connection(output, outputPin, input, inputPin);

            output.SetOutputConnection(connection);
            input.SetInputConnection(connection);
        }
Exemplo n.º 31
0
        private IGate Create(NetworkType itype)
        {
            IGate result = null;

            var asm = Assembly.GetExecutingAssembly().GetTypes();

            foreach (var type in asm)
            {
                //if (!type.IsClass || type.IsNotPublic) continue;

                Type[] interfaces = type.GetInterfaces();

                if (((IList)interfaces).Contains(typeof(IGate)))
                {
                    if (type.Name.Contains(itype.ToString()))
                    {
                        object obj = Activator.CreateInstance(type);
                        result = (IGate)obj;
                        break;
                    }
                }
            }

            return(result);
        }
Exemplo n.º 32
0
        /// <summary>
        /// Schedules a gate for evaluation
        /// </summary>
        /// <param name="gate"></param>
        public void Schedule(IGate gate)
        {
            if (gate.Type.IsFixed())
            {
                return;
            }

            var g  = gate.Simplify();
            var id = GetCodeLabelIdentifier(CurrentStage, g);

            CodeLabel label;

            if (_labels.TryGetValue(id, out label))
            {
                Gate.TraceLabel(g, label.Gate, "schedule ...");
                label.Schedule();
            }
            else
            {
                Gate.TraceLabel(g, g, "schedule elements ...");
                foreach (var e in gate.SelectAll().OfType <LabelGate>())
                {
                    ((LabelGate)e).Schedule();
                }
            }
        }
Exemplo n.º 33
0
 public static IEnumerable <Variable> GetVariables(this IGate gate)
 {
     return(gate
            .GetVariableConditions()
            .Select(e => e.Variable)
            .OrderBy(v => v.Index)
            .Distinct());
 }
Exemplo n.º 34
0
        protected TransitionMonitor(TransitionSet tset, IGate pre, IGate post)
        {
            _transitions = tset;

            Name          = "internal";
            PreCondition  = pre;
            PostCondition = post;
        }
Exemplo n.º 35
0
        protected TransitionMonitor(TransitionSet tset, IGate pre, IGate post)
        {
            _transitions = tset;

            Name = "internal";
            PreCondition = pre;
            PostCondition = post;
        }
Exemplo n.º 36
0
        public Response DeleteById(int id)
        {
            IGate response = m_InformationFinder.Delete(id);

            return(response == null
                       ? HttpStatusCode.NotFound
                       : AsJson(response));
        }
Exemplo n.º 37
0
 public FullAdder()
 {
     xor1=new XorGate();
     xor2=new XorGate();
     and1=new AndGate();
     and2=new AndGate();
     or=new OrGate();
 }
Exemplo n.º 38
0
        /// <summary>
        /// Composes two gates given the operator as a parameter.
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns>The resulting gate.</returns>
        public static IGate Compose(GateType type, IGate a, IGate b)
        {
            switch(type)
            {
                case GateType.OR:
                    return ComposeOR(a, b);

                case GateType.AND:
                    return ComposeAND(a, b);

                default:
                    throw new ArgumentException();
            }
        }
Exemplo n.º 39
0
 public void Enable(Feature feature, IGate gate, object thing)
 {
     if (gate.DataType == typeof (bool) || gate.DataType == typeof (int))
     {
         Write(Key(feature, gate), thing.ToString().ToLower());
     }
     else if (gate.DataType == typeof (ISet<string>))
     {
         AddToSet(Key(feature, gate), thing.ToString());
     }
     else
     {
         UnsupportedDataType(gate);
     }
 }
Exemplo n.º 40
0
        internal CodeLabel(GateConverter gc, int stage, int index, string name, IGate g)
            : this(index, name)
        {
            _gc = gc;
            _originalgate = _gate = g;

            Stage = stage;

            Debug.Assert(!(g is CodeLabel));

            // if (g is IVariableCondition)
            {
                _gate = new LabelGate(this);
            }
        }
Exemplo n.º 41
0
        /// <summary>
        /// Converts a gate into a label gate.
        /// </summary>
        /// <param name="stage">The execution stage where the label is evaluated.</param>
        /// <param name="g">The gate to convert.</param>
        /// <returns>The converted gate.</returns>
        public IGate ConvertToGate(int stage, IGate g)
        {
            // simplify to get cached
            g = Gate.Simplify(g);

            if(g.Type.IsFixed())
            {
                //throw new Exception("cannot convert fixed gate.");
                return g;
            }

            if (!(g is LabelGate))
            {
                g = MakeCodeLabels(stage, g);
            }

            return g;
        }
Exemplo n.º 42
0
 public void Disable(Feature feature, IGate gate, object thing)
 {
     if (gate.DataType == typeof(bool))
     {
         _database.KeyDelete(feature.Key);
     }
     else if (gate.DataType == typeof(int))
     {
         _database.HashSet(feature.Key, gate.Key, thing.ToString());
     }
     else if (gate.DataType == typeof(ISet<string>))
     {
         _database.HashDelete(feature.Key, ToField(gate, thing));
     }
     else
     {
         UnsupportedDataType(gate);
     }
 }
Exemplo n.º 43
0
 public void Disable(Feature feature, IGate gate, object thing)
 {
     if (gate.DataType == typeof (bool))
     {
         Clear(feature);
     }
     else if (gate.DataType == typeof (int))
     {
         Write(Key(feature, gate), thing.ToString());
     }
     else if (gate.DataType == typeof (ISet<string>))
     {
         RemoveFromSet(Key(feature, gate), thing.ToString());
     }
     else
     {
         UnsupportedDataType(gate);
     }
 }
Exemplo n.º 44
0
        private static void SimplifyConstants(ref IGate gate)
        {
            var inputs = gate.GetInputs();
            var list = new List<IGate>();

            foreach (var i in inputs)
            {
                if (i is TrueGate)
                {
                    // sum is constant => TRUE
                    gate = new TrueGate();
                    return;
                }
                else if (i is FalseGate)
                {
                    // remove any FALSE gates ...
                }
                else if (i.GetNestingLevel() > 1)
                {
                    var r = i.Simplify();
                    if (r.Type == GateType.OR)
                    {
                        list.AddRange(r.GetInputs());
                    }
                    else
                    {
                        list.Add(r);
                    }
                }
                else
                {
                    var r = i.Simplify();
                    list.Add(r);
                }
            }

            gate = ConsolidateList(list);
        }
Exemplo n.º 45
0
        public TransitionCondition(ICondition lcond, ICondition rcond)
        {
            if (lcond.ContainsTransitions() || rcond.ContainsTransitions())
            {
                throw new CompilerException(ErrorCode.BadCondition,
                    "arguments to transition condition must not include transitions.");
            }

            // right hand must be a product
            var r = rcond.Decompose(ConditionMode.Static);
            if(r.Type == GateType.OR)
            {
                throw new CompilerException(ErrorCode.BadCondition,
                    "right side of a transition must be a product.");
            }

            _rgate = r;

            var rvclist = r.GetVariableConditions().ToArray();

            var l = lcond.Decompose(ConditionMode.Static);

            // split left side into terms ...
            IEnumerable<IGate> terms = new[] { l };
            if(l.Type == GateType.OR)
            {
                terms = l.GetInputs();
            }

            // construct the transition set from the left side terms and the right side product.
            var tset = BuildTransitionSet(terms, rvclist);

            Left = lcond;
            Right = rcond;
            Transitions = tset;
        }
Exemplo n.º 46
0
 private IGate Convert(GateConverter gc, int stage, IGate c)
 {
     //return gc.ConvertToGate(stage, c);
     return c;
 }
Exemplo n.º 47
0
 public HomeController(ISecurityUserReader securityUserReader, IGate gate, IShipReader shipReader)
 {
     _securityUserReader = securityUserReader;
     _gate = gate;
     _shipReader = shipReader;
 }
Exemplo n.º 48
0
 public void ReplaceInput(int j, IGate input)
 {
     ValidateCanModify();
     _inputs[j] = input;
 }
Exemplo n.º 49
0
        private IGate EvaluateRecurse(ICodeLabelEvaluator cg, IGate g)
        {
            if (g.Type == GateType.Input)
            {
                if (g is LabelGate)
                {
                    var lg = (LabelGate)g;
                    lg.Label.Evaluate(cg);
                }
            }
            else
            {
                var list = new List<IGate>();
                foreach (var i in g.GetInputs())
                {
                    var u = i;
                    var l = _gc.GetScheduledLabel(u);
                    if (null != l)
                    {
                        u = l;
                    }
                    else
                    {
                        u = EvaluateRecurse(cg, u);
                    }

                    list.Add(u);
                }

                g = SMG.Common.Gate.Compose(g.Type, list);
            }

            return g;
        }
Exemplo n.º 50
0
 private static void UnsupportedDataType(IGate gate)
 {
     throw new NotSupportedException(string.Format("{0} is not supported by this adapter yet", gate.Name));
 }
Exemplo n.º 51
0
 public virtual void AddInput(IGate gate)
 {
     ValidateCanModify();
     Debug.Assert(Type.IsLogical());
     _inputs.Add(gate);
 }
Exemplo n.º 52
0
 /// <summary>
 /// Replaces variables conditions in a gate with the pre or post conditions.
 /// </summary>
 /// <param name="e">The gate to replace.</param>
 /// <param name="post">True if the post condition shall be evaluated, false otherwise.</param>
 /// <returns>The resulting gate.</returns>
 private IGate ReplaceVariableCondition(TransitionSet tset, IGate e, bool post)
 {
     return e.Replace(g => ReplaceVariableConditionHandler(tset, g, post));
 }
Exemplo n.º 53
0
        /// <summary>
        /// Replaces composite state conditions with their elementary equivalents.
        /// </summary>
        /// <param name="e"></param>
        /// <param name="post"></param>
        /// <returns></returns>
        private IGate ReplaceVariableConditionHandler(TransitionSet tset, IGate e, bool post)
        {
            IGate result = e;

            if (e is IVariableCondition)
            {
                var c = (IVariableCondition)e;
                var tlist = tset.GetTransitions(c.Variable);
                var count = tlist.Count();

                if(0 == count)
                {
                    // no transitions for this variable, keep
                }
                else if (count > 1)
                {
                    throw new CompilerException(ErrorCode.AmbigousPreCondition,
                        "multiple transitions for variable '" + c.Variable + "'.");
                }
                else
                {
                    // unique post state required
                    var t = tlist.First();
                    var stateindexes = post ? t.NewStateIndexes : t.PreStateIndexes;
                    if (stateindexes.Length != 1)
                    {
                        throw new CompilerException(ErrorCode.AmbigousPreCondition,
                            "ambigous variable condition.");
                    }

                    // replace with elementary
                    result = c.CreateElementaryCondition(stateindexes.First());
                }
            }

            // Gate.TraceDecompose(e, result, "var repl {0}", post);

            return result;
        }
Exemplo n.º 54
0
 /// <summary>
 /// Replaces variable conditions refering to a transition set with constants.
 /// </summary>
 /// <param name="tset">The transition set.</param>
 /// <param name="gate">The gate to translate.</param>
 /// <param name="value"></param>
 /// <returns>The resulting modified gate.</returns>
 private IGate ReplaceTransitionVariables(TransitionSet tset, IGate gate, bool value)
 {
     return gate
         .Replace(g => ReplaceTransitionVariablesHandler(tset, g, value))
         .Simplify();
 }
Exemplo n.º 55
0
        private IGate ReplaceTransitionVariablesHandler(TransitionSet tset, IGate q, bool value)
        {
            var result = q;

            if (result is IVariableCondition)
            {
                var vc = ((IVariableCondition)result);
                if (!tset.Contains(vc.Variable))
                {
                    result = Gate.Constant(value);
                }
            }

            return result;
        }
Exemplo n.º 56
0
        /// <summary>
        /// Replaces all variables not found in a guard with one.
        /// </summary>
        /// <param name="gate"></param>
        /// <param name="monitor"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private IGate ReplaceNonGuardVariables(IGate gate, Guard monitor)
        {
            // get variables referenced in the condition
            var variables = monitor.PreCondition
                .SelectAll(e => e is IVariableCondition)
                .OfType<IVariableCondition>()
                .Select(u => u.Variable)
                .Distinct();

            var vset = new HashSet<Variable>(variables);

            // TraceDependencies("monitor variables: {0}", variables.ToSeparatorList());

            IGate r = gate
                .Replace(g =>
                {
                    if (g is IVariableCondition)
                    {
                        var vc = (IVariableCondition)g;
                        if (!vset.Contains(vc.Variable))
                        {
                            g = Gate.Constant(true);
                        }
                    }

                    return g;
                })
                .Simplify();

            return r;
        }
Exemplo n.º 57
0
 private string Key(Feature feature, IGate gate)
 {
     return feature.Key + "/" + gate.Key;
 }
Exemplo n.º 58
0
 public TaskRunnerController(IGate gate)
 {
     _gate = gate;
 }
Exemplo n.º 59
0
 public MyEventsController(IDinnerReader dinnerReader, IGate gate)
 {
     _dinnerReader = dinnerReader;
     _gate = gate;
 }
Exemplo n.º 60
0
 public ProfileController(IGate gate, IProfileReader profileReader)
 {
     _gate = gate;
     _profileReader = profileReader;
 }