示例#1
0
        public void Write(Verbosity verbosity, LogLevel level, string format, params object[] args)
        {
            if (!string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable("TF_BUILD")))
            {
                switch (level)
                {
                case LogLevel.Fatal:
                case LogLevel.Error:
                    _cakeLogImplementation.Write(Verbosity.Quiet, LogLevel.Information,
                                                 "##teamcity[buildProblem description='{0}']", string.Format(format, args));
                    break;

                case LogLevel.Warning:
                    _cakeLogImplementation.Write(Verbosity.Quiet, LogLevel.Information,
                                                 "##teamcity[message text='{0}' status='WARNING']", string.Format(format, args));
                    break;

                case LogLevel.Information:
                case LogLevel.Verbose:
                case LogLevel.Debug:
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(level), level, null);
                }
            }
            _cakeLogImplementation.Write(verbosity, level, format, args);
        }
示例#2
0
        public void Write(Verbosity verbosity, LogLevel level, string format, params object[] args)
        {
            if (!string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable("TF_BUILD")))
            {
                switch (level)
                {
                case LogLevel.Fatal:
                case LogLevel.Error:
                    _cakeLogImplementation.Write(Verbosity.Quiet, LogLevel.Information,
                                                 "##vso[task.logissue type=error;]{0}", string.Format(format, args));
                    break;

                case LogLevel.Warning:
                    _cakeLogImplementation.Write(Verbosity.Quiet, LogLevel.Information,
                                                 "##vso[task.logissue type=warning;]{0}", string.Format(format, args));
                    break;

                case LogLevel.Information:
                case LogLevel.Verbose:
                case LogLevel.Debug:
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(level), level, null);
                }
            }
            _cakeLogImplementation.Write(verbosity, level, format, args);
        }
        public void Write(Verbosity verbosity, LogLevel level, string format, params object[] args)
        {
            switch (level)
            {
            case LogLevel.Fatal:
                _cakeLogImplementation.Write(Verbosity.Quiet, LogLevel.Information,
                                             _failOnFatal
                            ? "##myget[buildProblem description='{0}']"
                            : "##myget[message text='{0}' status='FAILURE']",
                                             string.Format(format, args));
                break;

            case LogLevel.Error:
                _cakeLogImplementation.Write(Verbosity.Quiet, LogLevel.Information,
                                             "##myget[message text='{0}' status='ERROR']", string.Format(format, args));
                break;

            case LogLevel.Warning:
                _cakeLogImplementation.Write(Verbosity.Quiet, LogLevel.Information,
                                             "##myget[message text='{0}' status='WARNING']", string.Format(format, args));
                break;

            case LogLevel.Information:
                _cakeLogImplementation.Write(verbosity, level, format, args);
                break;

            case LogLevel.Verbose:
            case LogLevel.Debug:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(level), level, null);
            }
        }
        /// <summary>
        /// Uploads test results XML file to AppVeyor. Results type can be one of the following: mstest, xunit, nunit, nunit3, junit.
        /// </summary>
        /// <param name="path">The file path of the test results XML to upload.</param>
        /// <param name="resultsType">The results type. Can be mstest, xunit, nunit, nunit3 or junit.</param>
        public void UploadTestResults(FilePath path, AppVeyorTestResultsType resultsType)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (!IsRunningOnAppVeyor)
            {
                throw new CakeException("The current build is not running on AppVeyor.");
            }

            var baseUri = _environment.GetEnvironmentVariable("APPVEYOR_URL").TrimEnd('/');

            if (string.IsNullOrWhiteSpace(baseUri))
            {
                throw new CakeException("Failed to get AppVeyor API url.");
            }

            var url = new Uri(string.Format(CultureInfo.InvariantCulture, "{0}/api/testresults/{1}/{2}", baseUri, resultsType, Environment.JobId).ToLowerInvariant());

            _cakeLog.Write(Verbosity.Diagnostic, LogLevel.Verbose, "Uploading [{0}] to [{1}]", path.FullPath, url);
            Task.Run(async() =>
            {
                using (var client = new HttpClient())
                {
                    var response = await client.UploadFileAsync(url, path.FullPath, "text/xml");
                    var content  = await response.Content.ReadAsStringAsync();
                    _cakeLog.Write(Verbosity.Diagnostic, LogLevel.Verbose, "Server response [{0}:{1}]:\n\r{2}", response.StatusCode, response.ReasonPhrase, content);
                }
            }).Wait();
        }
示例#5
0
        private string FindApplicationPath(string applicationName, string userPath, string exeToFind)
        {
            if (!string.IsNullOrEmpty(userPath))
            {
                if (!File.Exists(userPath))
                {
                    _cakeLog.Write(Verbosity.Normal, LogLevel.Fatal,
                                   $"{applicationName} provided by user can't be fount at {userPath}");
                    return(null);
                }

                _cakeLog.Write(Verbosity.Normal, LogLevel.Information,
                               $@"{applicationName} path provided by user: using {applicationName} version '{
                            GetVersion(userPath)
                        }' from {userPath}");
                return(userPath);
            }

            var applicationPath = FindExe(exeToFind);

            _cakeLog.Write(Verbosity.Normal, LogLevel.Information,
                           $@"{applicationName} auto-detection: using {applicationName} version '{
                        GetVersion(applicationPath)
                    }' from {applicationPath}");

            return(applicationPath);
        }
示例#6
0
        private static async Task <string> ExecuteUnicornAsync(string syncUrl, string signature, string challenge, ICakeLog log)
        {
            log.Write(Verbosity.Normal, LogLevel.Information, "Executing Unicorn...");
            var responseTextBuilder = new StringBuilder();

            using (var client = new HttpClient())
            {
                log.Write(Verbosity.Diagnostic, LogLevel.Debug, $"Executing Unicorn sync with signature {signature} and challenge {challenge}.");
                client.DefaultRequestHeaders.Add("X-MC-MAC", signature);
                client.DefaultRequestHeaders.Add("X-MC-NONCE", challenge);
                client.Timeout = new TimeSpan(10800000 * TimeSpan.TicksPerMillisecond);

                var responseStream = await client.GetStreamAsync(syncUrl);

                var responseStreamReader = new StreamReader(responseStream);

                while (!responseStreamReader.EndOfStream)
                {
                    var line = await responseStreamReader.ReadLineAsync();

                    var verbosity = Verbosity.Normal;
                    var logLevel  = LogLevel.Information;

                    if (line.StartsWith("Error:"))
                    {
                        line      = line.Substring(7);
                        verbosity = Verbosity.Quiet;
                        logLevel  = LogLevel.Error;
                    }
                    else if (line.StartsWith("Warning:"))
                    {
                        line      = line.Substring(9);
                        verbosity = Verbosity.Normal;
                        logLevel  = LogLevel.Warning;
                    }
                    else if (line.StartsWith("Debug:"))
                    {
                        line      = line.Substring(7);
                        verbosity = Verbosity.Diagnostic;
                        logLevel  = LogLevel.Debug;
                    }
                    else if (line.StartsWith("Info:"))
                    {
                        line      = line.Substring(6);
                        verbosity = Verbosity.Verbose;
                        logLevel  = LogLevel.Information;
                    }

                    log.Write(verbosity, logLevel, HttpUtility.HtmlDecode(line.Replace("{", "{{").Replace("}", "}}")));

                    responseTextBuilder.AppendLine(line);
                }

                return(responseTextBuilder.ToString());
            }
        }
示例#7
0
        private static string CreateSignature(string challenge, string sharedSecret, string syncUrl, ICakeLog log)
        {
            var service   = new SignatureService(sharedSecret);
            var signature = service.CreateSignature(challenge, syncUrl, null);

            log.Write(Verbosity.Diagnostic, LogLevel.Debug, $"MAC: '{signature.SignatureSource}'");
            log.Write(Verbosity.Diagnostic, LogLevel.Debug, $"HMAC: '{signature.SignatureHash}'");
            log.Write(Verbosity.Diagnostic, LogLevel.Debug, "If you get authorization failures compare the values above to the Sitecore logs.");
            return(signature.SignatureHash);
        }
示例#8
0
        private static async Task <string> GetChallengeAsync(string controlPanelUrl, ICakeLog log)
        {
            log.Write(Verbosity.Normal, LogLevel.Information, "Fetching authentication token...");
            using (var client = new HttpClient())
            {
                var challenge = await client.GetStringAsync($"{controlPanelUrl}?verb=Challenge");

                log.Write(Verbosity.Diagnostic, LogLevel.Debug, $"Received challenge from remote server: {challenge}");
                return(challenge);
            }
        }
示例#9
0
        /// <summary>
        /// Gets the Go.CD build history, including the repository modifications that caused the pipeline to start.
        /// </summary>
        /// <param name="username">The Go.CD username.</param>
        /// <param name="password">The Go.CD password.</param>
        /// <param name="serverUrl">The Go.CD server URL.</param>
        /// <returns>The Go.CD build history.</returns>
        public GoCDHistoryInfo GetHistory(string username, string password, string serverUrl)
        {
            if (username == null)
            {
                throw new ArgumentNullException(nameof(username));
            }

            if (password == null)
            {
                throw new ArgumentNullException(nameof(password));
            }

            if (serverUrl == null)
            {
                throw new ArgumentNullException(nameof(serverUrl));
            }

            if (!IsRunningOnGoCD)
            {
                throw new CakeException("The current build is not running on Go.CD.");
            }

            var url = new Uri(string.Format(
                                  CultureInfo.InvariantCulture,
                                  "{0}/go/api/pipelines/{1}/history/0",
                                  serverUrl,
                                  this.Environment.Pipeline.Name).ToLowerInvariant());

            _cakeLog.Write(Verbosity.Diagnostic, LogLevel.Verbose, "Getting [{0}]", url);
            return(Task.Run(async() =>
            {
                var encodedCredentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(
                                                                    string.Format(CultureInfo.InvariantCulture, "{0}:{1}", username, password)));
                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Add(
                        "Authorization",
                        string.Format(CultureInfo.InvariantCulture, "Basic {0}", encodedCredentials));
                    var response = await client.GetAsync(url);
                    var content = await response.Content.ReadAsStringAsync();
                    _cakeLog.Write(Verbosity.Diagnostic, LogLevel.Verbose, "Server response [{0}:{1}]:\n\r{2}", response.StatusCode, response.ReasonPhrase, content);

                    var jsonSerializer = new DataContractJsonSerializer(typeof(GoCDHistoryInfo));

                    using (var jsonStream = new MemoryStream(Encoding.UTF8.GetBytes(content)))
                    {
                        return jsonSerializer.ReadObject(jsonStream) as GoCDHistoryInfo;
                    }
                }
            }).GetAwaiter().GetResult());
        }
        /// <summary>
        /// Run the specified command on files specified by assemblyPath and the settings.
        /// </summary>
        /// <param name="assemblies">The assembly path.</param>
        /// <param name="settings">The settings.</param>
        public void Run(IEnumerable <string> assemblies, DotfuscatorSettings settings)
        {
            if (assemblies == null)
            {
                throw new ArgumentNullException("assemblies");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            _logger.Write(Verbosity.Normal, LogLevel.Information, "Find Dotfuscator : {0}", _resolver.GetToolPath());
            Run(settings, GetArguments(assemblies, settings));
        }
示例#11
0
 /// <summary>
 /// Writes a warning message to the log using the specified verbosity and format information.
 /// </summary>
 /// <param name="log">The log.</param>
 /// <param name="verbosity">The verbosity.</param>
 /// <param name="format">A composite format string.</param>
 /// <param name="args">An array of objects to write using format.</param>
 public static void Warning(this ICakeLog log, Verbosity verbosity, string format, params object[] args)
 {
     if (log != null)
     {
         log.Write(verbosity, LogLevel.Warning, format, args);
     }
 }
示例#12
0
        private void WriteToBuildLog(CakeReport report)
        {
            var b = _context.MyGet();

            var maxTaskNameLength = 29;

            foreach (var item in report)
            {
                if (item.TaskName.Length > maxTaskNameLength)
                {
                    maxTaskNameLength = item.TaskName.Length;
                }
            }

            maxTaskNameLength++;
            string lineFormat = "{0,-" + maxTaskNameLength + "}{1,-20}";

            foreach (var entry in report)
            {
                if (ShouldWriteTask(entry))
                {
                    _log.Write(Verbosity.Quiet, LogLevel.Information,
                               "##myget[message text='{0}' status='NORMAL']", string.Format(lineFormat, entry.TaskName, FormatDuration(entry)));
                }
            }

            // Write footer.
            _console.WriteLine(lineFormat, "Total:", FormatTime(GetTotalTime(report)));
        }
示例#13
0
        private void WriteLoggingCommand(string actionName, Dictionary <string, string> properties, string value)
        {
            var props = string.Join(string.Empty, properties.Select(pair =>
            {
                return(string.Format(CultureInfo.InvariantCulture, "{0}={1};", pair.Key, pair.Value));
            }));

            _log.Write(Verbosity.Quiet, LogLevel.Information, "{0}{1} {2}{3}{4}", MessagePrefix, actionName, props, MessagePostfix, value);
        }
示例#14
0
        /// <summary>
        /// Writes a message to the log using the specified verbosity, log level and log action delegate.
        /// Evaluates log message only if the verbosity is equal to or more verbose than the log's verbosity.
        /// </summary>
        /// <param name="log">The log.</param>
        /// <param name="verbosity">The verbosity.</param>
        /// <param name="level">The log level.</param>
        /// <param name="logAction">The log action.</param>
        public static void Write(this ICakeLog log, Verbosity verbosity, LogLevel level, LogAction logAction)
        {
            if (log == null || logAction == null)
            {
                return;
            }

            if (verbosity > log.Verbosity)
            {
                return;
            }

            LogActionEntry actionEntry = (format, args) => log.Write(verbosity, level, format, args);

            logAction(actionEntry);
        }
示例#15
0
        private void WriteServiceMessage(string messageName, Dictionary <string, string> values)
        {
            var valueString =
                string.Join(" ",
                            values
                            .Select(keypair =>
            {
                if (string.IsNullOrWhiteSpace(keypair.Key))
                {
                    return(string.Format(CultureInfo.InvariantCulture, "'{0}'", Sanitize(keypair.Value)));
                }
                return(string.Format(CultureInfo.InvariantCulture, "{0}='{1}'", keypair.Key, Sanitize(keypair.Value)));
            })
                            .ToArray());

            _log.Write(Verbosity.Quiet, LogLevel.Information, "{0}{1} {2}{3}", MessagePrefix, messageName, valueString, MessagePostfix);
        }
 public override void Write(ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value)
 {
     _Log.Write(Verbosity.Normal, LogLevel.Information, value.EscapeCurleyBrackets());
 }
示例#17
0
 public void WriteAnalysisReport(string analysisReport)
 {
     _contextLog.Write(Verbosity.Minimal, LogLevel.Information, analysisReport);
 }
 public override void Write(string value)
 {
     _Log.Write(Verbosity.Normal, LogLevel.Information, value);
 }
 public void Report(Exception exceptionFromResolution)
 {
     _contextLog.Write(Verbosity.Minimal, LogLevel.Error, exceptionFromResolution.ToString());
 }
示例#20
0
 /// <summary>
 /// Writes an error message to the log using the specified verbosity and format information.
 /// </summary>
 /// <param name="log">The log.</param>
 /// <param name="verbosity">The verbosity.</param>
 /// <param name="format">A composite format string.</param>
 /// <param name="args">An array of objects to write using format.</param>
 public static void Error(this ICakeLog log, Verbosity verbosity, string format, params object[] args)
 {
     log?.Write(verbosity, LogLevel.Error, format, args);
 }
示例#21
0
 public void Log(LogLevel level, string data) => _log.Write(GetVerbosity(level), GetLogLevel(level), data);