Why invitees/details of Windows.ApplicationModel.Appointments.Appointment are empty - c#

I am working on a Windows Phone 8.1 application, and this app want to get the meetings from Calendar.
I am using the Windows Runtime api to get all appointment like this:
AppointmentStore appointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadOnly);
IReadOnlyList<Windows.ApplicationModel.Appointments.Appointment> appointments = await appointmentStore.FindAppointmentsAsync(DateTime.Now, TimeSpan.FromHours(24)); ;
foreach (var appointment in appointments)
{
var persistentId = appointment.RoamingId;
var details = appointment.Details;//the details is empty, why
var invitees = appointment.Invitees;//the invitees is also empty, why?
}
Actually, I tried the Microsoft Phone api, I can get the details and attendees(invitees). However, the Microsoft Phone api can't get the appointment ID. Can anybody throw me some light how to get both appointment ID, and details/invitees? Thanks!
Appointments appts = new Appointments();
//Identify the method that runs after the asynchronous search completes.
appts.SearchCompleted += new EventHandler<AppointmentsSearchEventArgs>(Calendar_SearchCompleted);
DateTime start = DateTime.Now;
DateTime end = start.AddDays(1);
int max = 100;
appts.SearchAsync(start, end, max, "test");
private async void Calendar_SearchCompleted(object sender, AppointmentsSearchEventArgs e)
{
foreach (Microsoft.Phone.UserData.Appointment appt in e.Results)
{
var details = appt.Details;//I can get the details
var participants = new ObservableCollection<Person>();
var attendees = appt.Attendees;
if (attendees != null)
{
foreach (var attende in attendees)
{
Person attendPerson = new Person()
{
Email = attende.EmailAddress,
FullName = attende.DisplayName,
PersonID = attende.EmailAddress
};
participants.Add(attendPerson);
}
}
....
}
}

Your need to add FindAppointmentsOptions to get get whatever detail you want, try below code
AppointmentStore appointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadOnly);
FindAppointmentsOptions options = new FindAppointmentsOptions();
options.MaxCount = 100;
options.FetchProperties.Add(AppointmentProperties.Subject);
options.FetchProperties.Add(AppointmentProperties.Location);
options.FetchProperties.Add(AppointmentProperties.Invitees);
options.FetchProperties.Add(AppointmentProperties.Details);
options.FetchProperties.Add(AppointmentProperties.StartTime);
options.FetchProperties.Add(AppointmentProperties.ReplyTime);
IReadOnlyList<Windows.ApplicationModel.Appointments.Appointment> appointments = await appointmentStore.FindAppointmentsAsync(DateTime.Now, TimeSpan.FromHours(24), options);
foreach (var appointment in appointments)
{
var persistentId = appointment.RoamingId;
var details = appointment.Details;//the details is empty, why
var invitees = appointment.Invitees;//the invitees is also empty, why?
}

Related

Can't update SalesReceipt in Quickbooks desktop

I'm using QuickBooks Integrator from /nSoftware to integrate with QuickBooks Desktop
I'm trying to update an invoice and I don't get any errors but when I check in QuickBooks I see that nothing changed and it didn't actually get updated.
First I try to lookup the invoice based on the RefNumber and if it found an Invoice then I try to replace the Line Items and then i call the update method like this existingInvoice.Update();
Here's my code sample:
public static List<Invoice> FindInvoice(string refNumber)
{
var invoicesSearch = new Objsearch
{
QueryType = ObjsearchQueryTypes.qtInvoiceSearch,
RuntimeLicense = "MYLICENSEKEY",
QBConnectionString = "MYCONNECTIONSTRINGTOREMOTECONNECTOR",
SearchCriteria = new SearchCriteria
{
RefNumberContains = refNumber
},
};
invoicesSearch.Search();
var qbInvoiceList = invoicesSearch.Results.ToList();
var invoiceObjList = new List<Invoice>();
foreach (var inv in qbInvoiceList)
{
var newInv = new Invoice();
newInv.QBResponseAggregate = inv.Aggregate;
invoiceObjList.Add(newInv);
}
return invoiceObjList.FirstOrDefault();
}
public static void PutInvoice(Invoice invoice)
{
var existingInvoice = FindInvoice(invoice.RefNumber);
if (existingInvoice != null)
{
existingInvoice.LineItems.Clear();
existingInvoice.LineItems.AddRange(invoice.LineItems);
existingInvoice.QBConnectionString = "MYCONNECTIONSTRINGTOREMOTECONNECTOR";
existingInvoice.RuntimeLicense = RuntimeLicense;
existingInvoice.QBXMLVersion = "12.0";
existingInvoice.Update(); //this line
}
}
Okay, so the issue was that I was setting the QBXMLVersion the last thing before updating.
In order for the Update() to process successfully the QBXMLVersion needs to be set the first thing.
Here's an updated working example:
public static void PutInvoice(Invoice invoice)
{
var existingInvoice = FindInvoice(invoice.RefNumber);
if (existingInvoice != null)
{
existingInvoice.QBXMLVersion = "12.0";
existingInvoice.RuntimeLicense = "MyRuntimeLicenseKey";
existingInvoice.QBConnectionString = "MYCONNECTIONSTRINGTOREMOTECONNECTOR";
existingInvoice.LineItems.Clear();
existingInvoice.LineItems.AddRange(invoice.LineItems);
existingInvoice.Update();
}
}

Get Outlook Appointments including recurring ones using EWS

I have implemented an SSIS Package getting all appoinments from a particular shared outlook calendar.
What I noticed is that the recurring ones are NOT returned because they are a kind of virtual. Only the Master of them will give me the ability to get also the recurring ones.
Looking at my code, do you have any suggestions how I can retrieve also the recurring ones?
I'm just a little stuck and any hint is highly appreciated!
#region Namespaces
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using Microsoft.Exchange.WebServices.Data;
#endregion
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
string sharedCalendarID;
static FolderId FindPublicFolder(ExchangeService myService, FolderId baseFolderId, string folderName)
{
// search using paging.
FolderView folderView = new FolderView(10, 0);
folderView.OffsetBasePoint = OffsetBasePoint.Beginning;
// need only DisplayName and Id of every folder
// reduce the property set to the properties
folderView.PropertySet = new PropertySet(FolderSchema.DisplayName, FolderSchema.Id);
FindFoldersResults folderResults;
do
{
folderResults = myService.FindFolders(baseFolderId, folderView);
foreach (Folder folder in folderResults)
if (String.Compare(folder.DisplayName, folderName, StringComparison.OrdinalIgnoreCase) == 0)
return folder.Id;
if (folderResults.NextPageOffset.HasValue)
// go to the next page
folderView.Offset = folderResults.NextPageOffset.Value;
}
while (folderResults.MoreAvailable);
return null;
}
public override void CreateNewOutputRows()
{
// IMPORTANT: ExchangeService is NOT thread safe, so one should create an instance of
// ExchangeService whenever one needs it.
ExchangeService myService = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
myService.Credentials = new NetworkCredential("username", "password");
myService.Url = new Uri("https://......Exchange.asmx");
// next line is very practical during development phase or for debugging
myService.TraceEnabled = true;
Folder myPublicFoldersRoot = Folder.Bind(myService, WellKnownFolderName.PublicFoldersRoot);
string myPublicFolderPath = #"CHI\WIED PFL Agenda";
string[] folderPath = myPublicFolderPath.Split('\\');
FolderId fId = myPublicFoldersRoot.Id;
foreach (string subFolderName in folderPath)
{
fId = FindPublicFolder(myService, fId, subFolderName);
if (fId == null)
{
// No Calendar found
return;
}
}
// verify
Folder folderFound = Folder.Bind(myService, fId);
if (String.Compare(folderFound.FolderClass, "IPF.Appointment", StringComparison.Ordinal) == 0)
{
sharedCalendarID = fId.ToString(); ;
}
else
return;
CalendarFolder myPublicFolder = CalendarFolder.Bind(myService,
//WellKnownFolderName.Calendar,
fId,
PropertySet.FirstClassProperties);
// search using paging. page size 10
ItemView viewCalendar = new ItemView(10);
// include all properties which we need in the view
// comment the next line then ALL properties will be read from the server.
//viewCalendar.PropertySet = new PropertySet(ItemSchema.Subject, ItemSchema.Id);
viewCalendar.Offset = 0;
viewCalendar.OffsetBasePoint = OffsetBasePoint.Beginning;
viewCalendar.OrderBy.Add(ContactSchema.DateTimeCreated, SortDirection.Descending);
FindItemsResults<Item> findResultsCalendar;
do
{
//SearchFilter searchFilter = new SearchFilter.IsGreaterThan(AppointmentSchema.Start, DateTime.Today);
var searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And,
new SearchFilter.IsEqualTo(ItemSchema.ItemClass, "IPM.Appointment"),
new SearchFilter.IsGreaterThanOrEqualTo(AppointmentSchema.Start, DateTime.Now),
new SearchFilter.IsLessThan(AppointmentSchema.Start, DateTime.Now.AddDays(4)));
findResultsCalendar = myPublicFolder.FindItems(searchFilter, viewCalendar);
//get additional properties for each item returned by view, do this as view cannot return a lot of useful stuff like attendees
ServiceResponseCollection<ServiceResponse> addProperties =
myService.LoadPropertiesForItems(from Item item in findResultsCalendar select item,
new PropertySet(
BasePropertySet.IdOnly,
AppointmentSchema.Body,
AppointmentSchema.Subject,
AppointmentSchema.Start,
AppointmentSchema.End,
AppointmentSchema.IsRecurring,
AppointmentSchema.AppointmentType
));
List<Appointment> additionalProperties = new List<Appointment>(addProperties.Count);
if (addProperties != null)
{
foreach (ServiceResponse currentResponce in addProperties)
{
additionalProperties.Add(((Appointment)((GetItemResponse)currentResponce).Item));
}
}
foreach (Item item in findResultsCalendar)
{
Appointment appt = item as Appointment;
if (item is Appointment || appt.AppointmentType == AppointmentType.RecurringMaster)
{
Appointment currentAppointmentAddProps = null;
currentAppointmentAddProps = additionalProperties.Find(
delegate(Appointment arg)
{
return arg.Id == item.Id;
}
);
//convert to int wether the Appointment is recurring or not
int isRecurring = currentAppointmentAddProps.IsRecurring ? 1 : 0;
Appointment appoint = item as Appointment;
OutputRecordSetBuffer.AddRow();
OutputRecordSetBuffer.ActualEndDate = currentAppointmentAddProps.End;
OutputRecordSetBuffer.ActualStartDate = currentAppointmentAddProps.Start;
OutputRecordSetBuffer.Subject = appoint.Subject;
OutputRecordSetBuffer.EntryID = Guid.NewGuid();
//OutputRecordSetBuffer.Detail = appoint.Body.ToString();
//OutputRecordSetBuffer.CalendarID = fId.ToString();
//OutputRecordSetBuffer.AppointmentID = appoint.Id.ToString();
OutputRecordSetBuffer.CalendarID = sharedCalendarID;
OutputRecordSetBuffer.AppointmentID = Guid.NewGuid();
OutputRecordSetBuffer.IsRecurring = isRecurring;
}
}
if (findResultsCalendar.NextPageOffset.HasValue)
// go to the next page
viewCalendar.Offset = findResultsCalendar.NextPageOffset.Value;
}
while (findResultsCalendar.MoreAvailable);
}
}
I have solved my issue on my own :)
Instead of using the ItemView class, I used the CalendarView class.
CalendarView expands also the recurring appointments, thats it :)

Sitecore 8.1 EXM 3.2: How to add Contact to a list in List Manager programatically?

I have
ContactForm with checkbox to subscribe to a newsletter.
I need to check if subscribing person is already a sitecore contact, update this person's data and add contact to RecipientsList in List Manager.
Here is my code:
var recipientCollectionRepository = RecipientCollectionRepository.GetDefaultInstance();
var list = recipientCollectionRepository.GetEditableRecipientCollection(listId);
var contactRepository = new ContactRepository();
var contact = contactRepository.LoadContactReadOnly(ContactEmail);
if (contact != null)
{
if (list != null)
{
var xdbContact = new XdbContactId(contact.ContactId);
if (!list.Contains(xdbContact, true).Value)
{
list.AddRecipient(xdbContact);
}
}
}
else
{
contact = contactRepository.CreateContact(Sitecore.Data.ID.NewID);
contact.Identifiers.AuthenticationLevel = Sitecore.Analytics.Model.AuthenticationLevel.None;
contact.Identifiers.Identifier = ContactEmail;
contact.Tags.Add("ContactLists",listId);
var contactEmailAddresses = contact.GetFacet<IContactEmailAddresses>("Emails");
if (!contactEmailAddresses.Entries.Contains("Email"))
{
contactEmailAddresses.Entries.Create("Email").SmtpAddress = ContactEmail;
contactEmailAddresses.Preferred = "Email";
}
var contactPersonalInfo = contact.GetFacet<IContactPersonalInfo>("Personal");
contactPersonalInfo.FirstName = ContactFirstName;
contactPersonalInfo.Surname = ContactSurname;
if (list != null)
{
var xdbContact = new XdbContactId(contact.ContactId);
if (!list.Contains(xdbContact, true).Value)
{
list.AddRecipient(xdbContact);
}
contactRepository.SaveContact(contact, new ContactSaveOptions(true, null));
}
}
Although I can find it in mongoDB
screen here
I cannot see it on my list in ListManager.
What else I need to do to be able to see my new contact on the list in ListManager?
It will get added only after session End.
This is default behavior to limit MongoDB calls.
Also EXM 3.2 version, there were issues with contact list recipients count. You may need to check with sitecore support for hot fix. or alternatively you can upgrade to EXM 3.3

Delete and update Google events [Google Calendar] using ASP.NET

How I can add in my website the update and delete events to my Google Calendar using ASP.NET C#?
You can use the methods Calendars: update to update metadata for a calendar. and Calendars: delete to delete a secondary calendar. Use Calendars.clear for clearing all events on primary calendars.
Sample HTTP requests:
Update: PUT https://www.googleapis.com/calendar/v3/calendars/calendarId
Delete: DELETE https://www.googleapis.com/calendar/v3/calendars/calendarId
Clear: POST https://www.googleapis.com/calendar/v3/calendars/calendarId/clear
Found this thread with a working .NET code for Google Calendar API V3.
Update Event:
public string CreateUpdateEvent(string ExpKey, string ExpVal, string evTitle, string evDate)
{
EventsResource er = new EventsResource(calService);
var queryEvent = er.List(calID);
queryEvent.SharedExtendedProperty = ExpKey + "=" + ExpVal; //"EventKey=9999"
var EventsList = queryEvent.Execute();
Event ev = new Event();
EventDateTime StartDate = new EventDateTime();
StartDate.Date = evDate; //"2014-11-17";
EventDateTime EndDate = new EventDateTime();
EndDate.Date = evDate;
ev.Start = StartDate;
ev.End = EndDate;
ev.Summary = evTitle; //"My Google Calendar V3 Event!";
string FoundEventID = String.Empty;
foreach(var evItem in EventsList.Items)
{
FoundEventID = evItem.Id;
}
if (String.IsNullOrEmpty(FoundEventID))
{
//If event does not exist, Append Extended Property and create the event
Event.ExtendedPropertiesData exp = new Event.ExtendedPropertiesData();
exp.Shared = new Dictionary<string, string>();
exp.Shared.Add(ExpKey, ExpVal);
ev.ExtendedProperties = exp;
return er.Insert(ev, calID).Execute().Summary;
}
else
{
//If existing, Update the event
return er.Update(ev, calID, FoundEventID).Execute().Summary;
}
}
Delete Event:
public bool DeleteEvent(string ExpKey, string ExpVal)
{
EventsResource er = new EventsResource(calService);
var queryEvent = er.List(calID);
queryEvent.SharedExtendedProperty = ExpKey + "=" + ExpVal; //"EventKey=9999"
var EventsList = queryEvent.Execute();
string FoundEventID = String.Empty;
foreach (Event ev in EventsList.Items)
{
FoundEventID = ev.Id;
er.Delete(calID, FoundEventID).Execute();
return true;
}
return false;
}
Check also this Quickstart tutorial from Google documentation.

Getting the wrong event from google calendar api

Here is my current code:
Service = new CalendarService("googleid.apps.googleusercontent.com");
Service.setUserCredentials("calenderusername#gmail.com", "passwordforaccount");
var calendarquery = new EventQuery
{
Uri =new Uri("https://www.google.com/calendar/feeds/calenderusername#gmail.com/private/full"),
StartTime = DateTime.Now,
NumberToRetrieve = 1,
SortOrder = CalendarSortOrder.#ascending
};
var feedItem = Service.Query(calendarquery).Entries.FirstOrDefault() as EventEntry;
var times = new Google.GData.Extensions.When();
times = feedItem.Times[0];
var item = new CalendarEvent
{
Description = feedItem.Content.Content,
EventDateStart = times.StartTime,
Title = feedItem.Title.Text,
EventDateEnd = times.EndTime,
URL = feedItem.Links.FirstOrDefault().HRef.Content
};
However, i get the item listed out:
EventStartDate: {10.02.2014 11:00:00}
EventEndDate: {10.02.2014 23:30:00}
But i know there is an event today(07.02.2014). Anyone have any idea what im doing wrong?
I'm confused wether to use startDate or startTime in my calendarQuery.

Categories