public static Task WaitForCoroutine(ICoroutineThread toRun) { Exception problem = null; var onError = new Action <Exception>((ex) => { problem = ex; }); var cmanager = (ICoroutinesManager)_createMethod.Invoke(null, new object[] { }); cmanager.StartCoroutine(toRun, onError); var waitSlim = new ManualResetEventSlim(false); var task = new Task(() => { while ((long)RunningStatus.NotRunning > (long)toRun.Status) { waitSlim.Wait(50); } while (!toRun.Status.Is(RunningStatus.NotRunning)) { waitSlim.Wait(50); } if (problem != null) { throw new Exception("Error running subtask", problem); } }, TaskCreationOptions.AttachedToParent); task.Start(); return(task); }
private static IEnumerable <ICoroutineResult> CoroutineWaiter(ICoroutineThread coroutine) { while (!coroutine.Status.Is(RunningStatus.NotRunning)) { yield return(CoroutineResult.Wait); } }
public ICoroutineResult Send <T>(ICoroutineThread caller, T message, Action <IMessageResult> action = null, TimeSpan?timeout = null) where T : IMessage { throw new NotImplementedException(); /*var msTimeoutLength = timeout == null * ? -1 * : timeout.Value.Ticks/TimeSpan.TicksPerMillisecond; * var msTimeout = timeout == null * ? -1 * : DateTime.UtcNow.Ticks/TimeSpan.TicksPerMillisecond + msTimeoutLength; * * var msRemove = timeout == null ? -1 : msTimeout*2; * _messages.Enqueue(message); * var result = new MessageCoroutineResult * { * ResultCallback = action, * OriginalMesssage = message, * Caller = caller, * ExpireOn =msTimeout, * RemoveOn = msRemove, * TimeoutLength = msTimeoutLength * }; * _responses.Add(message.Id, result); * return result;*/ }
public void StartCoroutine(ICoroutineThread coroutineThreadToStart, Action <Exception> onError = null) { var loggable = coroutineThreadToStart as ILoggable; if (loggable != null) { loggable.Log = Log; } _coroutinesQueue.Enqueue(new CoroutineQueueContent(coroutineThreadToStart, onError)); }
public static IOnComplete RunCoroutine(ICoroutineThread coroutine, string name = null) { var result = new FluentResultBuilder { Type = FluentResultType.CoroutineFunction, Coroutine = coroutine, InstanceName = name }; return(result); }
public void Register(ICoroutineThread coroutineThreadBase) { var typeName = typeof(IMessageHandler).Name; var type = coroutineThreadBase.GetType(); foreach (var receiver in GetAllHandledMessageTypes(type, typeName)) { if (!_handlers.ContainsKey(receiver)) { _handlers.Add(receiver, new List <IMessageHandler>()); } // ReSharper disable once SuspiciousTypeConversion.Global _handlers[receiver].Add((IMessageHandler)coroutineThreadBase); } }
public void Unregister(ICoroutineThread coroutineThreadBase) { var typeName = typeof(IMessageHandler).Name; var type = coroutineThreadBase.GetType(); foreach (var receiver in GetAllHandledMessageTypes(type, typeName)) { if (!_handlers.ContainsKey(receiver)) { continue; } // ReSharper disable once SuspiciousTypeConversion.Global _handlers[receiver].Remove((IMessageHandler)coroutineThreadBase); if (_handlers[receiver].Count == 0) { _handlers.Remove(receiver); } } }
public IEnumerable <ICoroutineResult> RunEnumerator() { var moveNext = true; var timeout = DateTime.UtcNow + Timeout; while (moveNext) { ICoroutineResult current; try { if (DateTime.UtcNow > timeout) { throw new CoroutineTimeoutException(string.Format("Timeout on '{0}'", InstanceName)); } moveNext = Enumerator.MoveNext(); if (!moveNext) { if (_coroutine != null) { _coroutine.OnDestroy(); _coroutine = null; } break; } current = Enumerator.Current; if (current.ResultType == ResultType.Return) { if (OnCompleteWithResults != null) { OnCompleteWithResults(current); } break; } if (current.ResultType == ResultType.YieldReturn) { moveNext = OnEachItem == null || OnEachItem(current); current = CoroutineResult.Wait; } else if (current.ResultType == ResultType.YieldBreak) { Enumerator.MoveNext(); break; } } catch (Exception ex) { if (OnErrorDo != null) { if (OnErrorDo(ex)) { if (_coroutine != null) { _coroutine.OnDestroy(); _coroutine = null; } break; } } if (_coroutine != null) { _coroutine.OnDestroy(); _coroutine = null; } throw new CoroutineTimeoutException("Error running ", ex); } yield return(current); } if (OnCompleteWithoutResultDo != null) { try { OnCompleteWithoutResultDo(); } catch (Exception ex) { if (OnErrorDo != null) { OnErrorDo(ex); } } } }
public void StartCoroutine(ICoroutineThread coroutineThreadToStart, Action <Exception> onError = null) { _runner.StartCoroutine(coroutineThreadToStart, onError); }
public CoroutineInstance(ICoroutineThread coroutineThread, Action <Exception> onError) { Coroutine = coroutineThread; OnError = onError; }
public CoroutineQueueContent(ICoroutineThread coroutine, Action <Exception> onError) { Coroutine = coroutine; OnError = onError; }
public CoroutineMessageBusRegister(ICoroutineThread coroutineThread, Type messageType) { Coroutine = coroutineThread; MessageType = messageType; }
public void Unregister <T>(ICoroutineThread coroutineThreadBase) where T : IMessage { _commands.Enqueue(new CoroutineMessageBusUnregister(coroutineThreadBase, typeof(T))); }
public void Initialize() { if (_context.Request.Url == null) { throw new HttpException(500, string.Format("Missing url.")); } string requestPath; if (_context.Request.Url.IsAbsoluteUri) { requestPath = _context.Request.Url.LocalPath.Trim(); } else { requestPath = _context.Request.Url.ToString().Trim(); } var relativePath = requestPath; if (requestPath.StartsWith(_virtualDir.TrimEnd('/'))) { if (_virtualDir.Length >0 ) { relativePath = requestPath.Substring(_virtualDir.Length - 1); } } for (int index = 0; index < _pathProviders.Count; index++) { var pathProvider = _pathProviders[index]; var isDir = false; if (pathProvider.Exists(relativePath, out isDir)) { var renderer = FindRenderer(ref relativePath, pathProvider, isDir); if (renderer == null) { _coroutine = new StaticItemCoroutine( relativePath, pathProvider, _context, HttpListenerExceptionHandler); } else { _coroutine = new RenderizableItemCoroutine( renderer, relativePath, pathProvider, _context, HttpListenerExceptionHandler, _model, _modelStateDictionary, _viewBag); } return; } } throw new HttpException(404, string.Format("Not found '{0}'.", _context.Request.Url)); }