Exemple #1
0
 /// <summary>
 /// Logs potential errors. Returns true if no error occured, false on error.
 /// </summary>
 /// <param name="m"></param>
 /// <param name="res"></param>
 /// <returns>True on success, false on error.</returns>
 async Task <bool> LogErrors(IActivityMonitor m, HttpResponseMessage res)
 {
     if (res.StatusCode == HttpStatusCode.Unauthorized)
     {
         using (m.OpenError("Unauthorized Status Code"))
         {
             if (res.Headers.Contains("www-authenticate"))
             {
                 List <string> auth = res.Headers.GetValues("www-authenticate").ToList();
                 if (auth.Contains("ipaddress"))
                 {
                     m.Error("Login is not allowed from your IP address");
                 }
                 else if (auth.Contains("otp"))
                 {
                     m.Error("OTP required for authentication");
                 }
                 else
                 {
                     m.Error("Unable to authenticate, need: " + string.Join(", ", auth));
                 }
             }
             else
             {
                 if ((await res.Content.ReadAsStringAsync()).Contains("one-time pass"))
                 {
                     m.Error("OTP required for authentication.");
                 }
                 else
                 {
                     m.Error("Unknown error.");
                 }
             }
         }
         return(false);
     }
     if (!res.IsSuccessStatusCode)
     {
         using (m.OpenError($"Response status code is not a success code: '{res.ReasonPhrase}'."))
         {
             m.Trace(await res.Content.ReadAsStringAsync());
         }
         return(false);
     }
     else
     {
         m.Debug("Response status code is a success status code.");
     }
     return(true);
 }
Exemple #2
0
        /// <summary>
        /// Creates a ZeroBuilder.
        /// </summary>
        /// <param name="m">The monitor to use.</param>
        /// <param name="feeds">The local feeds.</param>
        /// <param name="depContext">The dependency context to consider.</param>
        /// <param name="driverFinder">The driver finder by solution name.</param>
        /// <param name="solutionReloader">Optional solutions reloader.</param>
        /// <returns>The ZeroBuilder on success, null on error.</returns>
        static ZeroBuilder Create(
            IActivityMonitor m,
            IEnvLocalFeedProvider feeds,
            IWorldSolutionContext context)
        {
            if (context.DependencyContext.BuildProjectsInfo.HasError)
            {
                using (m.OpenError("Build Projects dependencies failed to be computed."))
                {
                    context.DependencyContext.BuildProjectsInfo.RawBuildProjectsInfoSorterResult.LogError(m);
                }
                return(null);
            }
            var zeroProjects = context.DependencyContext.BuildProjectsInfo.ZeroBuildProjects;

            if (zeroProjects.Count == 0)
            {
                m.Error(context.DependencyContext.HasError ? "Invalid dependency analysis." : "No Build Project exist.");
                return(null);
            }
            var mustBuild = new HashSet <string>(zeroProjects.Select(p => p.Project.FullFolderPath.Path));
            var memPath   = feeds.ZeroBuild.PhysicalPath.AppendPart("CacheZeroVersion.txt");
            var sha1Cache = System.IO.File.Exists(memPath)
                            ? System.IO.File.ReadAllLines(memPath)
                            .Select(l => l.Split())
                            .Where(l => mustBuild.Contains(l[0]))
                            .ToDictionary(l => l[0], l => new HashSet <string>(l[1].Split('|')))
                            : new Dictionary <string, HashSet <string> >();

            m.Info($"File '{memPath}' contains {sha1Cache.Count} entries.");
            var currentShas = new string[zeroProjects.Count];

            return(new ZeroBuilder(feeds, memPath, sha1Cache, mustBuild, context));
        }
 /// <summary>
 /// Dumps the result of the compilation into a monitor.
 /// </summary>
 /// <param name="monitor">The monitor to use.</param>
 /// <param name="dumpSources">Optionnaly dumps the source as another <see cref="CK.Core.LogLevel"/>.</param>
 public void LogResult(IActivityMonitor monitor, LogLevel?dumpSources = null)
 {
     if (monitor == null)
     {
         throw new ArgumentNullException(nameof(monitor));
     }
     using (monitor.OpenInfo("Code Generation information."))
     {
         if (LoadConflicts != null && LoadConflicts.Count > 0)
         {
             using (monitor.OpenWarn($"{LoadConflicts.Count} assembly load conflict(s)."))
             {
                 foreach (var e in LoadConflicts)
                 {
                     if (e.Resolved != null)
                     {
                         monitor.Warn(e.ToString());
                     }
                     else
                     {
                         monitor.Error(e.ToString());
                     }
                 }
             }
         }
         if (Success)
         {
             monitor.Info(CompilationSkipped ? "Source code parsing succeeded." : "Source code compilation succeeded.");
             if (dumpSources.HasValue)
             {
                 DumpSources(monitor, dumpSources.Value);
             }
         }
         else
         {
             using (monitor.OpenError(CompilationSkipped ? "Parsing failed." : "Compilation failed."))
             {
                 if (EmitError != null)
                 {
                     monitor.Error(EmitError);
                 }
                 if (EmitResult != null)
                 {
                     if (!EmitResult.Success)
                     {
                         using (monitor.OpenInfo($"{EmitResult.Diagnostics.Count()} Compilation diagnostics."))
                         {
                             foreach (var diag in EmitResult.Diagnostics)
                             {
                                 monitor.Trace(diag.ToString());
                             }
                         }
                     }
                 }
                 else
                 {
                     Debug.Assert(CompilationSkipped);
                     using (monitor.OpenInfo($"{ParseDiagnostics.Count()} Parsing diagnostics."))
                     {
                         foreach (var diag in ParseDiagnostics)
                         {
                             monitor.Trace(diag.ToString());
                         }
                     }
                 }
                 if (dumpSources.HasValue)
                 {
                     DumpSources(monitor, dumpSources.Value);
                 }
             }
         }
         if (AssemblyLoadError != null)
         {
             monitor.Error("Generated assembly load failed.", AssemblyLoadError);
         }
         monitor.CloseGroup(Assembly != null
                                     ? "Generated assembly successfuly loaded."
                                     : (Success ? "Succeeded." : "Failed."));
     }
 }