Ejemplo n.º 1
0
		/// <summary>
		/// Static Method used to show the dialog and return the selected result.
		/// </summary>		
		/// <param name="provider">The Provider to get the service from</param>	
		/// <param name="schemaList">The list of schema names to select from</param>
		public static string SelectSchema(IServiceProvider provider, IList<string> schemaList)
		{
			string retVal = null;
            string messageResourceId = null;
			IUIService uiService = ORMDatabaseImportWizard.GetService<IUIService>(provider);
			if (uiService != null)
			{
                if (null != schemaList && schemaList.Count != 0)
                {
                    SchemaSelector fss = new SchemaSelector(schemaList);
                    if (uiService.ShowDialog(fss) == DialogResult.OK)
                    {
                        retVal = fss.mySelectedSchema;
                    }
                    else
                    {
                        messageResourceId = "SchemaNotSelectedMessage";
                    }
                }
                else
                {
                    messageResourceId = "SchemaNotAvailableMessage";
                }
                if (messageResourceId != null)
                {
                    uiService.ShowMessage(new System.ComponentModel.ComponentResourceManager(typeof(SchemaSelector)).GetString(messageResourceId));
                }
            }
			return retVal;
		}
Ejemplo n.º 2
0
        /// <summary>
        /// Implements <see cref="IWizard.RunStarted"/>
        /// </summary>
        protected void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
        {
            IOleServiceProvider oleServiceProvider = automationObject as IOleServiceProvider;
            ServiceProvider     serviceProvider    = (oleServiceProvider != null) ? new ServiceProvider(oleServiceProvider) : null;

            DataConnectionDialogFactory dialogFactory = GetService <DataConnectionDialogFactory>(serviceProvider);

            Debug.Assert(dialogFactory != null, "Can't get DataConnectionDialogFactory!");

            System.Data.IDbConnection dbConn;
            DataConnectionDialog      dialog = dialogFactory.CreateConnectionDialog();

            dialog.AddAllSources();
            DataConnection dataConn = dialog.ShowDialog(false);

            if (dataConn != null)
            {
                if ((dbConn = dataConn.ConnectionSupport.ProviderObject as System.Data.IDbConnection) == null)
                {
                    // show error
                    return;
                }

                DataProviderManager manager = GetService <DataProviderManager>(serviceProvider);
                if (manager != null)
                {
                    DataProvider provider      = manager.GetDataProvider(dataConn.Provider);
                    string       invariantName = provider.GetProperty("InvariantName") as string;

                    IList <string> schemaList     = DcilSchema.GetAvailableSchemaNames(dbConn, invariantName);
                    string         selectedSchema = null;
                    switch (schemaList.Count)
                    {
                    case 1:
                        selectedSchema = schemaList[0];
                        break;

                    default:
                        // Allow this for an empty list
                        selectedSchema = SchemaSelector.SelectSchema(serviceProvider, schemaList);
                        break;
                    }

                    if (!string.IsNullOrEmpty(selectedSchema))
                    {
                        DcilSchema schema = DcilSchema.FromSchemaName(selectedSchema, dbConn, invariantName);

                        StringBuilder stringBuilder     = new StringBuilder();
                        string        replacementString = null;
                        using (MemoryStream ms = new MemoryStream())
                        {
                            DcilSchema.Serialize(schema, ms);
                            ms.Seek(0, SeekOrigin.Begin);
                            StreamReader sr = new StreamReader(ms);
                            replacementString = sr.ReadToEnd();
                        }


                        replacementsDictionary.Add("$DcilFile$", replacementString);
                        myAddToProject = true;
                    }
                }
            }
        }