Example #1
0
        /// <inheritdoc />
        public ISettingsNode Merge(ISettingsNode other, SettingsMergeOptions options = null)
        {
            if (other == null)
            {
                return(this);
            }

            if (!(other is ArrayNode))
            {
                return(other);
            }

            options = options ?? SettingsMergeOptions.Default;

            switch (options.ArrayMergeStyle)
            {
            case ArrayMergeStyle.Replace:
                return(other);

            case ArrayMergeStyle.Concat:
                return(new ArrayNode(other.Name, children.Concat(other.Children).ToArray()));

            case ArrayMergeStyle.Union:
                return(new ArrayNode(other.Name, children.Union(other.Children).ToArray()));

            default:
                return(null);
            }
        }
Example #2
0
 public SettingsUpdaterResult(bool changed, long version, SettingsVersionType versionType, ISettingsNode settings)
 {
     Changed     = changed;
     Version     = version;
     VersionType = versionType;
     Settings    = settings;
 }
Example #3
0
        public ISettingsNode Convert(ISettingsNode node)
        {
            switch (node)
            {
            case ValueNode valueNode:
                return(valueNode);

            case ArrayNode arrayNode:
                return(new ArrayNode(arrayNode.Name, arrayNode.Children.Select(Convert).ToArray()));

            case ObjectNode objectNode:
                if (IsRedundantObjectNode(objectNode))
                {
                    var singleChild = objectNode.Children.Single();
                    //Make no difference between empty and nonexistent file.
                    if (string.IsNullOrEmpty(singleChild.Value) && !singleChild.Children.Any())
                    {
                        return(new ObjectNode(objectNode.Name));
                    }

                    return(objectNode.Children.Single().WithName(objectNode.Name));
                }

                return(new ObjectNode(objectNode.Name, objectNode.Children.Select(Convert)));

            default:
                return(node);
            }
        }
Example #4
0
        public INode GetNode(string name)
        {
            ISettingsNode child  = this.node.GetSubNode(name);
            INode         result = new SettingsNode(child);

            return(result);
        }
Example #5
0
        private static ISettingsNode Nest(ISettingsNode node, params string[] scopes)
        {
            var baseSource    = new ConstantSource(node);
            var nestingSource = new NestingSource(baseSource, scopes);

            return(nestingSource.Observe().WaitFirstValue(TimeSpan.FromSeconds(5)).settings);
        }
Example #6
0
        private void Load(ISettingsNode settingsNode)
        {
            ISettingsNode peerGroupsNode = settingsNode.GetSubNode(nameof(this.PeerGroups), false);

            if (peerGroupsNode != null)
            {
                foreach (string subNodeName in peerGroupsNode.GetSubNodeNames())
                {
                    ISettingsNode peerGroupNode = peerGroupsNode.GetSubNode(subNodeName, false);
                    PeerGroup     peerGroup     = PeerGroup.TryLoad(peerGroupNode);
                    if (peerGroup != null)
                    {
                        this.PeerGroups.Add(peerGroup);
                    }
                }
            }

            Dictionary <Guid, PeerGroup> idToGroupMap = this.PeerGroups.ToDictionary(group => group.Id);
            ISettingsNode locationsNode = settingsNode.GetSubNode(nameof(this.Locations), false);

            if (locationsNode != null)
            {
                foreach (string subNodeName in locationsNode.GetSubNodeNames())
                {
                    ISettingsNode locationNode = locationsNode.GetSubNode(subNodeName, false);
                    Location      location     = Location.TryLoad(locationNode, idToGroupMap);
                    if (location != null)
                    {
                        this.Locations.Add(location);
                    }
                }
            }
        }
Example #7
0
        public TSettings Bind <TSettings>(ISettingsNode rawSettings)
        {
            var value = binder.Bind <TSettings>(rawSettings);

            Validate(value);
            return(value);
        }
        public ISettingsNode Convert(ISettingsNode node)
        {
            string[] nameParts;

            switch (node)
            {
            case ValueNode valueNode:
                if (!TrySplitName(valueNode, out nameParts))
                {
                    return(valueNode);
                }

                return(TreeFactory.CreateTreeByMultiLevelKey(nameParts[0], nameParts.Skip(1).ToArray(), valueNode.Value));

            case ArrayNode arrayNode:
                var children = MergeRedundantObjectNodes(arrayNode.Children.Select(Convert));

                if (!IsArrayNodeOfValueNodes(arrayNode) || !TrySplitName(arrayNode, out nameParts))
                {
                    return(new ArrayNode(arrayNode.Name, children));
                }

                return(TreeFactory.CreateTreeByMultiLevelKey(nameParts[0], nameParts.Skip(1), new ArrayNode(nameParts.Last(), children)));

            case ObjectNode objectNode:
                return(new ObjectNode(objectNode.Name, MergeRedundantObjectNodes(objectNode.Children.Select(Convert))));

            default:
                return(node);
            }
        }
Example #9
0
        public static Dictionary <ClusterConfigPath, List <string> > Flatten([CanBeNull] this ISettingsNode node)
        {
            var result = new Dictionary <ClusterConfigPath, List <string> >();

            VisitNodeInternal(node, new List <string>(), result);

            return(result);
        }
Example #10
0
 public static void Save(ISettingsNode node)
 {
     node.SetValue(nameof(InsertedColor), InsertedColor.ToArgb());
     node.SetValue(nameof(DeletedColor), DeletedColor.ToArgb());
     node.SetValue(nameof(ChangedColor), ChangedColor.ToArgb());
     node.SetValue(nameof(SpacesPerTab), SpacesPerTab);
     node.SetValue(nameof(HatchDeadSpace), HatchDeadSpace);
 }
        public static string Render([CanBeNull] ISettingsNode node)
        {
            var builder = new StringBuilder();

            RenderInternal(node, builder, 0);

            return(builder.ToString());
        }
Example #12
0
        internal void Save(ISettingsNode settingsNode)
        {
            Debug.Assert(this.Id.ToString() == settingsNode.NodeName, "The Id should be the node name.");

            settingsNode.SetValue("PeerGroupId", this.PeerGroup.Id);
            settingsNode.SetValue(nameof(this.Name), this.Name);
            settingsNode.SetValue(nameof(this.Address), this.Address.ToString());
        }
        public void SetUp()
        {
            binder        = Substitute.For <ISettingsBinder>();
            cachingBinder = new CachingBinder(binder);

            node     = new ValueNode("value");
            settings = new object();
        }
Example #14
0
 public void Save(ISettingsNode settingsNode)
 {
     settingsNode.SetValue(nameof(this.ShowWindow), this.ShowWindow);
     settingsNode.SetValue(nameof(this.ShowNotification), this.ShowNotification);
     settingsNode.SetValue(nameof(this.ColorInactiveTaskbarItem), this.ColorInactiveTaskbarItem);
     settingsNode.SetValue(nameof(this.PlaySound), this.PlaySound);
     settingsNode.SetValue(nameof(this.SoundFileName), this.SoundFileName);
 }
Example #15
0
 private void Saver_SaveSettings(object sender, SettingsEventArgs e)
 {
     if (this.CurrentGizmo != null)
     {
         string        path      = this.GetGizmoSettingsNodePath(false);
         ISettingsNode gizmoNode = e.SettingsNode.GetSubNode(path, true);
         this.CurrentGizmo.SaveSettings(gizmoNode);
     }
 }
Example #16
0
        internal void Save(ISettingsNode settingsNode)
        {
            Debug.Assert(this.Id.ToString() == settingsNode.NodeName, "The Id should be the node name.");

            settingsNode.SetValue(nameof(this.Name), this.Name);
            settingsNode.SetValue(nameof(this.Fail), this.Fail);
            settingsNode.SetValue(nameof(this.Poll), this.Poll);
            settingsNode.SetValue(nameof(this.Wait), this.Wait);
        }
        private static ISettingsNode Nest([CanBeNull] ISettingsNode node, [NotNull] string[] scopes)
        {
            if (node == null || scopes.Length == 0)
            {
                return(node);
            }

            return(TreeFactory.CreateTreeByMultiLevelKey(null, scopes, PatchName(node, scopes.Last())));
        }
Example #18
0
        protected override void OnSaveSettings(ISettingsNode settings)
        {
            base.OnSaveSettings(settings);

            settings.SetValue("Show Zeros", this.ShowZeros);
            settings.SetValue("Show Tenths", this.ShowTenths);
            settings.SetValue("Top Count", this.TopCount);
            settings.SetValue("Refresh Seconds", this.timer.Interval.TotalSeconds);
        }
Example #19
0
 public static void Save(ISettingsNode node)
 {
     node.SetValue("MaxWorkMinutes", (int)MaxWorkTime.TotalMinutes);
     node.SetValue("MinBreakSeconds", (int)MinBreakTime.TotalSeconds);
     node.SetValue(nameof(ShowProgress), ShowProgress);
     node.SetValue(nameof(PlaySound), PlaySound);
     node.SetValue(nameof(StartScreenSaver), StartScreenSaver);
     node.SetValue("ScreenSaverDelayMinutes", (int)ScreenSaverDelay.TotalMinutes);
     node.SetValue("SnoozeMinutes", (int)SnoozeTime.TotalMinutes);
 }
Example #20
0
 internal void SaveNonWindowSettings()
 {
     using (ISettingsStore store = ApplicationInfo.CreateUserSettingsStore())
     {
         ISettingsNode settings = store.RootNode;
         this.profile?.Save(settings.GetSubNode(nameof(Profile), true));
         this.appOptions?.Save(settings.GetSubNode(nameof(AppOptions), true));
         store.Save();
     }
 }
Example #21
0
 private void LogApplicationConfiguration(ISettingsNode configuration)
 {
     try
     {
         log.Info($"Application configuration: {Environment.NewLine}{{ApplicationConfiguration}}.", configuration);
     }
     catch
     {
         log.Warn("Application configuration is unknown.");
     }
 }
 public ClusterConfigClientState(
     [CanBeNull] ISettingsNode localTree,
     [CanBeNull] RemoteTree remoteTree,
     [NotNull] RecyclingBoundedCache <ClusterConfigPath, ISettingsNode> cache,
     long version)
 {
     LocalTree  = localTree;
     RemoteTree = remoteTree;
     Cache      = cache;
     Version    = version;
 }
Example #23
0
        public CommonOptions(ISettingsNode settingsNode)
        {
            if (settingsNode != null)
            {
                this.logFileNameFormat = settingsNode.GetValue(nameof(this.LogFileNameFormat), this.LogFileNameFormat);
                this.logFolder         = settingsNode.GetValue(nameof(this.LogFolder), string.Empty);
            }

            this.ValidateLogFileNameFormat();
            this.ValidateLogFolder();
        }
        public static IDictionary <string, string> Flatten(this ISettingsNode settingsNode)
        {
            var context = new List <string>();
            IDictionary <string, string> result = new SortedDictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            if (settingsNode != null)
            {
                VisitNodeInternal(settingsNode, context, result);
            }

            return(result);
        }
Example #25
0
        public static void Apply([NotNull] ISettingsNode content, [NotNull] ClusterConfigClientSettings settings)
        {
            if (TryGet <bool>(content, nameof(ClusterConfigClientSettings.EnableLocalSettings), "enableLocalSettings", bool.TryParse, out var enableLocalSettings))
            {
                settings.EnableLocalSettings = enableLocalSettings;
            }

            if (TryGet <bool>(content, nameof(ClusterConfigClientSettings.EnableClusterSettings), "enableClusterSettings", bool.TryParse, out var enableClusterSettings))
            {
                settings.EnableClusterSettings = enableClusterSettings;
            }

            if (TryGet <TimeSpan>(content, nameof(ClusterConfigClientSettings.UpdatePeriod), "refreshPeriod", TimeSpan.TryParse, out var updatePeriod))
            {
                settings.UpdatePeriod = updatePeriod;
            }

            if (TryGet <TimeSpan>(content, nameof(ClusterConfigClientSettings.RequestTimeout), "requestTimeout", TimeSpan.TryParse, out var requestTimeout))
            {
                settings.RequestTimeout = requestTimeout;
            }

            if (TryGet(content, nameof(ClusterConfigClientSettings.Zone), "clusterSettingsZoneName", out var zone))
            {
                settings.Zone = zone;
            }

            if (TryGet(content, nameof(ClusterConfigClientSettings.LocalFolder), "localSettingsDirectory", out var localFolder))
            {
                settings.LocalFolder = localFolder;
            }

            if (TryGet(content, "clusterConfigHost", out var dnsEndpoint))
            {
                var parts = dnsEndpoint.Split(':');
                if (parts.Length == 2 && !string.IsNullOrEmpty(parts[0]) && int.TryParse(parts[1], out var port))
                {
                    settings.Cluster = new DnsClusterProvider(parts[0], port);
                }
            }
            else
            {
                var foundDns  = TryGet(content, "ServerDNS", out var dns);
                var foundPort = TryGet(content, "ServerPort", int.TryParse, out int port);

                if (foundDns || foundPort)
                {
                    settings.Cluster = new DnsClusterProvider(
                        dns ?? ClusterConfigClientDefaults.Dns,
                        port == default ? ClusterConfigClientDefaults.Port : port);
                }
            }
        }
Example #26
0
        public void Save(ISettingsNode settingsNode)
        {
            settingsNode.SetValue(nameof(this.RunAtLogin), this.RunAtLogin);
            settingsNode.SetValue(nameof(this.AutoStartMinimized), this.AutoStartMinimized);
            settingsNode.SetValue(nameof(this.MinimizeToTray), this.MinimizeToTray);
            settingsNode.SetValue(nameof(this.AlwaysOnTop), this.AlwaysOnTop);
            settingsNode.SetValue(nameof(this.ConfirmClose), this.ConfirmClose);

            this.FailureOptions.Save(settingsNode.GetSubNode(nameof(this.FailureOptions), true));
            this.ReconnectOptions.Save(settingsNode.GetSubNode(nameof(this.ReconnectOptions), true));
            this.CommonOptions.Save(settingsNode.GetSubNode(nameof(this.CommonOptions), true));
        }
Example #27
0
        public static void Load(ISettingsNode node)
        {
#pragma warning disable MEN010 // Avoid magic numbers. Default minutes and seconds values are clear in context.
            MaxWorkTime      = TimeSpan.FromMinutes(node.GetValue("MaxWorkMinutes", 30));
            MinBreakTime     = TimeSpan.FromSeconds(node.GetValue("MinBreakSeconds", 30));
            ShowProgress     = node.GetValue(nameof(ShowProgress), true);
            PlaySound        = node.GetValue(nameof(PlaySound), false);
            StartScreenSaver = node.GetValue(nameof(StartScreenSaver), false);
            ScreenSaverDelay = TimeSpan.FromMinutes(node.GetValue("ScreenSaverDelayMinutes", 3));
            SnoozeTime       = TimeSpan.FromMinutes(node.GetValue("SnoozeMinutes", 3));
#pragma warning restore MEN010 // Avoid magic numbers
        }
Example #28
0
        public static void Save(ISettingsNode node)
        {
            node.SetValue("CompareType", CompareType);

            node.SetValue("ShowWSInMainDiff", showWSInMainDiff);
            node.SetValue("ShowWSInLineDiff", showWSInLineDiff);
            node.SetValue("IgnoreCase", IgnoreCase);
            node.SetValue("IgnoreTextWhitespace", IgnoreTextWhitespace);
            node.SetValue("ShowOnlyInA", ShowOnlyInA);
            node.SetValue("ShowOnlyInB", ShowOnlyInB);
            node.SetValue("ShowDifferent", ShowDifferent);
            node.SetValue("ShowSame", ShowSame);
            node.SetValue("Recursive", Recursive);
            node.SetValue("IgnoreDirectoryComparison", IgnoreDirectoryComparison);
            node.SetValue("OnlyShowFileDialogIfShiftPressed", OnlyShowFileDialogIfShiftPressed);
            node.SetValue("OnlyShowDirDialogIfShiftPressed", OnlyShowDirDialogIfShiftPressed);
            node.SetValue("GoToFirstDiff", GoToFirstDiff);
            node.SetValue("CheckFileExists", checkFileExists);
            node.SetValue("CheckDirExists", checkDirExists);
            node.SetValue("ShowChangeAsDeleteInsert", ShowChangeAsDeleteInsert);
            node.SetValue("IgnoreXmlWhitespace", IgnoreXmlWhitespace);
            node.SetValue("ShowMdiTabs", showMdiTabs);

            node.SetValue("HashType", hashType);
            node.SetValue("LineDiffHeight", LineDiffHeight);
            node.SetValue("BinaryFootprintLength", BinaryFootprintLength);

            node.SetValue("LastFileA", LastFileA);
            node.SetValue("LastFileB", LastFileB);
            node.SetValue("LastDirA", LastDirA);
            node.SetValue("LastDirB", LastDirB);
            /* Note: We don't save or load the last text. */

            node.SetValue("FontName", viewFont.Name);
            node.SetValue("FontStyle", viewFont.Style);
            node.SetValue("FontSize", Convert.ToString(viewFont.SizeInPoints));

            // Save custom filters
            if (node.GetSubNode("Custom Filters", false) != null)
            {
                node.DeleteSubNode("Custom Filters");
            }

            if (customFilters.Count > 0)
            {
                node = node.GetSubNode("Custom Filters", true);
                for (int i = 0; i < customFilters.Count; i++)
                {
                    node.SetValue(i.ToString(), customFilters[i]);
                }
            }
        }
Example #29
0
        public ISettingsNode Transform([CanBeNull] ISettingsNode node)
        {
            ISettingsNode transformedNode;

            switch (node)
            {
            case ObjectNode objectNode:
                if (TryTransform(objectNode, out transformedNode))
                {
                    return(transformedNode);
                }

                var builder             = new ObjectNodeBuilder(objectNode.Name);
                var transformedAnything = false;

                foreach (var child in objectNode.Children)
                {
                    var transformedChild = Transform(child);
                    if (transformedChild != null)
                    {
                        builder.SetChild(transformedChild);
                    }

                    if (!ReferenceEquals(child, transformedChild))
                    {
                        transformedAnything = true;
                    }
                }

                return(transformedAnything ? builder.Build() : objectNode);

            case ArrayNode arrayNode:
                if (TryTransform(arrayNode, out transformedNode))
                {
                    return(transformedNode);
                }

                var transformedChildren = arrayNode.Children.Select(Transform).Where(t => t != null).ToArray();
                if (transformedChildren.SequenceEqual(arrayNode.Children, ByReferenceEqualityComparer <ISettingsNode> .Instance))
                {
                    return(arrayNode);
                }

                return(new ArrayNode(arrayNode.Name, transformedChildren));

            case ValueNode valueNode:
                return(TryTransform(valueNode, out transformedNode) ? transformedNode : valueNode);

            default:
                return(node);
            }
        }
        public void SetUp()
        {
            var boolBinder = Substitute.For <ISafeSettingsBinder <object> >();

            boolBinder.Bind(Arg.Is <ISettingsNode>(n => n is ValueNode && ((ValueNode)n).Value == "true"))
            .Returns(SettingsBindingResult.Success <object>(true));
            boolBinder.ReturnsForAll(_ => SettingsBindingResult.Error <object>(":("));

            provider = Substitute.For <ISettingsBinderProvider>();
            provider.CreateFor(typeof(bool)).Returns(boolBinder);

            settings = new ValueNode("true");
        }