Javascript 客户端函数未被调用信号器

Javascript 客户端函数未被调用信号器,javascript,asp.net-mvc-4,signalr,signalr-hub,signalr.client,Javascript,Asp.net Mvc 4,Signalr,Signalr Hub,Signalr.client,定义了集线器的控制器类 public abstract class MonitoringProfileLogChartController : Croem.NotificationManager.Website.Base.BaseController.BaseController { public ActionResult Index() { BusinessLogicReturn resu

定义了集线器的控制器类

    public abstract class MonitoringProfileLogChartController : Croem.NotificationManager.Website.Base.BaseController.BaseController
        {

            public ActionResult Index()
            {
                BusinessLogicReturn result = new ProcessBusinessLogic.Logic().GetRegisteredContexts();
                return base.TransalateToAction(result);
            }
            public ActionResult LiveMonitoringProfileLogChart()
            {
                return View();
            }
            public ActionResult test()
            {
                return View();
            }

**below is rest of the code of controller where our focus should be**


  public JsonResult GetMonitoringProfileLogChart(string FromDate, string ToDate, int ContextId)
        {
            BusinessLogicReturn result = new ProcessBusinessLogic.Logic().GetMonitoringProfileLogChart(FromDate, ToDate, ContextId);
            return Json(result.Model, JsonRequestBehavior.AllowGet);
        }
        public JsonResult GetMonitoringProfileLiveLogChart(string FromTime, string ToTime, string DataMinutes)
        {
            BusinessLogicReturn result = new ProcessBusinessLogic.Logic().GetMonitoringProfileLiveLogChart(FromTime, ToTime, DataMinutes);
            IHubContext context = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
            context.Clients.All.addMessage(result.Model);
            var hub = new MyHub();
            hub.Send("", "");
            return Json(result.Model, JsonRequestBehavior.AllowGet);

        }
        public JsonResult GetMonitoringProfileCombinationChart(string FromTime, string ToTime)
        {
            BusinessLogicReturn result = new ProcessBusinessLogic.Logic().GetMonitoringProfileCombinationChart(FromTime, ToTime);
            return Json(result.Model, JsonRequestBehavior.AllowGet);
        }
    }
    public class MyHub : Hub
    {
        IHubContext context = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
        public void Send(string name, string message)
        {

            BusinessLogicReturn result = new ProcessBusinessLogic.Logic().GetMonitoringProfileLiveLogChart(null, null, null);
            context.Clients.All.addMessage(result.Model);
        }
        public void test()
        {

            BusinessLogicReturn result = new ProcessBusinessLogic.Logic().GetMonitoringProfileLiveLogChart(null, null, null);
            context.Clients.All.addMessage(result.Model);

        }

    }
公共抽象类监视ProfileLogChartController:Croem.NotificationManager.Website.Base.BaseController.BaseController
{
公共行动结果索引()
{
BusinessLogicReturn结果=新流程BusinessLogic.Logic().GetRegisteredContexts();
返回基数。跨血小板作用(结果);
}
公共行动结果LiveMonitoringProfileLogChart()
{
返回视图();
}
公共行动结果测试()
{
返回视图();
}
**下面是控制器代码的其余部分,我们的重点应该放在这里**
公共JsonResult GetMonitoringProfileLogChart(字符串FromDate、字符串ToDate、int-ContextId)
{
BusinessLogicReturn result=new ProcessBusinessLogic.Logic().GetMonitoringProfileLogChart(FromDate、ToDate、ContextId);
返回Json(result.Model、JsonRequestBehavior.AllowGet);
}
公共JsonResult GetMonitoringProfileLiveLogChart(字符串FromTime、字符串ToTime、字符串DataMinutes)
{
BusinessLogicReturn result=new ProcessBusinessLogic.Logic().GetMonitoringProfileLiveLogChart(FromTime、ToTime、DataMinutes);
IHubContext context=GlobalHost.ConnectionManager.GetHubContext();
context.Clients.All.addMessage(result.Model);
var hub=新的MyHub();
hub.Send(“,”);
返回Json(result.Model、JsonRequestBehavior.AllowGet);
}
公共JsonResult GetMonitoringProfileCombinationChart(string FromTime,string ToTime)
{
BusinessLogicReturn result=new ProcessBusinessLogic.Logic().GetMonitoringProfileCombinationChart(FromTime,ToTime);
返回Json(result.Model、JsonRequestBehavior.AllowGet);
}
}
公共类MyHub:Hub
{
IHubContext context=GlobalHost.ConnectionManager.GetHubContext();
公共无效发送(字符串名称、字符串消息)
{
BusinessLogicReturn result=new ProcessBusinessLogic.Logic().GetMonitoringProfileLiveLogChart(null,null,null);
context.Clients.All.addMessage(result.Model);
}
公开无效测试()
{
BusinessLogicReturn result=new ProcessBusinessLogic.Logic().GetMonitoringProfileLiveLogChart(null,null,null);
context.Clients.All.addMessage(result.Model);
}
}
用于映射服务器url的控制台应用程序

class Program
{
    static void Main(string[] args)
    {
        string info = LoggingServer.Open();
        Console.WriteLine(info);

        string url = "http://localhost:8080";
        using (WebApp.Start<Startup>(url))
        {
            Console.WriteLine("Server running on {0}", url);
            var hubs = new Croem.NotificationManager.Website.Base.Controllers.MyHub();
            Console.ReadLine();
        }
        LoggingServer.Close();
    }
    class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // Turn cross domain on 
            var config = new HubConfiguration { EnableCrossDomain = true };

            // This will map out to http://localhost:8080/signalr by default
            app.MapHubs(config);
        }
    }

}
类程序
{
静态void Main(字符串[]参数)
{
string info=LoggingServer.Open();
控制台写入线(信息);
字符串url=”http://localhost:8080";
使用(WebApp.Start(url))
{
WriteLine(“在{0}上运行的服务器”,url);
var hubs=new Croem.NotificationManager.Website.Base.Controllers.MyHub();
Console.ReadLine();
}
LoggingServer.Close();
}
类启动
{
公共无效配置(IAppBuilder应用程序)
{
//打开跨域
var config=new-HubConfiguration{EnableCrossDomain=true};
//这将映射到http://localhost:8080/signalr 默认情况下
app.MapHubs(配置);
}
}
}
客户端页面

<!DOCTYPE html>
<html>
<head>
    <title>SignalR Live Chat</title>

</head>
<body>
    <div class="container">
        <input type="text" id="message" />
        <input type="button" id="sendmessage" value="Send" />
        <input type="hidden" id="displayname" />
        <strong>Error Count</strong>
        <input type="text" id="Error_count" value="0" />
        <ul id="discussion"></ul>
    </div>
    <!--Script references. -->
    <!--Reference the jQuery library. -->
    <script src="Scripts/jquery-1.7.1.min.js"></script>
    <!--Reference the SignalR library. -->
    <script src="Scripts/jquery.signalR-1.1.3.js"></script>
    <!--Reference the autogenerated SignalR hub script. -->
    <script src="http://localhost:8080/signalr/hubs"></script>
    <!--Add script to update the page and send messages.-->
    <script type="text/javascript">
        var chart;
        var timer;
        $(function () {



                Highcharts.setOptions({
                    global: {
                        useUTC: false
                    }
                });
                //Set the hubs URL for the connection
                $.connection.hub.url = "http://localhost:8080/signalr";

                // Declare a proxy to reference the hub.
                var chat = $.connection.myHub;

                // Create a function that the hub can call to broadcast messages.
                chat.client.addMessage = function (data) {

                    dataRecieved(data);
                    clearInterval(timer);
                    timer = setInterval(function () {
                        dataNotRecieved();
                    }, 10000);
                };
                $.connection.hub.logging = true;
                $.connection.hub.start().done(function () {
                    $('#sendmessage').click(function () {
                        // Call the Send method on the hub.
                        chat.server.send($('#displayname').val(), $('#message').val());
                        // Clear text box and reset focus for next comment.
                        $('#message').val('').focus();
                    });
                });

                $.ajax({
                    type: "GET",
                    dataType: "json",
                    data: {
                        DataMinutes: 5,
                        FromTime: null,
                        ToTime: null
                    },
                    url: "@Url.Action("GetMonitoringProfileLiveLogChart", "MonitoringProfileLogChart")",
                    success: function (data) {
                        chart = new Highcharts.Chart({
                            chart: {
                                renderTo: 'container',
                                type: 'spline',
                                animation: Highcharts.svg, // don't animate in old IE
                                marginRight: 10,


                            },
                            title: {
                                text: 'Live Profile Monitoring'
                            },
                            xAxis: {
                                type: 'datetime',

                                tickPixelInterval: 150
                            },
                            yAxis: {
                                title: {
                                    text: 'Value'
                                },
                                plotLines: [{
                                    value: 0,
                                    width: 1,
                                    color: '#808080'
                                }]
                            },
                            tooltip: {
                                formatter: function () {
                                    return '<b>' + this.series.name + '</b><br/>' +
                                    Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
                                    Highcharts.numberFormat(this.y, 2);
                                }
                            },
                            legend: {
                                enabled: true
                            },
                            exporting: {
                                enabled: false
                            },
                            series: data.series,

                        });
                    }
                });


                timer = setInterval(function () {
                    dataNotRecieved();
                }, 10000);

                function dataNotRecieved() {
                    var shift = false;
                    for (var j = 0; j < chart.series.length; j++) {
                        if (chart.series[j].data.length < 50) {
                            shift = false;

                        }
                        else {
                            shift = true;
                        }
                        chart.series[j].addPoint([new Date().getTime() - 4 * 1000 * 60 * 60, 0], true, shift);
                    }

                }
                function dataRecieved(data) {
                    // checking if series exsist in chart but is not in data coming from ajax call . and if it does not exsist add that series point with zero
                    var series_name_exist = 0;
                    var series_exist = 0;
                    var index = 0;
                    var shift = false;
                    var length = chart.series.length;
                    for (var j = 0; j < chart.series.length; j++) {

                        for (var k = 0; k < data.series.length; k++) {
                            if (chart.series[j].name == data.series[k].name) {
                                series_name_exist = 1;
                                break;
                            }

                        }
                        if (series_name_exist == 0) {

                            if (chart.series[j].data.length < 50) {
                                shift = false;

                            }
                            else {
                                shift = true;
                            }
                            chart.series[j].addPoint([new Date().getTime() - 4 * 1000 * 60 * 60, 0], true, shift);
                        }
                        else {
                            series_name_exist = 0;
                        }



                    }
                    //  if series exist add point otherwise add series
                    for (var k = 0; k < data.series.length; k++) {

                        for (var j = 0; j < chart.series.length; j++) {
                            if (chart.series[j].name == data.series[k].name) {
                                series_exist = 1;
                                index = j;
                                break;
                            }

                        }
                        if (series_exist == 1) {

                            if (chart.series[index].data.length < 50) {
                                shift = false;

                            }
                            else {
                                shift = true;
                            }
                            //chart.series[index].addPoint([data.series[k].time, data.series[k].count], true, shift);
                            chart.series[index].addPoint([new Date().getTime() - 4 * 1000 * 60 * 60, data.series[k].count], true, shift);
                            series_exist = 0;

                        }

                        else {

                            chart.addSeries({ name: '' + data.series[k].name + '', data: [] });
                            //chart.series[length].addPoint([data.series[k].time, data.series[k].count], true);
                            chart.series[length].addPoint([new Date().getTime() - 4 * 1000 * 60 * 60, data.series[k].count], true);
                            length = length + 1;
                        }


                    }
                }



                $('#message').focus();
                // Start the connection.


        });

    </script>
    <div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>

</body>
</html>

信号员现场聊天
错误计数
    var图; 无功定时器; $(函数(){ Highcharts.setOptions({ 全球:{ useUTC:false } }); //设置连接的集线器URL $.connection.hub.url=”http://localhost:8080/signalr"; //声明代理以引用中心。 var chat=$.connection.myHub; //创建一个中心可以调用以广播消息的函数。 chat.client.addMessage=函数(数据){ 接收到的数据(数据); 清除间隔(计时器); 定时器=设置间隔(函数(){ DataNotReceived(); }, 10000); }; $.connection.hub.logging=true; $.connection.hub.start().done(函数(){ $('#sendmessage')。单击(函数(){ //在集线器上调用Send方法。 chat.server.send($('#displayname').val(),$('#message').val()); //清除文本框并重置下一条注释的焦点。 $('#message').val('.focus(); }); }); $.ajax({ 键入:“获取”, 数据类型:“json”, 数据:{ 会议记录:5,, FromTime:null, ToTime:null }, url:@url.Action(“GetMonitoringProfileLiveLogChart”、“MonitoringProfileLogChart”), 成功:功能(数据){ 图表=新的高点图表。图表({ 图表:{ renderTo:'容器', 类型:“样条线”, 动画:Highcharts.svg,//不要在旧IE中设置动画 marginRight:10, }, 标题:{ 文本:“实时配置文件监视” }, xAxis:{ 键入:“日期时间”, 打上钩
    chat.client.addMessage = function() {...}
    
    $.connection.hub.start().done(function() {...});