示例#1
0
文件: IO.cs 项目: sq/Libraries
        public SignalFuture Write(byte[] buffer, int offset, int count)
        {
            var f = new SignalFuture();

            _Stream.BeginWrite(buffer, offset, count, _WriteCallback, f);
            return(f);
        }
示例#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);
        }
示例#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);
        }
示例#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
        }
示例#5
0
文件: IO.cs 项目: 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);
        }
示例#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);
        }
示例#7
0
文件: IO.cs 项目: 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);
        }
示例#8
0
文件: IO.cs 项目: mbahar94/fracture
        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
        }
示例#9
0
文件: Sockets.cs 项目: sq/Fracture
        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;
        }
示例#10
0
文件: IO.cs 项目: sq/Libraries
 public WriteThunk()
 {
     Result          = new SignalFuture();
     FlushOnComplete = _FlushOnComplete;
 }
示例#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;
        }
示例#12
0
文件: IO.cs 项目: sq/Fracture
 public WriteThunk()
 {
     Result = new SignalFuture();
     FlushOnComplete = _FlushOnComplete;
 }
示例#13
0
文件: IO.cs 项目: sq/Fracture
 public SignalFuture Write(byte[] buffer, int offset, int count)
 {
     var f = new SignalFuture();
     _Stream.BeginWrite(buffer, offset, count, _WriteCallback, f);
     return f;
 }
示例#14
0
文件: IO.cs 项目: 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;
 }
示例#15
0
文件: IO.cs 项目: pakoito/Fracture
 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
 }