public static string ToInfoMessage(Library.Net.Amoeba.Seed seed) { if (seed == null) { throw new ArgumentNullException("seed"); } try { var keywords = seed.Keywords.Where(n => !string.IsNullOrWhiteSpace(n)).ToList(); StringBuilder builder = new StringBuilder(); if (!string.IsNullOrWhiteSpace(seed.Name)) { builder.AppendLine(string.Format("{0}: {1}", LanguagesManager.Instance.Seed_Name, seed.Name)); } if (seed.Certificate != null) { builder.AppendLine(string.Format("{0}: {1}", LanguagesManager.Instance.Seed_Signature, seed.Certificate.ToString())); } builder.AppendLine(string.Format("{0}: {1:#,0}", LanguagesManager.Instance.Seed_Length, seed.Length)); if (keywords.Count != 0) { builder.AppendLine(string.Format("{0}: {1}", LanguagesManager.Instance.Seed_Keywords, String.Join(", ", keywords))); } builder.AppendLine(string.Format("{0}: {1} UTC", LanguagesManager.Instance.Seed_CreationTime, seed.CreationTime.ToUniversalTime().ToString(LanguagesManager.Instance.DateTime_StringFormat, System.Globalization.DateTimeFormatInfo.InvariantInfo))); if (!string.IsNullOrWhiteSpace(seed.Comment)) { builder.AppendLine(string.Format("{0}: {1}", LanguagesManager.Instance.Seed_Comment, seed.Comment)); } if (builder.Length != 0) { return(builder.ToString().Remove(builder.Length - 2)); } else { return(null); } } catch (Exception e) { throw new ArgumentException("ArgumentException", e); } }
protected override void ProtectedImport(Stream stream, BufferManager bufferManager, int count) { if (count > 256) { throw new ArgumentException(); } lock (this.ThisLock) { for (; ;) { byte id; { byte[] idBuffer = new byte[1]; if (stream.Read(idBuffer, 0, idBuffer.Length) != idBuffer.Length) { return; } id = idBuffer[0]; } int length; { byte[] lengthBuffer = new byte[4]; if (stream.Read(lengthBuffer, 0, lengthBuffer.Length) != lengthBuffer.Length) { return; } length = NetworkConverter.ToInt32(lengthBuffer); } using (RangeStream rangeStream = new RangeStream(stream, stream.Position, length, true)) { if (id == (byte)SerializeId.Name) { this.Name = ItemUtilities.GetString(rangeStream); } else if (id == (byte)SerializeId.CreationTime) { this.CreationTime = DateTime.ParseExact(ItemUtilities.GetString(rangeStream), "yyyy-MM-ddTHH:mm:ssZ", System.Globalization.DateTimeFormatInfo.InvariantInfo).ToUniversalTime(); } else if (id == (int)SerializeId.Comment) { this.Comment = ItemUtilities.GetString(rangeStream); } else if (id == (byte)SerializeId.Seed) { this.Seeds.Add(Seed.Import(rangeStream, bufferManager)); } else if (id == (byte)SerializeId.Box) { this.Boxes.Add(Box.Import(rangeStream, bufferManager, count + 1)); } else if (id == (byte)SerializeId.Certificate) { this.Certificate = Certificate.Import(rangeStream, bufferManager); } } } } }