コード例 #1
0
    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
        });
    }