Beispiel #1
0
        private void ValidateDatabaseParameters(SmugglerDatabaseApi api, SmugglerAction action)
        {
            if (allowImplicitDatabase == false)
            {
                if (string.IsNullOrEmpty(api.Options.Source.DefaultDatabase))
                {
                    throw new OptionException("--database parameter must be specified or pass --allow-implicit-database", "database");
                }

                if (action == SmugglerAction.Between && string.IsNullOrEmpty(api.Options.Destination.DefaultDatabase))
                {
                    throw new OptionException("--database2 parameter must be specified or pass --allow-implicit-database", "database2");
                }
            }
        }
Beispiel #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);
            }
        }
Beispiel #3
0
        private void ValidateDatabaseParameters(SmugglerDatabaseApi api, SmugglerAction action)
        {
            if (allowImplicitDatabase == false)
            {
                if (string.IsNullOrEmpty(api.Options.Source.DefaultDatabase))
                {
                    throw new OptionException("--database parameter must be specified or pass --allow-implicit-database", "database");
                }

                if (action == SmugglerAction.Between && string.IsNullOrEmpty(api.Options.Destination.DefaultDatabase))
                {
                    throw new OptionException("--database2 parameter must be specified or pass --allow-implicit-database", "database2");
                }
            }
        }
Beispiel #4
0
        public async Task Execute(SmugglerAction action)
        {
            try
            {
                switch (action)
                {
                case SmugglerAction.Import:
                    await PerformImportAsync(Options).ConfigureAwait(false);

                    break;

                case SmugglerAction.Export:
                    await PerformExportAsync(Options).ConfigureAwait(false);

                    break;

                case SmugglerAction.Between:
                    await PerformBetweenAsync(Options).ConfigureAwait(false);

                    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, Options.SourceUrl + (action == SmugglerAction.Between ? " => " + this.Options.DestinationUrl : ""));
                        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 || exception is InvalidDataException)
                    {
                        Console.WriteLine(exception.Message);
                    }
                    else if (exception is JsonReaderException)
                    {
                        Console.WriteLine("Failed to load JSON Data. Please make sure you are importing ." + FileExtension + " file, exported by smuggler (aka resource export). If you are importing a ." + FileExtension + " file then the file may be corrupted");
                    }
                    else
                    {
                        Console.WriteLine(exception);
                    }

                    Environment.Exit(-1);
                }
            }
        }
Beispiel #5
0
	    private void ValidateParameters(SmugglerAction action)
	    {
            if (allowImplicitDatabase == false)
            {
                if (string.IsNullOrEmpty(connectionStringOptions.DefaultDatabase))
                {
                    throw new OptionException("--database parameter must be specified or pass --allow-implicit-database", "database");
                }

                if (action == SmugglerAction.Between && string.IsNullOrEmpty(connectionStringOptions2.DefaultDatabase))
                {
                    throw new OptionException("--database2 parameter must be specified or pass --allow-implicit-database", "database2");
                }
            }
        }
Beispiel #6
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.File = args[2];
            if (options.File == null)
            {
                PrintUsageAndExit(-1);
            }

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

            var smugglerApi = new SmugglerApi(connectionStringOptions);

            try
            {
                switch (action)
                {
                case SmugglerAction.Import:
                    smugglerApi.ImportData(options);
                    break;

                case SmugglerAction.Export:
                    smugglerApi.ExportData(options);
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Environment.Exit(-1);
            }
        }