public GetCompareFileDataAsText ( ) : string | ||
Résultat | string |
/// <summary> /// Handles all command-line arguments /// </summary> /// <param name="args">Arguments array</param> /// <returns>CommandLineResult to indicate if the operation was successful or not</returns> private CommandLineResult ProcessCommandLine(string[] args) { string logFile = string.Empty; List <string> streamList = new List <string>(); bool updatePersonalMetadata = false; uint loopCount = 0; Dictionary <string, List <string> > commands = new Dictionary <string, List <string> >(); try { if (args == null) { return(CommandLineResult.Succeeded); } if (args.Length == 0) { return(CommandLineResult.Succeeded); } // gather commands and support parameters for (int i = 0; i < args.Length; i++) { string arg = args[i]; if (this.IsArgument(arg)) { string key = arg.Substring(1).ToUpperInvariant(); if (!commands.ContainsKey(key)) { commands.Add(key, new List <string>()); for (int j = i + 1; j < args.Length; j++) { string param = args[j]; if (!this.IsArgument(param)) { commands[key].Add(param); } else { break; } } } } } // process all command args if (commands.ContainsKey("?") || commands.ContainsKey(Strings.Command_Help)) { this.RunCommandLine(); this.ShowCommandLineHelp(); return(CommandLineResult.SucceededExit); } // -log <filename> if (commands.ContainsKey(Strings.Command_Log)) { if (commands[Strings.Command_Log].Count != 1) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Log)); return(CommandLineResult.Invalid); } logFile = commands[Strings.Command_Log][0]; } // -loop <count> if (commands.ContainsKey(Strings.Command_Loop)) { if (commands[Strings.Command_Loop].Count != 1) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Loop)); return(CommandLineResult.Invalid); } if (!uint.TryParse(commands[Strings.Command_Loop][0], out loopCount)) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Loop)); return(CommandLineResult.Invalid); } } // -pii if (commands.ContainsKey(Strings.Command_PII)) { updatePersonalMetadata = true; } // -stream <stream1> <stream2> <stream3> ... if (commands.ContainsKey(Strings.Command_Stream)) { if (commands[Strings.Command_Stream].Count == 0) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Stream)); return(CommandLineResult.Invalid); } streamList = commands[Strings.Command_Stream]; } // -view <filename> if (commands.ContainsKey(Strings.Command_View)) { this.RunCommandLine(); if (commands[Strings.Command_View].Count != 1) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_View)); return(CommandLineResult.Invalid); } string fileInfo = string.Empty; string filePath = commands[Strings.Command_View][0]; this.CheckFile(filePath); Console.WriteLine(Strings.WaitForViewFile); using (KStudioClient client = KStudio.CreateClient()) { if (filePath.ToUpperInvariant().StartsWith(Strings.ConsoleClipRepository.ToUpperInvariant())) { client.ConnectToService(); } using (KStudioEventFile eventFile = client.OpenEventFile(filePath)) { FileData data = new FileData(eventFile); fileInfo = data.GetFileDataAsText(); Console.WriteLine(fileInfo); } } if (!string.IsNullOrEmpty(logFile)) { Logger.Start(logFile, true); Logger.Log(fileInfo); Logger.Stop(); } Console.WriteLine(Strings.Done); return(CommandLineResult.SucceededExit); } // -compare <filename1> <filename2> if (commands.ContainsKey(Strings.Command_Compare)) { this.RunCommandLine(); if (commands[Strings.Command_Compare].Count != 2) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Compare)); return(CommandLineResult.Invalid); } string fileInfo = string.Empty; string file1 = commands[Strings.Command_Compare][0]; string file2 = commands[Strings.Command_Compare][1]; this.CheckFile(file1); this.CheckFile(file2); Console.WriteLine(Strings.WaitForCompareFiles); using (KStudioClient client = KStudio.CreateClient()) { if (file1.ToUpperInvariant().StartsWith(Strings.ConsoleClipRepository.ToUpperInvariant()) || file2.ToUpperInvariant().StartsWith(Strings.ConsoleClipRepository.ToUpperInvariant())) { client.ConnectToService(); } using (KStudioEventFile eventFile1 = client.OpenEventFile(file1)) using (KStudioEventFile eventFile2 = client.OpenEventFile(file2)) { FileData fileData1 = new FileData(eventFile1); FileData fileData2 = new FileData(eventFile2); CompareFileData compareData = new CompareFileData(fileData1, fileData2); fileInfo = compareData.GetCompareFileDataAsText(); Console.WriteLine(fileInfo); } } if (!string.IsNullOrEmpty(logFile)) { Logger.Start(logFile, true); Logger.Log(fileInfo); Logger.Stop(); } Console.WriteLine(Strings.Done); return(CommandLineResult.SucceededExit); } // -update <filename> <metadata key> <metadata value> if (commands.ContainsKey(Strings.Command_Update)) { this.RunCommandLine(); if (commands[Strings.Command_Update].Count != 3) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Update)); return(CommandLineResult.Invalid); } string filePath = commands[Strings.Command_Update][0]; string key = commands[Strings.Command_Update][1]; object value = commands[Strings.Command_Update][2]; this.CheckFile(filePath); string metadataText = string.Empty; if (streamList.Count > 0) { // update stream metadata foreach (string streamName in streamList) { Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.UpdatingStreamMetadata, streamName)); metadataText = this.EditMetadata(filePath, key, value, streamName, updatePersonalMetadata, true); Console.WriteLine(metadataText); } } else { // update file metadata Console.WriteLine(Strings.UpdatingFileMetadata); metadataText = this.EditMetadata(filePath, key, value, string.Empty, updatePersonalMetadata, false); Console.WriteLine(metadataText); } Console.WriteLine(Strings.Done); return(CommandLineResult.SucceededExit); } // -remove <filename> <metadata key> if (commands.ContainsKey(Strings.Command_Remove)) { this.RunCommandLine(); if (commands[Strings.Command_Remove].Count != 2) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Remove)); return(CommandLineResult.Invalid); } string filePath = commands[Strings.Command_Remove][0]; string key = commands[Strings.Command_Remove][1]; this.CheckFile(filePath); string metadataText = string.Empty; if (streamList.Count > 0) { // update stream metadata foreach (string streamName in streamList) { Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.UpdatingStreamMetadata, streamName)); metadataText = this.EditMetadata(filePath, key, null, streamName, updatePersonalMetadata, true); Console.WriteLine(metadataText); } } else { // update file metadata Console.WriteLine(Strings.UpdatingFileMetadata); metadataText = this.EditMetadata(filePath, key, null, string.Empty, updatePersonalMetadata, false); Console.WriteLine(metadataText); } Console.WriteLine(Strings.Done); return(CommandLineResult.SucceededExit); } // -play <filename> if (commands.ContainsKey(Strings.Command_Play)) { this.RunCommandLine(); if (commands[Strings.Command_Play].Count != 1) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Play)); return(CommandLineResult.Invalid); } string filePath = commands[Strings.Command_Play][0]; this.CheckFile(filePath); using (KStudioClient client = KStudio.CreateClient()) { Console.WriteLine(Strings.WaitToConnect); client.ConnectToService(); Console.WriteLine(Strings.StartPlayback); Playback.PlaybackClip(client, filePath, streamList, loopCount); Console.WriteLine(Strings.StopPlayback); client.DisconnectFromService(); } Console.WriteLine(Strings.Done); return(CommandLineResult.SucceededExit); } // -record <filename> <duration> if (commands.ContainsKey(Strings.Command_Record)) { this.RunCommandLine(); if (commands[Strings.Command_Record].Count != 2) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Record)); return(CommandLineResult.Invalid); } string filePath = commands[Strings.Command_Record][0]; this.CheckDirectory(filePath); double time = 0; if (!double.TryParse(commands[Strings.Command_Record][1], out time)) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Record)); return(CommandLineResult.Invalid); } TimeSpan duration = TimeSpan.FromSeconds(time); string errorMsg = string.Empty; string fileInfo = string.Empty; using (KStudioClient client = KStudio.CreateClient()) { Console.WriteLine(Strings.WaitToConnect); client.ConnectToService(); Console.WriteLine(Strings.StartRecording); Recording.RecordClip(client, filePath, duration, streamList); Console.WriteLine(Strings.StopRecording); using (KStudioEventFile eventFile = client.OpenEventFile(filePath)) { FileData fileData = new FileData(eventFile); fileInfo = fileData.GetFileDataAsText(); Console.WriteLine(fileInfo); } client.DisconnectFromService(); } if (!string.IsNullOrEmpty(logFile)) { Logger.Start(logFile, true); Logger.Log(fileInfo); Logger.Stop(); } Console.WriteLine(Strings.Done); return(CommandLineResult.SucceededExit); } } catch (Exception ex) { string errorMsg = string.Format(Strings.ErrorPrepend, ex.Message); Console.Error.WriteLine(errorMsg); return(CommandLineResult.Failed); } return(CommandLineResult.Invalid); }
/// <summary> /// Handles all command-line arguments /// </summary> /// <param name="args">Arguments array</param> /// <returns>CommandLineResult to indicate if the operation was successful or not</returns> private CommandLineResult ProcessCommandLine(string[] args) { string logFile = string.Empty; List<string> streamList = new List<string>(); bool updatePersonalMetadata = false; uint loopCount = 0; Dictionary<string, List<string>> commands = new Dictionary<string, List<string>>(); try { if (args == null) { return CommandLineResult.Succeeded; } if (args.Length == 0) { return CommandLineResult.Succeeded; } // gather commands and support parameters for (int i = 0; i < args.Length; i++) { string arg = args[i]; if (this.IsArgument(arg)) { string key = arg.Substring(1).ToUpperInvariant(); if (!commands.ContainsKey(key)) { commands.Add(key, new List<string>()); for (int j = i + 1; j < args.Length; j++) { string param = args[j]; if (!this.IsArgument(param)) { commands[key].Add(param); } else { break; } } } } } // process all command args if (commands.ContainsKey("?") || commands.ContainsKey(Strings.Command_Help)) { this.RunCommandLine(); this.ShowCommandLineHelp(); return CommandLineResult.SucceededExit; } // -log <filename> if (commands.ContainsKey(Strings.Command_Log)) { if (commands[Strings.Command_Log].Count != 1) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Log)); return CommandLineResult.Invalid; } logFile = commands[Strings.Command_Log][0]; } // -loop <count> if (commands.ContainsKey(Strings.Command_Loop)) { if (commands[Strings.Command_Loop].Count != 1) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Loop)); return CommandLineResult.Invalid; } if (!uint.TryParse(commands[Strings.Command_Loop][0], out loopCount)) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Loop)); return CommandLineResult.Invalid; } } // -pii if (commands.ContainsKey(Strings.Command_PII)) { updatePersonalMetadata = true; } // -stream <stream1> <stream2> <stream3> ... if (commands.ContainsKey(Strings.Command_Stream)) { if (commands[Strings.Command_Stream].Count == 0) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Stream)); return CommandLineResult.Invalid; } streamList = commands[Strings.Command_Stream]; } // -view <filename> if (commands.ContainsKey(Strings.Command_View)) { this.RunCommandLine(); if (commands[Strings.Command_View].Count != 1) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_View)); return CommandLineResult.Invalid; } string fileInfo = string.Empty; string filePath = commands[Strings.Command_View][0]; this.CheckFile(filePath); Console.WriteLine(Strings.WaitForViewFile); using (KStudioClient client = KStudio.CreateClient()) { if (filePath.ToUpperInvariant().StartsWith(Strings.ConsoleClipRepository.ToUpperInvariant())) { client.ConnectToService(); } using (KStudioEventFile eventFile = client.OpenEventFile(filePath)) { FileData data = new FileData(eventFile); fileInfo = data.GetFileDataAsText(); Console.WriteLine(fileInfo); } } if (!string.IsNullOrEmpty(logFile)) { Logger.Start(logFile, true); Logger.Log(fileInfo); Logger.Stop(); } Console.WriteLine(Strings.Done); return CommandLineResult.SucceededExit; } // -compare <filename1> <filename2> if (commands.ContainsKey(Strings.Command_Compare)) { this.RunCommandLine(); if (commands[Strings.Command_Compare].Count != 2) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Compare)); return CommandLineResult.Invalid; } string fileInfo = string.Empty; string file1 = commands[Strings.Command_Compare][0]; string file2 = commands[Strings.Command_Compare][1]; this.CheckFile(file1); this.CheckFile(file2); Console.WriteLine(Strings.WaitForCompareFiles); using (KStudioClient client = KStudio.CreateClient()) { if (file1.ToUpperInvariant().StartsWith(Strings.ConsoleClipRepository.ToUpperInvariant()) || file2.ToUpperInvariant().StartsWith(Strings.ConsoleClipRepository.ToUpperInvariant())) { client.ConnectToService(); } using (KStudioEventFile eventFile1 = client.OpenEventFile(file1)) using (KStudioEventFile eventFile2 = client.OpenEventFile(file2)) { FileData fileData1 = new FileData(eventFile1); FileData fileData2 = new FileData(eventFile2); CompareFileData compareData = new CompareFileData(fileData1, fileData2); fileInfo = compareData.GetCompareFileDataAsText(); Console.WriteLine(fileInfo); } } if (!string.IsNullOrEmpty(logFile)) { Logger.Start(logFile, true); Logger.Log(fileInfo); Logger.Stop(); } Console.WriteLine(Strings.Done); return CommandLineResult.SucceededExit; } // -update <filename> <metadata key> <metadata value> if (commands.ContainsKey(Strings.Command_Update)) { this.RunCommandLine(); if (commands[Strings.Command_Update].Count != 3) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Update)); return CommandLineResult.Invalid; } string filePath = commands[Strings.Command_Update][0]; string key = commands[Strings.Command_Update][1]; object value = commands[Strings.Command_Update][2]; this.CheckFile(filePath); string metadataText = string.Empty; if (streamList.Count > 0) { // update stream metadata foreach (string streamName in streamList) { Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.UpdatingStreamMetadata, streamName)); metadataText = this.EditMetadata(filePath, key, value, streamName, updatePersonalMetadata, true); Console.WriteLine(metadataText); } } else { // update file metadata Console.WriteLine(Strings.UpdatingFileMetadata); metadataText = this.EditMetadata(filePath, key, value, string.Empty, updatePersonalMetadata, false); Console.WriteLine(metadataText); } Console.WriteLine(Strings.Done); return CommandLineResult.SucceededExit; } // -remove <filename> <metadata key> if (commands.ContainsKey(Strings.Command_Remove)) { this.RunCommandLine(); if (commands[Strings.Command_Remove].Count != 2) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Remove)); return CommandLineResult.Invalid; } string filePath = commands[Strings.Command_Remove][0]; string key = commands[Strings.Command_Remove][1]; this.CheckFile(filePath); string metadataText = string.Empty; if (streamList.Count > 0) { // update stream metadata foreach (string streamName in streamList) { Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.UpdatingStreamMetadata, streamName)); metadataText = this.EditMetadata(filePath, key, null, streamName, updatePersonalMetadata, true); Console.WriteLine(metadataText); } } else { // update file metadata Console.WriteLine(Strings.UpdatingFileMetadata); metadataText = this.EditMetadata(filePath, key, null, string.Empty, updatePersonalMetadata, false); Console.WriteLine(metadataText); } Console.WriteLine(Strings.Done); return CommandLineResult.SucceededExit; } // -play <filename> if (commands.ContainsKey(Strings.Command_Play)) { this.RunCommandLine(); if (commands[Strings.Command_Play].Count != 1) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Play)); return CommandLineResult.Invalid; } string filePath = commands[Strings.Command_Play][0]; this.CheckFile(filePath); using (KStudioClient client = KStudio.CreateClient()) { Console.WriteLine(Strings.WaitToConnect); client.ConnectToService(); Console.WriteLine(Strings.StartPlayback); Playback.PlaybackClip(client, filePath, streamList, loopCount); Console.WriteLine(Strings.StopPlayback); client.DisconnectFromService(); } Console.WriteLine(Strings.Done); return CommandLineResult.SucceededExit; } // -record <filename> <duration> if (commands.ContainsKey(Strings.Command_Record)) { this.RunCommandLine(); if (commands[Strings.Command_Record].Count != 2) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Record)); return CommandLineResult.Invalid; } string filePath = commands[Strings.Command_Record][0]; this.CheckDirectory(filePath); double time = 0; if (!double.TryParse(commands[Strings.Command_Record][1], out time)) { Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Record)); return CommandLineResult.Invalid; } TimeSpan duration = TimeSpan.FromSeconds(time); string errorMsg = string.Empty; string fileInfo = string.Empty; using (KStudioClient client = KStudio.CreateClient()) { Console.WriteLine(Strings.WaitToConnect); client.ConnectToService(); Console.WriteLine(Strings.StartRecording); Recording.RecordClip(client, filePath, duration, streamList); Console.WriteLine(Strings.StopRecording); using (KStudioEventFile eventFile = client.OpenEventFile(filePath)) { FileData fileData = new FileData(eventFile); fileInfo = fileData.GetFileDataAsText(); Console.WriteLine(fileInfo); } client.DisconnectFromService(); } if (!string.IsNullOrEmpty(logFile)) { Logger.Start(logFile, true); Logger.Log(fileInfo); Logger.Stop(); } Console.WriteLine(Strings.Done); return CommandLineResult.SucceededExit; } } catch (Exception ex) { string errorMsg = string.Format(Strings.ErrorPrepend, ex.Message); Console.Error.WriteLine(errorMsg); return CommandLineResult.Failed; } return CommandLineResult.Invalid; }