Exemple #1
0
        private void Parse(string[] args)
        {
            // Do these arguments the traditional way to maintain compatibility
            if (args.Length < 3)
            {
                PrintUsageAndExit(-1);
            }

            var url = args[1];

            if (url == null)
            {
                PrintUsageAndExit(-1);
                return;
            }
            connectionStringOptions.Url = url;

            var backupPath = args[2];

            if (backupPath == null)
            {
                PrintUsageAndExit(-1);
            }

            SmugglerAction action;

            if (string.Equals(args[0], "in", StringComparison.OrdinalIgnoreCase))
            {
                action = SmugglerAction.Import;
            }
            else if (string.Equals(args[0], "out", StringComparison.OrdinalIgnoreCase))
            {
                action = SmugglerAction.Export;
            }
            else if (string.Equals(args[0], "between", StringComparison.OrdinalIgnoreCase))
            {
                action = SmugglerAction.Between;
            }
            else
            {
                PrintUsageAndExit(-1);
                return;
            }

            if (action != SmugglerAction.Between && Directory.Exists(backupPath))
            {
                options.Incremental = true;
            }

            try
            {
                optionSet.Parse(args);
            }
            catch (Exception e)
            {
                PrintUsageAndExit(e);
            }

            var smugglerApi = new SmugglerApi();

            try
            {
                switch (action)
                {
                case SmugglerAction.Import:
                    smugglerApi.ImportData(new SmugglerImportOptions {
                        FromFile = backupPath, To = connectionStringOptions
                    }, options).Wait();
                    if (waitForIndexing)
                    {
                        smugglerApi.WaitForIndexing(options).Wait();
                    }
                    break;

                case SmugglerAction.Export:
                    smugglerApi.ExportData(new SmugglerExportOptions {
                        From = connectionStringOptions, ToFile = backupPath
                    }, options).Wait();
                    break;

                case SmugglerAction.Between:
                    connectionStringOptions2.Url = backupPath;
                    SmugglerOperation.Between(new SmugglerBetweenOptions {
                        From = connectionStringOptions, To = connectionStringOptions2
                    }, options).Wait();
                    break;
                }
            }
            catch (AggregateException ex)
            {
                var exception = ex.ExtractSingleInnerException();
                var e         = exception as WebException;
                if (e != null)
                {
                    if (e.Status == WebExceptionStatus.ConnectFailure)
                    {
                        Console.WriteLine("Error: {0} {1}", e.Message, connectionStringOptions.Url + (action == SmugglerAction.Between ? " => " + connectionStringOptions2.Url : ""));
                        var socketException = e.InnerException as SocketException;
                        if (socketException != null)
                        {
                            Console.WriteLine("Details: {0}", socketException.Message);
                            Console.WriteLine("Socket Error Code: {0}", socketException.SocketErrorCode);
                        }

                        Environment.Exit((int)e.Status);
                    }

                    var httpWebResponse = e.Response as HttpWebResponse;
                    if (httpWebResponse == null)
                    {
                        throw;
                    }
                    Console.WriteLine("Error: " + e.Message);
                    Console.WriteLine("Http Status Code: " + httpWebResponse.StatusCode + " " + httpWebResponse.StatusDescription);

                    using (var reader = new StreamReader(httpWebResponse.GetResponseStream()))
                    {
                        string line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            Console.WriteLine(line);
                        }
                    }

                    Environment.Exit((int)httpWebResponse.StatusCode);
                }
                else
                {
                    if (exception is SmugglerException)
                    {
                        Console.WriteLine(exception.Message);
                    }
                    else
                    {
                        Console.WriteLine(exception);
                    }

                    Environment.Exit(-1);
                }
            }
        }
Exemple #2
0
        private void Parse(string[] args)
        {
            // Do these arguments the traditional way to maintain compatibility
            if (args.Length < 3)
            {
                PrintUsageAndExit(-1);
            }

            SmugglerAction action = SmugglerAction.Export;

            if (string.Equals(args[0], "in", StringComparison.OrdinalIgnoreCase))
            {
                action = SmugglerAction.Import;
            }
            else if (string.Equals(args[0], "out", StringComparison.OrdinalIgnoreCase))
            {
                action = SmugglerAction.Export;
            }
            else
            {
                PrintUsageAndExit(-1);
            }

            var url = args[1];

            if (url == null)
            {
                PrintUsageAndExit(-1);
                return;
            }
            connectionStringOptions.Url = url;

            options.BackupPath = args[2];
            if (options.BackupPath == null)
            {
                PrintUsageAndExit(-1);
            }

            try
            {
                optionSet.Parse(args);
            }
            catch (Exception e)
            {
                PrintUsageAndExit(e);
            }

            if (options.BackupPath != null && Directory.Exists(options.BackupPath))
            {
                incremental = true;
            }

            var smugglerApi = new SmugglerApi(options, connectionStringOptions);

            try
            {
                switch (action)
                {
                case SmugglerAction.Import:
                    smugglerApi.ImportData(options, incremental);
                    if (waitForIndexing)
                    {
                        smugglerApi.WaitForIndexing(options);
                    }
                    break;

                case SmugglerAction.Export:
                    smugglerApi.ExportData(options, incremental);
                    break;
                }
            }
            catch (WebException e)
            {
                if (e.Status == WebExceptionStatus.ConnectFailure)
                {
                    Console.WriteLine("Error: {0} {1}", e.Message, connectionStringOptions.Url);
                    var socketException = e.InnerException as SocketException;
                    if (socketException != null)
                    {
                        Console.WriteLine("Details: {0}", socketException.Message);
                        Console.WriteLine("Socket Error Code: {0}", socketException.SocketErrorCode);
                    }

                    Environment.Exit((int)e.Status);
                }

                var httpWebResponse = e.Response as HttpWebResponse;
                if (httpWebResponse == null)
                {
                    throw;
                }
                Console.WriteLine("Error: " + e.Message);
                Console.WriteLine("Http Status Code: " + httpWebResponse.StatusCode + " " + httpWebResponse.StatusDescription);

                using (var reader = new StreamReader(httpWebResponse.GetResponseStream()))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        Console.WriteLine(line);
                    }
                }

                Environment.Exit((int)httpWebResponse.StatusCode);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Environment.Exit(-1);
            }
        }
Exemple #3
0
		private void Parse(string[] args)
		{
			// Do these arguments the traditional way to maintain compatibility
			if (args.Length < 3)
				PrintUsageAndExit(-1);

			SmugglerAction action = SmugglerAction.Export;
			if (string.Equals(args[0], "in", StringComparison.OrdinalIgnoreCase))
				action = SmugglerAction.Import;
			else if (string.Equals(args[0], "out", StringComparison.OrdinalIgnoreCase))
				action = SmugglerAction.Export;
			else
				PrintUsageAndExit(-1);

			var url = args[1];
			if (url == null)
			{
				PrintUsageAndExit(-1);
				return;
			}
			connectionStringOptions.Url = url;

			options.BackupPath = args[2];
			if (options.BackupPath == null)
				PrintUsageAndExit(-1);

			try
			{
				optionSet.Parse(args);
			}
			catch (Exception e)
			{
				PrintUsageAndExit(e);
			}

			if (options.BackupPath != null && Directory.Exists(options.BackupPath))
			{
				incremental = true;
			}

			var smugglerApi = new SmugglerApi(options, connectionStringOptions);

			try
			{
				switch (action)
				{
					case SmugglerAction.Import:
						smugglerApi.ImportData(options, incremental).Wait();
						if (waitForIndexing)
							smugglerApi.WaitForIndexing(options).Wait();
						break;
					case SmugglerAction.Export:
						smugglerApi.ExportData(null, options, incremental).Wait();
						break;
				}
			}
			catch (AggregateException ex)
			{
				var exception = ex.ExtractSingleInnerException();
				var e = exception as WebException;
				if (e != null)
				{

					if (e.Status == WebExceptionStatus.ConnectFailure)
					{
						Console.WriteLine("Error: {0} {1}", e.Message, connectionStringOptions.Url);
						var socketException = e.InnerException as SocketException;
						if (socketException != null)
						{
							Console.WriteLine("Details: {0}", socketException.Message);
							Console.WriteLine("Socket Error Code: {0}", socketException.SocketErrorCode);
						}

						Environment.Exit((int)e.Status);
					}

					var httpWebResponse = e.Response as HttpWebResponse;
					if (httpWebResponse == null)
						throw;
					Console.WriteLine("Error: " + e.Message);
					Console.WriteLine("Http Status Code: " + httpWebResponse.StatusCode + " " + httpWebResponse.StatusDescription);

					using (var reader = new StreamReader(httpWebResponse.GetResponseStream()))
					{
						string line;
						while ((line = reader.ReadLine()) != null)
						{
							Console.WriteLine(line);
						}
					}

					Environment.Exit((int)httpWebResponse.StatusCode);
				}
				else
				{
					Console.WriteLine(ex);
					Environment.Exit(-1);
				}
			}
		}