Using parameters in XSockets.NET longrunning controller

237 views Asked by At

For filter conditions on queries to a database it is nessessary to have parameters in longrunning controllers. It is possible to pass QueryString parameter to Custom controller, but I haven't found a way to do this for longrunning controllers. Would that be possible?

1

There are 1 answers

0
dathor On

Hmm.. it is not possible to pass parameters to a longrunning controller. What i would do is set properties using the JavaScript API or by passing them as parameters in the querysting to the CustomController of yours. As there is an instance of that customcontroller in the long-running you can either filter or just call a certain method ( as shown here http://xsockets.net/docs/c-server-api#longrunning-internal-controllers ) .

You can also do like this

using System;
using System.Timers;
using Microsoft.Ajax.Utilities;
using XSockets.Core.Common.Globals;
using XSockets.Core.Common.Socket;
using XSockets.Core.XSocket;
using XSockets.Core.XSocket.Helpers;
using XSockets.Plugin.Framework;

namespace MyWeRole.Controllers
{
    [XSocketMetadata("LongrunningController1"
                    , Constants.GenericTextBufferSize
                    , PluginRange.Internal)             ]
    public class LongrunningController1 : XSocketController
    {
        static MyCustomController1 customController1;

        static LongrunningController1()
        {
            //Initialize your long running stuff here  
            customController1 = new MyCustomController1();
            var timer = new System.Timers.Timer();
            timer.Interval = 3000;
            timer.Elapsed += TimerOnElapsed;
            timer.Start();

        }

        private static void TimerOnElapsed(object sender
                                        , ElapsedEventArgs elapsedEventArgs)
        {
            var objectToSend = new {SomeInt = 1, SomeString = "HelloWorld"};

            customController1
                .SendTo( c =>  c.Interest.Equals("Travel")   
                             , objectToSend.AsTextArgs("YourTopic") );

        }
    }

    public class MyCustomController1 : XSocketController
    {
        public string Interest { get; set; }

        public MyCustomController1 ()
        {
            // set the default interset
            this.Interest = "Travel";
        }
    }
}

As you can modify properties on controllers using JavaScript you can change the "Interest" property by using i.e

ws.publish("set_Interest",{value: 'Code'});

Hope this helps!