Exemplo n.º 1
0
 public static IVisNode DeSerializeFromFile(string fn)
 {
     var x = new Polenter.Serialization.SharpSerializer();
     //XmlSerializer x = new XmlSerializer(typen);
     FileStream fs = new FileStream(fn, FileMode.Open);
     var n = (IVisNode)x.Deserialize(fs);
     fs.Close();
     return n;
 }
        public object DeserializeReply(Message message, object[] parameters)
        {
            Polenter.Serialization.SharpSerializer serializer = new Polenter.Serialization.SharpSerializer(true);

            using (var inStream = GetBodyInnerContentStream(message))
            {
                return serializer.Deserialize(DecompressStream(inStream, true));
            }
        }
 public void DeserializeRequest(System.ServiceModel.Channels.Message message, object[] parameters)
 {
     Polenter.Serialization.SharpSerializer serializer = new Polenter.Serialization.SharpSerializer(true);
     using (var inStream = GetBodyInnerContentStream(message))
     {
         for (int i = 0; i < parameters.Length; i++)
         {
             parameters[i] = serializer.Deserialize(inStream);
         }
     }
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="person"></param>
        public static void SerializeSharpSerializerXml(Person p)
        {
            // create instance of sharpSerializer
            // true - binary serialization, false - xml serialization
            var serializer = new Polenter.Serialization.SharpSerializer(false);

            // serialize
            serializer.Serialize(p, Path.Combine(path_root, "Person.SharpSerializer.xml"));

            return;
        }
Exemplo n.º 5
0
 public Client(string name, bool IsLocalClient)
 {
     this.IsLocalClient = IsLocalClient;
     serializer = new Polenter.Serialization.SharpSerializer(false);
     deserializer = new Polenter.Serialization.SharpSerializer(false);
     socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     entityMulti = new EntityMulti();
     OtherPlayers = new List<EntityMulti>();
     this.name = name;
     entityMulti.name = name;
 }
Exemplo n.º 6
0
 public Client(string name, bool IsLocalClient)
 {
     this.IsLocalClient = IsLocalClient;
     serializer         = new Polenter.Serialization.SharpSerializer(false);
     deserializer       = new Polenter.Serialization.SharpSerializer(false);
     socket             = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     entityMulti        = new EntityMulti();
     OtherPlayers       = new List <EntityMulti>();
     this.name          = name;
     entityMulti.name   = name;
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="person"></param>
        public static void SerializeSharpSerializerXml(Person p)
        {
            // create instance of sharpSerializer
            // true - binary serialization, false - xml serialization
            var serializer = new Polenter.Serialization.SharpSerializer(false);

            // serialize
            serializer.Serialize(p, Path.Combine(path_root, "Person.SharpSerializer.xml"));

            return;
        }
Exemplo n.º 8
0
 public ServeurClient(Socket socket, Serveur server)
 {
     this.socket  = socket;
     this.server  = server;
     stream       = new NetworkStream(socket);
     streamReader = new StreamReader(stream);
     streamWriter = new StreamWriter(stream);
     serializer   = new Polenter.Serialization.SharpSerializer(false);
     deserializer = new Polenter.Serialization.SharpSerializer(false);
     playerMul    = new EntityMulti();
     t_receive    = new Thread(Receive);
     t_receive.Start();
 }
        public static Person DeserializeSharpSerializerXml()
        {
            Person p = default(Person);

            // create instance of sharpSerializer
            // true - binary serialization, false - xml serialization
            var serializer = new Polenter.Serialization.SharpSerializer(false);

            // deserialize
            p = (Person)serializer.Deserialize(Path.Combine(path_root, "Person.SharpSerializer.xml"));

            return(p);
        }
        public static Person DeserializeSharpSerializerXml()
        {
            Person p = default(Person);

            // create instance of sharpSerializer
            // true - binary serialization, false - xml serialization
            var serializer = new Polenter.Serialization.SharpSerializer(false);

            // deserialize
            p = (Person)serializer.Deserialize(Path.Combine(path_root, "Person.SharpSerializer.xml"));

            return p;
        }
Exemplo n.º 11
0
 public ServeurClient(Socket socket, Serveur server)
 {
     this.socket = socket;
     this.server = server;
     stream = new NetworkStream(socket);
     streamReader = new StreamReader(stream);
     streamWriter = new StreamWriter(stream);
     serializer = new Polenter.Serialization.SharpSerializer(false);
     deserializer = new Polenter.Serialization.SharpSerializer(false);
     playerMul = new EntityMulti();
     t_receive = new Thread(Receive);
     t_receive.Start();
 }
Exemplo n.º 12
0
        public virtual void Serialize <T>(T data, Stream stream, bool binaryMode = false) where T : class
        {
            var sharpSerializer = new Polenter.Serialization.SharpSerializer(binaryMode);

            try
            {
                IsActive = true;

                sharpSerializer.Serialize(data, stream);
            }
            finally
            {
                IsActive = false;
            }
        }
Exemplo n.º 13
0
        public virtual object Deserialize(Stream stream, bool binaryMode = false)
        {
            var sharpSerializer = new Polenter.Serialization.SharpSerializer(binaryMode);

            object result = null;

            try
            {
                IsActive = true;

                result = sharpSerializer.Deserialize(stream);
            }
            finally
            {
                IsActive = false;
            }

            return(result);
        }
Exemplo n.º 14
0
        public virtual T Deserialize <T>(Stream stream, bool binaryMode = false) where T : class
        {
            var sharpSerializer = new Polenter.Serialization.SharpSerializer(binaryMode);

            T result = default(T);

            try
            {
                IsActive = true;

                result = sharpSerializer.Deserialize(stream) as T;
            }
            finally
            {
                IsActive = false;
            }

            return(result);
        }
Exemplo n.º 15
0
        public static bool ObjectSerialize(string fileName, object obj, bool isEncrypt = false, int backupSec = 0)
        {
            bool result = false;

            try
            {
                DateTime fileUpdateTime = DateTime.MinValue;
                string   filePath       = LkCommonUtil.GetFilePath(Path.Combine(DefaultDirectory, fileName));
                if (File.Exists(filePath))
                {
                    fileUpdateTime = File.GetLastWriteTime(filePath);
                }
                if (DateTime.Now.Subtract(fileUpdateTime).TotalSeconds > backupSec)
                {
                    Polenter.Serialization.SharpSerializer serializer = new Polenter.Serialization.SharpSerializer();
                    serializer.Serialize(obj, filePath);
                    if (isEncrypt)
                    {
                        string temp = string.Empty;
                        if (LkEncryptDecrypt.Encrypt(File.ReadAllText(filePath), out temp))
                        {
                            File.WriteAllText(filePath, temp);
                            result = true;
                        }
                    }
                    else
                    {
                        result = true;
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(result);
        }
Exemplo n.º 16
0
        public static bool ObjectDeserialize(string fileName, out object obj, bool isEncrypt = false)
        {
            bool result = false;

            obj = null;
            try
            {
                string filePath = LkCommonUtil.GetFilePath(Path.Combine(DefaultDirectory, fileName));
                if (File.Exists(filePath))
                {
                    Polenter.Serialization.SharpSerializer serializer = new Polenter.Serialization.SharpSerializer();

                    if (isEncrypt)
                    {
                        string temp = string.Empty;
                        if (LkEncryptDecrypt.Decrypt(File.ReadAllText(filePath), out temp))
                        {
                            File.WriteAllText(filePath + ".temp", temp);
                            obj = serializer.Deserialize(filePath + ".temp");
                            File.Delete(filePath + ".temp");
                            result = true;
                        }
                    }
                    else
                    {
                        obj    = serializer.Deserialize(filePath);
                        result = true;
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(result);
        }
        public Message SerializeRequest(MessageVersion messageVersion, object[] parameters)
        {
            Polenter.Serialization.SharpSerializer serializer = new Polenter.Serialization.SharpSerializer(true);

            //stream will be closed in the ContentStreamProvider
            MemoryStream outStream = new MemoryStream();

            foreach (var parameter in parameters)
            {
                serializer.Serialize(parameter, outStream);
            }

            //check
            outStream.Position = 0;

            Message prototype = null;
            if (InnerClientFormatter != null)
            {
                prototype = InnerClientFormatter.SerializeRequest(messageVersion, parameters);
                messageVersion = prototype.Version;
            }

            return CreateMessage(prototype, outStream, ROOT);
        }
Exemplo n.º 18
0
 public PersistenceListSharpSerializer(System.IO.Stream connectionStream, bool doSecure = false, bool liveOpen = true, CompressionMode compression = CompressionMode.NoCompression, bool binarySerialization = false)
     : base(connectionStream, doSecure, liveOpen, compression)
 {
     formatter = !binarySerialization ? new Polenter.Serialization.SharpSerializer(false) :
                 new Polenter.Serialization.SharpSerializer(new Polenter.Serialization.SharpSerializerBinarySettings(Polenter.Serialization.BinarySerializationMode.Burst));
 }
Exemplo n.º 19
0
        /// <summary>
        /// 把对象序列化并返回相应的字节
        /// </summary>
        /// <param name="pObj">需要序列化的对象</param>
        /// <returns>byte[]</returns>
        //public static byte[] SerializeObject(object pObj)
        //{
        //    var _memory = new MemoryStream();
        //    var formatter = new BinaryFormatter();
        //    // formatter.TypeFormat=System.Runtime.Serialization.Formatters.FormatterTypeStyle.XsdString;
        //    formatter.Serialize(_memory, pObj);
        //    _memory.Position = 0;
        //    byte[] read = new byte[_memory.Length];
        //    _memory.Read(read, 0, read.Length);
        //    _memory.Close();
        //    return read;
        //}
        /// <summary>
        /// 把对象序列化并返回相应的字节
        /// </summary>
        /// <param name="pObj">需要序列化的对象</param>
        /// <returns>byte[]</returns>
        public static byte[] SerializeObject(object pObj)
        {
            //    //StringBuilder sBuilder = new StringBuilder();

            //    //XmlSerializer xmlSerializer = new XmlSerializer(pObj.GetType());
            //    //XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
            //    //xmlWriterSettings.Encoding = Encoding.Unicode;
            //    //XmlWriter xmlWriter = XmlWriter.Create(sBuilder, xmlWriterSettings);
            //    //xmlSerializer.Serialize(xmlWriter, pObj);
            //    //xmlWriter.Close();

            //    //return Encoding.UTF8.GetBytes(sBuilder.ToString());

            Polenter.Serialization.SharpSerializer serializer = new Polenter.Serialization.SharpSerializer(true);
            return serializer.Serialize(pObj);
        }
Exemplo n.º 20
0
 public override void Dispose()
 {
     base.Dispose();
     formatter = null;
 }