Beispiel #1
0
        public void Send(SlackSocketMessage message)
        {
            if (message.id == 0)
            {
                message.id = Interlocked.Increment(ref currentId);
            }
            //socket.Send(JsonConvert.SerializeObject(message));

            if (message.type == null)
            {
                IEnumerable <SlackSocketRouting> routes = message.GetType().GetCustomAttributes <SlackSocketRouting>();

                SlackSocketRouting route = null;
                foreach (SlackSocketRouting r in routes)
                {
                    route = r;
                }
                if (route == null)
                {
                    throw new InvalidProgramException("Cannot send without a proper route!");
                }
                else
                {
                    message.type    = route.Type;
                    message.subtype = route.SubType;
                }
            }

            sendingQueue.Push(JsonConvert.SerializeObject(message));
            if (Interlocked.CompareExchange(ref currentlySending, 1, 0) == 0)
            {
                ThreadPool.QueueUserWorkItem(HandleSending);
            }
        }
Beispiel #2
0
        public void Send(SlackSocketMessage message)
        {
            if (message.id == 0)
            {
                message.id = Interlocked.Increment(ref currentId);
            }
            //socket.Send(JsonConvert.SerializeObject(message));

            if (string.IsNullOrEmpty(message.type))
            {
                IEnumerable <SlackSocketRouting> routes = message.GetType().GetTypeInfo().GetCustomAttributes <SlackSocketRouting>();

                SlackSocketRouting route = null;
                foreach (SlackSocketRouting r in routes)
                {
                    route = r;
                }
                if (route == null)
                {
                    throw new InvalidProgramException("Cannot send without a proper route!");
                }
                else
                {
                    message.type    = route.Type;
                    message.subtype = route.SubType;
                }
            }

            sendingQueue.Push(JsonConvert.SerializeObject(message, Formatting.None, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));
            if (Interlocked.CompareExchange(ref currentlySending, 1, 0) == 0)
            {
                Task.Factory.StartNew(HandleSending);
            }
        }