コード例 #1
0
        public override void Open()
        {
            if (!(channelState == ChannelState.Closed || channelState == ChannelState.Broken))
            {
                return;
            }

            channelState = ChannelState.Connecting;

            try
            {
                client = new POP3_Client();

                if ("/Settings/Channels/LoggerEnabled".AsKey(false))
                {
                    client.Logger           = new LumiSoft.Net.Log.Logger();
                    client.Logger.WriteLog += (sender, e) => Logger.Debug(e.LogEntry.Text, LogSource.Channel);
                }

                client.Connect(Hostname, Port, IsSecured);

                channelState = ChannelState.Connected;
            }
            catch (Exception ex)
            {
                channelState = ChannelState.Closed;

                throw new ChannelException("Unable to connect to server", ex);
            }
        }
コード例 #2
0
        public override void Authenticate()
        {
            if (channelState == ChannelState.Authenticated)
            {
                return;
            }

            if (channelState != ChannelState.Connected)
            {
                throw new ChannelException("Unable to authenticate in current channel state");
            }

            try
            {
                client.Authenticate(Username, Password, true);

                channelState = ChannelState.Authenticated;
            }
            catch (POP3_ClientException ex)
            {
                channelState = ChannelState.Broken;

                Logger.Debug("FAILED Authenticating connection {0}. Server said {1}", LogSource.Channel, UniqueId, ex.ResponseText);

                throw new ChannelAuthenticationException(ex.ResponseText, ex);
            }
        }
コード例 #3
0
        public ConnectResult Connect()
        {
            var credentials = CredentialsProvider.GetCredentials();
            var binding     = ChannelHelper.BuildChannel(Hostname, credentials.Claim, credentials.Evidence);

            folders = new List <ChannelFolder>();

            // Try connecting
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(binding.Url);

            request.AllowAutoRedirect = false;
            request.Credentials       = new NetworkCredential(credentials.Claim, credentials.Evidence);

            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                Logger.Debug("Server {0} returned status-code {1}", LogSource.Channel, binding.Url, response.StatusCode);

                if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Found)
                {
                    return(ConnectResult.Success);
                }

                AuthMessage = String.Format("Statuscode {0}", response.StatusCode);

                return(ConnectResult.AuthFailure);
            }
            catch (Exception ex)
            {
                AuthMessage = ex.Message;

                return(ConnectResult.AuthFailure);
            }
        }
コード例 #4
0
        public override void Authenticate()
        {
            Logger.Debug("Authenticating connection {0}", LogSource.Channel, UniqueId);

            if (channelState == ChannelState.Authenticated)
            {
                return;
            }

            if (channelState != ChannelState.Connected)
            {
                Logger.Error("Unable to authenticate in current channel state. ChannelState = {0}", LogSource.Channel, channelState);

                throw new ChannelException("Unable to authenticate in current channel state");
            }

            try
            {
                client.Capability();
                client.YahooImap();
                client.Authenticate(Username, Password);

                channelState = ChannelState.Authenticated;

                Logger.Debug("SUCCESS Authenticating connection {0}", LogSource.Channel, UniqueId);
            }
            catch (IMAP_ClientException ex)
            {
                channelState = ChannelState.Broken;

                Logger.Debug("FAILED Authenticating connection {0}. Server said {1}", LogSource.Channel, UniqueId, ex.ResponseText);

                throw new ChannelAuthenticationException(ex.ResponseText, ex);
            }
        }
コード例 #5
0
        public MemoryStream GetContentStream()
        {
            HttpWebResponse response = null;

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

                if (prepareRequest != null)
                {
                    prepareRequest(request);
                }

                response = (HttpWebResponse)request.GetResponse();

                MemoryStream ms = new MemoryStream();

                var stream = response.GetResponseStream();

                stream.CopyTo(ms);
                stream.Dispose();

                return(ms);
            }
            catch (Exception ex)
            {
                if (response != null && response.StatusCode != HttpStatusCode.NotFound)
                {
                    // Don't log 404
                    Logger.Error("An error has occured while trying to retrieve the web resource, Exception = {0}", LogSource.Channel, ex);
                }

                return(null);
            }
        }
コード例 #6
0
 public virtual void WriteToLog()
 {
     if (isEnabled && executeWhen)
     {
         // We use error logging because this is ususally enabled on production servers
         Logger.Debug("CodeTimer: [{0}] [{1}] ms", LogSource.Performance, methodName, Elapsed);
     }
 }
コード例 #7
0
        public IEnumerable <ChannelContact> GetContacts()
        {
            var client = new ExchangeClient(Hostname, CredentialsProvider);

            foreach (var contactItem in client.GetContacts())
            {
                if (contactItem.EmailAddresses == null || contactItem.EmailAddresses.Length == 0)
                {
                    Logger.Warn("Contact {0} had no email address, ignoring", LogSource.Sync, contactItem.DisplayName);

                    continue;
                }

                var contact = new ChannelContact();

                contact.Profile.ChannelProfileKey = contactItem.ItemId.Id;
                contact.Profile.SourceAddress     = new SourceAddress(contactItem.EmailAddresses[0].Value, contactItem.DisplayName);

                contact.Person.Lastname  = contactItem.Surname;
                contact.Person.Firstname = contactItem.GivenName;

                if (contactItem.BirthdaySpecified)
                {
                    contact.Person.DateOfBirth = contactItem.Birthday;
                }

                contact.Profile.ScreenName  = contactItem.Nickname;
                contact.Profile.Title       = contactItem.JobTitle;
                contact.Profile.ScreenName  = contactItem.DisplayName;
                contact.Profile.CompanyName = contactItem.CompanyName;

                if (contactItem.PhysicalAddresses.Length > 0)
                {
                    contact.Profile.Street  = contactItem.PhysicalAddresses[0].Street;
                    contact.Profile.ZipCode = contactItem.PhysicalAddresses[0].PostalCode;
                    contact.Profile.City    = contactItem.PhysicalAddresses[0].City;
                    contact.Profile.Country = contactItem.PhysicalAddresses[0].CountryOrRegion;
                }

                yield return(contact);
            }
        }
コード例 #8
0
        public override void Open()
        {
            Logger.Debug("Opening IMAP connection {0}", LogSource.Channel, UniqueId);

            if (!(channelState == ChannelState.Closed || channelState == ChannelState.Broken))
            {
                Logger.Debug("SUCCESS Connection was allready open {0}", LogSource.Channel, UniqueId);

                return;
            }

            channelState = ChannelState.Connecting;
            client       = new IMAP_Client();

            if ("/Settings/Channels/LoggerEnabled".AsKey(false))
            {
                client.Logger           = new LumiSoft.Net.Log.Logger();
                client.Logger.WriteLog += (sender, e) => Logger.Debug(e.LogEntry.Text.Replace("{", "{{").Replace("}", "}}"), LogSource.Channel);
            }

            try
            {
                client.Connect(Hostname, Port, IsSecured);

                channelState = ChannelState.Connected;
            }
            catch (Exception ex)
            {
                channelState = ChannelState.Closed;

                Logger.Debug("Unable to connect to server. Exception = {0}", LogSource.Channel, ex);

                throw new ChannelException("Unable to connect to server", ex);
            }

            Logger.Debug("SUCCESS Opening connection {0}", LogSource.Channel, UniqueId);
        }
コード例 #9
0
        public Resp Process(Req request)
        {
            try
            {
                WebServiceTracer.TracerId = request.Tracer;
                WebServiceTracer.UserId   = request.UserId;

                request.Validate();

                return(ProcessCore(request));
            }
            catch (UserFriendlyException ex)
            {
                Logger.Warn("Service handler threw an exception. Exception = {0}", LogSource.Sync, ex);

                Resp response = new Resp();

                response.Result            = new Result();
                response.Result.ResultCode = -1;
                response.Result.ResultText = ex.Message;

                return(response);
            }
            catch (Exception ex)
            {
                Logger.Warn("Service handler threw an exception. Exception = {0}", LogSource.Sync, ex);

                Resp response = new Resp();

                response.Result            = new Result();
                response.Result.ResultCode = -1;
                response.Result.ResultText = "A general processing error has occured.";

                return(response);
            }
        }