//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using System.Data.SqlClient;
using Microsoft.SqlTools.ManagedBatchParser;
namespace Microsoft.SqlTools.ServiceLayer.BatchParser.ExecutionEngineCode
{
///
/// Error totalAffectedRows for a Batch
///
public class BatchErrorEventArgs : EventArgs
{
#region Private Fields
private string message = string.Empty;
private string description = string.Empty;
private int line = -1;
private TextSpan textSpan;
private Exception exception;
private SqlError error;
#endregion
#region Constructors / Destructor
///
/// Default constructor
///
private BatchErrorEventArgs()
{
}
///
/// Constructor with message and no description
///
internal BatchErrorEventArgs(string message)
: this(message, null)
{
}
///
/// Constructor with exception and no description
///
internal BatchErrorEventArgs(string message, Exception ex)
: this(message, string.Empty, ex)
{
}
///
/// Constructor with message and description
///
internal BatchErrorEventArgs(string message, string description, Exception ex)
: this(message, description, -1, new TextSpan(), ex)
{
}
internal BatchErrorEventArgs(string message, SqlError error, TextSpan textSpan, Exception ex)
{
string desc = error != null ? error.Message : null;
if (error.Number == 7202)
{
desc += " " + Environment.NewLine + SR.TroubleshootingAssistanceMessage;
}
int lineNumber = error != null ? error.LineNumber : -1;
Init(message, desc, lineNumber, textSpan, ex);
this.error = error;
}
///
/// Constructor with message, description, textspan and line number
///
internal BatchErrorEventArgs(string message, string description, int line, TextSpan textSpan, Exception ex)
{
Init(message, description, line, textSpan, ex);
}
private void Init(string message, string description, int line, TextSpan textSpan, Exception ex)
{
this.message = message;
this.description = description;
this.line = line;
this.textSpan = textSpan;
exception = ex;
}
#endregion
#region Public properties
public string Message
{
get
{
return message;
}
}
public string Description
{
get
{
return description;
}
}
public int Line
{
get
{
return line;
}
}
public TextSpan TextSpan
{
get
{
return textSpan;
}
}
public Exception Exception
{
get
{
return exception;
}
}
public SqlError Error
{
get { return error; }
}
#endregion
}
}