Beispiel #1
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing)
            {
                if (Timer != null)
                {
                    Timer.Dispose();
                    Timer = null;
                }
                if (PauseEvent != null)
                {
                    PauseEvent.Close();
                    PauseEvent.Dispose();
                    PauseEvent = null;
                }
                if (RunEvent != null)
                {
                    RunEvent.Close();
                    RunEvent.Dispose();
                    RunEvent = null;
                }
                if (UnityFactory != null)
                {
                    UnityFactory.Container.Dispose();
                    UnityFactory = null;
                }
            }

            disposed = true;
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Location,Date,DistanceLength,DistanceMetric,CompetitionCode,TypeCode")] RunEvent runEvent)
        {
            if (id != runEvent.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(runEvent);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RunEventExists(runEvent.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(runEvent));
        }
Beispiel #3
0
        /// <summary>
        /// 删除执行前事件
        /// </summary>
        /// <param name="name">事件名称</param>
        /// <param name="tense">时态</param>
        /// <param name="stage">阶段</param>
        /// <returns>删除成功返回true,是失败返回false</returns>
        public bool Del(string name, string tense = null, string stage = null)
        {
            var bl = false;

            if (string.IsNullOrEmpty(stage))
            {
                CheckEvent.Del(name, tense);
                RunEvent.Del(name, tense);
                RenderEvent.Del(name, tense);
                bl = true;
            }
            else
            {
                switch (stage.ToLower())
                {
                case "check":
                    CheckEvent.Del(name, tense);
                    break;

                case "run":
                    RunEvent.Del(name, tense);
                    break;

                case "render":
                    RenderEvent.Del(name, tense);
                    break;
                }
            }
            return(bl);
        }
        public IList <RunEvent> Convert(RunImport run)
        {
            var events = _component.Convert(run);

            foreach (var playerAchievements in run.Achievements)
            {
                var playerId = playerAchievements.Key;
                foreach (var achievement in playerAchievements.Value)
                {
                    if (EventNames.AdvancementTranslation.ContainsKey(achievement.Event))
                    {
                        var value    = EventNames.AdvancementTranslation[achievement.Event];
                        var runEvent = new RunEvent(
                            EventTypes.Advancement,
                            achievement.Timestamp,
                            value,
                            playerId);

                        if (!events.Contains(runEvent))
                        {
                            events.Add(runEvent);
                        }
                    }
                }
            }

            return(events);
        }
        public void Update(NumericType numericType)
        {
            if (numericType < NumericType.Max)
            {
                return;
            }
            int final    = (int)numericType / 10;
            int bas      = final * 10 + 1;
            int add      = final * 10 + 2;
            int pct      = final * 10 + 3;
            int finalAdd = final * 10 + 4;
            int finalPct = final * 10 + 5;

            // 一个数值可能会多种情况影响,比如速度,加个buff可能增加速度绝对值100,也有些buff增加10%速度,所以一个值可以由5个值进行控制其最终结果
            // final = (((base + add) * (100 + pct) / 100) + finalAdd) * (100 + finalPct) / 100;
            int old    = this.NumericDic[final];
            int result = (int)(((this.GetByKey(bas) + this.GetByKey(add)) * (100 + this.GetAsFloat(pct)) / 100f + this.GetByKey(finalAdd)) * (100 + this.GetAsFloat(finalPct)) / 100f * 10000);

            this.NumericDic[final] = result;
            RunEvent.Publish(new NumbericChange()
            {
                Parent      = this.Parent,
                NumericType = (NumericType)final,
                Old         = old,
                New         = result
            }).Coroutine();
        }
Beispiel #6
0
        /// <summary>
        /// 获取事件
        /// </summary>
        /// <param name="name">事件名称</param>
        /// <param name="tense">时态</param>
        /// <param name="stage">阶段</param>
        /// <returns>返回执行前事件</returns>
        public List <EventConfig> Get(string name, string tense = null, string stage = null)
        {
            List <EventConfig> list = new List <EventConfig>();

            if (string.IsNullOrEmpty(stage))
            {
                list.Add(CheckEvent.Get(name, tense));
                list.Add(RunEvent.Get(name, tense));
                list.Add(RenderEvent.Get(name, tense));
            }
            else
            {
                switch (stage.ToLower())
                {
                case "check":
                    list.Add(CheckEvent.Get(name, tense));
                    break;

                case "run":
                    list.Add(RunEvent.Get(name, tense));
                    break;

                case "render":
                    list.Add(RenderEvent.Get(name, tense));
                    break;
                }
            }
            return(list);
        }
Beispiel #7
0
 public void Handle(RunEvent message)
 {
     if (CanRunScript)
     {
         RunScript();
     }
 }
Beispiel #8
0
 private void simpleButton1_Click(object sender, EventArgs e)
 {
   String t = comboBoxEdit1.Text;
   Thread th;
   var info  = t.Split('|');
   if(info.Length == 2)
   {
     var plug = GetSrcPlug(info[0]);
     if(plug != null)
     {
       if(!plug.SetCurentDeviceID(info[1]))
       {
         MessageBox.Show("找不到视频源", "显示视频失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
       }
       if(runEvent_ != null)
       {
         runEvent_.stop = true;
       }
       runEvent_ = new RunEvent(OnLiveDataReady, null);
       plug.SetRunEvent(runEvent_);
       th = new Thread(() =>{
             plug.Run();
       });
       th.IsBackground = true;
       th.Start();
     }
   }
   else
   {
     MessageBox.Show("找不到视频源", "显示视频失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
   }
 }
Beispiel #9
0
        private void initializeRunEventsInRange()
        {
            if (_runEventsInRange != null)
            {
                return;
            }

            RunEvent lastStateRunEventInRange = null;
            RunEvent tempRunEventToRemoveIfNotLastBeforeExportStart = null;

            _runEventsInRange = new List <RunEvent>(run.SortedRunEvents);

            foreach (RunEvent runEvent in run.SortedRunEvents)
            {
                if (runEvent.TimeTracked < exportSettings.ExportStart * 1000)
                {
                    if (runEvent.Behavior.Type == Behavior.BehaviorType.State)
                    {
                        lastStateRunEventInRange = runEvent;
                    }
                    if (tempRunEventToRemoveIfNotLastBeforeExportStart != null)
                    {
                        _runEventsInRange.Remove(tempRunEventToRemoveIfNotLastBeforeExportStart);
                    }
                    tempRunEventToRemoveIfNotLastBeforeExportStart = runEvent;
                }
                if (runEvent.TimeTracked >= exportSettings.ExportEnd * 1000)
                {
                    _runEventsInRange.RemoveAll(new Predicate <RunEvent>(r => (r.TimeTracked >= runEvent.TimeTracked)));
                    break;
                }
            }
        }
Beispiel #10
0
        public virtual void Pause()
        {
            try
            {
                PauseEvent.Set();
                //Timer.Change(Timeout.Infinite, Timeout.Infinite);

                // Wait for any current execution to finish
                var timeout = Profile.StopTaskTimeout;
                if (RunEvent.WaitOne(0))
                {
                    ServiceProfile.Service.RequestAdditionalTime((int)timeout.TotalMilliseconds);
                    if (RunEvent.WaitOne(timeout))
                    {
                        LogWarning("still running during Pause process. Wait timer exceeded.");
                    }
                }

                State = TaskState.Paused;
            }
            catch (Exception e)
            {
                LogException(e, "failed Pause process.");
            }
        }
Beispiel #11
0
        public virtual void Stop()
        {
            try
            {
                Timer.Change(Timeout.Infinite, Timeout.Infinite);

                // wait for any executions to finish
                if (RunEvent.WaitOne(0))
                {
                    var timeout = Profile.StopTaskTimeout;
                    ServiceProfile.Service.RequestAdditionalTime((int)timeout.TotalMilliseconds);
                    if (RunEvent.WaitOne(timeout))
                    {
                        LogWarning("wait timer exeeded Stop process.");
                    }
                }

                LogMessage("stopped.");

                // At this point we stop regardless...
                Dispose();
                State = TaskState.Stopped;
            }
            catch (Exception e)
            {
                LogException(e, "failed Stop process.");
            }
        }
Beispiel #12
0
        private void calculateCounters(List <RunEvent> runEventsInRange)
        {
            RunEvent lastStateRunEvent = runEventsInRange[0];

            foreach (RunEvent runEvent in runEventsInRange)
            {
                // calculate frequency
                behaviorFrequency[runEvent.Behavior]++;

                // ignore first event since we calculate diffs with previous event time
                if (runEvent.TimeTracked <= exportSettings.ExportStart * 1000)
                {
                    lastStateRunEvent = runEvent;
                    continue;
                }

                if (runEvent.Behavior.Type == Behavior.BehaviorType.State)
                {
                    double eventStart           = Math.Max(lastStateRunEvent.TimeTrackedInSeconds, exportSettings.ExportStart);
                    double currentEventDuration = runEvent.TimeTrackedInSeconds - eventStart;
                    // State Behaviors Duration
                    stateBehaviorTotalDuration[lastStateRunEvent.Behavior] += currentEventDuration;

                    // Latency
                    if (runEvent.TimeTrackedInSeconds > _LATENCY_TIME_TO_IGNORE_IN_SECONDS)
                    {
                        if (currentEventDuration >= _LATENCY_MINIMUM_DURATION_IN_SECONDS)
                        {
                            if (stateBehaviorLatency[lastStateRunEvent.Behavior] == null)
                            {
                                double latencyNoticedAt = eventStart;
                                if (eventStart < _LATENCY_TIME_TO_IGNORE_IN_SECONDS)
                                {
                                    latencyNoticedAt = _LATENCY_TIME_TO_IGNORE_IN_SECONDS;
                                }
                                stateBehaviorLatency[lastStateRunEvent.Behavior] = latencyNoticedAt;
                            }
                        }
                    }

                    lastStateRunEvent = runEvent;
                }
            }

            // State Behavior Duration add the time left till the end of the run
            stateBehaviorTotalDuration[lastStateRunEvent.Behavior] += exportSettings.ExportEnd - lastStateRunEvent.TimeTrackedInSeconds;

            // state behavior latency set to trial duration if unset
            foreach (Behavior behavior in run.Trial.Session.BehavioralTest.GetBehaviors())
            {
                if (behavior.Type == Behavior.BehaviorType.State)
                {
                    if (stateBehaviorLatency[lastStateRunEvent.Behavior] == null)
                    {
                        stateBehaviorLatency[lastStateRunEvent.Behavior] = exportSettings.ExportEnd;
                    }
                }
            }
        }
Beispiel #13
0
        private static void addRunEvent(Run run, Behavior behavior, long timeTracked)
        {
            RunEvent runEvent = new RunEvent();

            runEvent.TimeTracked = timeTracked;
            runEvent.Behavior    = behavior;
            run.AddRunEvent(runEvent);
        }
Beispiel #14
0
        protected virtual void ExecuteWrapper(object stateInfo)
        {
            try
            {
                // if already running then do nothing
                if (RunEvent.WaitOne(0))
                {
                    LogWarning("another thread already running.");
                    return;
                }

                if (PauseEvent.WaitOne(0))
                {
                    LogWarning("service is paused.");
                    return;
                }

                var result = Result <string> .Success();

                var batch = new RSMDB.BatchHistory
                {
                    RunStart = DateTime.Now,
                    SystemId = this.ExternalSystem.Id,
                };

                try
                {
                    RunEvent.Set();
                    Interlocked.Increment(ref _iterations);
                    LogMessage("executing.");

                    State  = TaskState.Running;
                    result = Execute(stateInfo);
                }
                finally
                {
                    State = TaskState.Idle;
                    RunEvent.Reset();

                    using (var controller = new BatchHistories())
                    {
                        var text = result != null ? result.Entity : string.Empty;
                        var msg  = (result.Succeeded)
                                                        ? LogMessageDetail(result.ToString(), "completed. {0}", text)
                                                        : LogErrorDetail(result.ToString(), "execution failed. {0}", text);

                        batch.RunEnd  = DateTime.Now;
                        batch.Message = msg;
                        batch.Outcome = (int)result.Outcome;
                        controller.Add(batch);
                    }
                }
            }
            catch (Exception e)
            {
                LogException(e, "execution failed.");
            }
        }
Beispiel #15
0
        protected override void OnUpdate()
        {
            if (RunEvent != null)
            {
                RunEvent.Invoke();
            }

            this.Entity.RemoveComponent(this);
        }
    public static void RaiseEvent(RunEvent re)
    {
        if (re == null)
        {
            throw new System.ArgumentNullException("RunEvent must not be null");
        }

        eventQueue.AddLast(re);
    }
Beispiel #17
0
    private void RunPressed(RunEvent rei)
    {
        gameStateManager.ChangeState(gameRunState);

        //At the begining of hte program set the ui state to the menu ui elemenet
        SendUIEvent suiei = new SendUIEvent();

        suiei.uiState = UIState.RUN_HUD;
        suiei.FireEvent();
    }
Beispiel #18
0
        public async Task <IActionResult> Create([Bind("Id,Title,Location,Date,DistanceLength,DistanceMetric,CompetitionCode,TypeCode")] RunEvent runEvent)
        {
            if (ModelState.IsValid)
            {
                _context.Add(runEvent);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(runEvent));
        }
Beispiel #19
0
        public override List <string> RunData()
        {
            List <String> runData = base.RunData();

            Dictionary <Behavior, int> behaviorScoring = new Dictionary <Behavior, int>();

            // Detke Scoring
            // initialize
            foreach (Behavior behavior in run.Trial.Session.BehavioralTest.GetBehaviors())
            {
                if (behavior.Type == Behavior.BehaviorType.State)
                {
                    behaviorScoring.Add(behavior, 0);
                }
            }

            int scoringInterval = 5000;
            int scoringIndex    = 1;
            int eventIndex      = 0;

            RunEvent lastStateRunEvent = stateRunEventsInRange[0];

            eventIndex++;

            while (true)
            {
                long eventEnd = eventIndex >= stateRunEventsInRange.Count ? exportSettings.ExportEnd * 1000 :
                                Math.Max(stateRunEventsInRange[eventIndex].TimeTracked, exportSettings.ExportStart * 1000);

                if (eventEnd < scoringIndex * scoringInterval)
                {
                    lastStateRunEvent = stateRunEventsInRange[eventIndex];
                    eventIndex++;
                    continue;
                }
                else
                {
                    scoringIndex++;
                    behaviorScoring[lastStateRunEvent.Behavior]++;
                    if (scoringIndex * scoringInterval > exportSettings.ExportEnd * 1000)
                    {
                        break;
                    }
                    continue;
                }
            }

            foreach (var behaviorScore in behaviorScoring)
            {
                runData.Add(behaviorScore.Value.ToString());
            }

            return(runData);
        }
Beispiel #20
0
    //=================================================================================================================

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        //The events from the UI
        GetUIEvent.RegisterListener(GetUIInput);
        //Regestiring the events for the game states
        RunEvent.RegisterListener(RunPressed);
        WinEvent.RegisterListener(WinGame);
        DeathEvent.RegisterListener(LoseGame);

        Load();
        Init();
    }
Beispiel #21
0
        public RunEventForm(RunEvent runEvent)
            : this(runEvent.Run)
        {
            if (runEvent != null)
            {
                _runEvent = runEvent;
                _run = runEvent.Run;

                cbBehavior.SelectedItem = runEvent.Behavior;
                txtTimeTracked.Text = runEvent.TimeTrackedInSeconds.ToString("F3");
            }
        }
Beispiel #22
0
        public RunEventForm(RunEvent runEvent)
            : this(runEvent.Run)
        {
            if (runEvent != null)
            {
                _runEvent = runEvent;
                _run      = runEvent.Run;

                cbBehavior.SelectedItem = runEvent.Behavior;
                txtTimeTracked.Text     = runEvent.TimeTrackedInSeconds.ToString("F3");
            }
        }
Beispiel #23
0
        /// <summary>
        /// 执行事件
        /// </summary>
        /// <param name="tag">标签</param>
        /// <param name="target">目标</param>
        /// <returns>返回执行结果</returns>
        public object Run(string tag, string target)
        {
            var ret = CheckEvent.Run(tag, target);

            if (ret == null)
            {
                ret = RunEvent.Run(tag, target, ret);
            }
            var result = RenderEvent.Run(tag, target, ret);

            if (result != null)
            {
                ret = result;
            }
            return(ret);
        }
        public void AddRunEvent(RunEvent runEvent)
        {
            UpdateInterval(runEvent.TimeTracked);

            switch (runEvent.Behavior.Type)
            {
                case Behavior.BehaviorType.State:
                    _lastStateBehavior = runEvent.Behavior;
                    break;
                case Behavior.BehaviorType.Instant:
                    _instantBehaviorCounts[runEvent.Behavior]++;
                    break;
            }

            UpdateDurationCountCells();
        }
Beispiel #25
0
        /// <summary>
        /// 执行事件(异步)
        /// </summary>
        /// <param name="tag">标签</param>
        /// <param name="target">目标</param>
        /// <returns>返回执行结果</returns>
        public async Task <object> RunAsync(string tag, string target)
        {
            var ret = await CheckEvent.RunAsync(tag, target);

            if (ret == null)
            {
                ret = await RunEvent.RunAsync(tag, target, ret);
            }
            var result = await RenderEvent.RunAsync(tag, target, ret);

            if (result != null)
            {
                ret = result;
            }
            return(ret);
        }
Beispiel #26
0
        private void btnRunEvent_Click(object sender, EventArgs e)
        {
            foreach (Form c in this.ParentForm.MdiChildren)
            {
                if (c.GetType() == new RunEvent().GetType())
                {
                    re = true;
                }
            }

            if (!re)
            {
                RunEvent runEvent = new RunEvent();
                runEvent.MdiParent = this.ParentForm;
                runEvent.Show();
            }
        }
Beispiel #27
0
        public void AddRunEvent(RunEvent runEvent)
        {
            UpdateInterval(runEvent.TimeTracked);

            switch (runEvent.Behavior.Type)
            {
            case Behavior.BehaviorType.State:
                _lastStateBehavior = runEvent.Behavior;
                break;

            case Behavior.BehaviorType.Instant:
                _instantBehaviorCounts[runEvent.Behavior]++;
                break;
            }

            UpdateDurationCountCells();
        }
Beispiel #28
0
        public List <TimeBin> calculateTimeBins()
        {
            RunEvent lastStateRunEvent = stateRunEventsInRange[0];

            int eventIndex = 1;
            int binIndex   = 0;

            while (true)
            {
                TimeBin currentBin = timeBins[binIndex];

                long eventEnd = (eventIndex >= stateRunEventsInRange.Count) ? exportSettings.ExportEnd * 1000 :
                                Math.Max(stateRunEventsInRange[eventIndex].TimeTracked, exportSettings.ExportStart * 1000);

                long eventStartInBin = Math.Max(lastStateRunEvent.TimeTracked, currentBin.start);
                long eventEndInBin   = Math.Min(eventEnd, currentBin.end);

                double currentEventDurationInBin = eventEndInBin - eventStartInBin;

                currentBin.stateBehaviorTotalDuration[lastStateRunEvent.Behavior] += currentEventDurationInBin;

                if (eventEnd < currentBin.end)
                {
                    if (eventIndex >= stateRunEventsInRange.Count)
                    {
                        break;
                    }
                    lastStateRunEvent = stateRunEventsInRange[eventIndex];
                    eventIndex++;
                    continue;
                }
                else
                {
                    binIndex++;
                    if (binIndex >= timeBins.Count)
                    {
                        break;
                    }
                    continue;
                }
            }

            return(timeBins);
        }
Beispiel #29
0
 private void Run_ToolStripButton_Click(object sender, EventArgs e)
 {
     for (int z = 0; z < tabControlCode.TabCount; z++)
     {
         for (int k = 0; k < proj.csfile.Count; k++)
         {
             if (proj.csfile[k].Name == tabControlCode.TabPages[z].Text)
             {
                 foreach (FastColoredTextBox item in tabControlCode.TabPages[z].Controls)
                 {
                     this.proj.csfile[k].Text = item.Text;
                 }
             }
         }
     }
     RunEvent?.Invoke(this, new ProjectEventArgs()
     {
         project = this.proj
     });
 }
Beispiel #30
0
        private void Run_ToolStripButton_Click(object sender, EventArgs e)
        {
            for (var z = 0; z < tabControlCode.TabCount; z++)
            {
                foreach (var t in _proj.CsFile)
                {
                    if (t.Name != tabControlCode.TabPages[z].Text)
                    {
                        continue;
                    }
                    foreach (FastColoredTextBox item in tabControlCode.TabPages[z].Controls)
                    {
                        t.Text = item.Text;
                    }
                }
            }

            RunEvent?.Invoke(this, new ProjectEventArgs {
                Project = _proj
            });
        }
Beispiel #31
0
        private void toolStripButtonRun_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < tabControlCode.TabCount; i++)
            {
                if (tabControlCode.TabPages[i].Focus())
                {
                    foreach (FastColoredTextBox item in tabControlCode.TabPages[i].Controls)
                    {
                        if (item is FastColoredTextBox)
                        {
                            this.project.csfile[i].Text = item.Text;
                        }
                    }

                    RunEvent?.Invoke(this, new CSEventArgs()
                    {
                        cS = this.project.csfile[i]
                    });
                }
            }
        }
Beispiel #32
0
        private void Key(Keys key)
        {
            bool     firstKey = false;
            Behavior behavior = GetBehaviorByKeyStroke(key);

            if (_runStatus == RunStatus.Ready &&
                behavior != null &&
                behavior.Type == Behavior.BehaviorType.State)
            {
                Start();
                firstKey = true;
            }

            long elapsedMilliseconds = _stopwatch.ElapsedMilliseconds;

            if (_runStatus == RunStatus.Running && elapsedMilliseconds <= _durationMilliseconds)
            {
                if (behavior != null && behavior != _lastStateBehavior)
                {
                    RunEvent runEvent = new RunEvent()
                    {
                        Behavior    = behavior,
                        Run         = _run,
                        TimeTracked = firstKey ? 0 : elapsedMilliseconds
                    };
                    _runEvents.Add(runEvent);
                    foreach (IEventVisualiser eventVisualiser in _eventVisualisers)
                    {
                        eventVisualiser.AddRunEvent(runEvent);
                    }

                    if (behavior.Type == Behavior.BehaviorType.State)
                    {
                        _lastStateBehavior = behavior;
                        RefreshStateBehaviorLabel(behavior);
                    }
                }
            }
        }
 public void AddRunEvent(RunEvent runEvent)
 {
     AppendLine(string.Format("Behavior {0} at time {1}.", runEvent.Behavior, runEvent.TimeTrackedInSeconds));
 }
Beispiel #34
0
        private void Key(Keys key)
        {
            bool firstKey = false;
            Behavior behavior = GetBehaviorByKeyStroke(key);

            if (_runStatus == RunStatus.Ready
                && behavior != null
                && behavior.Type == Behavior.BehaviorType.State)
            {
                Start();
                firstKey = true;
            }

            long elapsedMilliseconds = _stopwatch.ElapsedMilliseconds;
            if (_runStatus == RunStatus.Running && elapsedMilliseconds <= _durationMilliseconds)
            {
                if (behavior != null && behavior != _lastStateBehavior)
                {
                    RunEvent runEvent = new RunEvent()
                    {
                        Behavior = behavior,
                        Run = _run,
                        TimeTracked = firstKey ? 0 : elapsedMilliseconds
                    };
                    _runEvents.Add(runEvent);
                    foreach (IEventVisualiser eventVisualiser in _eventVisualisers)
                    {
                        eventVisualiser.AddRunEvent(runEvent);
                    }

                    if (behavior.Type == Behavior.BehaviorType.State)
                    {
                        _lastStateBehavior = behavior;
                        RefreshStateBehaviorLabel(behavior);
                    }
                }
            }
        }
        public void AddRunEvent(RunEvent runEvent)
        {
            Monitor.Enter(this);

            UpdateLastStateRectangle(runEvent.TimeTracked);

            double rectangleTop = _lastStateRectangle.IsEmpty ? _marginInRow : _lastStateRectangle.Y;

            ColoredRectangle newRectangle = new ColoredRectangle(
                _behaviorColorAssigner.GetBehaviorColor(runEvent.Behavior),
                _lastPositionInRow, rectangleTop, 0, _rectangleHeight);

            if (runEvent.Behavior.Type == Behavior.BehaviorType.Instant)
            {
                // Half margin for Instant events
                newRectangle.Y -= _marginInRow / 2.0;
                newRectangle.Height += _marginInRow;

                newRectangle.X -= InstantEventWidthPercentage / 2.0;
                newRectangle.Width += InstantEventWidthPercentage;

                _instantRectangles.Add(newRectangle);
            }
            else
            {
                if (!_lastStateRectangle.IsEmpty)
                {
                    _oldStateRectangles.Add(_lastStateRectangle);
                }

                _lastStateRectangle = newRectangle;
            }

            InvalidateRectangle(newRectangle);

            Monitor.Exit(this);
        }