Example #1
0
        /// <summary>
        /// Method for File monitoring
        /// </summary>
        public void Monitor()
        {
            LoggerHelper.Debug("Timer is firing");

            //Using X service UNC
            if (Environment.GetEnvironmentVariable(EnvVar.ASPNET_CORE_ENVRIONMENT) == "Development")
            {
                LoggerHelper.Info("Using local service UNC");
                // Attempt to create all directories needed
                UncFolderHelper.CreateUncFolders();

                try
                {
                    FileLoop();
                }
                catch (Exception ex)
                {
                    LoggerHelper.GeneralExceptionLogFile("FileManager_FileLoop", ex);
                }
            }
            else
            {
                LoggerHelper.Info("Using network service UNC");
                try
                {
                    NetworkCredential credential = new NetworkCredential(_volumeServiceUsername, _volumeServicePassword, _volumeServiceDomain);
                    using (WindowsNetworkFileShare networkPath = new WindowsNetworkFileShare(_volumeServiceShare, credential))
                    {
                        try
                        {
                            FileLoop();
                        }
                        catch (Exception ex)
                        {
                            LoggerHelper.GeneralExceptionLogFile("FileManager_FileLoop", ex);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LoggerHelper.GeneralExceptionLogFile("FileManager_FileLoop_NetworkCredentials", ex);
                }
            }

            LoggerHelper.Debug("Timer has finished");
        }
Example #2
0
        /// <summary>
        /// Download APM Files from SFG to Incoming Folder
        /// </summary>
        private void DownloadApmFile()
        {
            if (_sfgDownloadOn)
            {
                var connectionInfo = new ConnectionInfo(_sfgHost, _sfgPort,
                                                        _sfgUsername, new PasswordAuthenticationMethod(_sfgUsername, _sfgPassword));

                using (var client = new SftpClient(connectionInfo))
                {
                    client.Connect();
                    var files = client.ListDirectory(_sfgPath);

                    foreach (var file in files)
                    {
                        if (file.IsDirectory)
                        {
                            continue;
                        }

                        try
                        {
                            LoggerHelper.Debug($"Downloading {file.Name} from SFG.");
                            var newFilename = $"{Guid.NewGuid().ToString("N")}.downloading";
                            var fs          = File.Create($"{_volumeServiceShare}{_incomingFolder}\\{newFilename}");
                            client.DownloadFile(file.FullName, fs);
                            fs.Close();

                            LoggerHelper.Debug($"Download complete for {file.Name} from SFG, changed the name to {newFilename}");

                            // Get list of downloaded files
                            // and rename them to .apm
                            RenameDownloadedFiles();
                        }
                        catch (Exception ex)
                        {
                            LoggerHelper.GeneralExceptionLogFile("FileManager_DownloadApmInSfgLoop", ex);
                        }
                    }
                }
            }
        }