Beispiel #1
0
        private void ExecuteTask(string eventName, double steps)
        {
            var status = new Status
            {
                State = "starting",
                PercentComplete = 0.0
            };

            PublishEvent(eventName, status);

            for (double i = 0; i < steps; i++)
            {
                // Update the status and publish a new event
                //
                status.State = "working";
                status.PercentComplete = (i / steps) * 100;
                PublishEvent(eventName, status);

                Thread.Sleep(500);
            }

            status.State = "complete";
            status.PercentComplete = 100;
            PublishEvent(eventName, status);
        }
Beispiel #2
0
 private void PublishEvent(string eventName, Status status)
 {
     // From .NET code like this we can't invoke the methods that
     //  exist on our actual Hub class...because we only have a proxy
     //  to it. So to publish the event we need to call the method that
     //  the clients will be listening on.
     //
     _context.Clients.Group(_channel).OnEvent(Constants.TaskChannel, new ChannelEvent
     {
     ChannelName = Constants.TaskChannel,
     Name = eventName,
     Data = status
     });
 }