Esempio n. 1
0
        private void lstEvents_DoubleClick(object sender, EventArgs e)
        {
            string ParentFolderName     = string.Empty;
            string ParentFolderClass    = string.Empty;
            string OldParentFolderName  = string.Empty;
            string OldParentFolderClass = string.Empty;

            string ItemName     = string.Empty;
            string ItemClass    = string.Empty;
            string OldItemName  = string.Empty;
            string OldItemClass = string.Empty;

            string FolderEvent_FolderName  = string.Empty;
            string FolderEvent_FolderClass = string.Empty;
            string Folder_OldFolderName    = string.Empty;
            string Folder_OldFolderClass   = string.Empty;

            Folder          oFolderId        = null;
            Item            oItem            = null;
            ExchangeService oExchangeService = null;



            if (lstEvents.SelectedItems.Count > 0)
            {
                if (lstEvents.SelectedItems[0].Tag.ToString().StartsWith("[") == false)
                {
                    NotificationEvent evt = (NotificationEvent)lstEvents.SelectedItems[0].Tag;

                    ItemEvent itemevt = (evt is ItemEvent) ? (ItemEvent)evt : null;

                    FolderEvent folderevt = (evt is FolderEvent) ? (FolderEvent)evt : null;

                    // New service and app settings
                    EWSEditor.Common.EwsEditorAppSettings oCurrentAppSettings = new EWSEditor.Common.EwsEditorAppSettings();
                    oExchangeService = EwsProxyFactory.CreateExchangeService();
                    // Todo: Flush out oCurrentAppSettings
                    CurrentAppSettings = oCurrentAppSettings;

                    if (lstEvents.SelectedItems[0].SubItems[4].Text.TrimEnd().Length != 0)
                    {
                        try
                        {
                            oExchangeService.ClientRequestId = Guid.NewGuid().ToString();  // Set a new GUID
                            oFolderId = Folder.Bind(oExchangeService, new FolderId(evt.ParentFolderId.UniqueId));
                            if (oFolderId != null)
                            {
                                ParentFolderName  = oFolderId.DisplayName;
                                ParentFolderClass = oFolderId.FolderClass;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Error: " + ex.ToString());
                        }
                    }
                    if (lstEvents.SelectedItems[0].SubItems[5].Text.TrimEnd().Length != 0)
                    {
                        try
                        {
                            oExchangeService.ClientRequestId = Guid.NewGuid().ToString();  // Set a new GUID
                            oFolderId = Folder.Bind(oExchangeService, new FolderId(evt.OldParentFolderId.UniqueId));
                            if (oFolderId != null)
                            {
                                OldParentFolderName  = oFolderId.DisplayName;
                                OldParentFolderClass = oFolderId.FolderClass;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Error: " + ex.ToString());
                        }
                    }
                    if (lstEvents.SelectedItems[0].SubItems[6].Text.TrimEnd().Length != 0)
                    {
                        try
                        {
                            oExchangeService.ClientRequestId = Guid.NewGuid().ToString();  // Set a new GUID
                            oItem = Item.Bind(oExchangeService, new ItemId(itemevt.ItemId.UniqueId));
                            if (oItem != null)
                            {
                                ItemName  = oItem.Subject;
                                ItemClass = oItem.ItemClass;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Error: " + ex.ToString());
                        }
                    }
                    if (lstEvents.SelectedItems[0].SubItems[7].Text.TrimEnd().Length != 0)
                    {
                        try
                        {
                            oExchangeService.ClientRequestId = Guid.NewGuid().ToString();  // Set a new GUID
                            oItem = Item.Bind(oExchangeService, new ItemId(itemevt.OldItemId.UniqueId));
                            if (oItem != null)
                            {
                                OldItemName  = oItem.Subject;
                                OldItemClass = oItem.ItemClass;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Error: " + ex.ToString());
                        }
                    }
                    if (lstEvents.SelectedItems[0].SubItems[8].Text.TrimEnd().Length != 0)
                    {
                        try
                        {
                            oExchangeService.ClientRequestId = Guid.NewGuid().ToString();  // Set a new GUID
                            oFolderId = Folder.Bind(oExchangeService, new FolderId(folderevt.ParentFolderId.UniqueId));
                            if (oFolderId != null)
                            {
                                FolderEvent_FolderName  = oFolderId.DisplayName;
                                FolderEvent_FolderClass = oFolderId.FolderClass;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Error: " + ex.ToString());
                        }
                    }
                    if (lstEvents.SelectedItems[0].SubItems[9].Text.TrimEnd().Length != 0)
                    {
                        try
                        {
                            oExchangeService.ClientRequestId = Guid.NewGuid().ToString();  // Set a new GUID
                            oFolderId = Folder.Bind(oExchangeService, new FolderId(folderevt.OldParentFolderId.UniqueId));
                            if (oFolderId != null)
                            {
                                Folder_OldFolderName  = oFolderId.DisplayName;
                                Folder_OldFolderClass = oFolderId.FolderClass;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Error: " + ex.ToString());
                        }
                    }

                    StringBuilder oSB = new StringBuilder();
                    oSB.AppendFormat("EventType:                \r\n    {0}\r\n", lstEvents.SelectedItems[0].Text);
                    oSB.AppendFormat("\r\n");
                    oSB.AppendFormat("Thread:                   \r\n    {0}\r\n", lstEvents.SelectedItems[0].SubItems[1].Text);
                    oSB.AppendFormat("\r\n");
                    oSB.AppendFormat("TimeStamp:                \r\n    {0}\r\n", lstEvents.SelectedItems[0].SubItems[2].Text);
                    oSB.AppendFormat("\r\n");
                    oSB.AppendFormat("EventType:                \r\n    {0}\r\n", lstEvents.SelectedItems[0].SubItems[3].Text);
                    oSB.AppendFormat("\r\n");

                    oSB.AppendFormat("ParentFolderId:\r\n");
                    if (evt != null)
                    {
                        if (evt.ParentFolderId != null)
                        {
                            oSB.AppendFormat("    UniqueId:  {0}\r\n", evt.ParentFolderId.UniqueId.ToString());
                            oSB.AppendFormat("    ChangeKey: {0}\r\n", evt.ParentFolderId.ChangeKey.ToString());
                            oSB.AppendFormat("    Name:      {0}\r\n", ParentFolderName);
                            oSB.AppendFormat("    Class:     {0}\r\n", ParentFolderClass);
                        }
                    }
                    oSB.AppendFormat("\r\n");

                    oSB.AppendFormat("OldParentFolderId:\r\n");
                    if (evt != null)
                    {
                        if (evt.OldParentFolderId != null)
                        {
                            oSB.AppendFormat("    UniqueId:  {0}\r\n", evt.OldParentFolderId.UniqueId.ToString());
                            oSB.AppendFormat("    ChangeKey: {0}\r\n", evt.OldParentFolderId.ChangeKey.ToString());
                            oSB.AppendFormat("    Name:      {0}\r\n", OldParentFolderName);
                            oSB.AppendFormat("    Class:     {0}\r\n", OldParentFolderClass);
                        }
                    }
                    oSB.AppendFormat("\r\n");

                    oSB.AppendFormat("Item.ItemId:\r\n");
                    if (itemevt != null)
                    {
                        if (itemevt.ItemId != null)
                        {
                            oSB.AppendFormat("    UniqueId:  {0}\r\n", itemevt.ItemId.UniqueId.ToString());
                            oSB.AppendFormat("    ChangeKey: {0}\r\n", itemevt.ItemId.ChangeKey.ToString());
                            oSB.AppendFormat("    Name:      {0}\r\n", ItemName);
                            oSB.AppendFormat("    Class:     {0}\r\n", ItemClass);
                        }
                    }
                    oSB.AppendFormat("\r\n");

                    oSB.AppendFormat("Item.OldItemId:\r\n");
                    if (itemevt != null)
                    {
                        if (itemevt.OldItemId != null)
                        {
                            oSB.AppendFormat("    UniqueId:  {0}\r\n", itemevt.OldItemId.UniqueId.ToString());
                            oSB.AppendFormat("    ChangeKey: {0}\r\n", itemevt.OldItemId.ChangeKey.ToString());
                            oSB.AppendFormat("    Name:      {0}\r\n", OldItemName);
                            oSB.AppendFormat("    Class:     {0}\r\n", OldItemClass);
                        }
                    }
                    oSB.AppendFormat("\r\n");


                    oSB.AppendFormat("FolderEvent.FolderId:\r\n");
                    if (folderevt != null)
                    {
                        if (folderevt.ParentFolderId != null)
                        {
                            oSB.AppendFormat("    UniqueId:  {0}\r\n", folderevt.ParentFolderId.UniqueId.ToString());
                            oSB.AppendFormat("    ChangeKey: {0}\r\n", folderevt.ParentFolderId.ChangeKey.ToString());
                            oSB.AppendFormat("    Name:      {0}\r\n", FolderEvent_FolderName);
                            oSB.AppendFormat("    Class:     {0}\r\n", FolderEvent_FolderClass);
                        }
                    }
                    oSB.AppendFormat("\r\n");

                    oSB.AppendFormat("Folder.OldFolderId:\r\n");
                    if (folderevt != null)
                    {
                        if (folderevt.OldParentFolderId != null)
                        {
                            oSB.AppendFormat("    UniqueId:  {0}\r\n", folderevt.OldParentFolderId.UniqueId.ToString());
                            oSB.AppendFormat("    ChangeKey: {0}\r\n", folderevt.OldParentFolderId.ChangeKey.ToString());
                            oSB.AppendFormat("    Name:      {0}\r\n", Folder_OldFolderName);
                            oSB.AppendFormat("    Class:     {0}\r\n", Folder_OldFolderClass);
                        }
                    }
                    oSB.AppendFormat("\r\n");

                    //oSB.AppendFormat("ParentFolderId:           \r\n    {0}\r\n", lstEvents.SelectedItems[0].SubItems[4].Text.TrimEnd().Replace("ChangeKey:", "\r\n    ChangeKey:"));
                    //oSB.AppendFormat("\r\n");
                    //oSB.AppendFormat("OldParentFolderId:        \r\n    {0}\r\n", lstEvents.SelectedItems[0].SubItems[5].Text.TrimEnd().Replace("ChangeKey:", "\r\n    ChangeKey:"));
                    //oSB.AppendFormat("\r\n");

                    //oSB.AppendFormat("Item.ItemId:              \r\n    {0}\r\n", lstEvents.SelectedItems[0].SubItems[6].Text.TrimEnd().Replace("ChangeKey:", "    ChangeKey:"));
                    //oSB.AppendFormat("\r\n");
                    //oSB.AppendFormat("Item.OldItemId:           \r\n    {0}\r\n", lstEvents.SelectedItems[0].SubItems[7].Text.TrimEnd().Replace("ChangeKey:", "    ChangeKey:"));
                    //oSB.AppendFormat("\r\n");

                    //oSB.AppendFormat("FolderEvent.FolderId:     \r\n    {0}\r\n", lstEvents.SelectedItems[0].SubItems[8].Text.TrimEnd().Replace("ChangeKey:", "\r\n    ChangeKey:"));
                    //oSB.AppendFormat("\r\n");
                    //oSB.AppendFormat("Folder.OldFolderId:       \r\n    {0}\r\n", lstEvents.SelectedItems[0].SubItems[9].Text.TrimEnd().Replace("ChangeKey:", "    ChangeKey:"));
                    //oSB.AppendFormat("\r\n");

                    oSB.AppendFormat("FolderEvent.UnreadCount:  \r\n    {0}\r\n", lstEvents.SelectedItems[0].SubItems[10].Text);

                    string sContent = oSB.ToString();

                    ShowTextDocument oForm = new ShowTextDocument();
                    oForm.txtEntry.WordWrap = false;
                    oForm.Text          = "Information";
                    oForm.txtEntry.Text = sContent;
                    oForm.ShowDialog();
                }
            }
        }
Esempio n. 2
0
        ////DJB
        //private void GetGroupingInfo(ExchangeService oExchangeService, string DiscoverMailbox)
        //{
        //    //oExchangeService.get
        //    string UseVersion = oExchangeService.RequestedServerVersion.ToString();
        //    string UseUrl = oExchangeService.Url.ToString();  // djb - need to fix it to the autodiscover url.

        //    string EwsRequest = EwsRequests.GroupingInformationTemplateRequest;
        //    EwsRequest =  EwsRequest.Replace("XXXExchangeVersionXXX",  UseVersion);
        //    EwsRequest =  EwsRequest.Replace("XXXAutoDiscoverServiceServerXXX", UseUrl);
        //    EwsRequest =  EwsRequest.Replace("XXXMailboxSmtpXXX", DiscoverMailbox);

        //    // DO raw post
        //    // string sResponse
        //    // if (DoRawPost(UseUrl, oExchangeService.ServerCredentials, EwsRequest, ref sResponse));
        //    // {
        //    //    Extract GroupingInformation and external url from sResponse);
        //    // }
        //    // else
        //    // {
        //    //    return error;
        //    // }
        //}

        private void StreamingSubscribeWork()
        {
            // djb
            // get a list of maiboxes, thier external ews urls and grouping info
            // list of items = GetGroupingInfo(ExchangeService oExchangeService, string DiscoverMailbox);
            // Sort list of items by url + GroupingInformaiton
            //

            try
            {
                lock (WorkThreads)
                {
                    WorkThreads.Add(Thread.CurrentThread);
                    SetControlText(ThreadCount, WorkThreads.Count.ToString());
                }

                if (chkSerialize.Checked)
                {
                    mutConnection.WaitOne();
                }

                string       TID  = Thread.CurrentThread.ManagedThreadId.ToString("[0]");
                ListViewItem item = new ListViewItem();
                item.Tag  = "[local]ThreadStart";
                item.Text = "[local]ThreadStart";
                item.SubItems.Add(TID);
                item.SubItems.Add(DateTime.Now.ToString());
                AddToDisplay(lstEvents, item);

                // Note that EWS Managed API objects should not beshared accross threads - So, each thread should have its own service object.
                //EWSEditor.Common.EwsEditorServiceInstanceSettings.EwsEditorAppSettings oSettings = new EWSEditor.Common.EwsEditorServiceInstanceSettings.EwsEditorAppSettings();


                EWSEditor.Common.EwsEditorAppSettings oCurrentAppSettings = null;
                ExchangeService ThreadLocalService = EwsProxyFactory.CreateExchangeService( );
                // Todo: Flush out oCurrentAppSettings
                CurrentAppSettings = oCurrentAppSettings;

                List <StreamingSubscription> ThreadLocalSubscriptions = new List <StreamingSubscription>();

                // Create the subscriptions based on the form settings
                for (int i = 0; i < numSubs.Value; i++)
                {
                    try
                    {
                        StreamingSubscription CurrentSubscription = null;
                        if (chkAllFoldes.Checked == false)
                        {
                            CurrentSubscription = ThreadLocalService.SubscribeToStreamingNotifications(
                                new FolderId[] { this.CurrentFolderId },
                                EventTypes.ToArray());
                            //System.Diagnostics.Debug.WriteLine("-");
                            //System.Diagnostics.Debug.WriteLine("Subscribe - ID: " + CurrentSubscription.Id + "  Watermark: " + CurrentSubscription.Watermark);
                            //System.Diagnostics.Debug.WriteLine("-");
                        }
                        else
                        {
                            CurrentSubscription = ThreadLocalService.SubscribeToStreamingNotificationsOnAllFolders(
                                EventTypes.ToArray());
                            //System.Diagnostics.Debug.WriteLine("-");
                            //System.Diagnostics.Debug.WriteLine("Subscribe - ID: " + CurrentSubscription.Id + "  Watermark: " + CurrentSubscription.Watermark);
                            //System.Diagnostics.Debug.WriteLine("-");
                        }

                        ThreadLocalSubscriptions.Add(CurrentSubscription);
                        lock (ActiveSubscriptions)
                        {
                            ActiveSubscriptions.Add(CurrentSubscription);
                            SetControlText(SubscriptionCount, ActiveSubscriptions.Count.ToString());
                        }
                    }
                    catch (Exception ex)
                    {
                        DebugLog.WriteException("Error Subscribe or Add [TID:" + TID + "]", ex);
                        item             = new ListViewItem();
                        item.Tag         = "[local]SubscribeError";
                        item.Text        = "[local]SubscribeError";
                        item.ToolTipText = ex.ToString();
                        item.SubItems.Add(TID);
                        item.SubItems.Add(DateTime.Now.ToString());
                        AddToDisplay(lstEvents, item);
                    }
                }

                // Create a new StreamingSubscriptionConnection
                StreamingSubscriptionConnection CurrentConnection = new StreamingSubscriptionConnection(ThreadLocalService, (int)SubscriptionLifetime.Value);

                lock (ActiveConnections)
                {
                    ActiveConnections.Add(CurrentConnection);
                    SetControlText(ConnectionCount, ActiveConnections.Count.ToString());
                }

                // Add Handlers
                CurrentConnection.OnDisconnect        += OnDisconnect;
                CurrentConnection.OnSubscriptionError += OnSubscriptionError;
                CurrentConnection.OnNotificationEvent += OnStreamingEvent;


                // Add the Subscriptions to the Connection
                foreach (StreamingSubscription CurrentSubscription in ThreadLocalSubscriptions)
                {
                    CurrentConnection.AddSubscription(CurrentSubscription);
                }

                if (chkSerialize.Checked)
                {
                    mutConnection.ReleaseMutex();
                }

                // Open the Connection
                try
                {
                    if (ThreadLocalService.CookieContainer.Count > 0)
                    {
                        System.Net.CookieCollection MyCookies = ThreadLocalService.CookieContainer.GetCookies(ThreadLocalService.Url);
                    }
                    CurrentConnection.Open();

                    ShutdownThreads.WaitOne();
                }
                catch (Exception ex)
                {
                    DebugLog.WriteException("Error Opening StreamingSubscriptionConnection [TID:"
                                            + Thread.CurrentThread.ManagedThreadId.ToString() + "]", ex);
                    item             = new ListViewItem();
                    item.Tag         = "[local]OpenError";
                    item.Text        = "[local]OpenError";
                    item.ToolTipText = ex.ToString();
                    item.SubItems.Add(TID);
                    item.SubItems.Add(DateTime.Now.ToString());
                    AddToDisplay(lstEvents, item);

                    //System.Diagnostics.Debug.WriteLine("-");
                    //System.Diagnostics.Debug.WriteLine("Error Opening StreamingSubscriptionConnection [TID:" + Thread.CurrentThread.ManagedThreadId.ToString() + "]", ex);
                    //System.Diagnostics.Debug.WriteLine("-");
                }

                try
                {
                    //  Close Connection
                    if (CurrentConnection.IsOpen)
                    {
                        CurrentConnection.Close();
//                        Thread.Sleep(500);
                    }
                }
                catch (Exception ex)
                {
                    DebugLog.WriteException("Error Closing Streaming Connection [TID:" + Thread.CurrentThread.ManagedThreadId.ToString() + "]", ex);
                    item             = new ListViewItem();
                    item.Tag         = "[local]CloseError";
                    item.Text        = "[local]CloseError";
                    item.ToolTipText = ex.ToString();
                    item.SubItems.Add(TID);
                    item.SubItems.Add(DateTime.Now.ToString());
                    AddToDisplay(lstEvents, item);

                    //System.Diagnostics.Debug.WriteLine("-");
                    //System.Diagnostics.Debug.WriteLine("Error Closing Streaming Connection [TID:" + Thread.CurrentThread.ManagedThreadId.ToString() + "]", ex);
                    //System.Diagnostics.Debug.WriteLine("-");
                }
                finally
                {
                    lock (ActiveConnections)
                    {
                        ActiveConnections.Remove(CurrentConnection);
                        SetControlText(ConnectionCount, ActiveConnections.Count.ToString());
                    }
                }

                //  Remove Handlers
                CurrentConnection.OnDisconnect        -= OnDisconnect;
                CurrentConnection.OnSubscriptionError -= OnSubscriptionError;
                CurrentConnection.OnNotificationEvent -= OnStreamingEvent;

                foreach (StreamingSubscription CurrentSubscription in ThreadLocalSubscriptions)
                {
                    try
                    {
                        CurrentConnection.RemoveSubscription(CurrentSubscription);
                        CurrentSubscription.Unsubscribe();

                        //System.Diagnostics.Debug.WriteLine("-");
                        //System.Diagnostics.Debug.WriteLine("Unsubscribed - ID: " + CurrentSubscription.Id + "  Watermark: " + CurrentSubscription.Watermark);
                        //System.Diagnostics.Debug.WriteLine("-");
                    }
                    catch (Exception ex)
                    {
                        DebugLog.WriteException("Error Removing/Unsubscribing StreamingSubscription Elements [TID:"
                                                + Thread.CurrentThread.ManagedThreadId.ToString() + "]", ex);
                        item             = new ListViewItem();
                        item.Tag         = "[local]UnsubscribeError";
                        item.Text        = "[local]UnsubscribeError";
                        item.ToolTipText = ex.ToString();
                        item.SubItems.Add(TID);
                        item.SubItems.Add(DateTime.Now.ToString());
                        AddToDisplay(lstEvents, item);

                        //System.Diagnostics.Debug.WriteLine("-");
                        //System.Diagnostics.Debug.WriteLine("Error Removing/Unsubscribing StreamingSubscription Elements [TID:" + Thread.CurrentThread.ManagedThreadId.ToString() + "]", ex);
                        //System.Diagnostics.Debug.WriteLine("        ID: " + CurrentSubscription.Id + "  Watermark: " + CurrentSubscription.Watermark);
                        //System.Diagnostics.Debug.WriteLine("-");
                    }
                    finally
                    {
                        lock (ActiveSubscriptions)
                        {
                            //System.Diagnostics.Debug.WriteLine("-");
                            //System.Diagnostics.Debug.WriteLine("Removing subscription - ID: " + CurrentSubscription.Id + "  Watermark: " + CurrentSubscription.Watermark);
                            //System.Diagnostics.Debug.WriteLine("-");

                            ActiveSubscriptions.Remove(CurrentSubscription);
                            SetControlText(SubscriptionCount, ActiveSubscriptions.Count.ToString());
                        }
                    }
                }

                lock (WorkThreads)
                {
                    WorkThreads.Remove(Thread.CurrentThread);
                }
                SetControlText(ThreadCount, WorkThreads.Count.ToString());
            }
            catch (Exception ex) { DebugLog.WriteException("Unexpected Exception in WorkerThread", ex); }
            finally { }
        }
Esempio n. 3
0
        /// <summary>
        /// Constructor which loads a saved ServiceProfile from a file at the
        /// given path.
        /// </summary>
        /// <param name="profilePath">Path to ServiceProfile XML file.</param>
        /// /// <param name="showDialogs">Indicates whether to show UI when needed.</param>
        /// /// <param name="testServices">Indicates whether to test the ExchangeServices before returning them.</param>
        internal ServiceProfile(string profilePath, bool showDialogs, bool testServices)
        {
            ServicesProfile.ServiceBindingDataTable dt = new ServicesProfile.ServiceBindingDataTable();
            dt.ReadXml(profilePath);

            foreach (ServicesProfile.ServiceBindingRow row in dt.Rows)
            {
                try
                {
                    ExchangeService service = null;
                    EWSEditor.Common.EwsEditorAppSettings oAppSettings = null;

                    if (!row.UsesDefaultCredentials)
                    {
                        // Display the Name of the binding in the dialog rather than the URL which
                        // can be ambiguous...
                        System.Net.NetworkCredential cred = null;

                        // For the sake of debugging, we could allow a tester to hard code a user name
                        // and password into the ServiceProfile.
                        cred = new System.Net.NetworkCredential(
                            row.IsUserNameNull() ? null: row.UserName,
                            row.IsPasswordNull() ? null : row.Password,
                            row.IsDomainNull() ? null : row.Domain);

                        if (row.IsUserNameNull() || row.IsPasswordNull() || row.IsDomainNull())
                        {
                            // If we are allowed to show dialogs, pop up a credential dialog to get
                            // input from the user.
                            if (showDialogs)
                            {
                                // If we have a service name to display, use it as the caption for
                                // the credential dialog.
                                if (!row.IsNameNull())
                                {
                                    NetworkCredDialog.ShowDialog(row.Name, ref cred);
                                }
                                else
                                {
                                    NetworkCredDialog.ShowDialog(row.ServicesURL, ref cred);
                                }
                            }
                        }
                        else
                        {
                        }

                        // If we still don't have credentials, throw.
                        if (cred != null)
                        {
                            service = LoadExchangeServiceFromProfileRow(row, cred, out oAppSettings);
                        }
                        else
                        {
                            throw new ApplicationException(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Cannot load binding {0} without credentials.", row.Name));
                        }
                    }
                    else
                    {
                        service = LoadExchangeServiceFromProfileRow(row, null, out oAppSettings);
                    }

                    if (testServices)
                    {
                        service.TestExchangeService();
                    }

                    FolderId[] rootFolderIds = LoadRootFolderIdsFromProfileRow(row);

                    this.profileItems.Add(new ServiceProfileItem(service, rootFolderIds, oAppSettings));
                }
                catch (Exception ex)
                {
                    DebugLog.WriteVerbose("Handled exception when loading profile", ex);

                    // If we are allowed to show dialogs, display the exception.  If not, keep
                    // on loading ServiceProfileItems
                    if (showDialogs)
                    {
                        // Catch and handle each exception within the loop so that failing
                        // to load one ExchangeService doesn't cause the remaining to be skipped.
                        ErrorDialog.ShowError(ex);
                    }

                    // Because there might be multiple profiles loaded, instead of waiting for
                    // each one to fail, give the option to stop loading the entire profile
                    DialogResult result = MessageBox.Show(
                        "Do you want to continue to load ExchangeServices from this profile?",
                        BaseForm.GetFormTitle(""),
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question,
                        MessageBoxDefaultButton.Button1);

                    if (result == DialogResult.No)
                    {
                        break;
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Get the ExchangeService from a given row.
        /// </summary>
        private ExchangeService LoadExchangeServiceFromProfileRow(
            ServicesProfile.ServiceBindingRow row,
            NetworkCredential cred,
            out EWSEditor.Common.EwsEditorAppSettings oAppSettings)
        {
            // Create the ExchangeService


            if (!row.IsRequestedServerVersionNull())
            {
                // Convert the string to an ExchangeVersion enumeration
                ExchangeVersion req =
                    (ExchangeVersion)System.Enum.Parse(typeof(ExchangeVersion), row.RequestedServerVersion);
                EwsProxyFactory.RequestedExchangeVersion = req;
            }


            // Load autodiscover email if found
            if (!row.IsAutoDiscoverEmailNull())
            {
                EwsProxyFactory.AllowAutodiscoverRedirect = GlobalSettings.AllowAutodiscoverRedirect;
                EwsProxyFactory.ServiceEmailAddress       = new EmailAddress(row.AutoDiscoverEmail);
            }

            if (!row.IsServicesURLNull())
            {
                EwsProxyFactory.EwsUrl = new Uri(row.ServicesURL);
            }


            // If ImpersonationType is specified then we assume an Id is as well
            if (!row.IsImpersonationTypeNull())
            {
                // Convert the string to a ConnectingIdType enumeration
                ConnectingIdType impType =
                    (ConnectingIdType)System.Enum.Parse(typeof(ConnectingIdType), row.ImpersonationType);
                EwsProxyFactory.UserToImpersonate = new ImpersonatedUserId(impType, row.ImpersonationId);
            }

            // If credentials are not required then use DefaultCredentials
            if (row.UsesDefaultCredentials)
            {
                EwsProxyFactory.UseDefaultCredentials = true;
            }
            else
            {
                if (cred != null)
                {
                    EwsProxyFactory.ServiceCredential = cred;
                }
                else
                {
                    throw new ApplicationException("Credentials are required for this binding.");
                }
            }


            ExchangeService oService = EwsProxyFactory.CreateExchangeService();

            oAppSettings = new EWSEditor.Common.EwsEditorAppSettings();
            EwsProxyFactory.SetAppSettingsFromProxyFactory(ref oAppSettings);

            return(oService);
            //return EwsProxyFactory.CreateExchangeService();
        }
Esempio n. 5
0
 internal ServiceProfileItem(ExchangeService service, FolderId[] rootFolderIds, EWSEditor.Common.EwsEditorAppSettings oAppSettings)
 {
     Service       = service;
     RootFolderIds = rootFolderIds;
     AppSettings   = oAppSettings;
 }
Esempio n. 6
0
 /// <summary>
 /// Save the current ServiceBinding settings to the DataTable
 /// </summary>
 /// <param name="service">ExchangeService to store in profile.</param>
 /// <param name="rootFolderIds">Array of root folder ids to store with the ExchangeService.</param>
 internal void AddServiceToProfile(ExchangeService service, FolderId[] rootFolderIds, EWSEditor.Common.EwsEditorAppSettings oAppSettings)
 {
     this.profileItems.Add(new ServiceProfileItem(service, rootFolderIds, oAppSettings));
 }