示例#1
0
 public bool Handle(ReportTranscodingCompletion command)
 {
     _logger.Info($"{command.TranscodingId}: Completed Sucessfully Elapsed: {command.TotalProcessDuration.Seconds}s %");
     Completed++;
     InProgress--;
     return(true);
 }
示例#2
0
        private void RunProcess(ProcessStartInfo processStartInfo)
        {
            using (TranscodingProcess = Process.Start(processStartInfo))
            {
                StartedAt = DateTime.UtcNow;
                Stopwatch = Stopwatch.StartNew();
                Status    = Status.InProgress;
                var invoker = Invoker;

                TranscodingProcess.ErrorDataReceived += (sender, e) =>
                {
                    if (e.Data == null)
                    {
                        return;
                    }

                    try
                    {
                        ReceivedMessagesLog.Insert(0, e.Data);

                        if (EngineParameters.InputFile != null)
                        {
                            //RegexEngine.TestAudio(e.Data, EngineParameters);

                            var matchDuration = RegexEngine.Index[RegexEngine.Find.Duration].Match(e.Data);
                            if (matchDuration.Success)
                            {
                                var totalMediaDuration = new TimeSpan();
                                TimeSpan.TryParse(matchDuration.Groups[1].Value, out totalMediaDuration);
                                TotalMediaDuration = totalMediaDuration;
                                //EngineParameters.InputFile.Metadata.Duration = TotalMediaDuration;
                            }
                        }
                        ConversionCompleted  convertCompleted;
                        ConversionProgressed progressEvent;

                        if (RegexEngine.IsProgressData(e.Data, out progressEvent))
                        {
                            var elapsed = Stopwatch.Elapsed;
                            ProcessedMediaDuration = progressEvent.ProcessedDuration;

                            var command = new ReportTranscodingProgress(
                                TranscodingId,
                                TotalMediaDuration,
                                ProcessedMediaDuration,
                                elapsed,
                                StartedAt,
                                Input,
                                Output);

                            invoker.Tell(command);
                        }
                        else if (RegexEngine.IsConvertCompleteData(e.Data, out convertCompleted))
                        {
                            //does this even work?
                            var a = Stopwatch.Elapsed;
                            //_logger.Info($"Progress: Done!");
                        }
                    }
                    catch (Exception ex)
                    {
                        // catch the exception and kill the process since we're in a faulted state
                        Exceptions.Add(ex);

                        try
                        {
                            Status = Status.Failed;
                            TranscodingProcess.Kill();
                        }
                        catch (InvalidOperationException invalidOperationException)
                        {
                            Exceptions.Add(invalidOperationException);
                            // swallow exceptions that are thrown when killing the process,
                            // one possible candidate is the application ending naturally before we get a chance to kill it
                        }
                        finally
                        {
                        }
                    }
                };


                TranscodingProcess.BeginErrorReadLine();
                TranscodingProcess.WaitForExit();



                if ((TranscodingProcess.ExitCode != 0 && TranscodingProcess.ExitCode != 1) || Exceptions.Count > 0)
                {
                    Status = Status.Failed;
                    throw new Exception(
                              TranscodingProcess.ExitCode + ": " + ReceivedMessagesLog[1] + ReceivedMessagesLog[0]);
                }
                else
                {
                    Status = Status.Completed;
                }

                EndedAt = DateTime.UtcNow;
                TotalProcessDuration = Stopwatch.Elapsed;
                Stopwatch.Stop();


                switch (Status)
                {
                case Status.Completed:
                {
                    var command = new ReportTranscodingCompletion(
                        TranscodingId,
                        TotalMediaDuration,
                        ProcessedMediaDuration,
                        TotalProcessDuration,
                        StartedAt,
                        EndedAt,
                        Input,
                        Output,
                        ReceivedMessagesLog);

                    invoker.Tell(command);
                }
                break;

                case Status.Failed:
                {
                    var command = new ReportTranscodingFailure(
                        TranscodingId,
                        TotalMediaDuration,
                        TotalProcessDuration,
                        StartedAt,
                        EndedAt,
                        Input,
                        Output,
                        Exceptions,
                        ReceivedMessagesLog);

                    invoker.Tell(command);
                }
                break;
                }


                Context.Stop(Self);
            }
        }