public string SavePersonImage( Google.Protobuf.ByteString bytes, long personid) { string filename = DateTime.Now.Ticks.ToString() + ".jpg"; string localPath = String.Format("media\\person\\{0}\\photo\\{1}", personid, filename ); string fullPath = String.Format("{0}{1}", LocalStorage, localPath ); SaveFile(bytes.ToByteArray(), fullPath); return localPath; }
public void SendProtobuf(Google.ProtocolBuffers.IMessage message, PACKET_TYPE packet_type) { if (m_socket == null || m_socket.Connected == false) { Disconnect(); return; } byte[] type_bytes = BitConverter.GetBytes((int)packet_type); byte[] packet_buffer = message.ToByteArray(); int size = packet_buffer.Length; byte[] size_bytes = BitConverter.GetBytes(size); int buf_size = packet_buffer.Length + size_bytes.Length + type_bytes.Length; byte[] send_buf = new byte[buf_size]; System.Buffer.BlockCopy(size_bytes, 0, send_buf, 0, size_bytes.Length); System.Buffer.BlockCopy(type_bytes, 0, send_buf, size_bytes.Length, type_bytes.Length); System.Buffer.BlockCopy(packet_buffer, 0, send_buf, size_bytes.Length + type_bytes.Length, packet_buffer.Length); m_socket.Send(send_buf); // Console.WriteLine("Send len({0}) = header({1} + {2}) + body({3})", buf_size, size_bytes.Length, type_bytes.Length, packet_buffer.Length); }
/// <summary> /// Prepares the Protobuf message for sending via Cometd. /// </summary> /// <param name="message">Google ProtocolBuffers message</param> /// <returns>A dictionary with two elements.</returns> public static Dictionary<string, Object> prepareMessage(Google.ProtocolBuffers.IMessage message) { Dictionary<string, Object> output = new Dictionary<string, Object>(); if (message != null) { output.Add("type", message.GetType().ToString()); output.Add("s", Convert.ToBase64String(message.ToByteArray())); } return output; }