public SignalFuture Write(byte[] buffer, int offset, int count) { if (IsDisposed) { throw new ObjectDisposedException("SocketDataAdapter"); } var f = new SignalFuture(); if (!_Socket.Connected) { if (ThrowOnDisconnect) { f.Fail(new SocketDisconnectedException()); } else { f.Complete(); } } else { if (ThrowOnFullSendBuffer && IsSendBufferFull()) { throw new SocketBufferFullException(); } SocketError errorCode; _Socket.BeginSend(buffer, offset, count, SocketFlags.None, out errorCode, _WriteCallback, f); } return(f); }
public IEnumerator <object> PlaySound(ProcessInfo process, string pythonModuleName, string filename) { string scriptPath = Path.GetDirectoryName(Application.ExecutablePath); if (pythonModuleName != null) { ScriptName sn; if (Program.PythonModuleToScript.TryGetValue(pythonModuleName, out sn)) { var fn = Program.FindScript(sn); if (fn != null) { scriptPath = fn.Directory; } } } var soundPath = Path.Combine(scriptPath, filename); if (!File.Exists(soundPath)) { LogPrint(process, "PlaySound request failed because the sound '{0}' was not found.", soundPath); yield break; } SoundPlayer sp = new SoundPlayer(); var f = new SignalFuture(); sp.SoundLocation = soundPath; sp.LoadCompleted += (s, e) => { if (e.Error != null) { f.Fail(e.Error); } else { f.Complete(); } }; sp.LoadAsync(); yield return(f); if (f.Failed) { LogPrint(process, "PlaySound request failed because the sound '{0}' could not be loaded: {1}", soundPath, f.Error); yield break; } Console.WriteLine("Playing {0}...", soundPath); using (sp) yield return(Future.RunInThread(sp.PlaySync)); Console.WriteLine("Done playing {0}.", soundPath); }
private void _FlushOnComplete(IFuture f) { if (Parent.IsDisposed) { Result.Dispose(); return; } var e = f.Error; if (e != null) { Result.Fail(e); } else { StepString(); } }
public static SignalFuture AsyncWrite(this Stream stream, byte[] buffer, int offset, int count) { var f = new SignalFuture(); try { stream.BeginWrite(buffer, offset, count, (ar) => { try { lock (stream) stream.EndWrite(ar); f.Complete(); } catch (FutureHandlerException) { throw; } catch (Exception ex) { f.Fail(ex); } }, stream); } catch (Exception ex) { f.Fail(ex); } return(f); }
public static SignalFuture AsyncWrite (this Stream stream, byte[] buffer, int offset, int count) { #if XBOX return Future.RunInThread(() => stream.Write(buffer, offset, count)); #else var f = new SignalFuture(); try { stream.BeginWrite(buffer, offset, count, (ar) => { try { lock (stream) stream.EndWrite(ar); f.Complete(); } catch (FutureHandlerException) { throw; } catch (Exception ex) { f.Fail(ex); } }, stream); } catch (Exception ex) { f.Fail(ex); } return f; #endif }
public SignalFuture Flush() { var f = new SignalFuture(); WaitCallback wc = (state) => { var stream = (Stream)state; try { stream.Flush(); f.Complete(); } catch (Exception ex) { f.Fail(ex); } }; ThreadPool.QueueUserWorkItem(wc, _Stream); return(f); }
public SignalFuture Write(byte[] buffer, int offset, int count) { if (IsDisposed) throw new ObjectDisposedException("SocketDataAdapter"); var f = new SignalFuture(); if (!_Socket.Connected) { if (ThrowOnDisconnect) f.Fail(new SocketDisconnectedException()); else f.Complete(); } else { if (ThrowOnFullSendBuffer && IsSendBufferFull()) throw new SocketBufferFullException(); SocketError errorCode; _Socket.BeginSend(buffer, offset, count, SocketFlags.None, out errorCode, _WriteCallback, f); } return f; }
public SignalFuture Flush() { var f = new SignalFuture(); WaitCallback wc = (state) => { var stream = (Stream)state; try { stream.Flush(); f.Complete(); } catch (Exception ex) { f.Fail(ex); } }; ThreadPool.QueueUserWorkItem(wc, _Stream); return f; }