我有一个较早的帖子UWP C# Windows 10 IoT Alarm Clock,我目前正在转换使用Appointment
。我有一个添加约会的对话框。当我在rasp pi上运行时,似乎没有保存约会并触发它。请指教。我也希望能够在约会触发时触发外部输出引脚。
private async void Save_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
var appointment = new Windows.ApplicationModel.Appointments.Appointment();
var recurrence = new Windows.ApplicationModel.Appointments.AppointmentRecurrence();
var scheduleTime = TimePicker.Time;
var timeZoneOffset = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now);
var startTime = new DateTimeOffset(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, scheduleTime.Hours, scheduleTime.Minutes, 0, timeZoneOffset);
appointment.StartTime = startTime;
appointment.Subject = "Schedule Timer";
appointment.Duration = TimeSpan.FromMinutes(5);
if(dailyAlarm.IsOn == true)
{
recurrence.Unit = Windows.ApplicationModel.Appointments.AppointmentRecurrenceUnit.Daily;
} else
{
if (setMonday.IsChecked == true) { recurrence.DaysOfWeek |= Windows.ApplicationModel.Appointments.AppointmentDaysOfWeek.Monday; }
if (setTuesday.IsChecked == true) { recurrence.DaysOfWeek |= Windows.ApplicationModel.Appointments.AppointmentDaysOfWeek.Tuesday; }
if (setWednesday.IsChecked == true) { recurrence.DaysOfWeek |= Windows.ApplicationModel.Appointments.AppointmentDaysOfWeek.Wednesday; }
if (setThursday.IsChecked == true) { recurrence.DaysOfWeek |= Windows.ApplicationModel.Appointments.AppointmentDaysOfWeek.Thursday; }
if (setFriday.IsChecked == true) { recurrence.DaysOfWeek |= Windows.ApplicationModel.Appointments.AppointmentDaysOfWeek.Friday; }
if (setSaturdayday.IsChecked == true) { recurrence.DaysOfWeek |= Windows.ApplicationModel.Appointments.AppointmentDaysOfWeek.Saturday; }
if (setSunday.IsChecked == true) { recurrence.DaysOfWeek |= Windows.ApplicationModel.Appointments.AppointmentDaysOfWeek.Sunday; }
}
string appointmentId = await AppointmentManager.ShowAddAppointmentAsync(appointment, rect, Windows.UI.Popups.Placement.Default);
}
对你的问题不是真正的答案,因为我无法解决这个问题,我的Pi在家里而且我在办公室里。但是,我相信您可以创建与正在执行的操作非常相似的内容,并将其用于您的应用程序。
这是一个示例类:
public delegate void AlarmReadyToRing(object sender, object alarm);
public class AppointmentViewer
{
public event AlarmReadyToRing AlarmIsReady;
public List<object> Appointments { get; private set; }
private Timer _AlarmClock;
public AppointmentViewer()
{
LoadAppointmentsFromStorage();
_AlarmClock = new Timer(TriggerAlarms, null, 0, (int)TimeSpan.FromSeconds(1).TotalMilliseconds);
}
private void TriggerAlarms(object state)
{
if (DateTime.Now.Second == 59)
{
// Reset the timer so that it is checking every 60 seconds
_AlarmClock.Change(0, (int)TimeSpan.FromSeconds(60).TotalMilliseconds);
}
// Find all alarms that should be going off now
// FindAppointments(x=>x.StartTime == Datetime.Now)
var readyAlarms = FindAppointments(x=> 1==1);
foreach (var alarm in readyAlarms)
{
AlarmIsReady?.Invoke(this, alarm);
}
}
public void SaveAppointment(object appt)
{
// Save appointment logic
Appointments.Add(appt);
}
public void LoadAppointmentsFromStorage()
{
// Load appointments from local storage or other
Appointments = new List<object>();
}
public List<object> FindAppointments(Func<object, bool> search)
{
var found = Appointments.Where(search);
return found.ToList();
}
}
public class SomeOtherClass
{
private static AppointmentViewer ApptViewer { get; set; } = new AppointmentViewer();
public SomeOtherClass()
{
// Register for event
ApptViewer.AlarmIsReady += DoSomething;
}
private void DoSomething(object sender, object alarm)
{
// Here is the incoming alarm that needs to be going off
// Apply logic for app to display alarm
}
}