TraceErrorException() private method

private TraceErrorException ( Exception ex, string message = null, bool reportIt = true, [ filePath = "", [ lineNumber, [ method = "" ) : void
ex System.Exception
message string
reportIt bool
filePath [
lineNumber [
method [
return void
Beispiel #1
0
        //------------------------------------------------------------------------------------------------------------------------
        #endregion


        #region Functions
        //------------------------------------------------------------------------------------------------------------------------
        void callbackLanding(RequestInfo req)
        {
            // check if the request is canceled
            if (req.IsCanceled)
            {
                return;
            }

            // check if the Event is infinitely repeatable
            if (req.IsInfinitelyRepeatable)
            {
                SleepRequests.Enqueue(callbackLanding, req, req.Interval);
            }

            else
            {
                // resubmit timer if count > 0
                req.Count--;
                if (req.Count > 0)
                {
                    SleepRequests.Enqueue(callbackLanding, req, req.Interval);
                }
            }

            //tick handler
            Task.Run(() =>
            {
                try
                {
                    req.Callback(req.UserData);
                }
                catch (Exception ex) { DebugEx.TraceErrorException(ex); }
            });
        }
Beispiel #2
0
        //------------------------------------------------------------------------------------------------------------------------
        public virtual Trsp SendRequest <Trsp>(T wrapper_msg, object request, TimeSpan?timeout = null, bool auto_json = false)
        {
            //null check
            if (wrapper_msg == null)
            {
                DebugEx.Assert("Null wrapper detected");
                return(default(Trsp));
            }

            try
            {
                //create synchronization id
                var syncId = GetNewSyncId();

                //create waiter
                var w = new RpcWaiter();
                lock (RpcPending)
                    RpcPending.Add(syncId, w);

                //create wrapper message
                try
                {
                    wrapper_msg.IsRequest = true;
                    wrapper_msg.SyncId    = syncId;
                    wrapper_msg.Payload   = request?.ToJSON();
                }
                catch (Exception ex)
                {
                    DebugEx.Assert(ex, "msg wrapper create failed");
                    return(default(Trsp));
                }


                //Send request and wait for response
                bool failed = false;
                lock (w)
                {
                    DebugEx.TraceLog("MsgSync: sending " + request?.GetType() + ", syncid: " + wrapper_msg.SyncId);
                    PublishFunc?.Invoke(wrapper_msg, request);
                    //wait for response
#if DEBUG
                    Monitor.Wait(w);
#else
                    if (timeout.HasValue)
                    {
                        if (timeout.Value == TimeSpan.Zero)
                        {
                            Monitor.Wait(w); //if explicitly zero timespan, wait forever
                        }
                        else
                        {
                            Monitor.Wait(w, timeout.Value);
                        }
                    }
                    else
                    {
                        //if no value given, wait for default msec
                        Monitor.Wait(w, DefaultRPCTimeout);
                    }
#endif
                    if (w.Response == null)
                    {
                        failed = true;
                    }
                }
                if (failed)
                {
                    lock (RpcPending)
                        RpcPending.Remove(syncId); //remove if failed to receive within time limit
                }
                //give response back
                if (w.Response != null)
                {
                    if (w.Response is string && auto_json)
                    {
                        var rsp_str = w.Response as string;
                        if ((rsp_str.StartsWith("{") && rsp_str.EndsWith("}")) ||
                            (rsp_str.StartsWith("[") && rsp_str.EndsWith("]")))
                        {
                            return((Trsp)rsp_str.FromJSON(type: typeof(Trsp)));
                        }
                    }
                    else
                    {
                        return((Trsp)w.Response);
                    }
                }
                return(default(Trsp));
            }
            catch (Exception ex)
            {
                DebugEx.TraceErrorException(ex);
                return(default(Trsp));
            }
        }
Beispiel #3
0
        //--------------------------------------------------------------------------------------------------------------------------------------
        private void _ExecuteHandler <T>(object sender, T ev, object priv, bool forceAsync)
        {
            //declares
            SortedSetTS <EvHandler> allRoutesForType = null;
            var evType = typeof(T);

            //null check
            if (ev == null)
            {
                return;
            }

            //create event info
            var evInfo = new EvInfo()
            {
                Priv           = priv,
                IsDerivedMatch = false,
            };

            //Execute
            var executedCallbacks = new HashSet <object>();

            while (evType != null && evType != typeof(object))
            {
                //get routes for type
                allRoutesForType = _ActiveRoutes.TryGetOrDefault(evType);
                if (allRoutesForType != null)
                {
                    //Broadcast event
                    foreach (var evhandle in allRoutesForType)
                    {
                        if (!evInfo.IsDerivedMatch || evhandle.ReceiveDerivedTypeEvents)
                        {
                            try
                            {
                                //check that we haven't already run this callback
                                if (!executedCallbacks.Contains(evhandle.Cb))
                                {
                                    //run synchronously or asynchronously?
                                    if (evhandle.RunAsync)
                                    {
                                        //proper async mode; callbacks will be executed in series
                                        EventQueue.Enqueue(new EventDescriptor()
                                        {
                                            Ev = ev, EvHandle = evhandle, EvInfo = evInfo, Sender = sender
                                        });
                                    }
                                    else if (forceAsync)
                                    {
                                        //caller did TriggerEventAsync() and callback expects strong type
                                        TaskEx.RunSafe(() => __exec(sender, ev, evInfo, evhandle));
                                    }
                                    else
                                    {
                                        __exec(sender, ev, evInfo, evhandle);
                                    }
                                    //add to hashset so that it's not executed again
                                    executedCallbacks.Add(evhandle.Cb);
                                }
                            }
                            catch (Exception ex)
                            {
                                DebugEx.TraceErrorException(ex);
                            }
                        }
                    }
                }

                //now moving up the inheritance tree (toward object)
#if NETFX
                evType = evType.BaseType;
#elif UNIVERSAL
                evType = evType.GetTypeInfo().BaseType;
#endif
                evInfo.IsDerivedMatch = true;
            }
        }
Beispiel #4
0
        //--------------------------------------------------------------------------------------------------------------------------------------
        private void _ExecuteHandler <T>(object sender, T ev)
        {
            //declares
            SortedSetTS <EvHandler> allRoutesForType = null;
            var evType = typeof(T);

            //null check
            if (ev == null)
            {
                return;
            }

            //create event info
            var evInfo = new EvInfo()
            {
                priv           = null,
                IsDerivedMatch = false,
            };

            //Execute
            var executedCallbacks = new HashSet <object>();

            while (evType != null && evType != typeof(object))
            {
                //get routes for type
                allRoutesForType = _ActiveRoutes.TryGetOrDefault(evType);
                if (allRoutesForType != null)
                {
                    //Broadcast event
                    foreach (var evhandle in allRoutesForType)
                    {
                        if (!evInfo.IsDerivedMatch || evhandle.ReceiveDerivedTypeEvents)
                        {
                            try
                            {
                                //check that we haven't already run this callback
                                if (!executedCallbacks.Contains(evhandle.Cb))
                                {
                                    //use Dynamic callback if derived type; use known type otherwise
                                    if (evInfo.IsDerivedMatch)
                                    {
                                        ((dynamic)evhandle.Cb)(sender, evInfo, ev);
                                    }
                                    else
                                    {
                                        ((EventCb <T>)evhandle.Cb)(sender, evInfo, ev);
                                    }

                                    //add to hashset so that it's not executed again
                                    executedCallbacks.Add(evhandle.Cb);
                                }
                            }
                            catch (Exception ex)
                            {
                                DebugEx.TraceErrorException(ex);
                            }
                        }
                    }
                }

                //now moving up the inheritance tree (toward object)
#if NETFX
                evType = evType.BaseType;
#elif UNIVERSAL
                evType = evType.GetTypeInfo().BaseType;
#endif
                evInfo.IsDerivedMatch = true;
            }
        }