public Task SetFormula(byte[] data)
 {
     var(trackNo, clipNo, formula) = Decoder.GetFormula(data);
     Console.WriteLine($"{trackNo}, {clipNo}: Incoming formula {formula}");
     CommandHandler.SetFormula(trackNo, clipNo, formula);
     return(Task.CompletedTask);
 }
    public Task LogMessage(byte[] data)
    {
        var text = Decoder.GetText(data);

        Console.WriteLine($"From client: {text}");
        return(Task.CompletedTask);
    }
    public Task SetClipData(bool isLive11, byte[] data)
    {
        var clip = isLive11 ? Decoder.GetSingleLive11Clip(data) : Decoder.GetSingleClip(data);

        Console.WriteLine($"{clip.ClipReference.Track}, {clip.ClipReference.Clip} Incoming clip data");
        CommandHandler.SetClipData(clip);
        return(Task.CompletedTask);
    }
    public static void InputShouldProduceGivenOutput(byte[] input, byte[] output)
    {
        var(clips, formula, id, trackNo) = Decoder.DecodeData(input);
        var chainedCommandWrapper = Parser.ParseFormulaToChainedCommand(formula, clips, new ClipMetaData(id, trackNo));

        Assert.IsTrue(chainedCommandWrapper.Success);

        var processedClipWrapper = ClipProcessor.ProcessChainedCommand(chainedCommandWrapper.Result);

        Assert.IsTrue(processedClipWrapper.Success);
        Assert.IsTrue(processedClipWrapper.Result.Length > 0);

        var processedClip = processedClipWrapper.Result[0];

        byte[] clipData = IOUtilities.GetClipAsBytes(chainedCommandWrapper.Result.TargetMetaData.Id, processedClip).ToArray();

        Assert.IsTrue(output.Length == clipData.Length);
        Assert.IsTrue(output.SequenceEqual(clipData));
    }
    public async Task SetAndEvaluateFormula(bool isLive11, byte[] data)
    {
        var(trackNo, clipNo, formula) = Decoder.GetFormula(data);
        Console.WriteLine($"{trackNo}, {clipNo}: Incoming formula {formula}");
        var result = CommandHandler.SetAndEvaluateFormula(formula, trackNo, clipNo);

        PrintErrorsAndWarnings(result);
        if (result.RanToCompletion == false)
        {
            return;
        }

        foreach (var clip in result.SuccessfulClips)
        {
            await Clients.All.SetClipDataOnClient(isLive11,
                                                  isLive11
                                                  ?IOUtilities.GetClipAsBytesLive11(clip).ToArray()
                                                      : IOUtilities.GetClipAsBytesV2(clip).ToArray());
        }
    }
    public async Task SetAndEvaluateClipData(bool isLive11, byte[] data)
    {
        var clip = isLive11 ? Decoder.GetSingleLive11Clip(data) : Decoder.GetSingleClip(data);

        Console.WriteLine($"{clip.ClipReference.Track}, {clip.ClipReference.Clip} Incoming clip data to evaluate");
        var result = CommandHandler.SetAndEvaluateClipData(clip);

        PrintErrorsAndWarnings(result);
        if (result.RanToCompletion == false)
        {
            return;
        }

        foreach (var successfulClip in result.SuccessfulClips)
        {
            await Clients.All.SetClipDataOnClient(isLive11,
                                                  isLive11
                                                  ?IOUtilities.GetClipAsBytesLive11(successfulClip).ToArray()
                                                      : IOUtilities.GetClipAsBytesV2(successfulClip).ToArray());
        }
    }
Exemple #7
0
    public static LegacyClipSlot HandleInput(byte[] inputData)
    {
        var generateUnitTest = false;
        var generateSvgDoc   = false;

        if (Decoder.IsStringData(inputData))
        {
            string text = Decoder.GetText(inputData);
            Console.WriteLine(text);
            return(LegacyClipSlot.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(LegacyClipSlot.Empty);
        }

        ProcessResult <Clip[]> processedClipWrapper;

        try
        {
            processedClipWrapper = ClipProcessor.ProcessChainedCommand(chainedCommandWrapper.Result);
        }
        catch (Exception e)
        {
            processedClipWrapper =
                new ProcessResult <Clip[]>($"{formula}. Please check your syntax. Exception: {e.Message}");
        }

        if (processedClipWrapper.WarningMessage.Length > 0)
        {
            Console.WriteLine($"Warnings were generated:{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);
            }

            LegacyClipSlot processedLegacyClipSlot =
                new LegacyClipSlot(formula, processedClip, chainedCommandWrapper.Result, id);
            return(processedLegacyClipSlot);
        }

        Console.WriteLine($"Error applying formula: {processedClipWrapper.ErrorMessage}");
        return(LegacyClipSlot.Empty);
    }