public static PlayerActionEvents Map(this PlayerActionEvents toItems, ActionRequests fromItems, Actions actions) { toItems.Clear(); foreach (var fromItem in fromItems) { toItems.Add(new PlayerActionEvent().Map(fromItem, actions)); } return(toItems); }
/// <summary> /// Method to return those ActionRequests that qualify to be applid to a Goal based on Recurrance /// </summary> /// <param name="goalTrigger"></param> /// <param name="actionRequests"></param> /// <param name="actions"></param> /// <returns></returns> public static ActionRequests RecurranceQualifyingActionRequestsByGoalTriggerSteps( this GoalTrigger goalTrigger, ActionRequests actionRequests ) { var qualifyingActions = new ActionRequests(); foreach (var step in goalTrigger.Steps) { var start = goalTrigger.ReleaseOn.UtcDateTime.Date.AddMinutes( step.PeriodRecurrence.PeriodMinuteBeginOn.Value); var duration = step.PeriodRecurrence.PeriodTimeSpan.GetValueOrDefault(); // An event taking place between PeriodBeginOn + PeriodTimeSpan var vEvent = new CalendarEvent { Start = new CalDateTime(start), Duration = duration }; vEvent.RecurrenceRules = new List <RecurrencePattern> { new RecurrencePattern(step.PeriodRecurrence.PeriodPattern) }; var searchStart = DateTime.UtcNow.AddYears(-1).Date; var searchEnd = DateTime.UtcNow.Date; var calendar = new Calendar(); calendar.Events.Add(vEvent); var occurrences = calendar.GetOccurrences(searchStart, searchEnd); // do any of the ActionsRequests fall within this Step of this GoalTrigger foreach (var action in actionRequests) { // fall in recurrance date(s) if (vEvent.OccursOn(new CalDateTime(action.OccurredOn.Date))) { if ( action.OccurredOn.TimeOfDay > start.TimeOfDay && action.OccurredOn.TimeOfDay < start.Add(duration).TimeOfDay ) { // the Action occurred within a valid date and time of recurrance qualifyingActions.Add(action); } } } } return(qualifyingActions); }
public static List <ActionRequest> QualifyingActionRequestsByRecurrence(this GoalTrigger goalTrigger, ActionRequests actionRequests) { var qualifyingActionsRequests = new ActionRequests(); foreach (var rateLimitRule in goalTrigger.RateLimitRules) { // An event taking place between PeriodBeginOn + PeriodTimeSpan var vEvent = new CalendarEvent { Start = new CalDateTime(goalTrigger.ReleaseOn.UtcDateTime.Date.AddMinutes(rateLimitRule.PeriodRecurrence.PeriodMinuteBeginOn.Value)), Duration = rateLimitRule.PeriodRecurrence.PeriodTimeSpan.GetValueOrDefault() }; vEvent.RecurrenceRules = JsonConvert.DeserializeObject <List <RecurrencePattern> >( rateLimitRule.PeriodRecurrence.PeriodPattern ); var searchStart = DateTimeOffset.MinValue.DateTime; var searchEnd = DateTime.UtcNow; var calendar = new Calendar(); calendar.Events.Add(vEvent); var occurrences = calendar.GetOccurrences(searchStart, searchEnd); // do any of the ActionsRequests fall within this RateLimitRule of this GoalTrigger foreach (var actionRequest in actionRequests) { if (vEvent.OccursOn(new CalDateTime(actionRequest.OccurredOn.Date))) { // now check period hours qualifyingActionsRequests.Add(actionRequest); } } } return(qualifyingActionsRequests); }
private void Worker(object args) { var Args = (ThreadArgs)args; var HWND = Args.HWND; var HDC = IntPtr.Zero; var HGLRC = IntPtr.Zero; try { GLInit(HWND, out HDC, out HGLRC); gl.Enable(GL.BLEND); gl.BlendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA); gl.DepthMask(GL.FALSE); gl.MatrixMode(GL.PROJECTION); gl.Viewport(0, 0, ClientSize.Width, ClientSize.Height); gl.LoadIdentity(); gl.Ortho(-SurfaceSize.Width / 2f, SurfaceSize.Width / 2f, -SurfaceSize.Height / 2f, SurfaceSize.Height / 2f, 0f, 1f); GLStart?.Invoke(this, EventArgs.Empty); var FrameTimer = new Stopwatch(); while (RendererRunning) { if (FPS <= 0) { Thread.Sleep(100); } else { var delay = 1000 / FPS - (int)FrameTimer.ElapsedMilliseconds; if (delay > 0) { Thread.Sleep(delay); } FrameTimer.Restart(); lock (ActionRequests) while (ActionRequests.Count > 0) { ActionRequests.Dequeue().Invoke(); } if (!NoClear) { gl.ClearColor(BackColor.R / 256f, BackColor.G / 256f, BackColor.B / 256f, BackColor.A / 256f); gl.Clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); } GLPaint?.Invoke(this, EventArgs.Empty); gdi.SwapBuffers(HDC); } } } finally { GLStop?.Invoke(this, EventArgs.Empty); GLDispose(HWND, HDC, HGLRC); } }