protected override RoleViewModel TransformToViewModel(Role model) { var vm = base.TransformToViewModel(model); var permissionsChanges = _permissionsCache.Connect(); var rolePermissions = _domain0.Model.RolePermissions .Connect() .ToCollection(); var combined = Observable.CombineLatest( rolePermissions, permissionsChanges, (rp, _) => rp .Where(x => x.RoleId == vm.Id) .Select(x => _permissionsCache.Lookup(x.Id.Value).Value) ); combined .Subscribe(x => { vm.Permissions = x; vm.PermissionsString = string.Join(",", x.Select(p => p.Name)); }) .DisposeWith(vm.Disposables); return(vm); }
private IInstrumentedMethod CreateInstrumentedMethod(NewInstrumentedMethod m) { var module = mModuleCache.Lookup(m.ModuleId); IModule moduleIfKnown = module.HasValue ? module.Value : cUnknownModule; var sourceMethod = GetSourceMethod(moduleIfKnown, m.OwningType, m.Name, out string localMethodName); var method = new InstrumentedMethod(m.Id, moduleIfKnown, m.MetadataToken, localMethodName, sourceMethod); method.InstrumentedCalls = m.InstrumentedCalls.Select(c => CreateInstrumentedCall(method, c)).ToImmutableList(); return(method); }
private bool IsContainedIn(string name, AgeBracket bracket) { var group = _grouped.Lookup(bracket); if (!group.HasValue) { return(false); } return(group.Value.Cache.Lookup(name).HasValue); }
public void UpdateTreeWhenParentIdOfRootItemChangedToExistingId() { _sourceCache.Lookup(1).Value.BossId = 7; // node 1 added to node 7 children cache var node1 = _result.Lookup(7).Value.Children.Lookup(1); node1.HasValue.Should().BeTrue(); node1.Value.IsRoot.Should().BeFalse(); // node 1 removed from root _result.Lookup(1).HasValue.Should().BeFalse(); }
protected override PermissionViewModel TransformToViewModel(Permission model) { var vm = base.TransformToViewModel(model); _applicationsCache .Connect() .Select(x => _applicationsCache.Lookup(vm.ApplicationId).ValueOrDefault()?.Name) .Subscribe(x => vm.Application = x) .DisposeWith(vm.Disposables); return(vm); }
protected override MessageTemplateViewModel TransformToViewModel(MessageTemplate model) { var vm = base.TransformToViewModel(model); _environmentsCache .Connect() .Select(_ => _environmentsCache.Lookup(vm.EnvironmentId).ValueOrDefault()?.Name) .Subscribe(x => vm.Environment = x) .DisposeWith(vm.Disposables); return(vm); }
public static bool TryGetValue <TObject, TKey>(this IObservableCache <TObject, TKey> cache, TKey key, [MaybeNullWhen(false)] out TObject value) where TKey : notnull { var lookup = cache.Lookup(key); if (lookup.HasValue) { value = lookup.Value; return(true); } value = default; return(false); }
public void DoNotUpdateTreeWhenParentIdNotChanged() { _sourceCache.Lookup(1).Value.Name = "Employee11"; _sourceCache.Lookup(2).Value.Name = "Employee22"; var node1 = _result.Lookup(1); node1.HasValue.Should().BeTrue(); node1.Value.Parent.HasValue.Should().BeFalse(); var node2 = node1.Value.Children.Lookup(2); node2.HasValue.Should().BeTrue(); node2.Value.Parent.HasValue.Should().BeTrue(); node2.Value.Parent.Value.Key.Should().Be(1); }
public static bool TryLookup <TValue, TKey>(this IObservableCache <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); }
public ComplexMicrophoneController( IFactory<MultimediaMicrophoneController, IMicrophoneProvider> multimediaControllerFactory, IMicrophoneProvider microphoneProvider) { microphones = microphoneProvider .Microphones .ToObservableChangeSet() .Filter(x => x.LineId != MicrophoneLineData.All.LineId) .Transform(x => { var multimediaLine = multimediaControllerFactory.Create(microphoneProvider); multimediaLine.LineId = x; return (IMicrophoneController) multimediaLine; }) .Bind(out var sources) .AddKey(x => x.LineId) .AsObservableCache(); var allLinesController = new AllMicrophonesController(sources).AddTo(Anchors); this.WhenAnyValue(x => x.LineId) .Select(x => microphones.Lookup(x)) .Select(x => x.HasValue ? x.Value : allLinesController) .SubscribeSafe(x => ActiveController = x, Log.HandleUiException) .AddTo(Anchors); this.WhenAnyValue(x => x.ActiveController.VolumePercent) .SubscribeSafe(() => RaisePropertyChanged(nameof(VolumePercent)), Log.HandleUiException) .AddTo(Anchors); this.WhenAnyValue(x => x.ActiveController.Mute) .SubscribeSafe(() => RaisePropertyChanged(nameof(Mute)), Log.HandleUiException) .AddTo(Anchors); this.WhenAnyValue(x => x.ActiveController) .Select(x => x?.LineId.LineId == MicrophoneLineData.All.LineId ? sources.ToObservableChangeSet().OnItemAdded(newMicrophone => { Log.Debug($"New microphone {newMicrophone.LineId} detected in All microphones mode, assigning following parameters: {new {Mute, VolumePercent}}"); newMicrophone.Mute = Mute; newMicrophone.VolumePercent = VolumePercent; }) : Observable.Empty<IChangeSet>()) .Switch() .SubscribeToErrors(Log.HandleException) .AddTo(Anchors); LineId = MicrophoneLineData.All; }
public IObservable <Change <TObject, TKey> > Watch(TKey key) { return(Observable.Create <Change <TObject, TKey> > ( observer => { lock (_locker) { //Create or find the existing subscribers var existing = _subscribers.Lookup(key); SubjectWithRefCount <Change <TObject, TKey> > subject; if (existing.HasValue) { subject = existing.Value; } else { subject = new SubjectWithRefCount <Change <TObject, TKey> >(new ReplaySubject <Change <TObject, TKey> >(1)); var initial = _source.Lookup(key); if (initial.HasValue) { var update = new Change <TObject, TKey>(ChangeReason.Add, key, initial.Value); subject.OnNext(update); } _subscribers.BatchUpdate(updater => updater.AddOrUpdate(subject, key)); } //set up subscription var subscriber = subject.Subscribe(observer); return Disposable.Create(() => { //lock to ensure no race condition where the same key could be subscribed //to whilst disposal is taking place lock (_locker) { subscriber.Dispose(); if (subject.RefCount == 0) { _subscribers.BatchUpdate(updater => updater.Remove(key)); } } }); } })); }
private StreamEvent CreateStreamEvent(NewStreamEvent e) { switch (e.Kind) { case StreamEvent.EventKind.OnCompleted: return(new OnCompletedEvent(e.Info)); case StreamEvent.EventKind.OnNext: return(new OnNextEvent(e.Info, TranslatePayload(e.Payload))); case StreamEvent.EventKind.OnError: return(new OnErrorEvent(e.Info, TranslatePayload(e.Payload))); default: throw new ArgumentException(nameof(e)); } object TranslatePayload(PayloadInfo payloadInfo) { if (payloadInfo is SimplePayloadInfo s) { return(s.Value); } var objPayload = (ObjectPayloadInfo)payloadInfo; var typeInfo = mTypeInfoCache.Lookup(objPayload.TypeId).Value; // should always arrive before object that uses it var properties = mObjectPropertiesInfoByObjectId.WatchValue(objPayload.ObjectId) .Select(propsInfo => propsInfo.PropertyValues.Select(TranslatePayload)) .Select(propValues => typeInfo.PropertyNames.Zip(propValues, (name, val) => new KeyValuePair <string, object>(name, val))) .Select(namesAndValues => namesAndValues.ToImmutableDictionary()); return(new PayloadObject( typeInfo.TypeName, objPayload.ObjectId, objPayload.Representation, objPayload.IsExceptionGettingValue, objPayload.ItemCount, properties.Take(1), Observable.Never <IImmutableList <object> >())); } }
public void Select(string item) { _viewModels.Lookup(item) .IfHasValue(selected => Selected = selected); }
public Optional <TObject> Lookup(TKey key) { return(_cache.Lookup(key)); }
private IEnumerable <MetricValueItem> OnUpdate() { IEnumerable <MetricValueItem> response = null; try { switch (_model.MetricTerminalMode) { case MetricTerminalMode.Current: response = _model.Cache.Service.GetCurrentMetricValues() .Select(x => new { m = _metricsCache.Lookup(x.MetricId), v = x }) .Where(x => x.m.HasValue) .Select(x => new MetricValueItem { Metric = x.m.Value, Value = Math.Round(x.v.Value, 2), HasValue = true, Interval = x.v.Interval.ToLocalTime() }); break; case MetricTerminalMode.TimeWindow: response = _model.Cache.Service.GetWindowMetricValues() .Select(x => new { m = _metricsCache.Lookup(x.MetricId), v = x }) .Where(x => x.m.HasValue) .Select(x => new MetricValueItem { Metric = x.m.Value, Value = Math.Round(x.v.Value, 2), HasValue = true }); break; case MetricTerminalMode.Diagram: if (SelectedMetric == null) { break; } var amount = _model.MetricHistoryDepthHours * 12; var history = _model.Cache.Service.GetMetricHistory(SelectedMetric.Metric.ID, amount, _model.MetricHistorySkip5Min); response = history.Values .Select((v, i) => new MetricValueItem() { Interval = history.Interval.AddMinutes(-5 * i).ToLocalTime(), Metric = SelectedMetric.Metric, Value = v, HasValue = true }); break; default: throw new NotImplementedException(); } } catch (Exception) { return(new[] { new MetricValueItem { Metric = new Metric { ID = -1, Name = "", Instance = new Instance { ID = -1, Name = "INTERNAL", Source = new Source { ID = -1, Name = "ERROR" } }, } } }); } response = response? .OrderBy(x => x.Metric.Instance.Source.Name) .ThenBy(x => x.Metric.Instance.Name) .ThenBy(x => x.Metric.Name) .ToList(); return(response); }