Exemplo n.º 1
0
        private static PersistenceData Load(string fileName)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(fileName);
            XmlNode         fileNode        = xmlDoc.SelectSingleNode("logexpert/file");
            PersistenceData persistenceData = new PersistenceData();

            if (fileNode != null)
            {
                persistenceData = ReadPersistenceDataFromNode(fileNode);
            }
            return(persistenceData);
        }
Exemplo n.º 2
0
        private static PersistenceData ReadPersistenceDataFromNode(XmlNode node)
        {
            PersistenceData persistenceData = new PersistenceData();
            XmlElement      fileElement     = node as XmlElement;

            persistenceData.bookmarkList  = ReadBookmarks(fileElement);
            persistenceData.rowHeightList = ReadRowHeightList(fileElement);
            ReadOptions(fileElement, persistenceData);
            persistenceData.fileName = fileElement.GetAttribute("fileName");
            string sLineCount = fileElement.GetAttribute("lineCount");

            if (sLineCount != null && sLineCount.Length > 0)
            {
                persistenceData.lineCount = int.Parse(sLineCount);
            }
            persistenceData.filterParamsList  = ReadFilter(fileElement);
            persistenceData.filterTabDataList = ReadFilterTabs(fileElement);
            persistenceData.encoding          = ReadEncoding(fileElement);
            return(persistenceData);
        }
Exemplo n.º 3
0
        public static string SavePersistenceData(string logFileName, PersistenceData persistenceData, Preferences preferences)
        {
            string fileName;

            if (persistenceData.sessionFileName != null)
            {
                fileName = persistenceData.sessionFileName;
            }
            else
            {
                fileName = BuildPersisterFileName(logFileName, preferences);
            }
            if (preferences.saveLocation == SessionSaveLocation.SameDir)
            {
                // make to log file in .lxp file relative
                string filePart = Path.GetFileName(persistenceData.fileName);
                persistenceData.fileName = filePart;
            }

            Save(fileName, persistenceData);
            return(fileName);
        }
Exemplo n.º 4
0
        private static void Save(string fileName, PersistenceData persistenceData)
        {
            XmlDocument xmlDoc      = new XmlDocument();
            XmlElement  rootElement = xmlDoc.CreateElement("logexpert");

            xmlDoc.AppendChild(rootElement);
            XmlElement fileElement = xmlDoc.CreateElement("file");

            rootElement.AppendChild(fileElement);
            fileElement.SetAttribute("fileName", persistenceData.fileName);
            fileElement.SetAttribute("lineCount", "" + persistenceData.lineCount);
            WriteBookmarks(xmlDoc, fileElement, persistenceData.bookmarkList);
            WriteRowHeightList(xmlDoc, fileElement, persistenceData.rowHeightList);
            WriteOptions(xmlDoc, fileElement, persistenceData);
            WriteFilter(xmlDoc, fileElement, persistenceData.filterParamsList);
            WriteFilterTabs(xmlDoc, fileElement, persistenceData.filterTabDataList);
            WriteEncoding(xmlDoc, fileElement, persistenceData.encoding);
            if (xmlDoc.HasChildNodes)
            {
                xmlDoc.Save(fileName);
            }
        }
Exemplo n.º 5
0
        private static List <FilterTabData> ReadFilterTabs(XmlElement startNode)
        {
            List <FilterTabData> dataList = new List <FilterTabData>();
            XmlNode filterTabsNode        = startNode.SelectSingleNode("filterTabs");

            if (filterTabsNode != null)
            {
                XmlNodeList filterTabNodeList = filterTabsNode.ChildNodes; // all "filterTab" nodes
                foreach (XmlNode node in filterTabNodeList)
                {
                    PersistenceData persistenceData = ReadPersistenceDataFromNode(node);
                    XmlNode         filterNode      = node.SelectSingleNode("tabFilter");
                    if (filterNode != null)
                    {
                        List <FilterParams> filterList = ReadFilter(filterNode as XmlElement);
                        FilterTabData       data       = new FilterTabData();
                        data.persistenceData = persistenceData;
                        data.filterParams    = filterList[0]; // there's only 1
                        dataList.Add(data);
                    }
                }
            }
            return(dataList);
        }
Exemplo n.º 6
0
 private static void WriteFilterTabs(XmlDocument xmlDoc, XmlElement rootElement, List <FilterTabData> dataList)
 {
     if (dataList.Count > 0)
     {
         XmlElement filterTabsElement = xmlDoc.CreateElement("filterTabs");
         rootElement.AppendChild(filterTabsElement);
         foreach (FilterTabData data in dataList)
         {
             PersistenceData persistenceData  = data.persistenceData;
             XmlElement      filterTabElement = xmlDoc.CreateElement("filterTab");
             filterTabsElement.AppendChild(filterTabElement);
             WriteBookmarks(xmlDoc, filterTabElement, persistenceData.bookmarkList);
             WriteRowHeightList(xmlDoc, filterTabElement, persistenceData.rowHeightList);
             WriteOptions(xmlDoc, filterTabElement, persistenceData);
             WriteFilter(xmlDoc, filterTabElement, persistenceData.filterParamsList);
             WriteFilterTabs(xmlDoc, filterTabElement, persistenceData.filterTabDataList);
             XmlElement filterElement = xmlDoc.CreateElement("tabFilter");
             filterTabElement.AppendChild(filterElement);
             List <FilterParams> filterList = new List <FilterParams>();
             filterList.Add(data.filterParams);
             WriteFilter(xmlDoc, filterElement, filterList);
         }
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Loads the persistence options out of the given persistence file name.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static PersistenceData LoadOptionsOnly(string fileName)
        {
            PersistenceData persistenceData = new PersistenceData();
            XmlDocument     xmlDoc          = new XmlDocument();

            try
            {
                xmlDoc.Load(fileName);
            }
            catch (IOException)
            {
                return(null);
            }
            XmlNode fileNode = xmlDoc.SelectSingleNode("logexpert/file");

            if (fileNode != null)
            {
                XmlElement fileElement = fileNode as XmlElement;
                ReadOptions(fileElement, persistenceData);
                persistenceData.fileName = fileElement.GetAttribute("fileName");
                persistenceData.encoding = ReadEncoding(fileElement);
            }
            return(persistenceData);
        }
Exemplo n.º 8
0
 public static string SavePersistenceDataWithFixedName(string persistenceFileName,
                                                       PersistenceData persistenceData)
 {
     Save(persistenceFileName, persistenceData);
     return(persistenceFileName);
 }
Exemplo n.º 9
0
        private static void ReadOptions(XmlElement startNode, PersistenceData persistenceData)
        {
            XmlNode optionsNode = startNode.SelectSingleNode("options");
            string  value       = GetOptionsAttribute(optionsNode, "multifile", "enabled");

            persistenceData.multiFile        = value != null && value.Equals("1");
            persistenceData.multiFilePattern = GetOptionsAttribute(optionsNode, "multifile", "pattern");
            value = GetOptionsAttribute(optionsNode, "multifile", "maxDays");
            try
            {
                persistenceData.multiFileMaxDays = value != null?short.Parse(value) : 0;
            }
            catch (Exception)
            {
                persistenceData.multiFileMaxDays = 0;
            }

            XmlNode multiFileNode = optionsNode.SelectSingleNode("multifile");

            if (multiFileNode != null)
            {
                XmlNodeList multiFileNodeList = multiFileNode.ChildNodes; // all "fileEntry" nodes
                foreach (XmlNode node in multiFileNodeList)
                {
                    string fileName = null;
                    foreach (XmlAttribute attr in node.Attributes)
                    {
                        if (attr.Name.Equals("fileName"))
                        {
                            fileName = attr.InnerText;
                        }
                    }
                    persistenceData.multiFileNames.Add(fileName);
                }
            }

            value = GetOptionsAttribute(optionsNode, "currentline", "line");
            if (value != null)
            {
                persistenceData.currentLine = int.Parse(value);
            }
            value = GetOptionsAttribute(optionsNode, "firstDisplayedLine", "line");
            if (value != null)
            {
                persistenceData.firstDisplayedLine = int.Parse(value);
            }

            value = GetOptionsAttribute(optionsNode, "filter", "visible");
            persistenceData.filterVisible = value != null && value.Equals("1");
            value = GetOptionsAttribute(optionsNode, "filter", "advanced");
            persistenceData.filterAdvanced = value != null && value.Equals("1");
            value = GetOptionsAttribute(optionsNode, "filter", "position");
            if (value != null)
            {
                persistenceData.filterPosition = int.Parse(value);
            }

            value = GetOptionsAttribute(optionsNode, "bookmarklist", "visible");
            persistenceData.bookmarkListVisible = value != null && value.Equals("1");
            value = GetOptionsAttribute(optionsNode, "bookmarklist", "position");
            if (value != null)
            {
                persistenceData.bookmarkListPosition = int.Parse(value);
            }

            value = GetOptionsAttribute(optionsNode, "followTail", "enabled");
            persistenceData.followTail = value != null && value.Equals("1");

            value = GetOptionsAttribute(optionsNode, "bookmarkCommentColumn", "visible");
            persistenceData.showBookmarkCommentColumn = value != null && value.Equals("1");

            value = GetOptionsAttribute(optionsNode, "filterSaveList", "visible");
            persistenceData.filterSaveListVisible = value != null && value.Equals("1");

            XmlNode tabNode = startNode.SelectSingleNode("tab");

            if (tabNode != null)
            {
                persistenceData.tabName = (tabNode as XmlElement).GetAttribute("name");
            }
            XmlNode columnizerNode = startNode.SelectSingleNode("columnizer");

            if (columnizerNode != null)
            {
                persistenceData.columnizerName = (columnizerNode as XmlElement).GetAttribute("name");
            }
            XmlNode highlightGroupNode = startNode.SelectSingleNode("highlightGroup");

            if (highlightGroupNode != null)
            {
                persistenceData.highlightGroupName = (highlightGroupNode as XmlElement).GetAttribute("name");
            }
        }
Exemplo n.º 10
0
        private static void WriteOptions(XmlDocument xmlDoc, XmlElement rootElement, PersistenceData persistenceData)
        {
            XmlElement optionsElement = xmlDoc.CreateElement("options");

            rootElement.AppendChild(optionsElement);

            XmlElement element = xmlDoc.CreateElement("multifile");

            element.SetAttribute("enabled", persistenceData.multiFile ? "1" : "0");
            element.SetAttribute("pattern", persistenceData.multiFilePattern);
            element.SetAttribute("maxDays", "" + persistenceData.multiFileMaxDays);
            foreach (string fileName in persistenceData.multiFileNames)
            {
                XmlElement entryElement = xmlDoc.CreateElement("fileEntry");
                entryElement.SetAttribute("fileName", "" + fileName);
                element.AppendChild(entryElement);
            }
            optionsElement.AppendChild(element);

            element = xmlDoc.CreateElement("currentline");
            element.SetAttribute("line", "" + persistenceData.currentLine);
            optionsElement.AppendChild(element);

            element = xmlDoc.CreateElement("firstDisplayedLine");
            element.SetAttribute("line", "" + persistenceData.firstDisplayedLine);
            optionsElement.AppendChild(element);

            element = xmlDoc.CreateElement("filter");
            element.SetAttribute("visible", persistenceData.filterVisible ? "1" : "0");
            element.SetAttribute("advanced", persistenceData.filterAdvanced ? "1" : "0");
            element.SetAttribute("position", "" + persistenceData.filterPosition);
            optionsElement.AppendChild(element);

            element = xmlDoc.CreateElement("bookmarklist");
            element.SetAttribute("visible", persistenceData.bookmarkListVisible ? "1" : "0");
            element.SetAttribute("position", "" + persistenceData.bookmarkListPosition);
            optionsElement.AppendChild(element);

            element = xmlDoc.CreateElement("followTail");
            element.SetAttribute("enabled", persistenceData.followTail ? "1" : "0");
            optionsElement.AppendChild(element);

            element = xmlDoc.CreateElement("tab");
            element.SetAttribute("name", persistenceData.tabName);
            rootElement.AppendChild(element);

            element = xmlDoc.CreateElement("columnizer");
            element.SetAttribute("name", persistenceData.columnizerName);
            rootElement.AppendChild(element);

            element = xmlDoc.CreateElement("highlightGroup");
            element.SetAttribute("name", persistenceData.highlightGroupName);
            rootElement.AppendChild(element);

            element = xmlDoc.CreateElement("bookmarkCommentColumn");
            element.SetAttribute("visible", persistenceData.showBookmarkCommentColumn ? "1" : "0");
            optionsElement.AppendChild(element);

            element = xmlDoc.CreateElement("filterSaveList");
            element.SetAttribute("visible", persistenceData.filterSaveListVisible ? "1" : "0");
            optionsElement.AppendChild(element);
        }