Exemplo n.º 1
0
        public async Task <ResponseStatus> AudioUpdatesAvailable(NotificationRequest request, ServerCallContext context)
        {
            logger.LogInformation($"New examination audio update available! Action: {request.Action}. Name: {Path.GetFileNameWithoutExtension(request.FileName)}. Start updating.");
            try
            {
                switch (request.Action)
                {
                case NotificationAction.Add:
                {
                    var centralGazooFtpConfiguration = new FtpConfigurationModel
                    {
                        Host     = request.FtpIp,
                        Port     = request.FtpPort,
                        Login    = request.FtpLogin,
                        Password = request.FtpPassword
                    };

                    await remoteFileService.DownloadFileAsync(centralGazooFtpConfiguration, request.FileName);

                    break;
                }

                case NotificationAction.Delete:
                    localFileService.DeleteFile(CreateFilePath(request.FileName));
                    break;

                case NotificationAction.Update:
                    localFileService.RenameFile(CreateFilePath(request.OldFileName), CreateFilePath(request.FileName));
                    break;

                default:
                    break;
                }
                logger.LogInformation($"Updating examination audio: {Path.GetFileNameWithoutExtension(request.FileName)} finished successfully!");
                return(new ResponseStatus()
                {
                    NotificationStatus = NotificationStatus.Successful
                });
            }
            catch (RpcException ex)
            {
                logger.LogError(ex, $"Error was occured while updating examination audio file: {Path.GetFileNameWithoutExtension(request.FileName)}.");
                return(new ResponseStatus()
                {
                    NotificationStatus = NotificationStatus.Failure
                });
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"Error was occured while updating examination audio file: {Path.GetFileNameWithoutExtension(request.FileName)}.");
                return(new ResponseStatus()
                {
                    NotificationStatus = NotificationStatus.Failure
                });
            }
        }
        public void CleanupLogFiles(SiteCleanupConfiguration siteInfo)
        {
            _log.Debug($"Starting clean of {siteInfo.SiteName}");
            if (siteInfo.LogHistoryDaysToKeep < 2)
            {
                _log.Error("Unable to process, must keep at least 2 days of logs");
                return;
            }

            var directoryExists = _localFileService.DirectoryExists(siteInfo.DnnRootDirectoryPath);

            if (!directoryExists)
            {
                _log.Error("Provided directory not fount, no further processing for this site");
                return;
            }

            //Verify that it is a DNN install
            var dnnLogPath   = _localFileService.BuildDnnLogFolderPath(siteInfo.DnnRootDirectoryPath);
            var dnnLogExists = _localFileService.DirectoryExists(dnnLogPath);

            if (!dnnLogExists)
            {
                _log.Error($"Unable to find DNN log folder.  Looked in '{dnnLogPath}'");
                return;
            }

            //Get the list of log files
            _log.Debug($"Searching for files in {dnnLogPath}");
            var logFiles = _localFileService.FindFiles(dnnLogPath, "*.log.resources");

            if (logFiles.Count > siteInfo.LogHistoryDaysToKeep)
            {
                //Get the to delete files
                var toDelete = logFiles.OrderByDescending(lf => lf.CreationTimeUtc).Skip(siteInfo.LogHistoryDaysToKeep);
                foreach (var fileToDelete in toDelete)
                {
                    _log.Debug($"Deleting {fileToDelete.FullName}");
                    _localFileService.DeleteFile(fileToDelete.FullName);
                }
            }
            else
            {
                _log.Debug(
                    $"Found {logFiles.Count} files and log rules allow for up to {siteInfo.LogHistoryDaysToKeep} no action taken");
            }
        }