예제 #1
0
 internal SchemaType(XmlSchemaType type)
 {
     schemaType           = type;
     IsComplex            = false;
     DerivedByRestriction = false;
     thisComplexType      = null;
     thisSchemaAttributes = new List <ISchemaAttribute>();
     if (schemaType is XmlSchemaComplexType)
     {
         IsComplex       = true;
         thisComplexType = schemaType as XmlSchemaComplexType;
         if (this.thisComplexType.DerivedBy == XmlSchemaDerivationMethod.Restriction)
         {
             DerivedByRestriction = true;
         }
         thisSchemaAttributes.Capacity = thisComplexType.AttributeUses.Count;
         foreach (System.Collections.DictionaryEntry currentEntry in thisComplexType.AttributeUses)
         {
             var newAttribute = new SchemaAttribute(currentEntry.Value as XmlSchemaAttribute);
             thisSchemaAttributes.Add(newAttribute);
         }
     }
     thisQualifiedName  = null;
     thisBaseSchemaType = null;
 }
예제 #2
0
        public MutationType(ISchemaType returnType, object mutationClassInstance, MethodInfo method)
        {
            this.returnType            = returnType;
            this.mutationClassInstance = mutationClassInstance;
            this.method = method;

            var methodArg = method.GetParameters().ElementAt(1);

            this.argInstance = Activator.CreateInstance(methodArg.ParameterType);
        }
예제 #3
0
 private void RemoveFieldsOfType(string typeName, ISchemaType contextType)
 {
     foreach (var field in contextType.GetFields().ToList())
     {
         if (field.GetReturnType(this) == typeName)
         {
             contextType.RemoveField(field.Name);
         }
     }
 }
예제 #4
0
 private void RemoveFieldsOfType(string schemaType, ISchemaType contextType)
 {
     foreach (var field in contextType.GetFields().ToList())
     {
         if (field.ReturnType.SchemaType.Name == schemaType)
         {
             contextType.RemoveField(field.Name);
         }
     }
 }
예제 #5
0
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 internal ISchemaType GetXmlSchemaType(IQualifiedName ItemTypeValue)
 {
     foreach (var CurrentEntry in thisXmlSchemaSet.GlobalTypes)
     {
         ISchemaType CurrentType = CurrentEntry.Value as ISchemaType;
         if (CurrentType.QualifiedName.FullyQualifiedName.Equals(ItemTypeValue.FullyQualifiedName) == true)
         {
             return(CurrentType);
         }
     }
     return(null);
 }
예제 #6
0
 internal SchemaType(XmlSchemaType type)
 {
     schemaType           = type;
     IsComplex            = false;
     DerivedByRestriction = false;
     thisComplexType      = null;
     thisSchemaAttributes = new List <ISchemaAttribute>();
     if (schemaType is XmlSchemaComplexType)
     {
         InitializeFromComplexType();
     }
     thisQualifiedName  = null;
     thisBaseSchemaType = null;
 }
예제 #7
0
파일: Item.cs 프로젝트: Mihailorama/gepsio
 /// <summary>
 /// Determines whether or not the supplied item type is of the given type.
 /// </summary>
 /// <returns>
 /// True if the type is of the given type and false otherwise.
 /// </returns>
 private bool TypeNameContains(string TypeName, ISchemaType CurrentType)
 {
     if (CurrentType.Name.Contains(TypeName) == true)
     {
         return(true);
     }
     if (CurrentType.IsComplex == true)
     {
         if (CurrentType.DerivedByRestriction == true)
         {
             return(TypeNameContains(TypeName, CurrentType.BaseSchemaType));
         }
     }
     return(false);
 }
예제 #8
0
        public MutationType(string methodName, ISchemaType returnType, object mutationClassInstance, MethodInfo method, string description, RequiredClaims authorizeClaims)
        {
            this.Description           = description;
            this.ReturnType            = returnType;
            this.mutationClassInstance = mutationClassInstance;
            this.method     = method;
            Name            = methodName;
            AuthorizeClaims = authorizeClaims;

            var methodArg = method.GetParameters().ElementAt(1);

            this.argInstanceType = methodArg.ParameterType;
            foreach (var item in argInstanceType.GetProperties())
            {
                if (GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(item))
                {
                    continue;
                }
                argumentTypes.Add(SchemaGenerator.ToCamelCaseStartsLower(item.Name), new ArgType
                {
                    Type            = item.PropertyType,
                    TypeNotNullable = GraphQLNotNullAttribute.IsMemberMarkedNotNull(item) || item.PropertyType.GetTypeInfo().IsEnum
                });
            }
            foreach (var item in argInstanceType.GetFields())
            {
                if (GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(item))
                {
                    continue;
                }
                argumentTypes.Add(SchemaGenerator.ToCamelCaseStartsLower(item.Name), new ArgType
                {
                    Type            = item.FieldType,
                    TypeNotNullable = GraphQLNotNullAttribute.IsMemberMarkedNotNull(item) || item.FieldType.GetTypeInfo().IsEnum
                });
            }
        }
예제 #9
0
 public void SetValue(ISchemaType newValue)
 {
     SetDomNodeValue(domNode, newValue.ToString());
 }
예제 #10
0
 public SchemaBoolean(ISchemaType newvalue)
 {
     Assign(newvalue);
 }
예제 #11
0
 public SchemaTime( ISchemaType obj )
 {
     Assign( obj );
 }
예제 #12
0
		public TypesIncompatibleException(ISchemaType newobj1, ISchemaType newobj2) 
			: base("Incompatible schema-types")
		{
            this.SetSamplerState(0, SamplerStateobject1 = newobj1;
            this.SetSamplerState(0, SamplerStateobject2 = newobj2;
		}
예제 #13
0
 public SchemaHexBinary(ISchemaType obj)
 {
     Assign( obj );
 }
예제 #14
0
		public TypesIncompatibleException(ISchemaType newobj1, ISchemaType newobj2) 
			: base("Incompatible schema-types")
		{
			object1 = newobj1;
			object2 = newobj2;
		}
예제 #15
0
		public void Assign( ISchemaType newvalue )
		{
			if( newvalue == null || newvalue.IsEmpty() )
			{
				Reset();
				isEmpty = true;
				isNull = true;
				return;
			}
			isEmpty = false;
			isNull = false;
			if( newvalue is SchemaDateTime )
			{
				DateTime dtNow = DateTime.Now;
				DateTime dt = ((SchemaDateTime)newvalue).Value;
				myValue = new DateTime( dtNow.Year, dtNow.Month, dtNow.Day, dt.Hour, dt.Minute, dt.Second, dt.Millisecond );
				eTZ = ((SchemaDateTime)newvalue).HasTimezone;
			}
			else if( newvalue is SchemaTime )
			{
				DateTime dtNow = DateTime.Now;
				DateTime dt = ((SchemaTime)newvalue).Value;
				myValue = new DateTime( dtNow.Year, dtNow.Month, dtNow.Day, dt.Hour, dt.Minute, dt.Second, dt.Millisecond );
				eTZ = ((SchemaTime)newvalue).HasTimezone;
			}
			else if( newvalue is SchemaString )
				Parse( newvalue.ToString() );
			else
				throw new TypesIncompatibleException(newvalue, this);
		}
예제 #16
0
		public void Assign( ISchemaType newvalue )
		{
			if( newvalue == null || newvalue.IsEmpty() ) 
			{
				Reset();
				isEmpty = true;
				isNull = true;
				return;
			}
			isEmpty = false;
			isNull = true;
			if( newvalue is SchemaDate ) 
			{
				DateTime dt = ((SchemaDate)newvalue).Value;
				myValue = new DateTime( dt.Year, dt.Month, dt.Day );
				eTZ = ETZ.Missing;
				offsetTZ = 0;
			}
			else if( newvalue is SchemaDateTime ) 
			{
				DateTime dt = ((SchemaDateTime)newvalue).Value;
				myValue = new DateTime( dt.Year, dt.Month, dt.Day );
				eTZ = ETZ.Missing;
				offsetTZ = 0;
			}
			else if( newvalue is SchemaString ) 
			{
				Parse( newvalue.ToString() );
			}
			else
				throw new TypesIncompatibleException( newvalue, this );

		}
예제 #17
0
		public void Assign( ISchemaType newvalue )
		{
			if( newvalue == null || newvalue.IsEmpty() ) 
			{
				Value = DateTime.Now; // actual date and time
				isEmpty = true;
				isNull = true;
				return;
			}
			if( newvalue is SchemaDateTime )
			{
				SchemaDateTime dt = ((SchemaDateTime)newvalue);
				myValue = dt.myValue;
				eTZ = dt.eTZ;
				offsetTZ = dt.offsetTZ;
				isEmpty = dt.isEmpty;
				isNull = dt.isNull;
			}
			else if( newvalue is SchemaDate )
			{
				DateTime dt = ((SchemaDate)newvalue).Value;
				myValue = new DateTime( dt.Year, dt.Month, dt.Day, 0, 0, 0);
				eTZ = ETZ.Missing;
				offsetTZ = 0;
				isEmpty = newvalue.IsEmpty();
				isNull = newvalue.IsNull();
			}
			else if( newvalue is SchemaString )
				Parse( newvalue.ToString() );
			else
				throw new TypesIncompatibleException( newvalue, this );
		}
예제 #18
0
		public void Assign( ISchemaType newvalue )
		{
			if( newvalue == null || newvalue.IsEmpty() )
			{
				myValue = 0;
				isEmpty = true;
				isNull = true;
				return;
			}
			if( newvalue is ISchemaTypeNumber )
			{
				isEmpty = false;
				isNull = false;
				myValue = ((ISchemaTypeNumber)newvalue).DecimalValue();
			}
			else
				throw new TypesIncompatibleException(newvalue, this);
		}
예제 #19
0
 public ValuesNotConvertableException(ISchemaType newobj1, ISchemaType newobj2)
     : base("Value '" + newobj1.ToString() + "' could not be converted to type " + newobj2.GetType().Name)
 {
     object1 = newobj1;
     object2 = newobj2;
 }
 public void SetValue(ISchemaType newValue)
 {
     SetDomNodeValue(domNode, newValue.ToString());
 }
예제 #21
0
        public void Assign( ISchemaType newvalue )
        {
            if( newvalue == null )
            {
                SetEmpty(true);
                SetNull(true);
                return;
            }

            if( newvalue.IsEmpty() )
            {
                myValue = new TimeSpan(0);
                months = 0;
                years = 0;
                SetEmpty( true );
                SetNull( newvalue.IsNull() );
                return;
            }
            isEmpty = false;
            if( newvalue is SchemaDuration )
            {
                myValue = ((SchemaDuration)newvalue).myValue;
                months = ((SchemaDuration)newvalue).months;
                years = ((SchemaDuration)newvalue).years;
                isEmpty = ((SchemaDuration)newvalue).isEmpty;
                isNull = ((SchemaDuration)newvalue).isNull;
            }
            else if( newvalue is SchemaString )
                Parse( newvalue.ToString() );
            else
            {
                try
                {
                    Parse( newvalue.ToString() );
                }
                catch (StringParseException)
                {
                    throw new TypesIncompatibleException( newvalue, this );
                }
            }
        }
예제 #22
0
		public ValuesNotConvertableException(ISchemaType newobj1, ISchemaType newobj2) 
			: base("Values could not be converted")
		{
			object1 = newobj1;
			object2 = newobj2;
		}
예제 #23
0
 public SchemaDuration(ISchemaType obj)
 {
     Assign( obj );
 }
예제 #24
0
 public SchemaLong(ISchemaType newvalue)
 {
     Assign( newvalue );
 }
예제 #25
0
        public void Assign( ISchemaType newvalue )
        {
            if( newvalue == null )
            {
                SetNull(true);
                SetEmpty(true);
                return;
            }

            if( newvalue.IsEmpty() )
            {
                SetEmpty(true);
                SetNull(newvalue.IsNull());
                return;
            }

            if( newvalue is SchemaBinaryBase )
            {
                SchemaBinaryBase obj = ((SchemaBinaryBase)newvalue);
                myValue = obj.Value;
                isEmpty = obj.IsEmpty();
            }
            else
            {
                try
                {
                    Parse( newvalue.ToString() );
                }
                catch (StringParseException)
                {
                    throw new TypesIncompatibleException( newvalue, this );
                }
            }
        }
예제 #26
0
 public SchemaString( ISchemaType obj )
 {
     Assign( obj );
 }
예제 #27
0
 public SchemaInt(ISchemaType newvalue)
 {
     Assign( newvalue );
 }
예제 #28
0
		public ValuesNotConvertableException(ISchemaType newobj1, ISchemaType newobj2) 
			: base("Values could not be converted")
		{
            this.SetSamplerState(0, SamplerStateobject1 = newobj1;
            this.SetSamplerState(0, SamplerStateobject2 = newobj2;
		}
예제 #29
0
        public void Assign( ISchemaType newvalue )
        {
            if( newvalue == null )
            {
                SetNull( true );
                SetEmpty( true );
                return;
            }

            if( newvalue.IsEmpty() )
            {
                myValue = 0;
                SetNull( newvalue.IsNull() );
                SetEmpty( true );
                return;
            }
            if( newvalue is ISchemaTypeNumber )
            {
                isEmpty = false;
                isNull = false;
                myValue = ((ISchemaTypeNumber)newvalue).LongValue();
            }
            else
                throw new TypesIncompatibleException(newvalue, this);
        }
예제 #30
0
 public ValuesNotConvertableException(ISchemaType newobj1, ISchemaType newobj2)
     : base("Values could not be converted")
 {
     object1 = newobj1;
     object2 = newobj2;
 }
예제 #31
0
        public void Assign( ISchemaType newvalue )
        {
            if( newvalue == null )
            {
                SetNull(true);
                SetEmpty(true);
                myValue = "";
                return;
            }

            if( newvalue.IsEmpty() )
            {
                isEmpty = true;
                SetNull( newvalue.IsNull() );
                myValue = "";
                return;
            }
            myValue = newvalue.ToString();
            isEmpty = (myValue.Length == 0 );
            isNull = false;
        }
예제 #32
0
 public TypesIncompatibleException(ISchemaType newobj1, ISchemaType newobj2)
     : base("Incompatible schema-types")
 {
     object1 = newobj1;
     object2 = newobj2;
 }
예제 #33
0
        public void Assign( ISchemaType newvalue )
        {
            if( newvalue == null )
            {
                SetEmpty(true);
                SetNull(true);
                return;
            }

            if( newvalue.IsEmpty() )
            {
                Reset();
                SetEmpty(true);
                SetNull(newvalue.IsNull());
                return;
            }
            isEmpty = false;
            isNull = false;
            if( newvalue is SchemaDateTime )
            {
                System.DateTime dtNow = System.DateTime.Now;
                System.DateTime dt = ((SchemaDateTime)newvalue).Value;
                myValue = new System.DateTime( dtNow.Year, dtNow.Month, dtNow.Day, dt.Hour, dt.Minute, dt.Second, dt.Millisecond );
                eTZ = ((SchemaDateTime)newvalue).HasTimezone;
                offsetTZ = ((SchemaDateTime)newvalue).TimezoneOffset;
            }
            else if( newvalue is SchemaTime )
            {
                System.DateTime dtNow = System.DateTime.Now;
                System.DateTime dt = ((SchemaTime)newvalue).Value;
                myValue = new System.DateTime( dtNow.Year, dtNow.Month, dtNow.Day, dt.Hour, dt.Minute, dt.Second, dt.Millisecond );
                eTZ = ((SchemaTime)newvalue).HasTimezone;
                offsetTZ = ((SchemaTime)newvalue).offsetTZ;
            }
            else if( newvalue is SchemaString )
                Parse( newvalue.ToString() );
            else
            {
                try
                {
                    Parse( newvalue.ToString() );
                }
                catch (StringParseException)
                {
                    throw new TypesIncompatibleException( newvalue, this );
                }
            }
        }
예제 #34
0
 public SchemaDate(ISchemaType obj)
 {
     Assign( obj );
 }
예제 #35
0
        public void Assign( ISchemaType newvalue )
        {
            if( newvalue == null )
            {
                SetNull(true);
                SetEmpty(true);
                return;
            }

            if( newvalue.IsEmpty() )
            {
                SetEmpty(true);
                SetNull( newvalue.IsNull() );
                return;
            }

            Parse(newvalue.ToString());
        }
예제 #36
0
        public void Assign( ISchemaType newvalue )
        {
            if( newvalue == null )
            {
                SetNull(true);
                SetEmpty(true);
                return;
            }

            if( newvalue.IsEmpty() )
            {
                Reset();
                isEmpty = true;
                SetNull( newvalue.IsNull() );
                return;
            }
            isEmpty = false;
            isNull = false;
            if( newvalue is SchemaDate )
            {
                System.DateTime dt = ((SchemaDate)newvalue).Value;
                myValue = new System.DateTime( dt.Year, dt.Month, dt.Day );
                eTZ = ETZ.Missing;
                offsetTZ = 0;
            }
            else if( newvalue is SchemaDateTime )
            {
                System.DateTime dt = ((SchemaDateTime)newvalue).Value;
                myValue = new System.DateTime( dt.Year, dt.Month, dt.Day );
                eTZ = ETZ.Missing;
                offsetTZ = 0;
            }
            else if( newvalue is SchemaString )
            {
                Parse( newvalue.ToString() );
            }
            else
            {
                try
                {
                    Parse( newvalue.ToString() );
                }
                catch (StringParseException)
                {
                    throw new TypesIncompatibleException( newvalue, this );
                }
            }
        }
예제 #37
0
 public void Assign(ISchemaType newValue)
 {
     SetValue(newValue);
 }
예제 #38
0
 public SchemaBase64Binary(ISchemaType obj)
 {
     Assign( obj );
 }
 public void Assign(ISchemaType newValue)
 {
     SetValue(newValue);
 }
예제 #40
0
        public void Assign( ISchemaType newvalue )
        {
            if( newvalue == null )
            {
                SetNull(true);
                SetEmpty(true);
                return;
            }

            if( newvalue.IsEmpty() )
            {
                Value = System.DateTime.Now; // actual date and time
                isEmpty = true;
                SetNull( newvalue.IsNull() );
                return;
            }
            if( newvalue is SchemaDateTime )
            {
                SchemaDateTime dt = ((SchemaDateTime)newvalue);
                myValue = dt.myValue;
                eTZ = dt.eTZ;
                offsetTZ = dt.offsetTZ;
                isEmpty = dt.isEmpty;
                isNull = dt.isNull;
            }
            else if( newvalue is SchemaDate )
            {
                System.DateTime dt = ((SchemaDate)newvalue).Value;
                myValue = new System.DateTime( dt.Year, dt.Month, dt.Day, 0, 0, 0);
                eTZ = ETZ.Missing;
                offsetTZ = 0;
                isEmpty = newvalue.IsEmpty();
                isNull = newvalue.IsNull();
            }
            else
            {
                try
                {
                    Parse( newvalue.ToString() );
                }
                catch (StringParseException)
                {
                    throw new TypesIncompatibleException( newvalue, this );
                }
            }
        }
예제 #41
0
        public ExpressionResult GetExpressionForField(Expression context, string typeName, string fieldName, Dictionary <string, ExpressionResult> args, ClaimsIdentity claims)
        {
            if (!types.ContainsKey(typeName))
            {
                throw new EntityQuerySchemaException($"{typeName} not found in schema.");
            }

            ISchemaType schemaType = types[typeName];

            if (!AuthUtil.IsAuthorized(claims, schemaType.AuthorizeClaims))
            {
                throw new EntityGraphQLAccessException($"You do not have access to the '{typeName}' type. You require any of the following security claims [{string.Join(", ", schemaType.AuthorizeClaims.Claims.SelectMany(r => r))}]");
            }

            var field = schemaType.GetField(fieldName, claims);

            if (!AuthUtil.IsAuthorized(claims, field.ReturnType.SchemaType.AuthorizeClaims))
            {
                throw new EntityGraphQLAccessException($"You do not have access to the '{field.ReturnType.SchemaType.Name}' type. You require any of the following security claims [{string.Join(", ", field.ReturnType.SchemaType.AuthorizeClaims.Claims.SelectMany(r => r))}]");
            }

            var result = new ExpressionResult(field.Resolve ?? Expression.Property(context, fieldName), field.Services);

            if (field.ArgumentTypesObject != null)
            {
                var argType = field.ArgumentTypesObject.GetType();
                // get the values for the argument anonymous type object constructor
                var propVals  = new Dictionary <PropertyInfo, object>();
                var fieldVals = new Dictionary <FieldInfo, object>();
                // if they used AddField("field", new { id = Required<int>() }) the compiler makes properties and a constructor with the values passed in
                foreach (var argField in argType.GetProperties())
                {
                    var val = BuildArgumentFromMember(args, field, argField.Name, argField.PropertyType, argField.GetValue(field.ArgumentTypesObject));
                    // if this was a EntityQueryType we actually get a Func from BuildArgumentFromMember but the anonymous type requires EntityQueryType<>. We marry them here, this allows users to EntityQueryType<> as a Func in LINQ methods while not having it defined until runtime
                    if (argField.PropertyType.IsConstructedGenericType && argField.PropertyType.GetGenericTypeDefinition() == typeof(EntityQueryType <>))
                    {
                        // make sure we create a new instance and not update the schema
                        var entityQuery = Activator.CreateInstance(argField.PropertyType);

                        // set Query
                        var hasValue = val != null;
                        if (hasValue)
                        {
                            var genericProp = entityQuery.GetType().GetProperty("Query");
                            genericProp.SetValue(entityQuery, ((ExpressionResult)val).Expression);
                        }

                        propVals.Add(argField, entityQuery);
                    }
                    else
                    {
                        if (val != null && val.GetType() != argField.PropertyType)
                        {
                            val = ExpressionUtil.ChangeType(val, argField.PropertyType);
                        }
                        propVals.Add(argField, val);
                    }
                }
                // The auto argument is built at runtime from LinqRuntimeTypeBuilder which just makes public fields
                // they could also use a custom class, so we need to look for both fields and properties
                foreach (var argField in argType.GetFields())
                {
                    var val = BuildArgumentFromMember(args, field, argField.Name, argField.FieldType, argField.GetValue(field.ArgumentTypesObject));
                    fieldVals.Add(argField, val);
                }

                // create a copy of the anonymous object. It will have the default values set
                // there is only 1 constructor for the anonymous type that takes all the property values
                var    con = argType.GetConstructor(propVals.Keys.Select(v => v.PropertyType).ToArray());
                object parameters;
                if (con != null)
                {
                    parameters = con.Invoke(propVals.Values.ToArray());
                    foreach (var item in fieldVals)
                    {
                        item.Key.SetValue(parameters, item.Value);
                    }
                }
                else
                {
                    // expect an empty constructor
                    con        = argType.GetConstructor(new Type[0]);
                    parameters = con.Invoke(new object[0]);
                    foreach (var item in fieldVals)
                    {
                        item.Key.SetValue(parameters, item.Value);
                    }
                    foreach (var item in propVals)
                    {
                        item.Key.SetValue(parameters, item.Value);
                    }
                }
                // tell them this expression has another parameter
                var argParam = Expression.Parameter(argType, $"arg_{argType.Name}");
                result.Expression = new ParameterReplacer().ReplaceByType(result.Expression, argType, argParam);
                result.AddConstantParameter(argParam, parameters);
            }

            // the expressions we collect have a different starting parameter. We need to change that
            var paramExp = field.FieldParam;

            result.Expression = new ParameterReplacer().Replace(result.Expression, paramExp, context);

            return(result);
        }
예제 #42
0
 public SchemaDecimal(ISchemaType obj)
 {
     Assign( obj );
 }
예제 #43
0
 public SchemaDouble(ISchemaType obj)
 {
     Assign( obj );
 }
예제 #44
0
 public ValuesNotConvertableException(ISchemaType newobj1, ISchemaType newobj2)
     : base("Value '" + newobj1.ToString() + "' could not be converted to type " + newobj2.GetType().Name)
 {
     object1 = newobj1;
     object2 = newobj2;
 }