public async Task <DbFeature> InsertOrUpdateFeatureAsync(Feature feature, string productName, string groupName, string version) { _logger.LogInformation("Persisting feature {FeatureTitle} version {Version} for product {ProductName} and group {GroupName}", feature.Title, version, productName, groupName); var hash = feature.CalculateHash(); DbFeature dbFeature; using (var session = _storeProvider.Store.OpenAsyncSession()) { dbFeature = await session.LoadAsync <DbFeature>(DbFeatureExtensions.GetIdentifier(productName, groupName, feature.Title, hash)); if (dbFeature != null) { // Add the new version to the list var versions = new List <string>(dbFeature.Versions); versions.Add(version); // Prevent duplicates dbFeature.Versions = versions.Distinct().ToArray(); } else { // Create a new feature var processor = new FeatureProcessor(); string parentTitle = processor.DetermineParent(feature); dbFeature = new DbFeature(feature, productName, groupName, parentTitle, version); await session.StoreAsync(dbFeature, dbFeature.GetIdentifier()); } await session.SaveChangesAsync(); } return(dbFeature); }
public async Task InsertOrUpdateFeatureAsync(Feature feature, string productName, string groupName, string version) { var processor = new FeatureProcessor(); string parentTitle = processor.DetermineParent(feature); DbFeature dbFeature = new DbFeature(feature, productName, groupName, parentTitle, version); var configuration = await ConfigurationManager.GetOrCreateConfigurationAsync(); using (var session = Database.DocumentStore.OpenAsyncSession()) { // Using the store method when the feature already exists in the database will override it completely, this is acceptable await session.StoreAsync(dbFeature, dbFeature.GetIdentifier()); if (configuration.ExpirationEnabled && Regex.IsMatch(version, configuration.ExpirationRegex)) { // Set the expiration in the metadata session.Advanced.GetMetadataFor(dbFeature)["Raven-Expiration-Date"] = new RavenJValue(DateTime.UtcNow.Date.AddDays(configuration.ExpirationDays)); } await session.SaveChangesAsync(); } }
public async Task InsertOrUpdateFeatureAsync(Feature feature, string productName, string groupName, string version) { var processor = new FeatureProcessor(); string parentTitle = processor.DetermineParent(feature); DbFeature dbFeature = new DbFeature(feature, productName, groupName, parentTitle, version); using (var session = Database.DocumentStore.OpenAsyncSession()) { // Using the store method when the feature already exists in the database will override it completely, this is acceptable await session.StoreAsync(dbFeature, dbFeature.GetIdentifier()); await session.SaveChangesAsync(); } }
public async Task <DbFeature> InsertOrUpdateFeatureAsync(Feature feature, string productName, string groupName, string version) { _logger.LogInformation("Persisting feature {FeatureTitle} version {Version} for product {ProductName} and group {GroupName}", feature.Title, version, productName, groupName); var processor = new FeatureProcessor(); string parentTitle = processor.DetermineParent(feature); DbFeature dbFeature = new DbFeature(feature, productName, groupName, parentTitle, version); var configuration = await _configurationManager.GetOrCreateConfigurationAsync(); using (var session = _storeProvider.Store.OpenAsyncSession()) { // Using the store method when the feature already exists in the database will override it completely, this is acceptable await session.StoreAsync(dbFeature, dbFeature.GetIdentifier()); session.SetExpirationAccordingToConfiguration(dbFeature, version, configuration); await session.SaveChangesAsync(); } return(dbFeature); }