public static void SerializeObjectNameWithNoParent()
        {
            var objName = new ObjectName("name");

            var serializer = new BinarySerializer();
            byte[] bytes;

            using (var memoryStream = new MemoryStream()) {
                serializer.Serialize(memoryStream, objName);
                memoryStream.Flush();
                bytes = memoryStream.ToArray();
            }

            object graph = null;
            using (var memoryStream = new MemoryStream(bytes)) {
                graph = serializer.Deserialize(memoryStream, typeof(ObjectName));
            }

            Assert.IsNotNull(graph);
            Assert.IsInstanceOf<ObjectName>(graph);

            var objName2 = (ObjectName) graph;
            Assert.AreEqual(objName.Name, objName2.Name);
            Assert.AreEqual(objName, objName2);
        }
        public static void SerializeImplicit()
        {
            var obj = new TestClass2("test2");

            var serializer = new BinarySerializer();
            byte[] bytes;

            using (var memoryStream = new MemoryStream()) {
                serializer.Serialize(memoryStream, obj);
                memoryStream.Flush();
                bytes = memoryStream.ToArray();
            }

            object graph = null;
            using (var memoryStream = new MemoryStream(bytes)) {
                graph = serializer.Deserialize(memoryStream, typeof(TestClass2));
            }

            Assert.IsNotNull(graph);
            Assert.IsInstanceOf<TestClass2>(obj);

            obj = (TestClass2) graph;
            Assert.AreEqual("test2", obj.Value);
            Assert.IsNull(obj.Parent);
        }
Exemplo n.º 3
0
 public static SqlBinary AsBinary(this IQueryPlanNode planNode)
 {
     using (var memoryStream = new MemoryStream()) {
         var serializaer = new BinarySerializer();
         serializaer.Serialize(memoryStream, planNode);
         memoryStream.Flush();
         return new SqlBinary(memoryStream.ToArray());
     }
 }
Exemplo n.º 4
0
        public static void Serialize()
        {
            var obj = Type.NewObject(SqlExpression.Constant(34));

            var serializer = new BinarySerializer();
            var stream = new MemoryStream();
            serializer.Serialize(stream, obj);

            stream.Flush();

            stream.Seek(0, SeekOrigin.Begin);

            var serialized = (SqlUserObject) serializer.Deserialize(stream);

            Assert.IsNotNull(serialized);
            Assert.IsTrue(obj.Equals(serialized));
        }
Exemplo n.º 5
0
 private static IQueryPlanNode DeserializePlan(Type nodeType, BinaryReader reader)
 {
     var serializer = new BinarySerializer();
     return (IQueryPlanNode) serializer.Deserialize(reader, nodeType);
 }
Exemplo n.º 6
0
 private static void SerializePlan(IQueryPlanNode queryPlan, BinaryWriter writer)
 {
     var serializer = new BinarySerializer();
     serializer.Serialize(writer, queryPlan);
 }
Exemplo n.º 7
0
        private static void SerializeValue(BinaryWriter writer, Encoding encoding, Type type, object value)
        {
            var typeCode = GetTypeCode(type);
            if (typeCode == null)
                throw new NotSupportedException(String.Format("The type '{0}' is not supported.", type));

            var nullCheck = value == null;

            writer.Write(typeCode.Value);
            writer.Write(nullCheck);

            if (value == null)
                return;

            if (typeCode == ArrayType) {
                var typeString = type.GetElementType().FullName;
                writer.Write(typeString);

                var array = (Array) value;
                var arrayLength = array.Length;
                var arrayType = type.GetElementType();

                writer.Write(arrayLength);

                for (int i = 0; i < arrayLength; i++) {
                    var element = array.GetValue(i);
                    SerializeValue(writer, encoding, arrayType, element);
                }
            } else if (typeCode == ObjectType) {
                var realType = value.GetType();
                writer.Write(realType.FullName);

                var serializer = new BinarySerializer {Encoding = encoding};
                serializer.Serialize(writer, value);
            } else if (typeCode == BooleanType) {
                writer.Write((bool) value);
            } else if (typeCode == ByteType) {
                writer.Write((byte) value);
            } else if (typeCode == Int16Type) {
                writer.Write((short) value);
            } else if (typeCode == Int32Type) {
                writer.Write((int) value);
            } else if (typeCode == Int64Type) {
                writer.Write((long) value);
            } else if (typeCode == SingleType) {
                writer.Write((float) value);
            } else if (typeCode == DoubleType) {
                writer.Write((double) value);
            } else if (typeCode == StringType) {
                writer.Write((string) value);
            }
        }
Exemplo n.º 8
0
        private static object ReadObject(BinaryReader reader, Encoding encoding)
        {
            var objType = ReadType(reader);
            var serializer = new BinarySerializer {
                Encoding = encoding
            };

            return serializer.Deserialize(reader, objType);
        }
Exemplo n.º 9
0
 public static ViewInfo Deserialize(Stream stream)
 {
     var serializer = new BinarySerializer();
     return (ViewInfo) serializer.Deserialize(stream, typeof (ViewInfo));
 }
Exemplo n.º 10
0
        private static void SerializeValue(BinaryWriter writer, Encoding encoding, Type type, object value)
        {
            var typeCode = GetTypeCode(type);

            if (typeCode == null)
            {
                throw new NotSupportedException(String.Format("The type '{0}' is not supported.", type));
            }

            WriteValueHead(writer, typeCode.Value, type, value);

            if (value == null)
            {
                return;
            }

            if (typeCode == ArrayType)
            {
                var array       = (Array)value;
                var arrayLength = array.Length;
                var arrayType   = type.GetElementType();

                for (int i = 0; i < arrayLength; i++)
                {
                    var element = array.GetValue(i);
                    SerializeValue(writer, encoding, arrayType, element);
                }
            }
            else if (typeCode == ObjectType)
            {
                var serializer = new BinarySerializer {
                    Encoding = encoding
                };
                serializer.Serialize(writer, value);
            }
            else if (typeCode == BooleanType)
            {
                writer.Write((bool)value);
            }
            else if (typeCode == ByteType)
            {
                writer.Write((byte)value);
            }
            else if (typeCode == Int16Type)
            {
                writer.Write((short)value);
            }
            else if (typeCode == Int32Type)
            {
                writer.Write((int)value);
            }
            else if (typeCode == Int64Type)
            {
                writer.Write((long)value);
            }
            else if (typeCode == SingleType)
            {
                writer.Write((float)value);
            }
            else if (typeCode == DoubleType)
            {
                writer.Write((double)value);
            }
            else if (typeCode == StringType)
            {
                writer.Write((string)value);
            }
        }
Exemplo n.º 11
0
        private static byte[] SerializeArguments(TriggerArgument args)
        {
            using (var stream = new MemoryStream()) {
                var serializer = new BinarySerializer();
                serializer.Serialize(stream, args);

                stream.Flush();

                return stream.ToArray();
            }
        }
Exemplo n.º 12
0
 internal static void Serialize(SqlExpression expression, BinaryWriter writer)
 {
     var serializer = new BinarySerializer();
     serializer.Serialize(writer, expression);
 }
Exemplo n.º 13
0
 internal static SqlExpression Deserialize(BinaryReader reader)
 {
     var serializer = new BinarySerializer();
     return (SqlExpression) serializer.Deserialize(reader, typeof(SqlExpression));
 }
Exemplo n.º 14
0
        protected T BinaryDeserialize <T>(Stream stream) where T : class
        {
            var serializer = new BinarySerializer();

            return((T)serializer.Deserialize(stream));
        }
Exemplo n.º 15
0
 public static ViewInfo FromBinary(ISqlBinary binary)
 {
     using (var stream = binary.GetInput()) {
         var serializer = new BinarySerializer();
         return (ViewInfo) serializer.Deserialize(stream);
     }
 }
Exemplo n.º 16
0
        public SqlBinary AsBinary()
        {
            using (var stream = new MemoryStream()) {
                var serializer = new BinarySerializer();
                serializer.Serialize(stream, this);
                stream.Flush();

                var data = stream.ToArray();
                return new SqlBinary(data);
            }
        }
Exemplo n.º 17
0
 private static InvokeArgument[] DeserializeArguments(byte[] bytes)
 {
     using (var stream = new MemoryStream(bytes)) {
         var serializer = new BinarySerializer();
         var args = (TriggerArgument) serializer.Deserialize(stream);
         return args.Arguments;
     }
 }
Exemplo n.º 18
0
 public static void Serialize(ViewInfo viewInfo, BinaryWriter writer)
 {
     var serializer = new BinarySerializer();
     serializer.Serialize(writer, viewInfo);
 }
Exemplo n.º 19
0
        //public static void Serialize(ViewInfo viewInfo, BinaryWriter writer) {
        //    TableInfo.Serialize(viewInfo.TableInfo, writer);
        //    SqlExpression.Serialize(viewInfo.QueryExpression, writer);
        //    var queryPlanType = viewInfo.QueryPlan.GetType();
        //    writer.Write(queryPlanType.FullName);
        //    QueryPlanSerializers.Serialize(viewInfo.QueryPlan, writer);
        //}
        //public static ViewInfo Deserialize(Stream stream, ITypeResolver resolver) {
        //    var reader = new BinaryReader(stream, Encoding.Unicode);
        //    return Deserialize(reader, resolver);
        //}
        //public static ViewInfo Deserialize(BinaryReader reader, ITypeResolver typeResolver) {
        //    var tableInfo = TableInfo.Deserialize(reader, typeResolver);
        //    var expression = SqlExpression.Deserialize(reader);
        //    if (!(expression is SqlQueryExpression))
        //        throw new InvalidOperationException();
        //    var queryExpression = (SqlQueryExpression) expression;
        //    var queryPlanTypeString = reader.ReadString();
        //    var queryPlanType = Type.GetType(queryPlanTypeString, true);
        //    var queryPlan = QueryPlanSerializers.Deserialize(queryPlanType, reader);
        //    return new ViewInfo(tableInfo, queryExpression, queryPlan);
        //}
        public SqlBinary AsBinary()
        {
            using (var stream = new MemoryStream()) {
                using (var writer = new BinaryWriter(stream, Encoding.Unicode)) {
                    var serializer = new BinarySerializer();
                    serializer.Serialize(writer, this);
                    writer.Flush();
                }

                var data = stream.ToArray();
                return new SqlBinary(data);
            }
        }
Exemplo n.º 20
0
        protected T BinaryDeserialize <T>(Stream stream) where T : class
        {
            var serializer = new BinarySerializer();

            return(serializer.Deserialize(stream, typeof(T)) as T);
        }