コード例 #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);
        }
コード例 #2
0
        public void AddCollection()
        {
            if (!this.schemaItem.Schema.DataSource.IsSampleDataSource)
            {
                return;
            }
            SampleDataSet       sampleData    = this.schemaItem.Schema.DataSource.SampleData;
            SampleCompositeType effectiveType = this.DataSchemaNode.EffectiveType;

            if (effectiveType == null)
            {
                return;
            }
            this.model.SelectionContext.Clear();
            string uniquePropertyName           = effectiveType.GetUniquePropertyName("Collection");
            string uniqueTypeName               = sampleData.GetUniqueTypeName(uniquePropertyName + "Item");
            SampleCompositeType  compositeType  = sampleData.CreateCompositeType(uniqueTypeName);
            SampleCollectionType collectionType = sampleData.CreateCollectionType((SampleNonBasicType)compositeType);

            effectiveType.AddProperty(uniquePropertyName, (SampleType)collectionType);
            string schemaNodePath = DataSchemaItem.ProvideNodePathForPendingEdit(this, uniquePropertyName);

            this.model.RenameSampleDataSchemaItemUponRebuild(this.schemaItem.Schema.DataSource, schemaNodePath);
            this.model.ExtendSelectionUponRebuild(this.schemaItem.Schema.DataSource, schemaNodePath);
            this.IsExpanded = true;
            using (TemporaryCursor.SetWaitCursor())
                sampleData.CommitChanges(this.ViewModel.DesignerContext.MessageDisplayService);
        }
コード例 #3
0
        private string CreateNewProperty(SampleDataSet dataSet, string newProperyName)
        {
            string                uniqueTypeName = dataSet.GetUniqueTypeName(newProperyName);
            SampleProperty        sampleProperty = dataSet.RootType.AddProperty(uniqueTypeName, (SampleType)SampleBasicType.String);
            DocumentCompositeNode newRootNode    = (DocumentCompositeNode)dataSet.RootNode.Clone(dataSet.RootNode.Context);

            newRootNode.Properties[(IPropertyId)sampleProperty] = (DocumentNode)newRootNode.Context.CreateNode(StringTable.DefaultValueDataStore);
            dataSet.CommitChanges(newRootNode, this.ObjectSet.ViewModel.DesignerContext.MessageDisplayService);
            return(uniqueTypeName);
        }