/// <summary>
        /// Retrive the Sql Servers List on the local network.
        /// </summary>
        private void GetListOfSQLServers()
        {
            DataTable objServerList;

            try
            {
                ServersList = new BindingList <Server>();

                SqlDataSourceEnumerator objDataSourceEnumInstance = SqlDataSourceEnumerator.Instance;

                objServerList = objDataSourceEnumInstance.GetDataSources();

                foreach (DataRow objServerData in objServerList.Rows)
                {
                    LoadServerToList(objServerData);
                }
            }
            catch (Exception Ex)
            {
                throw new Exception("Failed In Get the list of Data Source Servers", Ex);
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            cboServer.Items.Add(".");
            cboServer.Items.Add("(Local)");
            cboServer.Items.Add("LocalHost");
            cboServer.Items.Add(@".\SQLEXPRESS");
            //cboServer.Items.Add(string.Format(@"{0}\SQLEXPRESS", Environment.MachineName));
            cboServer.SelectedIndex            = 2;
            chkUseIntergaratedSecurity.Checked = true;
            if (chkUseIntergaratedSecurity.Checked)
            {
                txtPassword.Enabled = false;
                txtUsername.Enabled = false;
            }
            else
            {
                txtPassword.Enabled = true;
                txtUsername.Enabled = true;
            }

            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;

            System.Data.DataTable table = instance.GetDataSources();

            foreach (System.Data.DataRow row in table.Rows)
            {
                cboServer.Items.Add(string.Format(@"{0}\SQLEXPRESS", row["ServerName"].ToString()));
                cboServer.Items.Add(string.Format(@"{0}", row["ServerName"].ToString()));
                //ServerName
                //txtRichTextBox.Text += row["ServerName"] + "\n";

                //foreach (System.Data.DataColumn col in table.Columns)
                //{
                //    //Console.WriteLine("{0} = {1}", col.ColumnName, row[col]);
                //    txtRichTextBox.Text += col.ColumnName + " " + row[col] + "\n";
                //}
            }
        }
Пример #3
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (comboBox3.Text == "")
     {
         SqlDataSourceEnumerator MyServers = SqlDataSourceEnumerator.Instance;
         DataTable ServerTable             = MyServers.GetDataSources();
         foreach (DataRow row in ServerTable.Rows)
         {
             if (row[1].ToString() == "")
             {
                 comboBox3.Items.Add(row[0].ToString());
             }
             else
             {
                 comboBox3.Items.Add(row[0].ToString() + "\\" + row[1].ToString());
             }
         }
     }
     else
     {
         if ((MessageBox.Show("Дальнейшие действия приведут к потери данных о текущем сервере, хотите продолжить?", "Предупреждение", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) == DialogResult.Yes)
         {
             SqlDataSourceEnumerator MyServers = SqlDataSourceEnumerator.Instance;
             DataTable ServerTable             = MyServers.GetDataSources();
             foreach (DataRow row in ServerTable.Rows)
             {
                 if (row[1].ToString() == "")
                 {
                     comboBox3.Items.Add(row[0].ToString());
                 }
                 else
                 {
                     comboBox3.Items.Add(row[0].ToString() + "\\" + row[1].ToString());
                 }
             }
         }
     }
 }
Пример #4
0
        private void frmConnect_Load(object sender, EventArgs e)
        {
            cmbAuthenticationMode.SelectedIndex = 0;

            SqlDataSourceEnumerator objDse = SqlDataSourceEnumerator.Instance;
            DataTable objTable             = objDse.GetDataSources();

            if (objTable == null)
            {
                MessageBox.Show("Servers no found!",
                                "Session",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            else
            {
                foreach (DataRow objRow in objTable.Rows)
                {
                    cmbServer.Items.Add(objRow["ServerName"].ToString() + "\\" + objRow["InstanceName"].ToString());
                    cmbServer.SelectedIndex = 0;
                }
            }
        }
Пример #5
0
        public FormAuth()
        {
            InitializeComponent();
            //Создаем енумератор, который будет искать активные соединения
            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
            //Создаем таблицу, в которой будут записаны активные соединения с MSSQL
            DataTable table = instance.GetDataSources();

            //Заполняем комбобокс соединениями
            foreach (DataRow row in table.Rows)
            {
                if (row["InstanceName"].ToString() == "")
                {
                    serverComboBox.Items.Add(row["ServerName"]);
                }
                else
                {
                    serverComboBox.Items.Add(row["ServerName"] + "\\" + row["InstanceName"]);
                }
            }
            //Текущий статус соединения
            statusStrip1.Items[1].Text = "Не установлено.";
        }
Пример #6
0
        /// <summary>
        /// Получение списка серверов
        /// </summary>
        /// <returns>Список серверов</returns>
        public string[] VisibleServers()
        {
            List <string>           result = new List <string>();
            SqlDataSourceEnumerator dse    = SqlDataSourceEnumerator.Instance;
            DataTable dt = dse.GetDataSources();
            string    ServerName, server, instance;

            foreach (DataRow row in dt.Rows)
            {
                server   = row["ServerName"].ToString();
                instance = row["InstanceName"].ToString();
                if (instance.Length == 0)
                {
                    ServerName = server;
                }
                else
                {
                    ServerName = server + "\\" + instance;
                }
                result.Add(ServerName);
            }
            return(result.ToArray());
        }
        public UserSelectSourceDatabase()
        {
            InitializeComponent();
            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
            DataTable dtDatabaseSources      = instance.GetDataSources();

            int i = 0;

            foreach (DataRow dr in dtDatabaseSources.Rows)
            {
                var obj = new SourceServer();
                i                 = i + 1;
                obj.Id            = i;
                obj.ServerName    = dr["ServerName"].ToString();
                obj.InstanceName  = dr["InstanceName"].ToString();
                obj.ConnectString = obj.ServerName + @"\" + obj.InstanceName;
                lstSource.Add(obj);
            }
            cbSelectServer.DataSource = lstSource;

            cbSelectServer.DisplayMember = "ConnectString";
            cbSelectServer.ValueMember   = "Id";
        }
Пример #8
0
    //==================================== Constructor ===========================
    public frmServerSelect(frmMain me)
    {
        InitializeComponent();
        this.mdiParent = me;
        string serverName;

        try
        {
            clsSqlServerList        SqlSL    = new clsSqlServerList();
            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
            DataTable mySources = instance.GetDataSources();
            foreach (DataRow row in mySources.Rows)
            {
                SqlSL      = new clsSqlServerList();
                serverName = row[0].ToString();
                cmbServer.Items.Add(serverName);
            }
            cmbServer.SelectedIndex = 0;
        } catch (Exception ex)
        {
            MessageBox.Show("Error: " + ex.Message);
        }
    }
Пример #9
0
        /// <summary>
        /// Handles the Load event of the FrmCreateNewDatabase control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        private void FrmConvertDatabase_Load(object sender, EventArgs e)
        {
            try
            {
                txtDatabaseName.EditValue = @"KETOAN_" + DateTime.Now.Year;
                var dataPath = RegistryHelperTransform.GetValueByRegistryKey("DatabasePath");
                btnDatabasePath.EditValue = dataPath.Substring(0, dataPath.LastIndexOf("\\", StringComparison.Ordinal));
                memoDescription.EditValue = @"Cơ sở dữ liệu kế toán cho các cơ quan đại diện";
                dtStartDate.EditValue     = DateTime.Parse("01/01/" + DateTime.Now.Year);
                LoadServerConnection();


                SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
                DataTable dtDatabaseSources      = instance.GetDataSources();

                int i = 0;
                foreach (DataRow dr in dtDatabaseSources.Rows)
                {
                    var obj = new SourceServer();
                    i                 = i + 1;
                    obj.Id            = i;
                    obj.ServerName    = dr["ServerName"].ToString();
                    obj.InstanceName  = dr["InstanceName"].ToString();
                    obj.ConnectString = obj.ServerName + @"\" + obj.InstanceName;
                    lstSource.Add(obj);
                }
                cbSelectServer.DataSource = lstSource;

                cbSelectServer.DisplayMember = "ConnectString";
                cbSelectServer.ValueMember   = "Id";
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.ToString(), "",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #10
0
        /// <summary>
        /// Determine if SQL-Server is available
        /// </summary>
        /// <returns></returns>
        public async Task <bool> SqlServerIsAvailable()
        {
            bool success = false;

            try
            {
                await Task.Run(() =>
                {
                    SqlDataSourceEnumerator sqlDataSourceEnumeratorInstance = SqlDataSourceEnumerator.Instance;
                    DataTable dt = sqlDataSourceEnumeratorInstance.GetDataSources();
                    if (dt != null)
                    {
                        success = true;
                    }
                });
            }
            catch (Exception ex)
            {
                hasException     = true;
                exceptionMessage = ex.Message;
            }

            return(success);
        }
Пример #11
0
        public List <string> Connect()
        {
            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
            var tableDataSources             = new System.Data.DataTable();

            if (tableDataSources.Rows.Count == 0)
            {
                tableDataSources = instance.GetDataSources();
                var listServers = new List <string>();
                foreach (DataRow rowServer in tableDataSources.Rows)
                {
                    if (String.IsNullOrEmpty(rowServer["InstanceName"].ToString()))
                    {
                        listServers.Add(rowServer["ServerName"].ToString());
                    }
                    else
                    {
                        listServers.Add(rowServer["ServerName"] + "\\" + rowServer["InstanceName"]);
                    }
                }
                return(listServers);
            }
            return(null);
        }
Пример #12
0
        private List <string> LoadServers()
        {
            try
            {
                // Retrieve enumerator instance and then the data
                SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
                DataTable     table      = instance.GetDataSources();
                List <string> serverList = new List <string>();

                // Display contents of table
                foreach (DataRow row in table.Rows)
                {
                    serverList.Add(row["ServerName"].ToString() + @"\" + row["InstanceName"].ToString());
                }

                return(serverList);
            }
            catch (Exception ex)
            {
                MessageBox.Show("SQL Server responded with an error: " + ex.Message,
                                "SQL Server Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(new List <string>());
            }
        }
Пример #13
0
        private void frmServerConnect_Load(object sender, EventArgs e)
        {
            //cargar cbo Instacias
            DataTable dtinstancias = instance.GetDataSources();

            cboInstancias2.DataSource    = dtinstancias;
            cboInstancias2.DisplayMember = "ServerName";
            cboInstancias2.ValueMember   = "ServerName";

            //Cargar cbo Forma de conexion
            DataTable oDT = new DataTable();

            oDT = enlace.cargarCboConexion();
            cboAutentificacion.DataSource    = oDT;
            cboAutentificacion.DisplayMember = "Descripcion";
            cboAutentificacion.ValueMember   = "Id";

            //Lanza el splashscreen
            Thread c = new Thread(new ThreadStart(iniciarSplashScreen));

            c.Start();
            Thread.Sleep(5000);
            c.Abort();
        }
Пример #14
0
        private void RefreshButton_Click(object sender, RoutedEventArgs e)
        {
            RefreshButton.IsEnabled = false;
            DataSourceList.Items.Clear();
            DataSourceList.Items.Add("localhost");
            SqlDataSourceEnumerator ServerList = SqlDataSourceEnumerator.Instance;

            Task.Run(() =>
            {
                DataTable ServerTable = ServerList.GetDataSources();
                foreach (DataRow row in ServerTable.Rows)
                {
                    DataSourceList.Dispatcher.BeginInvoke(new Action(delegate()
                    {
                        DataSourceList.Items.Add(row[0]);
                    }));
                }

                RefreshButton.Dispatcher.BeginInvoke(new Action(delegate()
                {
                    RefreshButton.IsEnabled = true;
                }));
            });
        }
Пример #15
0
    /// <summary>
    ///     Método estático que retorar instâncias SQL's de um determinado host (server).
    /// </summary>
    /// <param name="ServerName">Nome do servidor à ser validado as instâncias</param>
    /// <returns>Retorna uma List de String contendo o nome das instâncias SQL do host.</returns>
    public static List <string> LstInstanciasServerSql(string ServerName)
    {
        List <string> lstRet = new List <string>();

        try
        {
            SqlDataSourceEnumerator servers = SqlDataSourceEnumerator.Instance;
            DataTable dt = servers.GetDataSources();

            foreach (DataRow r in dt.Rows)
            {
                if (ServerName.ToUpper() == r[0].ToString().ToUpper())
                {
                    lstRet.Add(r[1].ToString().ToUpper());
                }
                else
                {
                    continue;
                }
            }
        }
        catch { }
        return(lstRet.OrderBy(l => l).ToList());
    }
        private void SelectServerForm_Load(object sender, EventArgs e)
        {
            // Local Servers
            string       ServerName   = Environment.MachineName;
            RegistryView registryView = Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32;

            using (RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView))
            {
                using (RegistryKey instancesKey = hklm.OpenSubKey(ServerInstanceRegistryKey))
                {
                    if (instancesKey != null)
                    {
                        using (instancesKey)
                        {
                            foreach (string instanceName in instancesKey.GetValueNames())
                            {
                                string instanceSetupKeyName = string.Format($"{SqlServerRegistryKey}\\{(string)instancesKey.GetValue(instanceName)}\\Setup");
                                try
                                {
                                    RegistryKey instanceSetupKey = hklm.OpenSubKey(instanceSetupKeyName);
                                    if (instanceSetupKey != null)
                                    {
                                        using (instanceSetupKey)
                                        {
                                            string version = (string)instanceSetupKey.GetValue("Version");
                                            string edition = (string)instanceSetupKey.GetValue("Edition");

                                            MokaDatabases.ServersRow srv = mokaDatabases.Servers.AddServersRow($@".\{instanceName}");
                                            GetDatabases(srv);
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    throw;
                                }
                            }
                        }
                    }
                }
            };
            // Network servers
            SqlDataSourceEnumerator ServerLister = SqlDataSourceEnumerator.Instance;
            DataTable SqlServers = ServerLister.GetDataSources();

            foreach (DataRow server in SqlServers.Rows)
            {
                string thisServer = "";
                if (string.IsNullOrEmpty(server["InstanceName"].ToString()))
                {
                    thisServer = server["ServerName"].ToString();
                }
                else
                {
                    thisServer = server["ServerName"].ToString() + "\\" + server["InstanceName"].ToString();
                }

                MokaDatabases.ServersRow srv = mokaDatabases.Servers.AddServersRow(thisServer);
                GetDatabases(srv);
            }
        }
Пример #17
0
        public async Task <DataTable> GetNameInstanceAsync()
        {
            SqlDataSourceEnumerator instance = System.Data.Sql.SqlDataSourceEnumerator.Instance;

            return(await Task.Run(() => instance.GetDataSources()));
        }
Пример #18
0
        private static DataTable dataTable;//буферная табличка
        static NetWorks()
        {
            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;//получает все экземпляры SQL серверов В сети

            dataTable = instance.GetDataSources();
        }
Пример #19
0
        static void Main(string[] args)
        {
            var prog = new Program();

            Options options      = null;
            var     parserResult = Parser.Default.ParseArguments <Options>(args)
                                   .WithParsed(f => { options = f; })
                                   .WithNotParsed(f =>
            {
                foreach (var error in f)
                {
                    Console.WriteLine($"ERROR: {error}");
                }
            });

            if (options == null)
            {
                Thread.Sleep(5000);
                return;
            }
            string connectionString = "";
            string outputDirectory  = null;

            if (!string.IsNullOrWhiteSpace(options.InputFile))
            {
                Console.WriteLine($"Specified command file: '{options.InputFile}'");
                if (File.Exists(options.InputFile))
                {
                    AutoConsole = new AutoConsole(options.InputFile, options.Variables);

                    var version = Assembly.GetExecutingAssembly().GetName().Version;
                    if (AutoConsole.Options.Version == null || new Version(AutoConsole.Options.Version) != version)
                    {
                        Console.WriteLine("WARNING");
                        Console.WriteLine(string.Format("The current Entity Creator version ({0}) is not equals the version ({1}) you have provided.", version, AutoConsole.Options.Version));
                        Console.WriteLine("There might be errors or unexpected Behavor");
                    }
                }
                else
                {
                    Console.WriteLine("The commandfile does not exist");
                    AutoConsole = new AutoConsole(null, new string[0]);
                }
            }
            else
            {
                AutoConsole = new AutoConsole(null, new string[0]);
            }

            WinConsole.WriteLine(@"Enter Connection string or type \explore to search for a server [Only MSSQL supported]");
            if (Clipboard.ContainsText() && AutoConsole.Options == null)
            {
                var maybeConnection = Clipboard.GetText(TextDataFormat.Text);
                var strings         = maybeConnection.Split(';');
                var any             = strings.Any(s => s.ToLower().Contains("data source=") || s.ToLower().Contains("initial catalog="));
                if (any)
                {
                    WinConsole.WriteLine("Use clipboard content? [(y|Enter*) | no]");
                    var WinConsoleKeyInfo = System.Console.ReadKey();
                    if (char.ToLower(WinConsoleKeyInfo.KeyChar) == 'y' || WinConsoleKeyInfo.Key == ConsoleKey.Enter)
                    {
                        connectionString = maybeConnection;
                        AutoConsole.SetNextOption(connectionString);
                    }
                    else
                    {
                        connectionString = string.Empty;
                    }
                }
                else
                {
                    connectionString = string.Empty;
                }
            }
            else
            {
                connectionString = string.Empty;
            }
            if (string.IsNullOrEmpty(connectionString))
            {
                do
                {
                    connectionString = AutoConsole.GetNextOption();
                    if (connectionString == @"\explore")
                    {
                        SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
                        WinConsole.WriteLine("Search for data Sources in current network");

                        var table = instance.GetDataSources();
                        WinConsole.WriteLine("Row count {0}", table.Rows.Count);

                        foreach (var column in table.Columns.Cast <DataColumn>())
                        {
                            WinConsole.Write(column.ColumnName + "|");
                        }

                        for (int i = 0; i < table.Rows.Count; i++)
                        {
                            var row = table.Rows[i];

                            WinConsole.Write("o {0} |", i);

                            foreach (DataColumn col in table.Columns)
                            {
                                WinConsole.Write(" {0} = {1} |", col.ColumnName, row[col]);
                            }
                            WinConsole.WriteLine("============================");
                        }
                        WinConsole.WriteLine();
                    }
                } while (string.IsNullOrEmpty(connectionString) || connectionString.ToLower().Contains(@"\explore"));
            }

            try
            {
                new MsSqlCreator(options.IncludeInVsProject).CreateEntrys(connectionString, outputDirectory, string.Empty);
            }
            catch (Exception e)
            {
                WinConsole.WriteLine("Error while executing the MsSQLEntity Creator:");
                WinConsole.WriteLine(e.ToString());
                WinConsole.WriteLine("Press any key to stop the application");
                Thread.Sleep(5000);

                return;
            }

            if (AutoConsole.Options == null && options.InputFile != null)
            {
                AutoConsole.SaveStorage(options.InputFile);
            }
        }
Пример #20
0
        /// <summary>
        /// Install chef to the specified drive
        /// </summary>
        /// <param name="installDir"></param>
        /// <param name="environmentId"></param>
        public void SelfInstall(string installDir, string environmentId)
        {
            if (string.IsNullOrWhiteSpace(environmentId))
            {
                environmentId = Environment.MachineName;
            }

            string settingsFile = null;

            // If chef is already installed, don't let us install!!
            var environmentSettingsFile = this.GetGlobalStorageVariable("environment-file-path");

            if (settingsFile != null)
            {
                environmentSettingsFile = settingsFile;
            }

            if (File.Exists(environmentSettingsFile))
            {
                this.Logger.LogWarning(false, "Chef already installed. Current config file in: " + environmentSettingsFile);
                return;
            }

            var autosettings = new EnvironmentSettings();

            autosettings.id = environmentId;

            autosettings.contentStorages = new List <StorageLocation>();
            autosettings.contentStorages.Add(new StorageLocation()
            {
                id   = "default",
                path = Path.Combine(installDir, "_contents")
            });
            autosettings.primaryContentStorage = "default";

            autosettings.tempStorages = new List <StorageLocation>();
            autosettings.tempStorages.Add(new StorageLocation()
            {
                id   = "default",
                path = Path.Combine(installDir, "_temp")
            });
            autosettings.primaryTempStorage = "default";

            autosettings.applicationStorages = new List <StorageLocation>();
            autosettings.applicationStorages.Add(new StorageLocation()
            {
                id   = "default",
                path = Path.Combine(installDir, "_apps")
            });
            autosettings.primaryApplicationStorage = "default";

            autosettings.logStorages = new List <StorageLocation>();
            autosettings.logStorages.Add(new StorageLocation()
            {
                id   = "default",
                path = Path.Combine(installDir, "_log")
            });
            autosettings.primaryLogStorage = "default";

            autosettings.defaultApplicationLimits = new ApplicationLimits();
            ApplicationLimits.PopulateDefaultsIfMissing(autosettings.defaultApplicationLimits);

            foreach (var p in autosettings.logStorages)
            {
                UtilsSystem.EnsureDir(p.path);
            }

            foreach (var p in autosettings.applicationStorages)
            {
                UtilsSystem.EnsureDir(p.path);
            }

            foreach (var p in autosettings.tempStorages)
            {
                UtilsSystem.EnsureDir(p.path);
            }

            foreach (var p in autosettings.contentStorages)
            {
                UtilsSystem.EnsureDir(p.path);
            }

            var settingsDir  = Path.Combine(installDir, "_configuration");
            var settingsPath = Path.Combine(settingsDir, "config.json");

            autosettings.endpoints = new List <NetworkInterface>();
            autosettings.endpoints.Add(new NetworkInterface()
            {
                forcehosts = true,
                id         = "local",
                ip         = UtilsIis.LOCALHOST_ADDRESS
            });

            // Retrieve the enumerator instance and then the data.
            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;

            this.Logger.LogInfo(false, "Searching for local SQL Server instances...");
            System.Data.DataTable table = instance.GetDataSources();

            string sqlserverSuffix = string.Empty;

            foreach (System.Data.DataRow t in table.Rows)
            {
                string id = "default" + sqlserverSuffix;

                string serverName   = t["ServerName"] as string;
                string instanceName = t["InstanceName"] as string;

                string serverString = serverName;
                if (!string.IsNullOrWhiteSpace(instanceName))
                {
                    serverString += "\\" + instanceName;
                }

                var connectionString = $"Server={serverString};Integrated Security = true;";

                autosettings.sqlServers = new List <SQLServer>();
                autosettings.sqlServers.Add(new SQLServer()
                {
                    id = id,
                    connectionString = connectionString
                });

                this.Logger.LogInfo(false, "Added server: {0}", connectionString);

                autosettings.primarySqlServer = id;
                sqlserverSuffix = autosettings.sqlServers.Count.ToString();
            }

            UtilsSystem.EnsureDir(settingsDir);
            string serialized = JsonConvert.SerializeObject(autosettings, Formatting.Indented);

            File.WriteAllText(settingsPath, serialized);

            this.SetGlobalEnvironmentFilePath(settingsPath);

            autosettings.installationSalt = Guid.NewGuid().ToString();

            this.Logger.LogInfo(true, "Find chef configuration file at: {0}", settingsPath);
        }
Пример #21
0
        static void Main(string[] args)
        {
            var prog = new Program();

            var    pathToCommandSet = "";
            string outputDir        = "";
            string connectionString = "";

            if (args.Count() == 1)
            {
                pathToCommandSet = args[0];
                if (File.Exists(pathToCommandSet))
                {
                    AutoConsole = new AutoConsole(pathToCommandSet);

                    var version = Assembly.GetExecutingAssembly().GetName().Version;
                    if (new Version(AutoConsole.Options.Version) != version)
                    {
                        Console.WriteLine("WARNING");
                        Console.WriteLine(string.Format("The current Entity Creator version ({0}) is not equals the version ({1}) you have provided.", version, AutoConsole.Options.Version));
                        Console.WriteLine("There might be errors or unexpected Behavor");
                    }
                }
                else
                {
                    AutoConsole = new AutoConsole(null);
                }
            }
            else
            {
                AutoConsole = new AutoConsole(null);
            }

            Console.WriteLine("Enter output dir");

            outputDir = AutoConsole.GetNextOption();
            if (outputDir == "temp")
            {
                outputDir = Path.GetTempPath();
            }

            if (string.IsNullOrEmpty(outputDir) || !Directory.Exists(outputDir))
            {
                Console.WriteLine("Invalid Directory ...");
                Console.ReadKey();
                return;
            }
            Console.WriteLine(@"Enter Connection string or type \explore to search for a server [ToBeSupported]");
            if (Clipboard.ContainsText() && AutoConsole.Options == null)
            {
                var maybeConnection = Clipboard.GetText(TextDataFormat.Text);
                var strings         = maybeConnection.Split(';');
                var any             = strings.Any(s => s.ToLower().Contains("data source=") || s.ToLower().Contains("initial catalog="));
                if (any)
                {
                    Console.WriteLine("Use clipboard content?");
                    var consoleKeyInfo = Console.ReadKey();
                    if (char.ToLower(consoleKeyInfo.KeyChar) == 'y')
                    {
                        connectionString = maybeConnection;
                        AutoConsole.SetNextOption(connectionString);
                    }
                    else
                    {
                        connectionString = string.Empty;
                    }
                }
                else
                {
                    connectionString = string.Empty;
                }
            }
            else
            {
                connectionString = string.Empty;
            }
            if (string.IsNullOrEmpty(connectionString))
            {
                do
                {
                    connectionString = AutoConsole.GetNextOption();
                    if (connectionString == @"\explore")
                    {
                        SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
                        Console.WriteLine("Search for data Sources in current network");

                        var table = instance.GetDataSources();
                        Console.WriteLine("Row count {0}", table.Rows.Count);

                        foreach (var column in table.Columns.Cast <DataColumn>())
                        {
                            Console.Write(column.ColumnName + "|");
                        }

                        for (int i = 0; i < table.Rows.Count; i++)
                        {
                            var row = table.Rows[i];

                            Console.Write("o {0} |", i);

                            foreach (System.Data.DataColumn col in table.Columns)
                            {
                                Console.Write(" {0} = {1} |", col.ColumnName, row[col]);
                            }
                            Console.WriteLine("============================");
                        }
                        Console.WriteLine();
                    }
                } while (string.IsNullOrEmpty(connectionString) || connectionString.ToLower().Contains(@"\explore"));
            }


            new MsSqlCreator().CreateEntrys(connectionString, outputDir, string.Empty);
            if (AutoConsole.Options == null && pathToCommandSet != null)
            {
                AutoConsole.SaveStorage(pathToCommandSet);
            }
        }
Пример #22
0
        public static DataTable getServers()
        {
            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;

            return(instance.GetDataSources());
        }
Пример #23
0
        private void ConfigurationForm_Load(object sender, EventArgs e)
        {
            SqlDataSourceEnumerator sqlDataSource = SqlDataSourceEnumerator.Instance;

            System.Data.DataTable table = sqlDataSource.GetDataSources();
        }
Пример #24
0
        public void SQL_Server_Enumurator()
        {
            SqlDataSourceEnumerator sourceEnumerator = SqlDataSourceEnumerator.Instance;

            server_Collection(sourceEnumerator.GetDataSources());
        }
        private void button2_Click(object sender, EventArgs e)//SQL
        {
            try
            {
                SaveFileDialog sfd = new SaveFileDialog(); // Create save the CSV
                sfd.Filter   = "Text File|*.txt";          // filters for text files only
                sfd.FileName = "SQL information.txt";
                sfd.Title    = "Save Text File";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    string path = sfd.FileName;
                    using (StreamWriter bw = new StreamWriter(File.Create(path)))
                    {
                        SqlDataSourceEnumerator sqldatasourceenumerator1 = SqlDataSourceEnumerator.Instance;
                        using (DataTable datatable1 = sqldatasourceenumerator1.GetDataSources())
                        {
                            foreach (DataRow row in datatable1.Rows)
                            {
                                bw.WriteLine("****************************************");
                                bw.WriteLine("Server Name:" + row["ServerName"]);
                                bw.WriteLine("Instance Name:" + row["InstanceName"]);
                                bw.WriteLine("Is Clustered:" + row["IsClustered"]);
                                bw.WriteLine("Version:" + row["Version"]);
                                bw.WriteLine("****************************************");
                            }
                        }
                        //using win32
                        var localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
                        var msSQLServer  = localMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server");
                        var instances    = (string[])msSQLServer.GetValue("InstalledInstances");
                        bw.WriteLine("This Machine Name; {0} ", Environment.MachineName);
                        if (instances != null)
                        {
                            foreach (var instance in instances)
                            {
                                var insNames           = localMachine.OpenSubKey(@"Software\Microsoft\Microsoft SQL Server\Instance Names\SQL");
                                var realNameInstanse   = (string)insNames.GetValue(instance);
                                var sqlEditionRegistry = localMachine.OpenSubKey(string.Format(@"Software\Microsoft\Microsoft SQL Server\{0}\Setup", realNameInstanse));
                                var edition            = (string)sqlEditionRegistry.GetValue("Edition");
                                bw.WriteLine("Instance {0}, RealName {2}, - Edition: {1}", instance, edition, realNameInstanse);
                            }
                        }
                        else
                        {
                            bw.WriteLine("No instances found on this PC");
                        }

                        bw.Flush();
                        bw.Close();
                    }
                    MessageBox.Show("Data Saved");
                }
                else
                {
                    MessageBox.Show("No option selected");
                }
            }//end try
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Пример #26
0
        public void getServers()
        {
            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;

            dtServers(instance.GetDataSources());
        }
Пример #27
0
        public void GetServers()
        {
            SqlDataSourceEnumerator sqlDataSourceEnumerator = SqlDataSourceEnumerator.Instance;

            DataTableServers(sqlDataSourceEnumerator.GetDataSources());
        }
Пример #28
0
        public DataTable GetNameInstance()
        {
            SqlDataSourceEnumerator instance = System.Data.Sql.SqlDataSourceEnumerator.Instance;

            return(instance.GetDataSources());
        }
Пример #29
0
        public void GetServers()
        {
            SqlDataSourceEnumerator sourceEnumerator = SqlDataSourceEnumerator.Instance;

            dtServers(sourceEnumerator.GetDataSources());
        }
Пример #30
0
        public void GetServers()    //получение серверов
        {
            SqlDataSourceEnumerator sqlDataSourceEnumerator = SqlDataSourceEnumerator.Instance;

            DataTableServers(sqlDataSourceEnumerator.GetDataSources());
        }