private void MnuDisplayAsItem_Click(object sender, EventArgs e)
        {
            // Don't do anything if a content row is not selected
            if (this.ContentsGrid.SelectedRows.Count == 0)
            {
                return;
            }

            Attachment attach = this.ContentsGrid.SelectedRows[0].Cells[ColNameAttachmentObj].Value as Attachment;

            // If we can't get the attachment object bail out
            if (attach == null)
            {
                return;
            }

            ItemAttachment itemAttachment = attach as ItemAttachment;

            if (itemAttachment == null)
            {
                // Warn the user that an ItemAttachment is required?
                return;
            }

            if (itemAttachment.Item == null)
            {
                DebugLog.WriteVerbose("Cannot display ItemAttachment.Item because ItemAttachment.Item is NULL.");
                ErrorDialog.ShowWarning("Cannot display ItemAttachment.Item because ItemAttachment.Item is NULL.");
                return;
            }

            this.PropertyDetailsGrid.LoadObject(itemAttachment.Item);
        }
Beispiel #2
0
        protected override void LoadContents()
        {
            FindItemsResults <Item> findResults = null;

            this.ContentItemView.Offset = 0;

            List <Item> folderItems = new List <Item>();

            while ((findResults == null || findResults.MoreAvailable) && folderItems.Count < 1000)
            {
                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    this.currentFolder.Service.ClientRequestId = Guid.NewGuid().ToString();  // Set a new GUID.
                    findResults = this.currentFolder.FindItems(this.ContentItemView);
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }

                this.ContentItemView.Offset = this.ContentItemView.Offset + GlobalSettings.FindItemViewSize;

                foreach (Item item in findResults.Items)
                {
                    this.AddContentItem(item);
                }
            }

            if (findResults.MoreAvailable && folderItems.Count == 1000)
            {
                ErrorDialog.ShowWarning(DisplayStrings.WARN_ITEM_VIEW_COUNT_LIMIT);
            }
        }
Beispiel #3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (this.tvwSchemas.SelectedNode != null)
            {
                // The form currently does support multiple selections.
                // If a parent node is selected, warn the user and bail
                // out of this method.
                if (this.tvwSchemas.SelectedNode.Nodes.Count > 0)
                {
                    ErrorDialog.ShowWarning(DisplayStrings.WARN_SELECT_SCHEMA_PROPS);
                    this.DialogResult = DialogResult.Ignore;
                    return;
                }

                this.propDef      = this.tvwSchemas.SelectedNode.Tag as PropertyDefinitionBase;
                this.DialogResult = DialogResult.OK;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Get the delegate list by calling GetDelegates passing the
        /// principal mailbox specified in txtPrincipal
        /// </summary>
        private void btnGetDelegates_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                // If there is no principal mailbox then there's nothing to do
                if (this.PrincipalMailbox == null)
                {
                    ErrorDialog.ShowWarning("A principal mailbox must be specified before calling GetDelegates.");
                    return;
                }

                GetDelegateInformation();
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
        /// <summary>
        /// Perform the CalendarView search and set the return Appointment
        /// collection to be returned.
        /// </summary>
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                // If no folder has been identified, warn the user
                if (this.CurrentCalendar == null)
                {
                    ErrorDialog.ShowWarning("No calendar folder selected.");
                    this.DialogResult = DialogResult.None;
                    return;
                }


                DateTime start = Convert.ToDateTime(txtStartTime.Text);
                DateTime end   = Convert.ToDateTime(txtEndTime.Text);



                CalendarView view = new CalendarView(start, end, GlobalSettings.CalendarViewSize);
                view.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties);

                FindItemsResults <Appointment> appts = this.CurrentService.FindAppointments(
                    this.CurrentCalendar,
                    view);

                this.AppointmentsFound = new List <Appointment>();
                this.AppointmentsFound.AddRange(appts.Items);

                // Warn the user if more results are available that we are not displaying
                if (appts.MoreAvailable)
                {
                    ErrorDialog.ShowWarning(string.Format(DisplayStrings.WARN_CALENDARVIEW_LIMT, GlobalSettings.CalendarViewSize));
                }
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Show the DelegatePermissionDialog for the selected user.
        /// </summary>
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            // If the dialog result returned is actionable, change the edit
            // state.
            DelegateUser delegateUser = GetSelectedDelegateUser();

            if (DelegateUserDialog.ShowDialog(this.CurrentService, ref delegateUser) == DialogResult.OK)
            {
                ICollection <DelegateUserResponse> results;

                try
                {
                    this.Cursor = Cursors.WaitCursor;

                    results = this.CurrentService.UpdateDelegates(
                        this.PrincipalMailbox,
                        GetScopeFromForm(),
                        new DelegateUser[] { delegateUser });
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }

                foreach (DelegateUserResponse result in results)
                {
                    if (result.Result == ServiceResult.Error)
                    {
                        ErrorDialog.ShowWarning(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Failed to update {0}.  {1}, {2}",
                                                              result.DelegateUser.UserId.StandardUser.HasValue ?
                                                              result.DelegateUser.UserId.StandardUser.Value.ToString() :
                                                              result.DelegateUser.UserId.PrimarySmtpAddress,
                                                              result.ErrorCode.ToString(),
                                                              result.ErrorMessage));
                    }
                }

                GetDelegateInformation();
            }
        }
Beispiel #7
0
        /// <summary>
        /// Display the DelegateUserDialog to get a new DelegateUser.  After
        /// getting that call AddDelegate
        /// </summary>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            DelegateUser newDelegate = null;

            if (DelegateUserDialog.ShowDialog(this.CurrentService, ref newDelegate) == DialogResult.OK &&
                newDelegate != null)
            {
                ICollection <DelegateUserResponse> results;

                try
                {
                    this.Cursor = Cursors.WaitCursor;

                    results = this.CurrentService.AddDelegates(
                        this.PrincipalMailbox,
                        GetScopeFromForm(),
                        new DelegateUser[] { newDelegate });
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }

                foreach (DelegateUserResponse result in results)
                {
                    if (result.Result == ServiceResult.Error)
                    {
                        ErrorDialog.ShowWarning(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Failed to add {0}.  {1}, {2}",
                                                              result.DelegateUser.UserId.StandardUser.HasValue ?
                                                              result.DelegateUser.UserId.StandardUser.Value.ToString() :
                                                              result.DelegateUser.UserId.PrimarySmtpAddress,
                                                              result.ErrorCode.ToString(),
                                                              result.ErrorMessage));
                    }
                }

                GetDelegateInformation();
            }
        }
Beispiel #8
0
        /// <summary>
        /// Get the OOF settings by passing the target mailbox specified
        /// in txtTarget
        /// </summary>
        /// <param name="sender">The parameter is not used.</param>
        /// <param name="e">The parameter is not used.</param>
        private void GetOofButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                // If there is no target mailbox then there's nothing to do
                if (this.TargetMailbox == null)
                {
                    ErrorDialog.ShowWarning("A target mailbox must be specified before calling GetUserOofSettings.");
                    return;
                }

                this.InitializeFormOofSettings();

                this.DisplayOofSettings();
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Beispiel #9
0
        private void ConvertButton_Click(object sender, EventArgs e)
        {
            if (this.srcFormatCombo.SelectedItem.HasValue == false &&
                this.reqFormatCombo.SelectedItem.HasValue == false)
            {
                if (this.srcFormatCombo.SelectedItem.HasValue == false)
                {
                    DebugLog.WriteVerbose("srcFormatCombo has no value");
                }
                if (this.reqFormatCombo.SelectedItem.HasValue == false)
                {
                    DebugLog.WriteVerbose("reqFormatCombo has no value");
                }

                ErrorDialog.ShowWarning("Select a source and requested ID format before converting.");
                return;
            }

            try
            {
                this.Cursor = Cursors.WaitCursor;

                AlternateId srcId = new AlternateId(
                    this.srcFormatCombo.SelectedItem.Value,
                    this.SrcIdText.Text,
                    this.SrcMbxText.Text);

                AlternateId cvrtId = (AlternateId)this.CurrentService.ConvertId(srcId, this.reqFormatCombo.SelectedItem.Value);

                this.CvrtIdText.Text    = System.Enum.GetName(typeof(IdFormat), cvrtId.Format);
                this.CvrtIdMbxText.Text = cvrtId.Mailbox;
                this.CvrtIdText.Text    = cvrtId.UniqueId;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Beispiel #10
0
        /// <summary>
        /// Display the UserIdDialog to get a UserId of the user to
        /// remove.  Prepopulate UserIdDialog if a delegate is selected
        /// in the delegate list.  After getting a UserId, call RemoveDelegate
        /// </summary>
        private void btnRemove_Click(object sender, EventArgs e)
        {
            UserId removeUser = null;

            if (GetSelectedDelegateUser() != null)
            {
                removeUser = GetSelectedDelegateUser().UserId;
            }

            if (UserIdDialog.ShowDialog(this.CurrentService, ref removeUser) == DialogResult.OK &&
                removeUser != null)
            {
                ICollection <DelegateUserResponse> results;
                try
                {
                    this.Cursor = Cursors.WaitCursor;

                    results = this.CurrentService.RemoveDelegates(this.PrincipalMailbox,
                                                                  new UserId[] { removeUser });
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }

                foreach (DelegateUserResponse result in results)
                {
                    if (result.Result == ServiceResult.Error)
                    {
                        ErrorDialog.ShowWarning(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Failed to remove delegate.  {0}, {1}",
                                                              result.ErrorCode.ToString(),
                                                              result.ErrorMessage));
                    }
                }

                GetDelegateInformation();
            }
        }
Beispiel #11
0
        private void OkButton_Click(object sender, EventArgs e)
        {
            AttendeeInfo attendee = new AttendeeInfo();

            if (String.IsNullOrEmpty(this.SmtpAddressText.Text))
            {
                ErrorDialog.ShowWarning("An SMTP address is required in order to create an AttendeeInfo object.");
                return;
            }
            else
            {
                attendee.SmtpAddress = this.SmtpAddressText.Text;
            }

            if (this.attendeeTypeCombo.SelectedItem.HasValue)
            {
                attendee.AttendeeType = this.attendeeTypeCombo.SelectedItem.Value;
            }

            attendee.ExcludeConflicts = this.ExcludeConflictsCheck.Checked;

            this.currentAttendee = attendee;
        }
        private void MnuSaveAttach_Click(object sender, EventArgs e)
        {
            // Don't do anything if a content row is not selected
            if (this.ContentsGrid.SelectedRows.Count == 0)
            {
                return;
            }

            Attachment attach = this.ContentsGrid.SelectedRows[0].Cells[ColNameAttachmentObj].Value as Attachment;

            // If we can't get the attachment object bail out
            if (attach == null)
            {
                return;
            }

            // Get the file name we'll save to and bail out if we don't succeed
            // Create a file path to save the item properties to
            string fileName = null;

            //fileName = string.Format(
            //System.Globalization.CultureInfo.CurrentCulture,
            //    "{0}\\{1}.xml",
            //    destinationFolderPath,
            //    FileHelper.SanitizeFileName(item.Subject));

            fileName = this.GetTargetFileName(fileName);
            if (fileName == string.Empty)
            {
                return;
            }

            this.Cursor = Cursors.WaitCursor;

            System.Diagnostics.Debug.WriteLine("ItemClass of Mesage: " + currentParentItem.ItemClass);


            // If the attachment is a FileAttachment then simply save the content
            FileAttachment fileAttach = attach as FileAttachment;

            if (fileAttach != null)
            {
                if (fileAttach.Content == null)
                {
                    ErrorDialog.ShowWarning("Cannot save FileAttachment because FileAttachment.Content is NULL.");
                    return;
                }

                try
                {
                    this.Cursor = Cursors.WaitCursor;

                    System.IO.File.WriteAllBytes(fileName, fileAttach.Content);
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }
            else
            {
                ItemAttachment itemAttachment = attach as ItemAttachment;
                if (itemAttachment != null)
                {
                    if (itemAttachment.Item == null)
                    {
                        ErrorDialog.ShowWarning("Cannot save ItemAttachment because ItemAttachment.Item is NULL.");
                        return;
                    }

                    try
                    {
                        this.Cursor = Cursors.WaitCursor;
                        //if (currentParentItem.ItemClass == "")
                        //{
                        //}

                        // Note that not everything has a MIME type. An NDR does not have one, so MIME conversion will fail.
                        // Save an attached email by using the EWS Managed API
                        //      https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-get-attachments-by-using-ews-in-exchange
                        string sMIME = string.Empty;

                        //System.Diagnostics.Debug.WriteLine("ItemClass of Mesage: " + currentParentItem.ItemClass);

                        try
                        {
                            itemAttachment.Load(ItemSchema.MimeContent);



                            //UTF8Encoding oUTF8Encoding = new UTF8Encoding();                            // For debugging
                            //sMIME = oUTF8Encoding.GetString(itemAttachment.Item.MimeContent.Content);   // For debugging

                            System.IO.File.WriteAllBytes(fileName, itemAttachment.Item.MimeContent.Content);
                        }
                        catch (Exception ex)
                        {
                        }


                        //string sFolderPath = System.IO.Path.GetPathRoot(fileName);
                        //string sFilePath = System.IO.Path.GetFileName(fileName);

                        //EWSEditor.Common.DumpHelper.DumpXMLbyFileName(
                        //    itemAttachment.Item,
                        //    sFolderPath,
                        //    sFilePath);
                    }
                    finally
                    {
                        this.Cursor = Cursors.Default;
                    }

                    this.Cursor = Cursors.WaitCursor;

                    // An Item Attachment may have attachemnets also - so, save them off also.  Things like NDR messages contain the origional message.
                    try
                    {
                        this.Cursor = Cursors.WaitCursor;

                        // Save an attached email by using the EWS Managed API
                        // https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-get-attachments-by-using-ews-in-exchange

                        // Code to save message attachment sub-items.  This will work for journaled messages.
                        int iSub1AttachCount = 0;
                        if (itemAttachment.Item.Attachments.Count > 0)
                        {
                            foreach (Attachment Sub1Attachment in itemAttachment.Item.Attachments)
                            {
                                ItemAttachment Sub1ItemAttachment = Sub1Attachment as ItemAttachment;
                                if (Sub1ItemAttachment != null)
                                {
                                    iSub1AttachCount++;

                                    try
                                    {
                                        Sub1ItemAttachment.Load(ItemSchema.MimeContent);  // if MIME can be pulled then save it.  not all types have a MIME equivilent.

                                        System.IO.File.WriteAllBytes(fileName + " - " + iSub1AttachCount.ToString(), Sub1ItemAttachment.Item.MimeContent.Content);
                                    }
                                    finally
                                    {
                                    }
                                }
                            }


                            //int iSub2AttachCount = 0;
                            //foreach (ItemAttachment o in itemAttachment.Item.Attachments)
                            //{

                            //    ItemAttachment itemSubAttachment = o as ItemAttachment;
                            //    if (itemAttachment != null)
                            //    {
                            //        iSub2AttachCount++;

                            //        try
                            //        {
                            //            //o.Load(ItemSchema.MimeContent);  // if MIME can be pulled then save it.  not all types have a MIME equivilent.

                            //            //System.IO.File.WriteAllBytes(fileName + " - ItemAttachment " + iSubAttachCount.ToString(), itemAttachment.Item.MimeContent.Content);

                            //            //int iSub2AttachCount = 0;

                            //            //foreach (ItemAttachment o2 in o.Item.Attachments)
                            //            //{

                            //            //    ItemAttachment itemSub2Attachment = o2 as ItemAttachment;
                            //            //    if (itemAttachment != null)
                            //            //    {
                            //            //        iSub2AttachCount++;

                            //            //        try
                            //            //        {
                            //            //            itemAttachment.Load(ItemSchema.MimeContent);  // if MIME can be pulled then save it.  not all types have a MIME equivilent.

                            //            //            System.IO.File.WriteAllBytes(fileName + " - ItemAttachment " + iSub2AttachCount.ToString(), itemAttachment.Item.MimeContent.Content);
                            //            //        }
                            //            //        finally
                            //            //        {
                            //            //        }
                            //            //    }
                            //            //}
                            //        }
                            //        finally
                            //        {
                            //        }
                            //    }
                            //}
                        }

                        this.Cursor = Cursors.Default;

                        string sFolderPath = System.IO.Path.GetPathRoot(fileName);
                        string sFilePath   = System.IO.Path.GetFileName(fileName);

                        //EWSEditor.Common.DumpHelper.DumpXMLbyFileName(
                        //    itemAttachment.Item,
                        //    sFolderPath,
                        //    sFilePath);
                    }
                    finally
                    {
                        this.Cursor = Cursors.Default;
                    }
                }
            }
        }
Beispiel #13
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            // If no folder has been identified, warn the user
            if (this._SelectedFolder == null)
            {
                ErrorDialog.ShowWarning("No calendar folder selected.");
                this.DialogResult = DialogResult.None;
                return;
            }


            DateTime start = Convert.ToDateTime(txtStartTime.Text);
            DateTime end   = Convert.ToDateTime(txtEndTime.Text);


            //// TODO: Add more search capablities
            // http://msdn.microsoft.com/en-us/library/dd633700(v=exchg.80).aspx

            SearchFilter.SearchFilterCollection searchFilter = new SearchFilter.SearchFilterCollection();
            searchFilter.Add(new SearchFilter.IsGreaterThanOrEqualTo(AppointmentSchema.Start, start));
            searchFilter.Add(new SearchFilter.IsGreaterThanOrEqualTo(AppointmentSchema.Start, end));
            if (this.chkSearchSubject.Checked == true)
            {
                searchFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.Subject, txtSubject.Text));
            }
            if (this.chkSearchToAttendee.Checked == true)
            {
                searchFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.DisplayTo, this.txtToAttendee.Text));
            }
            if (this.chkSearchCCAttendee.Checked == true)
            {
                searchFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.DisplayCc, this.txtCCAttendee.Text));
            }
            if (this.chkSearchBody.Checked == true)
            {
                searchFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.Body, this.txtBody.Text));
            }

            ItemView view = new ItemView(20);

            view.PropertySet = new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.AppointmentType);
            _CurrentService.ClientRequestId = Guid.NewGuid().ToString();  // Set a new GUID.
            FindItemsResults <Item> findResults = _CurrentService.FindItems(WellKnownFolderName.Calendar, searchFilter, view);

            foreach (Item item in findResults.Items)
            {
                Appointment appt = item as Appointment;
                if (appt.AppointmentType == AppointmentType.RecurringMaster)
                {
                    // Calendar item is a recurring master item for a recurring series.
                }
                if (appt.AppointmentType == AppointmentType.Occurrence)
                {
                    // Calendar item is an occurrence in a recurring series.
                }
                else if (appt.AppointmentType == AppointmentType.Exception)
                {
                    // Calendar item is an exception in a recurring series.
                }
            }
        }
Beispiel #14
0
        ///// <summary>
        ///// Show modal FolderIdDialog, if 'OK' not clicked return
        ///// NULL.
        ///// </summary>
        ///// <param name="id">Output parameter.</param>
        ///// <returns>
        ///// DialogResult indicating whether the user clicked
        ///// OK or cancelled the dialog.
        ///// </returns>
        //public static DialogResult ShowDialog(ref FolderId )
        //{
        //    id = null;

        //    //dialog._ExchangeService = oExchangeService;

        //    FolderIdDialog dialog = new FolderIdDialog();

        //    DialogResult res = ((Form)dialog).ShowDialog();

        //    if (res == DialogResult.OK)
        //    {
        //        id = dialog.currentFolderId;
        //    }

        //    return res;
        //}

        private void OkButton_Click(object sender, EventArgs e)
        {
            if (UniqueIdRadio.Checked)
            {
                if (this.SpecFolderIdText.Text.Length == 0)
                {
                    ErrorDialog.ShowWarning("A FolderId must be entered.");
                    // this.DialogResult = DialogResult.None;
                    this.ChoseOK = false;
                }
                else
                {
                    this.ChosenFolderId = new FolderId(this.SpecFolderIdText.Text);

                    //FolderId idPublicFoldersRoot = new FolderId(WellKnownFolderName.PublicFoldersRoot);
                    //if (this.ChosenFolderId == idPublicFoldersRoot)
                    //{
                    //    if (_ExchangeService.HttpHeaders.ContainsKey("X-PublicFolderMailbox"))
                    //        _ExchangeService.HttpHeaders.Remove("X-PublicFolderMailbox");
                    //    ...
                    //    GetUserSettingsResponse userResponse = GetUserSettings(adservice, "*****@*****.**", 3, UserSettingName.PublicFolderInformation);
                    //    Console.WriteLine("X-AnchorMailbox value for public folder hierarchy requests: {0}", userResponse.Settings[UserSettingName.PublicFolderInformation]);
                    //}

                    this.ChoseOK = true;
                    this.Close();
                }
            }

            if (WellKnownRadio.Checked)
            {
                WellKnownFolderName name = this.wellKnownFolderCombo.SelectedItem.Value;

                // Exchange throws a schema validation error if FolderId(WellKnownName, Mailbox)
                // is passed an empty string for mailbox address so don't do that!
                if (this.MailboxAddressText.Text.Length == 0)
                {
                    this.ChosenFolderId = new FolderId(name);
                }
                else
                {
                    this.ChosenFolderId = new FolderId(name, new Mailbox(MailboxAddressText.Text));
                }

                this.ChoseOK = true;
                this.Close();
            }

            if (this.rdoSelectFolder.Checked)
            {
                if (this.txtPickedFolder.Text.Trim().Length == 0)
                {
                    ErrorDialog.ShowWarning("A Folder must be selected.");
                    //this.DialogResult = DialogResult.None;
                    this.ChoseOK = false;
                }
                else
                {
                    // base = {AAMkADE3ZDEyNzIyLWNmYTEtNDJjNC1iMDcxLWQ1YzRlOTllNThmZgAuAAAAAAAPhJtWhlq+R7kfwUCSYEOdAQATi1dys5KiTYjQdU3KXtHXAAABXjDIAAA=}
                    ChosenFolderId = new FolderId(this.txtPickedFolder.Text);
                    this.ChoseOK   = true;
                    this.Close();
                }
            }
        }
        private void MnuSaveAttach_Click(object sender, EventArgs e)
        {
            // Don't do anything if a content row is not selected
            if (this.ContentsGrid.SelectedRows.Count == 0)
            {
                return;
            }

            Attachment attach = this.ContentsGrid.SelectedRows[0].Cells[ColNameAttachmentObj].Value as Attachment;

            // If we can't get the attachment object bail out
            if (attach == null)
            {
                return;
            }

            // Get the file name we'll save to and bail out if we don't succeed
            // Create a file path to save the item properties to
            string fileName = null;

            //fileName = string.Format(
            //System.Globalization.CultureInfo.CurrentCulture,
            //    "{0}\\{1}.xml",
            //    destinationFolderPath,
            //    FileHelper.SanitizeFileName(item.Subject));

            fileName = this.GetTargetFileName(fileName);
            if (fileName == string.Empty)
            {
                return;
            }

            // If the attachment is a FileAttachment then simply save the content
            FileAttachment fileAttach = attach as FileAttachment;

            if (fileAttach != null)
            {
                if (fileAttach.Content == null)
                {
                    ErrorDialog.ShowWarning("Cannot save FileAttachment because FileAttachment.Content is NULL.");
                    return;
                }

                try
                {
                    this.Cursor = Cursors.WaitCursor;

                    System.IO.File.WriteAllBytes(fileName, fileAttach.Content);
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }
            else
            {
                ItemAttachment itemAttachment = attach as ItemAttachment;
                if (itemAttachment != null)
                {
                    if (itemAttachment.Item == null)
                    {
                        ErrorDialog.ShowWarning("Cannot save ItemAttachment because ItemAttachment.Item is NULL.");
                        return;
                    }

                    try
                    {
                        this.Cursor = Cursors.WaitCursor;

                        EWSEditor.Common.DumpHelper.DumpXML(
                            itemAttachment.Item,
                            fileName);
                    }
                    finally
                    {
                        this.Cursor = Cursors.Default;
                    }
                }
            }
        }
Beispiel #16
0
        private void GetAvailabilityButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                // Get AttendeeInfo from AttendeeList
                List <AttendeeInfo> attendees = null;
                if (!this.TryGetAttendeesFromList(out attendees))
                {
                    ErrorDialog.ShowWarning("There must be at least one attendee listed to retrieve availability for.");
                    return;
                }

                // Get TimeWindow from input
                TimeWindow window = new TimeWindow(
                    this.StartWindowDate.Value.ToUniversalTime(),
                    this.EndWindowDate.Value.ToUniversalTime());

                // Get RequestedData from input
                AvailabilityData requestedData = AvailabilityData.FreeBusy;
                if (this.availDataCombo.SelectedItem.HasValue)
                {
                    requestedData = this.availDataCombo.SelectedItem.Value;
                }

                // Collect AvailabilityOptions from form input
                AvailabilityOptions options = new AvailabilityOptions();
                if (this.CurrentMeetingCheck.Checked)
                {
                    options.CurrentMeetingTime = this.CurrentMeetingDate.Value;
                }
                else
                {
                    options.CurrentMeetingTime = null;
                }

                options.MeetingDuration           = Convert.ToInt32(this.MeetingDurationText.Text);
                options.DetailedSuggestionsWindow = new TimeWindow(
                    this.StartDetailDate.Value,
                    this.EndDetailDate.Value);
                options.GlobalObjectId          = this.GlobalObjectIdText.Text;
                options.GoodSuggestionThreshold = Convert.ToInt32(this.GoodSuggestThresholdText.Text);
                options.MaximumNonWorkHoursSuggestionsPerDay = Convert.ToInt32(this.MaxNonWorkSuggestText.Text);
                options.MaximumSuggestionsPerDay             = Convert.ToInt32(this.MaxSuggestPerDayText.Text);
                options.MergedFreeBusyInterval = Convert.ToInt32(this.MergeFBIntervalText.Text);

                if (this.minSuggestQualCombo.SelectedItem.HasValue)
                {
                    options.MinimumSuggestionQuality = this.minSuggestQualCombo.SelectedItem.Value;
                }

                if (this.requestFBViewCombo.SelectedItem.HasValue)
                {
                    options.RequestedFreeBusyView = this.requestFBViewCombo.SelectedItem.Value;
                }

                // Remember which attendee was selected in the AttendeeList
                int selectedIndex = -1;
                if (this.AttendeeList.SelectedItems != null &&
                    this.AttendeeList.SelectedItems.Count == 1)
                {
                    selectedIndex = this.AttendeeList.SelectedItems[0].Index;
                    this.AttendeeList.Items[selectedIndex].Selected = false;
                }

                // Make the EWS request
                GetUserAvailabilityResults results = this.CurrentService.GetUserAvailability(
                    attendees,
                    window,
                    requestedData,
                    options);

                // Enable result lists
                this.AttendeeAvailabilityList.Enabled = true;
                this.CalEventsList.Enabled            = true;
                this.SuggestionsList.Enabled          = true;

                // Attach AttendeeAvailability to the associated attendee in the ListView.
                // It can be assumed that the order of the AttendeesAvailability and Suggestions
                // results arrays correspond to the order of the attendees.
                for (int i = 0; i < attendees.Count; i++)
                {
                    AttendeeAvailability availResult = null;
                    if (results.AttendeesAvailability != null &&
                        results.AttendeesAvailability[i] != null)
                    {
                        availResult = results.AttendeesAvailability[i];
                    }

                    this.AddResultsToAttendee(attendees[i], availResult);
                }

                if (results.Suggestions != null)
                {
                    // Display the Suggestion in the ListView
                    foreach (Suggestion suggest in results.Suggestions)
                    {
                        foreach (TimeSuggestion time in suggest.TimeSuggestions)
                        {
                            ListViewItem timeItem = this.SuggestionsList.Items.Add(suggest.Date.ToShortDateString());
                            timeItem.SubItems.Add(suggest.Quality.ToString());
                            timeItem.SubItems.Add(time.MeetingTime.ToShortTimeString());
                            timeItem.SubItems.Add(time.Quality.ToString());
                            timeItem.SubItems.Add(time.Conflicts.Count.ToString());
                            timeItem.SubItems.Add(time.IsWorkTime.ToString());
                        }
                    }
                }

                // Reset the selected Attendee and display the results or show a message
                // to inform the user how to display results.
                if (selectedIndex > -1)
                {
                    this.AttendeeList.Items[selectedIndex].Selected = true;
                }
                else
                {
                    //this.AttendeeAvailabilityGroup.Text = "Select an attendee in the list to display availability results.";
                }
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }