Example #1
0
        /// <summary>
        /// Get root folder ids from the given row.
        /// </summary>
        private FolderId[] LoadRootFolderIdsFromProfileRow(ServicesProfile.ServiceBindingRow row)
        {
            List <FolderId> ids = new List <FolderId>();

            // If the field has no value, bail out
            if (row.IsRootFolderIdsNull() || row.RootFolderIds.Length == 0)
            {
                return(ids.ToArray());
            }

            foreach (string idText in row.RootFolderIds.Split('|'))
            {
                string uniqueId             = string.Empty;
                WellKnownFolderName?name    = null;
                Mailbox             mailbox = null;

                foreach (string piece in idText.Split(','))
                {
                    // Clean up the piece separator
                    piece.Replace(",", "");

                    // Strip out the data from the pieces
                    if (piece.StartsWith("Name:"))
                    {
                        name = (WellKnownFolderName?)System.Enum.Parse(typeof(WellKnownFolderName), piece.Replace("Name:", ""));
                    }
                    else if (piece.StartsWith("Mbx:"))
                    {
                        mailbox = new Mailbox(piece.Replace("Mbx:", ""));
                    }
                    else if (piece.StartsWith("Id:"))
                    {
                        uniqueId = piece.Replace("Id:", "");
                    }
                }

                FolderId id;
                if (name.HasValue)
                {
                    if (mailbox != null)
                    {
                        id = new FolderId(name.Value, mailbox.Address);
                    }
                    else
                    {
                        id = new FolderId(name.Value);
                    }
                }
                else
                {
                    id = new FolderId(uniqueId);
                }
                ids.Add(id);
            }

            return(ids.ToArray());
        }
Example #2
0
        /// <summary>
        /// Save the current profile and its items to the given file path.
        /// </summary>
        /// <param name="profilePath">File to save the profile information.</param>
        internal void SaveProfile(string profilePath)
        {
            ServicesProfile.ServiceBindingDataTable data = new ServicesProfile.ServiceBindingDataTable();

            foreach (ServiceProfileItem item in this.profileItems)
            {
                ServicesProfile.ServiceBindingRow row = data.NewServiceBindingRow();

                row.Name = PropertyInterpretation.GetPropertyValue(item.Service);

                //row.AutoDiscoverEmail = this.AutodiscoverEmailUsed;

                row.ServicesURL = item.Service.Url.OriginalString;

                row.RequestedServerVersion = item.Service.RequestedServerVersion.ToString();

                if (item.Service.ImpersonatedUserId != null)
                {
                    row.ImpersonationId   = item.Service.ImpersonatedUserId.Id;
                    row.ImpersonationType = item.Service.ImpersonatedUserId.IdType.ToString();
                }

                row.UsesDefaultCredentials = item.Service.UseDefaultCredentials;
                //row.UserName = item.Service.GetNetworkCredential().UserName;  //TODO:  The saving and loading of profiles needs to be reworked.
                //row.Domain = item.Service.GetNetworkCredential().Domain;

                // Add root folders to the data table.
                StringBuilder sb = new StringBuilder();
                foreach (FolderId id in item.RootFolderIds)
                {
                    // If this is not the first FolderId add a separator
                    if (sb.Length > 0)
                    {
                        sb.Append("|");
                    }

                    if (id.FolderName.HasValue && id.Mailbox != null)
                    {
                        sb.Append(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Name:{0},Mbx:{1}", id.FolderName.ToString(), id.Mailbox.Address));
                    }
                    else if (id.FolderName.HasValue)
                    {
                        sb.Append(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Name:{0}", id.FolderName.ToString()));
                    }
                    else
                    {
                        sb.Append(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Id:{0}", id.UniqueId));
                    }
                }
                row.RootFolderIds = sb.ToString();

                data.AddServiceBindingRow(row);
            }

            data.WriteXml(profilePath);
        }
Example #3
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();
        }