private void UpdateForks() { var changedForkIds = new HashSet <int>(); var updatedForkIds = (List <int>)BinarySerializerHelper.DeserializeObject(Store.Get(Store.DefaultType, KeyGenerator.GenerateForksKey(AppId), null)); var newForkIds = updatedForkIds.Except(_forks.Keys); foreach (var newForkId in newForkIds) { var bytesNewRawFork = Store.Get(Store.DefaultType, KeyGenerator.GenerateForkKey(AppId, newForkId), null); if (bytesNewRawFork == null) { continue; } var newRawFork = ProtoBufSerializerHelper.Deserialize <ForkRawData>(bytesNewRawFork); var bytesNewForkTimeStamp = Store.Get(Store.DefaultType, KeyGenerator.GenerateForkTimeStampKey(AppId, newForkId), null); if (bytesNewForkTimeStamp == null) { continue; } var newForkTimeStamp = (DateTime)BinarySerializerHelper.DeserializeObject(bytesNewForkTimeStamp); var parentFork = newRawFork.ParentId == 0 ? null : _forks[newRawFork.ParentId]; var newFork = new Fork { Id = newForkId, Name = newRawFork.Name, Description = newRawFork.Description, IsInGracePeriod = newRawFork.IsInGracePeriod, Parent = parentFork }; if (parentFork != null) { parentFork.Children.Add(newFork); changedForkIds.Add(parentFork.Id); } _forks[newForkId] = newFork; _forksTimeStamps[newForkId] = newForkTimeStamp; } var toDel = _forks.Keys.Except(updatedForkIds).ToList(); foreach (var toDelFork in toDel) { _forks.Remove(toDelFork); _forksTimeStamps.Remove(toDelFork); } foreach (var forkId in _forks.Keys.ToList()) { var newTimeStamp = (DateTime)BinarySerializerHelper.DeserializeObject(Store.Get(Store.DefaultType, KeyGenerator.GenerateForkTimeStampKey(AppId, forkId), null)); var _currentForkTimeStamp = _forksTimeStamps[forkId]; if (newTimeStamp > _currentForkTimeStamp) { var rawFork = ProtoBufSerializerHelper.Deserialize <ForkRawData>(Store.Get(Store.DefaultType, KeyGenerator.GenerateForkKey(AppId, forkId), null)); _forksTimeStamps[forkId] = newTimeStamp; UpdateFork(_forks[forkId], rawFork); changedForkIds.Add(forkId); } } RaiseForkChanged(changedForkIds.ToList()); }
private void InitForksDict() { var rawForks = new Dictionary <int, ForkRawData>(); var forkIds = (List <int>)BinarySerializerHelper.DeserializeObject(Store.Get(Store.DefaultType, KeyGenerator.GenerateForksKey(AppId), null)); foreach (var forkId in forkIds) { rawForks[forkId] = ProtoBufSerializerHelper.Deserialize <ForkRawData>(Store.Get(Store.DefaultType, KeyGenerator.GenerateForkKey(AppId, forkId), null)); _forksTimeStamps[forkId] = (DateTime)BinarySerializerHelper.DeserializeObject(Store.Get(Store.DefaultType, KeyGenerator.GenerateForkTimeStampKey(AppId, forkId), null)); } var masterForks = rawForks.Where(x => x.Value.ParentId == 0).Select(x => x.Key).ToArray(); foreach (var masterFork in masterForks) { CreateFork(rawForks, masterFork); } }
private void SetFork(ForkRawData fork) { KeyValueStore.Set(KeyValueStore.DefaultType, KeyGenerator.GenerateForkKey(AppId, fork.Id), ProtoBufSerializerHelper.Serialize(fork), null); KeyValueStore.Set(KeyValueStore.DefaultType, KeyGenerator.GenerateForkTimeStampKey(AppId, fork.Id), BinarySerializerHelper.SerializeObject(DateTime.UtcNow), null); }