2016-03-23 15 views
1

SinyalR hub'larında özel hata günlüğü kaydetmem gerekiyor. Bu HubPipelineModule gelen devralır ve bu benim göbekHubPipelineModule OnIncomingError olayından hub üzerinde çağrı yöntemi

public class FooHub : Hub 
{ 
    public void MethodWithException() 
    { 
     throw new Exception(); 
    } 

    public void FooMethod() 
    { 

    } 
} 

bu

GlobalHost.HubPipeline.AddModule(new ErrorModule()); 

gibi Başlangıçta kayıtlı olacak ErrorModule oluşturarak yapılır Ve bu benim modüldür edilebilir

public class ErrorModule : HubPipelineModule 
{ 
    protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext) 
    { 
     //call foo method on foo hub 

     //log error 
    } 
} 

MethodWithException() çağrıldığını bildirelim. OnIncomingError olayını çağırdığı merkezde FooMethod() öğesini çağırmak mümkün mü? Böyle bir şey ile

cevap

1

:

protected override void OnIncomingError(ExceptionContext exceptionContext, 
               IHubIncomingInvokerContext invokerContext) 
     { 
      dynamic caller = invokerContext.Hub.Clients.Caller; 
      caller.ExceptionHandler(exceptionContext.Error.Message); 

      //log something here 
      Debug.WriteLine(exceptionContext.Error.Message); 
     } 

DÜZENLEME

belirli yapabileceğiniz göbek yöntemini çağırmak için:

protected override void OnIncomingError(ExceptionContext exceptionContext, 
               IHubIncomingInvokerContext invokerContext) 
     { 
      var hub = (invokerContext.Hub as HubType); // 
      hub.MyMethod("myparam","mysecondparam"); 

      //log something here 
      Debug.WriteLine(exceptionContext.Error.Message); 
     } 

Tam kodunu buraya bulabilirsiniz: How to handle SignalR server exception at client?

+0

Üzgünüz, ama metodu aramak istiyorum d işaretli istisna hub üzerinde tanımlı –

+0

Göbek örneğinizi almak istiyorsanız, ilgili hub'ı atabilirsiniz, cevabımı güncelleyeceğim. –

İlgili konular