Ejemplo n.º 1
0
            /// <summary>
            /// Serializes the given <see cref="Change"/> to a byte array.
            /// </summary>
            /// <param name="change"><see cref="Change"/> to serialize</param>
            /// <returns>A byte array containing the serialized change list</returns>
            private static byte[] Serialize(ChangeList.Change change)
            {
                if (change == null)
                {
                    throw new ArgumentNullException(nameof(change));
                }

                MemoryStream memoryStream = new MemoryStream();

                try
                {
                    using (var binaryWriter = new BinaryWriter(memoryStream))
                    {
                        memoryStream = null;
                        binaryWriter.Write((int)change.ChangeType);
                        change.Data.WriteTo(binaryWriter);

                        return(((MemoryStream)binaryWriter.BaseStream).ToArray());
                    }
                }
                finally
                {
                    if (memoryStream != null)
                    {
                        memoryStream.Dispose();
                    }
                }
            }
Ejemplo n.º 2
0
            public Task Remove(PersistedData data)
            {
                var change = new ChangeList.Change(ChangeList.ChangeType.Remove, data);

                this.serializedChanges.Add(Serialize(change));
                return(Task.FromResult <object>(null));
            }