Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebApiService"/> class.
        /// </summary>
        /// <param name="baseAddress">The base address of WebAPI REST interface.</param>
        /// <param name="sendingManager">The sending manager.</param>
        /// <param name="receivingManager">The receiving manager.</param>
        public WebApiService(string baseAddress, ISendingManager sendingManager, IReceivingManager receivingManager)
        {
            if (baseAddress == null)
            {
                throw new ArgumentNullException(nameof(baseAddress));
            }

            if (baseAddress == string.Empty)
            {
                throw new ArgumentException(nameof(baseAddress));
            }

            if (sendingManager == null)
            {
                throw new ArgumentNullException(nameof(sendingManager));
            }

            if (receivingManager == null)
            {
                throw new ArgumentNullException(nameof(receivingManager));
            }

            _baseAddress      = baseAddress;
            _sendingManager   = sendingManager;
            _receivingManager = receivingManager;
        }
        /// <summary>
        /// The save msg to db from many attachs.
        /// </summary>
        /// <param name="msgs">The msgs.</param>
        private static void SaveMsgToDBFromManyAttachs(IList <Header> msgs, IReceivingManager receivingManager)
        {
            string password;
            string group;

            ServiceBusMessage msg = GetDataFromBody(msgs[0].msg, out password, out group);

            var attList = new List <Attach>();

            foreach (Header header in msgs)
            {
                var attachments = header.msg.FindAllAttachments();
                attList.Add(
                    new Attach
                {
                    str = attachments[1].GetBodyAsText(),
                    num = header.msg.Headers.Subject.Split('_')[5]
                });
            }

            msg.Attachment = GetAttachmentFromMany(attList, password);

            if (group == string.Empty)
            {
                receivingManager.AcceptMessage(msg);
            }
            else
            {
                receivingManager.AcceptMessage(msg, group);
            }
        }
        /// <summary>
        /// The receive mess.
        /// </summary>
        public static void ReceiveMess(IReceivingManager receivingManager, ILogger logger)
        {
            string mailServer   = ConfigurationManager.AppSettings["MailServer"];
            int    mailPort     = Convert.ToInt32(ConfigurationManager.AppSettings["MailPort"]);
            string mailLogin    = ConfigurationManager.AppSettings["MailLogin"];
            string mailPassword = Encoding.Unicode.GetString(Convert.FromBase64String(ConfigurationManager.AppSettings["MailPassword"]));

            var client = new Pop3Client();

            try
            {
                client.Connect(mailServer, mailPort, false);
                client.Authenticate(mailLogin, mailPassword);

                List <Header> msgs = GetMsgsForSB(client);
                foreach (Header header in msgs)
                {
                    if (!header.stored)
                    {
                        if (header.msg.Headers.Subject.Contains("OUT_OF"))
                        {
                            Header        tmpHeader = header;
                            List <Header> curMsgs   =
                                msgs.Where(
                                    msg => msg.msg.Headers.Subject.Contains(tmpHeader.msg.Headers.Subject.Split('_')[4]))
                                .ToList();

                            if (curMsgs.Count() == Convert.ToInt32(header.msg.Headers.Subject.Split('_')[8]))
                            {
                                SaveMsgToDBFromManyAttachs(curMsgs, receivingManager);

                                foreach (Header msg in curMsgs)
                                {
                                    msg.stored = true;
                                }
                            }
                        }
                        else
                        {
                            SaveMsgToDB(header.msg, header.msg.Headers.Subject.Split('_')[4], receivingManager);

                            header.stored = true;
                        }
                    }
                }

                DeleteStoredMessages(client, msgs);
            }
            catch (Exception e)
            {
                logger.LogUnhandledException(e);
            }
            finally
            {
                if (client.Connected)
                {
                    client.Disconnect();
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WcfService"/> class.
        /// </summary>
        /// <param name="subscriptionsManager">The subscriptions manager.</param>
        /// <param name="sendingManager">The sending manager.</param>
        /// <param name="receivingManager">The receiving manager.</param>
        /// <param name="logger">The logger.</param>
        public WcfService(ISubscriptionsManager subscriptionsManager, ISendingManager sendingManager, IReceivingManager receivingManager, ILogger logger)
        {
            if (subscriptionsManager == null)
            {
                throw new ArgumentNullException(nameof(subscriptionsManager));
            }

            if (sendingManager == null)
            {
                throw new ArgumentNullException(nameof(sendingManager));
            }

            if (receivingManager == null)
            {
                throw new ArgumentNullException(nameof(receivingManager));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            _subscriptionsManager = subscriptionsManager;
            _sendingManager       = sendingManager;
            _receivingManager     = receivingManager;
            _logger = logger;
        }
        public SBService(ISubscriptionsManager subscriptionsManager, ISendingManager sendingManager, IReceivingManager receivingManager, IStatisticsService statisticsService, IObjectRepository objectRepository)
        {
            if (subscriptionsManager == null)
            {
                throw new ArgumentNullException(nameof(subscriptionsManager));
            }

            if (sendingManager == null)
            {
                throw new ArgumentNullException(nameof(sendingManager));
            }

            if (receivingManager == null)
            {
                throw new ArgumentNullException(nameof(receivingManager));
            }

            if (statisticsService == null)
            {
                throw new ArgumentNullException(nameof(statisticsService));
            }

            if (statisticsService == null)
            {
                throw new ArgumentNullException(nameof(objectRepository));
            }

            _subscriptionsManager = subscriptionsManager;
            _sendingManager       = sendingManager;
            _receivingManager     = receivingManager;
            _statisticsService    = statisticsService;
            _objectRepository     = objectRepository;
        }
Ejemplo n.º 6
0
        public RestServiceController(ISendingManager sendingManager, IReceivingManager receivingManager)
        {
            if (sendingManager == null)
            {
                throw new ArgumentNullException(nameof(sendingManager));
            }

            if (receivingManager == null)
            {
                throw new ArgumentNullException(nameof(receivingManager));
            }

            _sendingManager   = sendingManager;
            _receivingManager = receivingManager;
        }
        public RestDependencyScope(ISendingManager sendingManager, IReceivingManager receivingManager)
        {
            if (sendingManager == null)
            {
                throw new ArgumentNullException(nameof(sendingManager));
            }

            if (receivingManager == null)
            {
                throw new ArgumentNullException(nameof(receivingManager));
            }

            _sendingManager   = sendingManager;
            _receivingManager = receivingManager;
        }
        public MailScanningService(MailScanningServiceSettings settings, IReceivingManager receivingManager, ILogger logger)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (receivingManager == null)
            {
                throw new ArgumentNullException(nameof(receivingManager));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            _settings         = settings;
            _receivingManager = receivingManager;
            _logger           = logger;
        }
        /// <summary>
        /// The save msg to db.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="fileName">The file name.</param>
        private static void SaveMsgToDB(Message message, string fileName, IReceivingManager receivingManager)
        {
            string password;
            string group;

            ServiceBusMessage msg = GetDataFromBody(message, out password, out group);

            if (fileName != "empty")
            {
                var attachments = message.FindAllAttachments();
                msg.Attachment = GetAttachment(attachments[0].GetBodyAsText(), password);
            }

            if (group == string.Empty)
            {
                receivingManager.AcceptMessage(msg);
            }
            else
            {
                receivingManager.AcceptMessage(msg, group);
            }
        }
 public AsyncReciever(IReceivingManager recievingManager, IEnumerable <MessageForESB> messages) : this(recievingManager)
 {
     Jobs = messages
            .Select(x => new AsyncRecieverJob(x, 1))
            .ToArray();
 }
 public AsyncReciever(IReceivingManager recievingManager, IEnumerable <AsyncRecieverJob> jobs) : this(recievingManager)
 {
     Jobs = jobs;
 }
 private AsyncReciever(IReceivingManager recievingManager)
 {
     RecievingManager = recievingManager;
 }