private async void AttachmentViewerForm_Load(object sender, EventArgs e) { Icon = Properties.Resources.DefaultIcon; Text = "Attachments for '" + targetItemSubject + "'"; viewerRequestHelper = new ViewerRequestHelper(); List <AttachmentBase> result = new List <AttachmentBase>();; switch (targetFolder.Type) { case FolderContentType.Message: case FolderContentType.MsgFolderRoot: case FolderContentType.Drafts: try { result = await viewerRequestHelper.GetAllAttachmentsAsync(FolderContentType.Message, targetItemId); } catch (Exception ex) { MessageBox.Show(ex.Message); } break; case FolderContentType.Contact: // In the implementation of OutlookServicesClient, contact item does not have attachment. break; case FolderContentType.Calendar: try { result = await viewerRequestHelper.GetAllAttachmentsAsync(FolderContentType.Calendar, targetItemId); } catch (Exception ex) { MessageBox.Show(ex.Message); } break; case FolderContentType.Task: try { result = await viewerRequestHelper.GetAllAttachmentsAsync(FolderContentType.Task, targetItemId); } catch (Exception ex) { MessageBox.Show(ex.Message); } break; case FolderContentType.DummyCalendarGroupRoot: break; default: break; } foreach (var attachment in result) { // Add new row. string name = attachment.Name; string id = attachment.Id; string contentType = attachment.ContentType; DataGridViewRow itemRow = new DataGridViewRow { Tag = attachment.Id }; itemRow.CreateCells(dataGridView_AttachmentList, new object[] { name, id, contentType }); itemRow.ContextMenuStrip = contextMenuStrip_AttachmentList; if (dataGridView_AttachmentList.InvokeRequired) { dataGridView_AttachmentList.Invoke(new MethodInvoker(delegate { dataGridView_AttachmentList.Rows.Add(itemRow); })); } else { dataGridView_AttachmentList.Rows.Add(itemRow); } } }
private async void SendMailForm_LoadAsync(object sender, EventArgs e) { attachments = new List <ViewerHelper.Data.AttachmentAPI.AttachmentBase>(); comboBox_Importance.SelectedIndex = 1; comboBox_BodyType.SelectedIndex = 0; if (draftItemId != "") { // Editing a draft item. button_Attachments.Enabled = false; // When sending a draft item, it must be saved to SentItems. checkBox_SaveToSentItems.Checked = true; checkBox_SaveToSentItems.Enabled = false; viewerRequestHelper = new ViewerRequestHelper(); var draftItem = await viewerRequestHelper.GetDraftMessageAsync(draftItemId); if (comboBox_Importance.InvokeRequired) { comboBox_Importance.Invoke(new MethodInvoker(delegate { comboBox_Importance.SelectedIndex = (int)draftItem.Importance; })); } else { comboBox_Importance.SelectedIndex = (int)draftItem.Importance; } if (comboBox_Importance.InvokeRequired) { comboBox_Importance.Invoke(new MethodInvoker(delegate { comboBox_Importance.SelectedIndex = (int)draftItem.Importance;; })); } else { comboBox_Importance.SelectedIndex = (int)draftItem.Importance; } if (checkBox_RequestDeliveryReceipt.InvokeRequired) { checkBox_RequestDeliveryReceipt.Invoke(new MethodInvoker(delegate { checkBox_RequestDeliveryReceipt.Checked = draftItem.RequestDeliveryReceipt;; })); } else { checkBox_RequestDeliveryReceipt.Checked = draftItem.RequestDeliveryReceipt; } if (checkBox_RequestReadReceipt.InvokeRequired) { checkBox_RequestReadReceipt.Invoke(new MethodInvoker(delegate { checkBox_RequestReadReceipt.Checked = draftItem.RequestReadReceipt; })); } else { checkBox_RequestReadReceipt.Checked = draftItem.RequestReadReceipt; } if (textBox_To.InvokeRequired) { textBox_To.Invoke(new MethodInvoker(delegate { textBox_To.Text = RecipientsString(draftItem.ToRecipients); })); } else { textBox_To.Text = RecipientsString(draftItem.ToRecipients); } if (textBox_Cc.InvokeRequired) { textBox_Cc.Invoke(new MethodInvoker(delegate { textBox_Cc.Text = RecipientsString(draftItem.CcRecipients); })); } else { textBox_Cc.Text = RecipientsString(draftItem.CcRecipients); } if (textBox_Bcc.InvokeRequired) { textBox_Bcc.Invoke(new MethodInvoker(delegate { textBox_Bcc.Text = RecipientsString(draftItem.BccRecipients); })); } else { textBox_Bcc.Text = RecipientsString(draftItem.BccRecipients); } if (textBox_Subject.InvokeRequired) { textBox_Subject.Invoke(new MethodInvoker(delegate { textBox_Subject.Text = draftItem.Subject; })); } else { textBox_Subject.Text = draftItem.Subject; } if (textBox_Body.InvokeRequired) { textBox_Body.Invoke(new MethodInvoker(delegate { textBox_Body.Text = draftItem.Body; })); } else { textBox_Body.Text = draftItem.Body; } if (comboBox_BodyType.InvokeRequired) { comboBox_BodyType.Invoke(new MethodInvoker(delegate { comboBox_BodyType.SelectedIndex = (int)draftItem.BodyType; })); } else { comboBox_BodyType.SelectedIndex = (int)draftItem.BodyType; } var attachList = await viewerRequestHelper.GetAllAttachmentsAsync(FolderContentType.Message, draftItemId); foreach (var attach in attachList) { Dictionary <string, string> fullAttachInfo = await viewerRequestHelper.GetAttachmentAsync(FolderContentType.Message, draftItemId, attach.Id); string tempType = ""; string tempName = ""; string tempContentBytes = ""; foreach (KeyValuePair <string, string> item in fullAttachInfo) { if (item.Key == "@odata.type") { tempType = (item.Value == null) ? "" : item.Value.ToString(); } else if (item.Key == "Name") { tempName = (item.Value == null) ? "" : item.Value.ToString(); } else if (item.Key == "ContentBytes") { tempContentBytes = (item.Value == null) ? "" : item.Value.ToString(); } } if (tempType == "#Microsoft.OutlookServices.FileAttachment") { // This is a FileAttachment attachments.Add(FileAttachment.CreateFromContentBytes(tempName, tempContentBytes)); } } if (button_Attachments.InvokeRequired) { button_Attachments.Invoke(new MethodInvoker(delegate { button_Attachments.Enabled = true; })); } else { button_Attachments.Enabled = true; } } }
private async void CreateEventForm_LoadAsync(object sender, EventArgs e) { Icon = Properties.Resources.DefaultIcon; attachments = new List <ViewerHelper.Data.AttachmentAPI.AttachmentBase>(); // Display the window in the center of the parent window. Location = new Point(Owner.Location.X + (Owner.Width - Width) / 2, Owner.Location.Y + (Owner.Height - Height) / 2); viewerRequestHelper = new ViewerRequestHelper(); groupBox_Recurring_Pattern.Enabled = false; groupBox_Recurring_Range.Enabled = false; radioButton_Recurring_Pattern_Daily.Checked = true; groupBox_Recurring_Pattern_Weekly.Enabled = false; groupBox_Recurring_Pattern_Monthly.Enabled = false; groupBox_Recurring_Pattern_Yearly.Enabled = false; comboBox_Recurring_Pattern_Monthly_DayOfWeekIndex.Items.Add("First"); comboBox_Recurring_Pattern_Monthly_DayOfWeekIndex.Items.Add("Second"); comboBox_Recurring_Pattern_Monthly_DayOfWeekIndex.Items.Add("Third"); comboBox_Recurring_Pattern_Monthly_DayOfWeekIndex.Items.Add("Fourth"); comboBox_Recurring_Pattern_Monthly_DayOfWeekIndex.Items.Add("Last"); comboBox_Recurring_Pattern_Yearly_Relative_DayOfWeekIndex.Items.Add("First"); comboBox_Recurring_Pattern_Yearly_Relative_DayOfWeekIndex.Items.Add("Second"); comboBox_Recurring_Pattern_Yearly_Relative_DayOfWeekIndex.Items.Add("Third"); comboBox_Recurring_Pattern_Yearly_Relative_DayOfWeekIndex.Items.Add("Fourth"); comboBox_Recurring_Pattern_Yearly_Relative_DayOfWeekIndex.Items.Add("Last"); for (int i = 1; i <= 100; i++) { comboBox_Recurring_Pattern_Daily_Interval.Items.Add(i); comboBox_Recurring_Pattern_Weekly_Interval.Items.Add(i); comboBox_Recurring_Pattern_Monthly_Interval.Items.Add(i); comboBox_Recurring_Pattern_Yearly_Interval.Items.Add(i); comboBox_Recurring_Range_NumberOfConcurrences.Items.Add(i); } comboBox_Recurring_Pattern_Daily_Interval.SelectedItem = 1; comboBox_Recurring_Pattern_Weekly_Interval.SelectedItem = 1; comboBox_Recurring_Pattern_Monthly_Interval.SelectedItem = 1; comboBox_Recurring_Pattern_Yearly_Interval.SelectedItem = 1; comboBox_Recurring_Range_NumberOfConcurrences.SelectedItem = 10; radioButton_Recurring_Pattern_Monthly_MonthlyPattern.Checked = true; ToggleMonthlyPatternUI(true); for (int i = 1; i <= 31; i++) { comboBox_Recurring_Pattern_Monthly_DayOfTheMonth.Items.Add(i); comboBox_Recurring_Pattern_Yearly_Absolute_Day.Items.Add(i); } for (int i = 1; i <= 12; i++) { string monthName = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.MonthNames[i - 1]; comboBox_Recurring_Pattern_Yearly_Absolute_Month.Items.Add(monthName); comboBox_Recurring_Pattern_Yearly_Relative_Month.Items.Add(monthName); } comboBox_Recurring_Pattern_Monthly_DayOfTheMonth.SelectedItem = 1; radioButton_Recurring_Pattern_Yearly_OnSpecificDay.Checked = true; ToggleYearlyPatternUI(true); radioButton_Recurring_Range_NoEnd.Checked = true; DateTime now = DateTime.Now; // Use local time; DateTime tempStartDateTime = now; if (tempStartDateTime.Minute < 30) { tempStartDateTime = tempStartDateTime.AddMinutes(30 - tempStartDateTime.Minute); } else if (tempStartDateTime.Minute == 30) { tempStartDateTime = tempStartDateTime.AddMinutes(30); } else if (30 < tempStartDateTime.Minute && tempStartDateTime.Minute < 60) { tempStartDateTime = tempStartDateTime.AddMinutes(60 - tempStartDateTime.Minute); } dateTimePicker_Basic_StartDate.Value = tempStartDateTime; dateTimePicker_Basic_StartTime.Value = tempStartDateTime; DateTime tempEndDateTime = tempStartDateTime.AddMinutes(30); dateTimePicker_Basic_EndDate.Value = tempEndDateTime; dateTimePicker_Basic_EndTime.Value = tempEndDateTime; string localTimeZone = Util.LocalTimeZoneId; // Load all system time zones and add them to the combo box. var timeZoneCollection = TimeZoneInfo.GetSystemTimeZones(); foreach (var timeZone in timeZoneCollection) { var matches = Regex.Matches(timeZone.DisplayName, @"^\(UTC.*\)\s"); if (matches.Count == 1) { comboBox_Basic_TimeZone.Items.Add($"{matches[0]} {timeZone.Id}"); } else { comboBox_Basic_TimeZone.Items.Add(timeZone.Id); } if (timeZone.Id == localTimeZone) { // Select local time zone. comboBox_Basic_TimeZone.SelectedIndex = comboBox_Basic_TimeZone.Items.Count - 1; } } // Load all calendar API supported time zones and add them to the combo box. foreach (var timeZone in Util.GetCalendarApiSupportedTimeZones()) { comboBox_Basic_TimeZone.Items.Add(timeZone); } comboBox_BodyType.SelectedIndex = 1; comboBox_Recurring_Range_NumberOfConcurrences.Enabled = false; dateTimePicker_Recurring_Range_EndByDate.Enabled = false; comboBox_OnlineMeeting_Provider.Items.Add("None"); comboBox_OnlineMeeting_Provider.SelectedIndex = 0; // Get allowedOnlineMeetingProviders try { var allowedOnlineMeetingProviders = await viewerRequestHelper.GetAllowdOnlineMeetingProvidersAsync(); if (allowedOnlineMeetingProviders == null || allowedOnlineMeetingProviders.Count == 0) { throw new Exception("Microsoft Graph request was succeeded, but allowedOnlineMeetingProviders property is null or empty."); } if (allowedOnlineMeetingProviders.Count == 1 && allowedOnlineMeetingProviders[0] == "unknown") { throw new Exception("Microsoft Graph request was succeeded, but allowedOnlineMeetingProviders property contains only 'unknown'"); } foreach (var provider in allowedOnlineMeetingProviders) { if (provider != "unknown") { comboBox_OnlineMeeting_Provider.Items.Add(provider); } } } catch (Exception ex) { MessageBox.Show("Could not get allowed online meeting providers." + Environment.NewLine + Environment.NewLine + ex.Message, "Office365APIEditor", MessageBoxButtons.OK, MessageBoxIcon.Warning); } textBox_Basic_Title.Focus(); }
private async void Button_Save_Click(object sender, EventArgs e) { // Save new mail. Enabled = false; viewerRequestHelper = new ViewerRequestHelper(); NewEmailMessage newItem; try { newItem = CreateNewEmailMessageObject(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Office365APIEditor", MessageBoxButtons.OK, MessageBoxIcon.Error); Enabled = true; return; } try { if (draftItemId == "") { await viewerRequestHelper.SaveDraftAsync(newItem); } else { // This is a draft message. await viewerRequestHelper.UpdateDraftAsync(draftItemId, newItem); } Close(); } catch (WebException ex) { if (ex.Response == null) { MessageBox.Show(ex.Message, "Office365APIEditor", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { string jsonResponse = ""; using (Stream responseStream = ex.Response.GetResponseStream()) { StreamReader reader = new StreamReader(responseStream, Encoding.Default); jsonResponse = reader.ReadToEnd(); } HttpWebResponse response = (HttpWebResponse)ex.Response; MessageBox.Show(response.StatusCode.ToString() + Environment.NewLine + jsonResponse + Environment.NewLine, "Office365APIEditor", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Office365APIEditor", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Enabled = true; } }
private async void FolderViewerForm_Load(object sender, System.EventArgs e) { Icon = Properties.Resources.DefaultIcon; toolStripStatusLabel_Status.Text = "Loading all items..."; string typeForWindowTitle = ""; switch (targetFolder.Type) { case FolderContentType.Message: case FolderContentType.MsgFolderRoot: case FolderContentType.Drafts: typeForWindowTitle = "Message items"; break; case FolderContentType.Contact: typeForWindowTitle = "Contact items"; break; case FolderContentType.Calendar: typeForWindowTitle = "Calendar items"; break; case FolderContentType.Task: typeForWindowTitle = "Task items"; break; default: typeForWindowTitle = "items"; break; } Text = typeForWindowTitle + " in " + targetFolderDisplayName; viewerRequestHelper = new ViewerRequestHelper(); switch (targetFolder.Type) { case FolderContentType.Message: // Add columns. PrepareMessageItemListColumns(); bool hasMessageItem = await viewerRequestHelper.HasActualMessageItemAsync(targetFolder.ID); if (hasMessageItem) { // Get items. await LoadAllMessagesAsync(); } else { // This folder seems to be a message folder but it does not contain message items. var mailFolder = await viewerRequestHelper.GetMailFolderAsync(targetFolder.ID); if (mailFolder.TotalItemCount != 0 && MessageBox.Show("TotalItemCount of this folder is not 0 but getting items of this folder was failed.\r\nDo you want to retry getting items as Contact item?", "Office365APIEditor", MessageBoxButtons.YesNo) == DialogResult.Yes) { // Retry as Contact item. targetFolder.Type = FolderContentType.Contact; Text = FolderContentType.Contact.ToString() + " items in " + targetFolderDisplayName; // Reset DataGrid. if (dataGridView_ItemList.InvokeRequired) { dataGridView_ItemList.Invoke(new MethodInvoker(delegate { for (int i = dataGridView_ItemList.Columns.Count - 1; i >= 0; i--) { dataGridView_ItemList.Columns.RemoveAt(i); } })); } else { for (int i = dataGridView_ItemList.Columns.Count - 1; i >= 0; i--) { dataGridView_ItemList.Columns.RemoveAt(i); } } // Add columns. PrepareContactItemListColumns(); // Get items. await LoadAllContactsAsync(); } } break; case FolderContentType.Contact: // Add columns. PrepareContactItemListColumns(); // Get items. await LoadAllContactsAsync(); break; case FolderContentType.Calendar: // Add columns. PrepareCalendarItemListColumns(); // Get items. await LoadAllEventsAsync(); break; case FolderContentType.MsgFolderRoot: case FolderContentType.Drafts: // Add columns. PrepareMessageItemListColumns(); // Get items. await LoadAllMessagesAsync(); break; case FolderContentType.Task: // Add Columns. PrepareTaskItemListColumns(); // Get items. await LoadAllTasksAsync(); break; case FolderContentType.DummyCalendarGroupRoot: case FolderContentType.DummyTaskGroupRoot: case FolderContentType.TaskGroup: default: break; } toolStripStatusLabel_Status.Text = "Loaded all items."; }