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); } } } }
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; }
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)); } }
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); }
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) ); } } } }
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); } }
public ArchiveItem CreateChildItem(string name, int type) { ArchiveItem subItem = new ArchiveItem (archive, name, type); ChildItems.Add (subItem); return subItem; }
public ArchiveItem CreateRootItem(string itemName, int type) { ArchiveItem item = new ArchiveItem (this, itemName, type); rootItems.Add (item); return item; }
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; }
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) ); } }
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)); }
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)); }
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); }