예제 #1
0
 private static void Monitor(bool skipPublish,string eventName)
 {
     if (!skipPublish)
     {
         WowzaApi.GetMonitoringAsync($"MonitoringReport-{eventName}");
         Thread.Sleep(1000);
     }
 }
예제 #2
0
        private async Task <int> RunProcessAsync(ProcessStartInfo processStartInfo, WowzaApi wowzaApi, string streamName)
        {
            var           tcs    = new TaskCompletionSource <int>();
            StringBuilder output = new StringBuilder();
            StringBuilder error  = new StringBuilder();

            try
            {
                var process = new Process
                {
                    StartInfo           = processStartInfo,
                    EnableRaisingEvents = true
                };

                if (wowzaConfig.LogOutputToFile)
                {
                    process.OutputDataReceived += (s, e) =>
                    {
                        lock (output)
                        {
                            output.AppendLine(e.Data);
                        };
                    };
                    process.ErrorDataReceived += (s, e) =>
                    {
                        lock (error)
                        {
                            error.AppendLine(e.Data);
                        };
                    };
                }

                process.Exited += (sender, args) =>
                {
                    if (wowzaConfig.LogOutputToFile)
                    {
                        Helper.WriteToFile($"ConsoleLog-{streamName}", output.ToString() + error.ToString());
                    }
                    wowzaApi.GetMonitoringAsync($"MonitoringReport-{streamName}");
                    Thread.Sleep(1000);
                    tcs.SetResult(process.ExitCode);
                    process.Dispose();
                };

                process.Start();

                if (wowzaConfig.LogOutputToFile)
                {
                    process.BeginOutputReadLine();
                    process.BeginErrorReadLine();
                    process.StandardInput.AutoFlush = true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                tcs.SetResult(1);
            }

            return(await tcs.Task);
        }