示例#1
0
        public void LoadNamespaces()
        {
            _namespaces.Clear();

            CConsole.WriteLine("Loading custom namespaces...");

            string filePath = GetFilePath();

            if (File.Exists(filePath))
            {
                IEnumerable <string> lines = File.ReadLines(filePath);
                foreach (var line in lines)
                {
                    if (line.StartsWith("#"))
                    {
                        continue;                       //don't load comments
                    }
                    string[] parts = line.Split(";".ToCharArray(), 2, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length == 2)
                    {
                        AddNamespace(parts[0], parts[1]);
                    }
                }
            }
            else
            {
                CreateNamespacesFile();
            }

            CConsole.WriteLine($"{_namespaces.Count} namespaces loaded.");
            CConsole.WriteLine();
        }
示例#2
0
        public bool SaveNewNamespaces()
        {
            string path   = GetFilePath();
            bool   exists = File.Exists(path);

            try
            {
                if (exists)
                {
                    File.Delete(path);
                }

                using (StreamWriter writer = File.CreateText(path))
                {
                    writer.WriteLine(FILE_HEADER);
                    foreach (KeyValuePair <string, string> kv in _namespaces)
                    {
                        writer.WriteLine($"{kv.Key};{kv.Value}");
                    }
                    writer.Flush();
                }

                return(true);
            }
            catch (Exception ex)
            {
                CConsole.WriteLine("Error when saving namespaces file. Msg: " + ex.Message, ConsoleColor.Red);
                CConsole.WriteLine();
                return(false);
            }
        }
示例#3
0
 private void CreateNamespacesFile()
 {
     CConsole.WriteLine($"'{NAMESPACES_FILE_NAME}' file doesn't exists. Creating it.", ConsoleColor.Yellow);
     try
     {
         using (StreamWriter writer = File.CreateText(GetFilePath()))
         {
             writer.WriteLine(FILE_HEADER);
             writer.Flush();
         }
     }
     catch (Exception ex)
     {
         CConsole.WriteLine("Error when creating namespaces file. Msg: " + ex.Message, ConsoleColor.Red);
     }
     CConsole.WriteLine();
 }
示例#4
0
        public bool AddNamespace(string prefix, string uri)
        {
            if (_namespaces.ContainsKey(prefix))
            {
                CConsole.Write("Prefix '", ConsoleColor.Yellow);
                CConsole.Write(prefix);
                CConsole.Write("' is already in use!", ConsoleColor.Yellow);
                CConsole.WriteLine();
                return(false);
            }

            CConsole.Write("Adding namespace '");
            CConsole.Write(uri, ConsoleColor.Cyan);
            CConsole.Write("' with prefix '");
            CConsole.Write(prefix, ConsoleColor.Cyan);
            CConsole.WriteLine("'.");
            _namespaces.Add(prefix, uri);
            return(true);
        }