Пример #1
0
        private XmlSchemaType CreateSchemaCollectionType(SampleCollectionType collectionType)
        {
            XmlSchemaComplexType schemaComplexType = new XmlSchemaComplexType();

            schemaComplexType.Name = collectionType.Name;
            this.schemaTypes[schemaComplexType.Name] = (XmlSchemaType)schemaComplexType;
            XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
            XmlSchemaElement  xmlSchemaElement  = new XmlSchemaElement();

            xmlSchemaElement.MaxOccursString = "unbounded";
            if (collectionType.ItemSampleType.IsBasicType)
            {
                xmlSchemaElement.Name           = collectionType.Name + "Item";
                xmlSchemaElement.SchemaTypeName = this.GetBasicSchemaType(collectionType.ItemSampleType as SampleBasicType);
            }
            else
            {
                xmlSchemaElement.Name = collectionType.ItemSampleType.Name;
                XmlSchemaType createSchemaType = this.GetOrCreateSchemaType(collectionType.ItemSampleType as SampleNonBasicType);
                xmlSchemaElement.SchemaTypeName = new XmlQualifiedName(createSchemaType.Name, this.TargetNamespace);
            }
            xmlSchemaSequence.Items.Add((XmlSchemaObject)xmlSchemaElement);
            schemaComplexType.Particle = (XmlSchemaParticle)xmlSchemaSequence;
            return((XmlSchemaType)schemaComplexType);
        }
Пример #2
0
        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);
        }
Пример #3
0
        private void WriteCollectionType(SampleCollectionType collectionType)
        {
            string typeName1 = this.codeSnippets.GetTypeName((SampleType)collectionType);
            string typeName2 = this.codeSnippets.GetTypeName(collectionType.ItemSampleType);

            this.WriteSnippet(this.codeSnippets.CollectionType, SampleCodeGenerator.CollectionTypeTemplate, typeName1, SampleCodeGenerator.ItemTypeTemplate, typeName2);
        }
        private SampleDataDesignTimeTypeGenerator.TypeBuildState BeginCollectionType(SampleCollectionType collectionType)
        {
            Type               parent             = this.dataSet.ProjectContext.ResolveType(PlatformTypes.ObservableCollection).RuntimeType.MakeGenericType(this.GetOrBeginDesignTimeType(collectionType.ItemSampleType));
            TypeBuilder        typeBuilder        = RuntimeGeneratedTypesHelper.RuntimeGeneratedTypesAssembly.DefineType(this.designTimeClrNamespace + collectionType.Name, TypeAttributes.Public | TypeAttributes.Sealed, parent);
            ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);

            return(new SampleDataDesignTimeTypeGenerator.TypeBuildState(typeBuilder, constructorBuilder));
        }
        private Type GenerateCollectionType(SampleCollectionType collectionType, SampleDataDesignTimeTypeGenerator.TypeBuildState buildState)
        {
            collectionType.DesignTimeType = buildState.TypeBuilder.UnderlyingSystemType;
            Type            type        = this.dataSet.ProjectContext.ResolveType(PlatformTypes.ObservableCollection).RuntimeType.MakeGenericType(this.GetOrGenerateDesignTimeType(collectionType.ItemSampleType));
            ILGenerator     ilGenerator = buildState.ConstructorBuilder.GetILGenerator();
            ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);

            ilGenerator.Emit(OpCodes.Ldarg_0);
            ilGenerator.Emit(OpCodes.Call, constructor);
            ilGenerator.Emit(OpCodes.Ret);
            return(this.GenerateDesignTimeType(buildState.TypeBuilder));
        }
Пример #6
0
        public SampleDataSet CreateDefaultNewSampleDataSource(DataSetContext dataSetContext, string dataSourceName, bool enableAtRuntime)
        {
            SampleDataSet dataSet = (SampleDataSet)null;
            bool          flag    = false;

            try
            {
                dataSet = this.CreateSampleDataSet(dataSetContext, dataSourceName, enableAtRuntime);
                if (dataSet != null)
                {
                    using (dataSet.DisableChangeTracking())
                    {
                        if (dataSetContext.DataSetType == DataSetType.SampleDataSet)
                        {
                            string uniqueTypeName1            = dataSet.GetUniqueTypeName("Item");
                            SampleCompositeType compositeType = dataSet.CreateCompositeType(uniqueTypeName1);
                            string uniquePropertyName1        = compositeType.GetUniquePropertyName("Property1");
                            compositeType.AddProperty(uniquePropertyName1, (SampleType)SampleBasicType.String);
                            string uniquePropertyName2 = compositeType.GetUniquePropertyName("Property2");
                            compositeType.AddProperty(uniquePropertyName2, (SampleType)SampleBasicType.Boolean);
                            string uniqueTypeName2 = dataSet.GetUniqueTypeName("ItemCollection");
                            SampleCollectionType collectionType = dataSet.CreateCollectionType(uniqueTypeName2, (SampleType)compositeType);
                            string uniquePropertyName3          = dataSet.RootType.GetUniquePropertyName("Collection");
                            dataSet.RootType.AddProperty(uniquePropertyName3, (SampleType)collectionType);
                            dataSet.AutoGenerateValues();
                        }
                        else
                        {
                            string         uniquePropertyName = dataSet.RootType.GetUniquePropertyName("Property1");
                            SampleProperty sampleProperty     = dataSet.RootType.AddProperty(uniquePropertyName, (SampleType)SampleBasicType.String);
                            using (SampleDataValueBuilder valueBuilder = dataSet.CreateValueBuilder())
                            {
                                DocumentCompositeNode rootNode = valueBuilder.RootNode;
                                valueBuilder.RootNode.Properties[(IPropertyId)sampleProperty] = valueBuilder.CreatePropertyValue(rootNode, "Property1", StringTable.DefaultValueDataStore);
                            }
                            dataSet.Save();
                        }
                    }
                    flag = dataSet.IsSaved;
                }
            }
            finally
            {
                if (!flag && dataSet != null)
                {
                    this.SafelyRemoveSampleDataAndRootFolder(dataSet, true);
                    dataSet = (SampleDataSet)null;
                }
            }
            return(dataSet);
        }
Пример #7
0
        private DocumentNode CreateCollectionItemForPropertyInternal(DocumentCompositeNode documentNode, SampleProperty collectionProperty, string value)
        {
            SampleCollectionType sampleCollectionType = collectionProperty.PropertySampleType as SampleCollectionType;

            if (sampleCollectionType == null)
            {
                return((DocumentNode)null);
            }
            DocumentCompositeNode collectionNode = documentNode.Properties[(IPropertyId)collectionProperty] as DocumentCompositeNode;

            if (collectionNode == null)
            {
                collectionNode = this.CreateCompositeNode((SampleNonBasicType)sampleCollectionType);
                documentNode.Properties[(IPropertyId)collectionProperty] = (DocumentNode)collectionNode;
            }
            return(this.CreateCollectionItemInternal(collectionNode, value));
        }
Пример #8
0
        private SampleNonBasicType ReadType(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 && xmlSchemaSequence.Items.Count == 1)
            {
                XmlSchemaElement xmlSchemaElement = xmlSchemaSequence.Items[0] as XmlSchemaElement;
                if (xmlSchemaElement != null && xmlSchemaElement.MaxOccurs > new Decimal(1))
                {
                    SampleCollectionType collectionType = this.dataSet.CreateCollectionType(xmlComplexType.Name, (SampleType)SampleBasicType.String);
                    SampleType           sampleType     = this.GetSampleType(xmlSchemaElement.SchemaTypeName);
                    collectionType.ChangeItemType(sampleType);
                    if (collectionType.Name != xmlComplexType.Name)
                    {
                        throw new InvalidDataException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, ExceptionStringTable.InvalidNodeUsage, new object[2]
                        {
                            (object)this.xsdFileName,
                            (object)xmlComplexType.Name
                        }));
                    }
                    return((SampleNonBasicType)collectionType);
                }
            }
            SampleCompositeType compositeType = this.dataSet.CreateCompositeType(xmlComplexType.Name);

            if (compositeType.Name != xmlComplexType.Name)
            {
                throw new InvalidDataException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, ExceptionStringTable.InvalidNodeUsage, new object[2]
                {
                    (object)this.xsdFileName,
                    (object)xmlComplexType.Name
                }));
            }
            this.PopulateSampleCompositeType(compositeType, xmlComplexType);
            return((SampleNonBasicType)compositeType);
        }
Пример #9
0
        public void ChangeItemType(SampleType itemType)
        {
            if (this.itemSampleType == itemType)
            {
                return;
            }
            this.DeclaringDataSet.ThrowIfRecursiveRootType(itemType);
            for (SampleCollectionType sampleCollectionType = itemType as SampleCollectionType; sampleCollectionType != null; sampleCollectionType = sampleCollectionType.ItemSampleType as SampleCollectionType)
            {
                if (sampleCollectionType == this)
                {
                    throw new InvalidOperationException(ExceptionStringTable.SampleDataCollectionItemTypeCannotBeSelf);
                }
            }
            SampleType oldItemType = this.itemSampleType;

            this.itemSampleType = itemType;
            this.DeclaringDataSet.OnCollectionItemTypeChanged(this, oldItemType);
        }
Пример #10
0
        private DocumentNode GenerateNonBasicValue(SampleNonBasicType sampleType)
        {
            DocumentCompositeNode compositeNode = this.CreateCompositeNode(sampleType);

            if (sampleType.IsCollection)
            {
                SampleCollectionType sampleCollectionType = (SampleCollectionType)sampleType;
                if (this.buildingStack.PushCollectionItemType((SampleType)sampleCollectionType))
                {
                    int collectionCount = this.CollectionCount;
                    ++this.collectionDepth;
                    for (int index = 0; index < collectionCount; ++index)
                    {
                        DocumentNode documentNode = this.GenerateValue(sampleCollectionType.ItemSampleType);
                        compositeNode.Children.Add(documentNode);
                    }
                    --this.collectionDepth;
                    this.buildingStack.Pop();
                }
            }
            else
            {
                foreach (SampleProperty sampleProperty in (IEnumerable <SampleProperty>)((SampleCompositeType)sampleType).SampleProperties)
                {
                    if (this.buildingStack.PushProperty(sampleProperty))
                    {
                        DocumentNode documentNode = this.GeneratePropertyValue(sampleProperty);
                        if (documentNode != null)
                        {
                            compositeNode.Properties[(IPropertyId)sampleProperty] = documentNode;
                        }
                        this.buildingStack.Pop();
                    }
                }
            }
            return((DocumentNode)compositeNode);
        }