public override void WriteXml(XmlWriter writer) { writer.WriteAttributeString("type", type.ToString()); writer.WriteAttributeString("frequency", frequency.ToString()); writer.WriteAttributeString("executionTime", executionTime.ToString("O")); writer.WriteAttributeString("weeklySchedule", weeklySchedule.ToString()); writer.WriteAttributeString("monthlySchedule", monthlySchedule.ToString()); writer.WriteAttributeString("lastRun", LastRun.ToString("O")); writer.WriteAttributeString("nextRun", NextRunCache.ToString("O")); }
public override int GetHashCode() { unchecked { int hashCode = StationYear.GetHashCode();//(StationYear != null ? StationYear.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Priority; hashCode = (hashCode * 397) ^ RequestTime.GetHashCode(); hashCode = (hashCode * 397) ^ LastRun.GetHashCode();//(LastRun != null ? LastRun.GetHashCode() : 0); return(hashCode); } }
/// <summary> /// This will check to see if the schedule item should kick off at the time specified. /// </summary> /// <param name="checkTime">The date/time to check if the task should kick off at.</param> /// <param name="tickerIntervalSeconds">The ticker interval. This is the window in which /// the task can kick off only once.</param> /// <returns> /// True if the task should kick off, false otherwise. /// </returns> public override bool ShouldRun(DateTime checkTime, int tickerIntervalSeconds) { int timeSeconds = (int)Time.TimeOfDay.TotalSeconds; int triggerStartSeconds = (int)checkTime.TimeOfDay.TotalSeconds; int triggerEndSeconds = triggerStartSeconds + tickerIntervalSeconds; bool timeTriggered = timeSeconds >= triggerStartSeconds && timeSeconds <= triggerEndSeconds; return(timeTriggered && LastRun.AddSeconds(tickerIntervalSeconds) < checkTime); }
public void MergeFrom(Hook other) { if (other == null) { return; } if (other.Name.Length != 0) { Name = other.Name; } if (other.Kind.Length != 0) { Kind = other.Kind; } if (other.Path.Length != 0) { Path = other.Path; } if (other.Manifest.Length != 0) { Manifest = other.Manifest; } events_.Add(other.events_); if (other.lastRun_ != null) { if (lastRun_ == null) { lastRun_ = new global::Google.Protobuf.WellKnownTypes.Timestamp(); } LastRun.MergeFrom(other.LastRun); } if (other.Weight != 0) { Weight = other.Weight; } deletePolicies_.Add(other.deletePolicies_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); }
public override int GetHashCode() { int hash = 1; if (Name.Length != 0) { hash ^= Name.GetHashCode(); } if (Kind.Length != 0) { hash ^= Kind.GetHashCode(); } if (Path.Length != 0) { hash ^= Path.GetHashCode(); } if (Manifest.Length != 0) { hash ^= Manifest.GetHashCode(); } hash ^= events_.GetHashCode(); if (lastRun_ != null) { hash ^= LastRun.GetHashCode(); } if (Weight != 0) { hash ^= Weight.GetHashCode(); } hash ^= deletePolicies_.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public void DoAllTheThings() { try { //so times match, it doesn't matter if they are off by ~20 seconds... rather have keys match in AWS DateTime NowTime = DateTime.Now; //reset from last time SortedList <Room, int> allRooms = new SortedList <Room, int>(); List <VerboseLog> verboseLogOfActions = new List <VerboseLog>(); //Get TemperatureDefaults this.TempDefaults = AWSCommunication.GetTemperatureDefaults(); this.TempDefaults.GetForecast(); //Get All Rooms var allRoomsFromAWS = AWSCommunication.GetAllRooms(); //Get All Room Temps List <RoomStatus> allRoomStatus = new List <RoomStatus>(); foreach (Room aRoom in allRoomsFromAWS) { RoomStatus aStatus = new RoomStatus(NowTime, aRoom, this.TempDefaults); allRoomStatus.Add(aStatus); allRooms.Add(aRoom, aRoom.EMSRoomID); } //Store unit status AWSCommunication.BatchWriteRoomStatusToAWS(allRoomStatus); //Get All EMS Events List <Event> events; if (this.TheLastRun == null) { this.TheLastRun = AWSCommunication.GetMostRecentLastRun(); } if (this.TheLastRun != null) { events = EMSCommunication.GetRecentEvents(this.TheLastRun.LastRunTime); } else { events = EMSCommunication.GetRecentEvents(DateTime.Now.AddDays(-7)); } List <Room> alreadySet = new List <Room>(); //Set room temps based on events foreach (Event anEvent in events) { //assume no one is in a room bool isOccupied = false; //only if the room has an EMS identity if (anEvent.RoomID > 0 && allRooms.ContainsValue(anEvent.RoomID)) { //if an event is just too long... ignore it if ((anEvent.TimeEventEnd - anEvent.TimeEventStart).TotalDays > 2) { continue; } //Event is over if (anEvent.TimeEventEnd >= DateTime.Now) { continue; } //Event is still going on if (anEvent.TimeEventStart <= DateTime.Now && anEvent.TimeEventEnd >= DateTime.Now) { isOccupied = true; } //Event is happening in the next 2 hours if (anEvent.TimeEventStart >= DateTime.Now && anEvent.TimeEventStart <= DateTime.Now.AddHours(2)) { isOccupied = true; } if (isOccupied) { foreach (Room aUnit in allRooms.Keys) { if (aUnit.EMSRoomID == anEvent.RoomID) { //Set temp string whatTemp = this.SetRoomTemp(aUnit, isOccupied); if (XMLConfigData.VerboseLoggingToAWS) { verboseLogOfActions.Add(new VerboseLog(NowTime, aUnit.UnitID, aUnit.EMSRoomID, isOccupied, whatTemp, "Event Going on", anEvent.EventName, anEvent.TimeEventStart, anEvent.TimeEventEnd)); } //If we just set a room based on an event, don't set it again if (!alreadySet.Contains(aUnit)) { alreadySet.Add(aUnit); } } } } } } //being lazy instead of walking the list backwards... foreach (Room toRemove in alreadySet) { allRooms.Remove(toRemove); } //Set room temps based on office schedules foreach (Room aRoom in allRooms.Keys) { bool isOccupied = false; if (aRoom.IsOffice) { //check hours string today = DateTime.Now.ToString("yyyy-MM-dd"); DateTime startTime = DateTime.Parse(today + " " + aRoom.StartHour); DateTime endTime = DateTime.Parse(today + " " + aRoom.EndHour); if (DateTime.Now > startTime && DateTime.Now < endTime) { isOccupied = true; } switch (DateTime.Now.Day) { case 0: if (aRoom.SundayOff) { isOccupied = false; } break; case 1: if (aRoom.MondayOff) { isOccupied = false; } break; case 2: if (aRoom.TuesdayOff) { isOccupied = false; } break; case 3: if (aRoom.WednesdayOff) { isOccupied = false; } break; case 4: if (aRoom.ThursdayOff) { isOccupied = false; } break; case 5: if (aRoom.FridayOff) { isOccupied = false; } break; case 6: if (aRoom.SaturdayOff) { isOccupied = false; } break; } } //Set temp string whatTemp = this.SetRoomTemp(aRoom, isOccupied); if (XMLConfigData.VerboseLoggingToAWS) { verboseLogOfActions.Add(new VerboseLog(NowTime, aRoom.UnitID, aRoom.EMSRoomID, isOccupied, whatTemp, "Regular Hours, No Events")); } } //Add all the events for today to the online calendar int numOfUpdates = AWSCommunication.BatchWriteEventsToAWS(events); //Log this run LastRun theLastRun = new LastRun(NowTime, NowTime, NowTime.ToShortDateString(), "Success", "", numOfUpdates); AWSCommunication.SaveLastRun(theLastRun, true); this.TheLastRun = theLastRun; if (XMLConfigData.VerboseLoggingToAWS) { AWSCommunication.BatchWriteVerboseLogToAWS(verboseLogOfActions); } } catch (Exception ex) { try { LastRun theLastRun = new LastRun(DateTime.Now, DateTime.Now, DateTime.Now.ToShortDateString(), "Fail", "Exception!: " + ex.Message, 0); AWSCommunication.SaveLastRun(theLastRun, false); } catch (Exception e) { //darn... string output = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EMSToAWSServiceERROR.txt"; StreamWriter ops = new StreamWriter(output, true); ops.WriteLine("EMS To AWS Error"); ops.WriteLine("There was an error writing the error to the error log!"); ops.WriteLine("The Network is probably down...or something network/AWS access related. Check that or the AWS Credentials"); ops.WriteLine("Error Follows"); ops.WriteLine(e.Message); ops.WriteLine(e.InnerException); ops.Flush(); ops.Close(); ops.Dispose(); } } }
public override string ToString() => $"{FileName} ({_rows.Count}) {LastRun?.ToString() ?? ""}";
/// <summary> /// основной метод потока /// </summary> public void Run() { try { //Установить статус работы _serviceStatus = "RUN"; _errorMessage = ""; AfterStart(); //Постоянная работа int cyclecnt = 0; bool start = false; LastRun = DateTime.Now; while (true) { DateTime now = DateTime.Now; //Пауза для уменьшения нагрузки на процессор if (_interval > 0) { int delta = (int)(now - LastRun).TotalMilliseconds; int d = _interval - delta - 50; if (d > 50) { start = false; Thread.Sleep(50); } else if (d > 0) { //Сохраним дату и время начала прогона LastRun = LastRun.AddMilliseconds(_interval); //_server.LogWrite(LogType.DEBUG, "d > 0 && d < 50"); start = true; } else if (d < 0) { //Сохраним дату и время начала прогона с коррекцией на выход из интервала LastRun = LastRun.AddMilliseconds(_interval - d); //_server.LogWrite(LogType.DEBUG, "d < 0"); //LastRun = now; start = true; } } else { //Сохраним дату и время начала прогона LastRun = now; start = true; } if (start) { if (TestExpr(_startif))//есть условие запуска { //Работа на один прогон RunOnce(); //Фиксация результата RunStatus(); } //Сбросим счётчик ошибок FailCount = 0; //Плановый останов cyclecnt++; if (_maxcycle > 0 && cyclecnt > _maxcycle) { break; } } if (IsBreak) { break; //остановить поток } } } catch (Exception e) { //Ошибка работы сервиса _serviceStatus = "ERROR"; _errorMessage = e.Message; log.Warn("[" + this._name + "] Аварийное завершение потока : " + e.ToString()); } finally { BeforeStop(); } }