public async Task BehaviorWhenServerIsDown() { using (var store = NewStore()) { var server = GetServer(); var outputDirectory = Path.Combine(server.Configuration.DataDirectory, "Export"); try { var options = new FilesConnectionStringOptions { Url = "http://localhost:8078/", DefaultFileSystem = store.DefaultFileSystem }; var smugglerApi = new SmugglerFilesApi(); var e = await AssertAsync.Throws <SmugglerException>(() => smugglerApi.ImportData(new SmugglerImportOptions <FilesConnectionStringOptions> { FromFile = outputDirectory.ToFullPath(), To = options })); Assert.Contains("Smuggler encountered a connection problem:", e.Message); e = await AssertAsync.Throws <SmugglerException>(() => smugglerApi.ExportData(new SmugglerExportOptions <FilesConnectionStringOptions> { ToFile = outputDirectory.ToFullPath(), From = options })); Assert.Contains("Smuggler encountered a connection problem:", e.Message); } finally { IOExtensions.DeleteDirectory(outputDirectory); } } }
internal static async Task <FilesStore> CreateStore(FilesConnectionStringOptions options) { var credentials = options.Credentials as NetworkCredential; if (credentials == null) { credentials = CredentialCache.DefaultNetworkCredentials; } else if ((String.IsNullOrWhiteSpace(credentials.UserName) || String.IsNullOrWhiteSpace(credentials.Password))) { credentials = CredentialCache.DefaultNetworkCredentials; } var store = new FilesStore { Credentials = credentials, ApiKey = options.ApiKey, Url = options.Url, DefaultFileSystem = options.DefaultFileSystem, }; store.Initialize(); await ValidateThatServerIsUpAndFilesystemExists(options, store); return(store); }
internal static FilesStore CreateStore(FilesConnectionStringOptions options) { var credentials = options.Credentials as NetworkCredential; if (credentials == null) { credentials = CredentialCache.DefaultNetworkCredentials; } else if ((string.IsNullOrWhiteSpace(credentials.UserName) || string.IsNullOrWhiteSpace(credentials.Password))) { credentials = CredentialCache.DefaultNetworkCredentials; } var store = new FilesStore { Credentials = credentials, ApiKey = options.ApiKey, Url = options.Url, DefaultFileSystem = options.DefaultFileSystem, }; store.Initialize(false); return(store); }
public async Task ShouldNotThrowIfFileSystemExists() { using (var store = NewStore(fileSystemName: "DoesExists", requestedStorage: "esent")) { var server = GetServer(); var outputDirectory = Path.Combine(server.Configuration.DataDirectory, "Export"); try { await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(store.DefaultFileSystem); await InitializeWithRandomFiles(store, 2, 4); var options = new FilesConnectionStringOptions { Url = store.Url, DefaultFileSystem = store.DefaultFileSystem }; var smugglerApi = new SmugglerFilesApi(); var export = await smugglerApi.ExportData(new SmugglerExportOptions <FilesConnectionStringOptions> { From = options, ToFile = outputDirectory }); await smugglerApi.ImportData(new SmugglerImportOptions <FilesConnectionStringOptions> { FromFile = export.FilePath, To = options }); } finally { IOExtensions.DeleteDirectory(outputDirectory); } } }
internal static async Task<FilesStore> CreateStore(FilesConnectionStringOptions options) { var credentials = options.Credentials as NetworkCredential; if (credentials == null) { credentials = CredentialCache.DefaultNetworkCredentials; } else if ((String.IsNullOrWhiteSpace(credentials.UserName) || String.IsNullOrWhiteSpace(credentials.Password))) { credentials = CredentialCache.DefaultNetworkCredentials; } var store = new FilesStore { Credentials = credentials, ApiKey = options.ApiKey, Url = options.Url, DefaultFileSystem = options.DefaultFileSystem, }; store.Initialize(); await ValidateThatServerIsUpAndFilesystemExists(options, store); return store; }
public async Task ShouldThrowIfFileSystemDoesNotExist() { using (var store = NewStore()) { var server = GetServer(); var outputDirectory = Path.Combine(server.Configuration.DataDirectory, "Export"); try { var smugglerApi = new SmugglerFilesApi(); var options = new FilesConnectionStringOptions { Url = store.Url, DefaultFileSystem = "DoesNotExist" }; var message = string.Format("Smuggler does not support file system creation (file system 'DoesNotExist' on server '{0}' must exist before running Smuggler).", store.Url); var e = await AssertAsync.Throws<SmugglerException>(() => smugglerApi.ExportData(new SmugglerExportOptions<FilesConnectionStringOptions> { ToFile = outputDirectory.ToFullPath(), From = options })); Assert.Equal(message, e.Message); e = await AssertAsync.Throws<SmugglerException>(() => smugglerApi.ImportData(new SmugglerImportOptions<FilesConnectionStringOptions> { FromFile = outputDirectory.ToFullPath(), To = options })); Assert.Equal(message, e.Message); } finally { IOExtensions.DeleteDirectory(outputDirectory); } } }
public async Task CanDisableVersioningDuringImport() { long fileCount; string export = Path.Combine(NewDataPath("export_3219"), "Export"); using (var store = NewStore()) { for (int i = 0; i < 10; i++) { await store.AsyncFilesCommands.UploadAsync("test-" + i, StringToStream("hello")); } var options = new FilesConnectionStringOptions { Url = store.Url, DefaultFileSystem = store.DefaultFileSystem }; var smuggler = new SmugglerFilesApi(); await smuggler.ExportData(new SmugglerExportOptions<FilesConnectionStringOptions> { From = options, ToFile = export }); fileCount = (await store.AsyncFilesCommands.GetStatisticsAsync()).FileCount; } using (var store = NewStore(activeBundles: "Versioning", fileSystemName: "Import", index: 1)) { await store.AsyncFilesCommands.Configuration.SetKeyAsync(VersioningUtil.DefaultConfigurationName, new VersioningConfiguration { Id = VersioningUtil.DefaultConfigurationName }); var smuggler = new SmugglerFilesApi(new SmugglerFilesOptions() { ShouldDisableVersioningBundle = true }); var options = new FilesConnectionStringOptions { Url = store.Url, DefaultFileSystem = store.DefaultFileSystem }; await smuggler.ImportData(new SmugglerImportOptions<FilesConnectionStringOptions> { FromFile = export, To = options }); var fileCountAfterImport = (await store.AsyncFilesCommands.GetStatisticsAsync()).FileCount; Assert.Equal(fileCount, fileCountAfterImport); // after import versioning should be active await store.AsyncFilesCommands.UploadAsync("with-rev", StringToStream("rev")); using (var session = store.OpenAsyncSession()) { var revisions = await session.GetRevisionsForAsync("with-rev", 0, 10); Assert.Equal(1, revisions.Length); } } }
//private void DefineDatabaseOptionsSet(DatabaseSmugglerOptions databaseOptions) //{ // databaseOptionSet = new OptionSet(); // databaseOptionSet.OnWarning += s => ConsoleHelper.WriteLineWithColor(ConsoleColor.Yellow, s); // databaseOptionSet.Add("operate-on-types:", OptionCategory.SmugglerDatabase, "Specify the types to operate on. Specify the types to operate on. You can specify more than one type by combining items with a comma." + Environment.NewLine + // "Default is all items." + Environment.NewLine + // "Usage example: Indexes,Documents,Attachments,RemoveAnalyzers", value => // { // try // { // if (string.IsNullOrWhiteSpace(value) == false) // { // databaseOptions.OperateOnTypes = (ItemType) Enum.Parse(typeof (ItemType), value, ignoreCase: true); // } // } // catch (Exception e) // { // PrintUsageAndExit(e); // } // }); // databaseOptionSet.Add("metadata-filter:{=}", OptionCategory.SmugglerDatabase, "Filter documents by a metadata property." + Environment.NewLine + // "Usage example: Raven-Entity-Name=Posts, or Raven-Entity-Name=Posts,Persons for multiple document types", (key, val) => databaseOptions.Filters.Add(new FilterSetting // { // Path = "@metadata." + key, // ShouldMatch = true, // Values = FilterSetting.ParseValues(val) // })); // databaseOptionSet.Add("negative-metadata-filter:{=}", OptionCategory.SmugglerDatabase, "Filter documents NOT matching a metadata property." + Environment.NewLine + // "Usage example: Raven-Entity-Name=Posts", (key, val) => databaseOptions.Filters.Add( // new FilterSetting // { // Path = "@metadata." + key, // ShouldMatch = false, // Values = FilterSetting.ParseValues(val) // })); // databaseOptionSet.Add("filter:{=}", OptionCategory.SmugglerDatabase, "Filter documents by a document property" + Environment.NewLine + // "Usage example: Property-Name=Value", (key, val) => databaseOptions.Filters.Add( // new FilterSetting // { // Path = key, // ShouldMatch = true, // Values = FilterSetting.ParseValues(val) // })); // databaseOptionSet.Add("negative-filter:{=}", OptionCategory.SmugglerDatabase, "Filter documents NOT matching a document property" + Environment.NewLine + // "Usage example: Property-Name=Value", (key, val) => databaseOptions.Filters.Add( // new FilterSetting // { // Path = key, // ShouldMatch = false, // Values = FilterSetting.ParseValues(val) // })); // databaseOptionSet.Add("ignore-errors-and-continue", OptionCategory.SmugglerDatabase, "If this option is enabled, smuggler will not halt its operation on errors. Errors still will be displayed to the user.", value => // { // databaseOptions.IgnoreErrorsAndContinue = true; // }); // databaseOptionSet.Add("transform:", OptionCategory.SmugglerDatabase, "Transform documents using a given script (import only)", script => databaseOptions.TransformScript = script); // databaseOptionSet.Add("transform-file:", OptionCategory.SmugglerDatabase, "Transform documents using a given script file (import only)", script => databaseOptions.TransformScript = File.ReadAllText(script)); // databaseOptionSet.Add("max-steps-for-transform-script:", OptionCategory.SmugglerDatabase, "Maximum number of steps that transform script can have (import only)", s => databaseOptions.MaxStepsForTransformScript = int.Parse(s)); // databaseOptionSet.Add("batch-size:", OptionCategory.SmugglerDatabase, "The batch size for requests", s => databaseOptions.BatchSize = int.Parse(s)); // databaseOptionSet.Add("chunk-size:", OptionCategory.SmugglerDatabase, "The number of documents to import before new connection will be opened", s => databaseOptions.ChunkSize = int.Parse(s)); // databaseOptionSet.Add("d|database:", OptionCategory.SmugglerDatabase, "The database to operate on. If no specified, the operations will be on the default database.", value => databaseOptions.Source.DefaultDatabase = value); // databaseOptionSet.Add("d2|database2:", OptionCategory.SmugglerDatabase, "The database to export to. If no specified, the operations will be on the default database. This parameter is used only in the between operation.", value => databaseOptions.Destination.DefaultDatabase = value); // databaseOptionSet.Add("wait-for-indexing", OptionCategory.SmugglerDatabase, "Wait until all indexing activity has been completed (import only)", _ => databaseOptions.WaitForIndexing = true); // databaseOptionSet.Add("excludeexpired", OptionCategory.SmugglerDatabase, "Excludes expired documents created by the expiration bundle", _ => databaseOptions.ShouldExcludeExpired = true); // databaseOptionSet.Add("disable-versioning-during-import", OptionCategory.SmugglerDatabase, "Disables versioning for the duration of the import", _ => databaseOptions.ShouldDisableVersioningBundle = true); // databaseOptionSet.Add("limit:", OptionCategory.SmugglerDatabase, "Reads at most VALUE documents.", s => databaseOptions.Limit = int.Parse(s)); // databaseOptionSet.Add("timeout:", OptionCategory.SmugglerDatabase, "The timeout to use for requests", s => databaseOptions.Timeout = TimeSpan.FromMilliseconds(int.Parse(s))); // databaseOptionSet.Add("incremental", OptionCategory.SmugglerDatabase, "States usage of incremental operations", _ => databaseOptions.Incremental = true); // databaseOptionSet.Add("u|user|username:"******"The username to use when the database requires the client to authenticate.", value => GetCredentials(databaseOptions.Source).UserName = value); // databaseOptionSet.Add("u2|user2|username2:", OptionCategory.SmugglerDatabase, "The username to use when the database requires the client to authenticate. This parameter is used only in the between operation.", value => GetCredentials(databaseOptions.Destination).UserName = value); // databaseOptionSet.Add("p|pass|password:"******"The password to use when the database requires the client to authenticate.", value => GetCredentials(databaseOptions.Source).Password = value); // databaseOptionSet.Add("p2|pass2|password2:", OptionCategory.SmugglerDatabase, "The password to use when the database requires the client to authenticate. This parameter is used only in the between operation.", value => GetCredentials(databaseOptions.Destination).Password = value); // databaseOptionSet.Add("domain:", OptionCategory.SmugglerDatabase, "The domain to use when the database requires the client to authenticate.", value => GetCredentials(databaseOptions.Source).Domain = value); // databaseOptionSet.Add("domain2:", OptionCategory.SmugglerDatabase, "The domain to use when the database requires the client to authenticate. This parameter is used only in the between operation.", value => GetCredentials(databaseOptions.Destination).Domain = value); // databaseOptionSet.Add("key|api-key|apikey:", OptionCategory.SmugglerDatabase, "The API-key to use, when using OAuth.", value => databaseOptions.Source.ApiKey = value); // databaseOptionSet.Add("key2|api-key2|apikey2:", OptionCategory.SmugglerDatabase, "The API-key to use, when using OAuth. This parameter is used only in the between operation.", value => databaseOptions.Destination.ApiKey = value); // databaseOptionSet.Add("strip-replication-information", OptionCategory.SmugglerDatabase, "Remove all replication information from metadata (import only)", _ => databaseOptions.StripReplicationInformation = true); // databaseOptionSet.Add("continuation-token:", OptionCategory.SmugglerDatabase, "Activates the usage of a continuation token in case of unreliable connections or huge imports", s => databaseOptions.ContinuationToken = s); // databaseOptionSet.Add("skip-conflicted", OptionCategory.SmugglerDatabase, "The database will issue and error when conflicted documents are put. The default is to alert the user, this allows to skip them to continue.", _ => databaseOptions.SkipConflicted = true); //} private NetworkCredential GetCredentials(FilesConnectionStringOptions connectionStringOptions) { var cred = connectionStringOptions.Credentials as NetworkCredential; if (cred != null) { return(cred); } cred = new NetworkCredential(); connectionStringOptions.Credentials = cred; return(cred); }
public async Task enableVersioningDuringImportFs() { var export = Path.Combine(NewDataPath("src"), "Export"); using (var store = NewStore(activeBundles: "Versioning")) { await store.AsyncFilesCommands.Configuration.SetKeyAsync(VersioningUtil.DefaultConfigurationName, new VersioningConfiguration { Id = VersioningUtil.DefaultConfigurationName }); for (int i = 0; i < 10; i++) { await store.AsyncFilesCommands.UploadAsync("test-" + i, StringToStream("hello")); } var options = new FilesConnectionStringOptions { Url = store.Url, DefaultFileSystem = store.DefaultFileSystem }; var smuggler = new SmugglerFilesApi(); await smuggler.ExportData(new SmugglerExportOptions <FilesConnectionStringOptions> { From = options, ToFile = export }); } using (var store = NewStore(activeBundles: "Versioning", fileSystemName: "Import", index: 1)) { await store.AsyncFilesCommands.Configuration.SetKeyAsync(VersioningUtil.DefaultConfigurationName, new VersioningConfiguration { Id = VersioningUtil.DefaultConfigurationName }); var smuggler = new SmugglerFilesApi(new SmugglerFilesOptions() { ShouldDisableVersioningBundle = false }); var options = new FilesConnectionStringOptions { Url = store.Url, DefaultFileSystem = store.DefaultFileSystem }; var e = await AssertAsync.Throws <ErrorResponseException>(async() => await smuggler.ImportData(new SmugglerImportOptions <FilesConnectionStringOptions> { FromFile = export, To = options })); Assert.Contains("PUT vetoed on file /test-0/revisions/1 by Raven.Database.FileSystem.Bundles.Versioning.Plugins.VersioningPutTrigger because: Creating a historical revision is not allowed", e.Message); } }
public async Task disableVersioningDuringImportFs() { var export = Path.Combine(NewDataPath("src"), "Export"); using (var store = NewStore(activeBundles: "Versioning")) { await store.AsyncFilesCommands.Configuration.SetKeyAsync(VersioningUtil.DefaultConfigurationName, new VersioningConfiguration { Id = VersioningUtil.DefaultConfigurationName }); for (int i = 0; i < 10; i++) { await store.AsyncFilesCommands.UploadAsync("test-" + i, StringToStream("hello")); } var options = new FilesConnectionStringOptions { Url = store.Url, DefaultFileSystem = store.DefaultFileSystem }; var smuggler = new SmugglerFilesApi(); await smuggler.ExportData(new SmugglerExportOptions <FilesConnectionStringOptions> { From = options, ToFile = export }); } using (var store = NewStore(activeBundles: "Versioning", fileSystemName: "Import", index: 1)) { await store.AsyncFilesCommands.Configuration.SetKeyAsync(VersioningUtil.DefaultConfigurationName, new VersioningConfiguration { Id = VersioningUtil.DefaultConfigurationName }); var smuggler = new SmugglerFilesApi(new SmugglerFilesOptions() { ShouldDisableVersioningBundle = true }); var options = new FilesConnectionStringOptions { Url = store.Url, DefaultFileSystem = store.DefaultFileSystem }; var e = await AssertAsync.DoesNotThrow(async() => await smuggler.ImportData(new SmugglerImportOptions <FilesConnectionStringOptions> { FromFile = export, To = options })); Assert.True(e); } }
internal static async Task ValidateThatServerIsUpAndFileSystemExists(FilesConnectionStringOptions server, FilesStore s) { var shouldDispose = false; try { var commands = !string.IsNullOrEmpty(server.DefaultFileSystem) ? s.AsyncFilesCommands.ForFileSystem(server.DefaultFileSystem) : s.AsyncFilesCommands; await commands.GetStatisticsAsync().ConfigureAwait(false); // check if file system exist } catch (Exception e) { shouldDispose = true; var responseException = e as ErrorResponseException; if (responseException != null && responseException.StatusCode == HttpStatusCode.ServiceUnavailable && responseException.Message.StartsWith("Could not find a resource named:")) { throw new SmugglerException( string.Format( "Smuggler does not support file system creation (file system '{0}' on server '{1}' must exist before running Smuggler).", server.DefaultFileSystem, s.Url), e); } if (e.InnerException != null) { var webException = e.InnerException as WebException; if (webException != null) { throw new SmugglerException(string.Format("Smuggler encountered a connection problem: '{0}'.", webException.Message), webException); } } throw new SmugglerException(string.Format("Smuggler encountered a connection problem: '{0}'.", e.Message), e); } finally { if (shouldDispose) { s.Dispose(); } } }
public async Task ShouldNotThrowIfFileSystemExistsUsingDefaultConfiguration() { using (var store = NewStore()) { var server = GetServer(); var outputDirectory = Path.Combine(server.Configuration.DataDirectory, "Export"); try { await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(store.DefaultFileSystem); await InitializeWithRandomFiles(store, 1, 100); var options = new FilesConnectionStringOptions { Url = store.Url, DefaultFileSystem = store.DefaultFileSystem }; var smugglerApi = new SmugglerFilesApi(); var export = await smugglerApi.ExportData(new SmugglerExportOptions <FilesConnectionStringOptions> { From = options, ToFile = outputDirectory.ToFullPath() }); await smugglerApi.ImportData(new SmugglerImportOptions <FilesConnectionStringOptions> { FromFile = export.FilePath, To = options }); await VerifyDump(store, export.FilePath, s => { using (var session = s.OpenAsyncSession()) { var files = s.AsyncFilesCommands.BrowseAsync().Result; Assert.Equal(1, files.Count()); } }); } finally { IOExtensions.DeleteDirectory(outputDirectory); } } }
public async Task ShouldThrowIfFileSystemDoesNotExist() { using (var store = NewStore()) { var server = GetServer(); var outputDirectory = Path.Combine(server.Configuration.DataDirectory, "Export"); try { var smugglerApi = new SmugglerFilesApi(); var options = new FilesConnectionStringOptions { Url = store.Url, DefaultFileSystem = "DoesNotExist" }; var message = string.Format("Smuggler does not support file system creation (file system 'DoesNotExist' on server '{0}' must exist before running Smuggler).", store.Url); var e = await AssertAsync.Throws <SmugglerException>(() => smugglerApi.ExportData(new SmugglerExportOptions <FilesConnectionStringOptions> { ToFile = outputDirectory.ToFullPath(), From = options })); Assert.Equal(message, e.Message); e = await AssertAsync.Throws <SmugglerException>(() => smugglerApi.ImportData(new SmugglerImportOptions <FilesConnectionStringOptions> { FromFile = outputDirectory.ToFullPath(), To = options })); Assert.Equal(message, e.Message); } finally { IOExtensions.DeleteDirectory(outputDirectory); } } }
public async Task ShouldNotThrowIfFileSystemExists() { using (var store = NewStore(fileSystemName: "DoesExists", requestedStorage: "esent")) { var server = GetServer(); var outputDirectory = Path.Combine(server.Configuration.DataDirectory, "Export"); try { await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(store.DefaultFileSystem); await InitializeWithRandomFiles(store, 2, 4); var options = new FilesConnectionStringOptions { Url = store.Url, DefaultFileSystem = store.DefaultFileSystem }; var smugglerApi = new SmugglerFilesApi(); var export = await smugglerApi.ExportData(new SmugglerExportOptions<FilesConnectionStringOptions> { From = options, ToFile = outputDirectory }); await smugglerApi.ImportData(new SmugglerImportOptions<FilesConnectionStringOptions> { FromFile = export.FilePath, To = options }); } finally { IOExtensions.DeleteDirectory(outputDirectory); } } }
public virtual async Task <IAsyncEnumerator <FileHeader> > GetFiles(FilesConnectionStringOptions src, Etag lastEtag, int take) { ShowProgress("Streaming documents from {0}, batch size {1}", lastEtag, take); return(await PrimaryStore.AsyncFilesCommands.StreamFilesAsync(lastEtag, pageSize : take)); }
public virtual async Task<string> GetVersion(FilesConnectionStringOptions server) { var buildNumber = await DocumentStore.AsyncDatabaseCommands.GlobalAdmin.GetBuildNumberAsync(); return buildNumber.ProductVersion; }
public Task <string> GetVersion(FilesConnectionStringOptions server) { return(new CompletedTask <string>(DocumentDatabase.ProductVersion)); }
public virtual async Task <string> GetVersion(FilesConnectionStringOptions server) { var buildNumber = await DocumentStore.AsyncDatabaseCommands.GlobalAdmin.GetBuildNumberAsync().ConfigureAwait(false); return(buildNumber.ProductVersion); }
private NetworkCredential GetCredentials(FilesConnectionStringOptions connectionStringOptions) { var cred = connectionStringOptions.Credentials as NetworkCredential; if (cred != null) return cred; cred = new NetworkCredential(); connectionStringOptions.Credentials = cred; return cred; }
public async Task BehaviorWhenServerIsDown() { using (var store = NewStore()) { var server = GetServer(); var outputDirectory = Path.Combine(server.Configuration.DataDirectory, "Export"); try { var options = new FilesConnectionStringOptions { Url = "http://localhost:8078/", DefaultFileSystem = store.DefaultFileSystem }; var smugglerApi = new SmugglerFilesApi(); var e = await AssertAsync.Throws<SmugglerException>(() => smugglerApi.ImportData(new SmugglerImportOptions<FilesConnectionStringOptions> { FromFile = outputDirectory.ToFullPath(), To = options })); Assert.Contains("Smuggler encountered a connection problem:", e.Message); e = await AssertAsync.Throws<SmugglerException>(() => smugglerApi.ExportData(new SmugglerExportOptions<FilesConnectionStringOptions> { ToFile = outputDirectory.ToFullPath(), From = options })); Assert.Contains("Smuggler encountered a connection problem:", e.Message); } finally { IOExtensions.DeleteDirectory(outputDirectory); } } }
public RemoteSmugglingSource(FilesConnectionStringOptions connectionOptions) { this.connectionOptions = connectionOptions; }
public virtual async Task<IAsyncEnumerator<FileHeader>> GetFiles(FilesConnectionStringOptions src, Etag lastEtag, int take) { ShowProgress("Streaming documents from {0}, batch size {1}", lastEtag, take); return await PrimaryStore.AsyncFilesCommands.StreamFilesAsync(lastEtag, pageSize: take); }
public virtual Task <BuildNumber> GetVersion(FilesConnectionStringOptions server) { return(DocumentStore.AsyncDatabaseCommands.GlobalAdmin.GetBuildNumberAsync()); }
internal static DocumentStore CreateDocumentStore(FilesConnectionStringOptions options) { var credentials = options.Credentials as NetworkCredential; if (credentials == null) { credentials = CredentialCache.DefaultNetworkCredentials; } else if ((String.IsNullOrWhiteSpace(credentials.UserName) || String.IsNullOrWhiteSpace(credentials.Password))) { credentials = CredentialCache.DefaultNetworkCredentials; } var store = new DocumentStore { Credentials = credentials, ApiKey = options.ApiKey, Url = options.Url, }; store.Initialize(); return store; }
internal static async Task ValidateThatServerIsUpAndFilesystemExists(FilesConnectionStringOptions server, FilesStore s) { var shouldDispose = false; try { var commands = !string.IsNullOrEmpty(server.DefaultFileSystem) ? s.AsyncFilesCommands.ForFileSystem(server.DefaultFileSystem) : s.AsyncFilesCommands; await commands.GetStatisticsAsync(); // check if file system exist } catch (Exception e) { shouldDispose = true; var responseException = e as ErrorResponseException; if (responseException != null && responseException.StatusCode == HttpStatusCode.ServiceUnavailable && responseException.Message.StartsWith("Could not find a file system named")) throw new SmugglerException( string.Format( "Smuggler does not support file system creation (file system '{0}' on server '{1}' must exist before running Smuggler).", server.DefaultFileSystem, s.Url), e); if (e.InnerException != null) { var webException = e.InnerException as WebException; if (webException != null) { throw new SmugglerException(string.Format("Smuggler encountered a connection problem: '{0}'.", webException.Message), webException); } } throw new SmugglerException(string.Format("Smuggler encountered a connection problem: '{0}'.", e.Message), e); } finally { if (shouldDispose) s.Dispose(); } }
public Task<string> GetVersion(FilesConnectionStringOptions server) { return new CompletedTask<string>(DocumentDatabase.ProductVersion); }
public Task <BuildNumber> GetVersion(FilesConnectionStringOptions server) { return(new CompletedTask <BuildNumber>(new BuildNumber { BuildVersion = DocumentDatabase.BuildVersion.ToString(), ProductVersion = DocumentDatabase.ProductVersion })); }
private void DefineFilesystemOptionSet(OptionSet optionSet, FileSystemSmugglerOptions options, FilesConnectionStringOptions source, FilesConnectionStringOptions destination) { optionSet.OnWarning += s => ConsoleHelper.WriteLineWithColor(ConsoleColor.Yellow, s); // TODO arek //optionSet.Add("timeout:", OptionCategory.SmugglerFileSystem, "The timeout to use for requests", s => options.Timeout = TimeSpan.FromMilliseconds(int.Parse(s))); //optionSet.Add("incremental", OptionCategory.SmugglerFileSystem, "States usage of incremental operations", _ => options.Incremental = true); databaseOptionSet.Add("disable-versioning-during-import", OptionCategory.SmugglerFileSystem, "Disables versioning for the duration of the import", _ => options.ShouldDisableVersioningBundle = true); optionSet.Add("u|user|username:"******"The username to use when the filesystem requires the client to authenticate.", value => GetCredentials(source).UserName = value); optionSet.Add("u2|user2|username2:", OptionCategory.SmugglerFileSystem, "The username to use when the filesystem requires the client to authenticate. This parameter is used only in the between operation.", value => GetCredentials(destination).UserName = value); optionSet.Add("p|pass|password:"******"The password to use when the filesystem requires the client to authenticate.", value => GetCredentials(source).Password = value); optionSet.Add("p2|pass2|password2:", OptionCategory.SmugglerFileSystem, "The password to use when the filesystem requires the client to authenticate. This parameter is used only in the between operation.", value => GetCredentials(destination).Password = value); optionSet.Add("domain:", OptionCategory.SmugglerFileSystem, "The domain to use when the filesystem requires the client to authenticate.", value => GetCredentials(source).Domain = value); optionSet.Add("domain2:", OptionCategory.SmugglerFileSystem, "The domain to use when the filesystem requires the client to authenticate. This parameter is used only in the between operation.", value => GetCredentials(destination).Domain = value); optionSet.Add("key|api-key|apikey:", OptionCategory.SmugglerFileSystem, "The API-key to use, when using OAuth.", value => source.ApiKey = value); optionSet.Add("key2|api-key2|apikey2:", OptionCategory.SmugglerFileSystem, "The API-key to use, when using OAuth. This parameter is used only in the between operation.", value => destination.ApiKey = value); optionSet.Add("f|filesystem:", OptionCategory.SmugglerFileSystem, "The filesystem to operate on. If no specified, the operations will be on the default filesystem.", value => source.DefaultFileSystem = value); optionSet.Add("f2|filesystem2:", OptionCategory.SmugglerFileSystem, "The filesystem to export to. If no specified, the operations will be on the default filesystem. This parameter is used only in the between operation.", value => destination.DefaultFileSystem = value); }
public RemoteSmugglingDestination(FilesConnectionStringOptions connectionOptions) { this.connectionOptions = connectionOptions; }
public async Task ShouldNotThrowIfFileSystemExistsUsingDefaultConfiguration() { using (var store = NewStore()) { var server = GetServer(); var outputDirectory = Path.Combine(server.Configuration.DataDirectory, "Export"); try { await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(store.DefaultFileSystem); await InitializeWithRandomFiles(store, 1, 100); var options = new FilesConnectionStringOptions {Url = store.Url, DefaultFileSystem = store.DefaultFileSystem}; var smugglerApi = new SmugglerFilesApi(); var export = await smugglerApi.ExportData(new SmugglerExportOptions<FilesConnectionStringOptions> { From = options, ToFile = outputDirectory.ToFullPath() }); await smugglerApi.ImportData(new SmugglerImportOptions<FilesConnectionStringOptions> { FromFile = export.FilePath, To = options }); await VerifyDump(store, export.FilePath, s => { using (var session = s.OpenAsyncSession()) { var files = s.AsyncFilesCommands.BrowseAsync().Result; Assert.Equal(1, files.Count()); } }); } finally { IOExtensions.DeleteDirectory(outputDirectory); } } }
public async Task CanDisableVersioningDuringImport() { long fileCount; string export = Path.Combine(NewDataPath("export_3219"), "Export"); using (var store = NewStore()) { for (int i = 0; i < 10; i++) { await store.AsyncFilesCommands.UploadAsync("test-" + i, StringToStream("hello")); } var options = new FilesConnectionStringOptions { Url = store.Url, DefaultFileSystem = store.DefaultFileSystem }; var smuggler = new SmugglerFilesApi(); await smuggler.ExportData(new SmugglerExportOptions <FilesConnectionStringOptions> { From = options, ToFile = export }); fileCount = (await store.AsyncFilesCommands.GetStatisticsAsync()).FileCount; } using (var store = NewStore(activeBundles: "Versioning", fileSystemName: "Import", index: 1)) { await store.AsyncFilesCommands.Configuration.SetKeyAsync(VersioningUtil.DefaultConfigurationName, new VersioningConfiguration { Id = VersioningUtil.DefaultConfigurationName }); var smuggler = new SmugglerFilesApi(new SmugglerFilesOptions() { ShouldDisableVersioningBundle = true }); var options = new FilesConnectionStringOptions { Url = store.Url, DefaultFileSystem = store.DefaultFileSystem }; await smuggler.ImportData(new SmugglerImportOptions <FilesConnectionStringOptions> { FromFile = export, To = options }); var fileCountAfterImport = (await store.AsyncFilesCommands.GetStatisticsAsync()).FileCount; Assert.Equal(fileCount, fileCountAfterImport); // after import versioning should be active await store.AsyncFilesCommands.UploadAsync("with-rev", StringToStream("rev")); using (var session = store.OpenAsyncSession()) { var revisions = await session.GetRevisionsForAsync("with-rev", 0, 10); Assert.Equal(1, revisions.Length); } } }