Esempio n. 1
0
 public void ReadIndex()
 {
     using (Stream stream = physicalStore.OpenStream (IndexStreamId)) {
         using (BinaryReader reader = new BinaryReader(stream)) {
             int count = reader.ReadInt32 ();
             while (count-- > 0) {
                 ArchiveItem item = new ArchiveItem ();
                 rootItems.Add (item);
                 item.Deserialize (this, reader);
             }
         }
     }
 }
Esempio n. 2
0
        bool ProcessArchiveItem(ArchiveItem archiveItem)
        {
            bool same = true;

            using (Stream outputStream = archiveItem.OpenDataStream()) {
                if (outputStream != null) {
                    if (!streamVerifier.Verify (outputStream, archiveItem.DataStreamHash))
                        same = false;
                }
            }

            foreach (ArchiveItem archiveSubItem in archiveItem.ChildItems) {
                if (!ProcessArchiveItem (archiveSubItem))
                    same = false;
            }

            return same;
        }
Esempio n. 3
0
 void ProcessOriginChildItems(ArchiveItem archiveItem, IOriginItem originItem)
 {
     bool firstDone = false;
     foreach (IOriginItem originSubItem in originItem.ChildItems) {
         if (!firstDone) {
             if (Progress != null)
                 Progress (
                     this,
                     new OriginProgressEventArgs (State.BeginChildItems, originItem)
                 );
             firstDone = true;
         }
         ArchiveItem archiveSubItem = archiveItem.CreateChildItem (originSubItem.Name, originSubItem.Type);
         ProcessOriginItem (archiveSubItem, originSubItem);
     }
     if (!firstDone) {
         if (Progress != null)
             Progress (this, new OriginProgressEventArgs (State.EndChildItems, originItem));
     }
 }
Esempio n. 4
0
        bool ProcessArchiveItem(ArchiveItem archiveItem)
        {
            bool same = true;

            using (Stream outputStream = archiveItem.OpenDataStream()) {
                if (outputStream != null)
                {
                    if (!streamVerifier.Verify(outputStream, archiveItem.DataStreamHash))
                    {
                        same = false;
                    }
                }
            }

            foreach (ArchiveItem archiveSubItem in archiveItem.ChildItems)
            {
                if (!ProcessArchiveItem(archiveSubItem))
                {
                    same = false;
                }
            }

            return(same);
        }
Esempio n. 5
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)
                     );
             }
         }
     }
 }
Esempio n. 6
0
 public void Deserialize(Archive archive, BinaryReader reader)
 {
     this.archive = archive;
     Name = reader.ReadString ();
     Type = reader.ReadInt32 ();
     byte[] by = new byte[16];
     reader.Read (by, 0, 16);
     PhysicalStoreDataStreamId = new Guid (by);
     int hashLen = reader.ReadByte ();
     if (hashLen > 0) {
         DataStreamHash = reader.ReadBytes (hashLen);
     } else {
         DataStreamHash = null;
     }
     int cnt = reader.ReadInt32 ();
     while (cnt-- > 0) {
         ArchiveItem subItem = new ArchiveItem ();
         ChildItems.Add (subItem);
         subItem.Deserialize (archive, reader);
     }
 }
Esempio n. 7
0
 public ArchiveItem CreateChildItem(string name, int type)
 {
     ArchiveItem subItem = new ArchiveItem (archive, name, type);
     ChildItems.Add (subItem);
     return subItem;
 }
Esempio n. 8
0
 public ArchiveItem CreateRootItem(string itemName, int type)
 {
     ArchiveItem item = new ArchiveItem (this, itemName, type);
     rootItems.Add (item);
     return item;
 }
Esempio n. 9
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;
        }
Esempio n. 10
0
        void ProcessArchiveStreams(ArchiveItem archiveItem, IOriginItem originItem)
        {
            using (Stream archiveStream = archiveItem.OpenDataStream()) {
                if (archiveStream != null) {
                    if (Progress != null)
                        Progress (
                            this,
                            new OriginProgressEventArgs (State.BeginStream, originItem)
                        );

                    using (Stream originStream = originItem.CreateStream ()) {
                        byte[] hash;
                        streamPump.Progress = delegate(long done, long total) {
                            if (Progress != null)
                                Progress (
                                    this,
                                    new OriginProgressEventArgs (State.Block, originItem, done, total)
                                );
                        };
                        streamPump.Copy (archiveStream, originStream, out hash);
                        //archiveStream.Hash = hash;
                    }
                }
                if (Progress != null)
                    Progress (
                        this,
                        new OriginProgressEventArgs (State.EndStream, originItem)
                    );
            }
        }
Esempio n. 11
0
        void ProcessArchiveItem(ArchiveItem archiveItem, IOriginItem parentItem)
        {
            IOriginItem originItem = parentItem.CreateChildItem (
                archiveItem.Name,
                archiveItem.Type
            );

            if (Progress != null)
                Progress (this, new OriginProgressEventArgs (State.BeginItem, originItem));

            ProcessArchiveStreams (archiveItem, originItem);
            ProcessArchiveChildItems (archiveItem, originItem);

            if (Progress != null)
                Progress (this, new OriginProgressEventArgs (State.EndItem, originItem));
        }
Esempio n. 12
0
        void ProcessOriginItem(ArchiveItem archiveItem, IOriginItem originItem)
        {
            logger.DebugFormat ("Processing Origin {0}", originItem.Name);

            if (Progress != null)
                Progress (this, new OriginProgressEventArgs (State.BeginItem, originItem));

            ProcessOriginItemStreams (archiveItem, originItem);
            ProcessOriginChildItems (archiveItem, originItem);

            if (Progress != null)
                Progress (this, new OriginProgressEventArgs (State.EndItem, originItem));
        }
Esempio n. 13
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);
        }