Пример #1
0
            public override void Check()
            {
                if (OnEvent != null)
                {
                    var CallbackList = OnEvent.GetInvocationList();

                    foreach (var Callback in CallbackList)
                    {
                        LLogger.LWarning($"{Callback.Method.ReflectedType.Name} : {Callback.Method.Name} UnRegister");
                    }
                }
            }
        public void UnSubscribeAll()
        {
            if (OnEvent != null)
            {
                //Debug.Log($"{eventName} unsubscribing.");
                Delegate[] clients = OnEvent.GetInvocationList();

                foreach (Delegate d in clients)
                {
                    OnEvent -= (evenHandler)d;
                }
            }
        }
Пример #3
0
    /// <summary> Sequentially peform events in prioritized order. </summary>
    public IEnumerator Raise()
    {
        /* If There Are NO Subscribers To This Event, Return Immedietly */
        if (OnEvent == null)
        {
            yield break;
        }

        /* Call Each Routine In Invocation List One At A Time */
        Delegate[] routines = OnEvent.GetInvocationList();
        foreach (Delegate routine in routines)
        {
            yield return(routine.DynamicInvoke());
        }
    }
Пример #4
0
        public static void Listen(string v)
        {
            RedisChannel webhookChannel = new RedisChannel(v, RedisChannel.PatternMode.Auto);

            jsonRedisClient.SubscribeAsync <WebhookResponse>(webhookChannel, async(value) =>
            {
                if (OnEvent.GetInvocationList().Length > 0)
                {
                    try
                    {
                        await OnEvent(value);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            });
        }
Пример #5
0
    public void Suscribe(OnEventDel del)
    {
        bool found = false;

        if (OnEvent != null)
        {
            foreach (Delegate d in OnEvent.GetInvocationList())
            {
                if ((OnEventDel)d == del)
                {
                    found = true;
                    break;
                }
            }
        }

        if (!found)
        {
            OnEvent += del;
        }
    }
Пример #6
0
        public static void Listen(string v)
        {
            ConnectionFactory factory = new ConnectionFactory();

            factory.Uri = Global.Config.RabbitUrl;

            connection = factory.CreateConnection();
            channel    = connection.CreateModel();
            channel.ExchangeDeclare("miki", ExchangeType.Direct, true);
            channel.QueueDeclare(v, true, false, false, null);
            channel.QueueBind(v, "miki", "*", null);

            var consumer = new EventingBasicConsumer(channel);

            consumer.Received += async(ch, ea) =>
            {
                WebhookResponse resp = null;
                try
                {
                    string payload = Encoding.UTF8.GetString(ea.Body);
                    resp = JsonConvert.DeserializeObject <WebhookResponse>(payload);
                }
                catch (Exception e)
                {
                    Log.Error(e);
                    channel.BasicReject(ea.DeliveryTag, false);
                    return;
                }

                if (OnEvent.GetInvocationList().Length > 0)
                {
                    try
                    {
                        await OnEvent(resp);

                        channel.BasicAck(ea.DeliveryTag, false);
                    }
                    catch (RabbitException e)
                    {
                        var prop = channel.CreateBasicProperties();
                        prop.Headers = new Dictionary <string, object>();

                        if (ea.BasicProperties.Headers.TryGetValue("x-retry-count", out object value))
                        {
                            int rCount = int.Parse(value.ToString() ?? "0") + 1;

                            prop.Headers.Add("x-retry-count", rCount);

                            if (rCount > 10)
                            {
                                return;
                            }
                        }
                        else
                        {
                            prop.Headers.Add("x-retry-count", 1);
                        }
                        channel.BasicPublish("miki", "*", false, prop, ea.Body);
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                        channel.BasicAck(ea.DeliveryTag, false);
                    }
                }
            };
            string consumerTag = channel.BasicConsume("", false, consumer);
        }