Ejemplo n.º 1
0
Archivo: IO.cs Proyecto: sq/Libraries
        public SignalFuture Write(byte[] buffer, int offset, int count)
        {
            var f = new SignalFuture();

            _Stream.BeginWrite(buffer, offset, count, _WriteCallback, f);
            return(f);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        public SignalFuture Write(byte[] buffer, int offset, int count)
        {
#if XBOX
            return(Future.RunInThread(() => _Stream.Write(buffer, offset, count)));
#else
            var f = new SignalFuture();
            _Stream.BeginWrite(buffer, offset, count, _WriteCallback, f);
            return(f);
#endif
        }
Ejemplo n.º 5
0
Archivo: IO.cs Proyecto: sq/Libraries
        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);
        }
Ejemplo n.º 6
0
        public static SignalFuture WaitForProcessExit(Process process)
        {
            var exited = new SignalFuture();

            process.Exited += (s, e) =>
                              exited.Complete();

            if (process.HasExited)
            {
                try {
                    exited.Complete();
                } catch {
                }
            }

            return(exited);
        }
Ejemplo n.º 7
0
Archivo: IO.cs Proyecto: sq/Libraries
        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);
        }
Ejemplo n.º 8
0
        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
        }
Ejemplo n.º 9
0
        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;
        }
Ejemplo n.º 10
0
Archivo: IO.cs Proyecto: sq/Libraries
 public WriteThunk()
 {
     Result          = new SignalFuture();
     FlushOnComplete = _FlushOnComplete;
 }
Ejemplo n.º 11
0
        public static SignalFuture WaitForProcessExit(Process process)
        {
            var exited = new SignalFuture();

            process.Exited += (s, e) =>
                exited.Complete();

            if (process.HasExited)
                try {
                    exited.Complete();
                } catch {
                }

            return exited;
        }
Ejemplo n.º 12
0
Archivo: IO.cs Proyecto: sq/Fracture
 public WriteThunk()
 {
     Result = new SignalFuture();
     FlushOnComplete = _FlushOnComplete;
 }
Ejemplo n.º 13
0
Archivo: IO.cs Proyecto: sq/Fracture
 public SignalFuture Write(byte[] buffer, int offset, int count)
 {
     var f = new SignalFuture();
     _Stream.BeginWrite(buffer, offset, count, _WriteCallback, f);
     return f;
 }
Ejemplo n.º 14
0
Archivo: IO.cs Proyecto: sq/Fracture
 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;
 }
Ejemplo n.º 15
0
 public SignalFuture Write(byte[] buffer, int offset, int count)
 {
     #if XBOX
     return Future.RunInThread(() => _Stream.Write(buffer, offset, count));
     #else
     var f = new SignalFuture();
     _Stream.BeginWrite(buffer, offset, count, _WriteCallback, f);
     return f;
     #endif
 }