﻿
using Microsoft.Build.Exceptions;
using System;

namespace SolutionReader
{
  internal static class ProjectFileErrorUtilities
  {
    internal static void ThrowInvalidProjectFile(BuildEventFileInfo projectFile, string resourceName, params object[] args)
    {
      ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(false, (string) null, projectFile, resourceName, args);
    }

    internal static void ThrowInvalidProjectFile(BuildEventFileInfo projectFile, Exception innerException, string resourceName, params object[] args)
    {
      ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(false, (string) null, projectFile, innerException, resourceName, args);
    }

    internal static void VerifyThrowInvalidProjectFile(bool condition, BuildEventFileInfo projectFile, string resourceName, params object[] args)
    {
      ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(condition, (string) null, projectFile, resourceName, args);
    }

    internal static void VerifyThrowInvalidProjectFile(bool condition, string errorSubCategoryResourceName, BuildEventFileInfo projectFile, string resourceName, params object[] args)
    {
      ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(condition, errorSubCategoryResourceName, projectFile, (Exception) null, resourceName, args);
    }

    internal static void VerifyThrowInvalidProjectFile(bool condition, string errorSubCategoryResourceName, BuildEventFileInfo projectFile, Exception innerException, string resourceName, params object[] args)
    {
      ErrorUtilities.VerifyThrow(projectFile != null, "Must specify the invalid project file. If project file is not available, use VerifyThrowInvalidProject() and pass in the XML node instead.");
      if (!condition)
      {
        string errorSubcategory = (string) null;
        if (errorSubCategoryResourceName != null)
          errorSubcategory = AssemblyResources.GetString(errorSubCategoryResourceName);
        string code;
        string helpKeyword;
        string message = ResourceUtilities.FormatResourceString(out code, out helpKeyword, resourceName, args);
        throw new InvalidProjectFileException(projectFile.File, projectFile.Line, projectFile.Column, projectFile.EndLine, projectFile.EndColumn, message, errorSubcategory, code, helpKeyword, innerException);
      }
    }
  }
}
