Exemple #1
0
        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.");
                }
            }
        }
Exemple #2
0
        public Dictionary <string, string> GetSettingsValues(SettingsGroupDescriptor group, string user,
                                                             string instanceKey)
        {
            using (var context = new DataAccessContext())
            {
                var documentKey = new ConfigurationDocumentKey(group.Name, group.Version, user, instanceKey);
                var broker      = context.GetConfigurationDocumentBroker();

                var document = broker.GetConfigurationDocument(documentKey);

                var values = new Dictionary <string, string>();
                if (document != null)
                {
                    var parser = new SettingsParser();
                    parser.FromXml(document.DocumentText, values);
                }

                return(values);
            }
        }