Exemplo n.º 1
0
        /* G E T  D I R  S I Z E */
        /*----------------------------------------------------------------------------
            %%Function: GetDirSize
            %%Qualified: bedu.BEDir.GetDirSize
            %%Contact: rlittle

        ----------------------------------------------------------------------------*/
        public void ProcessDir(BEList belExclusions, BEList belInclusions, int cLevel, BEPref bep, IReportUsage iru)
        {
            if (m_plbed == null)
                PopulateDir();

            // at this point, we have populated (either because we were preloaded or we just loaded
            iru.OpenDir(m_sLabel, m_sFullPath);

            m_cbDirSize = 0;
            m_cbDirExcl = 0;

            foreach (BEDir bed in m_plbed)
                {
                bed.ProcessDir(belExclusions, belInclusions, cLevel + 1, bep, iru);
                m_cbDirSize += bed.DirSize;
                m_cbDirExcl += bed.DirExcl;
                }

            foreach (BEFile bef in m_plbef)
                {
                string sFullName = bef.FullName;
                if (bep.DoExclusions)
                    {
                    if ((belExclusions != null && belExclusions.FMatch(bep.ServerName, bep.ServerShare, sFullName, BEList.BoolOp.Or))
                        || (belInclusions != null && !belInclusions.FMatch(bep.ServerName, bep.ServerShare, sFullName, BEList.BoolOp.Or)))
                        {
                        iru.ReportFile(0, bef.Bytes, m_sLabel, sFullName);

                        m_cbDirExcl += bef.Bytes;
                        continue;
                        }
                    }

                iru.ReportFile(bef.Bytes, 0, m_sLabel, sFullName);

                m_cbDirSize += bef.Bytes;
                }

            iru.ReportDir(m_cbDirSize, m_cbDirExcl, m_sLabel, cLevel);
            iru.CloseDir();
        }
Exemplo n.º 2
0
        /* G E T  D I R  S I Z E  F R O M  D I R E C T O R Y  I N F O */
        /*----------------------------------------------------------------------------
            %%Function: GetDirSizeFromDirectoryInfo
            %%Qualified: bedu.BEDir.GetDirSizeFromDirectoryInfo
            %%Contact: rlittle

        ----------------------------------------------------------------------------*/
        public static long GetDirSizeFromDirectoryInfo(string sLabel, DirectoryInfo di, BEList belExclusions, BEList belInclusions, int cLevel, BEPref bep, IReportUsage iru, out long cBytesExcl)
        {
            long cBytes = 0;
            cBytesExcl = 0;

            iru.OpenDir(sLabel, di.FullName);

            DirectoryInfo []rgdi = null;

            // first, find any directories
            try
            {
                rgdi = di.GetDirectories();
            }
            catch {}

            if (rgdi != null)
                {
                foreach(DirectoryInfo di2 in rgdi)
                    {
                    long cBytesExcl2;

                    cBytes += GetDirSizeFromDirectoryInfo(sLabel + @"\" + di2.Name, di2, belExclusions, belInclusions, cLevel + 1, bep, iru, out cBytesExcl2);
                    cBytesExcl += cBytesExcl2;
                    }
                }

            // and now add on files -- this is where we actually check exclusions/inclusions....
            FileInfo []rgfi = null;

            try
            {
                rgfi = di.GetFiles();
            }
            catch {}

            if (rgfi != null)
                {
                foreach(FileInfo fi in rgfi)
                    {
                    try
                        {
                        string sFullName = fi.FullName;

                        if (bep.DoExclusions)
                            {
                            if ((belExclusions != null && belExclusions.FMatch(bep.ServerName, bep.ServerShare, sFullName, BEList.BoolOp.Or))
                                || (belInclusions != null && !belInclusions.FMatch(bep.ServerName, bep.ServerShare, sFullName, BEList.BoolOp.Or)))
                                {
                                if (bep.Verbose)
                                    iru.ReportFile(0, fi.Length, sLabel, sFullName);

                                cBytesExcl += fi.Length;
                                continue;
                                }
                            }

                        if (bep.Verbose)
                            iru.ReportFile(fi.Length, 0, sLabel, sFullName);

                        cBytes += fi.Length;
                        }
                    catch (Exception e)
                        {
                        Console.WriteLine(String.Format("cannot process file {0} in directory {1}: {2}", fi.Name, di.Name, e.Message));
                        }
                    }
                }

                iru.ReportDir(cBytes, cBytesExcl, sLabel, cLevel);

            iru.CloseDir();
            return cBytes;
        }