Esempio n. 1
0
        /// <summary>
        /// Reads and deserializes an Object from the supplied stream
        /// </summary>
        public static T ReadObjectFromStream <T>(Stream objectStream)
        {
            if (objectStream == null || !objectStream.CanRead || !objectStream.CanSeek)
            {
                throw new ArgumentException("stream is not seekable or readable", nameof(objectStream));
            }

            objectStream.Position = 0;

            var serializedBytes = new byte[objectStream.Length];

            objectStream.Read(serializedBytes, 0, serializedBytes.Length);
            objectStream.Position = 0;

            var settings = new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All,

#if NETSTANDARD2_0
                SerializationBinder = new PackageUpgradeSerializationBinder()
#else
                Binder = new PackageUpgradeSerializationBinder()
#endif
            };

            return(JsonConvert.DeserializeObject <T>(
                       Encoding.UTF8.GetString(serializedBytes),
                       settings));
        }
Esempio n. 2
0
        /// <summary>
        /// Deserializes an Object from the supplied bytes
        /// </summary>
        public static T ReadObjectFromByteArray <T>(byte[] serializedBytes)
        {
            var settings = new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.All,

#if NETSTANDARD2_0
                SerializationBinder = new PackageUpgradeSerializationBinder()
#else
                Binder = new PackageUpgradeSerializationBinder()
#endif
            };

            return(JsonConvert.DeserializeObject <T>(
                       Encoding.UTF8.GetString(serializedBytes),
                       settings));
        }
        /// <summary>
        /// Read an entity properties based on the supplied dictionary or entity properties
        /// </summary>
        /// <param name="properties">Dictionary of properties to read for the entity</param>
        /// <param name="operationContext">The operation context</param>
        public override void ReadEntity(IDictionary <string, EntityProperty> properties,
                                        OperationContext operationContext)
        {
            InstanceId     = GetValue("InstanceId", properties, property => property.StringValue);
            ExecutionId    = GetValue("ExecutionId", properties, property => property.StringValue);
            SequenceNumber = GetValue("SequenceNumber", properties, property => property.Int32Value).GetValueOrDefault();
            TaskTimeStamp  =
                GetValue("TaskTimeStamp", properties, property => property.DateTimeOffsetValue)
                .GetValueOrDefault()
                .DateTime;

            string serializedHistoryEvent = GetValue("HistoryEvent", properties, property => property.StringValue);

            HistoryEvent = JsonConvert.DeserializeObject <HistoryEvent>(serializedHistoryEvent,
                                                                        new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects,
#if NETSTANDARD2_0
                SerializationBinder = new PackageUpgradeSerializationBinder()
#else
                Binder = new PackageUpgradeSerializationBinder()
#endif
            });