private DocumentNode CreateCollectionItemInternal(DocumentCompositeNode collectionNode, string value) { SampleCollectionType sampleCollectionType = collectionNode.Type as SampleCollectionType; if (sampleCollectionType == null) { return((DocumentNode)null); } DocumentNode documentNode; if (sampleCollectionType.ItemSampleType.IsBasicType) { SampleBasicType sampleType = (SampleBasicType)sampleCollectionType.ItemSampleType; if (value == null) { value = this.valueGenerator.GetRandomValue(sampleType, (string)null, (string)null); } documentNode = (DocumentNode)this.CreateBasicNode(sampleType, value); } else { documentNode = (DocumentNode)this.CreateCompositeNode((SampleNonBasicType)sampleCollectionType.ItemSampleType); } collectionNode.Children.Add(documentNode); return(documentNode); }
public string GetRandomValue(SampleBasicType sampleType, string format, string formatParameters) { object obj = this.GetValueBuilder(sampleType, format, formatParameters).Value; if (obj == null) { return((string)null); } return(obj as string ?? MetadataStore.GetTypeConverter(obj.GetType()).ConvertToInvariantString((ITypeDescriptorContext)null, obj)); }
private XmlToSampleDataAdapter.BasicTypeInfo CreateBasicTypeInfo(SampleBasicType basicType, TypeConverter converter) { IType description = this.dataSet.ResolveSampleType((SampleType)basicType); if (converter == null) { converter = this.dataSet.Platform.Metadata.GetTypeConverter((MemberInfo)description.RuntimeType); } return(new XmlToSampleDataAdapter.BasicTypeInfo(basicType, description, converter)); }
private void InitializeField(FieldBuilder fieldBuilder, ILGenerator ilConstructor, SampleProperty sampleProperty) { if (ilConstructor == null) { return; } if (!sampleProperty.IsBasicType) { SampleDataDesignTimeTypeGenerator.TypeBuildState typeBuildState = this.buildStates[(SampleNonBasicType)sampleProperty.PropertySampleType]; ilConstructor.Emit(OpCodes.Ldarg_0); ilConstructor.Emit(OpCodes.Newobj, (ConstructorInfo)typeBuildState.ConstructorBuilder); ilConstructor.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder); } else { SampleBasicType sampleBasicType = (SampleBasicType)sampleProperty.PropertySampleType; if (sampleBasicType == SampleBasicType.String) { FieldInfo field = typeof(string).GetField("Empty", BindingFlags.Static | BindingFlags.Public); ilConstructor.Emit(OpCodes.Ldarg_0); ilConstructor.Emit(OpCodes.Ldsfld, field); ilConstructor.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder); } else if (sampleBasicType == SampleBasicType.Date) { PropertyInfo property = typeof(DateTime).GetProperty("Today", BindingFlags.Static | BindingFlags.Public); ilConstructor.Emit(OpCodes.Ldarg_0); ilConstructor.Emit(OpCodes.Call, property.GetGetMethod()); ilConstructor.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder); } else if (sampleBasicType == SampleBasicType.Number) { ilConstructor.Emit(OpCodes.Ldarg_0); ilConstructor.Emit(OpCodes.Ldc_R8, 0.0); ilConstructor.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder); } else if (sampleBasicType == SampleBasicType.Boolean) { ilConstructor.Emit(OpCodes.Ldarg_0); ilConstructor.Emit(OpCodes.Ldc_I4, 0); ilConstructor.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder); } else { if (sampleBasicType != SampleBasicType.Image) { return; } ilConstructor.Emit(OpCodes.Ldarg_0); ilConstructor.Emit(OpCodes.Ldnull); ilConstructor.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder); } } }
public DocumentPrimitiveNode CreateBasicNode(SampleBasicType sampleType, string value) { string str = value; if (sampleType == SampleBasicType.Image) { str = this.DataSet.AddOrUpdateAssetFile(value); } DocumentNodeStringValue documentNodeStringValue = new DocumentNodeStringValue(str); return(this.XamlDocumentContext.CreateNode(sampleType.TypeId, (IDocumentNodeValue)documentNodeStringValue)); }
private ISampleTypeConfiguration GetValueBuilder(SampleBasicType sampleType, string format, string formatParameters) { TypeFormatInfo key = new TypeFormatInfo(sampleType, format, formatParameters); ISampleTypeConfiguration configuration; if (!this.valueBuilders.TryGetValue(key, out configuration)) { configuration = SampleDataPropertyConfiguration.CreateConfiguration(this.dataSet, sampleType, format, formatParameters); this.valueBuilders[key] = configuration; } return(configuration); }
private XmlQualifiedName GetBasicSchemaType(SampleBasicType basicType) { if (basicType == SampleBasicType.String) { if (this.stringType == (XmlQualifiedName)null) { this.stringType = new XmlQualifiedName("string", SampleDataSet.XsdNS.Namespace); } return(this.stringType); } if (basicType == SampleBasicType.Number) { if (this.numberType == (XmlQualifiedName)null) { this.numberType = new XmlQualifiedName("double", SampleDataSet.XsdNS.Namespace); } return(this.numberType); } if (basicType == SampleBasicType.Boolean) { if (this.booleanType == (XmlQualifiedName)null) { this.booleanType = new XmlQualifiedName("boolean", SampleDataSet.XsdNS.Namespace); } return(this.booleanType); } if (basicType == SampleBasicType.Date) { if (this.dateType == (XmlQualifiedName)null) { this.dateType = new XmlQualifiedName("dateTime", SampleDataSet.XsdNS.Namespace); } return(this.dateType); } if (basicType != SampleBasicType.Image) { return((XmlQualifiedName)null); } if (this.imageType == (XmlQualifiedName)null) { this.imageType = new XmlQualifiedName(SampleBasicType.XsdImageTypeName, this.TargetNamespace); XmlSchemaSimpleType schemaSimpleType = new XmlSchemaSimpleType(); schemaSimpleType.Name = SampleBasicType.XsdImageTypeName; schemaSimpleType.Content = (XmlSchemaSimpleTypeContent) new XmlSchemaSimpleTypeRestriction() { BaseTypeName = new XmlQualifiedName("anyURI", SampleDataSet.XsdNS.Namespace) }; this.schemaTypes["blend:Image"] = (XmlSchemaType)schemaSimpleType; } return(this.imageType); }
private static SampleBasicType RegisterSampleType(string typeName, ITypeId platformType) { SampleBasicType sampleBasicType = new SampleBasicType(typeName, platformType); if (platformType != PlatformTypes.DateTime) { if (SampleBasicType.sampleBasicTypesInternal == null) { SampleBasicType.sampleBasicTypesInternal = new List <SampleBasicType>(); } SampleBasicType.sampleBasicTypesInternal.Add(sampleBasicType); } return(sampleBasicType); }
private void PopulateSampleCompositeType(SampleCompositeType compositeType, XmlSchemaComplexType xmlComplexType) { XmlSchemaSequence xmlSchemaSequence = xmlComplexType.Particle as XmlSchemaSequence; if (xmlSchemaSequence == null && xmlComplexType.Particle != null) { throw new InvalidDataException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, ExceptionStringTable.InvalidTypeFormat, new object[2] { (object)this.xsdFileName, (object)xmlComplexType.Name })); } if (xmlSchemaSequence != null) { foreach (XmlSchemaObject xmlSchemaObject in xmlSchemaSequence.Items) { XmlSchemaElement xmlSchemaElement = xmlSchemaObject as XmlSchemaElement; if (xmlSchemaElement != null) { SampleType sampleType = this.GetSampleType(xmlSchemaElement.SchemaTypeName); SampleProperty sampleProperty = compositeType.AddProperty(xmlSchemaElement.Name, sampleType); SampleDataXsdParser.UpdatePropertyFormatInfo((XmlSchemaAnnotated)xmlSchemaElement, sampleProperty); if (sampleProperty.Name != xmlSchemaElement.Name) { throw new InvalidDataException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, ExceptionStringTable.InvalidNodeUsage, new object[2] { (object)this.xsdFileName, (object)xmlSchemaElement.Name })); } } } } foreach (XmlSchemaAttribute xmlSchemaAttribute in xmlComplexType.Attributes) { SampleBasicType sampleBasicType = this.GetSampleType(xmlSchemaAttribute.SchemaTypeName) as SampleBasicType; SampleProperty sampleProperty = compositeType.AddProperty(xmlSchemaAttribute.Name, (SampleType)sampleBasicType); SampleDataXsdParser.UpdatePropertyFormatInfo((XmlSchemaAnnotated)xmlSchemaAttribute, sampleProperty); if (sampleProperty.Name != xmlSchemaAttribute.Name) { throw new InvalidDataException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, ExceptionStringTable.InvalidNodeUsage, new object[2] { (object)this.xsdFileName, (object)xmlSchemaAttribute.Name })); } } }
public static string NormalizeFormatParameters(SampleBasicType sampleType, string formatParameters, bool nullPreferred) { if (sampleType == null) { return(formatParameters); } TypeFormatInfo typeFormatInfo = SampleDataFormatHelper.defaults.Find((Predicate <TypeFormatInfo>)(info => info.SampleType == sampleType)); if (nullPreferred && (formatParameters == null || typeFormatInfo.FormatParameters == formatParameters)) { return((string)null); } if (!nullPreferred && formatParameters == null) { return(typeFormatInfo.FormatParameters); } return(formatParameters); }
private DocumentNode CreatePropertyValueInternal(DocumentCompositeNode documentNode, SampleProperty sampleProperty, string value) { DocumentNode documentNode1; if (sampleProperty.PropertySampleType.IsBasicType) { SampleBasicType sampleType = (SampleBasicType)sampleProperty.PropertySampleType; if (value == null) { value = this.valueGenerator.GetRandomValue(sampleType, sampleProperty.Format, sampleProperty.FormatParameters); } documentNode1 = (DocumentNode)this.CreateBasicNode(sampleType, value); } else { documentNode1 = (DocumentNode)this.CreateCompositeNode((SampleNonBasicType)sampleProperty.PropertySampleType); } documentNode.Properties[(IPropertyId)sampleProperty] = documentNode1; return(documentNode1); }
public static string GetDefaultFormatParameters(SampleBasicType sampleType) { return(SampleDataFormatHelper.defaults.Find((Predicate <TypeFormatInfo>)(info => info.SampleType == sampleType)).FormatParameters); }
private DocumentNode GenerateBasicValue(SampleBasicType sampleType, string format, string formatParameters) { string randomValue = this.valueGenerator.GetRandomValue(sampleType, format, formatParameters); return(randomValue != null ? (DocumentNode)this.CreateBasicNode(sampleType, randomValue) : (DocumentNode)null); }
public BasicTypeInfo(SampleBasicType sampleType, IType description, TypeConverter converter) { this.SampleType = sampleType; this.Type = description; this.Converter = converter; }