public PreFormActionResponse Execute(OwaContext owaContext, out ApplicationElement applicationElement, out string type, out string state, out string action) { if (owaContext == null) { throw new ArgumentNullException("owaContext"); } UserContext userContext = owaContext.UserContext; HttpRequest request = owaContext.HttpContext.Request; string[] array = null; applicationElement = ApplicationElement.Item; type = string.Empty; action = string.Empty; state = string.Empty; if (!Utilities.IsPostRequest(request)) { return(userContext.LastClientViewState.ToPreFormActionResponse()); } PreFormActionResponse preFormActionResponse = new PreFormActionResponse(); string formParameter = Utilities.GetFormParameter(request, "hidAB"); int num = 0; StoreObjectId storeObjectId = null; string changeKey = null; string[] array2 = formParameter.Split(new char[] { ';' }); if (array2 != null && array2.Length > 0) { if (string.CompareOrdinal(array2[0], "Ad") == 0) { num = 1; } else { if (string.CompareOrdinal(array2[0], "Con") != 0) { throw new OwaInvalidRequestException("Invalid search location for addressbook"); } num = 2; } } string action2 = owaContext.FormsRegistryContext.Action; if (action2 == null) { throw new OwaInvalidRequestException("Action query string parameter is missing"); } object obj = AddressBookPreFormAction.actionParser.Parse(action2); AddressBookPreFormAction.Action action3 = (AddressBookPreFormAction.Action)obj; string text = request.Form["chkRcpt"]; if (!string.IsNullOrEmpty(text)) { array = text.Split(new char[] { ',' }); } AddressBook.Mode mode = AddressBookHelper.TryReadAddressBookMode(request, AddressBook.Mode.None); if (AddressBook.IsEditingMode(mode)) { string formParameter2 = Utilities.GetFormParameter(request, "hidid", false); changeKey = Utilities.GetFormParameter(request, "hidchk", false); if (!string.IsNullOrEmpty(formParameter2)) { storeObjectId = Utilities.CreateStoreObjectId(userContext.MailboxSession, formParameter2); if (storeObjectId == null) { throw new OwaInvalidRequestException("ItemId cannot be null"); } } } switch (action3) { case AddressBookPreFormAction.Action.Done: if (AddressBook.IsEditingMode(mode)) { using (Item item = AddressBookHelper.GetItem(userContext, mode, storeObjectId, changeKey)) { if (array != null && array.Length > 0) { RecipientItemType type2 = RecipientItemType.To; string formParameter3 = Utilities.GetFormParameter(request, "hidrw"); if (!string.IsNullOrEmpty(formParameter3)) { int num2; if (!int.TryParse(formParameter3, out num2) || num2 < 1 || num2 > 3) { type2 = RecipientItemType.To; } else { type2 = (RecipientItemType)num2; } } if (num == 1) { AddressBookHelper.AddRecipientsToDraft(array, item, type2, userContext); } else if (num == 2) { AddressBookHelper.AddContactsToDraft(item, type2, userContext, array); } } preFormActionResponse = AddressBookHelper.RedirectToEdit(userContext, item, mode); break; } } throw new OwaInvalidRequestException("This action must be in editing mode"); case AddressBookPreFormAction.Action.Mail: if (array != null && array.Length > 0) { using (Item item2 = MessageItem.Create(userContext.MailboxSession, userContext.DraftsFolderId)) { item2[ItemSchema.ConversationIndexTracking] = true; if (num == 1) { AddressBookHelper.AddRecipientsToDraft(array, item2, RecipientItemType.To, userContext); } else if (num == 2) { AddressBookHelper.AddContactsToDraft(item2, RecipientItemType.To, userContext, array); } preFormActionResponse.ApplicationElement = ApplicationElement.Item; preFormActionResponse.Type = "IPM.Note"; preFormActionResponse.Action = "Open"; preFormActionResponse.State = "Draft"; preFormActionResponse.AddParameter("id", item2.Id.ObjectId.ToBase64String()); break; } } preFormActionResponse.ApplicationElement = ApplicationElement.Item; preFormActionResponse.Type = "IPM.Note"; preFormActionResponse.Action = "New"; break; case AddressBookPreFormAction.Action.MeetingRequest: preFormActionResponse.ApplicationElement = ApplicationElement.Item; preFormActionResponse.Type = "IPM.Appointment"; if (array != null && array.Length > 0) { using (CalendarItemBase calendarItemBase = EditCalendarItemHelper.CreateDraft(userContext, userContext.CalendarFolderId)) { calendarItemBase.IsMeeting = true; if (num == 1) { AddressBookHelper.AddRecipientsToDraft(array, calendarItemBase, RecipientItemType.To, userContext); } else if (num == 2) { AddressBookHelper.AddContactsToDraft(calendarItemBase, RecipientItemType.To, userContext, array); } preFormActionResponse.Action = "Open"; EditCalendarItemHelper.CreateUserContextData(userContext, calendarItemBase); break; } } preFormActionResponse.AddParameter("mr", "1"); preFormActionResponse.Action = "New"; break; case AddressBookPreFormAction.Action.Close: if (AddressBook.IsEditingMode(mode)) { using (Item item3 = AddressBookHelper.GetItem(userContext, mode, storeObjectId, changeKey)) { preFormActionResponse = AddressBookHelper.RedirectToEdit(userContext, item3, mode); break; } } throw new OwaInvalidRequestException("This action must be in editing mode"); case AddressBookPreFormAction.Action.AddToContacts: { string type3 = "IPM.Contact"; string text2 = null; if (array == null || array.Length != 1) { throw new OwaInvalidRequestException("User must select some recipient to add and can only add one recipient to contacts at one time"); } ADObjectId adobjectId = DirectoryAssistance.ParseADObjectId(array[0]); if (adobjectId == null) { throw new OwaADObjectNotFoundException(); } IRecipientSession recipientSession = Utilities.CreateADRecipientSession(Culture.GetUserCulture().LCID, true, ConsistencyMode.FullyConsistent, true, userContext); ADRecipient adrecipient = recipientSession.Read(adobjectId); if (adrecipient == null) { throw new OwaADObjectNotFoundException(); } using (ContactBase contactBase = ContactUtilities.AddADRecipientToContacts(userContext, adrecipient)) { if (contactBase != null) { contactBase.Load(); text2 = contactBase.Id.ObjectId.ToBase64String(); type3 = contactBase.ClassName; } } preFormActionResponse.ApplicationElement = ApplicationElement.Item; preFormActionResponse.Type = type3; if (text2 != null) { preFormActionResponse.Action = "Open"; preFormActionResponse.State = "Draft"; preFormActionResponse.AddParameter("id", text2); } else { preFormActionResponse.Action = "New"; } break; } default: throw new OwaInvalidRequestException("Invalid request for addressbook preformaction"); } return(preFormActionResponse); }
public PreFormActionResponse Execute(OwaContext owaContext, out ApplicationElement applicationElement, out string type, out string state, out string action) { if (owaContext == null) { throw new ArgumentNullException("owaContext"); } HttpContext httpContext = owaContext.HttpContext; UserContext userContext = owaContext.UserContext; HttpRequest request = httpContext.Request; applicationElement = ApplicationElement.Item; type = string.Empty; action = string.Empty; state = string.Empty; if (!Utilities.IsPostRequest(request)) { return(userContext.LastClientViewState.ToPreFormActionResponse()); } PreFormActionResponse preFormActionResponse = new PreFormActionResponse(); if (owaContext.FormsRegistryContext.Action == null) { throw new OwaInvalidRequestException("Action is missing"); } string formParameter = Utilities.GetFormParameter(request, "hidid", true); StoreObjectId storeObjectId = Utilities.CreateStoreObjectId(userContext.MailboxSession, formParameter); string action2; if ((action2 = owaContext.FormsRegistryContext.Action) != null) { if (!(action2 == "Mail")) { if (!(action2 == "MeetingRequest")) { if (action2 == "Delete") { goto IL_1E9; } if (!(action2 == "AddRcpt")) { goto IL_33E; } AddressBook.Mode mode = AddressBookHelper.TryReadAddressBookMode(request, AddressBook.Mode.None); if (mode != AddressBook.Mode.EditMessage && mode != AddressBook.Mode.EditMeetingResponse && mode != AddressBook.Mode.EditCalendar) { throw new OwaInvalidRequestException("Not in edit mode"); } string queryStringParameter = Utilities.GetQueryStringParameter(request, "id", false); StoreObjectId itemId = null; if (!string.IsNullOrEmpty(queryStringParameter)) { itemId = Utilities.CreateStoreObjectId(userContext.MailboxSession, queryStringParameter); } string queryStringParameter2 = Utilities.GetQueryStringParameter(request, "chk", false); RecipientItemType type2 = (RecipientItemType)RequestParser.TryGetIntValueFromQueryString(request, "rw", 1); using (Item item = AddressBookHelper.GetItem(userContext, mode, itemId, queryStringParameter2)) { Participant participant = Utilities.CreateParticipantFromQueryString(userContext, request); if (participant != null) { AddressBookHelper.AddParticipantToItem(item, type2, participant); CalendarItemBase calendarItemBase = item as CalendarItemBase; if (calendarItemBase != null) { EditCalendarItemHelper.CreateUserContextData(userContext, calendarItemBase); } else if (item is MessageItem) { AddressBookHelper.SaveItem(item); } } return(AddressBookHelper.RedirectToEdit(userContext, item, mode)); } goto IL_33E; } } else { using (MessageItem messageItem = MessageItem.Create(userContext.MailboxSession, userContext.DraftsFolderId)) { messageItem[ItemSchema.ConversationIndexTracking] = true; AddressBookHelper.AddContactsToDraft(messageItem, RecipientItemType.To, userContext, new string[] { storeObjectId.ToBase64String() }); preFormActionResponse.AddParameter("id", messageItem.Id.ObjectId.ToBase64String()); preFormActionResponse.ApplicationElement = ApplicationElement.Item; preFormActionResponse.Type = "IPM.Note"; preFormActionResponse.Action = "Open"; preFormActionResponse.State = "Draft"; return(preFormActionResponse); } } using (CalendarItemBase calendarItemBase2 = EditCalendarItemHelper.CreateDraft(userContext, userContext.CalendarFolderId)) { calendarItemBase2.IsMeeting = true; AddressBookHelper.AddContactsToDraft(calendarItemBase2, RecipientItemType.To, userContext, new string[] { storeObjectId.ToBase64String() }); preFormActionResponse.Action = "Open"; preFormActionResponse.ApplicationElement = ApplicationElement.Item; preFormActionResponse.Type = calendarItemBase2.ClassName; EditCalendarItemHelper.CreateUserContextData(userContext, calendarItemBase2); return(preFormActionResponse); } IL_1E9: string formParameter2 = Utilities.GetFormParameter(request, "hidcmdpst", true); if (formParameter2 == "d") { Utilities.DeleteItems(userContext, DeleteItemFlags.SoftDelete, new StoreId[] { storeObjectId }); } else { if (!(formParameter2 == "m")) { throw new OwaInvalidRequestException("Unknown delete command"); } Utilities.DeleteItems(userContext, DeleteItemFlags.MoveToDeletedItems, new StoreId[] { storeObjectId }); } userContext.ForceNewSearch = true; preFormActionResponse = userContext.LastClientViewState.ToPreFormActionResponse(); return(preFormActionResponse); } IL_33E: throw new OwaInvalidRequestException("Invalid action for readcontact preformaction"); }