Пример #1
0
        public static bool CompareFile(BEFile bef1, BEFile bef2)
        {
            if (String.Compare(bef1.m_sName, bef2.m_sName, true) != 0)
                return false;

            if (String.Compare(bef1.m_sFullName, bef2.m_sFullName, true) != 0)
                return false;

            if (bef1.m_nBytes != bef2.m_nBytes)
                return false;

            return true;
        }
Пример #2
0
        /* B E D  R E A D  F R O M  X M L */
        /*----------------------------------------------------------------------------
            %%Function: BedReadFromXml
            %%Qualified: bedu.bedu.BedReadFromXml
            %%Contact: rlittle

        ----------------------------------------------------------------------------*/
        public static BEDir BedFromXml(XmlReader xr, BEPref bep)
        {
            List<BEDir> plbedStack = new List<BEDir>();
            BEDir bed = null;
            BEDir bedRoot = null;
            string sLabel = ".";

            XmlReadState xrs = XmlReadState.Initial;
            while (true)
                {
                xr.MoveToContent();
                if (xrs == XmlReadState.Initial)
                    {
                    if (xr.LocalName != "root")
                        throw new Exception(String.Format("illegal element in initial state: {0}", xr.LocalName));

                    bep.ServerName = xr.GetAttribute("serverPath");
                    bep.ServerShare  = xr.GetAttribute("drive");
                    xr.ReadStartElement();
                    xr.MoveToContent();
                    xrs = XmlReadState.Root;
                    }

                if (xrs == XmlReadState.DirOrFile || xrs == XmlReadState.Root)
                    {
                    string sFullName = xr.GetAttribute("name");

                    if (xr.IsStartElement())
                        {
                        if (xr.LocalName == "dir")
                            {
                            if (xrs == XmlReadState.DirOrFile)
                                {
                                // here we cheat.  we know that we're beyond the root, and we know that the
                                // directory WILL NOT have a trailing "\" which means the path code will be
                                // confused and will think the directory name at the end is a filename...
                                sLabel = sLabel + @"\" + Path.GetFileName(sFullName);
                                }

                            if (sFullName[sFullName.Length - 1] != '\\')
                                sFullName += "\\";

                            BEDir bedNew = new BEDir(sFullName, sLabel);
                            bedNew.InitDirs();

                            if (bedRoot == null)
                                {
                                bed = bedRoot = bedNew;
                                if (!xr.IsEmptyElement)
                                    plbedStack.Add(null);
                                }
                            else
                                {
                                bed.AddDir(bedNew);
                                if (!xr.IsEmptyElement)
                                    {
                                    plbedStack.Add(bed);
                                    bed = bedNew;
                                    }
                                }
                            }
                        else if (xr.LocalName == "file")
                            {
                            if (xrs == XmlReadState.Root)
                                throw new Exception(String.Format("illegal element in root state state: {0}", xr.LocalName));

                            BEFile bef = new BEFile(xr);

                            bed.AddFile(bef);
                            }

                        xr.ReadStartElement();
                        xrs = XmlReadState.DirOrFile;
                        }
                    else
                        {
                        // we're at an end element
                        if (xrs == XmlReadState.Root)
                            throw new Exception(String.Format("found close element when looking for root dir: {0}", xr.LocalName));

                        if (xr.LocalName == "dir")
                            {
                            // pop the directory
                            bed = plbedStack[plbedStack.Count - 1];
                            if (bed != null)
                                sLabel = bed.Label;
                            plbedStack.RemoveAt(plbedStack.Count - 1);
                            xr.ReadEndElement();
                            xrs = XmlReadState.DirOrFile;
                            }
                        else if (xr.LocalName == "root")
                            {
                            // we're done
                            if (plbedStack.Count != 0)
                                throw new Exception(String.Format("encountered </root> with dirs on the stack: {0}", plbedStack.Count));
                            xr.ReadEndElement();
                            xrs = XmlReadState.Done;
                            break;
                            }
                        else
                            {
                            throw new Exception(String.Format("encountered unknown close element: {0}", xr.LocalName));
                            }
                        }
                    continue;
                    }
                }
            // we should be done...
            return bedRoot;
        }
Пример #3
0
 public void AddFile(BEFile bef)
 {
     m_plbef.Add(bef);
 }