Exemplo n.º 1
0
 public void Information(string message, params object[] propertyValues)
 {
     if (LoggingCreator.ShouldProcess(LogLevel, Core.Logging.LogLevel.Info))
     {
         TestContext.Out.WriteLine($"[INFO - {Name}]: {message}", propertyValues);
     }
 }
Exemplo n.º 2
0
 public void Debug(string message, params object[] propertyValues)
 {
     if (LoggingCreator.ShouldProcess(LogLevel, Core.Logging.LogLevel.Trace))
     {
         TestContext.Out.WriteLine($"[DEBUG - {Name}]: {message}", propertyValues);
     }
 }
Exemplo n.º 3
0
 public void Warning(string message, params object[] propertyValues)
 {
     if (LoggingCreator.ShouldProcess(LogLevel, Core.Logging.LogLevel.Warn))
     {
         TestContext.Out.WriteLine($"[WARNING - {Name}]: {message}", propertyValues);
     }
 }
Exemplo n.º 4
0
        public void CreateLogger_2OrMoreLoggersGivesWrapperLogger()
        {
            var oldLoggers = LoggingCreator._logBuilders;

            LoggingCreator._logBuilders = new LoggingBuilder[]
            {
                new DummyLoggerBuilder(),
                new ConsoleLoggerBuilder()
            };
            var l = LoggingCreator.CreateLogger(string.Empty);

            try
            {
                Assert.IsInstanceOf <WrapperLogger>(l,
                                                    "We should of been given an WrapperLogger but got {0}", nameof(l));
                ((IDisposable)l).Dispose();

                Array.Resize(ref LoggingCreator._logBuilders, 3);
                LoggingCreator._logBuilders[2] = new DisposableDummyLoggerBuilder();
                l = LoggingCreator.CreateLogger(string.Empty);

                Assert.IsInstanceOf <WrapperLogger>(l,
                                                    "We should of been given an WrapperLogger but got {0}", nameof(l));
            }
            finally
            {
                ((IDisposable)l).Dispose();
                LoggingCreator._logBuilders = oldLoggers;
            }
        }
Exemplo n.º 5
0
 public void Error(string message, params object[] propertyValues)
 {
     if (LoggingCreator.ShouldProcess(LogLevel, Core.Logging.LogLevel.Error))
     {
         TestContext.Error.WriteLine($"[ERROR - {Name}]: {message}", propertyValues);
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Writes data to <see cref="Console"/>
        /// </summary>
        /// <param name="type">What type of log this is (Debug, Info, Error etc...)</param>
        /// <param name="colour">Colour to be used for [TYPE - NAME]</param>
        /// <param name="logLevel">The log level that this is</param>
        /// <param name="message">Message to output</param>
        /// <param name="propertyValues">objects that should be formatted into the outputted message</param>
        private void WriteLine(string type, ConsoleColor colour, LogLevel logLevel, string message,
                               params object?[] propertyValues)
        {
            if (!LoggingCreator.ShouldProcess(LogLevel, logLevel))
            {
                return;
            }

            //If the output is being outputted then we can't
            //set the colours so no need to do all the fancy logic for colouring
            if (Console.IsOutputRedirected)
            {
                lock (WriteLineLock)
                {
                    Console.Out.WriteLine($"[{type} - {Name}]: " + string.Format(message, propertyValues));
                    return;
                }
            }

            lock (WriteLineLock)
            {
                var oldColour = Console.ForegroundColor;
                Console.ForegroundColor = colour;
                Console.Out.Write($"[{type} - {Name}]: ");
                Console.ForegroundColor = oldColour;

                WriteFormattedMessage(message + Environment.NewLine, propertyValues);
            }
        }
Exemplo n.º 7
0
 /// <inheritdoc cref="ILogging.Warning"/>
 public void Warning(string message, params object?[] propertyValues)
 {
     if (LoggingCreator.ShouldProcess(LogLevel, Logging.LogLevel.Warn))
     {
         Trace.TraceWarning(message + $" ({Name})", propertyValues);
     }
 }
Exemplo n.º 8
0
 /// <inheritdoc cref="ILogging.Information"/>
 public void Information(string message, params object?[] propertyValues)
 {
     if (LoggingCreator.ShouldProcess(LogLevel, Logging.LogLevel.Info))
     {
         Trace.TraceInformation(message + $" ({Name})", propertyValues);
     }
 }
Exemplo n.º 9
0
 /// <inheritdoc cref="ILogging.Debug"/>
 public void Debug(string message, params object?[] propertyValues)
 {
     if (LoggingCreator.ShouldProcess(LogLevel, Logging.LogLevel.Trace))
     {
         Trace.WriteLine(string.Format(message, propertyValues), $"DEBUG - {Name}");
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Api constructor
        /// </summary>
        /// <param name="githubClient">Client that owns this Api</param>
        /// <param name="httpClient"><see cref="System.Net.Http.HttpClient"/> to use for requests</param>
        /// <param name="apiEndpoint">Base endpoint to use</param>
        protected GithubApi(GithubUpdateClient githubClient, HttpClient httpClient, string apiEndpoint)
        {
            _githubClient = githubClient ?? throw new ArgumentNullException(nameof(githubClient));
            Logger        = LoggingCreator.CreateLogger(GetType().Name);

            HttpClient             = httpClient;
            HttpClient.BaseAddress = new Uri(apiEndpoint);
            HttpClient.DefaultRequestHeaders.Add("User-Agent", $"TinyUpdate-{ApplicationMetadata.ApplicationName}-{ApplicationMetadata.ApplicationVersion}");
        }
Exemplo n.º 11
0
 /// <inheritdoc cref="ILogging.Warning"/>
 public void Warning(string message, params object?[] propertyValues)
 {
     lock (_writeLock)
     {
         if (LoggingCreator.ShouldProcess(LogLevel, Logging.LogLevel.Warn))
         {
             _fileWriter.Value.WriteLine("[WARN] " + message, propertyValues);
         }
     }
 }
Exemplo n.º 12
0
 /// <inheritdoc cref="ILogging.Error(string, object[])"/>
 public void Error(string message, params object?[] propertyValues)
 {
     lock (_writeLock)
     {
         if (LoggingCreator.ShouldProcess(LogLevel, Logging.LogLevel.Error))
         {
             _fileWriter.Value.WriteLine("[ERROR] " + message, propertyValues);
         }
     }
 }
Exemplo n.º 13
0
 /// <inheritdoc cref="ILogging.Information"/>
 public void Information(string message, params object?[] propertyValues)
 {
     lock (_writeLock)
     {
         if (LoggingCreator.ShouldProcess(LogLevel, Logging.LogLevel.Info))
         {
             _fileWriter.Value.WriteLine("[INFO] " + message, propertyValues);
         }
     }
 }
Exemplo n.º 14
0
 /// <inheritdoc cref="ILogging.Debug"/>
 public void Debug(string message, params object?[] propertyValues)
 {
     lock (_writeLock)
     {
         if (LoggingCreator.ShouldProcess(LogLevel, Logging.LogLevel.Trace))
         {
             _fileWriter.Value.WriteLine("[DEBUG] " + message, propertyValues);
         }
     }
 }
Exemplo n.º 15
0
        public ReleaseEntry(
            string sha256,
            string filename,
            long filesize,
            bool isDelta,
            SemanticVersion version,
            string folderPath,
            SemanticVersion?oldVersion = null,
            object?tag            = null,
            int?stagingPercentage = null)
        {
            //If it's a delta file then we should also be given an oldVersion
            if (isDelta)
            {
                if (oldVersion == null)
                {
                    throw new OldVersionRequiredException();
                }

                OldVersion = oldVersion;
            }

            if (filesize < 0)
            {
                throw new BadFilesizeException();
            }

            //Check hash and file name/path
            if (!SHA256Util.IsValidSHA256(sha256))
            {
                throw new InvalidHashException();
            }

            if (!filename.IsValidForFileName(out var invalidChar))
            {
                throw new InvalidFileNameException(invalidChar);
            }
            if (!folderPath.IsValidForFilePath(out var invalidPathChar))
            {
                throw new InvalidFilePathException(invalidPathChar);
            }

            _logger = LoggingCreator.CreateLogger($"{nameof(ReleaseEntry)} ({filename})");

            SHA256            = sha256;
            Filename          = filename;
            Filesize          = filesize;
            IsDelta           = isDelta;
            Version           = version;
            FileLocation      = Path.Combine(folderPath, Filename);
            StagingPercentage = stagingPercentage;
            Tag = tag;
        }
Exemplo n.º 16
0
        public void CreateLogger_CanAddLogBuilder()
        {
            var oldLoggers = LoggingCreator._logBuilders;

            try
            {
                LoggingCreator.AddLogBuilder(new DummyLoggerBuilder());
            }
            finally
            {
                LoggingCreator._logBuilders = oldLoggers;
            }
        }
Exemplo n.º 17
0
 public void CreateLogger_ShouldProcessReturnCorrectly(
     LogLevel globalLevel,
     LogLevel?level,
     bool expectedTrace,
     bool expectedInfo,
     bool expectedWarn,
     bool expectedError)
 {
     LoggingCreator.GlobalLevel = globalLevel;
     Assert.True(LoggingCreator.ShouldProcess(level, LogLevel.Trace) == expectedTrace);
     Assert.True(LoggingCreator.ShouldProcess(level, LogLevel.Info) == expectedInfo);
     Assert.True(LoggingCreator.ShouldProcess(level, LogLevel.Warn) == expectedWarn);
     Assert.True(LoggingCreator.ShouldProcess(level, LogLevel.Error) == expectedError);
 }
Exemplo n.º 18
0
        public void CreateLogger_0LoggersGivesEmptyLogger()
        {
            var logBuilders = LoggingCreator._logBuilders;

            LoggingCreator._logBuilders = Array.Empty <LoggingBuilder>();

            try
            {
                var l = LoggingCreator.CreateLogger(string.Empty);
                Assert.IsInstanceOf <EmptyLogger>(l,
                                                  "We should of been given an EmptyLogger but got {0}", nameof(l));
            }
            finally
            {
                LoggingCreator._logBuilders = logBuilders;
            }
        }
Exemplo n.º 19
0
        public void CreateLogger_1LoggerGivesActualLogger()
        {
            var oldLoggers = LoggingCreator._logBuilders;

            LoggingCreator._logBuilders = new LoggingBuilder[] { new DummyLoggerBuilder() };

            try
            {
                var l = LoggingCreator.CreateLogger(string.Empty);
                Assert.IsInstanceOf <DummyLogger>(l,
                                                  "We should of been given an DummyLogger but got {0}", nameof(l));
            }
            finally
            {
                LoggingCreator._logBuilders = oldLoggers;
            }
        }
Exemplo n.º 20
0
 public BinaryApplier()
 {
     _logger = LoggingCreator.CreateLogger(GetType().Name);
 }
Exemplo n.º 21
0
 public IUpdateCreatorTest(IUpdateCreator updateCreator)
 {
     _logger        = LoggingCreator.CreateLogger(GetType().Name);
     _updateCreator = updateCreator;
 }
Exemplo n.º 22
0
 protected UpdateClient(IUpdateApplier updateApplier)
 {
     UpdateApplier = updateApplier;
     AppMetadata   = new ApplicationMetadata();
     Logger        = LoggingCreator.CreateLogger(GetType().Name);
 }
Exemplo n.º 23
0
 public void RunBeforeAnyTests()
 {
     LoggingCreator.AddLogBuilder(new TestLoggerBuilder());
 }