Exemplo n.º 1
0
        public T Call <T>(MQMessage sendMsg, int timeoutMilliseconds) where T : class
        {
            bool flag = false;
            Type type = typeof(T);

            T local = default(T);

            object obj2 = this._LockObj;

            lock (obj2)
            {
                this.Send(sendMsg);
                DataItem <MQMessage> item = this._lstDeviceDataQueue.Pull(f => f.Data != null && f.Data.MsgId == sendMsg.MsgId, TimeSpan.FromMilliseconds((double)timeoutMilliseconds));
                if (((item != null) && (item.Data != null)) && (item.Data.Body != null))
                {
                    if (flag)
                    {
                        local = Encoding.UTF8.GetString(item.Data.Body) as T;
                    }
                    else
                    {
                        local = SerializationUtility.BytesToObject <T>(item.Data.Body);
                    }
                }
                return(local);
            }
        }
Exemplo n.º 2
0
        public static MQMessage ToMessage(this byte[] data)
        {
            MQMessage message;

            if (data == null)
            {
                return(null);
            }
            else
            {
                message = SerializationUtility.BytesToObject <MQMessage>(data);
            }
            return(message);
        }
        public ConfigurationBase Get(string configKey, Type configType)
        {
            string configFileName = Path.Combine(ConfigDirectoryBase, configKey + ".cfg");

            if (!File.Exists(configFileName))
            {
                return(null);
            }

            object configObject = null;

            using (FileStream fileStream = new FileStream(configFileName, FileMode.Open, FileAccess.Read))
            {
                configObject = SerializationUtility.BytesToObject(fileStream);
            }

            return(configObject as ConfigurationBase);
        }
Exemplo n.º 4
0
        public T Call <T>(object sendObj, int timeoutMilliseconds) where T : class
        {
            bool flag = false;
            Type type = typeof(T);

            if (type.Name.Equals("string", (StringComparison)StringComparison.OrdinalIgnoreCase))
            {
                flag = true;
            }
            byte[] bytes = null;
            if (flag)
            {
                bytes = Encoding.UTF8.GetBytes((string)((string)sendObj));
            }
            else
            {
                bytes = SerializationUtility.ToBytes(sendObj);
            }
            T         local      = default(T);
            MQMessage requestMsg = new MQMessage();
            object    obj2       = this._LockObj;

            lock (obj2)
            {
                requestMsg.Body  = bytes;
                requestMsg.MsgId = IdentityHelper.NewSequentialGuid().ToString("N");

                this.Send(requestMsg);
                DataItem <MQMessage> item = this._lstDeviceDataQueue.Pull(f => f.Data != null && f.Data.MsgId == requestMsg.MsgId, TimeSpan.FromMilliseconds((double)timeoutMilliseconds));
                if (((item != null) && (item.Data != null)) && (item.Data.Body != null))
                {
                    if (flag)
                    {
                        local = Encoding.UTF8.GetString(item.Data.Body) as T;
                    }
                    else
                    {
                        local = SerializationUtility.BytesToObject <T>(item.Data.Body);
                    }
                }
                return(local);
            }
        }