Exemplo n.º 1
0
 public PolicyDescriptor(PolicyDescriptor src)
 {
     this.PolicyId    = src.PolicyId;
     this.Name        = src.Name;
     this.Description = src.Description;
     this.isActive    = src.isActive;
     this.CreatedOn   = src.CreatedOn;
 }
Exemplo n.º 2
0
        public void AddPolicy(PolicyDescriptor policy)
        {
            _policies.Add(policy.PolicyId, policy);

            foreach (var rule in policy.Rules.Values)
            {
                _policiesByRule.Add(rule.RuleId, policy);
            }
        }
Exemplo n.º 3
0
        private static PolicyCollection ParsePolicies(CxRestContext ctx,
                                                      CancellationToken token, JToken policyPayload)
        {
            PolicyCollection result = new PolicyCollection();

            using (JTokenReader reader = new JTokenReader(policyPayload))
                while (JsonUtils.MoveToNextProperty(reader, "id"))
                {
                    PolicyDescriptor policy = new PolicyDescriptor()
                    {
                        PolicyId = Convert.ToInt32(((JProperty)reader.CurrentToken).Value)
                    };

                    if (!JsonUtils.MoveToNextProperty(reader, "name"))
                    {
                        continue;
                    }
                    policy.Name = ((JProperty)reader.CurrentToken).Value.ToString();

                    if (!JsonUtils.MoveToNextProperty(reader, "description"))
                    {
                        continue;
                    }
                    policy.Description = ((JProperty)reader.CurrentToken).Value.ToString();

                    if (!JsonUtils.MoveToNextProperty(reader, "isActive"))
                    {
                        continue;
                    }
                    policy.isActive = Convert.ToBoolean(((JProperty)reader.CurrentToken).Value);

                    if (!JsonUtils.MoveToNextProperty(reader, "createdOn"))
                    {
                        continue;
                    }
                    policy.CreatedOn = JsonUtils.UtcEpochTimeToDateTime
                                           (Convert.ToInt64(((JProperty)reader.CurrentToken).Value) / 1000);

                    var rules = CxMnoPolicyRules.GetRulesForPolicy(ctx, token, policy.PolicyId);
                    policy.AddRule(rules);

                    result.AddPolicy(policy);
                }

            return(result);
        }