Exemplo n.º 1
0
        public bool Execute()
        {
            Uri uri = _uriString.ToUri("The from URI was invalid");

            AbsolutePathName fullPath = PathName.GetAbsolutePathName(_name, Environment.CurrentDirectory);

            _log.DebugFormat("Using output path name: {0}", fullPath);

            string directoryName = Path.GetDirectoryName(fullPath.GetPath());

            if (!System.IO.Directory.Exists(directoryName))
            {
                System.IO.Directory.CreateDirectory(directoryName);
            }

            IInboundTransport fromTransport = Program.Transports.GetInboundTransport(uri);

            ITextBlock text = new TextBlock()
                              .BeginBlock("Save messages from URI: " + uri, "");

            int lastCount;
            int saveCount = 0;

            do
            {
                lastCount = saveCount;

                fromTransport.Receive(receiveContext =>
                {
                    if (saveCount >= _count)
                    {
                        return(null);
                    }

                    string body = Encoding.UTF8.GetString(receiveContext.BodyStream.ReadToEnd());

                    text.BodyFormat("Message-Id: {0}", receiveContext.MessageId ?? "");

                    WriteMessageToFile(fullPath.ToString(), receiveContext, body);

                    saveCount++;

                    if (_remove)
                    {
                        return context => { }
                    }
                    ;

                    return(null);
                }, 5.Seconds());
            } while (_remove && saveCount < _count && saveCount != lastCount);

            _log.Info(text.ToString());

            return(true);
        }
Exemplo n.º 2
0
        public bool Execute()
        {
            Uri uri = _uriString.ToUri("The from URI was invalid");

            AbsolutePathName fullPath = PathName.GetAbsolutePathName(_name, Environment.CurrentDirectory);

            _log.DebugFormat("Using output path name: {0}", fullPath);

            string directoryName = Path.GetDirectoryName(fullPath.GetPath());

            if (!System.IO.Directory.Exists(directoryName))
            {
                System.IO.Directory.CreateDirectory(directoryName);
            }

            IOutboundTransport toTransport = Program.Transports.GetOutboundTransport(uri);

            ITextBlock text = new TextBlock()
                              .BeginBlock("Load messages to URI: " + uri, "");

            string[] files =
                System.IO.Directory.GetFiles(directoryName, fullPath.GetName() + "*.msg", SearchOption.TopDirectoryOnly)
                .OrderBy(x => x).ToArray();

            int loadCount = 0;

            for (int i = 0; i < files.Length && loadCount < _count; i++)
            {
                string file = files[i];

                string fileName = Path.Combine(directoryName, file);

                text.BodyFormat("Message File: {0}", file);

                ISendContext context = LoadMessageFromFile(fileName);

                toTransport.Send(context);

                if (_remove)
                {
                    System.IO.File.Delete(fileName);
                }

                loadCount++;
            }

            _log.Info(text.ToString());

            return(true);
        }
Exemplo n.º 3
0
        public override bool Execute()
        {
            Uri uri = _uri.ToUri("The from URI was invalid");

            AbsolutePathName fullPath = PathName.GetAbsolutePathName(_sourcePath, Environment.CurrentDirectory);

            _log.DebugFormat("Using output path name: {0}", fullPath);

            string directoryName = Path.GetDirectoryName(fullPath.GetPath());

            if (!System.IO.Directory.Exists(directoryName))
            {
                System.IO.Directory.CreateDirectory(directoryName);
            }

            IOutboundTransport toTransport = GetOutboundTransport(_uri);

            _log.InfoFormat("Loading messages from '{0}' to {1}", _sourcePath, _uri);

            string[] files =
                System.IO.Directory.GetFiles(directoryName, fullPath.GetName() + "*.msg", SearchOption.TopDirectoryOnly)
                .OrderBy(x => x).ToArray();

            int loadCount = 0;

            for (int i = 0; i < files.Length && loadCount < _count; i++)
            {
                string file = files[i];

                string fileName = Path.Combine(directoryName, file);

                _log.DebugFormat("Message-Id: '{0}'", file);

                ISendContext context = LoadMessageFromFile(fileName);

                toTransport.Send(context);

                if (_remove)
                {
                    System.IO.File.Delete(fileName);
                }

                loadCount++;
            }

            _log.InfoFormat("Loading messages from '{0}' to {1}", _sourcePath, _uri);

            return(true);
        }