internal Result <DateTime> GetShutdownTime(OperationContext context, bool logTimeStampToFile)
        {
            const string ErrorPrefix = "Could not determine shutdown time";
            var          result      = context.PerformOperation(
                Tracer,
                () =>
            {
                if (_fileSystem.FileExists(_logFilePath))
                {
                    var lastTime = System.Text.Encoding.Default.GetString(_fileSystem.ReadAllBytes(_logFilePath));
                    return(string.IsNullOrEmpty(lastTime)
                            ? new Result <DateTime>($"{ErrorPrefix}: CaSaaS running log file was empty")
                            : new Result <DateTime>(Convert.ToDateTime(lastTime)));
                }

                return(new Result <DateTime>($"{ErrorPrefix}: CaSaaS running log file was missing"));
            },
                traceErrorsOnly: true);

            if (logTimeStampToFile)
            {
                LogCurrentTimeStampToFile(context);
            }

            return(result);
        }
        /// <summary>
        ///     Reads the value from the marker file. Returns 0 is the marker does not exist.
        /// </summary>
        public int ReadValueFile()
        {
            int valueRead = 0;

            if (_fileSystem.FileExists(_valueFilePath))
            {
                valueRead = BitConverter.ToInt32(_fileSystem.ReadAllBytes(_valueFilePath), 0);
            }

            return(valueRead);
        }
示例#3
0
        private static Guid Read(IAbsFileSystem fileSystem, AbsolutePath filePath)
        {
            var bytes    = fileSystem.ReadAllBytes(filePath);
            var idString = Encoding.UTF8.GetString(bytes);

            if (!Guid.TryParseExact(idString, SerializationFormat, out var result))
            {
                fileSystem.DeleteFile(filePath);
                throw new CacheException("Cache id file was present but not in the correct format", filePath.Path);
            }

            return(result);
        }
示例#4
0
 public string GetStatus()
 {
     if (_fileSystem.FileExists(_logFilePath))
     {
         var lastTime = System.Text.Encoding.Default.GetString(_fileSystem.ReadAllBytes(_logFilePath));
         return(string.IsNullOrEmpty(lastTime)
             ? "CaSaaS running log file was empty, could not determine offline time"
             : $"offlineTime: {_clock.UtcNow - Convert.ToDateTime(lastTime)}");
     }
     else
     {
         return("creating CaSaaS running log file, could not determine offline time");
     }
 }
        internal Result <TimeSpan> GetOfflineDuration(OperationContext context)
        {
            const string ErrorPrefix = "Could not determine offline time";

            return(context.PerformOperation(
                       Tracer,
                       () =>
            {
                if (_fileSystem.FileExists(_logFilePath))
                {
                    var lastTime = System.Text.Encoding.Default.GetString(_fileSystem.ReadAllBytes(_logFilePath));
                    return string.IsNullOrEmpty(lastTime)
                            ? new Result <TimeSpan>($"{ErrorPrefix}: CaSaaS running log file was empty")
                            : new Result <TimeSpan>(_clock.UtcNow - Convert.ToDateTime(lastTime));
                }

                return new Result <TimeSpan>($"{ErrorPrefix}: CaSaaS running log file was missing");
            },
                       traceErrorsOnly: true));
        }