コード例 #1
0
            /// <summary>
            /// Deserializes a <see cref="Change"/> from the given byte array.
            /// </summary>
            /// <param name="serializedChange">Byte array containing a serialized change</param>
            /// <param name="factory">The <see cref="AbstractPersistedDataFactory"/> that must be associated with the deserialized change list</param>
            /// <returns>A <see cref="ChangeList"/></returns>
            private static ChangeList.Change Deserialize(byte[] serializedChange, AbstractPersistedDataFactory factory)
            {
                MemoryStream memoryStream = new MemoryStream(serializedChange);

                try
                {
                    using (var binaryReader = new BinaryReader(memoryStream))
                    {
                        memoryStream = null;

                        ChangeList.ChangeType changeType = (ChangeList.ChangeType)binaryReader.ReadInt32();
                        PersistedData         data       = new PersistedData(0);
                        data.ReadFrom(binaryReader);

                        return(new ChangeList.Change(changeType, data));
                    }
                }
                finally
                {
                    if (memoryStream != null)
                    {
                        memoryStream.Dispose();
                    }
                }
            }
コード例 #2
0
        /// <summary>
        /// Deserializes a <see cref="WinFabPersistence.PersistedData"/> from the given <see cref="BinaryReader"/>.
        /// </summary>
        /// <param name="binaryReader">The <see cref="BinaryReader"/> to deserialize from</param>
        /// <returns>The deserialized <see cref="WinFabPersistence.PersistedData"/></returns>
        public WinFabPersistence.PersistedData Read(BinaryReader binaryReader)
        {
            if (binaryReader == null)
            {
                throw new ArgumentNullException(nameof(binaryReader));
            }

            var pd = new PersistedData(0);

            pd.ReadFrom(binaryReader);
            ServiceFabricPersistenceEventSource.Log.PersistedDataSerializer_Read(pd.Id, pd.Name);

            return(new WinFabPersistence.PersistedData(pd));
        }
コード例 #3
0
        /// <summary>
        /// Enumerates the stream and returns a collection of persisted data
        /// </summary>
        /// <param name="stream">Stream to read</param>
        /// <returns>collection of persisted data object</returns>
        public IEnumerable <PersistedData> EnumerateFrom(Stream stream)
        {
            InMemoryPersistenceEventSource.Log.LoadFromStream();
            using (var binaryReader = new BinaryReader(stream))
            {
                ulong itemCount = binaryReader.ReadUInt64();

                for (ulong i = 0; i < itemCount; i++)
                {
                    PersistedData data = new PersistedData(0);
                    data.ReadFrom(binaryReader);
                    yield return(data);
                }
            }
        }