Beispiel #1
0
        private SimpleObjectSerializer(object Value, SimpleObjectFieldSerializationMode FieldMode, DefinitionList Types)
            : base(Value, Types)
        {
            this.FieldMode = FieldMode;
            if (IsEmpty)
            {
                return;
            }

            if (IsArray)
            {
                Children = GetArrayValues().ToArray();
            }
            else if (TypeCode == TypeCode.Object)
            {
                this.CustomSerializer = Object as ICustomSerializer;
                if (CustomSerializer != null && CustomSerializer.Initialize(this))
                {
                    return;
                }
                Children = GetFields().ToArray();
            }
            else if (TypeCode == TypeCode.String)
            {
                StringIndex = defs.Strings.Add((string)Value);
            }
        }
 internal NamedPipeConnection(int id, string name, PipeStream serverStream, ICustomSerializer <TRead> serializerRead, ICustomSerializer <TWrite> serializerWrite)
 {
     Id             = id;
     Name           = name;
     Handle         = serverStream.SafePipeHandle;
     _streamWrapper = new PipeStreamWrapper <TRead, TWrite>(serverStream, serializerRead, serializerWrite);
 }
Beispiel #3
0
        public override void ReadData(SerializedObject objSerializedObject)
        {
            base.ReadData(objSerializedObject);

            Initialize();

            SerializedObject objSerializedItems = objSerializedObject.Objects["Items"];

            if (objSerializedItems != null)
            {
                foreach (SerializedValue objItem in objSerializedItems.Values.ToArray())
                {
                    TObjectType objValue = (TObjectType)objItem.Value;
                    Add(objValue);
                }

                foreach (SerializedObject objItem in objSerializedItems.Objects.ToArray())
                {
                    TObjectType       objValue            = default(TObjectType);
                    ICustomSerializer objCustomSerializer = objItem.Deserialize();

                    if (objCustomSerializer is SerializedWrapperObject)
                    {
                        SerializedWrapperObject objSerializedWrapperObject = (SerializedWrapperObject)objCustomSerializer;
                        objValue = (TObjectType)objSerializedWrapperObject.Data;
                    }
                    else
                    {
                        objValue = (TObjectType)((object)objCustomSerializer);
                    }

                    Add(objValue);
                }
            }
        }
        public ReturnType Deserialize <ReturnType>(string pathToFile) where ReturnType : class
        {
            string            extension    = pathToFile.Split('.')[1];
            ICustomSerializer deserializer = GetDeserializer(extension);
            object            result       = deserializer.Deserialize(pathToFile);

            return(result as ReturnType);
        }
 public static void RegisterCustomSerializer(int num, Type type, ICustomSerializer serializer)
 {
     if (!types.ContainsKey(type))
     {
         types.Add(type, num);
         customSerializers.Add(num, serializer);
     }
 }
Beispiel #6
0
        /// <summary>
        /// The set custom serializer.
        /// </summary>
        /// <param name="type">
        /// The type.
        /// </param>
        /// <param name="serializer">
        /// The serializer.
        /// </param>
        public void SetCustomSerializer <T>(ICustomSerializer <T> serializer)
        {
            var type = typeof(T);

            this.customSerializers.Remove(type);

            this.customSerializers.Add(type, serializer);
        }
 public EventService(ILogger logger, IEventStoreConnection eventStoreConnection,
                     ICustomDataConverter customDataConverter, string streamName, ICustomSerializer customSerializer)
 {
     _eventStoreConnection = eventStoreConnection;
     _customDataConverter  = customDataConverter;
     _streamName           = streamName;
     _customSerializer     = customSerializer;
     _logger = logger;
 }
Beispiel #8
0
        public void SetValue(string strName, ICustomSerializer objObject)
        {
            if (strName == null)
            {
                throw new ArgumentNullException("strName", "A valid non-null string is required.");
            }

            Settings.Remove(strName);
            if (objObject != null)
            {
                Settings.Add(strName, objObject);
            }
        }
        ICustomSerializer GetDeserializer(string extension)
        {
            ICustomSerializer serializer = null;

            switch (extension)
            {
            case "cl":
                serializer = new CollisionComponentSerializer(); break;

            default:
                serializer = new EngineObjectsSerializer(); break;
            }

            return(serializer);
        }
Beispiel #10
0
        public SerializedObject Add(string strName, ICustomSerializer objCustomSerializer)
        {
            if (strName == null)
            {
                throw new ArgumentNullException("strName", "A valid non-null string is required..");
            }

            SerializedObject objSerializedObject = null;

            if (objCustomSerializer != null)
            {
                objSerializedObject = objCustomSerializer.Serialize(strName);
                Add(objSerializedObject);
            }

            return(objSerializedObject);
        }
Beispiel #11
0
        public static SerializedObject Serialize(string strName, ICustomSerializer objCustomSerializer)
        {
            if ((strName == null) || (strName.Length == 0))
            {
                throw new ArgumentOutOfRangeException("strName", "A valid non-null, non-empty string is required..");
            }
            if (objCustomSerializer == null)
            {
                throw new ArgumentException("objCustomSerializer", "A valid non-null ICustomSerializer is required..");
            }

            SerializedTypeInfo objTypeInfo         = new SerializedTypeInfo(objCustomSerializer);
            SerializedObject   objSerializedObject = new SerializedObject(strName, objTypeInfo);

            objCustomSerializer.WriteData(objSerializedObject);

            return(objSerializedObject);
        }
Beispiel #12
0
        public ICustomSerializer Deserialize()
        {
            string strAssemblyName = TypeInfo.AssemblyName;
            string strTypeName     = TypeInfo.TypeName;

            Assembly objAssembly = null;

            try
            {
                objAssembly = Assembly.Load(strAssemblyName);
            }
            catch (Exception objException)
            {
                string strErrorMessage = "An error was encountered while loading the assembly - Assembly.Load('" + strAssemblyName + "'):\n";
                throw new Exception(strErrorMessage, objException);
            }

            Type objType = null;

            try
            {
                objType = objAssembly.GetType(strTypeName, true, true);
            }
            catch (Exception objException)
            {
                string strErrorMessage = "An error was encountered while loading the type - objAssemblyName.GetType('" + strTypeName + "', True, True):\n";
                throw new Exception(strErrorMessage, objException);
            }

            ICustomSerializer objCustomSerializer = null;

            try
            {
                ConstructorInfo objConstructorInfo = objType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public, null, new Type[] { typeof(SerializedObject) }, null);
                objCustomSerializer = (ICustomSerializer)objConstructorInfo.Invoke(new object[] { this });
            }
            catch (Exception objException)
            {
                string strErrorMessage = "An error was encountered while creating the object - Activator.CreateInstance('" + objType.FullName + "'):\n";
                throw new Exception(strErrorMessage, objException);
            }

            return(objCustomSerializer);
        }
Beispiel #13
0
        public TObjectType GetObject <TObjectType>(string strName, TObjectType objDefaultValue)
        {
            TObjectType objReturnValue = objDefaultValue;

            SerializedObject objSerializedObject = this[strName];

            if (objSerializedObject != null)
            {
                ICustomSerializer objCustomSerializer = objSerializedObject.Deserialize();

                if (objCustomSerializer is SerializedWrapperBase <TObjectType> )
                {
                    SerializedWrapperBase <TObjectType> objSerializedWrapper = (SerializedWrapperBase <TObjectType>)objCustomSerializer;
                    objReturnValue = (TObjectType)objSerializedWrapper.Data;
                }
                else
                {
                    objReturnValue = (TObjectType)((object)objCustomSerializer);
                }
            }

            return(objReturnValue);
        }
 public LogWrapper(ILogger logger, ICustomSerializer serializer)
 {
     _logger     = logger;
     _serializer = serializer;
 }
 /// <inheritdoc />
 /// <summary>
 /// Constructs a new <c>PipeStreamWrapper</c> object that reads from and writes to the given <paramref name="stream" />.
 /// </summary>
 /// <param name="stream">Stream to read from and write to</param>
 /// <param name="serializer">Serializer to use. Can be null to use the default serializer</param>
 public PipeStreamWrapper(PipeStream stream, ICustomSerializer <TReadWrite> serializer) : base(stream, serializer, serializer)
 {
 }
Beispiel #16
0
 /// <summary>
 /// Constructs a new <c>NamedPipeClient</c> to connect to the <see cref="NamedPipeServer{TReadWrite}"/> specified by <paramref name="pipeName"/>.
 /// </summary>
 /// <param name="pipeName">Name of the server's pipe</param>
 /// <param name="serverName">Server name. By default, "." (local).</param>
 /// <param name="serializer">Serializer to use. Can be null to use the default serializer</param>
 public NamedPipeClient(string pipeName, string serverName, ICustomSerializer <TReadWrite> serializer = null) : base(pipeName, serverName, serializer, serializer)
 {
 }
Beispiel #17
0
 /// <summary>
 /// Objects that are castable to give type are serialized with given serializer
 /// </summary>
 public void AddCustomSerializer(ICustomSerializer serializer)
 {
     serializers.Add(serializer);
 }
Beispiel #18
0
 public static void RegisterCustomSerializer(int num, Type type, ICustomSerializer serializer)
 {
     types.Add(type, num);
     customSerializers.Add(num, serializer);
 }
Beispiel #19
0
        public static PipeStreamWrapper <TRead, TWrite> Connect <TRead, TWrite>(string pipeName, string serverName, ICustomSerializer <TRead> serializerRead, ICustomSerializer <TWrite> serializerWrite, CancellationToken cancelToken)
            where TRead : class
            where TWrite : class
        {
            var inner = CreateAndConnectPipe(pipeName, serverName, cancelToken);

            return(inner == null ? null : new PipeStreamWrapper <TRead, TWrite>(inner, serializerRead, serializerWrite));
        }
 public SerializationTester(ICustomSerializer <TData> serializer, bool showResult = false)
 {
     _serializer = serializer;
     _showResult = showResult;
 }
Beispiel #21
0
        public virtual void AddToMessageStream(Stream stream, Type type, object val)
        {
            if (null == val)
            {
                UnityEngine.Debug.Log("NULL VALUE of Type = " + type.ToString());
                return;
            }
            if (type == typeof(bool))
            {
                stream.WriteByte((byte)((bool)val ? 1 : 0));
                return;
            }
            if (type == typeof(byte))
            {
                stream.WriteByte((byte)val);
                return;
            }
            if (type == typeof(Int16))
            {
                var buf = BitConverter.GetBytes((Int16)val);
                stream.Write(buf, 0, buf.Length);
                return;
            }
            if (type == typeof(UInt16))
            {
                var buf = BitConverter.GetBytes((UInt16)val);
                stream.Write(buf, 0, buf.Length);
                return;
            }
            if (type == typeof(Int32))
            {
                var buf = BitConverter.GetBytes((Int32)val);
                stream.Write(buf, 0, buf.Length);
                return;
            }
            if (type == typeof(UInt32))
            {
                var buf = BitConverter.GetBytes((UInt32)val);
                stream.Write(buf, 0, buf.Length);
                return;
            }
            if (type == typeof(Int64))
            {
                var buf = BitConverter.GetBytes((Int64)val);
                stream.Write(buf, 0, buf.Length);
                return;
            }
            if (type == typeof(UInt64))
            {
                var buf = BitConverter.GetBytes((UInt64)val);
                stream.Write(buf, 0, buf.Length);
                return;
            }
            if (type == typeof(float))
            {
                var buf = BitConverter.GetBytes((float)val);
                stream.Write(buf, 0, buf.Length);
                return;
            }
            if (type == typeof(double))
            {
                var buf = BitConverter.GetBytes((double)val);
                stream.Write(buf, 0, buf.Length);
                return;
            }
            if (type == typeof(DateTime))
            {
                var buf = BitConverter.GetBytes((Int32)(((DateTime)val).Ticks / 10000000 - 62135596800)); // 01.01.1970
                stream.Write(buf, 0, buf.Length);
                return;
            }
            if (type == typeof(Byte[]))
            {
                var buf = (byte[])val;
                stream.Write(buf, 0, buf.Length);
                return;
            }
            if (type == typeof(String) || val.GetType() == typeof(string))
            {
                var typed = (string)val;
                if (string.IsNullOrEmpty(typed))
                {
                    stream.WriteByte(0);
                    return;
                }
                var buf    = Encoding.UTF8.GetBytes(typed);
                var buflen = VarInt(buf.Length);
                stream.Write(buflen, 0, buflen.Length);
                stream.Write(buf, 0, buf.Length);
                return;
            }

            ICustomSerializer customSerializer = val as ICustomSerializer;

            if (null != customSerializer)
            {
                customSerializer.Serializer(stream, this);
                return;
            }

            if (type.IsEnum)
            {
                stream.WriteByte((byte)val);
                return;
            }
            if (type.IsArray)
            {
                var typed = (ICollection)val;
                if (typed == null)
                {
                    return;
                }
                var buf = VarInt(typed.Count);
                stream.Write(buf, 0, buf.Length);
                foreach (var value in typed)
                {
                    AddToMessageStream(stream, value.GetType(), value);
                }
                return;
            }
            if (type.IsClass)
            {
                var chType     = val.GetType();
                var properties = GetPropertiesForMessage(chType);
                foreach (var prop in properties)
                {
                    AddToMessageStream(stream, prop, val);
                }
                return;
            }

            throw new NotImplementedException();
        }
Beispiel #22
0
 public SaverLoader(ICustomSerializer serializer)
 {
     internalSerializer = serializer;
 }
 public static NamedPipeConnection <TRead, TWrite> CreateConnection <TRead, TWrite>(PipeStream pipeStream, ICustomSerializer <TRead> serializerRead, ICustomSerializer <TWrite> serializerWrite)
     where TRead : class
     where TWrite : class
 => new NamedPipeConnection <TRead, TWrite>(++_lastId, "Client " + _lastId, pipeStream, serializerRead, serializerWrite);
 public static void RegisterCustomSerializer <T>(int num, ICustomSerializer serializer)
 {
     RegisterCustomSerializer(num, typeof(T), serializer);
 }
Beispiel #25
0
 internal void AddCustomSerializer(ICustomSerializer customSerializer)
 {
     m_CustomSerializers.Add(customSerializer.GetType(), customSerializer);
 }
Beispiel #26
0
 /// <summary>
 /// Constructs a new <c>NamedPipeServer</c> object that listens for client connections on the given <paramref name="pipeName"/>.
 /// </summary>
 /// <param name="pipeName">Name of the pipe to listen on</param>
 /// <param name="bufferSize">Size of input and output buffer</param>
 /// <param name="security">And object that determine the access control and audit security for the pipe</param>
 /// <param name="serializer">Serializer to use. Can be null to use the default serializer</param>
 public NamedPipeServer(string pipeName, int bufferSize, PipeSecurity security, ICustomSerializer <TReadWrite> serializer = null)
     : base(pipeName, bufferSize, security, serializer, serializer)
 {
 }
Beispiel #27
0
 /// <inheritdoc />
 protected CustomSerializor(ICustomSerializer serializer)
 {
     _serializer = serializer;
 }
 /// <summary>
 /// Constructs a new <c>PipeStreamWriter</c> object that writes to given <paramref name="stream"/>.
 /// </summary>
 /// <param name="stream">Pipe to write to</param>
 /// <param name="serializer">Serializer to use. Can be null to use the default serializer</param>
 public PipeStreamWriter(PipeStream stream, ICustomSerializer <T> serializer)
 {
     BaseStream  = stream;
     _serializer = serializer ?? new BinaryFormatterSerializer <T>();
 }
 public void SetCustomSerializer <T>(ICustomSerializer <T> serializer)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Constructs a new <c>PipeStreamReader</c> object that reads data from the given <paramref name="stream"/>.
 /// </summary>
 /// <param name="stream">Pipe to read from</param>
 /// <param name="serializer">Serializer to use. Can be null to use the default serializer</param>
 public PipeStreamReader(PipeStream stream, ICustomSerializer<T> serializer)
 {
     BaseStream = stream;
     IsConnected = stream.IsConnected;
     _serializer = serializer ?? new BinaryFormatterSerializer<T>();
 }