我试图通过定义connectionID将一些对象从信号器中心传递到客户端但是这似乎不起作用。因为我收到错误Microsoft.AspNet.SignalR.Hubs.IHubCallerConnectionContext<object>' does not contain a definition for 'Client'
这就是我调用代码的方式:
Clients.Client(initiatedBrowserId).mibChoice(connectionId, queriesDictionary, deviceID);
这是所要求的整个方法:
public void DetectDevice(dynamic message)
{
var connectionId = Context.ConnectionId;
//now we get the connectionID from the table.
var connectionObj = ConnectionTable[connectionId];
//we now check whether this is a pathfinder or browser client
if (connectionObj.clientType == "pathfinder")
{
/*The pathfinder initiated the request and so this means the message should be forwarded to the browser client
that requested this resource*/
var deviceDiscoveredNotification = JsonConvert.DeserializeObject<Dictionary<string, string>>(message);
var initiatedBrowserId = deviceDiscoveredNotification["browserConnectionID"];
//message should contain browser client connection id
if (deviceDiscoveredNotification["data"] == "FOUND")
{
//We can base these around device type
//snmp
var mibNames = db.OIDs.Select(oid => oid.Mibname).Distinct().ToList();
//wmi
var wmiQueries = db.WmiQueries.Select(wmi => wmi.Query).Where(wmi => !wmi.Contains("*")).Distinct().ToList();
var wmiList = new List<ScheduledMonitoring>();
var mibList = mibNames.Select(mib => new ScheduledMonitoring(mib, 60)).ToList();
mibList.AddRange(wmiQueries.Select(wmi => new ScheduledMonitoring(wmi, 60)));
//Let's construct a data structure that is easy to parse and traverse
var queriesDictionary = new Dictionary<string, List<ScheduledMonitoring>>();
queriesDictionary.Add("snmp", mibList);
queriesDictionary.Add("wmi", wmiList);
// pass the pathfinderID along with the mibnames, the pathfinder connectionID
// needs to also be passed back to the MonitorFeatures method so we know specifically
var deviceID = deviceDiscoveredNotification["deviceID"];
try
{
Clients.Client(initiatedBrowserId).mibChoice(connectionId, queriesDictionary, deviceID);
}
catch (Exception e)
{
throw e;
}
}
}
我知道存在这种连接,因为我可以在我的字典中看到它维护什么connectionID映射到谁,如果他们要断开它会将它们从字典中删除