Exemple #1
0
        private async Task Parse(string[] args)
        {
            var options      = smugglerApi.Options;
            var filesOptions = smugglerFilesApi.Options;

            // Do these arguments the traditional way to maintain compatibility
            if (args.Length < 3)
            {
                PrintUsageAndExit(-1);
            }

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

            var url = args[1];

            if (url == null || args[2] == 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;
            }

            try
            {
                switch (mode)
                {
                case SmugglerMode.Database:
                {
                    CallContext.LogicalSetData(Constants.Smuggler.CallContext, true);

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

                    options.Source.Url = url;
                    options.BackupPath = args[2];

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

                    if (NetworkUtil.IsLocalhost(smugglerApi.Options.Destination.Url) ||
                        NetworkUtil.IsLocalhost(smugglerApi.Options.BackupPath))
                    {
                        smugglerApi.Options.DisableCompressionOnImport = true;
                    }

                    ValidateDatabaseParameters(smugglerApi, action);
                    var databaseDispatcher = new SmugglerDatabaseOperationDispatcher(smugglerApi);
                    await databaseDispatcher.Execute(action).ConfigureAwait(false);
                }
                break;

                case SmugglerMode.Filesystem:
                {
                    try
                    {
                        filesystemOptionSet.Parse(args);
                    }
                    catch (Exception e)
                    {
                        PrintUsageAndExit(e);
                    }

                    filesOptions.Source.Url = url;
                    filesOptions.BackupPath = args[2];

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

                    var filesDispatcher = new SmugglerFilesOperationDispatcher(smugglerFilesApi);
                    await filesDispatcher.Execute(action).ConfigureAwait(false);
                }
                break;

                case SmugglerMode.Counter:
                {
                    try
                    {
                        counterOptionSet.Parse(args);
                    }
                    catch (Exception e)
                    {
                        PrintUsageAndExit(e);
                    }

                    switch (action)
                    {
                    case SmugglerAction.Export:
                        smugglerCounterApi.Options.Source.Url            = url;
                        smugglerCounterApi.Options.Source.CounterStoreId = counterStorageName;
                        break;

                    case SmugglerAction.Import:
                        smugglerCounterApi.Options.Destination.Url            = url;
                        smugglerCounterApi.Options.Destination.CounterStoreId = counterStorageName;
                        break;

                    case SmugglerAction.Between:
                        smugglerCounterApi.Options.Source.Url                 = url;
                        smugglerCounterApi.Options.Destination.Url            = url;
                        smugglerCounterApi.Options.Source.CounterStoreId      = counterStorageName;
                        smugglerCounterApi.Options.Destination.CounterStoreId = counterStorageName2;
                        break;
                    }

                    smugglerCounterApi.Options.BackupPath = args[2];

                    var countersDispatcher = new SmugglerCounterOperationDispatcher(smugglerCounterApi.Options);
                    await countersDispatcher.Execute(action).ConfigureAwait(false);
                }
                break;

                default:
                    Console.WriteLine("Smuggler mode is not identified. You should use --database or --filesystem.");
                    Environment.Exit(-1);
                    break;
                }
            }
            catch (Exception e)
            {
                if (e is AggregateException)
                {
                    Console.WriteLine(e.InnerException != null ? e.InnerException.SimplifyError() : e.SimplifyError());
                }
                else if (e is OperationVetoedException)
                {
                    Console.WriteLine("You are trying to import into database with versioning bundle enabled, use the flag: disable - versioning - during - import in the command line parameters\r\n");
                }
                else
                {
                    var errorResponseException = e as ErrorResponseException;
                    Console.WriteLine(errorResponseException != null ?
                                      String.Format("{0} \n\r {1}", errorResponseException.SimplifyError(), errorResponseException.Response) : e.Message);
                }

                Environment.Exit(-1);
            }
        }
Exemple #2
0
        private async Task Parse(string[] args)
        {
            var options      = smugglerApi.Options;
            var filesOptions = smugglerFilesApi.Options;

            // Do these arguments the traditional way to maintain compatibility
            if (args.Length < 3)
            {
                PrintUsageAndExit(-1);
            }

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

            var url = args[1];

            if (url == null || args[2] == 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;
            }

            try
            {
                switch (this.mode)
                {
                case SmugglerMode.Database:
                {
                    CallContext.LogicalSetData(Constants.Smuggler.CallContext, true);

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

                    options.Source.Url = url;
                    options.BackupPath = args[2];

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

                    ValidateDatabaseParameters(smugglerApi, action);
                    var databaseDispatcher = new SmugglerDatabaseOperationDispatcher(smugglerApi);
                    await databaseDispatcher.Execute(action);
                }
                break;

                case SmugglerMode.Filesystem:
                {
                    try
                    {
                        filesystemOptionSet.Parse(args);
                    }
                    catch (Exception e)
                    {
                        PrintUsageAndExit(e);
                    }

                    filesOptions.Source.Url = url;
                    filesOptions.BackupPath = args[2];

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

                    var filesDispatcher = new SmugglerFilesOperationDispatcher(smugglerFilesApi);
                    await filesDispatcher.Execute(action);
                }
                break;
                }
            }
            catch (Exception e)
            {
                if (e is AggregateException)
                {
                    Console.WriteLine(e.SimplifyError());
                }
                else
                {
                    Console.WriteLine(e.Message);
                }

                Environment.Exit(-1);
            }
        }