Ejemplo n.º 1
0
        public void UpdateVersioned <T>(VersionedStore <T> Store, int PartitionIndex, Func <T, T> Transformer)
        {
            var StorePath = Store.Path;
            var Partition = Store.GetPartition(PartitionIndex);
            Func <Version, Boolean> Update = WriterVersion =>
            {
                var Content = Partition.GetLastVersionContent();
                return(Partition.TryPutLastVersion(WriterVersion, Transformer(Content)));
            };

            if (UpdateStores.ContainsKey(StorePath))
            {
                var s = UpdateStores[StorePath];
                if (s.ContainsKey(PartitionIndex))
                {
                    var upi = s[PartitionIndex];
                    var ReaderVersionContent          = (T)(upi.CurrentStateFromReaderVersion);
                    var CurrentStateFromReaderVersion = Transformer(ReaderVersionContent);
                    upi.CurrentStateFromReaderVersion = CurrentStateFromReaderVersion;
                    Updates.Add(Update);
                    return;
                }
            }

            {
                var ReaderVersion                 = GetReaderVersion();
                var ReaderVersionContent          = Partition.GetVersionContent(ReaderVersion);
                var CurrentStateFromReaderVersion = Transformer(ReaderVersionContent);
                var upi = new UpdatePartitionInfo
                {
                    Partition = Partition,
                    CurrentStateFromReaderVersion = CurrentStateFromReaderVersion,
                    Revert = WriterVersion =>
                    {
                        Partition.RemoveVersion(WriterVersion);
                    }
                };
                if (UpdateStores.ContainsKey(StorePath))
                {
                    var s = UpdateStores[StorePath];
                    s.Add(PartitionIndex, upi);
                }
                else
                {
                    var s = new SortedDictionary <int, UpdatePartitionInfo>();
                    s.Add(PartitionIndex, upi);
                    UpdateStores.Add(StorePath, s);
                }
                Updates.Add(Update);
            }
        }
Ejemplo n.º 2
0
        public TRet CheckReaderVersioned <T, TRet>(VersionedStore <T> Store, int PartitionIndex, Func <T, TRet> Selector)
        {
            var StorePath = Store.Path;

            if (UpdateStores.ContainsKey(StorePath))
            {
                var s = UpdateStores[StorePath];
                if (s.ContainsKey(PartitionIndex))
                {
                    var upi = s[PartitionIndex];
                    return(Selector((T)(upi.CurrentStateFromReaderVersion)));
                }
            }
            var Partition     = Store.GetPartition(PartitionIndex);
            var ReaderVersion = GetReaderVersion();
            var Content       = Partition.GetVersionContent(ReaderVersion, GetPendingWriterVersions());

            return(Selector(Content));
        }