コード例 #1
0
        private void CreatePropertyValue(DocumentCompositeNode compositeNode, SampleProperty sampleProperty)
        {
            this.valueBuilder.InitCollectionDepth((DocumentNode)compositeNode);
            DocumentNode documentNode = this.valueBuilder.GeneratePropertyValue(sampleProperty);

            compositeNode.Properties[(IPropertyId)sampleProperty] = documentNode;
        }
コード例 #2
0
 private void RemoveNodesByProperty(DocumentCompositeNode compositeNode, SampleProperty deletedProperty)
 {
     if (compositeNode == null)
     {
         return;
     }
     if (compositeNode.Type == deletedProperty.DeclaringSampleType)
     {
         if (this.changeCount == 0 && compositeNode.Properties[(IPropertyId)deletedProperty] != null)
         {
             ++this.changeCount;
         }
         compositeNode.ClearValue((IPropertyId)deletedProperty);
     }
     for (int index = compositeNode.Properties.Count - 1; index >= 0; --index)
     {
         this.RemoveNodesByProperty(compositeNode.Properties[index] as DocumentCompositeNode, deletedProperty);
     }
     if (!compositeNode.SupportsChildren)
     {
         return;
     }
     for (int index = 0; index < compositeNode.Children.Count; ++index)
     {
         this.RemoveNodesByProperty(compositeNode.Children[index] as DocumentCompositeNode, deletedProperty);
     }
 }
コード例 #3
0
        private void UpdatePropertyValues(DocumentCompositeNode compositeNode, SamplePropertyTypeOrFormatChanged change)
        {
            if (compositeNode == null)
            {
                return;
            }
            SampleProperty sampleProperty = change.SampleProperty;

            if (compositeNode.Type == sampleProperty.DeclaringSampleType)
            {
                if (change.OldType == SampleBasicType.Image)
                {
                    DocumentPrimitiveNode documentPrimitiveNode = compositeNode.Properties[(IPropertyId)sampleProperty] as DocumentPrimitiveNode;
                    if (documentPrimitiveNode != null)
                    {
                        string relativePath = documentPrimitiveNode.GetValue <string>();
                        sampleProperty.DeclaringDataSet.UnuseAssetFile(relativePath);
                    }
                }
                this.CreatePropertyValue(compositeNode, sampleProperty);
                ++this.changeCount;
            }
            for (int index = 0; index < compositeNode.Properties.Count; ++index)
            {
                this.UpdatePropertyValues(compositeNode.Properties[index] as DocumentCompositeNode, change);
            }
            if (!compositeNode.SupportsChildren)
            {
                return;
            }
            for (int index = 0; index < compositeNode.Children.Count; ++index)
            {
                this.UpdatePropertyValues(compositeNode.Children[index] as DocumentCompositeNode, change);
            }
        }
コード例 #4
0
        private Type GenerateProperty(TypeBuilder typeBuilder, SampleProperty sampleProperty, ILGenerator ilDefaultConstructor)
        {
            Type            beginDesignTimeType = this.GetOrBeginDesignTimeType(sampleProperty.PropertySampleType);
            FieldBuilder    fieldBuilder        = typeBuilder.DefineField("_" + sampleProperty.Name, beginDesignTimeType, FieldAttributes.Private);
            PropertyBuilder propertyBuilder     = typeBuilder.DefineProperty(sampleProperty.Name, PropertyAttributes.HasDefault, fieldBuilder.FieldType, (Type[])null);

            if (sampleProperty.IsBasicType || sampleProperty.IsCollection)
            {
                this.InitializeField(fieldBuilder, ilDefaultConstructor, sampleProperty);
            }
            MethodAttributes attributes   = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName;
            MethodBuilder    mdBuilder1   = typeBuilder.DefineMethod("get_" + sampleProperty.Name, attributes, fieldBuilder.FieldType, Type.EmptyTypes);
            ILGenerator      ilGenerator1 = mdBuilder1.GetILGenerator();

            ilGenerator1.Emit(OpCodes.Ldarg_0);
            ilGenerator1.Emit(OpCodes.Ldfld, (FieldInfo)fieldBuilder);
            ilGenerator1.Emit(OpCodes.Ret);
            propertyBuilder.SetGetMethod(mdBuilder1);
            if (!sampleProperty.IsCollection)
            {
                MethodBuilder mdBuilder2 = typeBuilder.DefineMethod("set_" + sampleProperty.Name, attributes, (Type)null, new Type[1]
                {
                    fieldBuilder.FieldType
                });
                ILGenerator ilGenerator2 = mdBuilder2.GetILGenerator();
                ilGenerator2.DeclareLocal(typeof(bool));
                MethodInfo method1 = typeof(object).GetMethod("Equals", BindingFlags.Static | BindingFlags.Public);
                if (beginDesignTimeType.IsValueType)
                {
                    ilGenerator2.Emit(OpCodes.Ldarg_0);
                    ilGenerator2.Emit(OpCodes.Ldfld, (FieldInfo)fieldBuilder);
                    ilGenerator2.Emit(OpCodes.Box, beginDesignTimeType);
                    ilGenerator2.Emit(OpCodes.Ldarg_1);
                    ilGenerator2.Emit(OpCodes.Box, beginDesignTimeType);
                }
                else
                {
                    ilGenerator2.Emit(OpCodes.Ldarg_0);
                    ilGenerator2.Emit(OpCodes.Ldfld, (FieldInfo)fieldBuilder);
                    ilGenerator2.Emit(OpCodes.Ldarg_1);
                }
                ilGenerator2.Emit(OpCodes.Call, method1);
                Label label = ilGenerator2.DefineLabel();
                ilGenerator2.Emit(OpCodes.Stloc_0);
                ilGenerator2.Emit(OpCodes.Ldloc_0);
                ilGenerator2.Emit(OpCodes.Brtrue_S, label);
                ilGenerator2.Emit(OpCodes.Ldarg_0);
                ilGenerator2.Emit(OpCodes.Ldarg_1);
                ilGenerator2.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder);
                MethodInfo method2 = typeBuilder.BaseType.GetMethod("OnPropertyChanged");
                ilGenerator2.Emit(OpCodes.Ldarg_0);
                ilGenerator2.Emit(OpCodes.Ldstr, sampleProperty.Name);
                ilGenerator2.Emit(OpCodes.Call, method2);
                ilGenerator2.MarkLabel(label);
                ilGenerator2.Emit(OpCodes.Ret);
                propertyBuilder.SetSetMethod(mdBuilder2);
            }
            return(beginDesignTimeType);
        }
コード例 #5
0
        private static void UpdatePropertyFormatInfo(XmlSchemaAnnotated schemaItem, SampleProperty sampleProperty)
        {
            XmlAttribute[] unhandledAttributes  = schemaItem.UnhandledAttributes;
            string         blendAttributeValue1 = SampleDataXsdParser.GetBlendAttributeValue(unhandledAttributes, SampleProperty.FormatAttribute);
            string         blendAttributeValue2 = SampleDataXsdParser.GetBlendAttributeValue(unhandledAttributes, SampleProperty.FormatParametersAttribute);

            sampleProperty.ChangeFormat(blendAttributeValue1, blendAttributeValue2);
        }
コード例 #6
0
 public void DeleteProperty(SampleProperty sampleProperty)
 {
     for (int index = 0; index < this.sampleProperties.Count; ++index)
     {
         if (sampleProperty == this.sampleProperties[index])
         {
             this.sampleProperties.RemoveAt(index);
             this.DeclaringDataSet.OnPropertyDeleted(sampleProperty);
             break;
         }
     }
 }
コード例 #7
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);
        }
コード例 #8
0
        public DocumentNode CreatePropertyValue(DocumentCompositeNode documentNode, SampleProperty sampleProperty, string value)
        {
            SampleCompositeType sampleCompositeType = documentNode.Type as SampleCompositeType;

            if (sampleCompositeType == null)
            {
                return((DocumentNode)null);
            }
            if (sampleProperty.DeclaringSampleType != sampleCompositeType)
            {
                return((DocumentNode)null);
            }
            return(this.CreatePropertyValueInternal(documentNode, sampleProperty, value));
        }
コード例 #9
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
                    }));
                }
            }
        }
コード例 #10
0
        public DocumentNode CreatePropertyValue(DocumentCompositeNode documentNode, string propertyName, string value)
        {
            SampleCompositeType sampleCompositeType = documentNode.Type as SampleCompositeType;

            if (sampleCompositeType == null)
            {
                return((DocumentNode)null);
            }
            SampleProperty sampleProperty = sampleCompositeType.GetSampleProperty(propertyName);

            if (sampleProperty == null)
            {
                return((DocumentNode)null);
            }
            return(this.CreatePropertyValueInternal(documentNode, sampleProperty, value));
        }
コード例 #11
0
        public DocumentNode CreateCollectionItemForProperty(DocumentCompositeNode documentNode, string collectionPropertyName, string value)
        {
            SampleCompositeType sampleCompositeType = documentNode.Type as SampleCompositeType;

            if (sampleCompositeType == null)
            {
                return((DocumentNode)null);
            }
            SampleProperty sampleProperty = sampleCompositeType.GetSampleProperty(collectionPropertyName);

            if (sampleProperty == null)
            {
                return((DocumentNode)null);
            }
            return(this.CreateCollectionItemForPropertyInternal(documentNode, sampleProperty, value));
        }
コード例 #12
0
        public SampleProperty AddProperty(string name, SampleType sampleType)
        {
            if (sampleType == this.DeclaringDataSet.RootType)
            {
                throw new InvalidOperationException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, ExceptionStringTable.RecursiveSampleDataRootTypeNotSupported, new object[1]
                {
                    (object)this.DeclaringDataSet.RootType.Name
                }));
            }
            if (this.GetSampleProperty(name) != null)
            {
                throw new InvalidOperationException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, ExceptionStringTable.NameIsAlreadyInUse, new object[1]
                {
                    (object)name
                }));
            }
            SampleProperty sampleProperty = new SampleProperty(name, sampleType, this);

            this.sampleProperties.Add(sampleProperty);
            this.DeclaringDataSet.OnPropertyAdded(sampleProperty);
            return(sampleProperty);
        }
コード例 #13
0
 private void AddPropertyValues(DocumentCompositeNode compositeNode, SampleProperty newProperty)
 {
     if (compositeNode == null)
     {
         return;
     }
     if (compositeNode.SupportsChildren)
     {
         for (int index = 0; index < compositeNode.Children.Count; ++index)
         {
             this.AddPropertyValues(compositeNode.Children[index] as DocumentCompositeNode, newProperty);
         }
     }
     for (int index = 0; index < compositeNode.Properties.Count; ++index)
     {
         this.AddPropertyValues(compositeNode.Properties[index] as DocumentCompositeNode, newProperty);
     }
     if (compositeNode.Type != newProperty.DeclaringSampleType)
     {
         return;
     }
     this.CreatePropertyValue(compositeNode, newProperty);
     ++this.changeCount;
 }
コード例 #14
0
        private void UpdatePropertyFormatInfo(XmlSchemaAnnotated schemaItem, SampleProperty sampleProperty)
        {
            XmlAttribute blendAttribute1 = this.CreateBlendAttribute(sampleProperty.Format, SampleProperty.FormatAttribute);
            XmlAttribute blendAttribute2 = this.CreateBlendAttribute(sampleProperty.FormatParameters, SampleProperty.FormatParametersAttribute);

            if (blendAttribute1 == null && blendAttribute2 == null)
            {
                return;
            }
            XmlAttribute[] xmlAttributeArray;
            if (blendAttribute1 == null)
            {
                xmlAttributeArray = new XmlAttribute[1]
                {
                    blendAttribute2
                }
            }
            ;
            else if (blendAttribute2 == null)
            {
                xmlAttributeArray = new XmlAttribute[1]
                {
                    blendAttribute1
                }
            }
            ;
            else
            {
                xmlAttributeArray = new XmlAttribute[2]
                {
                    blendAttribute1,
                    blendAttribute2
                }
            };
            schemaItem.UnhandledAttributes = xmlAttributeArray;
        }
コード例 #15
0
        private DocumentNode CreatePropertyValueInternal(DocumentCompositeNode documentNode, SampleProperty sampleProperty, string value)
        {
            DocumentNode documentNode1;

            if (sampleProperty.PropertySampleType.IsBasicType)
            {
                SampleBasicType sampleType = (SampleBasicType)sampleProperty.PropertySampleType;
                if (value == null)
                {
                    value = this.valueGenerator.GetRandomValue(sampleType, sampleProperty.Format, sampleProperty.FormatParameters);
                }
                documentNode1 = (DocumentNode)this.CreateBasicNode(sampleType, value);
            }
            else
            {
                documentNode1 = (DocumentNode)this.CreateCompositeNode((SampleNonBasicType)sampleProperty.PropertySampleType);
            }
            documentNode.Properties[(IPropertyId)sampleProperty] = documentNode1;
            return(documentNode1);
        }
コード例 #16
0
            public string GetPropertyDefaultValue(SampleProperty sampleProperty)
            {
                SampleType propertySampleType = sampleProperty.PropertySampleType;

                return(!propertySampleType.IsBasicType ? this.NewInstanceFieldValue.Replace(SampleCodeGenerator.PropertyTypeTemplate, propertySampleType.Name) : this.BasicTypeValues[(SampleBasicType)propertySampleType]);
            }
コード例 #17
0
 public DocumentNode GeneratePropertyValue(SampleProperty sampleProperty)
 {
     return(!sampleProperty.IsBasicType ? this.GenerateNonBasicValue((SampleNonBasicType)sampleProperty.PropertySampleType) : this.GenerateBasicValue((SampleBasicType)sampleProperty.PropertySampleType, sampleProperty.Format, sampleProperty.FormatParameters));
 }
コード例 #18
0
 public bool PushProperty(SampleProperty sampleProperty)
 {
     return(this.Push(sampleProperty.PropertySampleType, sampleProperty.Name));
 }
コード例 #19
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));
        }
コード例 #20
0
        public DocumentNode CreateCollectionItemForProperty(DocumentCompositeNode documentNode, SampleProperty collectionProperty, string value)
        {
            SampleCompositeType sampleCompositeType = documentNode.Type as SampleCompositeType;

            if (sampleCompositeType == null)
            {
                return((DocumentNode)null);
            }
            if (collectionProperty.DeclaringSampleType != sampleCompositeType)
            {
                return((DocumentNode)null);
            }
            return(this.CreateCollectionItemForPropertyInternal(documentNode, collectionProperty, value));
        }
コード例 #21
0
 public DocumentNode CreateCollectionItemForProperty(DocumentCompositeNode documentNode, SampleProperty collectionProperty)
 {
     return(this.CreateCollectionItemForProperty(documentNode, collectionProperty, (string)null));
 }
コード例 #22
0
 public DocumentNode CreatePropertyValue(DocumentCompositeNode documentNode, SampleProperty sampleProperty)
 {
     return(this.CreatePropertyValue(documentNode, sampleProperty, (string)null));
 }
コード例 #23
0
 private void InitializeField(FieldBuilder fieldBuilder, ILGenerator ilConstructor, SampleProperty sampleProperty)
 {
     if (ilConstructor == null)
     {
         return;
     }
     if (!sampleProperty.IsBasicType)
     {
         SampleDataDesignTimeTypeGenerator.TypeBuildState typeBuildState = this.buildStates[(SampleNonBasicType)sampleProperty.PropertySampleType];
         ilConstructor.Emit(OpCodes.Ldarg_0);
         ilConstructor.Emit(OpCodes.Newobj, (ConstructorInfo)typeBuildState.ConstructorBuilder);
         ilConstructor.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder);
     }
     else
     {
         SampleBasicType sampleBasicType = (SampleBasicType)sampleProperty.PropertySampleType;
         if (sampleBasicType == SampleBasicType.String)
         {
             FieldInfo field = typeof(string).GetField("Empty", BindingFlags.Static | BindingFlags.Public);
             ilConstructor.Emit(OpCodes.Ldarg_0);
             ilConstructor.Emit(OpCodes.Ldsfld, field);
             ilConstructor.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder);
         }
         else if (sampleBasicType == SampleBasicType.Date)
         {
             PropertyInfo property = typeof(DateTime).GetProperty("Today", BindingFlags.Static | BindingFlags.Public);
             ilConstructor.Emit(OpCodes.Ldarg_0);
             ilConstructor.Emit(OpCodes.Call, property.GetGetMethod());
             ilConstructor.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder);
         }
         else if (sampleBasicType == SampleBasicType.Number)
         {
             ilConstructor.Emit(OpCodes.Ldarg_0);
             ilConstructor.Emit(OpCodes.Ldc_R8, 0.0);
             ilConstructor.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder);
         }
         else if (sampleBasicType == SampleBasicType.Boolean)
         {
             ilConstructor.Emit(OpCodes.Ldarg_0);
             ilConstructor.Emit(OpCodes.Ldc_I4, 0);
             ilConstructor.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder);
         }
         else
         {
             if (sampleBasicType != SampleBasicType.Image)
             {
                 return;
             }
             ilConstructor.Emit(OpCodes.Ldarg_0);
             ilConstructor.Emit(OpCodes.Ldnull);
             ilConstructor.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder);
         }
     }
 }
コード例 #24
0
 internal void TransferSortValue(SampleProperty fromProperty)
 {
     this.sortValue = fromProperty.sortValue;
 }