当前位置: 首页>>代码示例>>C#>>正文


C# DreamContext.GetState方法代码示例

本文整理汇总了C#中DreamContext.GetState方法的典型用法代码示例。如果您正苦于以下问题:C# DreamContext.GetState方法的具体用法?C# DreamContext.GetState怎么用?C# DreamContext.GetState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DreamContext的用法示例。


在下文中一共展示了DreamContext.GetState方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetContext

 //--- 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;
 }
开发者ID:heran,项目名称:DekiWiki,代码行数:8,代码来源:DekiContext.cs

示例2: ExceptionTranslation

 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;
 }
开发者ID:maximmass,项目名称:DReAM,代码行数:17,代码来源:DreamContextTests.cs

示例3: Epilogue

 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;
 }
开发者ID:maximmass,项目名称:DReAM,代码行数:26,代码来源:DreamContextTests.cs

示例4: Spawn

 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;
 }
开发者ID:maximmass,项目名称:DReAM,代码行数:43,代码来源:DreamContextTests.cs

示例5: CheckPrologue

 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;
 }
开发者ID:maximmass,项目名称:DReAM,代码行数:12,代码来源:DreamContextTests.cs

示例6: CallPlug

 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;
 }
开发者ID:maximmass,项目名称:DReAM,代码行数:33,代码来源:DreamContextTests.cs

示例7: CalledPlug

 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;
 }
开发者ID:maximmass,项目名称:DReAM,代码行数:13,代码来源:DreamContextTests.cs

示例8: CallCoroutine

 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;
 }
开发者ID:maximmass,项目名称:DReAM,代码行数:29,代码来源:DreamContextTests.cs

示例9: EpilogueStats

 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;
 }
开发者ID:heran,项目名称:DekiWiki,代码行数:7,代码来源:LuceneService.cs


注:本文中的DreamContext.GetState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。