コード例 #1
0
        public static MessagePathResult GetMessagePath(int vendorID, MessageTypes type)
        {
            using (var db = new Database(Environments.Current.Connection, "System.Data.SqlClient"))
            {
                PFACommunicatorHelper helper = new PFACommunicatorHelper(new PfaCommunicatorRepository(db), vendorID);

                var path = helper.GetLocalMessagePath(type);

                var errorPath     = Path.Combine(path, "Error");
                var processedPath = Path.Combine(path, "Processed");

                if (!Directory.Exists(errorPath))
                {
                    Directory.CreateDirectory(errorPath);
                }

                if (!Directory.Exists(processedPath))
                {
                    Directory.CreateDirectory(processedPath);
                }

                return(new MessagePathResult()
                {
                    MessagePath = path, ErrorPath = errorPath, ProcessedPath = processedPath
                });
            }
        }
コード例 #2
0
        protected override void Process()
        {
            using (var db = new Database(Connection, "System.Data.SqlClient"))
            {
                PfaCommunicatorRepository repo = new PfaCommunicatorRepository(db);

                var vendorsForCommunication = repo.GetVendorsWithPfaCommunication();

                foreach (var vendor in vendorsForCommunication)
                {
                    string remoteFileLocation = string.Empty;
                    NetworkExportUtility util = new NetworkExportUtility(log);
                    try
                    {
                        log.Info("Checking messages for vendor " + vendor.Name);
                        PFACommunicatorHelper helper = new PFACommunicatorHelper(repo, vendor.VendorID);
                        var messageTypes             = helper.GetMessageTypesForVendor();


                        try
                        {
                            remoteFileLocation = util.ConnectorNetworkPath(messageTypes.RemoteDirectory, "O:", messageTypes.UsernameForRemoteDirectory, messageTypes.PasswordForRemoteDirectory);
                        }
                        catch (Exception e)
                        {
                            throw new InvalidOperationException("Could not connect to remote location");
                        }

                        EnsureLocalDirectoryExists(messageTypes.LocalDirectory);
                        EnsureLocalDirectoryExists(messageTypes.ArchiveDirectory);

                        foreach (var message in messageTypes.Messages)
                        {
                            var localDirectory        = Path.Combine(messageTypes.LocalDirectory, message.LocalSubPath);
                            var localArchiveDirectory = Path.Combine(messageTypes.ArchiveDirectory, message.LocalSubPath);

                            EnsureLocalDirectoryExists(localDirectory);
                            EnsureLocalDirectoryExists(localArchiveDirectory);

                            if (message.Incoming)
                            {
                                SyncLocalMessages(message, remoteFileLocation + "\\", messageTypes.LocalDirectory, localArchiveDirectory);
                            }
                            else
                            {
                                SyncRemoteMessages(message, remoteFileLocation + "\\", messageTypes.LocalDirectory, localArchiveDirectory);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        log.AuditError("Something went wrong with Pfa communication for vendor " + vendor.VendorID, e);
                        throw;
                    }
                    finally
                    {
                        util.DisconnectNetworkPath(remoteFileLocation);
                    }
                }
            }
        }