Пример #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);
            }

            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);
        }
Пример #2
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);
        }