예제 #1
0
    public Task LogMessage(byte[] data)
    {
        var text = Decoder.GetText(data);

        Console.WriteLine($"From client: {text}");
        return(Task.CompletedTask);
    }
예제 #2
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);
    }