示例#1
0
        public QueryContext(IGraphContext graphService, RequestQuery query) : this(graphService.Graph.Address.Count)
        {
            GraphService = graphService;
            if (query.Issuers == null || query.Issuers.Count == 0)
            {
                throw new ApplicationException("Missing issuers");
            }

            foreach (var issuer in query.Issuers)
            {
                var index = GraphService.Graph.AddressIndex.ContainsKey(issuer) ? GraphService.Graph.AddressIndex[issuer] : -1;
                if (index > -1)
                {
                    IssuerIndex.Add(index);
                }
                else
                {
                    UnknownIssuers.Add(issuer);
                }
            }

            foreach (var subject in query.Subjects)
            {
                var index = GraphService.Graph.AddressIndex.ContainsKey(subject.Id) ? GraphService.Graph.AddressIndex[subject.Id] : -1;
                if (index == -1)
                {
                    UnknownSubjects.Add(subject.Id);
                }
                //throw new ApplicationException("Unknown subject id " + subject.Id.ConvertToHex());

                var type = GraphService.Graph.SubjectTypesIndex.ContainsKey(subject.Type) ? GraphService.Graph.SubjectTypesIndex[subject.Type] : -1;
                if (type == -1)
                {
                    UnknownSubjectTypes.Add(subject.Type);
                }
                //throw new ApplicationException("Unknown subject type: " + subject.Type);

                if (index > -1 && type > -1)
                {
                    TargetIndex.Add(new TargetIndex {
                        Id = index, Type = type
                    });
                }
            }

            Scope = (GraphService.Graph.ScopeIndex.ContainsKey(query.Scope)) ? GraphService.Graph.ScopeIndex[query.Scope] : -1;
            Claim = ClaimStandardModel.Parse(query.Claim);
        }
示例#2
0
        public byte      Rating; // Used for trust that use rating

        public static ClaimStandardModel Parse(JObject claim)
        {
            var result    = new ClaimStandardModel();
            var claimType = typeof(ClaimType);
            var names     = Enum.GetNames(claimType);

            foreach (var name in names)
            {
                var token = claim.GetValue(name, StringComparison.OrdinalIgnoreCase);
                if (token == null)
                {
                    continue;
                }

                if (token.Type == JTokenType.Null)
                {
                    continue;
                }

                var ct = (ClaimType)Enum.Parse(claimType, name);
                result.Types |= ct; // The claim has been defined

                if (token.Type == JTokenType.Boolean)
                {
                    var val = token.ToBoolean();
                    if (val)
                    {
                        result.Flags |= ct; // Set it to true in flags!
                    }
                }

                if (ct == ClaimType.Rating && token.Type == JTokenType.Integer)
                {
                    result.Rating = (byte)token.ToInteger();
                }
            }

            return(result);
        }