/// <summary> /// Called only once during the constructor /// </summary> /// <param name="jsonPayload"></param> private void BuildSchedule(string jsonPayload) { PTC.Log.AddLine("Building schedule", Verbosity.Normal); var o = JSON.DeserializeDynamic(jsonPayload); SchedulerItems = new List <SchedulerItem>(); for (int n = 0; n < o.Count; n++) { SchedulerItem si = new SchedulerItem(); //si.Type = (SchedulerItemType)Enum.ToObject(typeof(SchedulerItemType), (int)o[n]["type"]); si.At = o[n].ContainsKey("at") ? new SchedulerItemTime((string)o[n]["at"]) : null; string[] parsedCalls = ParseCall((string)o[n]["call"]); si.Assembly = parsedCalls[0]; si.Class += parsedCalls[1]; si.Call = parsedCalls[2]; //if (o[n].ContainsKey("afterEndItCall")) //{ // string[] parsedafterEndItCalls = ParseCall((string)o[n]["afterEndItCall"]); // si.AfterEndItAssembly = parsedafterEndItCalls[0]; // si.AfterEndItClass += parsedafterEndItCalls[1]; // si.AfterEndItCall = parsedafterEndItCalls[2]; //} si.Id = (string)o[n]["id"]; si.EndAt = o[n].ContainsKey("endAt") ? new SchedulerItemTime((string)o[n]["endAt"]) : null; si.ObjectId = o[n].ContainsKey("objectId") ? (string)o[n]["objectId"] : null; si.Estimate = o[n].ContainsKey("estimate") ? (int)o[n]["estimate"] : -1; //si.Every = o[n].ContainsKey("every") ? (SchedulerItemEvery)Enum.ToObject(typeof(SchedulerItemEvery), (int)o[n]["every"]) : SchedulerItemEvery.Unknown; //si.Until = o[n].ContainsKey("until") ? new SchedulerItemTime((string)o[n]["until"]) : null; //si.Required = o[n].ContainsKey("required") ? (bool)o[n]["required"] : false; //si.MustComplete = o[n].ContainsKey("mustComplete") ? ((string)o[n]["mustComplete"]).Split(',').ToList() : null; si.MarkedComplete = false; SchedulerItems.Add(si); PTC.Log.AddLine("SchedulerItem item added. id: " + si.Id, Verbosity.Verbose); } }
public bool ItemIsWithinCurrentTime(ZonedDateTime zdt, SchedulerItem si) { bool result = false; int currentMs = (zdt.Hour * 3600000) + (zdt.Minute * 60000) + (zdt.Second * 1000); int startMs = (si.At.H * 3600000) + (si.At.M * 60000) + (si.At.S * 1000); int estimate = 0; if (si.EndAt == null) { estimate = si.Estimate; } else { estimate = ((si.EndAt.H * 3600000) + (si.EndAt.M * 60000) + (si.EndAt.S * 1000)) - startMs; } int endMs = startMs + estimate; return(currentMs >= startMs && currentMs <= endMs); }