Exemple #1
0
		[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");
		}
        /// <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);
            }
        }
        /// <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);
            }
        }
        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));
        }
Exemple #5
0
 public ErrorMailHtmlPage(Error error, ErrorMailOptions options = null)
 {
     Error = error;
     if (error.Exception != null)
         ErrorLogEntry = LoggedException.RecallErrorLogEntry(error.Exception);
     Options = options ?? DefaultOptions;
 }
		/// <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;
			}
		}
        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);
            }
        }
        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;
        }
Exemple #9
0
 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);
 }
        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]);
            }
        }
Exemple #11
0
 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));
 }
        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 };
        }
Exemple #13
0
		[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");
		}
Exemple #14
0
		[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");
		}
		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");
		}
 public override string Log(Error error)
 {
     if (error == null)
     {
         throw new ArgumentNullException("error");
     }
     return ExceptionHandler.Report(error.Exception).Id;
 }
 public SimpleInMemProtocolErrorException(
     string message,
     Error details,
     Exception innerException)
     : base(message, innerException)
 {
     Details = details;
 }
        private void ToStringContainsMessagesCollection()
        {
            var errorMessages = new ErrorMessage[] { new ErrorMessage("key1", "message1"), new ErrorMessage("key2", "message2") };
            var error = new Error("id", errorMessages);

            Assert.Contains("message1", error.ToString());
            Assert.Contains("message2", error.ToString());
        }
 /// <summary>
 /// </summary>
 protected static String GetError(Exception ex, Error? error = null)
 {
     if (ex.IsNull())
         return Format(error: error);
     if (!ex.InnerException.IsNull())
         return Format(ex.InnerException.Message, error);
     return Format(ex.Message, error);
 }
Exemple #20
0
 public BarCodeScaner()
 {
     ThreadStart ts = new ThreadStart(ReadPort);
       _thread = new Thread(ts);
       _serialPort = new SerialPort();
       _err = new Error();
       _continue = false;
 }
Exemple #21
0
 /// <summary>
 /// Конструктор
 /// </summary>
 /// <param name="error">Код ошибки выполнения запроса</param>
 /// <param name="description">Описание ошибки</param>
 /// <param name="request">Запрос</param>
 /// <param name="answer">Ответное сообщение на запрос</param>
 public Result(Error error, String description,
     Message request, Message answer)
 {
     _Request = request;
     _ErrorCode = error;
     _Description = description;
     _Answer = answer;
     return;
 }
Exemple #22
0
        public void TestErrorConstructor_01()
        {
            Error error = new Error();
            error.Message = "message 1";

            Error error2 = new Error("message 1");

            Assert.IsTrue(error.DeepEquals(error2));
        }
Exemple #23
0
        public void TestErrorDeserialize_01()
        {
            Error error = new Error("message 1");

            string str = XmlHelper.Instance.ToXmlString<Error>(error);

            Error des = XmlHelper.Instance.FromXmlString<Error>(str);
            Assert.IsTrue(error.DeepEquals(des));
        }
Exemple #24
0
        private void OnError(Error error)
        {
            if (error.Code.IsWarning())
            {
                return;
            }

            this.Unsubscribe();
            this.taskCompletionSource.SetException(new IbException(error.Message, error.Code));
        }
        public static ErrorResponse FromException(Exception ex)
        {
            var exception = ex.GetBaseException();
            var summary = exception.Message;
            const HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
            var error = new Error { ErrorMessage = summary, FullException = exception.ToString() };
            var response = new ErrorResponse(error) { StatusCode = statusCode };

            return response;
        }
Exemple #26
0
        public void TestErrorSerialize_01()
        {
            Error error = new Error("message 1");

            string str = XmlHelper.Instance.ToXmlString<Error>(error);

            Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                            "<error xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">message 1</error>",
                            str);
        }
        private ErrorResponse(Error error) : base(error, new DefaultJsonSerializer())
        {
            Guard.AgainstNull(error, "error");
            _error = error;

            // Enable CORS
            Headers.Add("Access-Control-Allow-Origin", "*");
            Headers.Add("Access-Control-Allow-Headers", "Content-Type");
            Headers.Add("Access-Control-Allow-Methods", "POST,GET,DELETE,PUT,OPTIONS");
        }
Exemple #28
0
 private void HandleError(ISourceLocation errorLocation, Error error, params string[] messageParameters)
   // ^ modifies this.scannerAndParserErrors;
   //^ ensures this.currentToken == old(this.currentToken);
 {
   //^ Token oldToken = this.currentToken;
   if (this.originalScannerAndParserErrors == this.scannerAndParserErrors) {
   }
   this.scannerAndParserErrors.Add(new SpecSharpErrorMessage(errorLocation, (long)error, error.ToString(), messageParameters));
   //^ assume this.currentToken == oldToken;
 }
        public override string Log(Error error)
        {
            if (error == null)
            {
                throw new ArgumentNullException("error");
            }

            ErrorHelper.Obscure(error, this._obfuscationConfiguration);

            return base.Log(error);
        }
        public void CanGetErrors()
        {
            // Arrange
            var fixture = new Fixture();
            var id1 = fixture.Create<string>();
            var id2 = fixture.Create<string>();
            var applicationName = fixture.Create<string>();

            var error1 = new Error(new Exception("error1"));
            var error2 = new Error(new Exception("error2"));
            var errorXml1 = ErrorXml.EncodeString(error1);
            var errorXml2 = ErrorXml.EncodeString(error2);
            var errorDoc1 = new ErrorDocument {ErrorXml = errorXml1};
            var errorDoc2 = new ErrorDocument {ErrorXml = errorXml2};

            
            var queryResponse = new Mock<ISearchResponse<ErrorDocument>>();

            queryResponse.Setup(x => x.Total).Returns(2);
            queryResponse.Setup(x => x.Hits).Returns(() =>
            {
                var mockHit1 = new Mock<IHit<ErrorDocument>>();
                mockHit1.Setup(x => x.Id).Returns(id1);
                mockHit1.Setup(x => x.Source).Returns(errorDoc1);

                var mockHit2 = new Mock<IHit<ErrorDocument>>();
                mockHit2.Setup(x => x.Id).Returns(id2);
                mockHit2.Setup(x => x.Source).Returns(errorDoc2);

                return new[]
                {
                    mockHit1.Object,
                    mockHit2.Object
                };
            });
            queryResponse.Setup(x => x.IsValid).Returns(true);

            _elasticClientMock
                .Setup(x => x.Search(It.IsAny<Func<SearchDescriptor<ErrorDocument>, SearchDescriptor<ErrorDocument>>>()))
                .Returns(queryResponse.Object);

            var errorLog = new ElasticSearchErrorLog(_elasticClientMock.Object, new Hashtable())
            {
                ApplicationName = applicationName
            };

            // Act
            var result = new ArrayList();
            var count = errorLog.GetErrors(0, int.MaxValue, result);

            // Assert
            Assert.That(count, Is.EqualTo(2));
            Assert.That(result.Count, Is.EqualTo(2));
        }