Ejemplo n.º 1
0
        /// <summary>
        /// The SetJson.
        /// </summary>
        /// <param name="tmsg">The tmsg<see cref="DealMessage"/>.</param>
        /// <param name="tostream">The tostream<see cref="Stream"/>.</param>
        /// <returns>The <see cref="int"/>.</returns>
        public static int SetJson(this DealMessage tmsg, Stream tostream)
        {
            BinaryWriter binwriter = new BinaryWriter(tostream);

            binwriter.Write(tmsg.SetJsonString());
            return((int)tostream.Length);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// The SetJsonBag.
 /// </summary>
 /// <param name="tmsg">The tmsg<see cref="DealMessage"/>.</param>
 /// <returns>The <see cref="Dictionary{string, object}"/>.</returns>
 public static Dictionary <string, object> SetJsonBag(this DealMessage tmsg)
 {
     return(new Dictionary <string, object>()
     {
         { "DealMessage", JsonParserProperties.GetJsonProperties(typeof(DealMessage))
           .Select(k => new KeyValuePair <string, object>(k.Name, k.GetValue(tmsg, null)))
           .ToDictionary(k => k.Key, v => v.Value) }
     });
 }
Ejemplo n.º 3
0
        /// <summary>
        /// The SetBinary.
        /// </summary>
        /// <param name="bank">The bank<see cref="DealMessage"/>.</param>
        /// <param name="tostream">The tostream<see cref="Stream"/>.</param>
        /// <returns>The <see cref="int"/>.</returns>
        public static int SetBinary(this DealMessage bank, Stream tostream)
        {
            if (tostream == null)
            {
                tostream = new MemoryStream();
            }
            BinaryFormatter binform = new BinaryFormatter();

            binform.Serialize(tostream, bank);
            return((int)tostream.Length);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// The GetBinary.
 /// </summary>
 /// <param name="bank">The bank<see cref="DealMessage"/>.</param>
 /// <param name="fromstream">The fromstream<see cref="Stream"/>.</param>
 /// <returns>The <see cref="DealMessage"/>.</returns>
 public static DealMessage GetBinary(this DealMessage bank, Stream fromstream)
 {
     try
     {
         BinaryFormatter binform = new BinaryFormatter();
         return((DealMessage)binform.Deserialize(fromstream));
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// The GetJson.
 /// </summary>
 /// <param name="tmsg">The tmsg<see cref="DealMessage"/>.</param>
 /// <param name="jsonstring">The jsonstring<see cref="string"/>.</param>
 /// <returns>The <see cref="DealMessage"/>.</returns>
 public static DealMessage GetJson(this DealMessage tmsg, string jsonstring)
 {
     try
     {
         DealMessage trs = tmsg.GetJsonObject(jsonstring)["DealMessage"];
         return(trs);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// The SetBinary.
        /// </summary>
        /// <param name="bank">The bank<see cref="DealMessage"/>.</param>
        /// <param name="buffer">The buffer<see cref="ISerialBuffer"/>.</param>
        /// <returns>The <see cref="int"/>.</returns>
        public static int SetBinary(this DealMessage bank, ISerialBuffer buffer)
        {
            int          offset = buffer.BlockOffset;
            MemoryStream ms     = new MemoryStream();

            ms.Write(new byte[offset], 0, offset);
            BinaryFormatter binform = new BinaryFormatter();

            binform.Serialize(ms, bank);
            buffer.SerialBlock = ms.ToArray();
            ms.Dispose();
            return(buffer.SerialBlock.Length);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// The GetJson.
 /// </summary>
 /// <param name="tmsg">The tmsg<see cref="DealMessage"/>.</param>
 /// <param name="stringbuilder">The stringbuilder<see cref="StringBuilder"/>.</param>
 /// <returns>The <see cref="DealMessage"/>.</returns>
 public static DealMessage GetJson(this DealMessage tmsg, StringBuilder stringbuilder)
 {
     try
     {
         StringBuilder sb  = stringbuilder;
         DealMessage   trs = tmsg.GetJsonObject(sb.ToString())["DealMessage"];
         return(trs);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// The GetJsonObject.
        /// </summary>
        /// <param name="tmsg">The tmsg<see cref="DealMessage"/>.</param>
        /// <param name="_bag">The _bag<see cref="IDictionary{string, object}"/>.</param>
        /// <returns>The <see cref="Dictionary{string, DealMessage}"/>.</returns>
        public static Dictionary <string, DealMessage> GetJsonObject(this DealMessage tmsg, IDictionary <string, object> _bag)
        {
            Dictionary <string, DealMessage> result = new Dictionary <string, DealMessage>();
            IDictionary <string, object>     bags   = _bag;

            foreach (KeyValuePair <string, object> bag in bags)
            {
                object inst = new object();
                IEnumerable <PropertyInfo> map = JsonParser.PrepareInstance(out inst, typeof(DealMessage));
                JsonParser.DeserializeType(map, (IDictionary <string, object>)bag.Value, inst);
                DealMessage deck = (DealMessage)inst;
                result.Add(bag.Key, deck);
            }
            return(result);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// The GetBinary.
 /// </summary>
 /// <param name="bank">The bank<see cref="DealMessage"/>.</param>
 /// <param name="buffer">The buffer<see cref="ISerialBuffer"/>.</param>
 /// <returns>The <see cref="DealMessage"/>.</returns>
 public static DealMessage GetBinary(this DealMessage bank, ISerialBuffer buffer)
 {
     try
     {
         MemoryStream    ms      = new MemoryStream(buffer.DeserialBlock);
         BinaryFormatter binform = new BinaryFormatter();
         DealMessage     _bank   = (DealMessage)binform.Deserialize(ms);
         ms.Dispose();
         return(_bank);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="DealTransfer"/> class.
        /// </summary>
        /// <param name="identity">The identity<see cref="MemberIdentity"/>.</param>
        /// <param name="message">The message<see cref="object"/>.</param>
        /// <param name="context">The context<see cref="ITransferContext"/>.</param>
        public DealTransfer(MemberIdentity identity, object message = null, ITransferContext context = null)
        {
            Context = context;
            if (Context != null)
            {
                MyHeader = new DealHeader(this, Context, identity);
            }
            else
            {
                MyHeader = new DealHeader(this, identity);
            }

            Identity  = identity;
            Manager   = new TransferManager(this);
            MyMessage = new DealMessage(this, DirectionType.Send, message);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// The GetJson.
        /// </summary>
        /// <param name="tmsg">The tmsg<see cref="DealMessage"/>.</param>
        /// <param name="buffer">The buffer<see cref="ISerialBuffer"/>.</param>
        /// <returns>The <see cref="DealMessage"/>.</returns>
        public static DealMessage GetJson(this DealMessage tmsg, ISerialBuffer buffer)
        {
            try
            {
                DealMessage trs = null;

                byte[]        _fromarray = buffer.DeserialBlock;
                StringBuilder sb         = new StringBuilder();

                sb.Append(_fromarray.ToChars(CharEncoding.UTF8));
                trs = tmsg.GetJsonObject(sb.ToString())["DealMessage"];

                _fromarray = null;
                sb         = null;
                return(trs);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// The GetJson.
 /// </summary>
 /// <param name="tmsg">The tmsg<see cref="DealMessage"/>.</param>
 /// <param name="fromstream">The fromstream<see cref="Stream"/>.</param>
 /// <returns>The <see cref="DealMessage"/>.</returns>
 public static DealMessage GetJson(this DealMessage tmsg, Stream fromstream)
 {
     try
     {
         fromstream.Position = 0;
         byte[]        array = new byte[4096];
         int           read  = 0;
         StringBuilder sb    = new StringBuilder();
         while ((read = fromstream.Read(array, 0, array.Length)) > 0)
         {
             sb.Append(array.Cast <char>());
         }
         DealMessage trs = tmsg.GetJsonObject(sb.ToString())["DealMessage"];
         sb = null;
         fromstream.Dispose();
         return(trs);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Ejemplo n.º 13
0
 /// <summary>
 /// The SetJson.
 /// </summary>
 /// <param name="tmsg">The tmsg<see cref="DealMessage"/>.</param>
 /// <param name="stringbuilder">The stringbuilder<see cref="StringBuilder"/>.</param>
 /// <returns>The <see cref="int"/>.</returns>
 public static int SetJson(this DealMessage tmsg, StringBuilder stringbuilder)
 {
     stringbuilder.AppendLine(tmsg.SetJsonString());
     return(stringbuilder.Length);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DealTransfer"/> class.
 /// </summary>
 public DealTransfer()
 {
     MyHeader  = new DealHeader(this);
     Manager   = new TransferManager(this);
     MyMessage = new DealMessage(this, DirectionType.Send, null);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// The GetJsonBag.
 /// </summary>
 /// <param name="tmsg">The tmsg<see cref="DealMessage"/>.</param>
 /// <param name="JsonString">The JsonString<see cref="string"/>.</param>
 /// <param name="_bag">The _bag<see cref="IDictionary{string, object}"/>.</param>
 public static void GetJsonBag(this DealMessage tmsg, string JsonString, IDictionary <string, object> _bag)
 {
     _bag.Add(JsonParser.FromJson(JsonString));
 }
Ejemplo n.º 16
0
 /// <summary>
 /// The SetJsonString.
 /// </summary>
 /// <param name="tmsg">The tmsg<see cref="DealMessage"/>.</param>
 /// <param name="jsonbag">The jsonbag<see cref="IDictionary{string, object}"/>.</param>
 /// <returns>The <see cref="string"/>.</returns>
 public static string SetJsonString(this DealMessage tmsg, IDictionary <string, object> jsonbag)
 {
     return(JsonParser.ToJson(jsonbag));
 }
Ejemplo n.º 17
0
        /// <summary>
        /// The SetJsonString.
        /// </summary>
        /// <param name="tmsg">The tmsg<see cref="DealMessage"/>.</param>
        /// <returns>The <see cref="string"/>.</returns>
        public static string SetJsonString(this DealMessage tmsg)
        {
            IDictionary <string, object> toJson = tmsg.SetJsonBag();

            return(JsonParser.ToJson(toJson));
        }
Ejemplo n.º 18
0
 /// <summary>
 /// The SetJson.
 /// </summary>
 /// <param name="tmsg">The tmsg<see cref="DealMessage"/>.</param>
 /// <param name="buffer">The buffer<see cref="ISerialBuffer"/>.</param>
 /// <returns>The <see cref="int"/>.</returns>
 public static int SetJson(this DealMessage tmsg, ISerialBuffer buffer)
 {
     buffer.SerialBlock = Encoding.UTF8.GetBytes(tmsg.SetJsonString());
     return(buffer.SerialBlock.Length);
 }