Exemplo n.º 1
0
        public LazyNotification?PushMessage(string message)
        {
            string notifyname;
            int    splitindex = message.IndexOf(' ');

            if (splitindex < 0)
            {
                notifyname = message.TrimEnd();
            }
            else
            {
                notifyname = message.Substring(0, splitindex);
            }

            var ntfyType = MessageHelper.GetNotificationType(notifyname);

            if (ntfyType == NotificationType.Unknown)
            {
                cmdLineBuffer = message;
                return(null);
            }

            var lineDataPart = splitindex < 0 ? "" : message.Substring(splitindex);

            // if it's not an error it is a notification
            if (ntfyType != NotificationType.Error)
            {
                var notification     = CommandDeserializer.GenerateNotification(lineDataPart, ntfyType);
                var lazyNotification = new LazyNotification(notification, ntfyType);
                if (dependingBlocks[(int)ntfyType] != null)
                {
                    foreach (var item in dependingBlocks[(int)ntfyType])
                    {
                        if (!item.Closed)
                        {
                            item.SetNotification(lazyNotification);
                        }
                    }
                    dependingBlocks[(int)ntfyType].Clear();
                }

                return(lazyNotification);
            }

            var errorStatus = (CommandError)CommandDeserializer.GenerateSingleNotification(lineDataPart, NotificationType.Error);

            if (synchronQueue)
            {
                if (requestQueue.Count > 0)
                {
                    var waitBlock = requestQueue.Dequeue();
                    waitBlock.SetAnswer(errorStatus, cmdLineBuffer);
                    cmdLineBuffer = null;
                }
                else /* ??? */ } {
        }
Exemplo n.º 2
0
        public LazyNotification?PushMessage(string message)
        {
            string notifyname;
            int    splitindex = message.IndexOf(' ');

            if (splitindex < 0)
            {
                notifyname = message.TrimEnd();
            }
            else
            {
                notifyname = message.Substring(0, splitindex);
            }

            var ntfyType = MessageHelper.GetNotificationType(notifyname);

            if (ntfyType == NotificationType.Unknown)
            {
                cmdLineBuffer = message;
                return(null);
            }

            var lineDataPart = splitindex < 0 ? "" : message.Substring(splitindex);

            // if it's not an error it is a notification
            if (ntfyType != NotificationType.Error)
            {
                var notification     = CommandDeserializer.GenerateNotification(lineDataPart, ntfyType);
                var lazyNotification = new LazyNotification(notification, ntfyType);
                var dependantList    = dependingBlocks[(int)ntfyType];
                if (dependantList != null)
                {
                    lock (dependantBlockLock)
                    {
                        foreach (var item in dependantList)
                        {
                            if (!item.Closed)
                            {
                                item.SetNotification(lazyNotification);
                            }
                            if (item.DependsOn != null)
                            {
                                foreach (var otherDepType in item.DependsOn)
                                {
                                    if (otherDepType == ntfyType)
                                    {
                                        continue;
                                    }
                                    dependingBlocks[(int)otherDepType]?.Remove(item);
                                }
                            }
                        }
                        dependantList.Clear();
                    }
                }

                return(lazyNotification);
            }

            var errorStatus = (CommandError)CommandDeserializer.GenerateSingleNotification(lineDataPart, NotificationType.Error);

            if (synchronQueue)
            {
                WaitBlock waitBlock;
                if (!requestQueue.IsEmpty && requestQueue.TryDequeue(out waitBlock))
                {
                    waitBlock.SetAnswer(errorStatus, cmdLineBuffer);
                    cmdLineBuffer = null;
                }
                else /* ??? */ } {
        }