Exemplo n.º 1
0
 public ParseException(int row, int column, string reason, ExceptionLevel level) : base()
 {
     this._row    = row;
     this._column = column;
     this._reason = reason;
     this._level  = level;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AppException"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="inner">The inner.</param>
 /// <param name="level">The level.</param>
 public AppException(string message, Exception inner, ExceptionLevel level)
     : base(message, inner)
 {
     this.ID = Guid.NewGuid();
     this.Level = level;
     this.ErrorCode = InnerCode;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Add exception message to the object
        /// </summary>
        /// <param name="level"></param>
        /// <param name="message"></param>
        public void AddLog(ExceptionLevel level, string message)
        {
            //if(this.ExceptionData == null)
            //    this.ExceptionData = ExFactoryGeneric.GetNewInstance();

            //this.ExceptionData.AddLog(level, message);
        }
Exemplo n.º 4
0
 public ParseException(int row, int column, string reason, ExceptionLevel level)
     : base()
 {
     this._row = row;
     this._column = column;
     this._reason = reason;
     this._level = level;
 }
Exemplo n.º 5
0
        public void DeletePage_Throws_WhenPageIdInvalid(ExceptionLevel exceptionLevel)
        {
            auth.ExceptionLevel = exceptionLevel;

            var ex = Assert.Throws <GhostSharpException>(() => auth.DeletePage(InvalidPageId));

            Assert.That(ex.Message.StartsWith("Resource not found error, cannot delete page."));
        }
Exemplo n.º 6
0
        public void DeletePost_Throws_WhenPostIdInvalid(ExceptionLevel exceptionLevel)
        {
            auth.ExceptionLevel = exceptionLevel;

            var ex = Assert.Throws <GhostSharpException>(() => auth.DeletePost(InvalidPostId));

            Assert.AreEqual("Resource not found error, cannot delete post.", ex.Message);
        }
Exemplo n.º 7
0
 internal GhostAPI(string host, ExceptionLevel exceptionLevel, string baseUrl, APIType apiType)
 {
     this.apiType = apiType;
     Client       = new RestClient {
         BaseUrl = new Uri(new Uri(host), baseUrl)
     };
     ExceptionLevel = exceptionLevel;
 }
Exemplo n.º 8
0
        public void GetAuthorById_ThrowsGhostSharpException_WhenIdIsInvalid(ExceptionLevel exceptionLevel)
        {
            auth.ExceptionLevel = exceptionLevel;

            var ex = Assert.Throws <GhostSharpException>(() => auth.GetAuthorById(InvalidAuthorId));

            Assert.IsNotEmpty(ex.Errors);
            Assert.AreEqual("Author not found.", ex.Errors[0].Message);
        }
Exemplo n.º 9
0
        public void GetPostById_ThrowsGhostSharpException_WhenIdIsInvalid(ExceptionLevel exceptionLevel)
        {
            auth.ExceptionLevel = exceptionLevel;

            var ex = Assert.Throws <GhostSharpException>(() => auth.GetPostById(InvalidPostId));

            Assert.IsNotEmpty(ex.Errors);
            Assert.AreEqual("Resource not found error, cannot read post.", ex.Errors[0].Message);
        }
Exemplo n.º 10
0
        public void GetPageBySlug_ThrowsGhostSharpException_WhenSlugIsInvalid(ExceptionLevel exceptionLevel)
        {
            auth.ExceptionLevel = exceptionLevel;

            var ex = Assert.Throws <GhostSharpException>(() => auth.GetPageBySlug(InvalidPageSlug));

            Assert.IsNotEmpty(ex.Errors);
            Assert.AreEqual("Resource not found error, cannot read page.", ex.Errors[0].Message);
        }
        /// <summary>
        /// Passes the exception to listener.
        /// </summary>
        /// <param name="level">Exception level.</param>
        /// <param name="type">Exception type.</param>
        protected void PassExceptionToListener(ExceptionLevel level, ExceptionType type)
        {
            var handler = this.ShowException;

            if (handler != null)
            {
                handler(this, new RepositoryExceptionEventArgs(level, type));
            }
        }
Exemplo n.º 12
0
        public void GhostAdminAPI_AlwaysThrowsException_WhenKeyIsInvalidFormat(ExceptionLevel exceptionLevel)
        {
            var ex = Assert.Throws <ArgumentException>(() => new GhostAdminAPI(Host, InvalidFormattedApiKey)
            {
                ExceptionLevel = exceptionLevel
            });

            Assert.AreEqual("The Admin API Key should consist of an ID and Secret, separated by a colon.", ex.Message);
        }
Exemplo n.º 13
0
        public void GetPostBySlug_ThrowsGhostSharpException_WhenSlugIsInvalid(ExceptionLevel exceptionLevel)
        {
            auth.ExceptionLevel = exceptionLevel;

            var ex = Assert.Throws <GhostSharpException>(() => auth.GetPostBySlug(InvalidPostSlug));

            Assert.IsNotEmpty(ex.Errors);
            Assert.AreEqual("Post not found.", ex.Errors[0].Message);
        }
Exemplo n.º 14
0
        public void GetSettings_DoesNotThrow_ReturnsNull_WhenKeyIsInvalid(ExceptionLevel exceptionLevel)
        {
            var auth = new GhostContentAPI(Host, InvalidApiKey)
            {
                ExceptionLevel = exceptionLevel
            };

            Assert.IsNull(auth.GetSettings());
            Assert.IsNotNull(auth.LastException);
        }
Exemplo n.º 15
0
        public void GetAuthors_ThrowsException_WhenUnexpectedError(ExceptionLevel exceptionLevel)
        {
            mockClient.Setup(x => x.Execute <AuthorResponse>(It.IsAny <RestRequest>()))
            .Throws(new Exception(systemExceptionMessage));
            auth.ExceptionLevel = exceptionLevel;

            var ex = Assert.Throws <Exception>(() => auth.GetAuthors());

            Assert.AreEqual(systemExceptionMessage, ex.Message);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Log full exception data to file by serializing to xml
        /// </summary>
        public static void LogXmlSerializedException(Exception exception, ExceptionLevel level, string message = null, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
        {
            var location = $"[{memberName}({sourceFilePath}:{sourceLineNumber})]";
            var name     = "exception";

            switch (level)
            {
            case ExceptionLevel.ApplicationCrash:
                name = "applicationcrash";
                break;

            case ExceptionLevel.Unhandled:
                name = "unhandledexception";
                break;

            case ExceptionLevel.Ignored:
                name = "ignoredexception";
                break;
            }

            var    r        = new Regex(@"[^a-z0-9\._]+", RegexOptions.IgnoreCase | RegexOptions.Singleline);
            var    filename = $@"logs\{name}{(!string.IsNullOrWhiteSpace(memberName) ? $"_{r.Replace(memberName, "_")}" : "")}_{DateTime.Now:yyyy-MM-dd.HH.mm.ss.ffff}";
            var    ext      = ".log";
            string path     = null;
            var    n        = 0;

            while (true)
            {
                path = string.Format(@"{0}{1}{2}", filename, (n > 0 ? "-" + n.ToString("000") : ""), ext);
                if (!File.Exists(path))
                {
                    break;
                }
                else
                {
                    n++;
                }
            }
            using (var ifs = File.Open(path, FileMode.CreateNew, FileAccess.Write, FileShare.None))
            {
                using (var sw = new StreamWriter(ifs))
                {
                    if (message != null)
                    {
                        sw.WriteLine(message);
                    }
                    sw.WriteLine(location);
                    sw.WriteLine();
                    XElement root = new XElement("Exception");
                    root.Add(GetXElementExeception(exception));
                    sw.Write(root);
                }
            }
        }
Exemplo n.º 17
0
        public void GetAuthors_ThrowsGhostSharpException_WhenIdIsInvalid(ExceptionLevel exceptionLevel)
        {
            SetupMockAuthorGhostFailure();
            auth.ExceptionLevel = exceptionLevel;

            var ex = Assert.Throws <GhostSharpException>(() => auth.GetAuthors());

            Assert.IsNotEmpty(ex.Errors);
            Assert.IsNotNull(auth.LastException);
            Assert.That(ex.Message.StartsWith(ghostErrorMessage));
            Assert.AreEqual(ghostErrorType, ex.Errors[0].Type);
        }
Exemplo n.º 18
0
        public void GetPostBySlug_ThrowsGhostSharpException_WhenIdIsInvalid(ExceptionLevel exceptionLevel)
        {
            SetupMockPostGhostFailure();
            auth.ExceptionLevel = exceptionLevel;

            var ex = Assert.Throws <GhostSharpException>(() => auth.GetPostBySlug(slug));

            Assert.IsNotEmpty(ex.Errors);
            Assert.IsNotNull(auth.LastException);
            Assert.AreEqual(ghostErrorMessage, ex.Message);
            Assert.AreEqual(ghostErrorType, ex.Errors[0].ErrorType);
        }
Exemplo n.º 19
0
        public void GetPosts_ThrowsException_WhenKeyIsInvalid(ExceptionLevel exceptionLevel)
        {
            var auth = new GhostContentAPI(Host, InvalidApiKey)
            {
                ExceptionLevel = exceptionLevel
            };

            var ex = Assert.Throws <GhostSharpException>(() => auth.GetPosts());

            Assert.IsNotEmpty(ex.Errors);
            Assert.AreEqual("Unknown Content API Key", ex.Errors[0].Message);
        }
Exemplo n.º 20
0
        public void GetAuthors_ThrowsGhostSharpException_WhenRequestThrowsException(ExceptionLevel exceptionLevel)
        {
            mockClient.Setup(x => x.Execute <AuthorResponse>(It.IsAny <RestRequest>()))
            .Returns(new RestResponse <AuthorResponse> {
                ErrorException = new Exception(ghostErrorMessage)
            });
            auth.ExceptionLevel = exceptionLevel;

            var ex = Assert.Throws <GhostSharpException>(() => auth.GetAuthors());

            Assert.IsEmpty(ex.Errors);
            Assert.IsNotNull(auth.LastException);
            StringAssert.StartsWith($"Unable to GET /authors", ex.Message);
        }
Exemplo n.º 21
0
 public static void ErrorLog(Exception ex, ExceptionLevel el, ExceptionType et)
 {
     try
     {
         if (ConfigurationManager.AppSettings["AllowExceptionLogToDB"].ToUpper() == "TRUE")
         {
             WriteExceptionInDB(ex, el, et);
         }
     }
     catch (Exception exception)
     {
         throw exception;
     }
 }
Exemplo n.º 22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:GhostSharp.GhostAdminAPI"/> class.
        /// </summary>
        /// <param name="host">The Host for which to access the Admin API.</param>
        /// <param name="adminApiKey">Admin API key.</param>
        public GhostAdminAPI(string host, string adminApiKey, ExceptionLevel exceptionLevel = ExceptionLevel.All)
            : base(host, adminApiKey, exceptionLevel, "/ghost/api/v3/admin/", APIType.Admin)
        {
            var adminKeyParts = adminApiKey.Split(':');

            if (adminKeyParts.Length != 2)
            {
                var exception = new ArgumentException("The Admin API Key should consist of an ID and Secret, separated by a colon.");
                LastException = exception;
                throw exception;
            }

            var id     = adminKeyParts[0];
            var secret = adminKeyParts[1];

            var unixEpochInSeconds = new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds();

            var token = new JwtBuilder().WithAlgorithm(new HMACSHA256Algorithm())
                        .WithSecret(Ext.StringToByteArray(secret))
                        .AddHeader(HeaderName.KeyId, id)
                        .AddHeader(HeaderName.Type, "JWT")
                        .AddClaim("exp", unixEpochInSeconds + 300)
                        .AddClaim("iat", unixEpochInSeconds)
                        .AddClaim("aud", "/v3/admin/")
                        .Encode();

            try
            {
                var json = new JwtBuilder()
                           .WithAlgorithm(new HMACSHA256Algorithm())
                           .WithSecret(Ext.StringToByteArray(secret))
                           .MustVerifySignature()
                           .Decode(token);
            }
            catch (TokenExpiredException)
            {
                Console.WriteLine("Token has expired");
            }
            catch (SignatureVerificationException)
            {
                Console.WriteLine("Token has invalid signature");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            key = token;
        }
Exemplo n.º 23
0
        public static void WriteLog(ExceptionLevel level, string whereOccur, Exception ex)
        {
            StreamWriter writer = null;

            try
            {
                writer = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\LogExceptionFile.txt", true);
                writer.WriteLine("Exception at : " + whereOccur + " on :" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                writer.WriteLine("Exception message : " + ex.Source.ToString().Trim() + "; " + ex.Message.ToString().Trim());
                writer.WriteLine("Exception stacktrace : " + ex.Source.ToString().Trim() + "; " + ex.StackTrace.Trim());
                writer.WriteLine("============================================================================================");
                writer.Flush();
                writer.Close();
            }
            catch { }
        }
Exemplo n.º 24
0
		public DependencyMessageBox(
			string message, 
			string caption = "Error", 
			MessageBoxButton buttons = MessageBoxButton.OK,
			ExceptionLevel icon = ExceptionLevel.Error)
		{
			Message = message;
			Caption = caption;
			if (buttons == MessageBoxButton.OK)
			{
				ButtonList.Add(Button.OK(this));
				DefaultButton = ButtonList.First();
			}
			else Buttons = buttons;
			Icon = icon;
			IsEnabled = true;
		}
        public static Insights.Severity ToSeverity(this ExceptionLevel @this)
        {
            switch (@this)
            {
            case ExceptionLevel.Warning:
                return(Insights.Severity.Warning);

            case ExceptionLevel.Error:
                return(Insights.Severity.Error);

            case ExceptionLevel.Critial:
                return(Insights.Severity.Critical);

            default:
                throw new NotSupportedException("Unsupported exception level: " + @this);
            }
        }
Exemplo n.º 26
0
		public DependencyMessageBox(
			Exception exception,
			string message = "",
			string caption = "Error",
			MessageBoxButton buttons = MessageBoxButton.OK,
			ExceptionLevel icon = ExceptionLevel.Error)
		{
			if (!string.IsNullOrWhiteSpace(message)) Message = message + "\n" + exception.Message;
			else Message = exception.Message;
			if (exception.InnerException != null) Message += ("\n" + exception.InnerException.Message);
			Caption = caption;
			if (buttons == MessageBoxButton.OK)
			{
				ButtonList.Add(Button.OK(this));
				DefaultButton = ButtonList.First();
			}
			else Buttons = buttons;
			Icon = icon;
			IsEnabled = true;
		}
Exemplo n.º 27
0
        /// <summary>
        /// 获取异常的简写字符
        /// </summary>
        /// <param name="eLevel">异常等级</param>
        /// <returns></returns>
        public static string GetToken(ExceptionLevel eLevel)
        {
            switch (eLevel)
            {
            case ExceptionLevel.Warning:
                return("W");

            case ExceptionLevel.Infomation:
                return("I");

            case ExceptionLevel.Exception:
                return("E");

            case ExceptionLevel.Error:
                return("!");

            case ExceptionLevel.None:
                return("");

            default:
                return("?");
            }
        }
Exemplo n.º 28
0
 public KarrStyleException(string userFriendlyMessage, string message, ExceptionLevel level)
     : base(message)
 {
     Level = level;
     UserFriendlyMessage = userFriendlyMessage;
 }
Exemplo n.º 29
0
        public void GetAuthorById_ReturnsNull_WhenKeyIsInvalid_AndGhostExceptionsSuppressed(ExceptionLevel exceptionLevel)
        {
            auth.ExceptionLevel = exceptionLevel;

            Assert.IsNull(auth.GetAuthorById(InvalidAuthorId));
        }
Exemplo n.º 30
0
 public ServiceException(string resourceKey, string message = "", ExceptionLevel level = ExceptionLevel.Error)
     : base(string.Format("({0}) {1}", resourceKey, message))
 {
     ResourceMessageKey = resourceKey;
     Level = level;
 }
 public RepositoryExceptionEventArgs(ExceptionLevel level, ExceptionType type, Exception e = null) {
     this.Level = level;
     this.Exception = e;
     this.Type = type;
 }
Exemplo n.º 32
0
        /// <summary>Handles an exception</summary>
        /// <param name="exception">The exception to handle</param>
        /// <param name="debugMessage">An optional debug message</param>
        /// <param name="exceptionLevel">The level of the exception</param>
        /// <param name="debugObject">An optional debug object</param>
        /// <param name="origin">The caller member name (leave at default for compiler-time value)</param>
        /// <param name="filePath">The caller file path (leave at default for compiler-time value)</param>
        /// <param name="lineNumber">The caller line number (leave at default for compiler-time value)</param>
        public override void HandleException(Exception exception, string debugMessage, ExceptionLevel exceptionLevel, object debugObject = null, [CallerMemberName] string origin = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0)
        {
            // Call base implementation
            base.HandleException(exception, debugMessage, exceptionLevel, debugObject, origin, filePath, lineNumber);

            try
            {
                if (RCPServices.Data.DisplayExceptionLevel <= exceptionLevel)
                {
                    MessageBox.Show(GetMessage(), Resources.ExceptionMessageHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
#pragma warning disable 168
            catch (Exception ex)
#pragma warning restore 168
            {
                Debugger.Break();
            }

            // Helper method for getting the message to display
            string GetMessage()
            {
                var sb = new StringBuilder();

                sb.AppendLine(Resources.ExceptionMessageInfo);
                sb.AppendLine();

                if (Services.Data.CurrentUserLevel >= UserLevel.Debug)
                {
                    sb.AppendLine($"Exception: {exception}");

                    if (exception.Data.Any())
                    {
                        sb.AppendLine();
                        sb.AppendLine($"Data: {exception.Data.Values.Cast<object>().JoinItems(", ")}");
                    }

                    sb.AppendLine();
                    sb.AppendLine($"Origin: {origin}  -  File: {filePath}  -  Line: {lineNumber}");
                    sb.AppendLine();
                    sb.AppendLine($"Debug message: {debugMessage}");
                    if (debugObject != null)
                    {
                        sb.AppendLine($"Debug object: {debugObject}");
                    }
                }
                else
                {
                    sb.AppendLine($"Exception message: {exception.Message}");
                }

                if (Services.Data.CurrentUserLevel < UserLevel.Advanced)
                {
                    return(sb.ToString());
                }

                sb.AppendLine();
                sb.AppendLine($"Exception level: {exceptionLevel}");

                return(sb.ToString());
            }
        }
 /// <summary>
 /// Passes the exception to listener.
 /// </summary>
 /// <param name="level">Exception level.</param>
 /// <param name="type">Exception type.</param>
 protected void PassExceptionToListener(ExceptionLevel level, ExceptionType type) {
     var handler = this.ShowException;
     if (handler != null) {
         handler(this, new RepositoryExceptionEventArgs(level, type));
     }
 }
Exemplo n.º 34
0
 internal GhostAPI(string host, string key, ExceptionLevel exceptionLevel, string baseUrl, APIType apiType)
     : this(host, exceptionLevel, baseUrl, apiType)
 {
     this.key = key;
 }
Exemplo n.º 35
0
		public RoutedException(string message, ExceptionLevel level, object target)
			: base(message, level)
		{
			Target = target;
		}
Exemplo n.º 36
0
        public void DeletePage_ReturnsFalse_WhenPageIdInvalid(ExceptionLevel exceptionLevel)
        {
            auth.ExceptionLevel = exceptionLevel;

            Assert.IsFalse(auth.DeletePage(InvalidPageId));
        }
Exemplo n.º 37
0
 public KMJXCException(string message, ExceptionLevel level)
     : base(message)
 {
     this.Level = level;
 }
Exemplo n.º 38
0
		public SoheilExceptionBase(string message, ExceptionLevel level, string caption = "")
			: base(message)
		{
			Level = level;
			_captionInfo = caption;
		}
Exemplo n.º 39
0
 public GameException(string message,ExceptionLevel level)
     : base(message)
 {
     this.Level = level;
 }
Exemplo n.º 40
0
 public KarrStyleException(string userFriendlyMessage, string message, System.Exception innerException, ExceptionLevel level)
     : base(message, innerException)
 {
     Level = level;
     UserFriendlyMessage = userFriendlyMessage;
 }
Exemplo n.º 41
0
        public void GetPosts_ReturnsNull_WhenKeyIsInvalid_AndGhostExceptionsSuppressed(ExceptionLevel exceptionLevel)
        {
            var auth = new GhostContentAPI(Host, InvalidApiKey)
            {
                ExceptionLevel = exceptionLevel
            };

            Assert.IsNull(auth.GetPosts());
            Assert.IsNotNull(auth.LastException);
        }
 public void RecordException(Exception exception, ExceptionLevel exceptionLevel = ExceptionLevel.Error, IDictionary metadata = null) =>
     Insights.Report(exception, metadata, exceptionLevel.ToSeverity());
Exemplo n.º 43
0
        public void GetPostBySlug_ReturnsNull_WhenKeyIsInvalid_AndGhostExceptionsSuppressed(ExceptionLevel exceptionLevel)
        {
            auth.ExceptionLevel = exceptionLevel;

            Assert.IsNull(auth.GetPostBySlug(InvalidPostSlug));
        }
Exemplo n.º 44
0
 /// <summary>
 ///    Handles exceptions
 /// </summary>
 /// <param name="message">
 ///    The error message to display to the user or add to the log.
 /// </param>
 /// <param name="eLevel">
 ///    The severity of the error, a <see cref="ExeptionLevel"/> value. Deafult is <see cref="ExceptionLevel.Notice"/>.
 /// </param>
 /// <param name="exception">
 ///    The <see cref="Exception"/> object returned by the runtime or usercode.
 /// </param>
 /// <seealso cref="ExeptionLevel"/>
 public static void TriggerException(String message, ExceptionLevel eLevel = ExceptionLevel.Notice, Exception exception = null)
 {
     //MessageBox.Show(message+"\r\n"+eLevel.ToString());      obsolete
     //include logging instead
 }