예제 #1
0
 void ProcessOriginItemStreams(ArchiveItem archiveItem, IOriginItem originItem)
 {
     using (Stream inputStream = originItem.OpenStream()) {
         if (inputStream != null)
         {
             if (Progress != null)
             {
                 Progress(
                     this,
                     new OriginProgressEventArgs(State.BeginStream, originItem)
                     );
             }
             using (Stream outputStream = archiveItem.CreateDataStream()) {
                 byte[] hash;
                 streamPump.Progress = delegate(long done, long total) {
                     if (Progress != null)
                     {
                         Progress(
                             this,
                             new OriginProgressEventArgs(State.Block, originItem, done, total)
                             );
                     }
                 };
                 streamPump.Copy(inputStream, outputStream, out hash);
                 archiveItem.DataStreamHash = hash;
             }
             if (Progress != null)
             {
                 Progress(
                     this,
                     new OriginProgressEventArgs(State.EndStream, originItem)
                     );
             }
         }
     }
 }
예제 #2
0
        bool ProcessOriginItem(ArchiveItem archiveItem, IOriginItem originItem, VerificationType verificationType)
        {
            bool same = true;

            logger.InfoFormat ("Verifying {0}", originItem.Name);

            using (Stream inputStream = originItem.OpenStream()) {
                if (inputStream != null) {
                    if (verificationType == VerificationType.ArchiveHashWithOriginData) {
                        if (!streamVerifier.Verify (inputStream, archiveItem.DataStreamHash))
                            same = false;
                    } else if (verificationType == VerificationType.ArchiveDataWithOriginData) {
                        using (Stream outputStream = archiveItem.OpenDataStream()) {
                            if (outputStream != null) {
                                if (!streamVerifier.Verify (inputStream, outputStream))
                                    same = false;
                            } else {
                                logger.WarnFormat ("Only present in Origin: {0}", originItem.Name);
                                same = false;
                            }
                        }
                    } else {
                        throw new InvalidOperationException ();
                    }
                } else {
                    using (Stream outputStream = archiveItem.OpenDataStream()) {
                        if (outputStream != null) {
                            logger.WarnFormat ("Only present in Archive: {0}", archiveItem.Name);
                            same = false;
                        }
                    }
                }
            }

            var childItems = archiveItem.ChildItems.ToList ();
            foreach (IOriginItem subOriginItem in originItem.ChildItems) {
                var item = childItems.SingleOrDefault (p => p.Name == subOriginItem.Name);
                if (item != null) {
                    childItems.Remove (item);
                    if (!ProcessOriginItem (item, subOriginItem, verificationType))
                        same = false;
                } else {
                    logger.WarnFormat ("Only present in Origin: {0}", subOriginItem.Name);
                    same = false;
                }
            }

            foreach (var childItem in childItems) {
                logger.WarnFormat ("Only present in Archive: {0}", childItem.Name);
                same = false;
            }

            return same;
        }
예제 #3
0
 void ProcessOriginItemStreams(ArchiveItem archiveItem, IOriginItem originItem)
 {
     using (Stream inputStream = originItem.OpenStream()) {
         if (inputStream != null) {
             if (Progress != null)
                 Progress (
                     this,
                     new OriginProgressEventArgs (State.BeginStream, originItem)
                 );
             using (Stream outputStream = archiveItem.CreateDataStream()) {
                 byte[] hash;
                 streamPump.Progress = delegate(long done, long total) {
                     if (Progress != null)
                         Progress (
                             this,
                             new OriginProgressEventArgs (State.Block, originItem, done, total)
                         );
                 };
                 streamPump.Copy (inputStream, outputStream, out hash);
                 archiveItem.DataStreamHash = hash;
             }
             if (Progress != null)
                 Progress (
                     this,
                     new OriginProgressEventArgs (State.EndStream, originItem)
                 );
         }
     }
 }
예제 #4
0
        bool ProcessOriginItem(ArchiveItem archiveItem, IOriginItem originItem, VerificationType verificationType)
        {
            bool same = true;

            logger.InfoFormat("Verifying {0}", originItem.Name);

            using (Stream inputStream = originItem.OpenStream()) {
                if (inputStream != null)
                {
                    if (verificationType == VerificationType.ArchiveHashWithOriginData)
                    {
                        if (!streamVerifier.Verify(inputStream, archiveItem.DataStreamHash))
                        {
                            same = false;
                        }
                    }
                    else if (verificationType == VerificationType.ArchiveDataWithOriginData)
                    {
                        using (Stream outputStream = archiveItem.OpenDataStream()) {
                            if (outputStream != null)
                            {
                                if (!streamVerifier.Verify(inputStream, outputStream))
                                {
                                    same = false;
                                }
                            }
                            else
                            {
                                logger.WarnFormat("Only present in Origin: {0}", originItem.Name);
                                same = false;
                            }
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
                else
                {
                    using (Stream outputStream = archiveItem.OpenDataStream()) {
                        if (outputStream != null)
                        {
                            logger.WarnFormat("Only present in Archive: {0}", archiveItem.Name);
                            same = false;
                        }
                    }
                }
            }

            var childItems = archiveItem.ChildItems.ToList();

            foreach (IOriginItem subOriginItem in originItem.ChildItems)
            {
                var item = childItems.SingleOrDefault(p => p.Name == subOriginItem.Name);
                if (item != null)
                {
                    childItems.Remove(item);
                    if (!ProcessOriginItem(item, subOriginItem, verificationType))
                    {
                        same = false;
                    }
                }
                else
                {
                    logger.WarnFormat("Only present in Origin: {0}", subOriginItem.Name);
                    same = false;
                }
            }

            foreach (var childItem in childItems)
            {
                logger.WarnFormat("Only present in Archive: {0}", childItem.Name);
                same = false;
            }

            return(same);
        }