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);
        }
示例#2
0
        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 IProperty AddProperty(IType compositeType, string propertyName, IType propertyType)
        {
            SampleCompositeType sampleCompositeType = (SampleCompositeType)compositeType;
            SampleType          sampleType          = this.FromType(propertyType);

            return((IProperty)sampleCompositeType.AddProperty(propertyName, sampleType));
        }