public static ProcessResultArray <Clip> ProcessChainedCommand(ChainedCommand chainedCommand) { Clip[] sourceClips = chainedCommand.SourceClips.Where(c => c.Notes.Count > 0).ToArray(); if (sourceClips.Length < 1) { return(new ProcessResultArray <Clip>("No clips or empty clips specified. Aborting.")); } var currentSourceClips = sourceClips; var resultContainer = new ProcessResultArray <Clip>("No commands specified"); var warnings = new List <string>(); foreach (var command in chainedCommand.Commands) { resultContainer = ProcessCommand(command, currentSourceClips, chainedCommand.TargetMetaData); if (resultContainer.Success) { currentSourceClips = resultContainer.Result; if (resultContainer.WarningMessage.Length > 0) { warnings.Add(resultContainer.WarningMessage); } } else { break; } } if (warnings.Count > 0) { resultContainer = new ProcessResultArray <Clip>(resultContainer.Success, resultContainer.Result, resultContainer.ErrorMessage, string.Join(System.Environment.NewLine, warnings)); } return(resultContainer); }
public static ClipSlot HandleInput(byte[] inputData) { var generateUnitTest = false; var generateSvgDoc = false; if (Decoder.IsStringData(inputData)) { string text = Decoder.GetText(inputData); Console.WriteLine(text); return(ClipSlot.Empty); } (List <Clip> clips, string formula, ushort id, byte trackNo) = Decoder.DecodeData(inputData); formula = formula.Trim(' '); Console.WriteLine($"Received {clips.Count} clips and formula: {formula}"); if (formula.EndsWith(UnitTestDirective)) { Console.WriteLine( $"Saving autogenerated unit test to {Path.Join(Environment.CurrentDirectory, "GeneratedUnitTests.txt")}"); formula = formula.Substring(0, formula.Length - UnitTestDirective.Length); generateUnitTest = true; } if (formula.EndsWith(SvgDocDirective)) { Console.WriteLine( $"Saving autogenerated SVG documentation for this formula to {Path.Join(Environment.CurrentDirectory, "GeneratedDocs.svg")}"); formula = formula.Substring(0, formula.Length - SvgDocDirective.Length); generateSvgDoc = true; } var chainedCommandWrapper = Parser.ParseFormulaToChainedCommand(formula, clips, new ClipMetaData(id, trackNo)); if (!chainedCommandWrapper.Success) { Console.WriteLine(chainedCommandWrapper.ErrorMessage); return(ClipSlot.Empty); } ProcessResultArray <Clip> processedClipWrapper; try { processedClipWrapper = ClipProcessor.ProcessChainedCommand(chainedCommandWrapper.Result); } catch (Exception e) { processedClipWrapper = new ProcessResultArray <Clip>($"{formula}. Please check your syntax. Exception: {e.Message}"); } if (processedClipWrapper.WarningMessage.Length > 0) { Console.WriteLine($"Warnings were generated:{System.Environment.NewLine}" + $"{processedClipWrapper.WarningMessage}"); } if (processedClipWrapper.Success && processedClipWrapper.Result.Length > 0) { var processedClip = processedClipWrapper.Result[0]; byte[] processedClipData = IOUtilities.GetClipAsBytes(chainedCommandWrapper.Result.TargetMetaData.Id, processedClip).ToArray(); if (generateUnitTest) { TestUtilities.AppendUnitTest(formula, inputData, processedClipData); } if (generateSvgDoc) { SvgUtilities.GenerateSvgDoc(formula, clips, processedClip, 882, 300); } ClipSlot processedClipSlot = new ClipSlot(formula, processedClip, chainedCommandWrapper.Result, id); return(processedClipSlot); } Console.WriteLine($"Error applying formula: {processedClipWrapper.ErrorMessage}"); return(ClipSlot.Empty); }