Esempio n. 1
0
 //--- Class Methods ---
 public static DekiContext GetContext(DreamContext dreamContext) {
     var context = dreamContext.GetState<DekiContext>();
     if(context == null) {
         throw new DekiContextAccessException("DekiContext.Current is not set, because the current DreamContext does not contain a reference");
     }
     return context;
 }
Esempio n. 2
0
 private DreamMessage ExceptionTranslation(DreamContext context, Exception exception)
 {
     if(exception is CustomException) {
         _log.DebugFormat("caught custom exception");
         if(context.IsTaskEnvDisposed) {
             return DreamMessage.BadRequest("context is disposed");
         }
         if(ContextVar == null) {
             return DreamMessage.BadRequest("context var wasn't set");
         }
         if(ContextVar != context.GetState<ContextLifeSpan>()) {
             return DreamMessage.BadRequest("context vars didn't match");
         }
         return DreamMessage.Ok();
     }
     return null;
 }
Esempio n. 3
0
 private Yield Epilogue(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     _log.Debug("in epilogue");
     if(request.IsSuccessful && "disposal".EqualsInvariant(context.Feature.Signature) && context.IsTaskEnvDisposed) {
         throw new Exception("context disposed in epilogue");
     }
     if("prologueepilogue".EqualsInvariant(context.Feature.Signature)) {
         _log.DebugFormat("checking prologue data for epilogue in Env #{0}", TaskEnv.Current.GetHashCode());
         if(string.IsNullOrEmpty(PrologueData)) {
             throw new Exception("no prologue data in slot");
         }
         if(PrologueData != context.GetState<string>("prologue")) {
             throw new Exception("state from prologue didn't make it to epilogue");
         }
     } else if("epilogue".EqualsInvariant(context.Feature.Signature)) {
         _log.DebugFormat("checking epilogue data for epilogue in Env #{0}", TaskEnv.Current.GetHashCode());
         if(string.IsNullOrEmpty(EpilogueData)) {
             throw new Exception("no epilogue data in slot");
         }
         if(EpilogueData != context.GetState<string>("epilogue")) {
             throw new Exception("state from feature didn't make it to epilogue");
         }
     }
     response.Return(request);
     yield break;
 }
Esempio n. 4
0
 public Yield Spawn(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     var guid = Guid.NewGuid();
     ContextVar = new ContextLifeSpan(guid);
     context.SetState(guid);
     context.SetState(ContextVar);
     ContextLifeSpan capturedInner = null;
     yield return Async.Fork(() =>
     {
         var innerContextVar = DreamContext.Current.GetState<ContextLifeSpan>();
         capturedInner = innerContextVar;
         if(innerContextVar == ContextVar) {
             throw new Exception("spawned context instances were same");
         }
         if(innerContextVar.Guid != guid) {
             throw new Exception("spawned context guid is wrong");
         }
         if(innerContextVar.IsDisposed) {
             throw new Exception("subcall: context is disposed");
         }
     }, new Result());
     var contextVar = context.GetState<ContextLifeSpan>();
     if(contextVar == null) {
         throw new Exception("context instance is gone");
     }
     if(capturedInner == contextVar) {
         throw new Exception("outer instance was changed to inner");
     }
     if(!capturedInner.IsDisposed) {
         throw new Exception("inner instance wasn't disposed after closure completion");
     }
     if(contextVar.Guid != guid) {
         throw new Exception("context guid is wrong");
     }
     if(contextVar != ContextVar) {
         throw new Exception("context instance changed");
     }
     if(contextVar.IsDisposed) {
         throw new Exception("context is disposed");
     }
     response.Return(DreamMessage.Ok());
     yield break;
 }
Esempio n. 5
0
 public Yield CheckPrologue(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     _log.DebugFormat("checking prologue data in Env #{0}", TaskEnv.Current.GetHashCode());
     if(string.IsNullOrEmpty(PrologueData)) {
         throw new Exception("no prologue data in slot");
     }
     if(PrologueData != context.GetState<string>("prologue")) {
         throw new Exception("state from prologue didn't make it to feature");
     }
     response.Return(DreamMessage.Ok());
     yield break;
 }
Esempio n. 6
0
 public Yield CallPlug(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     _log.Debug("callplug start");
     var guid = Guid.NewGuid();
     ContextVar = new ContextLifeSpan(guid);
     context.SetState(guid);
     _log.Debug("setting disposable state");
     context.SetState(ContextVar);
     Result<DreamMessage> sub;
     _log.Debug("calling plug");
     yield return sub = Self.At("calledplug").GetAsync();
     _log.Debug("return from plug");
     if(!sub.Value.IsSuccessful) {
         response.Return(sub.Value);
     }
     var contextVar = context.GetState<ContextLifeSpan>();
     if(contextVar == null) {
         throw new Exception("context instance is gone");
     }
     if(contextVar.Guid != guid) {
         throw new Exception("context guid is wrong");
     }
     if(contextVar != ContextVar) {
         throw new Exception("context instance changed");
     }
     if(contextVar.IsDisposed) {
         throw new Exception("context is disposed");
     }
     _log.Debug("callplug return");
     response.Return(DreamMessage.Ok());
     _log.Debug("callplug end");
     yield break;
 }
Esempio n. 7
0
 public Yield CalledPlug(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     _log.Debug("calledplug start");
     var contextVar = context.GetState<ContextLifeSpan>();
     if(contextVar != null) {
         throw new Exception("called plug context instance already exists");
     }
     context.SetState(new ContextLifeSpan(Guid.NewGuid()));
     _log.Debug("calledplug return");
     response.Return(DreamMessage.Ok());
     _log.Debug("calledplug end");
     yield break;
 }
Esempio n. 8
0
 public Yield CallCoroutine(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     _log.Debug("callcoroutine start");
     var guid = Guid.NewGuid();
     ContextVar = new ContextLifeSpan(guid);
     context.SetState(guid);
     context.SetState(ContextVar);
     if(context.GetState<ContextLifeSpan>() == null) {
         throw new Exception("context instance was never set");
     }
     _log.DebugFormat("callcoroutine calling coroutine within Env #{0}", TaskEnv.Current.GetHashCode());
     yield return Coroutine.Invoke(SubCall, new Result());
     var contextVar = context.GetState<ContextLifeSpan>();
     _log.DebugFormat("callcoroutine coroutine returned within Env #{0}", TaskEnv.Current.GetHashCode());
     if(contextVar == null) {
         throw new Exception("context instance is gone");
     }
     if(contextVar.Guid != guid) {
         throw new Exception("context guid is wrong");
     }
     if(contextVar != ContextVar) {
         throw new Exception("context instance changed");
     }
     if(contextVar.IsDisposed) {
         throw new Exception("context is disposed");
     }
     response.Return(DreamMessage.Ok());
     yield break;
 }
Esempio n. 9
0
 private Yield EpilogueStats(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
     var sw = context.GetState<Stopwatch>("stats-stopwatch");
     sw.Stop();
     _log.InfoFormat("Finished [{0}:{1}] [{2}] {3:0}ms", context.Verb, context.Uri.Path, request.Status.ToString(), sw.ElapsedMilliseconds);
     response.Return(request);
     yield break;
 }