Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo 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);
        }
Exemplo n.º 4
0
Arquivo: IO.cs Projeto: 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);
        }
Exemplo n.º 5
0
Arquivo: IO.cs Projeto: 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);
        }
Exemplo n.º 6
0
Arquivo: IO.cs Projeto: sq/Libraries
            public void StepStrings()
            {
                try {
                    StringIndex += 1;
                    if (StringIndex >= NumStrings)
                    {
                        if (FlushWhenDone)
                        {
                            Result.Bind(Parent.Flush(Parent._BufferCount));
                        }
                        else
                        {
                            Result.Complete();
                        }
                        return;
                    }

                    StringPos = 0;
                    StepString();
                } catch (Exception ex) {
                    Result.Fail(ex);
                }
            }
Exemplo n.º 7
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
        }
Exemplo n.º 8
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;
        }
Exemplo n.º 9
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;
        }
Exemplo n.º 10
0
Arquivo: IO.cs Projeto: 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;
 }
Exemplo n.º 11
0
 public void Start()
 {
     BindAll();
     ListenAll();
     Started.Complete();
 }