public ExchangeService GetExchangeService(ExchangeServerSettings exchangeServerSettings)
 {
     ExchangeVersion exchangeVersion;
     var isValidVersion = Enum.TryParse(exchangeServerSettings.ExchangeVersion, true, out exchangeVersion);
     if (isValidVersion)
     {
         var service = new ExchangeService(exchangeVersion)
         {
             UseDefaultCredentials = exchangeServerSettings.UsingCorporateNetwork,
             EnableScpLookup = false,
             Url = new Uri(exchangeServerSettings.ExchangeServerUrl)
         };
         if (string.IsNullOrEmpty(exchangeServerSettings.ExchangeServerUrl))
         {
             service.AutodiscoverUrl(exchangeServerSettings.EmailId);
         }
         if (!exchangeServerSettings.UsingCorporateNetwork)
         {
             service.Credentials = new WebCredentials(exchangeServerSettings.EmailId,
                 exchangeServerSettings.Password,
                 exchangeServerSettings.Domain);
         }
         //service.Credentials = new WebCredentials("*****@*****.**", "password");
         return service;
     }
     return null;
 }
 public CalendarSyncProfile()
 {
     Name = "Default Profile";
     SyncSettings = new SyncSettings();
     ExchangeServerSettings = new ExchangeServerSettings();
     OutlookSettings = new OutlookSettings();
     IsSyncEnabled = true;
     IsDefault = true;
 }
Esempio n. 3
0
 public CalendarSyncProfile()
 {
     Name                   = "Default Profile";
     SyncSettings           = new SyncSettings();
     ExchangeServerSettings = new ExchangeServerSettings();
     OutlookSettings        = new OutlookSettings();
     IsSyncEnabled          = true;
     IsDefault              = true;
 }
        public ExchangeServerSettings GetBestSuitedExchangeServerData(string domain, string emailId, string password,
            bool usingCorporateNetwork = false)
        {
            ExchangeServerSettings exchangeServerSettings = null;
            var enumList =
                Enum.GetValues(typeof (ExchangeVersion)).Cast<ExchangeVersion>().Reverse();

            var proxy = WebRequest.DefaultWebProxy;
            proxy.Credentials = CredentialCache.DefaultNetworkCredentials;


            var exchangeVersions = enumList as ExchangeVersion[] ?? enumList.ToArray();
            foreach (var exchangeVersion in exchangeVersions)
            {
                var service = new ExchangeService(exchangeVersion)
                {
                    UseDefaultCredentials = usingCorporateNetwork,
                    WebProxy = proxy
                };

                if (usingCorporateNetwork)
                {
                    service.Credentials = string.IsNullOrEmpty(domain)
                        ? new WebCredentials(emailId, password)
                        : new WebCredentials(emailId, password, domain);
                }

                try
                {
                    service.AutodiscoverUrl(emailId);
                    //Try to get value form Exchange Server
                    var calendarFolder = CalendarFolder.Bind(service, WellKnownFolderName.Calendar);
                    exchangeServerSettings = new ExchangeServerSettings
                    {
                        ExchangeServerUrl = service.Url.AbsoluteUri,
                        ExchangeVersion = exchangeVersion.ToString(),
                        Password = password,
                        EmailId = emailId,
                        Domain = domain,
                        UsingCorporateNetwork = usingCorporateNetwork
                    };
                }
                catch (Exception exception)
                {
                    ApplicationLogger.Error(exception);
                }
            }
            return exchangeServerSettings;
        }
        public void CheckCalendarSpecificData(IDictionary<string, object> calendarSpecificData)
        {
            if (calendarSpecificData == null)
            {
                throw new ArgumentNullException("calendarSpecificData", "Calendar Specific Data cannot be null");
            }

            object ewsCalendar;
            object serverSettings;
            object addAsAppointments;
            if (!(calendarSpecificData.TryGetValue(EWSCALENDAR, out ewsCalendar) &&
                  calendarSpecificData.TryGetValue(EXCHANGESERVERSETTINGS, out serverSettings) &&
                  calendarSpecificData.TryGetValue("AddAsAppointments", out addAsAppointments)))
            {
                throw new InvalidOperationException(
                    string.Format(
                        "{0} {1} and {2}  keys should be present, both of them can be null in case Default Profile and Default Calendar will be used. {0} is of 'string' type, {1} is of 'OutlookCalendar' type and {2} is of bool type.",
                        EWSCALENDAR, EXCHANGESERVERSETTINGS, "AddAsAppointments"));
            }
            _ewsCalendar = ewsCalendar as EWSCalendar;
            ExchangeServerSettings = serverSettings as ExchangeServerSettings;
            _addAsAppointments = (bool) addAsAppointments;
            object eventCategory;
            if (calendarSpecificData.TryGetValue("EventCategory", out eventCategory))
            {
                _eventCategory = eventCategory as Category;
            }
            else
            {
                _eventCategory = null;
            }
        }