Exemple #1
0
            private IInstrumentedCall CreateInstrumentedCall(IInstrumentedMethod method, NewInstrumentedCall c)
            {
                var observableInstances = mObservableInstancesByCall
                                          .WatchValue(c.Id)
                                          .Take(1)
                                          .SelectMany(obses => obses);

                return(new InstrumentedCall(c.Id, method, c.CalledMethod, c.InstructionOffset, observableInstances));
            }
Exemple #2
0
            private IModule CreateModule(NewModuleUpdate m)
            {
                var instrumentedMethods = mInstrumentedMethodsByModule
                                          .WatchValue(m.ModuleId)
                                          .Take(1)
                                          .SelectMany(calls => calls);

                return(new Module(m.ModuleId, m.Path, m.AssemblyName, instrumentedMethods));
            }
Exemple #3
0
            private IObservableInstance CreateObservableInstance(NewObservableInstance o)
            {
                var inputs = mObservableInstanceInputsByOutput
                             .WatchValue(o.Created.SequenceId)
                             .Take(1)
                             .SelectMany(inputs => inputs);

                var subscriptions = mSubscriptionsByObservableInstance
                                    .WatchValue(o.Created.SequenceId)
                                    .Take(1)
                                    .SelectMany(subs => subs);

                var call = mInstrumentedCallsCache
                           .WatchValue(o.InstrumentedCallId)
                           .Take(1)
                           .StartWith(cUnknownInstrumentedCall);

                return(new ObservableInstance(o.Created, call, inputs, subscriptions));
            }
Exemple #4
0
            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> >()));
                }
            }
Exemple #5
0
            private ISubscription CreateSubscription(NewSubscription s)
            {
                var obs = mObservableInstancesCache
                          .WatchValue(s.ObservableId)
                          .Take(1)
                          .StartWith(cUnknownObservable);

                var streamEvents = mStreamEventsBySubscription
                                   .WatchValue(s.Subscribed.SequenceId)
                                   .Take(1)
                                   .SelectMany(es => es);

                var unsubscribeEvent = mSubscriptionDisposalsCache
                                       .WatchValue(s.Subscribed.SequenceId)
                                       .Take(1);

                var allEvents = streamEvents
                                .Merge(unsubscribeEvent)
                                .StartWith(new SubscribeEvent(s.Subscribed));

                return(new Subscription(s.Subscribed.SequenceId, obs, allEvents));
            }
Exemple #6
0
 public IObservable <FileInfo> Get(FileInfoHashKey key)
 => _fileHashCache.WatchValue(key);
Exemple #7
0
            public Impl(IModelUpdateSource updateSource)
            {
                object moduleCacheLocker = new object();

                mModuleCache = updateSource.Modules
                               .ToObservableChangeSet(m => m.ModuleId)
                               .Transform(CreateModule)
                               .Synchronize(moduleCacheLocker)
                               .AsObservableCache();

                Modules = mModuleCache.Connect().SynchronizeSubscribe(moduleCacheLocker).Flatten().Select(chg => chg.Current);

                IObservable <IInstrumentedMethod> methods = updateSource.InstrumentedMethods
                                                            .Select(CreateInstrumentedMethod)
                                                            .Publish()
                                                            .ConnectForEver();

                object instrumentedMethodCacheLocker = new object();

                mInstrumentedMethodCache = methods
                                           .ToObservableChangeSet(m => m.InstrumentedMethodId)
                                           .Synchronize(instrumentedMethodCacheLocker)
                                           .AsObservableCache();

                InstrumentedMethods = mInstrumentedMethodCache.Connect().SynchronizeSubscribe(instrumentedMethodCacheLocker)
                                      .Flatten().Select(chg => chg.Current);

                object instrumentedCallsCacheLocker = new object();

                mInstrumentedCallsCache = methods.SelectMany(m => m.InstrumentedCalls)
                                          .ToObservableChangeSet(c => c.InstrumentedCallId)
                                          .Synchronize(instrumentedCallsCacheLocker)
                                          .AsObservableCache();

                InstrumentedCalls = mInstrumentedCallsCache.Connect().SynchronizeSubscribe(instrumentedCallsCacheLocker)
                                    .Flatten().Select(chg => chg.Current);

                object observableInstancesCacheLocker = new object();

                mObservableInstancesCache = updateSource.ObservableInstances
                                            .ToObservableChangeSet(o => o.Created.SequenceId)
                                            .Transform(CreateObservableInstance)
                                            .Synchronize(observableInstancesCacheLocker)
                                            .AsObservableCache();

                ObservableInstances = mObservableInstancesCache.Connect().SynchronizeSubscribe(observableInstancesCacheLocker)
                                      .Flatten().Select(chg => chg.Current);

                mSubscriptionsCache = updateSource.CreatedSubscriptions
                                      .ToObservableChangeSet(s => s.Subscribed.SequenceId)
                                      .Transform(CreateSubscription)
                                      .AsObservableCache();

                mSubscriptionDisposalsCache = updateSource.DisposedSubscriptions
                                              .ToObservableChangeSet(d => d.SubscriptionId)
                                              .Transform(d => new UnsubscribeEvent(d.Disposed))
                                              .AsObservableCache();

                mInstrumentedMethodsByModule = methods
                                               .GroupBy(m => m.Module.ModuleId)
                                               .ToObservableChangeSet(grp => grp.Key)
                                               .Transform(grp => grp.Replay().ConnectForEver())
                                               .AsObservableCache();

                mObservableInstancesByCall = updateSource.ObservableInstances
                                             .GroupBy(o => o.InstrumentedCallId)
                                             .ToObservableChangeSet(grp => grp.Key)
                                             .Transform(obses => obses.SelectMany(obs => mObservableInstancesCache.WatchValue(obs.Created.SequenceId).Take(1)).Replay().ConnectForEver())
                                             .AsObservableCache();

                mObservableInstanceInputsByOutput = updateSource.ObservableInstanceLinks
                                                    .GroupBy(l => l.OutputId)
                                                    .ToObservableChangeSet(grp => grp.Key)
                                                    .Transform(links => links.SelectMany(link => mObservableInstancesCache.WatchValue(link.InputId).Take(1)).Replay().ConnectForEver())
                                                    .AsObservableCache();

                mSubscriptionsByObservableInstance = updateSource.CreatedSubscriptions
                                                     .GroupBy(s => s.ObservableId)
                                                     .ToObservableChangeSet(grp => grp.Key)
                                                     .Transform(subs => subs.SelectMany(sub => mSubscriptionsCache.WatchValue(sub.Subscribed.SequenceId).Take(1)).Replay().ConnectForEver())
                                                     .AsObservableCache();

                mStreamEventsBySubscription = updateSource.StreamEvents
                                              .GroupBy(e => e.SubscriptionId)
                                              .ToObservableChangeSet(grp => grp.Key)
                                              .Transform(es => es.Select(CreateStreamEvent).Replay().ConnectForEver())
                                              .AsObservableCache();

                mTypeInfoCache = updateSource.Types
                                 .ToObservableChangeSet(t => t.TypeId)
                                 .AsObservableCache();

                mObjectPropertiesInfoByObjectId = updateSource.ObjectPropertiesInfos
                                                  .ToObservableChangeSet(info => info.ObjectId)
                                                  .AsObservableCache();

                var clientEvents = updateSource.ClientEvents.Replay();

                clientEvents.Connect();
                ClientEvents = clientEvents.AsObservable();
            }
        public KeepItemSelected(IObservableCache <KeepSelectedObject, int> source)
        {
            //an observable of updates to the selected item. When selecteditem == null, do nothing
            var selectedItemUpdates = this.WhenValueChanged(x => x.SelectedItem)
                                      .Select(selected => selected == null ? Observable.Never <KeepSelectedObject>() : source.WatchValue(selected.Id))
                                      .Switch();

            //when the item updates, reset the selected item.
            _cleanUp = selectedItemUpdates.Subscribe(selected => SelectedItem = selected);
        }