Exemple #1
0
        public static void Compact()
        {
            Assert.True(
                string.Equals(
                    "Member, File.cs:5",
                    FileLine.Compact(
                        "File.cs",
                        "Member",
                        5),
                    StringComparison.OrdinalIgnoreCase));

            Assert.True(
                string.Equals(
                    "Member, File.cs:5",
                    FileLine.Compact(
                        @"c:\dir1\dir2\File.cs",
                        "Member",
                        5),
                    StringComparison.OrdinalIgnoreCase));

            Assert.True(
                string.Equals(
                    "Member, File.cs:5",
                    FileLine.Compact(
                        @"/mnt/sdcard/File.cs",
                        "Member",
                        5),
                    StringComparison.OrdinalIgnoreCase));
        }
Exemple #2
0
        /// <summary>
        /// Invoked before the event is added to the <see cref="IEventQueueStorage"/>.
        /// Can optionally cancel the the adding.
        /// </summary>
        /// <param name="evnt">The event about to be added to the queue.</param>
        /// <param name="file">The source file of the caller.</param>
        /// <param name="member">The method or property name of the caller to this method.</param>
        /// <param name="line">The line number in <paramref name="file"/>.</param>
        /// <param name="canAdd">Determines whether the event can be added to the queue.</param>
        protected virtual void BeforeAdding(
            EventBase evnt,
            string file,
            string member,
            int line,
            out bool canAdd)
        {
            if (evnt.NullReference())
            {
                throw Exc.Null(nameof(evnt));
            }

            lock (this.syncLock)
            {
                // already enqueued?
                if (this.Storage.Contains(evnt))
                {
                    canAdd = false;
                    return;
                }

                // shutdown request event?
                if (evnt is ShutdownRequestEvent)
                {
                    if (this.shutdownRequestEnqueued || // another request is already enqueued or being handled
                        (this.eventsState >= State.ShuttingDownEnqueued))  // we are already shutting down, there is no question about it
                    {
                        canAdd = false;
                        return;
                    }
                    else
                    {
                        this.shutdownRequestEnqueued = true;
                    }
                }
                else if (evnt is ShuttingDownEvent)  // shutting down event?
                {
                    if (this.eventsState >= State.ShuttingDownEnqueued)
                    {
                        // another shutting down event already enqueued
                        canAdd = false;
                        return;
                    }
                    else
                    {
                        this.eventsState = State.ShuttingDownEnqueued;
                    }
                }

                evnt.EventEnqueuePos = FileLine.Compact(file, member, line);
                canAdd = true;
            }
        }
Exemple #3
0
        /// <summary>
        /// Stores the current source file position (using the "PartialStackTrace" key).
        /// </summary>
        /// <typeparam name="TException">The type of the exception.</typeparam>
        /// <param name="e">The exception to store data in.</param>
        /// <param name="file">The source file that contains the caller.</param>
        /// <param name="member">The method or property name of the caller to this method.</param>
        /// <param name="line">The line number in the source file at which this method is called.</param>
        /// <returns>The exception the data was stored in.</returns>
        public static TException StoreFileLine <TException>(
            this TException e,
            [CallerFilePath] string file     = "",
            [CallerMemberName] string member = "",
            [CallerLineNumber] int line      = 0)
            where TException : Exception
        {
            const string key      = "PartialStackTrace";
            string       newValue = FileLine.Compact(file, member, line);

            if (TryGetValue(e, key, out var oldValue))
            {
                if (!oldValue.NullOrEmpty())
                {
                    newValue = newValue + "\r\n" + oldValue;
                }
            }
            AddOrSet(e, key, newValue);
            return(e);
        }