public static DealHeader GetJson(this DealHeader thdr, ref object fromarray)
        {
            try
            {
                DealHeader trs = null;
                if (fromarray is String)
                {
                    trs = thdr.GetJsonObject((String)fromarray)["DealHeader"];
                }
                else
                {
                    byte[]        _fromarray = (byte[])fromarray;
                    StringBuilder sb         = new StringBuilder();

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

                    fromarray  = null;
                    _fromarray = null;
                    sb         = null;
                }
                return(trs);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public static int SetJson(this DealHeader thdr, Stream tostream)
        {
            BinaryWriter binwriter = new BinaryWriter(tostream);

            binwriter.Write(thdr.SetJsonString());
            return((int)tostream.Length);
        }
        private void CltRecHead(ref object array)
        {
            DealHeader headerObject = (DealHeader)transaction.MyHeader.Deserialize(ref array);

            if (headerObject != null)
            {
                transaction.HeaderReceived = headerObject;

                transaction.MyHeader.Context.Identity.Key    = null;
                transaction.MyHeader.Context.Identity.Name   = null;
                transaction.MyHeader.Context.Identity.UserId = transaction.HeaderReceived.Context.Identity.UserId;
                transaction.MyHeader.Context.Identity.Token  = transaction.HeaderReceived.Context.Identity.Token;
                transaction.MyHeader.Context.Identity.DeptId = transaction.HeaderReceived.Context.Identity.DeptId;

                object reciveContent = transaction.HeaderReceived.Content;

                Type[] ifaces = reciveContent.GetType().GetInterfaces();
                if (ifaces.Contains(typeof(IFigureFormatter)) && ifaces.Contains(typeof(IDealSource)))
                {
                    if (transaction.MyHeader.Content == null)
                    {
                        transaction.MyHeader.Content = ((IDealSource)reciveContent).Locate();
                    }

                    object myContent = transaction.MyHeader.Content;

                    ((IDealSource)myContent).Impact(reciveContent);

                    int objectCount = transaction.HeaderReceived.Context.ObjectsCount;
                    if (objectCount == 0)
                    {
                        vsspContext.ReceiveMessage = false;
                    }
                    else
                    {
                        transaction.MessageReceived = new DealMessage(transaction, DirectionType.Receive, myContent);
                    }
                }
                else if (reciveContent is Hashtable)
                {
                    Hashtable hashTable = (Hashtable)reciveContent;
                    if (hashTable.Contains("Register"))
                    {
                        vsspContext.Denied = !(bool)hashTable["Register"];
                        if (vsspContext.Denied)
                        {
                            vsspContext.Close          = true;
                            vsspContext.ReceiveMessage = false;
                            vsspContext.SendMessage    = false;
                        }
                    }
                }
                else
                {
                    vsspContext.SendMessage = false;
                }
            }
        }
 public static IDictionary <string, object> SetJsonBag(this DealHeader thdr)
 {
     return(new Dictionary <string, object>()
     {
         { "DealHeader", JsonParserProperties.GetJsonProperties(typeof(DealHeader), thdr.Context.Complexity)
           .Select(k => new KeyValuePair <string, object>(k.Name, k.GetValue(thdr, null)))
           .ToDictionary(k => k.Key, v => v.Value) }
     });
 }
        public static int SetRaw(this DealHeader bank, Stream tostream)
        {
            if (tostream == null)
            {
                tostream = new MemoryStream();
            }
            BinaryFormatter binform = new BinaryFormatter();

            binform.Serialize(tostream, bank);
            return((int)tostream.Length);
        }
 public static DealHeader GetJson(this DealHeader thdr, string jsonstring)
 {
     try
     {
         DealHeader trs = thdr.GetJsonObject(jsonstring)["DealHeader"];
         return(trs);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
 public static DealHeader GetRaw(this DealHeader bank, Stream fromstream)
 {
     try
     {
         BinaryFormatter binform = new BinaryFormatter();
         return((DealHeader)binform.Deserialize(fromstream));
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
        public static int SetRaw(this DealHeader bank, IFigurePacket tostream)
        {
            MemoryStream ms = new MemoryStream();

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

            binform.Serialize(ms, bank);
            tostream.SerialPacket = ms.ToArray();
            ms.Dispose();
            return(tostream.SerialPacket.Length);
        }
 public static DealHeader GetJson(this DealHeader thdr, StringBuilder stringbuilder)
 {
     try
     {
         StringBuilder sb  = stringbuilder;
         DealHeader    trs = thdr.GetJsonObject(sb.ToString())["DealHeader"];
         return(trs);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
        public static Dictionary <string, DealHeader> GetJsonObject(this DealHeader thdr, IDictionary <string, object> _bag)
        {
            Dictionary <string, DealHeader> result = new Dictionary <string, DealHeader>();
            IDictionary <string, object>    bags   = _bag;

            foreach (KeyValuePair <string, object> bag in bags)
            {
                object inst = new object();
                IEnumerable <PropertyInfo> map = JsonParser.PrepareInstance(out inst, typeof(DealHeader));
                JsonParser.DeserializeType(map, (IDictionary <string, object>)bag.Value, inst);
                DealHeader deck = (DealHeader)inst;
                result.Add(bag.Key, deck);
            }
            return(result);
        }
 public static DealHeader GetRaw(this DealHeader bank, ref object fromarray)
 {
     try
     {
         MemoryStream    ms      = new MemoryStream((byte[])fromarray);
         BinaryFormatter binform = new BinaryFormatter();
         DealHeader      _bank   = (DealHeader)binform.Deserialize(ms);
         ms.Dispose();
         return(_bank);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Beispiel #12
0
        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);
        }
        public static int SetJson(this DealHeader thdr, IFigurePacket buffor, int offset = 0)
        {
            if (offset > 0)
            {
                byte[] jsonBytes   = Encoding.UTF8.GetBytes(thdr.SetJsonString());
                byte[] serialBytes = new byte[jsonBytes.Length + offset];
                jsonBytes.CopyTo(serialBytes, offset);
                buffor.SerialPacket = serialBytes;
                jsonBytes           = null;
            }
            else
            {
                buffor.SerialPacket = Encoding.UTF8.GetBytes(thdr.SetJsonString());
            }

            return(buffor.SerialPacket.Length);
        }
 public static DealHeader GetJson(this DealHeader thdr, 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.Select(b => (char)b).ToArray());
         }
         DealHeader trs = thdr.GetJsonObject(sb.ToString())["DealHeader"];
         sb = null;
         fromstream.Dispose();
         return(trs);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
        private bool SrvRecPostDealHeader(ref object array, int objcount)
        {
            bool   isError      = false;
            string errorMessage = "";

            try
            {
                DealHeader headerObject = (DealHeader)transaction.MyHeader.Deserialize(ref array, FigureFormat.Json);
                headerObject.Context.Identity.Ip = transaction.MyHeader.Context.RemoteEndPoint.Address.ToString();
                if (DealServer.Security.Register(headerObject.Context.Identity, true))
                {
                    transaction.HeaderReceived = (headerObject != null) ? headerObject : null;
                    transaction.MyHeader.Context.Complexity = headerObject.Context.Complexity;
                    transaction.MyHeader.Context.Identity   = headerObject.Context.Identity;

                    if (headerObject.Context.ContentType != null)
                    {
                        object instance = new object();
                        JsonParser.PrepareInstance(out instance, headerObject.Context.ContentType);
                        object content = headerObject.Content;
                        object result  = ((IFigureFormatter)instance).Deserialize(ref content, FigureFormat.Json);
                        transaction.HeaderReceived.Content = result;
                        object _content = transaction.HeaderReceived.Content;

                        Type[] ifaces = _content.GetType().GetInterfaces();
                        if (ifaces.Contains(typeof(IFigureFormatter)) && ifaces.Contains(typeof(IDealSource)))
                        {
                            int objectCount = objcount;

                            object myheader = ((IDealSource)_content).Locate();

                            //Settings clientConfig = ((ISettings)_content).Config;

                            if (myheader != null)
                            {
                                if (objectCount == 0)
                                {
                                    vsspContext.ReceiveMessage = false;

                                    //if (clientConfig.DealerId.IsNotEmpty)
                                    //    transaction.MyHeader.Content = ((IDealSource)myheader).Impact(_content);
                                    //else
                                    //{
                                    //  ((ISettings)myheader).State.Expeled = true;
                                    transaction.MyHeader.Content = myheader;
                                    // }
                                }
                                else
                                {
                                    transaction.MyHeader.Content = ((IDealSource)myheader).Impact(_content);
                                    transaction.MessageReceived  = new DealMessage(transaction, DirectionType.Receive, transaction.MyHeader.Content);
                                }
                            }
                            else
                            {
                                isError       = true;
                                errorMessage += "Prime not exist - incorrect object target ";
                            }
                        }
                        else
                        {
                            isError       = true;
                            errorMessage += "Incorrect DPOT object - deserialization error ";
                        }
                    }
                    else
                    {
                        transaction.MyHeader.Content = new Hashtable()
                        {
                            { "Register", true }
                        };
                        transaction.MyHeader.Context.Echo += "Registration success - ContentType: null ";
                    }
                }
                else
                {
                    isError = true;
                    transaction.MyHeader.Content = new Hashtable()
                    {
                        { "Register", false }
                    };
                    transaction.MyHeader.Context.Echo += "Registration failed - access denied ";
                }
            }
            catch (Exception ex)
            {
                isError       = true;
                errorMessage += ex.ToString();
            }

            if (isError)
            {
                transaction.Context.SendMessage = false;
                if (errorMessage != "")
                {
                    transaction.MyHeader.Content      += errorMessage;
                    transaction.MyHeader.Context.Echo += errorMessage;
                }
                transaction.MyHeader.Context.Errors++;
            }
            return(isError);
        }
 public static int SetJson(this DealHeader thdr, StringBuilder stringbuilder)
 {
     stringbuilder.AppendLine(thdr.SetJsonString());
     return(stringbuilder.Length);
 }
 public static void GetJsonBag(this DealHeader thdr, string JsonString, IDictionary <string, object> _bag)
 {
     _bag.AddRange(JsonParser.FromJson(JsonString));
 }
Beispiel #18
0
 public DealTransfer()
 {
     MyHeader  = new DealHeader(this);
     Manager   = new TransferManager(this);
     MyMessage = new DealMessage(this, DirectionType.Send, null);
 }
 public static string SetJsonString(this DealHeader thdr, IDictionary <string, object> jsonbag)
 {
     return(JsonParser.ToJson(jsonbag, thdr.Context.Complexity));
 }
        public static string SetJsonString(this DealHeader thdr)
        {
            IDictionary <string, object> toJson = thdr.SetJsonBag();

            return(JsonParser.ToJson(toJson, thdr.Context.Complexity));
        }
        private void SrvRecHead(ref object array)
        {
            bool   isError      = false;
            string errorMessage = "";

            try
            {
                DealHeader headerObject = (DealHeader)transaction.MyHeader.Deserialize(ref array);
                if (headerObject != null)
                {
                    transaction.HeaderReceived = headerObject;

                    if (DealServer.Security.Register(transaction.HeaderReceived.Context.Identity, true))
                    {
                        transaction.MyHeader.Context.Identity.UserId = transaction.HeaderReceived.Context.Identity.UserId;
                        transaction.MyHeader.Context.Identity.Token  = transaction.HeaderReceived.Context.Identity.Token;
                        transaction.MyHeader.Context.Identity.DeptId = transaction.HeaderReceived.Context.Identity.DeptId;

                        if (transaction.HeaderReceived.Context.ContentType != null)
                        {
                            object _content = transaction.HeaderReceived.Content;
                            //((ISettings)_content).State.Synced = false;

                            Type[] ifaces = _content.GetType().GetInterfaces();
                            if (ifaces.Contains(typeof(IFigureFormatter)) && ifaces.Contains(typeof(IDealSource)))
                            {
                                int objectCount = transaction.HeaderReceived.Context.ObjectsCount;
                                vsspContext.Synchronic = transaction.HeaderReceived.Context.Synchronic;

                                object myheader = ((IDealSource)_content).Locate();

                                if (myheader != null)
                                {
                                    if (objectCount == 0)
                                    {
                                        vsspContext.ReceiveMessage = false;

                                        //if (((ISettings)_content).Config.DealerId.IsNotEmpty)
                                        //    transaction.MyHeader.Content = ((IDealSource)myheader).Impact(_content);
                                        //else
                                        //{
                                        //    ((ISettings)myheader).State.Expeled = true;
                                        transaction.MyHeader.Content = myheader;
                                        // }
                                    }
                                    else
                                    {
                                        transaction.MyHeader.Content = ((IDealSource)myheader).Impact(_content);
                                        transaction.MessageReceived  = new DealMessage(transaction, DirectionType.Receive, transaction.MyHeader.Content);
                                    }
                                }
                                else
                                {
                                    isError       = true;
                                    errorMessage += "Prime not exist - incorrect object target ";
                                }
                            }
                            else
                            {
                                isError       = true;
                                errorMessage += "Incorrect DPOT object - deserialization error ";
                            }
                        }
                        else
                        {
                            transaction.MyHeader.Content = new Hashtable()
                            {
                                { "Register", true }
                            };
                            transaction.MyHeader.Context.Echo += "Registration success - ContentType: null ";
                        }
                    }
                    else
                    {
                        isError = true;
                        transaction.MyHeader.Content = new Hashtable()
                        {
                            { "Register", false }
                        };
                        transaction.MyHeader.Context.Echo += "Registration failed - access denied ";
                    }
                }
                else
                {
                    isError       = true;
                    errorMessage += "Incorrect DPOT object - deserialization error ";
                }
            }
            catch (Exception ex)
            {
                isError       = true;
                errorMessage += ex.ToString();
            }

            if (isError)
            {
                transaction.Context.Close          = true;
                transaction.Context.ReceiveMessage = false;
                transaction.Context.SendMessage    = false;

                if (errorMessage != "")
                {
                    transaction.MyHeader.Content      += errorMessage;
                    transaction.MyHeader.Context.Echo += errorMessage;
                }
                transaction.MyHeader.Context.Errors++;
            }
        }