public static void sendMessage(User user, MessageTypeEnum type) { if (user.first_name == "control") { return; } AmazonSimpleNotificationServiceClient snsClient = new AmazonSimpleNotificationServiceClient(AWSConstants.SNS_ACCESS_KEY, AWSConstants.SNS_SECRET_ACCESS_KEY, Amazon.RegionEndpoint.USEast1); PublishRequest pubRequest = new PublishRequest(); // get the message that corresponds to the type of notification pubRequest.Message = MessageTypeExtension.GetDescription(type); // sending sms message if (user._Notification_Type == NotificationTypeEnum.SMS || user._Notification_Type == NotificationTypeEnum.ALL) { // we need to have +1 on the beginning of the number in order to send if (user.phone_number.Substring(0, 2) != "+1") { pubRequest.PhoneNumber = "+1" + user.phone_number; } else { pubRequest.PhoneNumber = user.phone_number; } PublishResponse pubResponse = snsClient.Publish(pubRequest); Console.WriteLine(pubResponse.MessageId); } }
/// <summary> /// Starts movement of the RT by updating the appointment status and /// then calling the RT controller to move the RT to the orientation /// it needs to go to. /// </summary> /// <param name="NextAppointment"> The appointment that is currently running. </param> private void PerformRadioTelescopeMovement(Appointment NextAppointment) { NextAppointment._Status = AppointmentStatusEnum.IN_PROGRESS; DatabaseOperations.UpdateAppointment(NextAppointment); // send message to appointment's user SNSMessage.sendMessage(NextAppointment.User, MessageTypeEnum.APPOINTMENT_STARTED); logger.Info(Utilities.GetTimeStamp() + ": Appointment _Type: " + NextAppointment._Type); // Loop through each second or minute of the appointment (depending on appt type) TimeSpan length = NextAppointment.end_time - NextAppointment.start_time; double duration = NextAppointment._Type == AppointmentTypeEnum.FREE_CONTROL ? length.TotalSeconds : length.TotalMinutes; for (int i = 0; i <= (int)duration; i++) { // before we move, check to see if it is safe if (checkCurrentSensorAndOverrideStatus()) { // Get orientation for current datetime DateTime datetime = NextAppointment._Type == AppointmentTypeEnum.FREE_CONTROL ? NextAppointment.start_time.AddSeconds(i) : NextAppointment.start_time.AddMinutes(i); NextObjectiveOrientation = RTController.CoordinateController.CalculateOrientation(NextAppointment, datetime); // Wait for datetime while (DateTime.UtcNow < datetime) { if (InterruptAppointmentFlag) { logger.Info(Utilities.GetTimeStamp() + ": Interrupted appointment [" + NextAppointment.Id.ToString() + "] at " + DateTime.Now.ToString()); break; } //logger.Debug(datetime.ToString() + " vs. " + DateTime.UtcNow.ToString()); Thread.Sleep(1000); } if (InterruptAppointmentFlag) { break; } // Move to orientation if (NextObjectiveOrientation != null) { // Kate - removed the check for azumith < 0 in the below if statement due to Todd's request // Reason being, we should not have an azimuth below 0 be given to us. That check is in the // method calling this! if (NextObjectiveOrientation.Elevation < 0) { logger.Warn(Utilities.GetTimeStamp() + ": Invalid Appt: Az = " + NextObjectiveOrientation.Azimuth + ", El = " + NextObjectiveOrientation.Elevation); InterruptAppointmentFlag = true; break; } logger.Info(Utilities.GetTimeStamp() + ": Moving to Next Objective: Az = " + NextObjectiveOrientation.Azimuth + ", El = " + NextObjectiveOrientation.Elevation); MovementResult apptMovementResult = RTController.MoveRadioTelescopeToOrientation(NextObjectiveOrientation, MovementPriority.Appointment); // If the movement result was anything other than success, it means the movement failed and something is wrong with // the hardware. // TODO: Talk to Todd about thresholds for this. (issue #388) Right now, it is cancelling the appointment if the movement // returns back any single error. See the MovementResult enum for a list of the different errors. if (apptMovementResult != MovementResult.Success) { logger.Info($"{Utilities.GetTimeStamp()}: Appointment movement FAILED with the following error message: {apptMovementResult.ToString()}"); InterruptAppointmentFlag = true; } if (InterruptAppointmentFlag) { break; } Thread.Sleep(100); NextObjectiveOrientation = null; } } else { logger.Info(Utilities.GetTimeStamp() + ": Telescope stopped movement."); i--; } } // Set email sender string emailSender = "*****@*****.**"; if (InterruptAppointmentFlag) { logger.Info(Utilities.GetTimeStamp() + ": Interrupted appointment [" + NextAppointment.Id.ToString() + "] at " + DateTime.Now.ToString()); NextAppointment._Status = AppointmentStatusEnum.CANCELED; DatabaseOperations.UpdateAppointment(NextAppointment); NextObjectiveOrientation = null; InterruptAppointmentFlag = false; // send message to appointment's user SNSMessage.sendMessage(NextAppointment.User, MessageTypeEnum.APPOINTMENT_CANCELLED); string subject = MessageTypeExtension.GetDescription(MessageTypeEnum.APPOINTMENT_CANCELLED); string text = MessageTypeExtension.GetDescription(MessageTypeEnum.APPOINTMENT_CANCELLED); EmailNotifications.sendToUser(NextAppointment.User, subject, text, emailSender); } else { NextAppointment._Status = AppointmentStatusEnum.COMPLETED; DatabaseOperations.UpdateAppointment(NextAppointment); // send message to appointment's user SNSMessage.sendMessage(NextAppointment.User, MessageTypeEnum.APPOINTMENT_COMPLETION); // Gather up email data string subject = MessageTypeExtension.GetDescription(MessageTypeEnum.APPOINTMENT_COMPLETION); string text = MessageTypeExtension.GetDescription(MessageTypeEnum.APPOINTMENT_COMPLETION); string attachmentPath = ""; string fname = System.DateTime.Now.ToString("yyyyMMddHHmmss"); string currentPath = AppDomain.CurrentDomain.BaseDirectory; List <RFData> data = (List <RFData>)NextAppointment.RFDatas; try { attachmentPath = Path.Combine(currentPath, $"{fname}.csv"); DataToCSV.ExportToCSV(data, fname); } catch (Exception e) { Console.Out.WriteLine($"Could not write data! Error: {e}"); } EmailNotifications.sendToUser(NextAppointment.User, subject, text, emailSender, attachmentPath, true); // Clean up after yourself, otherwise you'll just fill up our storage space DataToCSV.DeleteCSVFileWhenDone(attachmentPath); } }