public static MessageWrapper GetMessageWrapper(string source, MessageAction action, BaseMessage message, DateTime timeStamp) { MessageWrapper wrapper = new MessageWrapper(); wrapper.Action = action; wrapper.Time = string.Format("{0}:{1} {2}.{3}", timeStamp.Hour, timeStamp.Minute, timeStamp.Second, timeStamp.Millisecond); wrapper.Key = message.Key; wrapper.Source = source; if (_messageTranslators.ContainsKey(wrapper.Key)) { BaseMessage toUse = _messageTranslators[wrapper.Key](message); if (_messageWriter.ContainsKey(wrapper.Key)) { wrapper.Message = _messageWriter[wrapper.Key](toUse); } } return wrapper; }
public void ViewMessage(string source, MessageAction action, BaseMessage message, DateTime timeStamp) { MessageWrapper wrapper = MessageWrapper.GetMessageWrapper(source, action, message, timeStamp); _messages.Add(wrapper); }
private static string GetFileChunkMessage(BaseMessage message) { FileChunkMessage chunk = message as FileChunkMessage; return string.Format("File ({0}): Chunk {1} of {2} - Start {3} End {4}", chunk.Header.Hash, chunk.ChunkIndex + 1, chunk.Header.ChunkCount, chunk.IsStartChunk, chunk.IsEndChunk ); }
private static BaseMessage TranslateIdentificationMessage(BaseMessage message) { if (!(message is IdentificationMessage)) throw new InvalidOperationException(); if (message.MessageData == null || message.MessageData.Length == 0) return message; using(IdentificationMessage id = _protocol.TranslateMessage<IdentificationMessage>(message)) { return id; } }
private static BaseMessage TranslateFileRequestMessage(BaseMessage message) { if (!(message is FileRequestMessage)) throw new InvalidOperationException(); if (message.MessageData == null || message.MessageData.Length == 0) return message; using (FileRequestMessage request = _protocol.TranslateMessage<FileRequestMessage>(message)) { return request; } }
private static string GetIdentificationMessage(BaseMessage message) { if (!(message is IdentificationMessage)) throw new InvalidOperationException(); return string.Format("Server {0}, Client {1}, {2}:{3}", (message as IdentificationMessage).Client.ServerPublicName, (message as IdentificationMessage).Client.PublicName, (message as IdentificationMessage).Client.IPAddress, (message as IdentificationMessage).Client.Port); }
private static string GetFileRequestMessage(BaseMessage message) { FileRequestMessage request = message as FileRequestMessage; return string.Format("{0} - {1} ({2})", request.Header.Response, request.RequestedFile.FileName, request.Header.Id); }
private static string GetFileModificationMessage(BaseMessage message) { if (!(message is FileModificationMessage)) throw new InvalidOperationException(); StringBuilder builder = new StringBuilder(); builder.AppendLine(); foreach (FileModificationDescriptor modification in (message as FileModificationMessage).Modifications) { builder.AppendLine(string.Format("{0} {1}: {2}", modification.Mode, modification.Hash, modification.FileFullName)); } return builder.Length == 0 ? "No files listed" : builder.ToString(); }
private static string GetFileListMessage(BaseMessage message) { if (!(message is FileListMessage)) throw new InvalidOperationException(); StringBuilder builder = new StringBuilder(); if ((message as FileListMessage).FileList == null || (message as FileListMessage).FileList.Count == 0) return "No files available"; builder.AppendLine(); foreach (FileDescriptor file in (message as FileListMessage).FileList) { builder.AppendLine(string.Format("{0}: {1}", file.Hash, file.FileFullName)); } return builder.ToString(); }