예제 #1
0
        /// <summary>
        ///  Set the values for a handler
        /// </summary>
        private void SetHandlerValues(XElement node, HandlerSettings handler, uSyncSettings defaultSettings)
        {
            node.SetAttributeValue("Alias", handler.Alias);
            node.SetAttributeValue("Enabled", handler.Enabled);

            if (handler.GuidNames.IsOverridden)
            {
                node.SetAttributeValue("GuidNames", handler.GuidNames.Value);
            }

            if (handler.UseFlatStructure.IsOverridden)
            {
                node.SetAttributeValue("UseFlatStructure", handler.UseFlatStructure.Value);
            }

            if (handler.FailOnMissingParent.IsOverridden)
            {
                node.SetAttributeValue("FailOnMissingParent", handler.FailOnMissingParent.Value);
            }

            node.SetAttributeValue("Actions", string.Join(",", handler.Actions));

            if (handler.Settings != null && handler.Settings.Count > 0)
            {
                foreach (var setting in handler.Settings)
                {
                    var s = node.FindOrCreate("Add", "Key", setting.Key);
                    s.SetAttributeValue("Value", setting.Value);
                }

                node.RemoveMissingElements("Add", "Key", handler.Settings.Keys.ToList());
            }
        }
예제 #2
0
        /// <summary>
        ///  load hte config for a single handler.
        /// </summary>
        public HandlerSettings LoadHandlerConfig(XElement node, uSyncSettings defaultSettings)
        {
            if (node == null)
            {
                return(null);
            }
            var alias = node.Attribute("Alias").ValueOrDefault(string.Empty);

            if (string.IsNullOrEmpty(alias))
            {
                return(null);
            }

            var enabled = node.Attribute("Enabled").ValueOrDefault(true);

            var settings = new HandlerSettings(alias, enabled);

            // these values can be set locally, but if they aren't
            // we get them from the global setting.
            settings.GuidNames           = GetLocalValue(node.Attribute("GuidNames"), defaultSettings.UseGuidNames);
            settings.UseFlatStructure    = GetLocalValue(node.Attribute("UseFlatStructure"), defaultSettings.UseFlatStructure);
            settings.Actions             = node.Attribute("Actions").ValueOrDefault("All").ToDelimitedList().ToArray();
            settings.FailOnMissingParent = GetLocalValue(node.Attribute("FailOnMissingParent"), defaultSettings.FailOnMissingParent);
            settings.Group = node.Attribute("Group").ValueOrDefault(string.Empty);

            // handlers can have their own individual settings beneath a node
            //
            // <Handler Alias="simple" ... >
            //  <Add Key="settingName" Value="settingValue" />
            // </Handler>
            //
            // These get added to a Settings dictionary for the handler, so it
            // can access them as needed (v8.7+ also passed to serializers)
            //


            var perHandlerSettings = new Dictionary <string, string>();

            // merge in the defaults
            if (defaultSettings.DefaultHandlerSettings != null)
            {
                defaultSettings.DefaultHandlerSettings.ToList()
                .ForEach(x => perHandlerSettings[x.Key] = x.Value);
            }

            // merge in the handler.
            var handlerSettings = LoadKeyValueSettings(node);

            if (handlerSettings != null)
            {
                handlerSettings.ToList()
                .ForEach(x => perHandlerSettings[x.Key] = x.Value);
            }

            settings.Settings = perHandlerSettings;

            return(settings);
        }
        public void SaveHandlerConfig(XElement node, HandlerSettings config, uSyncSettings globalSettings)
        {
            if (node == null)
            {
                return;
            }

            node.SetAttributeValue("Alias", config.Alias);
            node.SetAttributeValue("Enabled", config.Enabled);

            if (config.GuidNames.IsOverridden)
            {
                node.SetAttributeValue("GuidNames", config.GuidNames);
            }

            if (config.UseFlatStructure.IsOverridden)
            {
                node.SetAttributeValue("UseFlatStructure", config.UseFlatStructure);
            }

            if (config.BatchSave.IsOverridden)
            {
                node.SetAttributeValue("BatchSave", config.BatchSave);
            }

            if (config.FailOnMissingParent.IsOverridden)
            {
                node.SetAttributeValue("FailOnMissingParent", config.FailOnMissingParent);
            }

            if (config.Actions.Length > 0 && !(config.Actions.Length == 1 && config.Actions[0].InvariantEquals("all")))
            {
                node.SetAttributeValue("Actions", string.Join(",", config.Actions));
            }

            if (config.Settings != null && config.Settings.Any())
            {
                var settingNode = new XElement("Settings");

                foreach (var setting in config.Settings)
                {
                    settingNode.Add(new XElement("Add",
                                                 new XAttribute("Key", setting.Key),
                                                 new XAttribute("Value", setting.Value)));
                }

                var existing = node.Element("Settings");
                if (existing != null)
                {
                    existing.Remove();
                }

                node.Add(settingNode);
            }
        }
예제 #4
0
        /// <summary>
        ///  load hte config for a single handler.
        /// </summary>
        public HandlerSettings LoadHandlerConfig(XElement node, uSyncSettings defaultSettings)
        {
            if (node == null)
            {
                return(null);
            }
            var alias = node.Attribute("Alias").ValueOrDefault(string.Empty);

            if (string.IsNullOrEmpty(alias))
            {
                return(null);
            }

            var enabled = node.Attribute("Enabled").ValueOrDefault(true);

            var settings = new HandlerSettings(alias, enabled);

            // these values can be set locally, but if they aren't
            // we get them from the global setting.
            settings.GuidNames           = GetLocalValue(node.Attribute("GuidNames"), defaultSettings.UseGuidNames);
            settings.UseFlatStructure    = GetLocalValue(node.Attribute("UseFlatStructure"), defaultSettings.UseFlatStructure);
            settings.Actions             = node.Attribute("Actions").ValueOrDefault("All").ToDelimitedList().ToArray();
            settings.FailOnMissingParent = GetLocalValue(node.Attribute("FailOnMissingParent"), defaultSettings.FailOnMissingParent);

            // handlers can have their own individual settings beneath a node
            //
            // <Handler Alias="simple" ... >
            //  <Add Key="settingName" Value="settingValue" />
            // </Handler>
            //
            // These get added to a Settings dictionary for the handler, so it
            // can access them as needed (v8.7+ also passed to serializers)
            //

            var perHandlerSettings = new Dictionary <string, string>();

            foreach (var settingItem in node.Elements("Add"))
            {
                var key   = settingItem.Attribute("Key").ValueOrDefault(string.Empty);
                var value = settingItem.Attribute("Value").ValueOrDefault(string.Empty);

                if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value))
                {
                    continue;
                }
                perHandlerSettings.Add(key, value);
            }

            settings.Settings = perHandlerSettings;

            return(settings);
        }
        public HandlerSettings LoadHandlerConfig(XElement node, uSyncSettings defaultSettings)
        {
            if (node == null)
            {
                return(null);
            }
            var alias = node.Attribute("Alias").ValueOrDefault(string.Empty);

            if (string.IsNullOrEmpty(alias))
            {
                return(null);
            }

            var enabled = node.Attribute("Enabled").ValueOrDefault(true);

            var settings = new HandlerSettings(alias, enabled);

            // these values can be set locally, but if they aren't
            // we get them from the global setting.
            settings.GuidNames           = GetLocalValue(node.Attribute("GuidNames"), defaultSettings.UseGuidNames);
            settings.UseFlatStructure    = GetLocalValue(node.Attribute("UseFlatStructure"), defaultSettings.UseFlatStructure);
            settings.BatchSave           = GetLocalValue(node.Attribute("BatchSave"), defaultSettings.BatchSave);
            settings.Actions             = node.Attribute("Actions").ValueOrDefault("All").ToDelimitedList().ToArray();
            settings.FailOnMissingParent = GetLocalValue(node.Attribute("FailOnMissingParent"), defaultSettings.FailOnMissingParent);

            // var settingNode = node.Element("Settings");
            // if (settingNode != null)
            // {
            var perHandlerSettings = new Dictionary <string, string>();

            foreach (var settingItem in node.Elements("Add"))
            {
                var key   = settingItem.Attribute("Key").ValueOrDefault(string.Empty);
                var value = settingItem.Attribute("Value").ValueOrDefault(string.Empty);

                if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value))
                {
                    continue;
                }

                perHandlerSettings.Add(key, value);
            }

            settings.Settings = perHandlerSettings;
            // }

            return(settings);
        }