TraceError() 개인적인 메소드

private TraceError ( Exception ex, string message, bool reportIt = true, [ filePath = "", [ lineNumber, [ method = "" ) : void
ex System.Exception
message string
reportIt bool
filePath [
lineNumber [
method [
리턴 void
예제 #1
0
파일: TypeCache.cs 프로젝트: sm6uax/plegma
        //------------------------------------------------------------------------------------------------------------------------
        #endregion


        #region Constructors
        //------------------------------------------------------------------------------------------------------------------------
        static TypeCache()
        {
#if NETFX
            //add entry assembly
            var EntryAssembly = Assembly.GetEntryAssembly();
            if (EntryAssembly != null)
            {
                EntryAssemblies.Add(EntryAssembly);
            }

            //Add as many assemblies as we can
            //add from stack
            try
            {
                var frameAssemblies = new System.Diagnostics.StackTrace().GetFrames().Select(t => t.GetMethod().Module.Assembly).ToHashSet();
                foreach (var entry in frameAssemblies)
                {
                    EntryAssemblies.Add(entry);
                }
            }
            catch (Exception ex) { DebugEx.TraceError(ex, "Unhandled exception during Stack Frame assembly examination"); }

            //add from domain
            try
            {
                EntryAssemblies.AddFromSource(AppDomain.CurrentDomain.GetAssemblies());
            }
            catch (Exception ex) { DebugEx.TraceError(ex, "Unhandled exception during AppDomain assembly examination"); }
#elif UNIVERSAL
            EntryAssemblies.Add(Windows.UI.Xaml.Application.Current.GetType().GetTypeInfo().Assembly);
#endif
        }
예제 #2
0
        //------------------------------------------------------------------------------------------------------------------------
        public void Dispose()
        {
            if (_IsDisposed)
            {
                return;
            }

            //dispose
            try
            {
                lock (locker)
                {
                    if (_IsDisposed)
                    {
                        return;
                    }
                    else
                    {
                        _IsDisposed = true;
                    }

                    //stop it
                    if (isRunning)
                    {
                        Stop();
                    }
                }
            }
            catch (Exception ex) { DebugEx.TraceError(ex, "FutureCallbackQueue dispose failed"); }
        }
예제 #3
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     if (disposing && !LeaveOpen)
     {
         GC.SuppressFinalize(this);
         try
         {
             BaseStream.Dispose();
         }
         catch (Exception ex) { DebugEx.TraceError(ex, "Exception while closing underlying stream", reportIt: false); }
     }
 }
예제 #4
0
        //------------------------------------------------------------------------------------------------------------------------
#if NETFX
        public override void Close()
        {
            base.Close();
            if (!LeaveOpen)
            {
                try
                {
                    BaseStream.Close();
                    BaseStream.Dispose();
                }
                catch (Exception ex) { DebugEx.TraceError(ex, "Exception while closing underlying stream", reportIt: false); }
            }
        }
예제 #5
0
        //------------------------------------------------------------------------------------------------------------------------
        public virtual bool SendResponse(T wrapper_msg, object response, int syncId)
        {
            if (wrapper_msg == null || response == null)
            {
                return(false);
            }
            try
            {
                wrapper_msg.IsResponse = true;
                wrapper_msg.SyncId     = syncId;
                wrapper_msg.Payload    = response.ToJSON();

                return(PublishFunc?.Invoke(wrapper_msg, response) == true);
            }
            catch (Exception ex)
            {
                DebugEx.TraceError(ex, "Could not send MsgSync response message");
                return(false);
            }
        }
예제 #6
0
        //------------------------------------------------------------------------------------------------------------------------
        public void Stop()
        {
            try
            {
#if UNIVERSAL
                Task _heartbeat = null;
#else
                Thread _heartbeat = null;
#endif
                lock (RequestQueue)
                {
                    if (!_IsAlive)
                    {
                        return;
                    }

                    _IsAlive = false;
                    RequestQueue.Clear();
                    Monitor.Pulse(RequestQueue);

                    //wait for heartbeat stop
                    _heartbeat = heartbeat;
                    heartbeat  = null;
                }
                try
                {
                    //wait for finish
                    if (_heartbeat != null)
                    {
#if UNIVERSAL
                        _heartbeat.Wait(5000);
#else
                        _heartbeat.Join(5000);
#endif
                    }
                }
                catch { }
            }
            catch (Exception ex) { DebugEx.TraceError(ex, "Unhandled exception in RQC Stop()"); }
        }
예제 #7
0
        //------------------------------------------------------------------------------------------------------------------------
        public bool OnMessageReceived(T wrapper_msg, object payload)
        {
            //check if this is a response, in which case unblock pending request
            if (wrapper_msg.IsResponse)
            {
                int syncId = wrapper_msg.SyncId;

                DebugEx.Assert(syncId != 0, "IsResponse flag without valid syncId not allowed");
                if (syncId == 0)
                {
                    return(false);
                }

                DebugEx.TraceLog("MsgSync: got " + payload.GetType() + ", syncid: " + wrapper_msg.SyncId);

                //find waiter
                RpcWaiter w = null;
                lock (RpcPending)
                    if (RpcPending.TryGetValue(syncId, out w))
                    {
                        RpcPending.Remove(syncId);
                    }                              //remove if found

                //set result and wake
                if (w != null)
                {
                    lock (w)
                    {
                        w.Response = payload;
                        Monitor.Pulse(w);
                        return(true);
                    }
                }
                else
                {
                    DebugEx.TraceError("Could not find MsgSync waiter from " + payload.GetType() + " with syncId=" + syncId);
                }
            }
            return(false);
        }
예제 #8
0
        //------------------------------------------------------------------------------------------------------------------------
        #endregion


        #region Functions
        //------------------------------------------------------------------------------------------------------------------------
        void HeartBeatEntryPoint()
        {
            try
            {
                //declares
                TimeSpan?timeout = null;
                //spin
                while (isRunning)
                {
                    lock (locker)
                    {
                        //check pending requests.. if none the sleep the good sleep
                        if (RequestQueue.Count == 0)
                        {
                            timeout = TimeSpan.MaxValue; //infinite
                        }
                        else
                        {
                            //get first pending request (has smallest wake timestamp)
                            var req = RequestQueue.First();
                            //get remaining time
                            var rem = req.WakeupTimestamp - DateTime.UtcNow;
                            if (rem.TotalMilliseconds > 0.5d)
                            {
                                timeout = rem;
                            }
                            else
                            {
                                //consume event
                                RequestQueue.Dequeue();
                                RequestLookup.Remove(req.RequestID);
                                //callback
                                if (req.AsyncCallback)
                                {
                                    Task.Run(() =>
                                    {
                                        try
                                        {
                                            //fire event
                                            if (req.Callback != null)
                                            {
                                                req.Callback(req.UserData);
                                            }
                                            else if (req.WeakCallback != null)
                                            {
                                                req.WeakCallback.Invoke(req.UserData);
                                            }
                                            else
                                            {
                                                DebugEx.Assert("FutureCallbackQueue reqId:" + req.RequestID + " has no callback to invoke");
                                            }
                                        }
                                        catch (Exception ex) { DebugEx.Assert(ex, "Unhandled exception in callback caught by FutureCallbackQueue"); }
                                    });
                                }
                                else
                                {
                                    //exit lock to fire event
                                    Monitor.Exit(locker);
                                    try
                                    {
                                        //fire event
                                        if (req.Callback != null)
                                        {
                                            req.Callback(req.UserData);
                                        }
                                        else if (req.WeakCallback != null)
                                        {
                                            req.WeakCallback.Invoke(req.UserData);
                                        }
                                        else
                                        {
                                            DebugEx.Assert("FutureCallbackQueue reqId:" + req.RequestID + " has no callback to invoke");
                                        }
                                    }
                                    catch (Exception ex) { DebugEx.Assert(ex, "Unhandled exception in callback caught by FutureCallbackQueue"); }
                                    finally { Monitor.Enter(locker); }
                                }
                                //no timeout..keep spinning
                                timeout = null;
                            }
                        }

                        //sleep/wait manager
                        if (timeout.HasValue)
                        {
                            int _clampedTimeout = (int)timeout.Value.TotalMilliseconds.ClampCeil(MaxSleepMilisecondsD);
                            Monitor.Wait(locker, _clampedTimeout);
                            if (!isRunning)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { DebugEx.TraceError(ex, "FutureCallbackQueue heartbeat failed"); }
        }