Exemplo n.º 1
0
        public void LoadTemplate()
        {
            var filename = GetTemplateFilename();

            try
            {
                var template = JsonSerializer.Deserialize <Template>(File.ReadAllText(filename), _options);

                Pathes.Clear();

                foreach (var path in template.Pathes)
                {
                    Pathes.Add(path);
                }

                foreach (var value in template.Values)
                {
                    if (!Values.Any(each => each.Value == value.Value))
                    {
                        Values.Add(value);
                    }
                }
                ValuesChanged?.Invoke(this, EventArgs.Empty);
                PathesChanged?.Invoke(this, EventArgs.Empty);
            }
            catch
            {
                LoadEnvValues();
            }
        }
Exemplo n.º 2
0
        public void Clear()
        {
            Values.Clear();
            ValuesChanged?.Invoke(this, EventArgs.Empty);

            Pathes.Clear();
            PathesChanged?.Invoke(this, EventArgs.Empty);
        }
Exemplo n.º 3
0
        private void LoadValueAndPathes(string filename, string trim = null)
        {
            var currentDirectory = Directory.GetCurrentDirectory();

            var templates = Directory.GetFiles(currentDirectory, filename, SearchOption.AllDirectories);

            foreach (var template in templates)
            {
                var lines = File.ReadAllLines(template);

                var relativePath = Path.GetRelativePath(currentDirectory, template);

                if (!string.IsNullOrEmpty(trim))
                {
                    relativePath = relativePath.Substring(0, relativePath.Length - trim.Length);
                }

                var valueAndPathes = Parse(lines);

                foreach (var path in valueAndPathes.Select(each => new EnvironmentValuePath {
                    Path = relativePath, Name = each.name, Value = each.value
                }))
                {
                    Pathes.Add(path);
                }

                foreach (var value in valueAndPathes)
                {
                    if (!Values.Any(each => each.Value == value.value))
                    {
                        Values.Add(new EnvironmentValue {
                            Value = value.value, Description = value.name
                        });
                    }
                }
            }

            var valueDic = Values.ToDictionary(each => each.Value);

            ValuesChanged?.Invoke(this, EventArgs.Empty);
            PathesChanged?.Invoke(this, EventArgs.Empty);
        }
Exemplo n.º 4
0
 public void LoadEnvValues()
 {
     Pathes.Clear();
     LoadValueAndPathes(".env");
     PathesChanged?.Invoke(this, EventArgs.Empty);
 }
Exemplo n.º 5
0
 public void LoadEnvTemplate()
 {
     Pathes.Clear();
     LoadValueAndPathes(".env.template", ".template");
     PathesChanged?.Invoke(this, EventArgs.Empty);
 }