Exemplo n.º 1
0
		static int Main(string[] args)
		{
			var options = new Options();
			ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(System.Console.Error));
			if (!parser.ParseArguments(args, options))
			{
				System.Console.Error.WriteLine("Some of argumens are incorrect");
				return IncorrectOptionsReturnCode;
			}

			LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(options.Verbose ? LogLevel.Info: LogLevel.Warn, false, true, true, null);
			log = LogManager.GetCurrentClassLogger();

			var directoryPath = !string.IsNullOrWhiteSpace(options.BaseDirectory)? options.BaseDirectory: Environment.CurrentDirectory;

			var baseDirectory = new DirectoryInfo(directoryPath);
			if(!baseDirectory.Exists)
			{
				log.ErrorFormat("Provided directory {0} does not exist.", options.BaseDirectory);
				return IncorrectOptionsReturnCode;
			}

			var url = new Lazy<Uri>(() => ParseDatabaseUrl(options));

			if (options.Command == CommandType.Help)
				System.Console.WriteLine(options.GetUsage());
			else
				try 
				{
					ExecuteCommand(options.Command, baseDirectory, url, options.UserName, options.Password);
				}
				catch (Exception e)
				{
					log.ErrorFormat(e.ToString());
					return UnknownErrorReturnCode;
				}

			return OkReturnCode;
		}
Exemplo n.º 2
0
		static Uri ParseDatabaseUrl(Options options)
		{
			Uri uri;
			if (!options.DatabaseUrl.EndsWith("/"))
				options.DatabaseUrl = options.DatabaseUrl + "/";

			if(!Uri.TryCreate(options.DatabaseUrl, UriKind.RelativeOrAbsolute, out uri))
			{
				log.ErrorFormat("Provided URI is malformed: {0}", options.DatabaseUrl);
				Environment.Exit(IncorrectOptionsReturnCode);
			}
			if (uri.Scheme != "http" && uri.Scheme != "https")
			{
				log.ErrorFormat("Provided URI is not of HTTP(S) scheme: {0}", options.DatabaseUrl);
				Environment.Exit(IncorrectOptionsReturnCode);
			}
			if (!uri.IsAbsoluteUri)
			{
				log.ErrorFormat("Provided URI is not absolute: {0}", options.DatabaseUrl);
				Environment.Exit(IncorrectOptionsReturnCode);
			}
			return uri;
		}