コード例 #1
0
ファイル: Program.cs プロジェクト: JPVenson/DataAccess
		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);

		}
コード例 #2
0
        private 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;
            }

            var    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(
                            "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 = 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")
                    {
                        var 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 (var 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);
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: JosefHaslinger/DataAccess
        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);
            }
        }