public void Clear() { this.SafeInvoke(() => { ConsoleText.Clear(); }); }
private void MenuItem_ClearConsole_Click(object sender, RoutedEventArgs e) { ConsoleText.Clear(); }
/// <summary> /// Clear the output stream. /// </summary> public void ClearOutput() { ConsoleText.Clear(); }
private async Task <LogItem> ProcessItem(EncodeServer server, QueueItem src) { DateTime now = DateTime.Now; if (File.Exists(src.Path) == false) { return(FailLogItem(src.Path, "入力ファイルが見つかりません", now, now)); } bool isMp4 = src.Path.ToLower().EndsWith(".mp4"); string dstpath = Path.Combine(encoded, Path.GetFileName(src.Path)); string srcpath = src.Path; string localsrc = null; string localdst = dstpath; // ハッシュがある(ネットワーク経由)の場合はローカルにコピー if (hashList != null) { localsrc = tmpBase + "-in" + Path.GetExtension(srcpath); string name = Path.GetFileName(srcpath); if (hashList.ContainsKey(name) == false) { return(FailLogItem(src.Path, "入力ファイルのハッシュがありません", now, now)); } byte[] hash = await HashUtil.CopyWithHash(srcpath, localsrc); var refhash = hashList[name]; if (hash.SequenceEqual(refhash) == false) { File.Delete(localsrc); return(FailLogItem(src.Path, "コピーしたファイルのハッシュが一致しません", now, now)); } srcpath = localsrc; localdst = tmpBase + "-out.mp4"; } string json = Path.Combine( Path.GetDirectoryName(localdst), Path.GetFileNameWithoutExtension(localdst)) + "-enc.json"; string logpath = Path.Combine( Path.GetDirectoryName(dstpath), Path.GetFileNameWithoutExtension(dstpath)) + "-enc.log"; string args = server.MakeAmatsukazeArgs(isMp4, srcpath, localdst, json); string exename = server.appData.setting.AmatsukazePath; Util.AddLog(id, "エンコード開始: " + src.Path); Util.AddLog(id, "Args: " + exename + " " + args); DateTime start = DateTime.Now; var psi = new ProcessStartInfo(exename, args) { UseShellExecute = false, WorkingDirectory = Directory.GetCurrentDirectory(), RedirectStandardError = true, RedirectStandardOutput = true, RedirectStandardInput = false, CreateNoWindow = true }; IntPtr affinityMask = new IntPtr((long)server.affinityCreator.GetMask(id)); Util.AddLog(id, "AffinityMask: " + affinityMask.ToInt64()); int exitCode = -1; logText.Clear(); try { using (var p = Process.Start(psi)) { // アフィニティを設定 p.ProcessorAffinity = affinityMask; p.PriorityClass = ProcessPriorityClass.BelowNormal; process = p; using (logWriter = File.Create(logpath)) { await Task.WhenAll( RedirectOut(server, p.StandardOutput.BaseStream), RedirectOut(server, p.StandardError.BaseStream), Task.Run(() => p.WaitForExit())); } exitCode = p.ExitCode; } } catch (Win32Exception w32e) { Util.AddLog(id, "Amatsukazeプロセス起動に失敗"); throw w32e; } finally { logWriter = null; process = null; } DateTime finish = DateTime.Now; if (hashList != null) { File.Delete(localsrc); } if (exitCode == 0) { // 成功ならログを整形したテキストに置き換える using (var fs = new StreamWriter(File.Create(logpath), Encoding.Default)) { foreach (var str in logText.TextLines) { fs.WriteLine(str); } } } // ログファイルを専用フォルダにコピー if (File.Exists(logpath)) { string logbase = server.GetLogFileBase(start); Directory.CreateDirectory(Path.GetDirectoryName(logbase)); string dstlog = logbase + ".txt"; File.Copy(logpath, dstlog); if (File.Exists(json)) { string dstjson = logbase + ".json"; File.Move(json, dstjson); json = dstjson; } } if (exitCode == 0) { // 成功 var log = LogFromJson(isMp4, json, start, finish); // ハッシュがある(ネットワーク経由)の場合はリモートにコピー if (hashList != null) { log.SrcPath = src.Path; string outbase = Path.GetDirectoryName(dstpath) + "\\" + Path.GetFileNameWithoutExtension(dstpath); for (int i = 0; i < log.OutPath.Count; ++i) { string outext = Path.GetExtension(log.OutPath[i]); string outpath = outbase + ((i == 0) ? outext : ("-" + i + outext)); var hash = await HashUtil.CopyWithHash(log.OutPath[i], outpath); string name = Path.GetFileName(outpath); HashUtil.AppendHash(Path.Combine(encoded, "_mp4.hash"), name, hash); File.Delete(log.OutPath[i]); log.OutPath[i] = outpath; } } return(log); } else { // 失敗 return(FailLogItem(src.Path, "Amatsukaze.exeはコード" + exitCode + "で終了しました。", start, finish)); } }