public void TestSendingEmailWithAttachment() { string testpath = $"{Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $@".\PushNotificationTestResults\test-out-{System.DateTime.Now.ToString("yyyyMMddHHmmss")}")}"; string sender = "*****@*****.**"; string subject = "Amazon SES Test WITH ATTACHMENT"; string body = "AmazonSES Test (.NET) with Attachment\r\nThis email and its attachment were sent through AmazonSES using the AWS SDK for .NET."; // If you want to actually get emails while testing, change the email address below to whatever one you want to receive at. // This was already done earlier. User fakeUser = new User("Test", "User", "*****@*****.**", NotificationTypeEnum.ALL); // Gather dummy data RFData junkdata = new RFData(); junkdata.Id = 0; junkdata.appointment_id = 0; junkdata.TimeCaptured = System.DateTime.Now; junkdata.Intensity = 8675309; List <RFData> JunkRFData = new List <RFData>(); JunkRFData.Add(junkdata); DataToCSV.ExportToCSV(JunkRFData, testpath); // Execute task Task <bool> task = EmailNotifications.sendToUser(fakeUser, subject, body, sender, $"{testpath}.csv", true); // Wait for main task to finish before assertion task.Wait(); Assert.IsTrue(task.Result); }
public void TestSendingEmailToUser() { string sender = "*****@*****.**"; string subject = "Amazon SES Test"; string body = "AmazonSES Test (.NET)\r\nThis email was sent through AmazonSES using the AWS SDK for .NET."; User fakeUser = new User("Test", "User", "*****@*****.**", NotificationTypeEnum.ALL); // Execute task Task <bool> task = EmailNotifications.sendToUser(fakeUser, subject, body, sender, null, true); // Wait for main task to finish before assertion task.Wait(); Assert.IsTrue(task.Result); }
/// <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); } }