2017-07-13 8 views
0

ModRalを更新するためにSignalRアップデートが私たちのページに届くと、アイテム名が変更され、スクリプトが壊れているようです。SignalRアップデートにより、ページ上のレイアウトとスクリプトが破損する

簡単な概要:私たちのSignalRアップデートはウェブサイトに送られますが、データ自体の名前は無効です。 更新されると、私たちのアイテムは不正な形式の名前で更新されます。私たちの名前は、最初にSignalRによって更新されるべきではありません。私たちのコードでは、その名前への参照を見つけることができません。 モーダルを閉じると、HighchartsとAngularスクリプトがコンソールエラーを投げます。

サーバーサイドコード:

public partial class Device 
{ 
if (device != null) 
{ 
    if ((Enumerables.DeviceType)device.Type == Enumerables.DeviceType.Store) 
    SignalrClient.UpdateStore(device.DeviceID); 
    else // check if need to update a modal on the dashboard 
    { 
    foreach (var key in SignalrClient.DevicesDictionary.Keys) 
    { 
    var devices = SignalrClient.DevicesDictionary[key]; 
    if (devices != null) 
    { 
    if (devices.Contains(device.DeviceID)) 
     SignalrClient.UpdateModal(key, device.DeviceID); 
    } 
    } 
    } 
} 
} 

class SignalrClient 
{ 
public static async Task Start() 
{ 
    if (_hubConnection == null || _hubConnection.State == ConnectionState.Disconnected) 
    { 
    _hubConnection = new HubConnection("http://stevessiteofamazingboats.net/"); 
    _dashboardHubProxy = _hubConnection.CreateHubProxy("DashboardHub"); 
    _dashboardHubProxy.On("OnRegisterDevice", new Action<string, int>(OnRegisterDevice)); 
    _dashboardHubProxy.On("OnDeregisterDevices", new Action<string>(OnDeregisterDevices)); 
    _dashboardHubProxy.On("OnDeregisterDevice", new Action<string, int>(OnDeregisterDevice)); 
    await _hubConnection.Start(); 
    } 
} 
public static async void UpdateModal(string connectionId, int deviceId) 
{ 
    await Start(); 
    if (_hubConnection.State == ConnectionState.Connected) 
    await _dashboardHubProxy.Invoke("UpdateModal", new object[] { connectionId, deviceId }); 
    } 
} 

public class DashboardHub : Hub 
{ 
private static string EventHubConnectionId {get;set;} 
private AlarmDBEntities db = Utils.DbContext; 

public void UpdateModal(string connectionId, int deviceId) 
{ 
    var db = Utils.DbContext; 
    var device = db.Device.Find(deviceId); 
    var modal = new Portal.DeviceModalViewModel() 
    { 
    DeviceId = deviceId, 
    SuctionGroups = device.Device1.Where(x => (Enumerables.DeviceType)x.Type == Enumerables.DeviceType.SuctionGroup).Select(x => new DeviceModalViewModel.SGNode() 
    { 
    SubChildren = x.Device1.Where(y => (Enumerables.DeviceType)y.Type == Enumerables.DeviceType.Compressor).Select(y => new DeviceModalViewModel.DeviceNode() 
    { 
    DeviceId = y.DeviceID, 
    Name = y.Name, 
    Amp = db.Property.Where(z => z.Name == "Amps" && z.DeviceID == y.DeviceID).OrderByDescending(z => z.CreatedOn).Select(z => z.Value).FirstOrDefault() 
    }).OrderBy(y => y.Name).ToList() 
    }).OrderBy(x => x.Name).ToList(), 
}; 
} 

クライアント側のJavaScript。 ViewModelには、不正な形式の名前が含まれていますJSFiddle で表示可能https://jsfiddle.net/wmqdyv8r/

は、これが私たちの角度コンソールエラーです:私たちはSignalRのリフレッシュ後にチャートを開こうと

angular.min.js:6 Uncaught Error: [ng:areq]  
http://errors.angularjs.org/1.5.7/ng/areq? 
p0=HeaderController&p1=not%20a%20function%2C%20got%20undefined 
at angular.min.js:6 
at sb (angular.min.js:22) 
at Qa (angular.min.js:23) 
at angular.min.js:89 
at ag (angular.min.js:72) 
at m (angular.min.js:64) 
at g (angular.min.js:58) 
at g (angular.min.js:58) 
at g (angular.min.js:58) 
at g (angular.min.js:58) 

angular.min.js:312 WARNING: Tried to load angular more than once. 

これはエラーをHighchartsアップを示しています。

store.js:856 Uncaught TypeError: $(...).highcharts is not a function 
at Object.success (store.js:856) 
at c (<anonymous>:1:132617) 
at Object.fireWith [as resolveWith] (<anonymous>:1:133382) 
at b (<anonymous>:1:168933) 
at XMLHttpRequest.<anonymous> (<anonymous>:1:173769) 

また、モーダルを閉じた後、私たちのメインページが更新され、今、このエラーがスローされます:

Exception: Sequence contains no elements 
Type: System.InvalidOperationException 

主な懸念は、更新イベントが何かを壊していることです。私はそれが関連していると確信していますが、命名の問題は低い優先順位です。

+0

読む[、最小完全、かつ検証例を作成する方法](HTTPS:/

私がしなければならなかったすべてだったデバイスIDの下にここで見storeIDフィールドを追加いまいましい電車に従ってください/stackoverflow.com/help/mcve)。あなたのコードをトリミングし、実例を作ることができますか? jfiddleで? – morganfree

+0

JSFiddleをhttps://jsfiddle.net/wmqdyv8r/に追加しましたが、C#がなくても完全には機能しませんが、他の人には何が起こっているのかがわかります。 さらに詳しい情報を表示するために、ここにサーバー側のSignalRコードも追加されています。 – Steveo

答えて

0

問題が見つかりました。

この不正な名前は、実際の名前から最初の5文字を​​切り捨てていることが判明しています。

さらに深刻な問題として、スクリプトの破損も解決されました。 UpdateModalメソッドでは、スクリプトの1つがstoreIDフィールドとdeviceIDフィールドを探していました。 Chromeのjavascriptコンソールにログを出力した後、以前にUpdateModalメソッドの前に初期化されていたとしても、storeIDは常に0を返していました。

public void UpdateModal(string connectionId, int deviceId) 
{ 
var db = Utils.DbContext; 
var device = db.Device.Find(deviceId); 
var modal = new Portal.DeviceModalViewModel() 
{ 
    DeviceId = deviceId, 
    *THIS*-> StoreId = db.Device.Where(x => device.Name.Contains(x.Name.Replace("-Store", "")) && x.ParentID == null).Select(x => x.DeviceID).FirstOrDefault(), 
    SuctionGroups = device.Device1.Where(x => (Enumerables.DeviceType)x.Type == 
    Enumerables.DeviceType.SuctionGroup).Select(x => new 
    DeviceModalViewModel.SGNode() 
    { 
    SubChildren = x.Device1.Where(y => (Enumerables.DeviceType)y.Type == 
    Enumerables.DeviceType.Compressor).Select(y => new 
    DeviceModalViewModel.DeviceNode() 
    { 
    DeviceId = y.DeviceID, 
    *ALSO THIS*-> Name = "12345Comp " + y.Name.Substring(y.Name.Length - 2), 
    Amp = db.Property.Where(z => z.Name == "Amps" && z.DeviceID == y.DeviceID).OrderByDescending(z => z.CreatedOn).Select(z => z.Value).FirstOrDefault() 
    }).OrderBy(y => y.Name).ToList() 
    }).OrderBy(x => x.Name).ToList(), 
}; 
関連する問題