// Updates the parameters collection associated with the specified property name
        private static void SetParameters(string propertyName, EntityDataSourceDesigner designer, ParameterCollection parameters)
        {
            switch (propertyName)
            {
            case "CommandText":
                designer.SetCommandParameterContents(parameters);
                break;

            case "OrderBy":
                designer.SetOrderByParameterContents(parameters);
                break;

            case "Select":
                designer.SetSelectParameterContents(parameters);
                break;

            case "Where":
                designer.SetWhereParameterContents(parameters);
                break;

            default:
                Debug.Fail("Unknown property name in EntityDataSourceStatementEditor: " + propertyName);
                break;
            }
        }
        public EntityDataSourceWizardForm(IServiceProvider serviceProvider, EntityDataSourceState entityDataSourceState, EntityDataSourceDesigner entityDataSourceDesigner)
            : base(serviceProvider)
        {
            _entityDataSourceState = entityDataSourceState;
            this.SetGlyph(new Bitmap(BitmapSelector.GetResourceStream(typeof(EntityDataSourceWizardForm), "EntityDataSourceWizard.bmp")));
            this.Text = String.Format(CultureInfo.InvariantCulture, Strings.Wizard_Caption(((EntityDataSource)entityDataSourceDesigner.Component).ID));

            _helper = entityDataSourceDesigner.Helper;

            EntityDataSourceConfigureObjectContextPanel contextPanel = new EntityDataSourceConfigureObjectContextPanel();
            _configureContext = new EntityDataSourceConfigureObjectContext(contextPanel, this, entityDataSourceDesigner.Helper, _entityDataSourceState);

            EntityDataSourceDataSelectionPanel dataPanel = new EntityDataSourceDataSelectionPanel();
            _configureDataSelection = new EntityDataSourceDataSelection(dataPanel, this, entityDataSourceDesigner.Helper, _entityDataSourceState);

            _configureContext.ContainerNameChanged += _configureDataSelection.ContainerNameChangedHandler;

            _configureContext.LoadState();
            _configureDataSelection.LoadState();

            // Adds the panels to the wizard
            SetPanels(new WizardPanel[] {
                contextPanel,
                dataPanel});
        }
 // Determines if the specified property is one that has an associated "AutoGenerateXXXClause" property
 private static bool GetAutoGen(string operation, EntityDataSourceDesigner entityDataSourceDesigner)
 {
     if (String.Equals("Where", operation, StringComparison.Ordinal))
     {
         return entityDataSourceDesigner.AutoGenerateWhereClause;
     }
     else if (String.Equals("OrderBy", operation, StringComparison.Ordinal))
     {
         return entityDataSourceDesigner.AutoGenerateOrderByClause;
     }
     return false;
 }
 // Determines if the specified property is one that has an associated "AutoGenerateXXXClause" property
 private static bool GetAutoGen(string operation, EntityDataSourceDesigner entityDataSourceDesigner)
 {
     if (String.Equals("Where", operation, StringComparison.Ordinal))
     {
         return(entityDataSourceDesigner.AutoGenerateWhereClause);
     }
     else if (String.Equals("OrderBy", operation, StringComparison.Ordinal))
     {
         return(entityDataSourceDesigner.AutoGenerateOrderByClause);
     }
     return(false);
 }
        // Configures and displays the editor dialog based on the specified property name
        private bool Initialize(EntityDataSourceDesigner designer, EntityDataSource entityDataSource, string propertyName, IServiceProvider serviceProvider, string statement)
        {
            string propertyParameters      = GetOperationParameterProperty(propertyName);
            string autoGenProperty         = GetOperationAutoGenerateProperty(propertyName);
            bool   hasAutoGen              = (autoGenProperty != null);
            bool   autoGen                 = GetAutoGen(propertyName, designer);
            ParameterCollection parameters = GetParameters(propertyName, designer);
            string label          = GetStatementLabel(propertyName, false);
            string accessibleName = GetStatementLabel(propertyName, true);
            string helpTopic      = GetHelpTopic(propertyName);

            EntityDataSourceStatementEditorForm form = new EntityDataSourceStatementEditorForm(entityDataSource, serviceProvider,
                                                                                               hasAutoGen, autoGen, propertyName, label, accessibleName, helpTopic, statement, parameters);

            DialogResult result = UIHelper.ShowDialog(serviceProvider, form);

            if (result == DialogResult.OK)
            {
                // We use the property descriptors to reset the values to
                // make sure we clear out any databindings or expressions that
                // may be set.
                PropertyDescriptor propDesc = null;

                if (autoGenProperty != null)
                {
                    propDesc = TypeDescriptor.GetProperties(entityDataSource)[autoGenProperty];
                    propDesc.ResetValue(entityDataSource);
                    propDesc.SetValue(entityDataSource, form.AutoGen);
                }

                if (propertyName != null)
                {
                    propDesc = TypeDescriptor.GetProperties(entityDataSource)[propertyName];
                    propDesc.ResetValue(entityDataSource);
                    propDesc.SetValue(entityDataSource, form.Statement);
                }

                if (propertyParameters != null)
                {
                    SetParameters(propertyName, designer, form.Parameters);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
        private bool EditQueryChangeCallback(object pair)
        {
            // pair.First is a wrapper that contains the EntityDataSource instance and property name being edited
            // pair.Second contains the value of the property being edited
            ITypeDescriptorContext context = (ITypeDescriptorContext)((Pair)pair).First;
            string value = (string)((Pair)pair).Second;

            EntityDataSource entityDataSource = (EntityDataSource)context.Instance;
            IServiceProvider serviceProvider  = entityDataSource.Site;

            IDesignerHost designerHost = (IDesignerHost)serviceProvider.GetService(typeof(IDesignerHost));

            Debug.Assert(designerHost != null, "Did not get DesignerHost service.");

            EntityDataSourceDesigner designer = (EntityDataSourceDesigner)designerHost.GetDesigner(entityDataSource);

            // Configure the dialog for the specified property and display it
            return(Initialize(designer, entityDataSource, context.PropertyDescriptor.Name, serviceProvider, value));
        }
        // Gets a clone of the parameters collection associated with the specified property name
        private static ParameterCollection GetParameters(string propertyName, EntityDataSourceDesigner designer)
        {
            switch (propertyName)
            {
            case "CommandText":
                return(designer.CloneCommandParameters());

            case "OrderBy":
                return(designer.CloneOrderByParameters());

            case "Select":
                return(designer.CloneSelectParameters());

            case "Where":
                return(designer.CloneWhereParameters());

            default:
                Debug.Fail("Unknown property name in EntityDataSourceStatementEditor: " + propertyName);
                return(null);
            }
        }
        // Configures and displays the editor dialog based on the specified property name
        private bool Initialize(EntityDataSourceDesigner designer, EntityDataSource entityDataSource, string propertyName, IServiceProvider serviceProvider, string statement)
        {
            string propertyParameters = GetOperationParameterProperty(propertyName);
            string autoGenProperty = GetOperationAutoGenerateProperty(propertyName);
            bool hasAutoGen = (autoGenProperty != null);
            bool autoGen = GetAutoGen(propertyName, designer);
            ParameterCollection parameters = GetParameters(propertyName, designer);
            string label = GetStatementLabel(propertyName, false);
            string accessibleName = GetStatementLabel(propertyName, true);
            string helpTopic = GetHelpTopic(propertyName);

            EntityDataSourceStatementEditorForm form = new EntityDataSourceStatementEditorForm(entityDataSource, serviceProvider,
                hasAutoGen, autoGen, propertyName, label, accessibleName, helpTopic, statement, parameters);

            DialogResult result = UIHelper.ShowDialog(serviceProvider, form);

            if (result == DialogResult.OK)
            {
                // We use the property descriptors to reset the values to
                // make sure we clear out any databindings or expressions that
                // may be set.
                PropertyDescriptor propDesc = null;

                if (autoGenProperty != null)
                {
                    propDesc = TypeDescriptor.GetProperties(entityDataSource)[autoGenProperty];
                    propDesc.ResetValue(entityDataSource);
                    propDesc.SetValue(entityDataSource, form.AutoGen);
                }

                if (propertyName != null)
                {
                    propDesc = TypeDescriptor.GetProperties(entityDataSource)[propertyName];
                    propDesc.ResetValue(entityDataSource);
                    propDesc.SetValue(entityDataSource, form.Statement);
                }

                if (propertyParameters != null)
                {
                    SetParameters(propertyName, designer, form.Parameters);
                }

                return true;
            }
            else
            {
                return false;
            }
        }
        // Updates the parameters collection associated with the specified property name
        private static void SetParameters(string propertyName, EntityDataSourceDesigner designer, ParameterCollection parameters)
        {
            switch (propertyName)
            {
                case "CommandText":
                    designer.SetCommandParameterContents(parameters);
                    break;
                case "OrderBy":
                    designer.SetOrderByParameterContents(parameters);
                    break;
                case "Select":
                    designer.SetSelectParameterContents(parameters);
                    break;
                case "Where":
                    designer.SetWhereParameterContents(parameters);
                    break;
                default:
                    Debug.Fail("Unknown property name in EntityDataSourceStatementEditor: " + propertyName);
                    break;

            }
        }
 // Gets a clone of the parameters collection associated with the specified property name
 private static ParameterCollection GetParameters(string propertyName, EntityDataSourceDesigner designer)
 {
     switch (propertyName)
     {
         case "CommandText":
             return designer.CloneCommandParameters();
         case "OrderBy":
             return designer.CloneOrderByParameters();
         case "Select":
             return designer.CloneSelectParameters();
         case "Where":
             return designer.CloneWhereParameters();
         default:
             Debug.Fail("Unknown property name in EntityDataSourceStatementEditor: " + propertyName);
             return null;
     }
 }
 public EntityDesignerDataSourceView(EntityDataSourceDesigner owner)
     : base(owner, EntityDataSourceDesignerHelper.DefaultViewName)
 {
     _helper = owner.Helper;
 }
        public EntityDataSourceWizardForm(IServiceProvider serviceProvider, EntityDataSourceState entityDataSourceState, EntityDataSourceDesigner entityDataSourceDesigner)
            : base(serviceProvider)
        {
            _entityDataSourceState = entityDataSourceState;
            this.SetGlyph(new Bitmap(BitmapSelector.GetResourceStream(typeof(EntityDataSourceWizardForm), "EntityDataSourceWizard.bmp")));
            this.Text = String.Format(CultureInfo.InvariantCulture, Strings.Wizard_Caption(((EntityDataSource)entityDataSourceDesigner.Component).ID));

            _helper = entityDataSourceDesigner.Helper;

            EntityDataSourceConfigureObjectContextPanel contextPanel = new EntityDataSourceConfigureObjectContextPanel();

            _configureContext = new EntityDataSourceConfigureObjectContext(contextPanel, this, entityDataSourceDesigner.Helper, _entityDataSourceState);

            EntityDataSourceDataSelectionPanel dataPanel = new EntityDataSourceDataSelectionPanel();

            _configureDataSelection = new EntityDataSourceDataSelection(dataPanel, this, entityDataSourceDesigner.Helper, _entityDataSourceState);

            _configureContext.ContainerNameChanged += _configureDataSelection.ContainerNameChangedHandler;

            _configureContext.LoadState();
            _configureDataSelection.LoadState();

            // Adds the panels to the wizard
            SetPanels(new WizardPanel[] {
                contextPanel,
                dataPanel
            });
        }
 public EntityDesignerDataSourceView(EntityDataSourceDesigner owner)
     : base(owner, EntityDataSourceDesignerHelper.DefaultViewName)
 {
     _helper = owner.Helper;
 }
        internal EntityDataSourceDesignerHelper(EntityDataSource entityDataSource, bool interactiveMode)
        {
            Debug.Assert(entityDataSource != null, "null entityDataSource");

            _entityDataSource = entityDataSource;
            _interactiveMode = interactiveMode;

            _canLoadWebConfig = true;

            IServiceProvider serviceProvider = _entityDataSource.Site;
            if (serviceProvider != null)
            {
                // Get the designer instance associated with the specified data source control
                IDesignerHost designerHost = (IDesignerHost)serviceProvider.GetService(typeof(IDesignerHost));
                if (designerHost != null)
                {
                    _owner = designerHost.GetDesigner(this.EntityDataSource) as EntityDataSourceDesigner;
                }

                // Get other services used to determine design-time information                
                _webApplication = serviceProvider.GetService(typeof(IWebApplication)) as IWebApplication;

            }            
            Debug.Assert(_owner != null, "expected non-null owner");            
            Debug.Assert(_webApplication != null, "expected non-null web application service");            
        }