本文整理汇总了C#中System.Error类的典型用法代码示例。如果您正苦于以下问题:C# Error类的具体用法?C# Error怎么用?C# Error使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Error类属于System命名空间,在下文中一共展示了Error类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EqualsWithDifferentFiles
[Test] public void EqualsWithDifferentFiles()
{
Error E1 = new Error(File1, "Error");
Error E2 = new Error(File2, "Error");
Assert.IsFalse(E1.Equals(E2), "Error.Equals does not return false for errors with differing files");
}
示例2: SendMail
/// <summary>
/// If enabled, sends an error email to the configured recipients
/// </summary>
/// <param name="error">The error the email is about</param>
public static void SendMail(Error error)
{
if (!Enabled) return;
// The following prevents errors that have already been stored from being emailed a second time.
if (PreventDuplicates && error.IsDuplicate) return;
try
{
using (var message = new MailMessage())
{
message.To.Add(ToAddress);
if (FromAddress != null) message.From = FromAddress;
message.Subject = ErrorStore.ApplicationName + " error: " + error.Message.Replace(Environment.NewLine, " ");
message.Body = GetErrorHtml(error);
message.IsBodyHtml = true;
using (var client = GetClient())
{
client.Send(message);
}
}
}
catch (Exception e)
{
Trace.WriteLine(e);
}
}
示例3: SendMail
/// <summary>
/// If enabled, sends an error email to the configured recipients
/// </summary>
/// <param name="error">The error the email is about</param>
public static void SendMail(Error error)
{
if (!Enabled) return;
try
{
using (var message = new MailMessage())
{
message.To.Add(ToAddress);
if (FromAddress != null) message.From = FromAddress;
message.Subject = ErrorStore.ApplicationName + " error: " + error.Message;
message.Body = GetErrorHtml(error);
message.IsBodyHtml = true;
using (var client = GetClient())
{
client.Send(message);
}
}
}
catch (Exception e)
{
Trace.WriteLine(e);
}
}
示例4: CanGetError
public void CanGetError()
{
// Arrange
var fixture = new Fixture();
const string id = "mock error id";
var applicationName = fixture.Create<string>();
var error = new Error(new HttpException());
var errorXml = ErrorXml.EncodeString(error);
var mockResponse = new Mock<IGetResponse<ErrorDocument>>();
mockResponse.Setup(x => x.Source).Returns(new ErrorDocument { ErrorXml = errorXml });
mockResponse.Setup(x => x.IsValid).Returns(true);
var elasticClientMock = new Mock<IElasticClient>();
elasticClientMock
.Setup(x => x.Get(It.IsAny<Func<GetDescriptor<ErrorDocument>, GetDescriptor<ErrorDocument>>>()))
.Returns(mockResponse.Object);
var errorLog = new ElasticSearchErrorLog(elasticClientMock.Object, new Hashtable())
{
ApplicationName = applicationName,
};
// Act
var elmahError = errorLog.GetError(id);
// Assert
Assert.That(elmahError != null);
Assert.That(elmahError.Id, Is.EqualTo(id));
Assert.That(elmahError.Error != null);
Assert.That(elmahError.Error.ApplicationName, Is.EqualTo(applicationName));
}
示例5: ErrorMailHtmlPage
public ErrorMailHtmlPage(Error error, ErrorMailOptions options = null)
{
Error = error;
if (error.Exception != null)
ErrorLogEntry = LoggedException.RecallErrorLogEntry(error.Exception);
Options = options ?? DefaultOptions;
}
示例6: ContainsWord
/// <summary>
/// Dictionary contains the word.
/// </summary>
public bool ContainsWord(string word, Lang lang, out Error error)
{
lock (_sync)
{
error = null;
if (_externalDictionary.ContainWord(word, lang))
return true;
SpellResult result = _yandexSpeller.CheckText(word, lang, Options.ByWords, TextFormat.Plain);
if (result.Errors.Count > 0)
{
error = result.Errors[0];
return false;
}
_innerUpdate = true;
try
{
_externalDictionary.AddWord(word, lang);
}
finally
{
_innerUpdate = false;
}
return true;
}
}
示例7: Run
public void Run()
{
Console.WriteLine("Press 'Enter' to send a message. To exit, Ctrl + C");
while (true)
{
var read = Console.ReadLine();
LogMessage message = null;
read = string.IsNullOrEmpty(read) ? "info Info Message" : read;
if (read.IndexOf(" ") < 0)
read += " Log Message";
var type = read.Substring(0, read.IndexOf(" "));
var payload = read.Substring(read.IndexOf(" ") + 1);
switch (type.ToLower())
{
case "warn":
message = new Warn();
break;
case "error":
message = new Error();
break;
default:
message = new Info();
break;
}
message.Message = payload;
Bus.Send(message);
}
}
示例8: recibeMensajeBErr
public static IList recibeMensajeBErr(byte[] byteRec)
{
Array.Resize(ref byteRec, 169);
PRN prn = new PRN();
Error err = new Error();
//codPaquete = Conversiones.AgregaCadena(byteRec, 0, 1);// Cod. de Paquete
err.CodError = (UInt16)Conversiones.AgregaDigito16(byteRec, 1);// Cod. de ERROR
//flagLongFile = (byte)Conversiones.AgregaDigito(byteRec, 3, 1);// FLag LongFile
//longFile = (UInt32)Conversiones.AgregaDigito32(byteRec, 4, 4);// LongFile
//correo = (byte)Conversiones.AgregaDigito(byteRec, 8, 1);// Correo
prn.Nombre1 = Conversiones.AgregaCadena(byteRec, 9, 10); // Usuario 0
prn.Nombre2 = Conversiones.AgregaCadena(byteRec, 19, 10); // Usuario 1
prn.Nombre3 = Conversiones.AgregaCadena(byteRec, 29, 10); // Usuario 2
prn.Port1 = Conversiones.AgregaCadena(byteRec, 39, 15); // Direccion 0 //DUDA: string o int?
prn.Port2 = Conversiones.AgregaCadena(byteRec, 54, 15); // Direccion 1 //DUDA: string o int?
prn.Port3 = Conversiones.AgregaCadena(byteRec, 69, 15); // Direccion 2 //DUDA: string o int?
prn.Telefono1 = Conversiones.AgregaCadena(byteRec, 84, 15); // Telefono 0
prn.Telefono2 = Conversiones.AgregaCadena(byteRec, 99, 15); // Telefono 1
prn.Telefono3 = Conversiones.AgregaCadena(byteRec, 114, 15); // Telefono 2
err.Descripcion = Conversiones.AgregaCadena(byteRec, 129, 40); // Mensaje de ERROR
IList menB = new List<object> { err, prn };
return menB;
}
示例9: ErroneousTrack
public ErroneousTrack(ISession session, IntPtr handle, Error error, IPlaylist playlist = null)
: base(session, handle)
{
_error = error;
_playlist = playlist;
_artists = new DelegateArray<IArtist>(() => 0, index => null);
}
示例10: TestCookie
public void TestCookie()
{
const string CookieName = "ASP.NET_SessionId";
var configurationSection = new MaskedValuesConfigurationSection();
configurationSection.RemoveAspxAuth = false;
configurationSection.ReplacementText = "OBSCURED";
configurationSection.Cookies.Add(new MaskedItemElement(CookieName));
using (HttpSimulator simulator = new HttpSimulator("/", @"c:\inetpub\"))
{
simulator.SetCookies(Cookies)
.SimulateRequest(new Uri("http://localhost/"));
var error = new Error(new HttpRequestValidationException(), HttpContext.Current);
Assert.IsNotNull(HttpContext.Current.Request.Cookies[CookieName]);
ErrorHelper.Obscure(error, configurationSection);
Assert.AreEqual(configurationSection.ReplacementText, error.Cookies[CookieName]);
Assert.AreNotEqual(configurationSection.ReplacementText, error.Cookies[MaskedValuesConfigurationSection.AspxAuthCookie]);
}
}
示例11: TestDeepEquals
private void TestDeepEquals(Error objectA, Error objectB, bool expect, bool expectDeep)
{
Assert.AreEqual(expectDeep, objectA.DeepEquals(objectB));
Assert.AreEqual(expectDeep, objectB.DeepEquals(objectA));
Assert.AreEqual(expect, objectA.Equals(objectB));
Assert.AreEqual(expect, objectB.Equals(objectA));
}
示例12: FromException
public static ErrorResponse FromException(Exception exception)
{
//var exception = ex.GetRootError();
var summary = exception.Message;
if (exception is WebException || exception is SocketException)
summary = "";
var statusCode = HttpStatusCode.InternalServerError;
var error = new Error();
if (exception is LightstoneAutoException)
{
statusCode = HttpStatusCode.InternalServerError;
error.ErrorMessage = summary;
}
else if (exception is NotImplementedException)
statusCode = HttpStatusCode.NotImplemented;
else if (exception is UnauthorizedAccessException)
{
statusCode = HttpStatusCode.Forbidden;
error.ErrorMessage = "Sorry, you do not have permission to perform that action. Please contact Lightstone Auto.";
}
else if (exception is AuthenticationException)
statusCode = HttpStatusCode.Unauthorized;
else if (exception is ArgumentException)
statusCode = HttpStatusCode.BadRequest;
return new ErrorResponse(error) { StatusCode = statusCode };
}
示例13: Equals
[Test] public void Equals()
{
Error E1 = new Error(File1, "Error");
Error E2 = new Error(File1, "Error");
Assert.IsTrue(E1.Equals(E2), "Error.Equals does not return true for identical errors");
}
示例14: EqualsWithDifferentMessages
[Test] public void EqualsWithDifferentMessages()
{
Error E1 = new Error(File1, "Error");
Error E2 = new Error(File1, "Warning");
Assert.IsFalse(E1.Equals(E2), "Error.Equals does not return false for errors with differing descriptions");
}
示例15: ErrorAndMessageConstructorWorks
public void ErrorAndMessageConstructorWorks() {
var err = new Error { Message = "Some message" };
var ex = new JsErrorException(err, "Overridden message");
Assert.IsTrue((object)ex is JsErrorException, "is JsErrorException");
Assert.IsTrue(ex.InnerException == null, "InnerException");
Assert.IsTrue(ReferenceEquals(ex.Error, err), "Error");
Assert.AreEqual(ex.Message, "Overridden message", "Message");
}