GetMessage() public method

public GetMessage ( string file ) : byte[]
file string
return byte[]
Ejemplo n.º 1
0
        public static byte[] GetMessage(
            this MessageRepository messageRepository,
            MessageEntry entry)
        {
            if (messageRepository == null)
            {
                throw new ArgumentNullException(nameof(messageRepository));
            }
            if (entry == null)
            {
                throw new ArgumentNullException(nameof(entry));
            }

            return(messageRepository.GetMessage(entry.File));
        }
Ejemplo n.º 2
0
        public IObservable <MimeMessage> Get(MessageEntry messageEntry)
        {
            _logger.Verbose("Loading Message Entry {@MessageEntry}", messageEntry);

            return(Observable.Create <MimeMessage>(
                       o =>
            {
                // in case of multiple subscriptions...
                var observer = Observer.Synchronize(o, true);
                var disposable = new CancellationDisposable();

                MimeMessage message = null;

                try
                {
                    message = MimeMessageCache.GetOrSet(
                        messageEntry.File,
                        () =>
                    {
                        _logger.Verbose(
                            "Getting Message Data from Cached Message Repository",
                            messageEntry);
                        var messageData = _messageRepository.GetMessage(messageEntry);
                        MimeMessage mimeMessage;

                        // wrap in a memorystream...
                        using (var ms = new MemoryStream(messageData))
                        {
                            _logger.Verbose(
                                "MimeMessage Load for {@MessageEntry}",
                                messageEntry);

                            mimeMessage = MimeMessage.Load(
                                ParserOptions.Default,
                                ms,
                                disposable.Token);
                        }

                        return mimeMessage;
                    },
                        m =>
                    {
                        var policy = new CacheItemPolicy
                        {
                            SlidingExpiration = TimeSpan.FromSeconds(10)
                        };

                        MimeMessageCache.Add(messageEntry.File, m, policy);
                    });
                }
                catch (OperationCanceledException)
                {
                    // no need to respond...
                }
                catch (Exception ex)
                {
                    _logger.Error(ex, "Exception Loading {@MessageEntry}", messageEntry);
                    observer.OnError(ex);
                }

                if (message != null)
                {
                    observer.OnNext(message);
                    observer.OnCompleted();
                }

                return disposable;
            }).SubscribeOn(TaskPoolScheduler.Default));
        }