Exemple #1
0
        private static void AddNewProperties(List <CustomProperty> propCollection, Type customActivityType, IServiceProvider serviceProvider, List <CustomProperty> existingProps)
        {
            IMemberCreationService memberCreationService = serviceProvider.GetService(typeof(IMemberCreationService)) as IMemberCreationService;

            if (memberCreationService == null)
            {
                throw new Exception(SR.GetString(SR.General_MissingService, typeof(IMemberCreationService).FullName));
            }

            ITypeProvider typeProvider = serviceProvider.GetService(typeof(ITypeProvider)) as ITypeProvider;

            if (typeProvider == null)
            {
                throw new Exception(SR.GetString(SR.General_MissingService, typeof(ITypeProvider).FullName));
            }

            try
            {
                //



                foreach (CustomProperty property in propCollection)
                {
                    bool createNew = (property.oldPropertyName == null || property.oldPropertyType == null);
                    if (!createNew)
                    {
                        if (!property.IsEvent)
                        {
                            createNew = (customActivityType.GetProperty(property.oldPropertyName, typeProvider.GetType(property.oldPropertyType)) == null);
                        }
                        else
                        {
                            createNew = (customActivityType.GetEvent(property.oldPropertyName) == null);
                        }
                    }

                    if (createNew)
                    {
                        AttributeInfo[] attributes = CreateCustomPropertyAttributeArray(property, serviceProvider);
                        if (property.IsEvent)
                        {
                            memberCreationService.CreateEvent(customActivityType.FullName, property.Name, typeProvider.GetType(property.Type), attributes, property.GenerateDependencyProperty);
                        }
                        else
                        {
                            memberCreationService.CreateProperty(customActivityType.FullName, property.Name, typeProvider.GetType(property.Type), attributes, property.GenerateDependencyProperty, false, false, null, false);
                        }
                    }
                    else
                    {
                        //

                        CustomProperty oldProperty = null;
                        foreach (CustomProperty existingProperty in existingProps)
                        {
                            if (existingProperty.Name == property.oldPropertyName && existingProperty.Type == property.oldPropertyType)
                            {
                                oldProperty = existingProperty;
                            }
                        }

                        if (oldProperty == null || ArePropertiesDifferent(property, oldProperty))
                        {
                            AttributeInfo[] attributes    = CreateCustomPropertyAttributeArray(property, serviceProvider);
                            AttributeInfo[] oldAttributes = CreateCustomPropertyAttributeArray(oldProperty, serviceProvider);

                            Type propertyType    = typeProvider.GetType(property.Type, false);
                            Type oldPropertyType = typeProvider.GetType(property.oldPropertyType, false);
                            if (propertyType != null)
                            {
                                if (property.IsEvent)
                                {
                                    memberCreationService.UpdateEvent(customActivityType.FullName, property.oldPropertyName, oldPropertyType, property.Name, propertyType, attributes, property.GenerateDependencyProperty, false);
                                }
                                else
                                {
                                    memberCreationService.UpdateProperty(customActivityType.FullName, property.oldPropertyName, oldPropertyType, property.Name, propertyType, attributes, property.GenerateDependencyProperty, false);
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                //
            }
        }
        private static void AddNewProperties(List <CustomProperty> propCollection, System.Type customActivityType, IServiceProvider serviceProvider, List <CustomProperty> existingProps)
        {
            IMemberCreationService service = serviceProvider.GetService(typeof(IMemberCreationService)) as IMemberCreationService;

            if (service == null)
            {
                throw new Exception(SR.GetString("General_MissingService", new object[] { typeof(IMemberCreationService).FullName }));
            }
            ITypeProvider provider = serviceProvider.GetService(typeof(ITypeProvider)) as ITypeProvider;

            if (provider == null)
            {
                throw new Exception(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).FullName }));
            }
            foreach (CustomProperty property in propCollection)
            {
                bool flag = (property.oldPropertyName == null) || (property.oldPropertyType == null);
                if (!flag)
                {
                    if (!property.IsEvent)
                    {
                        flag = customActivityType.GetProperty(property.oldPropertyName, provider.GetType(property.oldPropertyType)) == null;
                    }
                    else
                    {
                        flag = customActivityType.GetEvent(property.oldPropertyName) == null;
                    }
                }
                if (flag)
                {
                    AttributeInfo[] attributes = CreateCustomPropertyAttributeArray(property, serviceProvider);
                    if (property.IsEvent)
                    {
                        service.CreateEvent(customActivityType.FullName, property.Name, provider.GetType(property.Type), attributes, property.GenerateDependencyProperty);
                    }
                    else
                    {
                        service.CreateProperty(customActivityType.FullName, property.Name, provider.GetType(property.Type), attributes, property.GenerateDependencyProperty, false, false, null, false);
                    }
                }
                else
                {
                    CustomProperty oldProperty = null;
                    foreach (CustomProperty property3 in existingProps)
                    {
                        if ((property3.Name == property.oldPropertyName) && (property3.Type == property.oldPropertyType))
                        {
                            oldProperty = property3;
                        }
                    }
                    if ((oldProperty == null) || ArePropertiesDifferent(property, oldProperty))
                    {
                        AttributeInfo[] infoArray2 = CreateCustomPropertyAttributeArray(property, serviceProvider);
                        CreateCustomPropertyAttributeArray(oldProperty, serviceProvider);
                        System.Type newEventType = provider.GetType(property.Type, false);
                        System.Type type         = provider.GetType(property.oldPropertyType, false);
                        if (newEventType != null)
                        {
                            if (property.IsEvent)
                            {
                                service.UpdateEvent(customActivityType.FullName, property.oldPropertyName, type, property.Name, newEventType, infoArray2, property.GenerateDependencyProperty, false);
                            }
                            else
                            {
                                service.UpdateProperty(customActivityType.FullName, property.oldPropertyName, type, property.Name, newEventType, infoArray2, property.GenerateDependencyProperty, false);
                            }
                        }
                    }
                }
            }
        }