Exemplo n.º 1
0
        private void OnGetChannelMetadataCore(object sender, MapRequestEventArgs <v12.Protocol.ChannelSubscribe.GetChannelMetadata, v12.Datatypes.ChannelData.ChannelMetadataRecord> args)
        {
            var handler   = (v12.Protocol.ChannelSubscribe.IChannelSubscribeStore)sender;
            var sessionId = GetSessionId(handler);

            if (!Store.HasChannelSubscription(sessionId))
            {
                var callbacks = CreateChannelStreamingCallbacks(handler);
                if (!Store.StartChannelSubscription(EtpVersion.v12, sessionId, int.MaxValue, TimeSpan.FromSeconds(0), false, callbacks))
                {
                    args.FinalError = handler.ErrorInfo().RequestDenied();
                }
            }

            foreach (var kvp in args.Request.Body.Uris)                                                // Register metadata subscriptions
            {
                var subscriptionInfo = new MockSubscriptionInfo(kvp.Value, handler.Session.SessionId); // Use the actual sesison ID as a namespace.
                if (Store.HasChannelSubscriptionScope(sessionId, subscriptionInfo))
                {
                    continue;
                }

                IList <MockObject> addedChannels;
                if (Store.AddChannelSubscriptionChannelScope(sessionId, subscriptionInfo, out addedChannels) && addedChannels.Count == 1)
                {
                    args.ResponseMap[kvp.Key] = ((MockChannel)addedChannels[0]).ChannelMetadataRecord12(Store.GetChannelId(sessionId, addedChannels[0]));
                }
                else
                {
                    args.ErrorMap[subscriptionInfo.RequestUuid.ToString()] = handler.ErrorInfo().RequestDenied($"URI: {kvp.Value}");
                }
            }
        }
Exemplo n.º 2
0
        public bool AddChannelSubscriptionChannelScope(Guid sessionId, MockSubscriptionInfo channelScope, out IList <MockObject> addedChannels)
        {
            addedChannels = new List <MockObject>();

            CheckLocked();

            ChannelSubscription channelSubscription;

            if (!ChannelSubscriptionsBySessionId.TryGetValue(sessionId, out channelSubscription))
            {
                return(false);
            }

            var channelScopeUuid = channelScope.RequestUuid;

            if (channelSubscription.ChannelScopesByChannelScopeUuid.ContainsKey(channelScopeUuid))
            {
                return(false);
            }

            channelSubscription.ChannelScopesByChannelScopeUuid[channelScopeUuid] = channelScope;

            RefreshChannelSubscription(channelSubscription);

            foreach (var channel in channelSubscription.Objects.Values)
            {
                addedChannels.Add(channel);
            }

            return(true);
        }
Exemplo n.º 3
0
        public bool HasChannelSubscriptionScope(Guid sessionId, MockSubscriptionInfo channelScope)
        {
            CheckLocked();

            ChannelSubscription channelSubscription;

            if (!ChannelSubscriptionsBySessionId.TryGetValue(sessionId, out channelSubscription))
            {
                return(false);
            }

            return(channelSubscription.ChannelScopesByChannelScopeUuid.ContainsKey(channelScope.RequestUuid));
        }
Exemplo n.º 4
0
        private void OnNotificationRequestCore(object sender, VoidRequestEventArgs <v11.Protocol.StoreNotification.NotificationRequest> args)
        {
            var handler = (v11.Protocol.StoreNotification.IStoreNotificationStore)sender;

            var request          = args.Request.Body.Request;
            var subscriptionInfo = new MockSubscriptionInfo(request);
            var callbacks        = CreateStoreNotificationCallbacks(handler);

            var startTime = request.StartTime;

            if (!Store.SubscribeObjectNotifications(EtpVersion.v11, startTime < Store.StoreLastWrite, startTime, false, handler.Session.SessionId, subscriptionInfo, callbacks))
            {
                args.FinalError = handler.ErrorInfo().RequestUuidRejected(args.Request.Body.Request);
            }
        }
Exemplo n.º 5
0
        private void OnSubscribeNotificationsCore(object sender, MapRequestEventArgs <v12.Protocol.StoreNotification.SubscribeNotifications, string> args)
        {
            var handler = (v12.Protocol.StoreNotification.IStoreNotificationStore)sender;

            foreach (var kvp in args.Request.Body.Request)
            {
                var callbacks        = CreateStoreNotificationCallbacks(handler);
                var subscriptionInfo = new MockSubscriptionInfo(kvp.Value);
                if (Store.SubscribeObjectNotifications(EtpVersion.v12, false, Store.StoreLastWrite, true, handler.Session.SessionId, subscriptionInfo, callbacks))
                {
                    args.ResponseMap[kvp.Key] = string.Empty;
                }
                else
                {
                    args.ErrorMap[kvp.Key] = handler.ErrorInfo().RequestUuidRejected(kvp.Value);
                }
            }
        }
Exemplo n.º 6
0
        private void OnStartCore(object sender, VoidRequestEventArgs <v11.Protocol.ChannelStreaming.Start> args)
        {
            var handler   = (v11.Protocol.ChannelStreaming.IChannelStreamingProducer)sender;
            var sessionId = GetSessionId(handler);
            var callbacks = CreateChannelStreamingCallbacks(handler);

            if (Store.StartChannelSubscription(EtpVersion.v11, sessionId, args.Request.Body.MaxDataItems, TimeSpan.FromMilliseconds(args.Request.Body.MaxMessageRate), handler.Capabilities.SimpleStreamer ?? false, callbacks))
            {
                if (handler.Capabilities.SimpleStreamer ?? false)
                {
                    var describe = new v11.Protocol.ChannelStreaming.ChannelDescribe
                    {
                        Uris = new List <string> {
                            EtpUri.RootUri11
                        },
                    };
                    foreach (var subscription in describe.GetSubscriptions(sessionId)) // Register global metadata subscriptions
                    {
                        var subscriptionInfo = new MockSubscriptionInfo(subscription);
                        if (Store.HasChannelSubscriptionScope(sessionId, subscriptionInfo))
                        {
                            continue;
                        }

                        IList <MockObject> addedChannels;
                        if (Store.AddChannelSubscriptionChannelScope(sessionId, subscriptionInfo, out addedChannels))
                        {
                            var channels = addedChannels
                                           .Where(o => o is IMockGrowingObject)
                                           .Select(o => ((IMockGrowingObject)o).ChannelMetadataRecord11(Store.GetChannelId(sessionId, o)))
                                           .ToList();
                            handler.ChannelMetadata(subscription.RequestUuid, channels);
                        }
                    }
                }
            }
            else
            {
                args.FinalError = handler.ErrorInfo().RequestDenied();
            }
        }
Exemplo n.º 7
0
        private void OnChannelDescribeCore(object sender, ListRequestEventArgs <v11.Protocol.ChannelStreaming.ChannelDescribe, v11.Datatypes.ChannelData.ChannelMetadataRecord> args)
        {
            var handler   = (v11.Protocol.ChannelStreaming.IChannelStreamingProducer)sender;
            var sessionId = GetSessionId(handler);

            if (handler.Capabilities.SimpleStreamer ?? false)
            {
                args.FinalError = handler.ErrorInfo().RequestDenied();
                return;
            }
            if (!Store.HasChannelSubscription(sessionId))
            {
                args.FinalError = handler.ErrorInfo().InvalidState("Start must be sent before ChannelDescribe.");
            }

            var allAddedChannels = new List <MockObject>();

            foreach (var subscription in args.Request.Body.GetSubscriptions(sessionId)) // Register metadata subscriptions
            {
                var subscriptionInfo = new MockSubscriptionInfo(subscription);
                if (Store.HasChannelSubscriptionScope(sessionId, subscriptionInfo))
                {
                    continue;
                }

                IList <MockObject> addedChannels;
                if (Store.AddChannelSubscriptionChannelScope(sessionId, subscriptionInfo, out addedChannels))
                {
                    allAddedChannels.AddRange(addedChannels);
                }
                else
                {
                    args.ErrorMap[subscriptionInfo.RequestUuid.ToString()] = handler.ErrorInfo().RequestDenied($"URI: {subscription.Uri}");
                }
            }
            args.Responses = allAddedChannels
                             .Where(o => o is IMockGrowingObject)
                             .Select(o => ((IMockGrowingObject)o).ChannelMetadataRecord11(Store.GetChannelId(sessionId, o)))
                             .ToList();
        }
Exemplo n.º 8
0
        private void OnStoreNotificationStoreStarted(object sender, EventArgs args)
        {
            var handler = (v12.Protocol.StoreNotification.IStoreNotificationStore)sender;

            if (!handler.Session.SessionSupportedDataObjects.IsSupported(Dataspace.Wellbore05.DataObjectType))
            {
                return;
            }

            Store.ExecuteWithLock(() =>
            {
                var callbacks        = CreateStoreNotificationCallbacks(handler);
                var uuid             = Guid.NewGuid();
                var subscriptionInfo = new MockSubscriptionInfo(EtpVersion.v12, Dataspace.Wellbore05, uuid);
                if (Store.SubscribeObjectNotifications(EtpVersion.v12, false, Store.StoreLastWrite, true, handler.Session.SessionId, subscriptionInfo, callbacks))
                {
                    handler.UnsolicitedStoreNotifications(new List <v12.Datatypes.Object.SubscriptionInfo> {
                        subscriptionInfo.SubsriptionInfo12
                    });
                }
            });
        }
Exemplo n.º 9
0
        private void OnStartStreamingCore(object sender, VoidRequestEventArgs <v12.Protocol.ChannelStreaming.StartStreaming> args)
        {
            var handler   = (v12.Protocol.ChannelStreaming.IChannelStreamingProducer)sender;
            var sessionId = GetSessionId(handler);
            var callbacks = CreateChannelStreamingCallbacks(handler);

            if (Store.StartChannelSubscription(EtpVersion.v11, sessionId, int.MaxValue, TimeSpan.FromMilliseconds(0), true, callbacks))
            {
                var describe = new v11.Protocol.ChannelStreaming.ChannelDescribe
                {
                    Uris = new List <string> {
                        EtpUri.RootUri11
                    },
                };
                foreach (var subscription in describe.GetSubscriptions(sessionId)) // Register global metadata subscriptions
                {
                    var subscriptionInfo = new MockSubscriptionInfo(subscription);
                    if (Store.HasChannelSubscriptionScope(sessionId, subscriptionInfo))
                    {
                        continue;
                    }

                    IList <MockObject> addedChannels;
                    if (Store.AddChannelSubscriptionChannelScope(sessionId, subscriptionInfo, out addedChannels))
                    {
                        var channels = addedChannels
                                       .Where(o => o is MockChannel)
                                       .Select(o => ((MockChannel)o).ChannelMetadataRecord12(Store.GetChannelId(sessionId, o)))
                                       .ToList();
                        handler.ChannelMetadata(channels);
                    }
                }
            }
            else
            {
                args.FinalError = handler.ErrorInfo().RequestDenied();
            }
        }
Exemplo n.º 10
0
        public bool SubscribeObjectNotifications(EtpVersion version, bool sendHistoricalChanges, DateTime historicalChangesStartTime, bool endIfRootDeleted, Guid sessionId, MockSubscriptionInfo subscriptionInfo, MockObjectCallbacks callbacks)
        {
            CheckLocked();

            if (ObjectSubscriptionsByRequestUuid.ContainsKey(subscriptionInfo.RequestUuid))
            {
                return(false);
            }

            MockObject root = null;
            var        uri  = subscriptionInfo.Context.Uri;

            if (uri.IsObjectUri)
            {
                root = GetObject(version, uri);
                if (root == null)
                {
                    return(false);
                }
            }

            ObjectSubscriptionsByRequestUuid[subscriptionInfo.RequestUuid] = new ObjectSubscription
            {
                SessionId             = sessionId,
                Version               = version,
                Uuid                  = subscriptionInfo.RequestUuid,
                LastNotificationTime  = sendHistoricalChanges ? historicalChangesStartTime : StoreLastWrite,
                SubscriptionInfo      = subscriptionInfo,
                Callbacks             = callbacks,
                Root                  = root,
                SendHistoricalChanges = sendHistoricalChanges,
                EndIfRootDeleted      = endIfRootDeleted,
            };

            return(true);
        }