private void ApplyEvents(IEnumerable <IEvent <TKey, TAggregate> > events, Action <IEnumerable <TAggregate> > apply)
        {
            var aggregates = new List <TAggregate>();

            foreach (var @event in events)
            {
                var aggregate = _sourceCache.Lookup(@event.EventStreamId);

                if (!aggregate.HasValue)
                {
                    var @new = new TAggregate
                    {
                        Id            = @event.EventStreamId,
                        DoStoreEvents = _configuration.DoStoreEvents
                    };

                    @new.Apply(@event);

                    aggregates.Add(@new);
                }
                else
                {
                    aggregate.Value.Apply(@event);

                    aggregates.Add(aggregate.Value);
                }
            }

            apply(aggregates);
        }
Example #2
0
        public void Handle(ApplicationMsgs.RoleCreated @event)
        {
            var policy = _policies.Lookup(@event.PolicyId);

            if (policy.HasValue && !_roles.ContainsKey(@event.RoleId))
            {
                var role = new RoleDTO(@event);
                _roles.Add(@event.RoleId, role);
                policy.Value.Roles.AddOrUpdate(role);
            }
        }
        public void AddToFavorites(int cakeId, CakeDto cake)
        {
            var hasCake = _favouriteCakes.Lookup(cakeId);

            if (!hasCake.HasValue)
            {
                _favouriteCakes.AddOrUpdate(cake);
            }
        }
Example #4
0
        public SearchInfo Get(string key)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentException("message", nameof(key));
            }

            var optional = _cache.Lookup(key);

            return(optional.HasValue ? optional.Value : null);
        }
Example #5
0
        /// <inheritdoc/>
        public GeofenceRegion Get(string id)
        {
            var optional = _store.Lookup(id);

            if (optional.HasValue)
            {
                return(optional.Value);
            }

            return(GeofenceRegion.Default);
        }
Example #6
0
        public Session GetSession(string id)
        {
            lock (_sessions) {
                var session = _sessions.Lookup(id).ValueOrDefault();
                if (session == null)
                {
                    _sessions.AddOrUpdate(session = new Session(id));
                }

                return(session);
            }
        }
Example #7
0
        private BoxViewModel GetBox(string uri)
        {
            var o = BoxesCache.Lookup(uri);

            return(o.ValueOr(() =>
            {
                var box = shell.Container.Resolve <BoxViewModel>();
                box.Uri = uri;
                BoxesCache.AddOrUpdate(box);
                return box;
            }));
        }
Example #8
0
        public TViewModel?TryGet(string key)
        {
            var viewModel = _sourceCache.Lookup(key);

            if (viewModel.HasValue)
            {
                return(viewModel.Value);
            }
            else
            {
                return(null);
            }
        }
Example #9
0
        public static bool TryLookup <TValue, TKey>(this SourceCache <TValue, TKey> cache, TKey key,
                                                    [MaybeNullWhen(false)] out TValue value)
        {
            var option = cache.Lookup(key);

            if (option.HasValue)
            {
                value = option.Value;
                return(true);
            }

            value = default;
            return(false);
        }
        private void ApplyEvent(IEvent <TKey, TAggregate> @event)
        {
            var aggregate = _sourceCache.Lookup(@event.EventStreamId);

            if (!aggregate.HasValue)
            {
                var @new = new TAggregate
                {
                    Id = @event.EventStreamId
                };

                @new.Apply(@event);

                _sourceCache.AddOrUpdate(@new);
            }
            else
            {
                aggregate.Value.Apply(@event);

                _sourceCache.AddOrUpdate(aggregate.Value);
            }
        }
Example #11
0
        private SteamConnectService()
        {
            mCurrent = this;

            SteamApps    = new SourceCache <SteamApp, uint>(t => t.AppId);
            DownloadApps = new SourceCache <SteamApp, uint>(t => t.AppId);

            DownloadApps
            .Connect()
            .Subscribe(_ =>
            {
                foreach (var app in DownloadApps.Items)
                {
                    var optional = SteamApps.Lookup(app.AppId);
                    if (optional.HasValue)
                    {
                        var value             = optional.Value;
                        value.InstalledDir    = app.InstalledDir;
                        value.State           = app.State;
                        value.SizeOnDisk      = app.SizeOnDisk;
                        value.LastOwner       = app.LastOwner;
                        value.BytesToDownload = app.BytesToDownload;
                        value.BytesDownloaded = app.BytesDownloaded;
                        value.BytesToStage    = app.BytesToStage;
                        value.BytesStaged     = app.BytesStaged;
                        value.LastUpdated     = app.LastUpdated;
                    }
                }
            });

            this.WhenValueChanged(x => x.IsWatchSteamDownloading, false)
            .Subscribe(x =>
            {
                if (x)
                {
                    InitializeDownloadGameList();
                    if (OperatingSystem2.IsLinux)
                    {
                        IPlatformService.Instance.TryGetSystemUserPassword();
                    }
                    SteamTool.StartWatchSteamDownloading(app =>
                    {
                        var optional = DownloadApps.Lookup(app.AppId);
                        if (!optional.HasValue)
                        {
                            DownloadApps.AddOrUpdate(app);
                        }
                        else
                        {
                            var current             = optional.Value;
                            current.InstalledDir    = app.InstalledDir;
                            current.State           = app.State;
                            current.SizeOnDisk      = app.SizeOnDisk;
                            current.LastOwner       = app.LastOwner;
                            current.BytesToDownload = app.BytesToDownload;
                            current.BytesDownloaded = app.BytesDownloaded;
                            current.BytesToStage    = app.BytesToStage;
                            current.BytesStaged     = app.BytesStaged;
                            current.LastUpdated     = app.LastUpdated;
                        }

                        if (WatchDownloadingSteamAppIds.Contains(app.AppId))
                        {
                            if (app.IsDownloading)
                            {
                                app.IsWatchDownloading = true;
                            }
                            else
                            {
                                WatchDownloadingSteamAppIds.Remove(app.AppId);
                                if (!WatchDownloadingSteamAppIds.Any())
                                {
                                    WatchDownloadingComplete();
                                }
                            }
                        }
                    }, appid =>
                    {
                        DownloadApps.RemoveKey(appid);
                    });
                }
                else
                {
                    SteamTool.StopWatchSteamDownloading();
                }
            });
        }
Example #12
0
 public Optional <ProcessWindow> LookupWindow(IntPtr handle) => _windows.Lookup(handle);
        /// <inheritdoc/>
        public GeofenceRegion Get(string id)
        {
            var lookup = _sourceCache.Lookup(id);

            return(lookup.HasValue ? lookup.Value : GeofenceRegion.Default);
        }
Example #14
0
 public Optional <TValue> Lookup(TKey key)
 => _cache.Lookup(key);
 public Optional <IFileReference> Lookup(int key)
 {
     return(_cache.Lookup(key.ToString()));
 }
Example #16
0
 public Optional <ExplicitConnection> Get(Guid id)
 {
     return(_connectionSoureCache.Lookup(id));
 }
Example #17
0
 /// <inheritdoc />
 public Optional <Device> Lookup(string key)
 => _controllers?.Lookup(key) ?? throw new ObjectDisposedException(nameof(Devices));