示例#1
0
 private void Start()
 {
     this.demoHub      = new DemoHub();
     this.typedDemoHub = new TypedDemoHub();
     this.vbDemoHub    = new Hub("vbdemo");
     Hub[] hubs = new Hub[] { this.demoHub, this.typedDemoHub, this.vbDemoHub };
     this.signalRConnection              = new Connection(this.URI, hubs);
     this.signalRConnection.JsonEncoder  = new LitJsonEncoder();
     this.signalRConnection.OnConnected += delegate(Connection connection) {
         < > __AnonType2 <string, int, <> __AnonType1 <string, string> > person = new < > __AnonType2 <string, int, <> __AnonType1 <string, string> >("Foo", 20, new < > __AnonType1 <string, string>("One Microsoft Way", "98052"));
         this.demoHub.AddToGroups();
         this.demoHub.GetValue();
         this.demoHub.TaskWithException();
         this.demoHub.GenericTaskWithException();
         this.demoHub.SynchronousException();
         this.demoHub.DynamicTask();
         this.demoHub.PassingDynamicComplex(person);
         this.demoHub.SimpleArray(new int[] { 5, 5, 6 });
         this.demoHub.ComplexType(person);
         object[] complexArray = new object[] { person, person, person };
         this.demoHub.ComplexArray(complexArray);
         this.demoHub.ReportProgress("Long running job!");
         this.demoHub.Overload();
         this.demoHub.State["name"] = "Testing state!";
         this.demoHub.ReadStateValue();
         this.demoHub.PlainTask();
         this.demoHub.GenericTaskWithContinueWith();
         this.typedDemoHub.Echo("Typed echo callback");
         this.vbDemoHub.Call("readStateValue", (hub, msg, result) => this.vbReadStateResult = $"Read some state from VB.NET! => {(result.ReturnValue != null) ? result.ReturnValue.ToString() : "undefined"}", Array.Empty <object>());
     };
示例#2
0
    void Start()
    {
        // Create the hubs
        demoHub      = new DemoHub();
        typedDemoHub = new TypedDemoHub();
        vbDemoHub    = new Hub("vbdemo");

        // Create the SignalR connection, passing all the three hubs to it
        signalRConnection = new Connection(URI, demoHub, typedDemoHub, vbDemoHub);

        // Switch from the default encoder to the LitJson Encoder becouse it can handle the complex types too.
        signalRConnection.JsonEncoder = new LitJsonEncoder();

        // Call the demo functions when we successfully connect to the server
        signalRConnection.OnConnected += (connection) =>
        {
            var person = new { Name = "Foo", Age = 20, Address = new { Street = "One Microsoft Way", Zip = "98052" } };

            // Call the demo functions

            demoHub.AddToGroups();
            demoHub.GetValue();
            demoHub.TaskWithException();
            demoHub.GenericTaskWithException();
            demoHub.SynchronousException();
            demoHub.DynamicTask();
            demoHub.PassingDynamicComplex(person);
            demoHub.SimpleArray(new int[] { 5, 5, 6 });
            demoHub.ComplexType(person);
            demoHub.ComplexArray(new object[] { person, person, person });
            demoHub.ReportProgress("Long running job!");

            demoHub.Overload();

            // set some state
            demoHub.State["name"] = "Testing state!";
            demoHub.ReadStateValue();

            demoHub.PlainTask();
            demoHub.GenericTaskWithContinueWith();

            typedDemoHub.Echo("Typed echo callback");

            // vbDemo is not wrapped in a hub class, it would contain only one function
            vbDemoHub.Call("readStateValue", (hub, msg, result) => vbReadStateResult = string.Format("Read some state from VB.NET! => {0}", result.ReturnValue == null ? "undefined" : result.ReturnValue.ToString()));
        };

        // Start opening the signalR connection
        signalRConnection.Open();
    }