Ejemplo n.º 1
0
 /// <summary>
 /// Save configuration to upstream
 /// </summary>
 public IRecordMatchingConfiguration SaveConfiguration(IRecordMatchingConfiguration configuration)
 {
     try
     {
         using (var client = this.GetClient())
         {
             if (configuration is MatchConfiguration sc)
             {
                 return(client.Client.Post <MatchConfiguration, MatchConfiguration>($"MatchConfiguration", sc));
             }
             else
             {
                 throw new InvalidOperationException("Can't understand this match configuration type");
             }
         }
     }
     catch (Exception e)
     {
         throw new Exception($"Could not save configuration {configuration} to upstream", e);
     }
 }
 /// <summary>
 /// Save configuration to the specified stream
 /// </summary>
 /// <param name="config"></param>
 /// <returns></returns>
 public IRecordMatchingConfiguration SaveConfiguration(IRecordMatchingConfiguration config)
 {
     throw new NotSupportedException("Saving to assemblies is not supported");
 }
Ejemplo n.º 3
0
 public IRecordMatchingConfiguration SaveConfiguration(IRecordMatchingConfiguration configuration)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Save configuration
 /// </summary>
 public IRecordMatchingConfiguration SaveConfiguration(IRecordMatchingConfiguration configuration) => this.m_matchingConfigurationService.SaveConfiguration(configuration);
 /// <summary>
 /// Save configuration to the source
 /// </summary>
 public IRecordMatchingConfiguration SaveConfiguration(IRecordMatchingConfiguration configuration)
 {
     throw new NotSupportedException("This service does not support saving match configurations");
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Save configuration to the file system
        /// </summary>
        /// <param name="configuration">The configuration to be saved</param>
        /// <returns>The updated configuration</returns>
        public IRecordMatchingConfiguration SaveConfiguration(IRecordMatchingConfiguration configuration)
        {
            this.m_pepService.Demand(PermissionPolicyIdentifiers.AlterMatchConfiguration);

            if (!this.m_matchConfigurations.TryGetValue(configuration.Id, out ConfigCacheObject configData))
            {
                // Lookup by UUID

                if (this.m_matchConfigurations.Any(o => o.Value.Configuration.Uuid == configuration.Uuid))
                {
                    throw new InvalidOperationException(this.m_localizationService.FormatString("error.server.core.duplicateKey", new { id = configuration.Uuid }));
                }
                else
                {
                    var savePath = this.m_configuration.FilePath.FirstOrDefault(o => !o.ReadOnly);
                    if (savePath == null)
                    {
                        throw new InvalidOperationException("Cannot find a read/write configuration path");
                    }

                    // Set select metadata
                    if (configuration is MatchConfiguration mci)
                    {
                        mci.Metadata.CreationTime = DateTime.Now;
                        mci.Metadata.CreatedBy    = AuthenticationContext.Current.Principal.Identity.Name;
                        mci.Metadata.Version      = 1;
                    }
                    else
                    {
                        configuration.Metadata = new MatchConfigurationMetadata(configuration.Metadata)
                        {
                            CreationTime = DateTime.Now,
                            CreatedBy    = AuthenticationContext.Current.Principal.Identity.Name
                        };
                    }

                    configData = new ConfigCacheObject()
                    {
                        Configuration    = configuration,
                        OriginalFilePath = Path.ChangeExtension(Path.Combine(savePath.Path, configuration.Uuid.ToString()), "xml")
                    };

                    if (!this.m_matchConfigurations.TryAdd(configuration.Id, configData))
                    {
                        throw new InvalidOperationException("Storing configuration has failed");
                    }
                }
            }
            else if (configuration is MatchConfiguration mc)
            {
                mc.Metadata.UpdatedTime = DateTime.Now;
                mc.Metadata.UpdatedBy   = AuthenticationContext.Current.Principal.Identity.Name;
                mc.Metadata.Version++;
            }

            // Open for writing and write the configuration
            try
            {
                using (var fs = System.IO.File.Create(configData.OriginalFilePath))
                {
                    if (configuration is MatchConfiguration mc)
                    {
                        // is the user changing the state
                        if (mc.Metadata.State != configData.Configuration.Metadata.State)
                        {
                            this.m_pepService.Demand(PermissionPolicyIdentifiers.ActivateMatchConfiguration);
                        }

                        mc.Save(fs);
                    }
                    else if (configuration is MatchConfigurationCollection mcc)
                    {
                        mcc.Save(fs);
                    }
                }

                configData.Configuration = configuration;

                return(configData.Configuration);
            }
            catch (Exception e)
            {
                throw new Exception($"Error while saving match configuration {configuration.Id}", e);
            }
        }