internal static void _Parallel(Action <TaskItem> action1, Action <TaskItem, ThreadItem> action2, IList <TaskItem> tasks, IList <ThreadItem> threads) { int ntasks = tasks.Count; int nthreads = threads.Count; if (nthreads < 2 || ntasks < 2) // Will only be 1 thread here. { if (null != action2) { for (int i = 0; i < ntasks; i++) { action2(tasks[i], threads[0]); } } else { for (int i = 0; i < ntasks; i++) { action1(tasks[i]); } } } else // More than one thread! { int tpt = ntasks / nthreads; // Tasks per thread. if (0 != (ntasks % nthreads)) { tpt++; } List <PTO> ptos = new List <PTO>(nthreads); int offset = 0; for (int it = 0; offset < ntasks; it++) { PTO pto = new PTO(); pto.thread = new System.Threading.Thread(new System.Threading.ThreadStart(pto.threadproc)); pto.alltasks = tasks; pto.start = offset; offset += tpt; if (offset > ntasks) { offset = ntasks; } pto.stop = offset; pto.action1 = action1; pto.action2 = action2; pto.threaditem = threads[it]; ptos.Add(pto); pto.thread.Start(); } for (int i = 0; i < ptos.Count; i++) { ptos[i].thread.Join(); if (ptos[i].exception != null) { throw ptos[i].exception; } } } }
protected override void Main() { while (true) { DriveTrain.TankDrive(-DriveStick_Left.GetRawAxis(1), -DriveStick_Right.GetRawAxis(1)); if ((DriveStick_Left.GetRawAxis(1) < -0.1 || DriveStick_Right.GetRawAxis(1) < -0.1) && !Custom_Board.GetRawButton(4)) { Intake1.Set(-1); Intake2.Set(-1); } else { Intake1.Set(0); Intake2.Set(0); } if (Custom_Board.GetRawButton(4)) { Shooter.Set(.9); Agitator.Set(1); } else { Shooter.Set(0); Agitator.Set(0); } if (DriveStick_Left.GetRawButton(1) || DriveStick_Right.GetRawButton(1)) { if (flag) { Shifters.Set(!Shifters.Get()); flag = false; } } else { flag = true; } if (DriveStick_Left.GetRawAxis(2) > 0.1) { PTO.Set(true); } else { PTO.Set(false); } Shooter_Pivot.Set(.5 * Custom_Board.GetRawAxis(4)); Snooze(10); } }
public static void SetVacationSeniority(PTO pto, DateTime curDate, string month) { if (!pto.PTO_Type.IsHourType && pto.PTOType_ID == Constants.PTO_TYPE_MATERINITY_LEAVE) { PTOReportDao ptoReportDao = new PTOReportDao(); PTO_Detail ptoDetail = new PTOReportDao().GetPToDetailByPTOID(pto.ID); if (ptoDetail != null) { if (ptoDetail.DateOffFrom.HasValue) { if (ptoDetail.DateOffFrom.Value <= curDate) { DateTime datePTO_Report = DateTime.Parse(Constants.DAY_MONTH_YEAR_REPORT + month); int vacetionseniority = ptoReportDao.SetVacationSeniority(pto.Submitter, datePTO_Report); PTO_Report objReport = ptoReportDao.GetBalanceByDate(pto.Submitter, datePTO_Report); if (objReport != null) { ptoReportDao.UpdateVacationSerinority(objReport, vacetionseniority); } } } } } }
protected override void Main() { while (true) { if (Custom_Board.GetRawAxis(2) > 0.1) { Intake1.Set(-1); Intake2.Set(1); } else if (DriveStick_Right.GetRawButton(3) || Custom_Board.GetRawAxis(3) > 0.1) { Intake1.Set(1); Intake2.Set(-1); } else { Intake1.Set(0); Intake2.Set(0); } if (Custom_Board.GetRawButton(3)) { if (started) { if ((Environment.TickCount - time) > 1000) { Agitator.Set(1); IntakeSecondStage.Set(-1); } } else { time = Environment.TickCount; started = true; Shooter.Set(.95); } } else if (Custom_Board.GetRawButton(2)) { if (started) { if ((Environment.TickCount - time) > 1000) { Agitator.Set(-1); IntakeSecondStage.Set(-1); } } else { time = Environment.TickCount; started = true; Shooter.Set(.95); } } else { Shooter.Set(0); Agitator.Set(0); IntakeSecondStage.Set(0); started = false; } if (DriveStick_Left.GetRawButton(1) || DriveStick_Right.GetRawButton(1)) { if (toggleshift) { Shifters.Set(!Shifters.Get()); toggleshift = false; } } else { toggleshift = true; } if (DriveStick_Left.GetRawButton(6) && DriveStick_Right.GetRawButton(11)) { if (togglepto) { PTO.Set(!PTO.Get()); togglepto = false; } } else { togglepto = true; } if (PTO.Get()) { if (DriveStick_Right.GetRawAxis(1) >= 0) { DriveTrain.StopMotor(); } else { DriveTrain.Move(DriveStick_Right.GetRawAxis(1), DriveStick_Right.GetRawAxis(1)); } } else { DriveTrain.Move(-DriveStick_Left.GetRawAxis(1), -DriveStick_Right.GetRawAxis(1)); } if (Custom_Board.GetRawButton(4)) { GearSlot.Set(true); } else { GearSlot.Set(false); } //if (DriveStick_Left.GetRawAxis(2) > 0.1) PTO.Set(true); //else PTO.Set(false); // Set the shooter pivot to a specific point based on the joysticks. //TurntableController.Controller.Setpoint = ((encoderTicks + Custom_Board.GetRawAxis(4)) / 2); Shooter_Pivot.Set(.5 * Custom_Board.GetRawAxis(4)); Snooze(10); } }
public static void SendEmailToEmployee(PTODao ptoDao, PTO pto, List<PTO_Detail> listPTO_Detail, bool? isManager, string ccMail="") { try { EmployeeDao empDao = new EmployeeDao(); string template=""; if (pto.DeleteFlag) template = GetTemplateForDeletion; else if(isManager.HasValue) template = isManager.Value ? GetTemplateForManager : GetTemplateForEmployee; string sTemplate = string.Empty; string sFooter = GetEmailFooter(); sTemplate = template + sFooter; //PTO pto = ptoDao.GetPTOById(id); Employee emp = empDao.GetById(pto.Submitter); Employee manager = empDao.GetById(pto.SubmitTo); string actor = CommonFunc.GetEmployeeFullName(manager); sTemplate = sTemplate.Replace(Constants.PTO_EMAIL_FIELD_PTO_REASON, HttpUtility.HtmlEncode(pto.Reason)); sTemplate = sTemplate.Replace(Constants.PTO_EMAIL_FIELD_PTO_STATUS_NAME, pto.PTO_Status.Name); sTemplate = sTemplate.Replace(Constants.PTO_EMAIL_FIELD_PTO_TYPE_NAME, pto.PTO_Type.Name); string sPTO_ID = ""; string sAction = ""; string sEmailSubject = ""; string sEmpName = CommonFunc.GetEmployeeFullName(emp, Constants.FullNameFormat.FirstMiddleLast); string toEmail = pto.Employee.OfficeEmail; if (pto.DeleteFlag) { sEmailSubject = String.Format(Constants.PTO_EMAIL_SUBJECT_DELETE, pto.ID); } else if (pto.Status_ID == Constants.PTO_STATUS_NEW) { sPTO_ID = "Your PTO (" + pto.ID + ")"; sAction = "submitted to"; sEmailSubject = String.Format(Constants.PTO_EMAIL_SUBJECT_NEW, pto.ID); } else if (pto.Status_ID == Constants.PTO_STATUS_APPROVED) { sPTO_ID = "The " + pto.ID; sAction = "approved by"; sEmailSubject = String.Format(Constants.PTO_EMAIL_SUBJECT_APPROVE_REJECT, pto.ID, "approved"); } else if (pto.Status_ID == Constants.PTO_STATUS_REJECTED) { sPTO_ID = "The " + pto.ID; sAction = "rejected by"; sEmailSubject = String.Format(Constants.PTO_EMAIL_SUBJECT_APPROVE_REJECT, pto.ID, "rejected"); } else if (pto.Status_ID == Constants.PTO_STATUS_CONFIRM) { sPTO_ID = "The " + pto.ID; sAction = "approved by"; sEmailSubject = String.Format(Constants.PTO_EMAIL_SUBJECT_APPROVE_REJECT, pto.ID, "approved"); } else if (pto.Status_ID == Constants.PTO_STATUS_VERIFIED) { sPTO_ID = "The " + pto.ID; sAction = "verified by"; actor = CommonFunc.GetEmployeeFullName(CommonFunc.GetEmployeeByUserName(HttpContext.Current.User.Identity.Name), Constants.FullNameFormat.FirstMiddleLast); sEmailSubject = String.Format(Constants.PTO_EMAIL_SUBJECT_VERIFIED, pto.ID); } if (!isManager.HasValue) { toEmail = HttpContext.Current.User.Identity.Name + Constants.LOGIGEAR_EMAIL_DOMAIN; } else if (isManager.Value) { if(!pto.DeleteFlag) sEmailSubject = String.Format(Constants.PTO_EMAIL_SUBJECT_TO_MANAGER, sEmpName); toEmail = pto.Employee1.OfficeEmail; } var empUser = CommonFunc.GetEmployeeByUserName(HttpContext.Current.User.Identity.Name); string recipent = ""; if (!isManager.HasValue) recipent = empDao.FullName(empUser.ID, Constants.FullNameFormat.FirstMiddleLast); else if (isManager.Value) recipent = empDao.FullName(manager.ID, Constants.FullNameFormat.FirstMiddleLast); else recipent = sEmpName; string commentTemplate = "<br/><b>{0}</b>: <i>{1}</i>"; sTemplate = sTemplate.Replace(Constants.PTO_EMAIL_FIELD_MANAGER_NAME, actor); sTemplate = sTemplate.Replace(Constants.PTO_EMAIL_FIELD_EMPLOYEE_NAME, sEmpName); sTemplate = sTemplate.Replace(Constants.PTO_EMAIL_FIELD_EMPLOYEE_SUBMIT_DATE, pto.CreateDate.ToString(Constants.DATETIME_FORMAT_VIEW)); sTemplate = sTemplate.Replace(Constants.PTO_EMAIL_FIELD_PTO_ID, sPTO_ID); sTemplate = sTemplate.Replace(Constants.PTO_EMAIL_FIELD_PTO_REAL_ID, pto.ID); sTemplate = sTemplate.Replace(Constants.PTO_EMAIL_FIELD_PTO_ACTION, sAction); sTemplate = sTemplate.Replace(Constants.PTO_EMAIL_FIELD_PTO_USER, empDao.FullName(empUser.ID, Constants.FullNameFormat.FirstMiddleLast)); sTemplate = sTemplate.Replace(Constants.PTO_EMAIL_FIELD_PTO_PTO_ID, pto.ID); sTemplate = sTemplate.Replace(Constants.PTO_EMAIL_FIELD_PTO_RECIPENT, recipent); sTemplate = sTemplate.Replace(Constants.PTO_PM_COMMENT_FIELD, string.IsNullOrEmpty(pto.ManagerComment) ? "" : string.Format(commentTemplate, "Manager comment (" + CommonFunc.GetEmployeeFullName(pto.Employee1, Constants.FullNameFormat.FirstMiddleLast) + ")", HttpUtility.HtmlEncode(pto.ManagerComment))); sTemplate = sTemplate.Replace(Constants.PTO_HR_COMMENT_FIELD, string.IsNullOrEmpty(pto.HRComment) ? "" : string.Format(commentTemplate, "HR comment", HttpUtility.HtmlEncode(pto.HRComment))); string sDetail = ""; //List<PTO_Detail> listPTO_Detail = ptoDao.GetPTO_DetailByPTO_ID(pto.ID).OrderBy(p => p.DateOff).ToList(); foreach (PTO_Detail detail in listPTO_Detail) { if (pto.PTO_Type.IsHourType) { sDetail += detail.DateOff.Value.ToString(Constants.DATETIME_FORMAT_VIEW) + ": " + (detail.HourFrom < 10 ? "0" + detail.HourFrom : detail.HourFrom.ToString()) + ":00 ยป " + (detail.HourTo < 10 ? "0" + detail.HourTo : detail.HourTo.ToString()) + ":00<br/>"; } else { sDetail += "From " + detail.DateOffFrom.Value.ToString(Constants.DATETIME_FORMAT_VIEW); sDetail += " to " + detail.DateOffTo.Value.ToString(Constants.DATETIME_FORMAT_VIEW); sDetail += "<br/>"; } } sTemplate = sTemplate.Replace(Constants.PTO_EMAIL_FIELD_PTO_DETAIL, sDetail); string host = ConfigurationManager.AppSettings["mailserver_host"]; string port = ConfigurationManager.AppSettings["mailserver_port"]; string from = Constants.CRM_MAIL_FROM_ADDRESS; string fromName = Constants.PTO_SENDER_NAME; WebUtils.SendMail(host, port, from, fromName, toEmail, ccMail, sEmailSubject, sTemplate); } catch { } }