/// <summary>
        /// Imports the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        public void Import(string path)
        {
            try
            {
                var document = new XmlDocument();
                document.Load(path);
                var colorNodes = document.GetElementsByTagName("Color");

                foreach (XmlNode node in colorNodes)
                {
                    var name       = node.Attributes["name"];
                    var foreground = node.Attributes["foreground"];

                    var type  = EnumExtensions.GetValueFromDescription <Command.TypeE>(name.Value);
                    var color = (Color)ColorConverter.ConvertFromString(foreground.Value);

                    Colors[type] = color;
                }
                FilePath = path;
                HighlightingChanged?.Invoke();
            }
            catch (Exception)
            {
                Console.Error.WriteLine("Could not import highlighting definition. Loading defauls.");
                MissingFileManager.CreateHighlightingDefinitionFile();
                Import(MissingFileManager.DEFAULT_HIGHLIGHTING_PATH);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Loads the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        public void Load(string path)
        {
            try
            {
                CommandsMap.Clear();
                document.RemoveAll();
                document.Load(path);

                var root         = document.SelectSingleNode("/Commands");
                var commandNodes = root.ChildNodes;

                foreach (XmlNode commandNode in commandNodes)
                {
                    var name    = commandNode.Attributes["name"].Value;
                    var content = commandNode.Attributes["content"].Value;
                    var regex   = new Regex(commandNode.Attributes[2].Value);
                    var type    = EnumExtensions
                                  .GetValueFromDescription <Command.TypeE>(commandNode.Attributes["type"].Value);
                    var description = commandNode.FirstChild.InnerText;

                    CommandsMap.Add(Command.CreateCommand(name, content, description, regex, type));
                }
                FilePath = path;
            }
            catch
            {
                Console.Error.WriteLine("Could not load command list into memory");
                MissingFileManager.CreateCommandsFile();
                Load(MissingFileManager.DEFAULT_COMMANDS_PATH);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Prevents a default instance of the <see cref="Session"/> class from being created.
 /// </summary>
 private Session()
 {
     document.Load(MissingFileManager.SESSION_PATH);
     if (document.SelectSingleNode("/Session") == null)
     {
         MissingFileManager.CreateSessionFile();
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Loads the programs.
        /// </summary>
        /// <returns></returns>
        public ObservableCollection <Program> LoadPrograms()
        {
            var list = new ObservableCollection <Program>();

            // Create session file if it does not exist
            MissingFileManager.CheckForRequiredFiles();

            try
            {
                document.Load(MissingFileManager.SESSION_PATH);
                var root = document.SelectSingleNode(SESSION_NODE);

                if (root == null)
                {
                    return(list);
                }

                foreach (XmlNode child in root.ChildNodes)
                {
                    var path = child.InnerText;
                    try
                    {
                        if (!string.IsNullOrEmpty(path) && list.All(p => p.Path != path))
                        {
                            var program = new Program(Path.GetFileNameWithoutExtension(path))
                            {
                                Content = File.ReadAllText(path, Encoding.ASCII),
                                Path    = path
                            };
                            list.Add(program);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine(ex.Message);
                    }
                }
                return(list);
            }
            catch (Exception)
            {
                return(list);
            }
        }