예제 #1
0
        } // LoadMostRecentlySavedFillBookLoad()

        //
        private List <IStringifiable> ReadNodes(string filePath)
        {
            if (!System.IO.File.Exists(filePath))
            {
                return(new List <IStringifiable>());              // return empty list.
            }
            // 1.  Read the file backwards until we find the last startTag for the FillBook XML.
            // Search for the last block for the object.
            List <string> lines      = new List <string>();
            string        objectName = m_FillHub.GetType().FullName;
            string        startTag   = string.Format("<{0}", m_FillHub.GetType().FullName); // leave trailing parts off to allow for attributes.

            using (BackwardReader br = new BackwardReader(filePath))
            {
                bool isContinuing = true;
                while (!br.SOF && isContinuing)
                {
                    string aLine = br.Readline();
                    if (aLine.Contains(startTag))
                    {
                        m_FillHub.Log.NewEntry(LogLevel.Major, "DropRules.Load: Loading fill hub {0}", aLine);
                        isContinuing = false;
                        // Keep everything after the startTag, dump everything on the line
                        string[] truncatedLineParts = aLine.Split(new string[] { startTag }, StringSplitOptions.RemoveEmptyEntries);
                        string   truncatedLine      = string.Format("{0}{1}", startTag, truncatedLineParts[truncatedLineParts.Length - 1]);
                        lines.Add(truncatedLine);
                    }
                    else
                    {
                        lines.Add(aLine);
                    }
                } //wend
            }     //using reader
            lines.Reverse();                                            // since I read backwards, reverse the lines now.

            // 2. Now, create a string stream of the block, create nodes.
            StringBuilder msg = new StringBuilder();

            foreach (string aLine in lines)
            {
                msg.Append(aLine);
            }
            byte[] byteBuffer               = ASCIIEncoding.ASCII.GetBytes(msg.ToString());
            System.IO.MemoryStream stream   = new System.IO.MemoryStream(byteBuffer);
            StringifiableReader    reader   = new StringifiableReader(stream);
            List <IStringifiable>  nodeList = reader.ReadToEnd(true);

            return(nodeList);
        } // ReadNodes
예제 #2
0
        } // GetMostRecentDropFile()

        //
        //
        //
        //
        private List <IStringifiable> Load2(string filePath)
        {
            List <IStringifiable> objectList = null;
            // 1.  Read the file backwards until we find the last startTag for the FillBook XML.
            // Search for the last block for the object.
            List <string> lines      = new List <string>();
            string        objectName = m_FillHub.GetType().FullName;
            string        startTag   = string.Format("<{0}", m_FillHub.GetType().FullName); // leave trailing parts off to allow for attributes.

            using (BackwardReader br = new BackwardReader(filePath))
            {
                bool isContinuing = true;
                while (!br.SOF && isContinuing)
                {
                    string aLine = br.Readline();
                    if (aLine.Contains(startTag))
                    {
                        m_FillHub.Log.NewEntry(LogLevel.Major, "DropRules.Load: Loading fill hub {0}", aLine);
                        isContinuing = false;
                        // Keep everything after the startTag, dump everything on the line
                        string[] truncatedLineParts = aLine.Split(new string[] { startTag }, StringSplitOptions.RemoveEmptyEntries);
                        string   truncatedLine      = string.Format("{0}{1}", startTag, truncatedLineParts[truncatedLineParts.Length - 1]);
                        lines.Add(truncatedLine);
                    }
                    else
                    {
                        lines.Add(aLine);
                    }
                } //wend
            }     //using reader
            lines.Reverse();                                            // since I read backwards, reverse the lines now.

            // 2. Now, create a string stream of the block, create nodes.
            StringBuilder msg = new StringBuilder();

            foreach (string aLine in lines)
            {
                msg.Append(aLine);
            }
            byte[] byteBuffer               = ASCIIEncoding.ASCII.GetBytes(msg.ToString());
            System.IO.MemoryStream stream   = new System.IO.MemoryStream(byteBuffer);
            StringifiableReader    reader   = new StringifiableReader(stream);
            List <IStringifiable>  nodeList = reader.ReadToEnd(true);



            // 3. Now convert these nodes into real objects.
            objectList = new List <IStringifiable>();
            foreach (IStringifiable iNode in nodeList)
            {
                Node node = (Node)iNode;
                if (node.Name.Contains("FillHub"))
                {   // We need the sub elements of the FillHub
                    foreach (IStringifiable subElem in node.SubElements)
                    {
                        IStringifiable obj = Stringifiable.DeStringify((Node)subElem);
                        objectList.Add(obj);
                    }
                }
                else
                {   // These are fill events and other things.
                    IStringifiable obj = Stringifiable.DeStringify((Node)iNode);
                    objectList.Add(obj);
                }
            }

            return(objectList);
        }// Load2()