コード例 #1
0
        private void LogBeforeReadingFromProvider(DateTime requestTime, int userId)
        {
            string msg = "[1]--Start reading image from source.".PadRight(84) +
                         " Request by UserId: " + userId.GetFormattedUserId() + " , at " +
                         DateTimeFormatter.ConvertTimeToCompactString(requestTime, true);

            _logger?.LogCacheStat(msg, userId);
        }
コード例 #2
0
        private void LogReadOldImageFromCache(int userId)
        {
            string statusMessage = "From cache  . OLD IMAGE until cache is updated"
                                   + " ,  LastUpdate: " + DateTimeFormatter.ConvertTimeToCompactString(GetLastCacheAccess(userId), true) //(_lastCacheAccess, true) //
                                   + "    Request by UserId: " + userId.GetFormattedUserId();

            _logger?.LogCacheStat(statusMessage, userId);
        }
コード例 #3
0
        private static (string strPrevTime, string strRequestTime) GetLogDateTimeValuesAsStrings(
            DateTime lastUpdate,
            DateTime requestTime)
        {
            string strPrevTime    = DateTimeFormatter.ConvertTimeToCompactString(lastUpdate, true);
            string strRequestTime = DateTimeFormatter.ConvertTimeToCompactString(requestTime, true);

            return(strPrevTime, strRequestTime);
        }
コード例 #4
0
        private void LogAfterReadingFromProvider(int userId)
        {
            string msg = "[2]--Finish reading image from source. " +
                         "                                              " +
                         "Request by UserId: " + userId.GetFormattedUserId() + " , at " +
                         DateTimeFormatter.ConvertTimeToCompactString(GetLastCacheAccess(userId), true);

            _logger?.LogCacheStat(msg, userId);
        }
コード例 #5
0
        private string CreateMessageWhenCanReturnImage()
        {
            string statusMessage = ("From cache (2)." + // Granted access to cache
                                    "Current = userId: " + _cacheUpdateService.UserId.GetFormattedUserId()).PadRight(50)
                                   + "LastUpdate: " +
                                   DateTimeFormatter.ConvertTimeToCompactString(_cacheUpdateService.LastUpdate, true);

            return(statusMessage.PadRight(85));
        }
コード例 #6
0
        private void LogCanReturnCachedImage(int userId, DateTime timeRequested, bool canReturnImage)
        {
            string statusMessage = canReturnImage
                ? CreateMessageWhenCanReturnImage()
                : CreateMessageWhenCanNotReturnImage(userId, timeRequested);

            statusMessage += "Request by userId: " + userId.GetFormattedUserId() + " , at " +
                             DateTimeFormatter.ConvertTimeToCompactString(timeRequested, true);
            _logger?.LogCacheStat(statusMessage, userId);
        }
コード例 #7
0
        private string PrepareUpdateCacheLogMessage(int newUserId, DateTime lastCacheUpdate)
        {
            var    statMessage = "UPDATE cache . ";
            string action      = _cacheUpdateService.UserId == newUserId ? "Updated " : "Replaced";

            statMessage += $"{action}= userId: " + _cacheUpdateService.UserId.GetFormattedUserId();
            statMessage  = statMessage.PadRight(50);
            statMessage += "LastUpdate: "
                           + DateTimeFormatter.ConvertTimeToCompactString(lastCacheUpdate, true) + " ";
            return(statMessage);
        }
コード例 #8
0
        private void LogNewImageReadFromCache(int userId, DateTime requestTime)
        {
            string msg = "From cache (3) = Read image.".PadRight(50)
                         + "LastUpdate: " +
                         DateTimeFormatter.ConvertTimeToCompactString(_imageFromCacheService.CacheLastUpdate, true)
                         + ".   Request by UserId: " + userId.GetFormattedUserId()
                         + "    lastCacheAccess "
                         + DateTimeFormatter.ConvertTimeToCompactString(GetLastCacheAccess(userId), true)
                         + " => "
                         + DateTimeFormatter.ConvertTimeToCompactString(requestTime, true);

            _logger?.LogCacheStat(msg, userId);
        }
コード例 #9
0
        private void LogRequestAccessToCache(int userId, DateTime timeRequested, DateTime lastCacheUpdate,
                                             int waitTimeMilliSec, string reason)
        {
            var    requestDelay = (int)timeRequested.Subtract(lastCacheUpdate).TotalMilliseconds;
            string msg          = "From cache (1) = Request access and WAIT".PadRight(50) +
                                  "LastUpdate: " +
                                  DateTimeFormatter.ConvertTimeToCompactString(lastCacheUpdate, true) +
                                  $"    Request by userId: {userId.GetFormattedUserId()} " +
                                  "  at " +
                                  DateTimeFormatter.ConvertTimeToCompactString(timeRequested, true) +
                                  $"  Delta T = {requestDelay} ms." +
                                  $"  Time to wait = {waitTimeMilliSec} ms  {reason}";

            _logger?.LogCacheStat(msg, userId);
        }
コード例 #10
0
        public static void WriteImageToFile(Image image, DateTime dateTime,
                                            string imageDirectory, IMiniLogger logger,
                                            int userId, string userIp,
                                            bool roundSecondsToZero = true)
        {
            if (image == null)
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(imageDirectory))
            {
                return;
            }

            dateTime = RoundSecondsToZero(dateTime, roundSecondsToZero);

            string dateTimeCompact = DateTimeFormatter.ConvertTimeToCompactString(dateTime: dateTime, withMilliSeconds: false);

            WriteImageToFile(image, imageDirectory, dateTimeCompact, logger, userId, userIp);
        }
コード例 #11
0
        private static void WriteToLogFile(string fileName, string text)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            string logFileName = GetTodaysLogFileName(fileName);

            try
            {
                lock (LockFileWrite)
                {
                    DateTime dateTimeNow = _dateTimeProvider.DateTimeNow;
                    string   strDateTime = DateTimeFormatter.ConvertTimeToCompactString(dateTime: dateTimeNow, withMilliSeconds: true);
                    text = strDateTime + "," + text;
                    File.AppendAllText(logFileName, text + Environment.NewLine);
                }
            }
            catch (DirectoryNotFoundException)
            {
                string directoryName = Path.GetDirectoryName(logFileName);
                if (!string.IsNullOrWhiteSpace(directoryName))
                {
                    Directory.CreateDirectory(directoryName);
                    File.AppendAllText(logFileName, text + Environment.NewLine);
                }
            }

            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
コード例 #12
0
 private void LogCacheHasBeenUpdated(string statMessage)
 {
     statMessage += " With = userId: " + _cacheUpdateService.UserId.GetFormattedUserId() + " , LastUpdate: "
                    + DateTimeFormatter.ConvertTimeToCompactString(_cacheUpdateService.LastUpdate, true) + " ";
     _logger?.LogCacheStat(statMessage, _cacheUpdateService.UserId);
 }