Beispiel #1
0
        public override int OnSubscriptionEvent(SubscriptionEvent e)
        {
            short code = e.getCode();
            tsip_subscribe_event_type_t type    = e.getType();
            SubscriptionSession         session = e.getSession();
            SipMessage message = e.getSipMessage();

            switch (type)
            {
            case tsip_subscribe_event_type_t.tsip_ao_subscribe:
            case tsip_subscribe_event_type_t.tsip_ao_unsubscribe:
                break;

            case tsip_subscribe_event_type_t.tsip_i_notify:
                byte[] content = message.getSipContent();
                if (content != null)
                {
                    Console.WriteLine("Notify Content ==> {0}", Encoding.UTF8.GetString(content));
                }
                break;
            }

            Console.WriteLine("OnSubscriptioChanged() ==> {0}:{1}", code, e.getPhrase());

            return(0);
        }
Beispiel #2
0
        private void buttonSub_Click(object sender, EventArgs e)
        {
            if (this.subSession == null)
            {
                this.subSession = new SubscriptionSession(stack);
                this.subSession.addHeader("Accept", "application/reginfo+xml");
                this.subSession.addHeader("Event", "reg");
                this.subSession.setExpires(30);

                this.subSession.Subscribe();
            }
        }
Beispiel #3
0
        public async Task Handle_Stop_Subscription()
        {
            // arrange
            var connection   = new SocketConnectionMock();
            var subscription = new Mock <ISubscription>();

            IRequestExecutor executor = await new ServiceCollection()
                                        .AddGraphQL()
                                        .AddStarWarsTypes()
                                        .AddStarWarsRepositories()
                                        .AddInMemorySubscriptions()
                                        .Services
                                        .BuildServiceProvider()
                                        .GetRequiredService <IRequestExecutorResolver>()
                                        .GetRequestExecutorAsync();

            var stream =
                (IResponseStream)await executor.ExecuteAsync(
                    "subscription { onReview(episode: NEW_HOPE) { stars } }");

            var interceptor         = new SocketSessionInterceptorMock();
            var subscriptionSession = new SubscriptionSession(
                new CancellationTokenSource(),
                interceptor,
                connection,
                stream,
                subscription.Object,
                new NoopExecutionDiagnosticEvents(),
                "123");

            connection.Subscriptions.Register(subscriptionSession);

            var handler = new DataStopMessageHandler();
            var message = new DataStopMessage("123");

            // act
            await handler.HandleAsync(
                connection,
                message,
                CancellationToken.None);

            // assert
            Assert.Empty(connection.Subscriptions);
        }
Beispiel #4
0
    protected override async Task HandleAsync(
        ISocketConnection connection,
        DataStartMessage message,
        CancellationToken cancellationToken)
    {
        var session  = new CancellationTokenSource();
        var combined = CancellationTokenSource.CreateLinkedTokenSource(
            session.Token, cancellationToken);
        var sessionIsHandled = false;

        IExecutionResult result = await ExecuteAsync(combined.Token);

        try
        {
            switch (result)
            {
            case SubscriptionResult subscriptionResult:
                // first we add the cts to the result so that they are disposed when the
                // subscription is disposed.
                subscriptionResult.RegisterDisposable(combined);

                // while a subscription result must be disposed we are not handling it here
                // and leave this responsibility to the subscription session.
                ISubscription subscription = GetSubscription(result);

                var subscriptionSession = new SubscriptionSession(
                    session,
                    _socketSessionInterceptor,
                    connection,
                    subscriptionResult,
                    subscription,
                    _diagnosticEvents,
                    message.Id);

                connection.Subscriptions.Register(subscriptionSession);
                sessionIsHandled = true;
                break;

            case IResponseStream streamResult:
                // stream results represent deferred execution streams that use execution
                // resources. We need to ensure that these are disposed when we are
                // finished.
                await using (streamResult)
                {
                    await HandleStreamResultAsync(
                        connection,
                        message,
                        streamResult,
                        cancellationToken);
                }

                break;

            case IQueryResult queryResult:
                // query results use pooled memory an need to be disposed after we have
                // used them.
                using (queryResult)
                {
                    await HandleQueryResultAsync(
                        connection,
                        message,
                        queryResult,
                        cancellationToken);
                }

                break;

            default:
                throw DataStartMessageHandler_RequestTypeNotSupported();
            }
        }
        finally
        {
            if (!sessionIsHandled)
            {
                session.Dispose();
                combined.Dispose();
            }
        }

        async ValueTask <IExecutionResult> ExecuteAsync(CancellationToken cancellationToken)
        {
            try
            {
                IQueryRequestBuilder requestBuilder =
                    QueryRequestBuilder.From(message.Payload)
                    .SetServices(connection.RequestServices);

                await _socketSessionInterceptor.OnRequestAsync(
                    connection, requestBuilder, cancellationToken);

                return(await _requestExecutor.ExecuteAsync(
                           requestBuilder.Create(), cancellationToken));
            }
            catch (Exception ex)
            {
                IErrorBuilder error = _errorHandler.CreateUnexpectedError(ex);
                return(QueryResultBuilder.CreateError(error.Build()));
            }
        }
    }
        public MySubscriptionSession(MySipStack sipStack, string toUri, MySubscriptionSession.EVENT_PACKAGE_TYPE eventPackage) : base(sipStack)
        {
            this.session      = new SubscriptionSession(sipStack.WrappedStack);
            this.eventPackage = eventPackage;
            base.init();
            base.SigCompId = sipStack.SigCompId;
            switch (eventPackage)
            {
            case MySubscriptionSession.EVENT_PACKAGE_TYPE.CONFERENCE:
                this.session.addHeader("Event", "conference");
                this.session.addHeader("Accept", "application/conference-info+xml");
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.DIALOG:
                this.session.addHeader("Event", "dialog");
                this.session.addHeader("Accept", "application/dialog-info+xml");
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.MESSAGE_SUMMARY:
                this.session.addHeader("Event", "message-summary");
                this.session.addHeader("Accept", "application/simple-message-summary");
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.PRESENCE:
            case MySubscriptionSession.EVENT_PACKAGE_TYPE.PRESENCE_LIST:
                this.session.addHeader("Event", "presence");
                if (eventPackage == MySubscriptionSession.EVENT_PACKAGE_TYPE.PRESENCE_LIST)
                {
                    this.session.addHeader("Supported", "eventlist");
                }
                this.session.addHeader("Accept", string.Format("{0}, {1}, {2}, {3}", new object[]
                {
                    "multipart/related",
                    "application/pidf+xml",
                    "application/rlmi+xml",
                    "application/rpid+xml"
                }));
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.REG:
                this.session.addHeader("Event", "reg");
                this.session.addHeader("Accept", "application/reginfo+xml");
                this.session.setSilentHangup(true);
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.SIP_PROFILE:
                this.session.addHeader("Event", "sip-profile");
                this.session.addHeader("Accept", "application/vnd.oma.im.deferred-list+xml");
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.UA_PROFILE:
                this.session.addHeader("Event", "ua-profile");
                this.session.addHeader("Accept", "application/xcap-diff+xml");
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.WINFO:
                this.session.addHeader("Event", "presence.winfo");
                this.session.addHeader("Accept", "application/watcherinfo+xml");
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.XCAP_DIFF:
                this.session.addHeader("Event", "xcap-diff");
                this.session.addHeader("Accept", "application/xcap-diff+xml");
                break;
            }
            base.ToUri   = UriUtils.GetValidSipUri(toUri);
            this.fromUri = UriUtils.GetValidSipUri(this.fromUri);
            this.session.addHeader("Allow-Events", "refer, presence, presence.winfo, xcap-diff, conference");
        }
Beispiel #6
0
        private void buttonSub_Click(object sender, EventArgs e)
        {
            if (this.subSession == null)
            {
                this.subSession = new SubscriptionSession(stack);
                this.subSession.addHeader("Accept", "application/reginfo+xml");
                this.subSession.addHeader("Event", "reg");
                this.subSession.setExpires(30);

                this.subSession.Subscribe();
            }
        }
Beispiel #7
0
        public MySubscriptionSession(MySipStack sipStack, string toUri, MySubscriptionSession.EVENT_PACKAGE_TYPE eventPackage) : base(sipStack)
        {
            this.session      = new SubscriptionSession(sipStack.WrappedStack);
            this.eventPackage = eventPackage;
            base.init();
            base.SigCompId = sipStack.SigCompId;
            switch (eventPackage)
            {
            case MySubscriptionSession.EVENT_PACKAGE_TYPE.CONFERENCE:
                this.session.addHeader("Event", "conference");
                this.session.addHeader("Accept", "application/conference-info+xml");
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.DIALOG:
                this.session.addHeader("Event", "dialog");
                this.session.addHeader("Accept", "application/dialog-info+xml");
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.MESSAGE_SUMMARY:
                this.session.addHeader("Event", "message-summary");
                this.session.addHeader("Accept", "application/simple-message-summary");
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.PRESENCE:
            case MySubscriptionSession.EVENT_PACKAGE_TYPE.PRESENCE_LIST:
                this.session.addHeader("Event", "presence");
                if (eventPackage == MySubscriptionSession.EVENT_PACKAGE_TYPE.PRESENCE_LIST)
                {
                    this.session.addHeader("Supported", "eventlist");
                }
                this.session.addHeader("Accept", string.Format("{0}, {1}, {2}, {3}", new object[]
                {
                    "multipart/related",
                    "application/pidf+xml",
                    "application/rlmi+xml",
                    "application/rpid+xml"
                }));
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.REG:
                this.session.addHeader("Event", "reg");
                this.session.addHeader("Accept", "application/reginfo+xml");
                this.session.setSilentHangup(true);
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.SIP_PROFILE:
                this.session.addHeader("Event", "sip-profile");
                this.session.addHeader("Accept", "application/vnd.oma.im.deferred-list+xml");
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.UA_PROFILE:
                this.session.addHeader("Event", "ua-profile");
                this.session.addHeader("Accept", "application/xcap-diff+xml");
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.WINFO:
                this.session.addHeader("Event", "presence.winfo");
                this.session.addHeader("Accept", "application/watcherinfo+xml");
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.XCAP_DIFF:
                this.session.addHeader("Event", "xcap-diff");
                this.session.addHeader("Accept", "application/xcap-diff+xml");
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.PTT_MEMBRELATION_SUB:
                this.session.addHeader("Event", "MembershipAttributes");
                this.session.addHeader("Accept", "application/pttmembershipinfo+xml");
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.PTT_REG_SUB:
                this.session.addHeader("Event", "UERegisterStatus");
                this.session.addHeader("Accept", "application/pttuereginfo+xml");
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.PTT_UECALL_SUB:
                this.session.addHeader("Event", "UECallStatus");
                this.session.addHeader("Accept", "application/pttuecallinfo+xml");
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.PTT_GRCALL_SUB:
                this.session.addHeader("Event", "GroupCallStatus");
                this.session.addHeader("Accept", "application/pttgroupcallinfo+xml");
                break;

            case MySubscriptionSession.EVENT_PACKAGE_TYPE.PTT_ONLINECALL_SUB:
                this.session.addHeader("Event", "OnLineCallStatus");
                this.session.addHeader("Accept", "application/pttsysonlinecallinfo+xml");
                break;
            }
            base.ToUri = UriUtils.GetValidSipUri(toUri);
        }
Beispiel #8
0
        protected override async Task HandleAsync(
            ISocketConnection connection,
            DataStartMessage message,
            CancellationToken cancellationToken)
        {
            IQueryRequestBuilder requestBuilder =
                QueryRequestBuilder.From(message.Payload)
                .SetServices(connection.RequestServices);

            await _socketSessionInterceptor.OnRequestAsync(
                connection, requestBuilder, cancellationToken);

            IExecutionResult result = await _requestExecutor.ExecuteAsync(
                requestBuilder.Create(), cancellationToken);

            switch (result)
            {
            case ISubscriptionResult subscriptionResult:
                // while a subscription result must be disposed we are not handling it here
                // and leave this responsibility to the subscription session.
                ISubscription subscription = GetSubscription(result);

                var subscriptionSession = new SubscriptionSession(
                    connection,
                    subscriptionResult,
                    subscription,
                    _diagnosticEvents,
                    message.Id);

                connection.Subscriptions.Register(subscriptionSession);
                break;

            case IResponseStream streamResult:
                // stream results represent deferred execution streams that use execution
                // resources. We need to ensure that these are disposed when we are
                // finished.
                await using (streamResult)
                {
                    await HandleStreamResultAsync(
                        connection,
                        message,
                        streamResult,
                        cancellationToken);
                }
                break;

            case IQueryResult queryResult:
                // query results use pooled memory an need to be disposed after we have
                // used them.
                using (queryResult)
                {
                    await HandleQueryResultAsync(
                        connection,
                        message,
                        queryResult,
                        cancellationToken);
                }
                break;

            default:
                throw DataStartMessageHandler_RequestTypeNotSupported();
            }
        }
            /// <summary>
            /// Subscription events
            /// </summary>
            /// <param name="e"></param>
            /// <returns></returns>
            public override int OnSubscriptionEvent(SubscriptionEvent e)
            {
                tsip_subscribe_event_type_t type = e.getType();

                switch (type)
                {
                case tsip_subscribe_event_type_t.tsip_i_notify:
                {
                    SubscriptionSession   session = e.getSession();
                    MySubscriptionSession mysession;
                    if (session == null || (mysession = this.sipService.FindSubscription(session.getId())) == null)
                    {
                        LOG.Error("Null session");
                        return(-1);
                    }
                    SipMessage message = e.getSipMessage();
                    if (message == null)
                    {
                        LOG.Error("Null message");
                        return(-1);
                    }
                    String contentType = message.getSipHeaderValue("c");
                    byte[] content     = message.getSipContent();
                    if (String.IsNullOrEmpty(contentType) || content == null)
                    {
                        LOG.Error("Invalid content");
                        return(-1);
                    }

                    // Save content: To allow the end user to request this content at any time
                    if (String.Equals(contentType, ContentType.REG_INFO))
                    {
                        this.sipService.subRegContent = content;
                    }
                    else if (String.Equals(contentType, ContentType.WATCHER_INFO))
                    {
                        this.sipService.subWinfoContent = content;
                    }

                    short  code   = e.getCode();
                    String phrase = e.getPhrase();

                    SubscriptionEventArgs eargs = new SubscriptionEventArgs(SubscriptionEventTypes.INCOMING_NOTIFY,
                                                                            code, phrase, content, contentType, mysession.EventPackage);
                    eargs.AddExtra(SubscriptionEventArgs.EXTRA_SESSION, mysession);
                    if (ContentType.MULTIPART_RELATED.Equals(contentType, StringComparison.InvariantCultureIgnoreCase))
                    {
                        String ctype = message.getSipHeaderParamValue("c", "type");
                        eargs.AddExtra(SubscriptionEventArgs.EXTRA_CONTENTYPE_TYPE, ctype == null ? String.Empty : ctype.Replace("\"", String.Empty));

                        String start = message.getSipHeaderParamValue("c", "start");
                        eargs.AddExtra(SubscriptionEventArgs.EXTRA_CONTENTYPE_START, start == null ? String.Empty : start.Replace("\"", String.Empty));

                        String boundary = message.getSipHeaderParamValue("c", "boundary");
                        eargs.AddExtra(SubscriptionEventArgs.EXTRA_CONTENTYPE_BOUNDARY, boundary == null ? String.Empty : boundary.Replace("\"", String.Empty));
                    }
                    EventHandlerTrigger.TriggerEvent <SubscriptionEventArgs>(this.sipService.onSubscriptionEvent, this.sipService, eargs);

                    break;
                }

                default:
                case tsip_subscribe_event_type_t.tsip_i_subscribe:
                case tsip_subscribe_event_type_t.tsip_ao_subscribe:
                case tsip_subscribe_event_type_t.tsip_i_unsubscribe:
                case tsip_subscribe_event_type_t.tsip_ao_unsubscribe:
                case tsip_subscribe_event_type_t.tsip_ao_notify:
                {
                    break;
                }
                }

                return(0);
            }
Beispiel #10
0
        public void SubscriptionSessionConstructorTest()
        {
            SubscriptionBehaviour behaviour = new SubscriptionBehaviour();
            SubscriptionSession   target    = new SubscriptionSession(behaviour);

            target.SubscriptionChanged += (sessn, subArgs) =>
            {
                var builder = new StringBuilder();

                foreach (var item in subArgs.FieldData)
                {
                    builder.AppendFormat("{0} to {1}{2}", item.Key, item.Value, Environment.NewLine);
                }
                var msg = string.Format("{0}: {1} changed:{3}{2}", subArgs.Id, subArgs.Topic, builder.ToString(), Environment.NewLine);
                Console.WriteLine(msg);
            };

            behaviour.ServiceOpened += (sender, args) =>
            {
                List <Subscription> list = new List <Subscription>();

                list.Add(new Subscription("XS0585380602@GSSD CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(18595973)));
                list.Add(new Subscription("XS0788176070@RBCD CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(18803310)));
                list.Add(new Subscription("XS0799547137@RABS CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(18044452)));
                list.Add(new Subscription("CH0189535229@UBSF CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19953522)));
                list.Add(new Subscription("XS0806746789@HSED CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19043879)));
                list.Add(new Subscription("XS0807559454@HSED CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19055243)));
                list.Add(new Subscription("XS0807582605@RABS CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(18044484)));
                list.Add(new Subscription("XS0816364433@HSED CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19238472)));
                list.Add(new Subscription("CH0187367930@EFGZ CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(18736793)));
                list.Add(new Subscription("XS0815510812@HSED CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19210627)));
                list.Add(new Subscription("CH0188287632@CSZE CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(18828763)));
                list.Add(new Subscription("CH0148735324@SARA CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(14873532)));
                list.Add(new Subscription("CH0148735332@SARA CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(14873533)));
                list.Add(new Subscription("CH0187368110 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(18736811)));
                list.Add(new Subscription("CH0141501947@VONT CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(14150194)));
                list.Add(new Subscription("CH0141501954@exch CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(14150195)));
                list.Add(new Subscription("GB00B8MKWW97 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(10474448)));
                list.Add(new Subscription("XS0826054289 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(18293952)));
                list.Add(new Subscription("XS0826056144 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19399264)));
                list.Add(new Subscription("CH0193303010 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19330301)));
                list.Add(new Subscription("CH0194083454 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19408345)));
                list.Add(new Subscription("XS0826535030@RABS CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(18044543)));
                list.Add(new Subscription("FR0011315654@EXA CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19376476)));
                list.Add(new Subscription("CH0182602141@EFGZ CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(18260214)));
                list.Add(new Subscription("XS0827216739 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19424709)));
                list.Add(new Subscription("CH0190890969@EFGZ CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19089096)));
                list.Add(new Subscription("FR0011315670@EXA CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19376475)));
                list.Add(new Subscription("XS0831818264@RABS CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(18044557)));
                list.Add(new Subscription("XS0831345425 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19568729)));
                list.Add(new Subscription("CH0192713839@EFGZ CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19271383)));
                list.Add(new Subscription("CH0193320634 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19332063)));
                list.Add(new Subscription("CH0193320659 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19332065)));
                list.Add(new Subscription("CH0197277368@UBSF CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19727736)));
                list.Add(new Subscription("CH0196851569 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19256161)));
                list.Add(new Subscription("XS0848449772 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19862827)));
                list.Add(new Subscription("CH0199037646 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19903764)));
                list.Add(new Subscription("CH0195362873 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19536287)));
                list.Add(new Subscription("DE000CZ36U01@CBED CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19994508)));
                list.Add(new Subscription("CH0199655421@WDRL CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19965542)));
                list.Add(new Subscription("XS0857368418 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(18044674)));
                list.Add(new Subscription("CH0199960300@UBSF CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19996030)));
                list.Add(new Subscription("XS0687757442 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19536333)));
                list.Add(new Subscription("CH0200342639 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(20034263)));
                list.Add(new Subscription("CH0187197782 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(18719778)));
                list.Add(new Subscription("CH0194435795 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19443579)));
                list.Add(new Subscription("DE000CZ36U01 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19859810)));
                list.Add(new Subscription("DE000CZ36X24 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(20076171)));
                list.Add(new Subscription("XS0859349291 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(18044683)));
                list.Add(new Subscription("XS0859346511 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(20095111)));
                list.Add(new Subscription("XS0859940859 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(18176081)));
                list.Add(new Subscription("CH0195364309 CORP", "BID,ASK,TIME", "interval=15", new CorrelationID(19536430)));

                target.Subscribe(list);
            };

            target.Start();

            while (true)
            {
                Thread.Sleep(1000);
            }
        }
        public MySubscriptionSession(MySipStack sipStack, String toUri, EVENT_PACKAGE_TYPE eventPackage)
            : base(sipStack)
        {
            this.session      = new SubscriptionSession(sipStack);
            this.eventPackage = eventPackage;

            // commons
            base.init();

            // SigComp
            base.SigCompId = sipStack.SigCompId;

            switch (eventPackage)
            {
            case EVENT_PACKAGE_TYPE.CONFERENCE:
                this.session.addHeader("Event", "conference");
                this.session.addHeader("Accept", ContentType.CONFERENCE_INFO);
                break;

            case EVENT_PACKAGE_TYPE.DIALOG:
                this.session.addHeader("Event", "dialog");
                this.session.addHeader("Accept", ContentType.DIALOG_INFO);
                break;

            case EVENT_PACKAGE_TYPE.MESSAGE_SUMMARY:
                this.session.addHeader("Event", "message-summary");
                this.session.addHeader("Accept", ContentType.MESSAGE_SUMMARY);
                break;

            case EVENT_PACKAGE_TYPE.PRESENCE:
            case EVENT_PACKAGE_TYPE.PRESENCE_LIST:
                this.session.addHeader("Event", "presence");
                if (eventPackage == EVENT_PACKAGE_TYPE.PRESENCE_LIST)
                {
                    this.session.addHeader("Supported", "eventlist");
                }
                this.session.addHeader("Accept",
                                       String.Format("{0}, {1}, {2}, {3}",
                                                     ContentType.MULTIPART_RELATED,
                                                     ContentType.PIDF,
                                                     ContentType.RLMI,
                                                     ContentType.RPID
                                                     ));
                break;

            case EVENT_PACKAGE_TYPE.REG:
                this.session.addHeader("Event", "reg");
                this.session.addHeader("Accept", ContentType.REG_INFO);
                // 3GPP TS 24.229 5.1.1.6 User-initiated deregistration
                this.session.setSilentHangup(true);
                break;

            case EVENT_PACKAGE_TYPE.SIP_PROFILE:
                this.session.addHeader("Event", "sip-profile");
                this.session.addHeader("Accept", ContentType.OMA_DEFERRED_LIST);
                break;

            case EVENT_PACKAGE_TYPE.UA_PROFILE:
                this.session.addHeader("Event", "ua-profile");
                this.session.addHeader("Accept", ContentType.XCAP_DIFF);
                break;

            case EVENT_PACKAGE_TYPE.WINFO:
                this.session.addHeader("Event", "presence.winfo");
                this.session.addHeader("Accept", ContentType.WATCHER_INFO);
                break;

            case EVENT_PACKAGE_TYPE.XCAP_DIFF:
                this.session.addHeader("Event", "xcap-diff");
                this.session.addHeader("Accept", ContentType.XCAP_DIFF);
                break;
            }

            this.ToUri = toUri;
            // common to all subscription sessions
            this.session.addHeader("Allow-Events", "refer, presence, presence.winfo, xcap-diff, conference");
        }