Ejemplo n.º 1
0
        /// <summary>
        /// Persists the provided configuration.
        /// </summary>
        /// <param name="configuration">A <see cref="Configuration"/> instance containing the configuration that should be persisted.</param>
        public async Task PersistConfigurationAsync(Configuration configuration)
        {
            Configuration originalConfiguration = null;

            using (var session = _storeProvider.Store.OpenAsyncSession())
            {
                // Retrieve the original configuration
                originalConfiguration = await session.LoadAsync <Configuration>(DOCUMENT_KEY);
            }

            using (var session = _storeProvider.Store.OpenAsyncSession())
            {
                // Using the store method when the configuration already exists in the database will override it completely, this is acceptable
                await session.StoreAsync(configuration, DOCUMENT_KEY);

                await session.SaveChangesAsync();
            }

            if (originalConfiguration == null ||
                originalConfiguration.ExpirationDays != configuration.ExpirationDays ||
                originalConfiguration.ExpirationEnabled != configuration.ExpirationEnabled ||
                !originalConfiguration.ExpirationRegex.Equals(configuration.ExpirationRegex, StringComparison.Ordinal)
                )
            {
                await _expirationManager.ApplyExpirationPolicyAsync(configuration);
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Import(IFormFile file)
        {
            // Make sure that we have an input file
            if (file == null)
            {
                return(BadRequest("No file to import specified."));
            }

            // Store the uploaded file into a temporary location
            string filePath = Path.GetTempFileName();

            using (var stream = new FileStream(filePath, FileMode.Create))
            {
                // Copy file to temporary location
                await file.CopyToAsync(stream);

                // Perform import
                var importOptions = new DatabaseSmugglerImportOptions()
                {
                    OperateOnTypes = DatabaseItemType.Documents,
                    IncludeExpired = false,
                };

                var operation = await _documentStore.Smuggler.ImportAsync(importOptions, filePath);

                await operation.WaitForCompletionAsync();

                // Delete temporary file
                System.IO.File.Delete(filePath);

                // Set the expirations as configured
                await _expirationManager.ApplyExpirationPolicyAsync(await _configurationManager.GetOrCreateConfigurationAsync());

                return(NoContent());
            }
        }