Пример #1
0
        public ShardsViewModel()
        {
            _manager = ShardManager.GetInstance();
            Shards   = _manager.Shards;

            Refresh(this);
        }
Пример #2
0
        public static ShardManager GetInstance()
        {
            // ReSharper disable once InvertIf
            if (_instance == null)
            {
                lock ( _lock )
                {
                    if (_instance != null)
                    {
                        return(_instance);
                    }

                    _instance = new ShardManager();
                    return(_instance);
                }
            }

            return(_instance);
        }
Пример #3
0
        public MainViewModel()
        {
            RemoveAlternateDataStreams(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

            _manager = ShardManager.GetInstance();

            _manager.Shards.CollectionChanged += (sender, args) => { ShardEntries = _manager.Shards; };

            ShardEntries = _manager.Shards;

            string fullPath = Path.Combine(Environment.CurrentDirectory, CONFIG_FILENAME);

            if (!File.Exists(fullPath))
            {
                return;
            }

            using (JsonTextReader jtr = new JsonTextReader(new StreamReader(fullPath)))
            {
                JObject config = (JObject)JToken.ReadFrom(jtr);

                if (config["ClientPaths"] != null)
                {
                    foreach (JToken token in config["ClientPaths"])
                    {
                        string path = token.ToObject <string>();

                        if (File.Exists(path))
                        {
                            ClientPaths.Add(path);
                        }
                    }
                }

                if (config["SelectedClientPath"] != null)
                {
                    string path = config["SelectedClientPath"].ToObject <string>();

                    SelectedClientPath = File.Exists(path) ? path : ClientPaths.FirstOrDefault();
                }

                if (config["DataPaths"] != null)
                {
                    foreach (JToken token in config["DataPaths"])
                    {
                        string path = token.ToObject <string>();

                        if (Directory.Exists(path))
                        {
                            DataPaths.Add(path);
                        }
                    }
                }

                if (config["SelectedDataPath"] != null)
                {
                    string path = config["SelectedDataPath"].ToObject <string>();

                    SelectedDataPath = Directory.Exists(path) ? path : DataPaths.FirstOrDefault();
                }

                if (config["Shards"] != null)
                {
                    foreach (JToken token in config["Shards"])
                    {
                        ShardEntry shard = new ShardEntry
                        {
                            Name              = token["Name"]?.ToObject <string>() ?? "Unknown",
                            Address           = token["Address"]?.ToObject <string>() ?? "localhost",
                            Port              = token["Port"]?.ToObject <int>() ?? 2593,
                            HasStatusProtocol = token["HasStatusProtocol"]?.ToObject <bool>() ?? true,
                            Encryption        = token["Encryption"]?.ToObject <bool>() ?? false
                        };

                        ShardEntries.Add(shard);
                    }
                }

                if (config["SelectedShard"] != null)
                {
                    ShardEntry match = _manager.Shards.FirstOrDefault(
                        s => s.Name == config["SelectedShard"].ToObject <string>());

                    if (match != null)
                    {
                        SelectedShard = match;
                    }
                }

                if (config["Plugins"] != null)
                {
                    foreach (JToken token in config["Plugins"])
                    {
                        string pluginPath = token.ToObject <string>();
                        Plugins.Add(new PluginEntry {
                            Name = Path.GetFileName(pluginPath), FullPath = pluginPath
                        });
                    }
                }

                ReadClassicOptions(config);
            }
        }