コード例 #1
0
 private void OnExpressionBuilderComboBoxSelectedIndexChanged(object sender, EventArgs e)
 {
     if (!this._internalChange)
     {
         this._currentSheet = null;
         if (this._expressionBuilderComboBox.SelectedItem != this.NoneItem)
         {
             this._currentEditor = (ExpressionEditor)this._expressionEditors[this._expressionBuilderComboBox.SelectedItem.ToString()];
             if (this._currentNode != null)
             {
                 if (this._currentNode.IsBound)
                 {
                     ExpressionBinding binding = this._currentNode.Binding;
                     if (this._expressionEditors[binding.ExpressionPrefix] == this._currentEditor)
                     {
                         this._currentSheet = this._currentEditor.GetExpressionEditorSheet(binding.Expression, base.ServiceProvider);
                     }
                 }
                 if (this._currentSheet == null)
                 {
                     this._currentSheet = this._currentEditor.GetExpressionEditorSheet(string.Empty, base.ServiceProvider);
                 }
                 this._currentNode.IsValid = this._currentSheet.IsValid;
             }
         }
         this.SaveCurrentExpressionBinding();
         this._expressionBuilderPropertyGrid.SelectedObject = this._currentSheet;
         this.UpdateUIState();
     }
 }
コード例 #2
0
        public static ExpressionEditor GetExpressionEditor(string expressionPrefix, IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }
            if (expressionPrefix.Length == 0)
            {
                return(null);
            }
            ExpressionEditor editor  = null;
            IWebApplication  service = (IWebApplication)serviceProvider.GetService(typeof(IWebApplication));

            if (service != null)
            {
                IDictionary expressionEditorsCache = GetExpressionEditorsCache(service);
                if (expressionEditorsCache != null)
                {
                    editor = (ExpressionEditor)expressionEditorsCache[expressionPrefix];
                }
                if (editor == null)
                {
                    string str;
                    Type   expressionBuilderType = GetExpressionBuilderType(expressionPrefix, serviceProvider, out str);
                    if (expressionBuilderType != null)
                    {
                        editor = GetExpressionEditorInternal(expressionBuilderType, str, service, serviceProvider);
                    }
                }
            }
            return(editor);
        }
コード例 #3
0
        private void LoadExpressionEditors()
        {
            this._expressionEditors = new HybridDictionary(true);
            IWebApplication service = (IWebApplication)base.ServiceProvider.GetService(typeof(IWebApplication));

            if (service != null)
            {
                try
                {
                    System.Configuration.Configuration configuration = service.OpenWebConfiguration(true);
                    if (configuration != null)
                    {
                        CompilationSection section = (CompilationSection)configuration.GetSection("system.web/compilation");
                        foreach (ExpressionBuilder builder in section.ExpressionBuilders)
                        {
                            string           expressionPrefix = builder.ExpressionPrefix;
                            ExpressionEditor expressionEditor = ExpressionEditor.GetExpressionEditor(expressionPrefix, base.ServiceProvider);
                            if (expressionEditor != null)
                            {
                                this._expressionEditors[expressionPrefix] = expressionEditor;
                                this._expressionBuilderComboBox.Items.Add(new ExpressionItem(expressionPrefix));
                            }
                        }
                    }
                }
                catch
                {
                }
                this._expressionBuilderComboBox.InvalidateDropDownWidth();
            }
            this._expressionBuilderComboBox.Items.Add(this.NoneItem);
        }
コード例 #4
0
        private static string LocalizeControl(Control control, IServiceProvider serviceProvider, IDesignTimeResourceWriter resourceWriter, bool shouldLocalizeInnerContent)
        {
            ResourceExpressionEditor expressionEditor  = (ResourceExpressionEditor)ExpressionEditor.GetExpressionEditor("resources", serviceProvider);
            IControlBuilderAccessor  accessor          = control;
            ControlBuilder           controlBuilder    = accessor.ControlBuilder;
            ObjectPersistData        objectPersistData = controlBuilder.GetObjectPersistData();
            string resourceKey = controlBuilder.GetResourceKey();
            string b           = LocalizeObject(serviceProvider, control, objectPersistData, expressionEditor, resourceWriter, resourceKey, string.Empty, control, string.Empty, shouldLocalizeInnerContent, false, false);

            if (!string.Equals(resourceKey, b, StringComparison.OrdinalIgnoreCase))
            {
                controlBuilder.SetResourceKey(b);
            }
            if (objectPersistData != null)
            {
                foreach (PropertyEntry entry in objectPersistData.AllPropertyEntries)
                {
                    BoundPropertyEntry entry2 = entry as BoundPropertyEntry;
                    if ((entry2 != null) && !entry2.Generated)
                    {
                        string[] strArray = entry2.Name.Split(new char[] { '.' });
                        if (strArray.Length > 1)
                        {
                            object component = control;
                            foreach (string str3 in strArray)
                            {
                                PropertyDescriptor descriptor = TypeDescriptor.GetProperties(component)[str3];
                                if (descriptor == null)
                                {
                                    break;
                                }
                                PersistenceModeAttribute attribute = descriptor.Attributes[typeof(PersistenceModeAttribute)] as PersistenceModeAttribute;
                                if (attribute != PersistenceModeAttribute.Attribute)
                                {
                                    if (string.Equals(entry2.ExpressionPrefix, "resources", StringComparison.OrdinalIgnoreCase))
                                    {
                                        System.Web.Compilation.ResourceExpressionFields parsedExpressionData = entry2.ParsedExpressionData as System.Web.Compilation.ResourceExpressionFields;
                                        if ((parsedExpressionData != null) && string.IsNullOrEmpty(parsedExpressionData.ClassKey))
                                        {
                                            object obj3 = expressionEditor.EvaluateExpression(entry2.Expression, entry2.ParsedExpressionData, entry2.PropertyInfo.PropertyType, serviceProvider);
                                            if (obj3 == null)
                                            {
                                                object obj4;
                                                obj3 = ControlDesigner.GetComplexProperty(control, entry2.Name, out obj4).GetValue(obj4);
                                            }
                                            resourceWriter.AddResource(parsedExpressionData.ResourceKey, obj3);
                                        }
                                    }
                                    break;
                                }
                                component = descriptor.GetValue(component);
                            }
                        }
                    }
                }
            }
            return(b);
        }
コード例 #5
0
        private void OnBindablePropsTreeAfterSelect(object sender, TreeViewEventArgs e)
        {
            BindablePropertyNode selectedNode = (BindablePropertyNode)this._bindablePropsTree.SelectedNode;

            if (this._currentNode != selectedNode)
            {
                this._currentNode = selectedNode;
                if ((this._currentNode != null) && this._currentNode.IsBound)
                {
                    ExpressionBinding binding = this._currentNode.Binding;
                    if (!this._currentNode.IsGenerated)
                    {
                        ExpressionEditor editor = (ExpressionEditor)this._expressionEditors[binding.ExpressionPrefix];
                        if (editor == null)
                        {
                            UIServiceHelper.ShowMessage(base.ServiceProvider, System.Design.SR.GetString("ExpressionBindingsDialog_UndefinedExpressionPrefix", new object[] { binding.ExpressionPrefix }), System.Design.SR.GetString("ExpressionBindingsDialog_Text", new object[] { this.Control.Site.Name }), MessageBoxButtons.OK);
                            editor = new GenericExpressionEditor();
                        }
                        this._currentEditor  = editor;
                        this._currentSheet   = this._currentEditor.GetExpressionEditorSheet(binding.Expression, base.ServiceProvider);
                        this._internalChange = true;
                        try
                        {
                            foreach (ExpressionItem item in this._expressionBuilderComboBox.Items)
                            {
                                if (string.Equals(item.ToString(), binding.ExpressionPrefix, StringComparison.OrdinalIgnoreCase))
                                {
                                    this._expressionBuilderComboBox.SelectedItem = item;
                                }
                            }
                            this._currentNode.IsValid = this._currentSheet.IsValid;
                        }
                        finally
                        {
                            this._internalChange = false;
                        }
                    }
                }
                else
                {
                    this._expressionBuilderComboBox.SelectedItem = this.NoneItem;
                    this._currentEditor = null;
                    this._currentSheet  = null;
                }
                this._expressionBuilderPropertyGrid.SelectedObject = this._currentSheet;
                this.UpdateUIState();
            }
        }
コード例 #6
0
        internal static ExpressionEditor GetExpressionEditorInternal(Type expressionBuilderType, string expressionPrefix, IWebApplication webApp, IServiceProvider serviceProvider)
        {
            if (expressionBuilderType == null)
            {
                throw new ArgumentNullException("expressionBuilderType");
            }
            ExpressionEditor editor = null;

            object[] customAttributes           = expressionBuilderType.GetCustomAttributes(typeof(ExpressionEditorAttribute), true);
            ExpressionEditorAttribute attribute = null;

            if (customAttributes.Length > 0)
            {
                attribute = (ExpressionEditorAttribute)customAttributes[0];
            }
            if (attribute != null)
            {
                string editorTypeName = attribute.EditorTypeName;
                Type   c = Type.GetType(editorTypeName);
                if (c == null)
                {
                    ITypeResolutionService service = (ITypeResolutionService)serviceProvider.GetService(typeof(ITypeResolutionService));
                    if (service != null)
                    {
                        c = service.GetType(editorTypeName);
                    }
                }
                if ((c != null) && typeof(ExpressionEditor).IsAssignableFrom(c))
                {
                    editor = (ExpressionEditor)Activator.CreateInstance(c);
                    editor.SetExpressionPrefix(expressionPrefix);
                }
                IDictionary expressionEditorsCache = GetExpressionEditorsCache(webApp);
                if (expressionEditorsCache != null)
                {
                    expressionEditorsCache[expressionPrefix] = editor;
                }
                IDictionary expressionEditorsByTypeCache = GetExpressionEditorsByTypeCache(webApp);
                if (expressionEditorsByTypeCache != null)
                {
                    expressionEditorsByTypeCache[expressionBuilderType] = editor;
                }
            }
            return(editor);
        }
コード例 #7
0
        public static ExpressionEditor GetExpressionEditor(Type expressionBuilderType, IServiceProvider serviceProvider)
        {
            object[] attrs = expressionBuilderType.GetCustomAttributes(typeof(ExpressionEditorAttribute), false);

            if (attrs == null || attrs.Length == 0)
            {
                return(null);
            }

            ExpressionEditorAttribute ee = (ExpressionEditorAttribute)attrs[0];

            Type             editor_type = Type.GetType(ee.EditorTypeName);
            ExpressionEditor editor      = (ExpressionEditor)Activator.CreateInstance(editor_type);

            editor.ExpressionBuilderType = expressionBuilderType;

            return(editor);
        }
コード例 #8
0
        public static ExpressionEditor GetExpressionEditor(Type expressionBuilderType, IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }
            if (expressionBuilderType == null)
            {
                throw new ArgumentNullException("expressionBuilderType");
            }
            ExpressionEditor editor  = null;
            IWebApplication  service = (IWebApplication)serviceProvider.GetService(typeof(IWebApplication));

            if (service != null)
            {
                IDictionary expressionEditorsByTypeCache = GetExpressionEditorsByTypeCache(service);
                if (expressionEditorsByTypeCache != null)
                {
                    editor = (ExpressionEditor)expressionEditorsByTypeCache[expressionBuilderType];
                }
                if (editor != null)
                {
                    return(editor);
                }
                System.Configuration.Configuration configuration = service.OpenWebConfiguration(true);
                if (configuration == null)
                {
                    return(editor);
                }
                CompilationSection          section            = (CompilationSection)configuration.GetSection("system.web/compilation");
                ExpressionBuilderCollection expressionBuilders = section.ExpressionBuilders;
                bool   flag     = false;
                string fullName = expressionBuilderType.FullName;
                foreach (System.Web.Configuration.ExpressionBuilder builder in expressionBuilders)
                {
                    if (string.Equals(builder.Type, fullName, StringComparison.OrdinalIgnoreCase))
                    {
                        editor = GetExpressionEditorInternal(expressionBuilderType, builder.ExpressionPrefix, service, serviceProvider);
                        flag   = true;
                    }
                }
                if (flag)
                {
                    return(editor);
                }
                object[] customAttributes           = expressionBuilderType.GetCustomAttributes(typeof(ExpressionPrefixAttribute), true);
                ExpressionPrefixAttribute attribute = null;
                if (customAttributes.Length > 0)
                {
                    attribute = (ExpressionPrefixAttribute)customAttributes[0];
                }
                if (attribute != null)
                {
                    System.Web.Configuration.ExpressionBuilder buildProvider = new System.Web.Configuration.ExpressionBuilder(attribute.ExpressionPrefix, expressionBuilderType.FullName);
                    configuration = service.OpenWebConfiguration(false);
                    section       = (CompilationSection)configuration.GetSection("system.web/compilation");
                    section.ExpressionBuilders.Add(buildProvider);
                    configuration.Save();
                    editor = GetExpressionEditorInternal(expressionBuilderType, buildProvider.ExpressionPrefix, service, serviceProvider);
                }
            }
            return(editor);
        }
 private void OnExpressionBuilderComboBoxSelectedIndexChanged(object sender, EventArgs e)
 {
     if (!this._internalChange)
     {
         this._currentSheet = null;
         if (this._expressionBuilderComboBox.SelectedItem != this.NoneItem)
         {
             this._currentEditor = (ExpressionEditor) this._expressionEditors[this._expressionBuilderComboBox.SelectedItem.ToString()];
             if (this._currentNode != null)
             {
                 if (this._currentNode.IsBound)
                 {
                     ExpressionBinding binding = this._currentNode.Binding;
                     if (this._expressionEditors[binding.ExpressionPrefix] == this._currentEditor)
                     {
                         this._currentSheet = this._currentEditor.GetExpressionEditorSheet(binding.Expression, base.ServiceProvider);
                     }
                 }
                 if (this._currentSheet == null)
                 {
                     this._currentSheet = this._currentEditor.GetExpressionEditorSheet(string.Empty, base.ServiceProvider);
                 }
                 this._currentNode.IsValid = this._currentSheet.IsValid;
             }
         }
         this.SaveCurrentExpressionBinding();
         this._expressionBuilderPropertyGrid.SelectedObject = this._currentSheet;
         this.UpdateUIState();
     }
 }
 private void OnBindablePropsTreeAfterSelect(object sender, TreeViewEventArgs e)
 {
     BindablePropertyNode selectedNode = (BindablePropertyNode) this._bindablePropsTree.SelectedNode;
     if (this._currentNode != selectedNode)
     {
         this._currentNode = selectedNode;
         if ((this._currentNode != null) && this._currentNode.IsBound)
         {
             ExpressionBinding binding = this._currentNode.Binding;
             if (!this._currentNode.IsGenerated)
             {
                 ExpressionEditor editor = (ExpressionEditor) this._expressionEditors[binding.ExpressionPrefix];
                 if (editor == null)
                 {
                     UIServiceHelper.ShowMessage(base.ServiceProvider, System.Design.SR.GetString("ExpressionBindingsDialog_UndefinedExpressionPrefix", new object[] { binding.ExpressionPrefix }), System.Design.SR.GetString("ExpressionBindingsDialog_Text", new object[] { this.Control.Site.Name }), MessageBoxButtons.OK);
                     editor = new GenericExpressionEditor();
                 }
                 this._currentEditor = editor;
                 this._currentSheet = this._currentEditor.GetExpressionEditorSheet(binding.Expression, base.ServiceProvider);
                 this._internalChange = true;
                 try
                 {
                     foreach (ExpressionItem item in this._expressionBuilderComboBox.Items)
                     {
                         if (string.Equals(item.ToString(), binding.ExpressionPrefix, StringComparison.OrdinalIgnoreCase))
                         {
                             this._expressionBuilderComboBox.SelectedItem = item;
                         }
                     }
                     this._currentNode.IsValid = this._currentSheet.IsValid;
                 }
                 finally
                 {
                     this._internalChange = false;
                 }
             }
         }
         else
         {
             this._expressionBuilderComboBox.SelectedItem = this.NoneItem;
             this._currentEditor = null;
             this._currentSheet = null;
         }
         this._expressionBuilderPropertyGrid.SelectedObject = this._currentSheet;
         this.UpdateUIState();
     }
 }
コード例 #11
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            System.Web.UI.Control instance = context.Instance as System.Web.UI.Control;
            if (provider != null)
            {
                IDataEnvironment environment = (IDataEnvironment)provider.GetService(typeof(IDataEnvironment));
                if (environment != null)
                {
                    IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                    if ((edSvc != null) && (context.Instance != null))
                    {
                        if (this._connectionStringPicker == null)
                        {
                            this._connectionStringPicker = new ConnectionStringPicker();
                        }
                        string           connectionString = (string)value;
                        ExpressionEditor expressionEditor = ExpressionEditor.GetExpressionEditor(typeof(ConnectionStringsExpressionBuilder), provider);
                        if (expressionEditor == null)
                        {
                            return(value);
                        }
                        string expressionPrefix = expressionEditor.ExpressionPrefix;
                        DesignerDataConnection currentConnection = GetCurrentConnection(instance, context.PropertyDescriptor.Name, connectionString, expressionPrefix);
                        this._connectionStringPicker.Start(edSvc, environment.Connections, currentConnection);
                        edSvc.DropDownControl(this._connectionStringPicker);
                        if (this._connectionStringPicker.SelectedItem != null)
                        {
                            DesignerDataConnection selectedConnection = this._connectionStringPicker.SelectedConnection;
                            if (selectedConnection == null)
                            {
                                selectedConnection = environment.BuildConnection(UIServiceHelper.GetDialogOwnerWindow(provider), null);
                            }
                            if (selectedConnection != null)
                            {
                                if (selectedConnection.IsConfigured)
                                {
                                    ((IExpressionsAccessor)instance).Expressions.Add(new ExpressionBinding(context.PropertyDescriptor.Name, context.PropertyDescriptor.PropertyType, expressionPrefix, selectedConnection.Name));
                                    this.SetProviderName(context.Instance, selectedConnection);
                                    IComponentChangeService service = (IComponentChangeService)provider.GetService(typeof(IComponentChangeService));
                                    if (service != null)
                                    {
                                        service.OnComponentChanged(instance, null, null, null);
                                    }
                                }
                                else
                                {
                                    value = selectedConnection.ConnectionString;
                                    this.SetProviderName(context.Instance, selectedConnection);
                                }
                            }
                        }
                        this._connectionStringPicker.End();
                    }
                    return(value);
                }
            }
            string providerName = this.GetProviderName(context.Instance);
            ConnectionStringEditorDialog form = new ConnectionStringEditorDialog(provider, providerName)
            {
                ConnectionString = (string)value
            };

            if (UIServiceHelper.ShowDialog(provider, form) == DialogResult.OK)
            {
                value = form.ConnectionString;
            }
            return(value);
        }