Ejemplo n.º 1
0
 public void SetNotification(LazyNotification notification)
 {
     if (isDisposed)
     {
         return;
     }
     if (DependsOn != null && Array.IndexOf(DependsOn, notification.NotifyType) < 0)
     {
         throw new ArgumentException("The notification does not match this waitblock");
     }
     this.notification = notification;
     notificationWaiter.Set();
 }
Ejemplo n.º 2
0
 public void SetNotification(LazyNotification notification)
 {
     if (isDisposed)
     {
         return;
     }
     if (notificationWaiterAsync is null || DependsOn is null)
     {
         throw new InvalidOperationException(NotANotifyBlock);
     }
     if (Array.IndexOf(DependsOn, notification.NotifyType) < 0)
     {
         throw new ArgumentException(NotifyDoesNotMatch);
     }
     notificationWaiterAsync.SetResult(notification);
 }
Ejemplo n.º 3
0
 public void Invoke(LazyNotification lazyNotification)
 {
     eventQueue.Enqueue(lazyNotification);
     eventBlock.Set();
 }
Ejemplo n.º 4
0
 public void Invoke(LazyNotification lazyNotification) => ThreadPool.QueueUserWorkItem(Call, lazyNotification);
Ejemplo n.º 5
0
 public void Invoke(LazyNotification lazyNotification)
 {
 }
Ejemplo n.º 6
0
        public LazyNotification?PushMessage(ReadOnlyMemory <byte> message)
        {
            var    msgSpan = message.Span;
            string notifyname;
            int    splitindex = msgSpan.IndexOf(AsciiSpace);

            if (splitindex < 0)
            {
                notifyname = msgSpan.TrimEnd(AsciiSpace).NewUtf8String();
            }
            else
            {
                notifyname = msgSpan.Slice(0, splitindex).NewUtf8String();
            }

            bool             hasEqual = notifyname.IndexOf('=') >= 0;
            NotificationType ntfyType;

            if (hasEqual || (ntfyType = findTypeOfNotification(notifyname)) == NotificationType.Unknown)
            {
                if (!hasEqual)
                {
                    Log.Debug("Maybe unknown notification: {0}", notifyname);
                }
                cmdLineBuffer = message;
                return(null);
            }

            var lineDataPart = splitindex < 0 ? ReadOnlySpan <byte> .Empty : msgSpan.Slice(splitindex);

            // if it's not an error it is a notification
            if (ntfyType != NotificationType.CommandError)
            {
                var notification = Deserializer.GenerateNotification(lineDataPart, ntfyType);
                if (notification is null)
                {
                    Log.Warn("Got unparsable message. ({0})", msgSpan.NewUtf8String());
                    return(null);
                }

                var lazyNotification = new LazyNotification(notification, ntfyType);
                var dependantList    = dependingBlocks[(int)ntfyType];
                if (dependantList != null)
                {
                    foreach (var item in dependantList)
                    {
                        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 result      = Deserializer.GenerateSingleNotification(lineDataPart, NotificationType.CommandError);
            var errorStatus = result is null?CommandError.Custom("Invalid Error code") : (CommandError)result;

            return(PushMessageInternal(errorStatus, ntfyType));
        }