コード例 #1
0
ファイル: ReproEngine.cs プロジェクト: mcskik/Utilities
        /// <summary>
        /// Load target sample data which can be used to ensure that existing target directories and files take precedence for updates to existing directories and files.
        /// Directory and file rules will be used for any directories or files which are not decided by the presence of existing directories and files.
        /// This essantially means that any new directories or files use the directory and file rules.
        /// </summary>
        protected void LoadTargetSampleData()
        {
            AdvancedDirectoryEngine directoryEngine = new AdvancedDirectoryEngine();

            directoryEngine.Interrupt     = new Interrupt("OK");
            _targetSampleTotalBytes       = 0;
            _targetSampleDirectoryListing = directoryEngine.DirList(TargetSampleHlq, ref _targetSampleTotalBytes);
            long totalBytes = _targetSampleTotalBytes;
        }
コード例 #2
0
        /// <summary>
        /// Compare directory level information from the two specified directory listings.
        /// </summary>
        public virtual void Compare(ref AdvancedDirectoryEntries entriesBef, ref AdvancedDirectoryEntries entriesAft)
        {
            SignalBeginProgress("Changes");
            try
            {
                //Identify entries which are common to both before and after directory listings.
                //This is accomplished using a LINQ query fashioned to implement an inner join.
                List <AdvancedDirectoryEntry> innerEntries = (List <AdvancedDirectoryEntry>)(from b in entriesBef
                                                                                             join a in entriesAft
                                                                                             on new { b.StdDir, b.StdFile } equals new { a.StdDir, a.StdFile }
                                                                                             select new AdvancedDirectoryEntry(a.StdHlq, a.StdDir, a.StdFile, a.StdSize, a.StdDate, a.StdDate, b.StdDate, a.StdHlq, a.StdFile, b.StdHlq, b.StdFile, a.StdType, "BOTH")).ToList();

                //Identify entries which have been deleted.
                //This is accomplished using a LINQ query fashioned to implement a left join
                //then selecting entries which only exist on the left side (before side) of the join.
                List <AdvancedDirectoryEntry> deletedEntries = (List <AdvancedDirectoryEntry>)(from b in entriesBef
                                                                                               join a in entriesAft
                                                                                               on new { b.StdDir, b.StdFile } equals new { a.StdDir, a.StdFile }
                                                                                               into changes
                                                                                               from c in changes.DefaultIfEmpty(new AdvancedDirectoryEntry())
                                                                                               where c.CtlComparison == "EMPTY"
                                                                                               select new AdvancedDirectoryEntry(b.StdHlq, b.StdDir, b.StdFile, b.StdSize, b.StdDate, DateTime.MinValue, b.StdDate, this.targetHlq, b.StdFile, b.StdHlq, b.StdFile, b.StdType, "DELETED")).ToList();

                //Identify entries which have been inserted.
                //This is accomplished using a LINQ query fashioned to implement a left join
                //then selecting entries which only exist on the left side (after side) of the join.
                List <AdvancedDirectoryEntry> insertedEntries = (List <AdvancedDirectoryEntry>)(from a in entriesAft
                                                                                                join b in entriesBef
                                                                                                on new { a.StdDir, a.StdFile } equals new { b.StdDir, b.StdFile }
                                                                                                into changes
                                                                                                from c in changes.DefaultIfEmpty(new AdvancedDirectoryEntry())
                                                                                                where c.CtlComparison == "EMPTY"
                                                                                                select new AdvancedDirectoryEntry(a.StdHlq, a.StdDir, a.StdFile, a.StdSize, a.StdDate, a.StdDate, DateTime.MinValue, a.StdHlq, a.StdFile, this.targetHlq, a.StdFile, a.StdType, "INSERTED")).ToList();
                //Reconstruct the before list.
                entriesBef = new AdvancedDirectoryEntries();
                entriesBef.AddRange(innerEntries);
                entriesBef.AddRange(deletedEntries);

                //Reconstruct the after list.
                entriesAft = new AdvancedDirectoryEntries();
                entriesAft.AddRange(innerEntries);
                entriesAft.AddRange(insertedEntries);
            }
            catch (Exception oException)
            {
                System.Diagnostics.Debug.WriteLine(oException.Message);
            }
            finally
            {
            }
        }
コード例 #3
0
        /// <summary>
        /// Scan directory information into memory resident directory listing object.
        /// </summary>
        /// <param name="qualifier">Top level directory.</param>
        /// <param name="estimate">Number of directory entries found. Used for future estimating.</param>
        /// <returns>List of directory entries.</returns>
        public AdvancedDirectoryEntries DirList(string qualifier, ref long estimate)
        {
            List <string> dirs      = new List <string>();
            string        directory = string.Empty;
            long          count;
            long          entries;

            SignalBeginProgress("DirList");
            try
            {
                this.directoryListing = new AdvancedDirectoryEntries();
                //Build directory and file list.
                dirs      = new List <string>();
                qualifier = qualifier.Trim();
                qualifier = qualifier.Strip(StringExtender.StripMode.Trailing, Path.DirectorySeparatorChar.ToString());
                dirs.Add(qualifier);
                estimate = 1;
                count    = 1;
                entries  = dirs.Count;
                while (count <= entries)
                {
                    directory = dirs[(int)count - 1].ToString();
                    DirLevel(qualifier, directory, ref dirs, ref estimate);
                    count++;
                    entries = dirs.Count;
                    if (Interrupt.Reason == "Cancel")
                    {
                        break;
                    }
                }
            }
            catch (OleDbException oException)
            {
                System.Diagnostics.Debug.WriteLine(oException.Errors[0].Message);
            }
            finally
            {
                SignalEndOfProgress("DirList");
            }
            return(directoryListing);
        }
コード例 #4
0
        /// <summary>
        /// Store details of changes to the specified change list.
        /// </summary>
        public void Changes(AdvancedDirectoryEntries entriesBef, AdvancedDirectoryEntries entriesAft, ref AdvancedDirectoryEntries entriesChg, ref long estimate)
        {
            estimate = 0;
            try
            {
                AdvancedDirectoryEntries deletedEntries = new AdvancedDirectoryEntries((from b in entriesBef
                                                                                        where b.CtlComparison == "DELETED"
                                                                                        select b).ToList());
                SignalUpdateProgress("Changes", 1);

                AdvancedDirectoryEntries innerEntries = new AdvancedDirectoryEntries((from b in entriesBef
                                                                                      where b.CtlComparison == "BOTH"
                                                                                      select b).ToList());
                SignalUpdateProgress("Changes", 1);

                AdvancedDirectoryEntries insertedEntries = new AdvancedDirectoryEntries((from a in entriesAft
                                                                                         where a.CtlComparison == "INSERTED"
                                                                                         select a).ToList());
                SignalUpdateProgress("Changes", 1);

                entriesChg = new AdvancedDirectoryEntries();
                entriesChg.AddRange(deletedEntries);
                entriesChg.AddRange(innerEntries);
                entriesChg.AddRange(insertedEntries);
                SignalUpdateProgress("Changes", 1);
            }
            catch (OleDbException oException)
            {
                System.Diagnostics.Debug.WriteLine(oException.Errors[0].Message);
            }
            finally
            {
            }
            SignalEndOfProgress("Changes");

            //Generate comparisons collection.
            GenerateComparisons(entriesChg, ref estimate);
        }