Пример #1
0
        public static IEnumerable <ConsoleProject> LoadProjects()
        {
            IList <ConsoleProject> tmpResult;

            if (File.Exists(PROJECTS_FILE_NAME))
            {
                try
                {
                    tmpResult = new List <ConsoleProject>();
                    XDocument tmpProjectsDocument = XDocument.Load(PROJECTS_FILE_NAME);
                    foreach (XElement tmpProjectXml in tmpProjectsDocument.Descendants(TAG_PROJECT))
                    {
                        ConsoleProject tmpProject = ConsoleProject.LoadFromXElement(tmpProjectXml);
                        tmpProject.Commands = new ObservableCollection <CommandData>();

                        foreach (XElement tmpCommandXml in tmpProjectXml.Descendants(TAG_COMMAND))
                        {
                            CommandData tmpChildCommand = CommandData.LoadFromXElement(tmpCommandXml);
                            tmpProject.Commands.Add(tmpChildCommand);
                        }

                        tmpResult.Add(tmpProject);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Failed to load projects", ex);
                }
            }
            else
            {
                tmpResult = null;
            }
            return(tmpResult);
        }
Пример #2
0
        private static void AddProject(XDocument tmpConfigDoc, ConsoleProject argProject)
        {
            XElement tmpProjectsNode;

            if ((tmpProjectsNode = tmpConfigDoc.Descendants("Projects").SingleOrDefault()) == null)
            {
                tmpProjectsNode = new XElement("Projects");
                tmpConfigDoc.Add(tmpProjectsNode);
            }

            XElement tmpProjectElement = argProject.ToXElement();

            tmpProjectsNode.Add(tmpProjectElement);

            if (argProject.Commands != null && argProject.Commands.Any())
            {
                XElement tmpCommandsElement = tmpProjectElement.Descendants("Commands").SingleOrDefault();
                if (tmpCommandsElement == null)
                {
                    tmpCommandsElement = new XElement("Commands");
                    tmpProjectElement.Add(tmpCommandsElement);
                }

                foreach (CommandData tmpCommand in argProject.Commands)
                {
                    tmpCommandsElement.Add(tmpCommand.ToXElement());
                }
            }
        }
Пример #3
0
        public static void SaveProject(ConsoleProject argProject)
        {
            XDocument tmpConfigDoc = XDocument.Load(StorageManager.PROJECTS_FILE_NAME);

            AddProject(tmpConfigDoc, argProject);
            tmpConfigDoc.Save(StorageManager.PROJECTS_FILE_NAME);
        }
Пример #4
0
        public static void UpdateProject(string projectName, ConsoleProject argProject)
        {
            XDocument tmpConfigDoc = XDocument.Load(StorageManager.PROJECTS_FILE_NAME);

            RemoveProject(tmpConfigDoc, projectName);
            AddProject(tmpConfigDoc, argProject);
            tmpConfigDoc.Save(StorageManager.PROJECTS_FILE_NAME);
        }
Пример #5
0
        internal static ConsoleProject LoadFromXElement(XElement argXml)
        {
            ConsoleProject tmpProject = new ConsoleProject();

            foreach (XAttribute tmpAttribute in argXml.Attributes())
            {
                switch (tmpAttribute.Name.LocalName.ToLower())
                {
                case ATTRIBUTE_ARGUMENTS:
                    tmpProject.Arguments = tmpAttribute.Value;
                    break;

                case ATTRIBUTE_EXECUTABLE:
                    tmpProject.Executable = tmpAttribute.Value;
                    break;

                case ATTRIBUTE_NAME:
                    tmpProject.Name = tmpAttribute.Value;
                    break;

                case ATTRIBUTE_WORKING_DIR:
                    tmpProject.WorkingDir = tmpAttribute.Value;
                    break;

                case ATTRIBUTE_AUTO_LOAD:
                    bool tmpLoad;
                    if (!Boolean.TryParse(tmpAttribute.Value, out tmpLoad))
                    {
                        tmpLoad = false;
                    }
                    tmpProject.AutoLoad = tmpLoad;
                    break;

                case ATTRIBUTE_BACKGROUND_COLOR:
                    tmpProject.BackgroundColor = ColorUtilities.GetColorFromString(tmpAttribute.Value, Colors.Black);
                    break;

                case ATTRIBUTE_MESSAGE_COLOR:
                    tmpProject.MessageColor = ColorUtilities.GetColorFromString(tmpAttribute.Value, Colors.White);
                    break;

                case ATTRIBUTE_ERROR_COLOR:
                    tmpProject.ErrorMessageColor = ColorUtilities.GetColorFromString(tmpAttribute.Value, Colors.Red);
                    break;

                case ATTRIBUTE_CARET_COLOR:
                    tmpProject.CaretColor = ColorUtilities.GetColorFromString(tmpAttribute.Value, Colors.White);
                    break;
                }
            }
            return(tmpProject);
        }
Пример #6
0
 private ConsoleProject(ConsoleProject argCopyFrom)
 {
     this.name            = argCopyFrom.Name;
     this.arguments       = argCopyFrom.Arguments;
     this.autoLoad        = argCopyFrom.AutoLoad;
     this.backgroundColor = argCopyFrom.BackgroundColor;
     this.caretColor      = argCopyFrom.CaretColor;
     if (argCopyFrom.Commands != null)
     {
         this.commands = new ObservableCollection <CommandData>(argCopyFrom.Commands.Select(item => item.GetCopy()));
     }
     this.errorMessageColor = argCopyFrom.ErrorMessageColor;
     this.executable        = argCopyFrom.Executable;
     this.messageColor      = argCopyFrom.MessageColor;
     this.workingDir        = argCopyFrom.WorkingDir;
 }