예제 #1
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
            {
            }
        }
예제 #2
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);
        }