示例#1
0
        public void MakeHierarchicalCollection()
        {
            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();
            SampleNonBasicType sampleNonBasicType   = (SampleNonBasicType)this.DataSchemaNode.SampleType;
            string             uniquePropertyName1  = effectiveType.GetUniquePropertyName(this.DataSchemaNode.PathName);
            SampleProperty     hierarchicalProperty = effectiveType.AddProperty(uniquePropertyName1, (SampleType)sampleNonBasicType);
            SampleProperty     sampleProperty       = this.DataSchemaNode.EffectiveParentType.GetSampleProperty(this.DataSchemaNode.PathName);
            string             uniquePropertyName2  = DataSchemaItem.GetUniquePropertyName(sampleProperty, hierarchicalProperty, uniquePropertyName1);
            string             schemaNodePath       = DataSchemaItem.ProvideNodePathForPendingEdit(this, uniquePropertyName2, sampleProperty, hierarchicalProperty);

            sampleProperty.Rename(uniquePropertyName2);
            hierarchicalProperty.Rename(uniquePropertyName2);
            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);
        }
示例#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 static SampleProperty GetHierarchicalPropertyToRename(SampleProperty sampleProperty)
        {
            SampleCollectionType collectionType = sampleProperty.PropertySampleType as SampleCollectionType;

            if (collectionType == null)
            {
                return((SampleProperty)null);
            }
            SampleCompositeType sampleCompositeType = collectionType.ItemSampleType as SampleCompositeType;

            if (sampleCompositeType == null)
            {
                return((SampleProperty)null);
            }
            SampleProperty hierarchicalProperty = Enumerable.FirstOrDefault <SampleProperty>((IEnumerable <SampleProperty>)sampleCompositeType.SampleProperties, (Func <SampleProperty, bool>)(p => p.PropertySampleType == collectionType));

            if (hierarchicalProperty == null)
            {
                return((SampleProperty)null);
            }
            if (Enumerable.FirstOrDefault <SampleProperty>((IEnumerable <SampleProperty>)sampleCompositeType.SampleProperties, (Func <SampleProperty, bool>)(p =>
            {
                if (p != hierarchicalProperty)
                {
                    return(p.PropertySampleType == collectionType);
                }
                return(false);
            })) != null)
            {
                return((SampleProperty)null);
            }
            return(hierarchicalProperty);
        }
示例#4
0
        private bool RenameProperty(string rawName)
        {
            SampleCompositeType effectiveParentType1 = this.DataSchemaNode.EffectiveParentType;
            SampleProperty      sampleProperty1      = effectiveParentType1.GetSampleProperty(this.DataSchemaNode.PathName);
            SampleProperty      propertyToRename1    = DataSchemaItem.GetHierarchicalPropertyToRename(sampleProperty1);

            if (propertyToRename1 == null || propertyToRename1 != sampleProperty1)
            {
                return(this.RenamePropertyInternal(sampleProperty1, propertyToRename1, rawName));
            }
            for (DataSchemaItem dataSchemaItem = this.Parent as DataSchemaItem; dataSchemaItem != null; dataSchemaItem = dataSchemaItem.Parent as DataSchemaItem)
            {
                SampleCompositeType effectiveParentType2 = dataSchemaItem.DataSchemaNode.EffectiveParentType;
                if (effectiveParentType2 != effectiveParentType1)
                {
                    SampleProperty sampleProperty2 = effectiveParentType2 != null?effectiveParentType2.GetSampleProperty(dataSchemaItem.DataSchemaNode.PathName) : (SampleProperty)null;

                    if (sampleProperty2 == null)
                    {
                        return(this.RenamePropertyInternal(sampleProperty1, (SampleProperty)null, rawName));
                    }
                    SampleProperty propertyToRename2 = DataSchemaItem.GetHierarchicalPropertyToRename(sampleProperty2);
                    if (propertyToRename2 != sampleProperty1)
                    {
                        return(this.RenamePropertyInternal(sampleProperty1, (SampleProperty)null, rawName));
                    }
                    return(dataSchemaItem.RenamePropertyInternal(sampleProperty2, propertyToRename2, rawName));
                }
            }
            return(this.RenamePropertyInternal(sampleProperty1, (SampleProperty)null, rawName));
        }
        public SampleDataEditorModel(DataSchemaNodePath schemaPath, IMessageDisplayService messageService)
        {
            this.messageService = messageService;
            SampleType     sampleType         = schemaPath.Node.SampleType;
            DataSchemaNode collectionItemNode = schemaPath.EffectiveCollectionItemNode;

            this.editingSchemaPath    = new DataSchemaNodePath(schemaPath.Schema, collectionItemNode.Parent);
            this.sampleCompositeType  = (SampleCompositeType)collectionItemNode.SampleType;
            this.ValueBuilder         = new SampleDataValueBuilderBase(this.SampleDataSet, this.SampleDataSet.RootNode.Context);
            this.SampleDataProperties = (IList <SampleDataProperty>) new List <SampleDataProperty>();
            foreach (SampleProperty sampleProperty in (IEnumerable <SampleProperty>) this.sampleCompositeType.SampleProperties)
            {
                if (sampleProperty.IsBasicType)
                {
                    this.SampleDataProperties.Add(new SampleDataProperty(sampleProperty, this));
                }
            }
            ((List <SampleDataProperty>) this.SampleDataProperties).Sort((Comparison <SampleDataProperty>)((a, b) => StringLogicalComparer.Instance.Compare(a.SampleProperty.Name, b.SampleProperty.Name)));
            this.sourceCollectionNode = this.GetCollectionNode(this.SampleDataSet.RootNode, false);
            this.ValueBuilder.InitCollectionDepth(this.editingSchemaPath);
            List <SampleDataRow> rows = new List <SampleDataRow>();

            if (this.sourceCollectionNode != null)
            {
                int count = this.sourceCollectionNode.Children.Count;
                for (int rowNumber = 0; rowNumber < count; ++rowNumber)
                {
                    rows.Add(new SampleDataRow(this, rowNumber));
                }
            }
            this.SampleDataRows = (ObservableCollection <SampleDataRow>) new SampleDataEditorModel.SampleDataRowCollection(rows);
        }
示例#6
0
        private void ChangeEffectivePropertyIfValid(DataSchemaItem.ModifySamplePropertyOperation operation)
        {
            SampleCompositeType effectiveParentType = this.DataSchemaNode.EffectiveParentType;

            if (effectiveParentType == null)
            {
                return;
            }
            SampleDataSet  declaringDataSet = effectiveParentType.DeclaringDataSet;
            SampleProperty sampleProperty   = effectiveParentType.GetSampleProperty(this.DataSchemaNode.PathName);

            if (sampleProperty == null)
            {
                return;
            }
            operation(effectiveParentType, sampleProperty);
            using (TemporaryCursor.SetWaitCursor())
                declaringDataSet.CommitChanges(this.ViewModel.DesignerContext.MessageDisplayService);
        }
示例#7
0
        private static string ProvideNodePathForPendingEdit(DataSchemaItem parentItem, string newPropertyName, params SampleProperty[] renamedProperties)
        {
            DataSchemaNodePath dataSchemaNodePath = parentItem.DataSchemaNodePath;
            DataSchemaNode     endNode            = (DataSchemaNode)null;

            if (dataSchemaNodePath.IsCollection)
            {
                endNode = dataSchemaNodePath.EffectiveCollectionItemNode;
            }
            if (endNode == null)
            {
                endNode = dataSchemaNodePath.Node;
            }
            if (endNode == null)
            {
                return(newPropertyName);
            }
            string inheritedPath = (string)null;

            if (renamedProperties.Length == 0)
            {
                if (endNode != dataSchemaNodePath.Node)
                {
                    dataSchemaNodePath = new DataSchemaNodePath(dataSchemaNodePath.Schema, endNode);
                }
                return(ClrObjectSchema.CombinePaths(dataSchemaNodePath.Path, newPropertyName));
            }
            List <string> list = new List <string>()
            {
                newPropertyName
            };
            string pathName = endNode.PathName;

            for (DataSchemaNode parent = endNode.Parent; parent != null; parent = parent.Parent)
            {
                SampleCompositeType sampleCompositeType = parent.SampleType as SampleCompositeType;
                if (sampleCompositeType == null)
                {
                    list.Add(pathName);
                }
                else
                {
                    string         name           = pathName;
                    SampleProperty sampleProperty = sampleCompositeType.GetSampleProperty(name);
                    if (Enumerable.FirstOrDefault <SampleProperty>((IEnumerable <SampleProperty>)renamedProperties, (Func <SampleProperty, bool>)(p => p == sampleProperty)) != null)
                    {
                        name = newPropertyName;
                    }
                    list.Add(name);
                }
                if (parent != dataSchemaNodePath.Schema.Root)
                {
                    pathName = parent.PathName;
                }
                else
                {
                    break;
                }
            }
            for (int index = list.Count - 1; index >= 0; --index)
            {
                inheritedPath = ClrObjectSchema.CombinePaths(inheritedPath, list[index]);
            }
            return(inheritedPath);
        }