Esempio 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}");
                }
            }
        }
Esempio n. 2
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();
            }
        }
Esempio n. 3
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();
        }
Esempio n. 4
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();
            }
        }