/// <summary>
        /// When a AudioProperty in the fed packets is found this callback is called
        /// </summary>
        private void AudioPropertyFound(object sender, PropertyFoundEventArgs args)
        {
            if (args.Property == AudioFileStreamProperty.ReadyToProducePackets)
            {
                Started = false;

                if (OutputQueue != null)
                {
                    OutputQueue.Dispose();
                }

                OutputQueue = new OutputAudioQueue(_audioFileStream.StreamBasicDescription);
                OutputReady?.Invoke(OutputQueue);

                _currentByteCount            = 0;
                OutputQueue.BufferCompleted += HandleBufferCompleted;
                _outputBuffers = new List <AudioBuffer>();

                for (int i = 0; i < MaxBufferCount; i++)
                {
                    OutputQueue.AllocateBuffer(BufferSize, out IntPtr outBuffer);
                    _outputBuffers.Add(new AudioBuffer()
                    {
                        Buffer             = outBuffer,
                        PacketDescriptions = new List <AudioStreamPacketDescription>()
                    });
                }

                _currentBuffer = _outputBuffers.First();

                OutputQueue.MagicCookie = _audioFileStream.MagicCookie;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Start the psuedoconsole and run the process as shown in
        /// https://docs.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session#creating-the-pseudoconsole
        /// </summary>
        /// <param name="command">the command to run, e.g. cmd.exe</param>
        /// <param name="consoleHeight">The height (in characters) to start the pseudoconsole with. Defaults to 80.</param>
        /// <param name="consoleWidth">The width (in characters) to start the pseudoconsole with. Defaults to 30.</param>
        public void Start(string command, string directory, int consoleWidth = 80, int consoleHeight = 30)
        {
            _inputPipe     = new PseudoConsolePipe();
            _outputPipe    = new PseudoConsolePipe();
            _pseudoConsole = PseudoConsole.Create(_inputPipe.ReadSide, _outputPipe.WriteSide, consoleWidth, consoleHeight);

            using (var process = ProcessFactory.Start(command, directory, PseudoConsole.PseudoConsoleThreadAttribute, _pseudoConsole.Handle))
            {
                // copy all pseudoconsole output to a FileStream and expose it to the rest of the app
                ConsoleOutStream = new FileStream(_outputPipe.ReadSide, FileAccess.Read);
                OutputReady.Invoke(this, EventArgs.Empty);

                // Store input pipe handle, and a writer for later reuse
                _consoleInputPipeWriteHandle = _inputPipe.WriteSide;
                _consoleInputWriter          = new StreamWriter(new FileStream(_consoleInputPipeWriteHandle, FileAccess.Write))
                {
                    AutoFlush = true
                };

                // free resources in case the console is ungracefully closed (e.g. by the 'x' in the window titlebar)
                OnClose(() => DisposeResources(process, _pseudoConsole, _outputPipe, _inputPipe, _consoleInputWriter));

                WaitForExit(process).WaitOne(Timeout.Infinite);
            }
            Exited?.Invoke(this, EventArgs.Empty);
        }
Esempio n. 3
0
        /// <summary>
        /// Start the psuedoconsole and run the process as shown in
        /// https://docs.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session#creating-the-pseudoconsole
        /// </summary>
        /// <param name="command">the command to run, e.g. cmd.exe</param>
        /// <param name="consoleHeight">The height (in characters) to start the pseudoconsole with. Defaults to 80.</param>
        /// <param name="consoleWidth">The width (in characters) to start the pseudoconsole with. Defaults to 30.</param>
        public void Start(string command, string directory, string environment, int consoleWidth = 80, int consoleHeight = 30)
        {
            _inputPipe     = new PseudoConsolePipe();
            _outputPipe    = new PseudoConsolePipe();
            _pseudoConsole = PseudoConsole.Create(_inputPipe.ReadSide, _outputPipe.WriteSide, consoleWidth, consoleHeight);

            _process = ProcessFactory.Start(command, directory, environment, PseudoConsole.PseudoConsoleThreadAttribute, _pseudoConsole.Handle);

            // copy all pseudoconsole output to a FileStream and expose it to the rest of the app
            ConsoleOutStream = new FileStream(_outputPipe.ReadSide, FileAccess.Read);
            OutputReady.Invoke(this, EventArgs.Empty);

            // Store input pipe handle, and a writer for later reuse
            _consoleInputPipeWriteHandle = _inputPipe.WriteSide;
            _consoleInputWriter          = new FileStream(_consoleInputPipeWriteHandle, FileAccess.Write);

            WaitForExit(_process).WaitOne(Timeout.Infinite);
            this.ExitCode = (int)_process.GetExitCode();

            Exited?.Invoke(this, EventArgs.Empty);
        }
Esempio n. 4
0
        public void Handle(string input)
        {
            if (input.Length <= 0)
            {
                return;
            }

            string[] inputArr = input.Split(' ');

            string inputCommand = inputArr[0];

            string[] inputArgs = RemoveCommandString(inputArr);

            foreach (Command comm in Commands)
            {
                if (inputArr[0].ToLower() == comm.CommandString)
                {
                    if (comm.GetType() == typeof(CommandExit))
                    {
                        ExitCommandOccurred.Invoke(this, new EventArgs());
                    }
                    else
                    {
                        string output = string.Empty;

                        if ((output = comm.Execute(inputArgs)) != string.Empty)
                        {
                            OutputReady.Invoke(this, new OutputReadyEventArgs(output));
                        }
                    }

                    return;
                }
            }

            OutputReady.Invoke(this, new OutputReadyEventArgs("Invalid command \"" + inputCommand + "\"!"));
        }
Esempio n. 5
0
 protected virtual void OnOutputReady(OutputReadyEventArgs e)
 {
     OutputReady?.Invoke(this, e);
 }
Esempio n. 6
0
 protected virtual void OnOutputReady(int cnt) => OutputReady?.Invoke(this, cnt);