Ejemplo n.º 1
0
        public object Deserialize(Stream stream, Type type)
        {
            var bytes = LZ4MessagePackSerializer.Decode(stream);

            using (var memStream = new MemoryStream(bytes))
            {
                return(_serializer.Deserialize(memStream));
            }
        }
Ejemplo n.º 2
0
        public void Decode()
        {
            var originalData = Enumerable.Range(1, 100).Select(x => new FirstSimpleData {
                Prop1 = x * x, Prop2 = "hoge", Prop3 = x
            }).ToArray();
            var simple  = LZ4MessagePackSerializer.Serialize(100);
            var complex = LZ4MessagePackSerializer.Serialize(originalData);

            var msgpack1 = LZ4MessagePackSerializer.Decode(simple);
            var msgpack2 = LZ4MessagePackSerializer.Decode(complex);

            MessagePackSerializer.Deserialize <int>(msgpack1).Is(100);
            MessagePackSerializer.Deserialize <FirstSimpleData[]>(msgpack2).IsStructuralEqual(originalData);
        }
Ejemplo n.º 3
0
        public int Process(Stream content)
        {
            var memory = new MemoryStream();

            content.CopyTo(memory);

            int result = -100;
            var bytes  = memory.ToArray();
            var json   = Encoding.UTF8.GetString(LZ4MessagePackSerializer.Decode(bytes));

            if (string.IsNullOrEmpty(json) || string.IsNullOrWhiteSpace(json))
            {
                return(result);
            }
            var resultStream = new MemoryStream();
            var package      = JsonConvert.DeserializeObject <HttpPipelinePackage>(json);
            var cryptorSql   = package.Sql;
            var sqlBytes     = Convert.FromBase64String(cryptorSql);

            MemoryStream ms  = new MemoryStream(sqlBytes);
            CryptoStream cst = new CryptoStream(ms, _cryptoTransform, CryptoStreamMode.Read);

            using (StreamReader sr = new StreamReader(cst))
            {
                var sql = sr.ReadToEnd();

                try
                {
                    switch (package.D)
                    {
                    case Database.MySql:
                    {
                        using (var conn = new MySqlConnection(Configuration.MySqlConnectionString))
                        {
                            if (package.Dt == null)
                            {
                                result = conn.Execute(sql);
                            }
                            else
                            {
                                result = conn.Execute(sql, package.Dt);
                            }
                        }
                        break;
                    }

                    default:
                    {
                        result = -100;
                        break;
                    }
                    }
                }
                catch (Exception e)
                {
                    Logger.LogError($"Pipeline execute failed {json}: {e}");
                    throw e;
                }
            }

            return(result);
        }