private void Timer_Tick(ThreadPoolTimer timer) { // Get the current time var currentTime = DateTimeOffset.Now; // Margin (there is already light before sunrise and there is still light after sunset) var margin = TimeSpan.FromMinutes(15); // Calculate sunrise & sunset for the current day var solarTimes = new SolarTimes(currentTime, _geoCoordinate.Latitude, _geoCoordinate.Longitude); var sunrise = new DateTimeOffset(solarTimes.Sunrise); var sunset = new DateTimeOffset(solarTimes.Sunset); // Has the sun already risen today (minus the margin)? // => No, do nothing // => Yes and is it after 7h30 on a working day? // => No, do nothing // => Yes and have we already opened the blinds today? // => No, open the blinds // => Yes, do nothing if (sunrise.Subtract(margin) < currentTime) { // TODO: Add holidays if (currentTime.DayOfWeek != DayOfWeek.Saturday && currentTime.DayOfWeek != DayOfWeek.Sunday && currentTime.TimeOfDay >= new TimeSpan(7, 30, 0)) { if (_settingsController.LastOpeningTime == null || _settingsController.LastOpeningTime.Value.Date != currentTime.Date) { var sendMailResult = _mailController.Send("Opening the Velux blinds", $"Sunrise: {sunrise.ToString("F")}\r\nMargin: {margin.ToString("%m' min.'")}\r\n\r\nCurrent time: {currentTime.ToString("F")}\r\n\r\nLocation: http://www.google.com/maps/place/{_geoCoordinate.Latitude},{_geoCoordinate.Longitude}"); _veluxController.Up(); _settingsController.LastOpeningTime = currentTime; sendMailResult.Wait(); } } } // TODO: Do not open & close the blinds in the same interval // Has the sun already set today? // => No, do nothing // => Yes and have we already closed the blinds today? // => No, close the blinds // => Yes, do nothing if (sunset.Add(margin) < currentTime) { if (_settingsController.LastClosingTime == null || _settingsController.LastClosingTime.Value.Date != currentTime.Date) { var sendMailResult = _mailController.Send("Closing the Velux blinds", $"Sunset: {sunset.ToString("F")}\r\nMargin: {margin.ToString("%m' min.'")}\r\n\r\nCurrent time: {currentTime.ToString("F")}\r\n\r\nLocation: http://www.google.com/maps/place/{_geoCoordinate.Latitude},{_geoCoordinate.Longitude}"); _veluxController.Down(); _settingsController.LastClosingTime = currentTime; sendMailResult.Wait(); } } }
private void OnOpenOrder(Order order) { try { OnMessage(order.GetShortOpenMessage()); string fileName = Path.Combine(Application.StartupPath, order.OpenTime.ToString("dd-MM-yyyy-HH-mm") + ".jpg"); chart1.SaveImage(fileName, ChartImageFormat.Jpeg); Dictionary <string, string> images = new Dictionary <string, string>(); images.Add("chart", fileName); _mailController.Send(order.GetShortOpenMessage(), order.GetFullOpenMessage() + Environment.NewLine + "<img src=cid:chart>", images); } catch (Exception ex) { OnMessage(ex.Message); } }
public void SendEmail(object sender, EventArgs e) { string userEmail = email.GetValue() as string; UserController user = UserController.FromEmail(userEmail); if (user == null) { MessageBox.Show("Пользователь не найден"); return; } UserCode userCode = user.SetUserCode(); MailController.Send(userEmail, userCode.Code); }