gpt4 book ai didi

c# - UWP 约会 : Appointment ID returning empty

转载 作者:行者123 更新时间:2023-11-30 23:11:42 25 4
gpt4 key购买 nike

我正在尝试添加 Appointments到我的 UWP 应用。

我已成功设置约会,但创建的约会 ID 结果为空,这意味着约会未创建。

以下是我的代码:

        public static Rect GetElementRect(FrameworkElement element)
{
GeneralTransform transform = element.TransformToVisual(null);
Point point = transform.TransformPoint(new Point());
return new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
}
private async Task<ManagerResponseModel> AddAppointmentToOutlookCalendar(ViewingSummaryModel model)
{
ManagerResponseModel result = new ManagerResponseModel();

//Add appointment if assigned to the same user
if(model.HousingOfficerId == AppSession.LoggedinUserId)
{
// Create an Appointment that should be added the user's appointments provider app.
var appointment = new Appointment();
//Populate Viewing Data in appointment
appointment.Subject = string.Format("Viewing at {0}", model.PropertyAddress);
appointment.Location = (string.IsNullOrWhiteSpace(model.PropertyAddress)) ? "NA" : model.PropertyAddress;
appointment.BusyStatus = AppointmentBusyStatus.Tentative;
appointment.Sensitivity = AppointmentSensitivity.Public;
appointment.AllDay = false;
//var timeZoneOffset = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now);
var date = GeneralHelper.GetCombinedDateTimeStringForViewing(model.ViewingDate, model.FormattedTime);
//var startTime = new DateTimeOffset(date.Year, date.Month, date.Day, date.Hour, date.Minute, 0, TimeZoneInfo.Local.BaseUtcOffset);
appointment.StartTime = date;
appointment.Details = string.Format("Customer: {0}", model.CustomerName) + "\r"
+ string.Format("Housing Officer: {0}", (string.IsNullOrWhiteSpace(model.AssignedTo)) ? "NA" : model.AssignedTo) + "\r"
+ string.Format("Address: {0}", model.PropertyAddress) + "\r"
+ string.Format("Created by: {0}", (string.IsNullOrWhiteSpace(model.CreatorName)) ? "You" : model.CreatorName);




// Get the selection rect of the button pressed to add this appointment
var rect = GetElementRect(this.Frame as FrameworkElement);
string appointmentId = string.Empty;
// ShowAddAppointmentAsync returns an appointment id if the appointment given was added to the user's calendar.
// This value should be stored in app data and roamed so that the appointment can be replaced or removed in the future.
// An empty string return value indicates that the user canceled the operation before the appointment was added.

if (!string.IsNullOrWhiteSpace(model.OutlookIdentifier))
{
appointmentId = await AppointmentManager.ShowReplaceAppointmentAsync(model.OutlookIdentifier, appointment, rect, Placement.Default, date);
/*Appointment doesn't exist on this system, try to add a new one*/
if (string.IsNullOrWhiteSpace(appointmentId))
{
appointmentId = await AppointmentManager.ShowAddAppointmentAsync(appointment, rect, Windows.UI.Popups.Placement.Default);
}
}
else
{
appointmentId = await AppointmentManager.ShowAddAppointmentAsync(appointment, rect, Windows.UI.Popups.Placement.Default);
}

model.OutlookIdentifier = appointmentId;

result.isSuccessful = string.IsNullOrWhiteSpace(appointmentId);
result.responseObject = model;
}
else
{
result.isSuccessful = true;
result.responseObject = model;
}

return result;
}

下面一行:

 appointmentId = await AppointmentManager.ShowAddAppointmentAsync(appointment, rect, Windows.UI.Popups.Placement.Default);

仅当用户取消操作或存在导致约会创建失败的其他问题时才返回空。我没有取消操作,也没有引发任何异常,所以我不知道我在这里做错了什么。

最佳答案

看了一篇相关的thread on MSDN才明白.这是一个非常愚蠢的错误。我忘记添加约会 capability在我的 Package.appxmanifest 文件中。

所以问题是,我的应用程序未被授权将约会添加到用户的日历中,这就是约会 ID 返回空的原因(如果也返回相关错误会很好,Microsoft)。

要解决此问题,请将以下行添加到 Capabilities 中的 package.appxmanifest 文件中:

<Capabilities>
<uap:Capability Name="appointments" />
</Capabilities>

或者,您也可以单击该文件,转到“功能”选项卡并检查“约会”功能,如下面的屏幕截图所示:

enter image description here

关于c# - UWP 约会 : Appointment ID returning empty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44569189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com