public void PutSettingsValues(SettingsGroupDescriptor group, string user, string instanceKey,
                                      Dictionary <string, string> dirtyValues)
        {
            using (var context = new DataAccessContext())
            {
                // next we obtain any previously stored configuration document for this settings group
                var documentKey = new ConfigurationDocumentKey(group.Name, group.Version, user, instanceKey);
                var broker      = context.GetConfigurationDocumentBroker();

                var values = new Dictionary <string, string>();
                var parser = new SettingsParser();

                var document = broker.GetConfigurationDocument(documentKey);
                if (document == null)
                {
                    document = new ConfigurationDocument
                    {
                        CreationTime          = Platform.Time,
                        DocumentName          = group.Name,
                        DocumentVersionString = VersionUtils.ToPaddedVersionString(group.Version, false, false),
                        User         = user,
                        DocumentText = string.Empty
                    };
                    broker.AddConfigurationDocument(document);
                }
                else
                {
                    // parse document
                    parser.FromXml(document.DocumentText, values);
                }

                // update the values that have changed
                foreach (var kvp in dirtyValues)
                {
                    values[kvp.Key] = kvp.Value;
                }

                try
                {
                    if (values.Count > 0)
                    {
                        // generate the document, update local cache and server
                        document.DocumentText = parser.ToXml(values);
                        context.Commit();
                    }
                }
                catch (EndpointNotFoundException e)
                {
                    Platform.Log(LogLevel.Debug, e, "Unable to save settings to configuration service.");
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Insert a ConfigurationDocument
 /// </summary>
 /// <param name="entity"></param>
 public void AddConfigurationDocument(ConfigurationDocument entity)
 {
     Context.ConfigurationDocuments.InsertOnSubmit(entity);
 }
        public void PutSettingsValues(SettingsGroupDescriptor group, string user, string instanceKey,
                                      Dictionary<string, string> dirtyValues)
        {            
            using (var context = new DataAccessContext())
            {
                // next we obtain any previously stored configuration document for this settings group
                var documentKey = new ConfigurationDocumentKey(group.Name, group.Version, user, instanceKey);
                var broker = context.GetConfigurationDocumentBroker();

                var values = new Dictionary<string, string>();
                var parser = new SettingsParser();

                var document = broker.GetConfigurationDocument(documentKey);
                if (document == null)
                {
                    document = new ConfigurationDocument
                                   {
                                       CreationTime = Platform.Time,
                                       DocumentName = group.Name,
                                       DocumentVersionString = VersionUtils.ToPaddedVersionString(group.Version,false,false),
                                       User = user,
                                       DocumentText = string.Empty
                                   };
                    broker.AddConfigurationDocument(document);
                }
                else
                {
                    // parse document
                    parser.FromXml(document.DocumentText, values);
                }

                // update the values that have changed
                foreach (var kvp in dirtyValues)
                    values[kvp.Key] = kvp.Value;

                try
                {
                    if (values.Count > 0)
                    {
                        // generate the document, update local cache and server
                        document.DocumentText = parser.ToXml(values);
                        context.Commit();
                    }
                }
                catch (EndpointNotFoundException e)
                {
                    Platform.Log(LogLevel.Debug, e, "Unable to save settings to configuration service.");
                }
            }
        }
 partial void DeleteConfigurationDocument(ConfigurationDocument instance);
 /// <summary>
 /// Insert a ConfigurationDocument
 /// </summary>
 /// <param name="entity"></param>
 public void AddConfigurationDocument(ConfigurationDocument entity)
 {
     Context.ConfigurationDocuments.InsertOnSubmit(entity);
 }
 partial void UpdateConfigurationDocument(ConfigurationDocument instance);
 partial void InsertConfigurationDocument(ConfigurationDocument instance);
 partial void DeleteConfigurationDocument(ConfigurationDocument instance);
 partial void UpdateConfigurationDocument(ConfigurationDocument instance);
 partial void InsertConfigurationDocument(ConfigurationDocument instance);