Exemplo n.º 1
0
        public void Execute(TransmitFileContext context, CancellationToken token)
        {
            var marketFiles = marketDataAccess.ListEncryptedOutboundMarketFiles()
                              .Where(x => !x.FileType.Equals("CBF", StringComparison.Ordinal))
                              .ToArray();

            if (!marketFiles.Any())
            {
                return;
            }

            logger.DebugFormat("Transmitting {0} encrypted outbound market file(s).", marketFiles.Length);

            var ports = clientDataAccess.ListCspDunsPort();

            foreach (var marketFile in marketFiles)
            {
                if (token.IsCancellationRequested)
                {
                    token.ThrowIfCancellationRequested();
                }

                var port = IdentifyCspDunsPort(marketFile, ports);
                if (port == null)
                {
                    var message = string.Format("No CspDunsPort found for LDCID: {0} and CSPDUNSID: {1}.",
                                                marketFile.LdcId, marketFile.CspDunsId);

                    logger.Error(message);

                    marketFile.Status       = MarketFileStatusOptions.Error;
                    marketFile.ProcessError = message;
                    marketFile.ProcessDate  = DateTime.Now;
                    marketDataAccess.UpdateMarketFile(marketFile);
                    continue;
                }

                if (!port.TransportEnabledFlag)
                {
                    logger.InfoFormat("CspDunsPort {0} is not enabled for transport.", marketFile.CspDunsId);

                    marketFile.Status       = MarketFileStatusOptions.Error;
                    marketFile.ProcessError = "Transport not enabled.";
                    marketFile.ProcessDate  = DateTime.Now;
                    marketDataAccess.UpdateMarketFile(marketFile);
                    continue;
                }

                logger.TraceFormat("Transmitting file \"{0}\" for CSPDUNS {1}.", marketFile.FileName, port.CspDunsId);
                TransmitMarketFile(context, marketFile, port);
            }
        }
Exemplo n.º 2
0
        public void Initialize()
        {
            clientId            = 1;
            logger              = MockRepository.GenerateMock <ILogger>();
            adminDataAccess     = MockRepository.GenerateMock <IAdminDataAccess>();
            clientDataAccess    = MockRepository.GenerateMock <IClientDataAccess>();
            marketDataAccess    = MockRepository.GenerateMock <IMarketFile>();
            transmitFileContext = new TransmitFileContext
            {
                DirectoryArchive   = "archive",
                DirectoryDecrypted = "decrypted",
                DirectoryEncrypted = "encrypted",
                DirectoryException = "exception"
            };

            task = new TransmitFileTask(adminDataAccess, clientDataAccess, marketDataAccess, logger, clientId);
        }
Exemplo n.º 3
0
        public void TransmitMarketFile(TransmitFileContext context, MarketFileModel marketFile, CspDunsPortModel port)
        {
            var fileName          = string.Concat(marketFile.FileName, ".pgp");
            var encryptedFilePath = Path.Combine(context.DirectoryArchive, "Encrypted", fileName);
            var sourceFilePath    = Path.Combine(port.DirectoryOut, fileName);
            var targetFilePath    = Path.Combine(port.DirectoryOut, "Complete", fileName);

            var encryptedFile = new FileInfo(encryptedFilePath);

            if (encryptedFile.Exists)
            {
                encryptedFile.CopyTo(sourceFilePath, true);
            }

            var sourceFile = new FileInfo(sourceFilePath);

            try
            {
                var result = TransmitFile(sourceFile, port);

                marketFile.Status = (result.Transmitted)
                    ? MarketFileStatusOptions.Transmitted
                    : MarketFileStatusOptions.Error;
                marketFile.ProcessError = result.Message;
                marketFile.ProcessDate  = DateTime.Now;
                marketDataAccess.UpdateMarketFile(marketFile);

                if (result.Transmitted)
                {
                    MoveFile(sourceFile, targetFilePath);
                }
            }
            catch (Exception ex)
            {
                logger.ErrorFormat(ex, "Unknown error occurred while transmitting file \"{0}\".",
                                   marketFile.FileName);

                marketFile.Status       = MarketFileStatusOptions.Error;
                marketFile.ProcessError = ex.Message;
                marketFile.ProcessDate  = DateTime.Now;
                marketDataAccess.UpdateMarketFile(marketFile);
            }
        }
Exemplo n.º 4
0
        public void Execute(CancellationToken token)
        {
            var configuration = adminDataAccess.LoadExportConfiguration(clientId);
            var context       = new TransmitFileContext
            {
                DirectoryArchive   = Path.Combine(configuration.DirectoryArchive, DateTime.Now.ToString("yyyyMM")),
                DirectoryDecrypted = configuration.DirectoryDecrypted,
                DirectoryEncrypted = configuration.DirectoryEncrypted,
                DirectoryException = configuration.DirectoryException,
            };

            logger.TraceFormat(
                "Executing Transmit Task with configuration: Client Id: {0} \nDecrypted: \"{1}\" \nEncrypted: \"{2}\" \nArchive: \"{3}\" \nException: \"{4}\" \n",
                clientId, context.DirectoryDecrypted, context.DirectoryEncrypted, context.DirectoryArchive,
                context.DirectoryException);

            using (logger.NestLog("Transmit"))
            {
                Execute(context, token);
            }
        }