private void BrowseAndSelectType(DataGridViewCell currentCell)
        {
            bool doneSelectingType = false;

            while (!doneSelectingType)
            {
                using (TypeBrowserDialog typeBrowserDialog = new TypeBrowserDialog(
                           this.ServiceProvider as IServiceProvider, new ParameterTypeFilterProvider(), "System.String"))
                {
                    doneSelectingType = TrySelectType(typeBrowserDialog, currentCell);
                }
            }
        }
        bool TrySelectType(TypeBrowserDialog typeBrowserDialog, DataGridViewCell cell)
        {
            typeBrowserDialog.ShowDialog();
            if (typeBrowserDialog.SelectedType != null)
            {
                if (!ParameterTypeFilterProvider.IsValidType(typeBrowserDialog.SelectedType))
                {
                    DesignerHelpers.ShowMessage(this.ServiceProvider, SR2.GetString(SR2.InvalidParameterType,
                                                                                    typeBrowserDialog.SelectedType), DR.GetString(DR.WorkflowDesignerTitle), MessageBoxButtons.OK,
                                                MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    return(false);
                }
                AddToTypeList(typeBrowserDialog.SelectedType);
            }
            typeChooserCellItem.ChosenType = typeBrowserDialog.SelectedType;
            cell.Value = typeBrowserDialog.SelectedType;

            return(true);
        }
            public bool? ShowDialog( IntPtr owner )
            {
                // create view model based on picker properties, then
                // create and show the view
                var model = new TypeBrowserViewModel()
                {
                    NameConvention = NameConvention,
                    FilterByConvention = !string.IsNullOrEmpty( NameConvention ),
                    LocalAssembly = localAssembly
                };

                model.RestrictedBaseTypeNames.AddRange( RestrictedBaseTypeNames ?? Enumerable.Empty<string>() );
                model.LocalAssemblyReferences.AddRange( localAssemblyReferences );

                using ( var view = new TypeBrowserDialog( model ) )
                {
                    var helper = new WindowInteropHelper( view )
                    {
                        Owner = owner
                    };

                    // change title from default value only if an alternate title is provided
                    if ( !string.IsNullOrEmpty( Title ) )
                        model.Title = Title;

                    var result = view.ShowDialog();

                    // if a type is selected, set it. wrap the type so that it is
                    // serialized across appdomain boundaries
                    if ( ( result ?? false ) )
                        SelectedType = new SimpleType( model.SelectedType );

                    helper.Owner = IntPtr.Zero;

                    return result;
                }
            }
        void ImportContractButtonClicked(object sender, EventArgs e)
        {
            using (TypeBrowserDialog typeBrowserDialog = new TypeBrowserDialog(serviceProvider as IServiceProvider, new ServiceContractsTypeFilterProvider(), "System.String"))
            {
                typeBrowserDialog.ShowDialog();
                if (typeBrowserDialog.SelectedType != null)
                {
                    ServiceContractListItem contractItem = new ServiceContractListItem(this.operationsListBox);
                    contractItem.Validating      += new CancelEventHandler(ServiceContractValidating);
                    contractItem.Name             = typeBrowserDialog.SelectedType.FullName;
                    contractItem.ContractType     = typeBrowserDialog.SelectedType;
                    contractItem.IsCustomContract = false;
                    CancelEventArgs cancelEventArgs = new CancelEventArgs();
                    contractItem.Validating.Invoke(contractItem, cancelEventArgs);
                    if (cancelEventArgs.Cancel)
                    {
                        return;
                    }
                    AddServiceContract(contractItem);

                    ImportContract(typeBrowserDialog.SelectedType);
                }
            }
        }
Exemple #5
0
        public override object EditValue(ITypeDescriptorContext typeDescriptorContext, IServiceProvider serviceProvider, object value)
        {
            if (typeDescriptorContext == null)
            {
                throw new ArgumentNullException("typeDescriptorContext");
            }
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            object returnVal = value;

            this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService));
            if (editorService != null)
            {
                ITypeFilterProvider         typeFilterProvider = null;
                TypeFilterProviderAttribute typeFilterProvAttr = null;

                if (typeDescriptorContext.PropertyDescriptor != null && typeDescriptorContext.PropertyDescriptor.Attributes != null)
                {
                    typeFilterProvAttr = typeDescriptorContext.PropertyDescriptor.Attributes[typeof(TypeFilterProviderAttribute)] as TypeFilterProviderAttribute;
                }

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

                    Type typeFilterProviderType = Type.GetType(typeFilterProvAttr.TypeFilterProviderTypeName);
                    //typeProvider.GetType(typeFilterProvAttr.TypeFilterProviderTypeName);
                    if (typeFilterProviderType != null)
                    {
                        typeFilterProvider = Activator.CreateInstance(typeFilterProviderType, new object[] { serviceProvider }) as ITypeFilterProvider;
                    }
                }

                if (typeFilterProvider == null)
                {
                    typeFilterProvider = ((typeDescriptorContext.Instance is object[]) ? ((object[])typeDescriptorContext.Instance)[0] : typeDescriptorContext.Instance) as ITypeFilterProvider;
                }

                if (typeFilterProvider == null)
                {
                    typeFilterProvider = value as ITypeFilterProvider;
                }

                if (typeFilterProvider == null)
                {
                    IReferenceService rs = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService;
                    if (rs != null)
                    {
                        IComponent baseComponent = rs.GetComponent(typeDescriptorContext.Instance);
                        if (baseComponent is ITypeFilterProvider)
                        {
                            typeFilterProvider = baseComponent as ITypeFilterProvider;
                        }
                    }
                }

                if (typeFilterProvider == null)
                {
                    typeFilterProvider = typeDescriptorContext.PropertyDescriptor as ITypeFilterProvider;
                }

                string oldTypeName = value as string;
                if (value != null && typeDescriptorContext.PropertyDescriptor.PropertyType != typeof(string) && typeDescriptorContext.PropertyDescriptor.Converter != null && typeDescriptorContext.PropertyDescriptor.Converter.CanConvertTo(typeof(string)))
                {
                    oldTypeName = typeDescriptorContext.PropertyDescriptor.Converter.ConvertTo(typeDescriptorContext, CultureInfo.CurrentCulture, value, typeof(string)) as string;
                }

                using (TypeBrowserDialog dlg = new TypeBrowserDialog(serviceProvider, typeFilterProvider as ITypeFilterProvider, oldTypeName))
                {
                    if (DialogResult.OK == editorService.ShowDialog(dlg))
                    {
                        if (typeDescriptorContext.PropertyDescriptor.PropertyType == typeof(Type))
                        {
                            returnVal = dlg.SelectedType;
                        }
                        else if (typeDescriptorContext.PropertyDescriptor.PropertyType == typeof(string))
                        {
                            returnVal = dlg.SelectedType.FullName;
                        }
                        else if (typeDescriptorContext.PropertyDescriptor.Converter != null && typeDescriptorContext.PropertyDescriptor.Converter.CanConvertFrom(typeDescriptorContext, typeof(string)))
                        {
                            returnVal = typeDescriptorContext.PropertyDescriptor.Converter.ConvertFrom(typeDescriptorContext, CultureInfo.CurrentCulture, dlg.SelectedType.FullName);
                        }
                    }
                }
            }
            return(returnVal);
        }
Exemple #6
0
        public override object EditValue(ITypeDescriptorContext typeDescriptorContext, IServiceProvider serviceProvider, object value)
        {
            if (typeDescriptorContext == null)
            {
                throw new ArgumentNullException("typeDescriptorContext");
            }
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }
            object obj2 = value;

            this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService));
            if (this.editorService != null)
            {
                ITypeFilterProvider         filterProvider = null;
                TypeFilterProviderAttribute attribute      = null;
                if ((typeDescriptorContext.PropertyDescriptor != null) && (typeDescriptorContext.PropertyDescriptor.Attributes != null))
                {
                    attribute = typeDescriptorContext.PropertyDescriptor.Attributes[typeof(TypeFilterProviderAttribute)] as TypeFilterProviderAttribute;
                }
                if (attribute != null)
                {
                    if (!(serviceProvider.GetService(typeof(ITypeProvider)) is ITypeProvider))
                    {
                        throw new Exception(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).FullName }));
                    }
                    System.Type type = System.Type.GetType(attribute.TypeFilterProviderTypeName);
                    if (type != null)
                    {
                        filterProvider = Activator.CreateInstance(type, new object[] { serviceProvider }) as ITypeFilterProvider;
                    }
                }
                if (filterProvider == null)
                {
                    filterProvider = ((typeDescriptorContext.Instance is object[]) ? ((ITypeFilterProvider)((object[])typeDescriptorContext.Instance)[0]) : ((ITypeFilterProvider)typeDescriptorContext.Instance)) as ITypeFilterProvider;
                }
                if (filterProvider == null)
                {
                    filterProvider = value as ITypeFilterProvider;
                }
                if (filterProvider == null)
                {
                    IReferenceService service = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService;
                    if (service != null)
                    {
                        IComponent component = service.GetComponent(typeDescriptorContext.Instance);
                        if (component is ITypeFilterProvider)
                        {
                            filterProvider = component as ITypeFilterProvider;
                        }
                    }
                }
                if (filterProvider == null)
                {
                    filterProvider = typeDescriptorContext.PropertyDescriptor as ITypeFilterProvider;
                }
                string selectedTypeName = value as string;
                if (((value != null) && (typeDescriptorContext.PropertyDescriptor.PropertyType != typeof(string))) && ((typeDescriptorContext.PropertyDescriptor.Converter != null) && typeDescriptorContext.PropertyDescriptor.Converter.CanConvertTo(typeof(string))))
                {
                    selectedTypeName = typeDescriptorContext.PropertyDescriptor.Converter.ConvertTo(typeDescriptorContext, CultureInfo.CurrentCulture, value, typeof(string)) as string;
                }
                using (TypeBrowserDialog dialog = new TypeBrowserDialog(serviceProvider, filterProvider, selectedTypeName))
                {
                    if (DialogResult.OK != this.editorService.ShowDialog(dialog))
                    {
                        return(obj2);
                    }
                    if (typeDescriptorContext.PropertyDescriptor.PropertyType == typeof(System.Type))
                    {
                        return(dialog.SelectedType);
                    }
                    if (typeDescriptorContext.PropertyDescriptor.PropertyType == typeof(string))
                    {
                        return(dialog.SelectedType.FullName);
                    }
                    if ((typeDescriptorContext.PropertyDescriptor.Converter != null) && typeDescriptorContext.PropertyDescriptor.Converter.CanConvertFrom(typeDescriptorContext, typeof(string)))
                    {
                        obj2 = typeDescriptorContext.PropertyDescriptor.Converter.ConvertFrom(typeDescriptorContext, CultureInfo.CurrentCulture, dialog.SelectedType.FullName);
                    }
                }
            }
            return(obj2);
        }