public CommandHandlerResult SetAndEvaluateClipData(Clip clipToEvaluate) { if (ClipSet[clipToEvaluate.ClipReference] != ClipSlot.Empty && clipToEvaluate.Equals(ClipSet[clipToEvaluate.ClipReference].Clip)) { return CommandHandlerResult.AbortedResult with { Warnings = new List <string> { $"Aborted evaluation of clip at {clipToEvaluate.ClipReference.ToString()} since it was unchanged." } } } ; var clipSlot = new ClipSlot("", clipToEvaluate, Formula.Empty); ClipSet[clipSlot.ClipReference] = clipSlot; var clipReferences = ClipSet.GetAllDependentClipRefsFromClipRef(clipSlot.ClipReference); var allClipsByClipRef = ClipSet.GetAllReferencedClipsByClipRef(); var orderedClipReferences = ClipSet.GetClipReferencesInProcessableOrder( clipReferences.Distinct().ToDictionary( key => key, key => allClipsByClipRef[key] .Where(x => clipReferences.Contains(x)) .ToList())); Debug.WriteLine($"Found dependencies: {string.Join(' ', clipReferences.Select(x => x.ToString()))}"); Debug.WriteLine($"Found sorted: {string.Join(' ', orderedClipReferences.Result.Select(x => x.ToString()))}"); var clipsToProcess = ClipSet.GetClipSlotsFromClipReferences(orderedClipReferences.Result); var(successfulClips, errors) = ClipSet.ProcessClips(clipsToProcess); return(CommandHandlerResult.CompletedResult with { SuccessfulClips = ClipSet.GetClipsFromClipReferences(successfulClips).ToList(), Errors = errors }); }
public CommandHandlerResult SetAndEvaluateFormula(string formula, int trackNo, int clipNo) { var clipRef = new ClipReference(trackNo, clipNo); if (ClipSet[clipRef] != ClipSlot.Empty && ClipSet[clipRef].Name == formula) { return CommandHandlerResult.AbortedResult with { Warnings = new List <string> { $"Aborted evaluation of formula at {clipRef.ToString()} since it was unchanged." } } } ; var(success, result, errorMessage) = Parser.ParseFormula(formula); if (!success) { return CommandHandlerResult.AbortedResult with { Errors = new List <string> { errorMessage } } } ; var clipSlot = new ClipSlot(formula, new Clip(clipRef), result); ClipSet[clipSlot.ClipReference] = clipSlot; var(successfulClipRefs, errors) = ClipSet.ProcessClips(new [] { clipSlot }); return(CommandHandlerResult.CompletedResult with { SuccessfulClips = ClipSet.GetClipsFromClipReferences(successfulClipRefs).ToList(), Errors = errors }); }
public void SetClipData(Clip clip) { if (clip != Clip.Empty) { var clipSlot = new ClipSlot("", clip, Formula.Empty); ClipSet[clipSlot.ClipReference] = clipSlot; } }
public void SetFormula(int trackNo, int clipNo, string formula) { var parsedFormula = Parser.ParseFormula(formula); if (parsedFormula.Success) { var clipRef = new ClipReference(trackNo, clipNo); var clipSlot = new ClipSlot(formula, new Clip(clipRef), parsedFormula.Result); ClipSet[clipSlot.ClipReference] = clipSlot; } }
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); }
public InternalCommand(InternalCommandType type, ClipSlot clipSlot, ClipReference[] clipReferences = null) { Type = type; ClipSlot = clipSlot; ClipReferences = clipReferences ?? new ClipReference[0]; }