コード例 #1
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);
        }