public override int GetHashCode()
        {
            var result = OperationType.GetHashCode();

            if (Name != null)
            {
                result ^= Name.GetHashCode();
            }

            if (VariableDefinitions != null)
            {
                result = VariableDefinitions.Aggregate(result, (x, y) => x ^ y.GetHashCode());
            }

            if (Directives != null)
            {
                result = Directives.Aggregate(result, (x, y) => x ^ y.GetHashCode());
            }

            if (SelectionSet != null)
            {
                result = SelectionSet.Aggregate(result, (x, y) => x ^ y.GetHashCode());
            }

            return(result);
        }
Example #2
0
        public override int GetHashCode()
        {
            var result = Name.GetHashCode();

            if (Alias != null)
            {
                result ^= Alias.GetHashCode();
            }

            if (Arguments != null)
            {
                result = Arguments.Aggregate(result, (x, y) => x ^ y.GetHashCode());
            }

            if (Directives != null)
            {
                result = Directives.Aggregate(result, (x, y) => x ^ y.GetHashCode());
            }

            if (SelectionSet != null)
            {
                result = SelectionSet.Aggregate(result, (x, y) => x ^ y.GetHashCode());
            }

            return(result);
        }
Example #3
0
        private Directives GutsDirectives()
        {
            var patch     = new Directives().Add("items");
            var knowledge = this.memory.Contents().Knowledge(this.name.AsString());

            new Each <string>(
                (key) =>
                patch
                .Add("item")
                .Add("name")
                .Set(key.Substring((this.name.AsString() + "/").Length))
                .Up()
                .Add("size")
                .Set(
                    new LengthOf(
                        this.memory
                        .Contents()
                        .Bytes(key, () => new byte[0])
                        ).Value()
                    )
                .Up()
                .Up(),
                knowledge
                ).Invoke();
            return(patch);
        }
Example #4
0
 protected override void EnterDirectives(PrinterContext context, Directives directives)
 {
     if (context.Parent != null)
     {
         context.Append(' ');
     }
 }
Example #5
0
        TokenType DecodeIdentifier(string value)
        {
            TokenType identifierType = TokenType.Symbol;

            if (Instructions.Contains("|" + value.ToUpper() + "|"))
            {
                identifierType |= TokenType.Opcode;
            }
            if (RegisterPairs.Contains("|" + value.ToUpper() + "|"))
            {
                identifierType |= TokenType.RegisterPair;
            }
            if (Registers.Contains("|" + value.ToUpper() + "|"))
            {
                identifierType |= TokenType.Register;
            }
            if (Conditions.Contains("|" + value.ToUpper() + "|"))
            {
                identifierType |= TokenType.Condition;
            }
            if (Directives.Contains("|" + value.ToUpper() + "|"))
            {
                identifierType |= TokenType.Directive;
            }
            if (Preprocessor.Contains("|" + value.ToUpper() + "|"))
            {
                identifierType |= TokenType.Preprocessor;
            }
            return(identifierType);
        }
Example #6
0
        public override bool Equals(object obj)
        {
            if (obj is Field field)
            {
                return
                    (Name.Equals(field.Name) &&
                     (
                         Arguments == null &&
                         field.Arguments == null ||
                         Arguments != null &&
                         field.Arguments != null &&
                         Arguments.SequenceEqual(field.Arguments)
                     ) &&
                     (
                         Directives == null &&
                         field.Directives == null ||
                         Directives != null &&
                         field.Directives != null &&
                         Directives.SequenceEqual(field.Directives)
                     ) &&
                     (
                         SelectionSet == null &&
                         field.SelectionSet == null ||
                         SelectionSet != null &&
                         field.SelectionSet != null &&
                         SelectionSet.SequenceEqual(field.SelectionSet)
                     ));
            }

            return(base.Equals(obj));
        }
        public ValidationSchema()
        {
            Query = new ValidationQueryRoot();
            this.RegisterType <Dog>();
            this.RegisterType <Cat>();
            this.RegisterType <Human>();
            this.RegisterType <Alien>();

            Directives.Register(
                new DirectiveGraphType("onQuery", DirectiveLocation.Query),
                new DirectiveGraphType("onMutation", DirectiveLocation.Mutation),
                new DirectiveGraphType("onSubscription", DirectiveLocation.Subscription),
                new DirectiveGraphType("onField", DirectiveLocation.Field),
                new DirectiveGraphType("onFragmentDefinition", DirectiveLocation.FragmentDefinition),
                new DirectiveGraphType("onFragmentSpread", DirectiveLocation.FragmentSpread),
                new DirectiveGraphType("onInlineFragment", DirectiveLocation.InlineFragment),
                new DirectiveGraphType("onSchema", DirectiveLocation.Schema),
                new DirectiveGraphType("onScalar", DirectiveLocation.Scalar),
                new DirectiveGraphType("onObject", DirectiveLocation.Object),
                new DirectiveGraphType("onFieldDefinition", DirectiveLocation.FieldDefinition),
                new DirectiveGraphType("onArgumentDefinition", DirectiveLocation.ArgumentDefinition),
                new DirectiveGraphType("onInterface", DirectiveLocation.Interface),
                new DirectiveGraphType("onUnion", DirectiveLocation.Union),
                new DirectiveGraphType("onEnum", DirectiveLocation.Enum),
                new DirectiveGraphType("onEnumValue", DirectiveLocation.EnumValue),
                new DirectiveGraphType("onInputObject", DirectiveLocation.InputObject),
                new DirectiveGraphType("onInputFieldDefinition", DirectiveLocation.InputFieldDefinition)
                );
        }
Example #8
0
        /// <summary>
        /// GET for establishing the downchannel using the directives path
        /// Refer
        /// </summary>
        public async void CreateDownchannel()
        {
            using (System.Net.Http.HttpClient get = new System.Net.Http.HttpClient())
            {
                get.DefaultRequestHeaders.Add("Authorization", "Bearer " + Ini.access_token);
                var response = await(get.GetAsync(directivesURL, System.Net.Http.HttpCompletionOption.ResponseHeadersRead));

                var stream = await response.Content.ReadAsStreamAsync();

                var buffer = new byte[2048];

                while (await stream.ReadAsync(buffer, 0, buffer.Length) > 0)
                {
                    // Report progress and write to a different stream
                    string directive = System.Text.Encoding.UTF8.GetString(buffer, 0, buffer.Length);
                    using (StringReader reader = new StringReader(directive))
                    {
                        string line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            if (line.Contains("{\"directive\":{\""))
                            {
                                Directives.ParseDirective(line);
                            }
                        }
                    }
                    Array.Clear(buffer, 0, buffer.Length);
                }
            }
        }
        private static bool ShouldIncludeNode(Directives directives)
        {
            if (directives != null)
            {
                var directive = directives.Find(DirectiveGraphType.Skip.Name);
                if (directive != null)
                {
                    var values = GetArgumentValues(
                        DirectiveGraphType.Skip.Arguments,
                        directive.Arguments,
                        null);

                    values.TryGetValue("if", out object ifObj);

                    return(!(bool.TryParse(ifObj?.ToString() ?? string.Empty, out bool ifVal) && ifVal));
                }

                directive = directives.Find(DirectiveGraphType.Include.Name);
                if (directive != null)
                {
                    var values = GetArgumentValues(
                        DirectiveGraphType.Include.Arguments,
                        directive.Arguments,
                        null);

                    values.TryGetValue("if", out object ifObj);

                    return(bool.TryParse(ifObj?.ToString() ?? string.Empty, out bool ifVal) && ifVal);
                }
            }

            return(true);
        }
        private static void CheckDirectives(ValidationContext context, Directives directives)
        {
            if (directives == null || directives.Count == 0)
            {
                return;
            }

            if (!directives.HasDuplicates)
            {
                return;
            }

            var knownDirectives = new Dictionary <string, Directive>(directives.Count);

            foreach (var directive in directives)
            {
                if (knownDirectives.ContainsKey(directive.Name))
                {
                    context.ReportError(new UniqueDirectivesPerLocationError(context, knownDirectives[directive.Name], directive));
                }
                else
                {
                    knownDirectives[directive.Name] = directive;
                }
            }
        }
Example #11
0
 public override AstStatement Clone()
 => CopyValuesTo(new AstConstantDeclaration(
                     Pattern.Clone(),
                     TypeExpr?.Clone(),
                     Initializer.Clone(),
                     Documentation,
                     Directives?.Select(d => d.Clone()).ToList()));
Example #12
0
        public MetaEntry(Directives d, string info)
        {
            Nested = new List <MetaEntry>();

            Directive = d;
            Info      = info;
        }
Example #13
0
 public void AddDirectives(params string[] directives)
 {
     if (directives != null)
     {
         Directives.AddRange(directives);
     }
 }
Example #14
0
            public byte[] GetContent(Directives directive)
            {
                if (properties == null)
                {
                    return(null);
                }

                foreach (Property p in properties)
                {
                    if (p.Directive == (byte)directive)
                    {
                        return(p.Content);
                    }
                }

                foreach (Property p in attributes)
                {
                    if (p.Directive == (byte)directive)
                    {
                        return(p.Content);
                    }
                }

                return(null);
            }
Example #15
0
        private void CheckDirectives(ValidationContext context, Directives directives)
        {
            if (directives == null || directives.Count == 0)
            {
                return;
            }

            if (!directives.HasDuplicates)
            {
                return;
            }

            var knownDirectives = new Dictionary <string, Directive>(directives.Count);

            foreach (var directive in directives)
            {
                if (knownDirectives.ContainsKey(directive.Name))
                {
                    var error = new ValidationError(
                        context.OriginalQuery,
                        "5.6.3",
                        DuplicateDirectiveMessage(directive.Name),
                        knownDirectives[directive.Name],
                        directive);

                    context.ReportError(error);
                }
                else
                {
                    knownDirectives[directive.Name] = directive;
                }
            }
        }
Example #16
0
        /// <summary>
        /// Whether command has a directive.
        /// </summary>
        public bool HasDirective(string directive)
        {
            string v = directive.Trim('[', ']')
                       .ToLower();

            return(Directives.Where(x => x.Name == v)
                   .Any());
        }
Example #17
0
        public TableCompileContext(TableCompileContext context) : this((IAnalyzerContext)context)
        {
            Parent = context;
            Depth  = context.Depth + 1;

            // Priority: this > parent
            Directives = Directives.Concat(context.Directives);
        }
Example #18
0
 public void AddDirective(IDirective directive)
 {
     if (Directives == null)
     {
         Directives = new List <IDirective>();
     }
     Directives.Add(directive);
 }
Example #19
0
        public void AddDirective(Directives d, string info)
        {
            DirDataCheck(d, ref info);

            Debug.PrintDbg($"@{d}:{info}");

            _current = new MetaEntry(d, info);
            _entries.Add(_current);
        }
Example #20
0
 public AppRegistrationSchema(IServiceProvider services, Query query, Mutation mutation) : base(services)
 {
     Query    = query;
     Mutation = mutation;
     Directives.Register(new AuthorizeDirective());
     Directives.Register(new RequirePermissionDirective());
     RegisterVisitor(typeof(AuthorizeDirectiveVisitor));
     RegisterVisitor(typeof(RequirePermissionDirectiveVisitor));
 }
Example #21
0
        public TypeDiscoverer(
            IDescriptorContext context,
            TypeRegistry typeRegistry,
            TypeLookup typeLookup,
            IEnumerable <ITypeReference> initialTypes,
            ITypeInterceptor interceptor,
            bool includeSystemTypes = true)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (typeRegistry is null)
            {
                throw new ArgumentNullException(nameof(typeRegistry));
            }

            if (typeLookup is null)
            {
                throw new ArgumentNullException(nameof(typeLookup));
            }

            if (initialTypes is null)
            {
                throw new ArgumentNullException(nameof(initialTypes));
            }

            if (interceptor is null)
            {
                throw new ArgumentNullException(nameof(interceptor));
            }

            _typeRegistry = typeRegistry;

            if (includeSystemTypes)
            {
                _unregistered.AddRange(
                    IntrospectionTypes.CreateReferences(context.TypeInspector));
                _unregistered.AddRange(
                    Directives.CreateReferences(context.TypeInspector));
            }

            _unregistered.AddRange(typeRegistry.GetTypeRefs());
            _unregistered.AddRange(initialTypes.Distinct());

            _typeRegistrar = new TypeRegistrar(context, typeRegistry, typeLookup, interceptor);

            _handlers = new ITypeRegistrarHandler[]
            {
                new SchemaTypeReferenceHandler(),
                new ExtendedTypeReferenceHandler(context.TypeInspector),
                new SyntaxTypeReferenceHandler(context.TypeInspector)
            };

            _typeInspector = context.TypeInspector;
        }
Example #22
0
 private void DirDataCheck(Directives d, ref string info)
 {
     if (d == Directives.Lc)
     {
         info = "" + _lcCounter++;
     }
     else if (d == Directives.Ascii)
     {
         info = info.Replace("\"", "");
     }
 }
        public SchemaWithDuplicateArgumentsInDirective()
        {
            Query = new ObjectGraphType {
                Name = "q"
            };
            Query.Fields.Add(new FieldType {
                Name = "f", ResolvedType = new StringGraphType()
            });

            Directives.Register(new MyDirective());
        }
Example #24
0
        /// <summary>
        /// Finds command schema by name.
        /// </summary>
        public DirectiveSchema?TryFindDirective(string directiveName)
        {
            if (string.IsNullOrWhiteSpace(directiveName))
            {
                return(null);
            }

            Directives.TryGetValue(directiveName, out DirectiveSchema? value);

            return(value);
        }
        public SchemaWithNullDirectiveArgumentWhenShouldBeNonNull()
        {
            Query = new ObjectGraphType {
                Name = "MyQuery"
            };
            Query.AddField(new FieldType {
                Name = "field", ResolvedType = new StringGraphType()
            }).ApplyDirective("test", "arg", null);

            Directives.Register(new TestDirective());
        }
        public override int GetHashCode()
        {
            var result = FragmentName.GetHashCode() ^ TypeCondition.GetHashCode();

            if (Directives != null)
            {
                result = Directives.Aggregate(result, (x, y) => x ^ y.GetHashCode());
            }

            return(SelectionSet.Aggregate(result, (x, y) => x ^ y.GetHashCode()));
        }
Example #27
0
        public override bool Equals(Object o)
        {
            if (o == null || !(o is ProceduralType))
            {
                return(false);
            }

            ProceduralType ft = (ProceduralType)o;

            return(funcret.Equals(ft.funcret) && Directives.Equals(ft.Directives) && @params.Equals(ft.@params));
        }
Example #28
0
        private string GetDirectiveString(Directives d, string info)
        {
            switch (d)
            {
            case Directives.Lc: return($".LC{info}:");

            case Directives.Ascii: return($".ascii \"{info}\\0\"");

            case Directives.Text: return(".text");

            default: return(null);
            }
        }
Example #29
0
        public bool AddDirective(Directives d, string info, bool nested = false)
        {
            if (nested)
            {
                Meta.AddNestedDirective(d, info);
            }
            else
            {
                Meta.AddDirective(d, info);
            }

            return(true);
        }
Example #30
0
        /// <summary>
        /// Adds the specified directive to the plan.
        /// </summary>
        /// <param name="directive">The directive.</param>
        public void Add(IDirective directive)
        {
            Ensure.ArgumentNotNull(directive, "directive");

            var constructorInjectionDirective = directive as ConstructorInjectionDirective;

            if (constructorInjectionDirective != null)
            {
                ConstructorInjectionDirectives.Add(constructorInjectionDirective);
            }

            Directives.Add(directive);
        }
Example #31
0
 public Directive(Directives wat, ScreenBuffer source, ScreenBuffer target, List<Layer> layers, EffectInstance effect = null, uint color = 0xff000000)
 {
     this.do_what        = wat;
     this.source_buffer  = source;
     this.target_buffer  = target;
     this.layers         = layers;
     this.color          = color;
     this.effect         = effect;
     if (this.effect == null) this.effect = EffectInstance.empty;
 }
 /// <summary>
 ///     Constructor that will take a predifined directive type name
 /// </summary>
 /// <param name="directive">The predifined directive type</param>
 public Directive(Directives directive)
     : this(directive.GetDefaultValue() as string)
 {
 }
Example #33
0
 //////////////////////////////////////////////////////////////////////////////////////////////////////
 public static Directive add_directive(Directives which_directive, ScreenBuffer target_buffer = null, List<Layer> layers = null, ScreenBuffer source_buffer = null, EffectInstance shader = null, uint color = 0xff000000)
 {
     Directive D = new Directive(which_directive, source_buffer, target_buffer, layers, shader, color);
     program.Add(D);
     return D;
 }
Example #34
0
        public bool ShouldIncludeNode(ExecutionContext context, Directives directives)
        {
            if (directives != null)
            {
                var directive = directives.Find(DirectiveGraphType.Skip.Name);
                if (directive != null)
                {
                    var values = GetArgumentValues(
                        context.Schema,
                        DirectiveGraphType.Skip.Arguments,
                        directive.Arguments,
                        context.Variables);
                    return !((bool) values["if"]);
                }

                directive = directives.Find(DirectiveGraphType.Include.Name);
                if (directive != null)
                {
                    var values = GetArgumentValues(
                        context.Schema,
                        DirectiveGraphType.Include.Arguments,
                        directive.Arguments,
                        context.Variables);
                    return (bool) values["if"];
                }
            }

            return true;
        }
Example #35
0
			public byte[] GetContent (Directives directive)
			{
				if (properties == null)
					return null;
				
				foreach (Property p in properties) {
					if (p.Directive == (byte) directive)
						return p.Content;
				}
				
				foreach (Property p in attributes) {
					if (p.Directive == (byte) directive)
						return p.Content;
				}
				
				return null;
			}
 public FragmentSpread()
 {
     Directives = new Directives();
 }
Example #37
0
 public Operation()
 {
     OperationType = OperationType.Query;
     Directives = new Directives();
     Variables = new Variables();
 }
 public FragmentDefinition()
 {
     Directives = new Directives();
 }
        public bool ShouldIncludeNode(ExecutionContext context, Directives directives)
        {
            if (directives != null)
            {
                var directive = directives.Find(DirectiveGraphType.Skip.Name);
                if (directive != null)
                {
                    var values = GetArgumentValues(
                        context.Schema,
                        DirectiveGraphType.Skip.Arguments,
                        directive.Arguments,
                        context.Variables);

                    object ifObj;
                    values.TryGetValue("if", out ifObj);

                    bool ifVal;
                    return !(bool.TryParse(ifObj?.ToString() ?? string.Empty, out ifVal) && ifVal);
                }

                directive = directives.Find(DirectiveGraphType.Include.Name);
                if (directive != null)
                {
                    var values = GetArgumentValues(
                        context.Schema,
                        DirectiveGraphType.Include.Arguments,
                        directive.Arguments,
                        context.Variables);

                    object ifObj;
                    values.TryGetValue("if", out ifObj);

                    bool ifVal;
                    return bool.TryParse(ifObj?.ToString() ?? string.Empty, out ifVal) && ifVal;
                }
            }

            return true;
        }