} // SetAdditionalData private void SetAction(TaskDefinition definition, RecordTask record, string dbFile, string logFolder) { var arguments = new[] { "/Action:Record", $"/TaskId:{record.TaskId}", $"/Database:{dbFile}", $"/LogFolder:{logFolder}" }; var action = new ExecAction() { Path = _recorderLauncherPath, Arguments = ArgumentsManager.JoinArguments(arguments), WorkingDirectory = record.Action.SaveLocationPath, }; definition.Actions.Add(action); } // SetAction
} // ShowTvChannel public static void Launch(TvPlayer player, UiBroadcastService service, bool throughShortcut) { if (!File.Exists(player.Path)) { var ex = new FileNotFoundException(); throw new FileNotFoundException(ex.Message + "\r\n" + player.Path); } // if if (LaunchParamKeys == null) { LaunchParamKeys = new string[] { "Channel.Url", "Channel.Name", "Channel.Description", "Channel.Icon.Path", }; } // if var paramValues = new string[] { service.LocationUrl, service.DisplayName, service.DisplayDescription, service.Logo.GetLogoIconPath(), }; var parameters = ArgumentsManager.CreateParameters(LaunchParamKeys, paramValues, false); var arguments = ArgumentsManager.ExpandArguments(player.Arguments, parameters, TvPlayer.ParameterOpenBrace, TvPlayer.ParameterCloseBrace, StringComparison.CurrentCultureIgnoreCase); var launchArguments = ArgumentsManager.JoinArguments(arguments); if (throughShortcut) { LaunchShortcut(player, service, launchArguments); } else { LaunchProcess(player, launchArguments); } // if-else } // Launch
} // DisplayTaskData private Program.Result LaunchRecorderProgram(RecordTask task) { var scheduledStartTime = task.Schedule.GetStartDateTime(); var scheduledTotalTime = task.Schedule.SafetyMarginTimeSpan + task.Duration.GetDuration(task.Schedule) + task.Duration.SafetyMarginTimeSpan; var now = DateTime.Now; // var scheduledDateTime = new DateTime(scheduledStartTime.Year, scheduledStartTime.Month, scheduledStartTime.Day, scheduledStartTime.Hour, scheduledStartTime.Minute, scheduledStartTime.Second); // TODO: determine most probable launch date; we need to account for HUGE delays between scheduled run time and real run time var scheduledDateTime = new DateTime(now.Year, now.Month, now.Day, scheduledStartTime.Hour, scheduledStartTime.Minute, scheduledStartTime.Second); var gap = now - scheduledDateTime; if (gap.TotalSeconds < 1) { gap = TimeSpan.Zero; } TotalTime = scheduledTotalTime - gap; Logger.Log(Logger.Level.Verbose, Properties.Texts.LogVerboseScheduledStartTimeGap, scheduledStartTime, scheduledTotalTime, gap, TotalTime); DisplayTaskData(task, TotalTime); if (TotalTime.TotalSeconds < 1) { Logger.Log(Logger.Level.Error, Properties.Texts.LogErrorTooLate); return(Program.Result.TooLate); } // if if (gap.TotalSeconds < 30) { gap = TimeSpan.Zero; } if (task.Schedule.Kind != RecordScheduleKind.RightNow) { if (gap.TotalSeconds > task.Schedule.SafetyMarginTimeSpan.TotalSeconds) { RecordingLate = true; Logger.Log(Logger.Level.Warning, Properties.Texts.LogWarningRecordingLate, (int)task.Schedule.SafetyMarginTimeSpan.TotalMinutes); Console.WriteLine(Properties.Texts.DisplayWarningRecordingLate, (int)task.Schedule.SafetyMarginTimeSpan.TotalMinutes); } else if (gap.TotalSeconds > 0) { Logger.Log(Logger.Level.Warning, Properties.Texts.LogWarningBehindSchedule, gap); Console.WriteLine(Properties.Texts.DisplayWarningBehindSchedule, gap); } // if-else } // if-else var date = string.Format(Properties.Texts.FormatRecordFileDate, now.Year, now.Month, now.Day, scheduledStartTime.Hour, scheduledStartTime.Minute, scheduledStartTime.Second); var filename = string.Format(Properties.Texts.FormatRecordFileName, task.Action.SaveLocationPath, task.Action.Filename, date, RecordingLate ? Properties.Texts.FormatRecordFileDelayed : null, task.Action.FileExtension); var parameters = CreateParameters(filename, task); LogParameters(parameters); var arguments = ArgumentsManager.ExpandArguments(task.Action.Recorder.Arguments, parameters, Properties.Resources.ArgumentsOpenBrace, Properties.Resources.ArgumentsCloseBrace, StringComparison.CurrentCultureIgnoreCase); var joinedArguments = ArgumentsManager.JoinArguments(arguments); LogArguments(task.Action.Recorder.Path, task.Action.Recorder.Arguments, joinedArguments); try { var info = new ProcessStartInfo() { FileName = task.Action.Recorder.Path, Arguments = joinedArguments, ErrorDialog = false, UseShellExecute = false, }; Logger.Log(Logger.Level.Info, Properties.Texts.LogInfoLaunchingRecorder); Console.Write(Properties.Texts.DisplayLaunchingRecorder); using (var process = Process.Start(info)) { Logger.Log(Logger.Level.Info, Properties.Texts.LogInfoLaunchingRecorderOk, process.Id); Console.WriteLine(Properties.Texts.DisplayLaunchingRecorderOk, process.Id); TimerTickCount = 0; StartTime = DateTime.UtcNow; var timer = new System.Threading.Timer(OnTimerTick, null, 0, 60000); Logger.Log(Logger.Level.Verbose, Properties.Texts.LogVerboseWaitForExit); process.WaitForExit(); timer.Dispose(); Logger.Log(Logger.Level.Info, Properties.Texts.LogInfoRecorderExited, process.ExitCode); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(Properties.Texts.DisplayRecorderFinished); if (process.ExitCode != 0) { return(Program.Result.ExecFailure); } // if } // using } catch (Exception ex) { Logger.Exception(ex, Properties.Texts.LogExceptionLaunchingRecorder); Program.DisplayException(ex); return(Program.Result.ExecProblem); } // try-catch return(Program.Result.Ok); } // LaunchRecorderProgram