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; }
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); }
private void RemoveFieldsOfType(string typeName, ISchemaType contextType) { foreach (var field in contextType.GetFields().ToList()) { if (field.GetReturnType(this) == typeName) { contextType.RemoveField(field.Name); } } }
private void RemoveFieldsOfType(string schemaType, ISchemaType contextType) { foreach (var field in contextType.GetFields().ToList()) { if (field.ReturnType.SchemaType.Name == schemaType) { contextType.RemoveField(field.Name); } } }
//------------------------------------------------------------------------------- //------------------------------------------------------------------------------- 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); }
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; }
/// <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); }
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 }); } }
public void SetValue(ISchemaType newValue) { SetDomNodeValue(domNode, newValue.ToString()); }
public SchemaBoolean(ISchemaType newvalue) { Assign(newvalue); }
public SchemaTime( ISchemaType obj ) { Assign( obj ); }
public TypesIncompatibleException(ISchemaType newobj1, ISchemaType newobj2) : base("Incompatible schema-types") { this.SetSamplerState(0, SamplerStateobject1 = newobj1; this.SetSamplerState(0, SamplerStateobject2 = newobj2; }
public SchemaHexBinary(ISchemaType obj) { Assign( obj ); }
public TypesIncompatibleException(ISchemaType newobj1, ISchemaType newobj2) : base("Incompatible schema-types") { object1 = newobj1; object2 = newobj2; }
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); }
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 ); }
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 ); }
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); }
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 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 ); } } }
public ValuesNotConvertableException(ISchemaType newobj1, ISchemaType newobj2) : base("Values could not be converted") { object1 = newobj1; object2 = newobj2; }
public SchemaDuration(ISchemaType obj) { Assign( obj ); }
public SchemaLong(ISchemaType newvalue) { Assign( newvalue ); }
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 ); } } }
public SchemaString( ISchemaType obj ) { Assign( obj ); }
public SchemaInt(ISchemaType newvalue) { Assign( newvalue ); }
public ValuesNotConvertableException(ISchemaType newobj1, ISchemaType newobj2) : base("Values could not be converted") { this.SetSamplerState(0, SamplerStateobject1 = newobj1; this.SetSamplerState(0, SamplerStateobject2 = newobj2; }
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); }
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; }
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 ); } } }
public SchemaDate(ISchemaType obj) { Assign( obj ); }
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()); }
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 ); } } }
public void Assign(ISchemaType newValue) { SetValue(newValue); }
public SchemaBase64Binary(ISchemaType obj) { Assign( obj ); }
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 ); } } }
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); }
public SchemaDecimal(ISchemaType obj) { Assign( obj ); }
public SchemaDouble(ISchemaType obj) { Assign( obj ); }