Exemple #1
0
            public static ActiveEvent FromExt(ActiveEventExt item)
            {
                var rv = new ActiveEvent()
                {
                    Start   = item.OriginalStart,
                    End     = item.End,
                    Hash    = item.Hash,
                    Key     = item.Key,
                    Payload = item.Payload
                };

                return(rv);
            }
Exemple #2
0
        // The "SkipBuffering" tells us that we're at the end of a round, called from "purge". Rather than buffering this, we should
        // just issue it as a begin event.
        private void ActOnStart(TPayload payload, TKey key, int hash, long eventstart, bool skipBuffering = false)
        {
            var lookupStart = new KHP // we look up start events by Hash, Key, Payload
            {
                Hash    = hash,
                Key     = key,
                Payload = payload
            };

            // We should match ONLY on
            bool foundInClosedEvents = this.ClosedEvents.entries[this.ClosedEventsIndex].value.ContainsKey(eventstart) && this.ClosedEvents.entries[this.ClosedEventsIndex].value[eventstart].Lookup(lookupStart, out _);

            if (foundInClosedEvents)
            {
                // reopen it! Make sure that we squirrel away the ORIGINAL start time as VALUE, and the MOST RECENT as the Key
                var original    = RemoveOne(this.ClosedEvents.entries[this.ClosedEventsIndex].value[eventstart], lookupStart); //  .entries[indx].value; // this has the original start time
                var originalExt = new ActiveEventExt
                {
                    OriginalStart = original.Start,
                    Start         = eventstart,
                    End           = StreamEvent.InfinitySyncTime,
                    Hash          = hash,
                    Key           = key,
                    Payload       = payload
                };

                InsertOrAppend(this.OpenEvents.entries[this.OpenEventsIndex].value, lookupStart, originalExt);
            }
            else
            {
                // We MIGHT match an open event. We need to search through anything that might be in
                // OpenEvents[ lookupStart ] to see if it's there.
                // Matching an "open" event means that we've already got something like
                // BEGIN( Payload = P, Start = 0 )
                // BEGIN( Payload = P, Start = 1 )
                // END  ( Payload = P, End = 1, Start = 0)
                // In this case, we don't want to issue a new Start on the second Begin--instead, we
                // want to wait for the Begin and get rid of it.
                bool candidatesInOpenEvents = this.OpenEvents.entries[this.OpenEventsIndex].value.Lookup(lookupStart, out var indx);

                if (candidatesInOpenEvents && !skipBuffering && this.OpenEvents.entries[this.OpenEventsIndex].value.entries[indx].value.Count > 0)
                {
                    // We found a matching event. What we need to do is squirrel this away until the
                    // end of the time step.
                    // Every time we see an END event, we'll check if it matches this squirreled-away
                    // event. If it does, well and good; we'll process the END , then this
                    // If it doesn't, we should issue a brand new Start, as below
                    if (this.CurrentTimeOpenEventBuffer.entries[this.CurrentTimeOpenEventBufferIndex].value.Lookup(lookupStart, out int ctoindx))
                    {
                        this.CurrentTimeOpenEventBuffer.entries[this.CurrentTimeOpenEventBufferIndex].value.entries[ctoindx].value++;
                    }
                    else
                    {
                        this.CurrentTimeOpenEventBuffer.entries[this.CurrentTimeOpenEventBufferIndex].value.Insert(lookupStart, 1);
                    }
                    this.CurrentTimeOpenEventBufferTime.entries[this.CurrentTimeOpenEventBufferTimeIndex].value = eventstart;
                }
                else
                { // issue a brand new start
                    var activeEventExt = new ActiveEventExt
                    {
                        Hash          = hash,
                        Key           = key,
                        Payload       = payload,
                        Start         = eventstart,
                        OriginalStart = eventstart,
                        End           = StreamEvent.InfinitySyncTime
                    };

                    // brand new event! Issue a public version
                    Emit(ActiveEvent.FromExt(activeEventExt));
                    InsertOrAppend(this.OpenEvents.entries[this.OpenEventsIndex].value, lookupStart, activeEventExt);
                }
            }
        }