Пример #1
0
        TwCommandResult DispatchActionView(TwCommand command, bool next)
        {
            var commandResult = new TwCommandResult();

            var constraint = new TwCommandConstraintBool();

            constraint.Attribute = TwCommandConstraintAttribute.Selected;
            constraint.Value     = true;
            command.Constraints.Add(constraint);

            if (analysisPanel.Analysis.Events.SelectedEvents.Count == 0)
            {
                commandResult.ErrorMessage = "First select one or more events.";
            }
            else if (next)
            {
                analysisPanel.SelectedEventView = analysisPanel.StyledEventsViewer.EventsViewer.FindNext(command, analysisPanel.SelectedEventView);
            }
            else
            {
                analysisPanel.SelectedEventView = analysisPanel.StyledEventsViewer.EventsViewer.FindPrevious(command, analysisPanel.SelectedEventView);
            }

            return(commandResult);
        }
Пример #2
0
        TwCommandConstraint GetConstraint(string[] tokens, ref int index, ref string error)
        {
            error = null;

            var constraintDateTime = DispatchConstraintDateTime(tokens, ref index);

            if (constraintDateTime != null)
            {
                return(constraintDateTime);
            }

            var constraintListItem = DispatchConstraintListItem(tokens, ref index);

            if (constraintListItem != null)
            {
                return(constraintListItem);
            }

            switch (tokens[index])
            {
            case "volume":
            case "vol":
                try {
                    var constraint = new TwCommandConstraintDouble();
                    constraint.Attribute = TwCommandConstraintAttribute.Volume;
                    constraint.Relation  = GetRelation(tokens[index + 1]);
                    constraint.Value     = double.Parse(tokens[index + 2]);
                    index = index + 3;
                    return(constraint);
                } catch {
                    error = "Invalid Volume constraint";
                    return(null);
                }

            case "peak":
            case "pe":
            case "pk":
                try {
                    var constraint = new TwCommandConstraintDouble();
                    constraint.Attribute = TwCommandConstraintAttribute.Peak;
                    constraint.Relation  = GetRelation(tokens[index + 1]);
                    constraint.Value     = double.Parse(tokens[index + 2]);
                    index = index + 3;
                    return(constraint);
                } catch {
                    error = "Invalid Peak constraint";
                    return(null);
                }

            case "duration":
            case "dur":
                try {
                    var constraint = new TwCommandConstraintTimeSpan();
                    constraint.Attribute = TwCommandConstraintAttribute.Duration;
                    constraint.Relation  = GetRelation(tokens[index + 1]);
                    constraint.Value     = (TimeSpan)(new TwHelper.FriendlyDurationConverter().ConvertBack(tokens[index + 2], null, null, null));
                    if (constraint.Value == TimeSpan.MinValue)
                    {
                        throw new Exception();
                    }
                    index = index + 3;
                    return(constraint);
                } catch {
                    error = "Invalid Duration constraint";
                    return(null);
                }

            case "mode":
            case "md":
                try {
                    var constraint = new TwCommandConstraintDouble();
                    constraint.Attribute = TwCommandConstraintAttribute.Mode;
                    constraint.Relation  = GetRelation(tokens[index + 1]);
                    constraint.Value     = Double.Parse(tokens[index + 2]);
                    index = index + 3;
                    return(constraint);
                } catch {
                    error = "Invalid Mode constraint";
                    return(null);
                }

            case "1stcycle":
            case "-1stcycle":
            case "1st":
            case "-1st":
            case "1":
            case "-1":
                try {
                    var constraint = new TwCommandConstraintBool();
                    constraint.Attribute = TwCommandConstraintAttribute.FirstCycle;
                    constraint.Value     = tokens[index][0] == '-' ? false :true;
                    index = index + 1;
                    return(constraint);
                } catch { return(null); }

            case "manuallyclassified":
            case "-manuallyclassified":
            case "manual":
            case "-manual":
            case "man":
            case "-man":
            case "preserved":
            case "-preserved":
                try {
                    var constraint = new TwCommandConstraintBool();
                    constraint.Attribute = TwCommandConstraintAttribute.ManuallyClassified;
                    constraint.Value     = tokens[index][0] == '-' ? false : true;
                    index = index + 1;
                    return(constraint);
                } catch { return(null); }

            case "classifiedusingmachinelearning":
            case "-classifiedusingmachinelearning":
            case "classifiedbymachinelearning":
            case "-classifiedbymachinelearning":
            case "machinelearning":
            case "-machinelearning":
            case "machine":
            case "-machine":
                try {
                    var constraint = new TwCommandConstraintBool();
                    constraint.Attribute = TwCommandConstraintAttribute.ClassifiedUsingMachineLearning;
                    constraint.Value     = tokens[index][0] == '-' ? false : true;
                    index = index + 1;
                    return(constraint);
                } catch { return(null); }

            case "classifedusingfixturelist":
            case "-classifiedusingfixturelist":
            case "classifedbyfixturelist":
            case "-classifiedbyfixturelist":
            case "fixturelist":
            case "-fixturelist":
            case "list":
            case "-list":
                try {
                    var constraint = new TwCommandConstraintBool();
                    constraint.Attribute = TwCommandConstraintAttribute.ClassifiedUsingFixtureList;
                    constraint.Value     = tokens[index][0] == '-' ? false : true;
                    index = index + 1;
                    return(constraint);
                } catch { return(null); }

            case "manuallyapproved":
            case "-manuallyapproved":
            case "manuallyapprove":
            case "-manuallyapprove":
            case "approved":
            case "-approved":
            case "approve":
            case "-approve":
            case "app":
            case "-app":
                try {
                    var constraint = new TwCommandConstraintBool();
                    constraint.Attribute = TwCommandConstraintAttribute.Approved;
                    constraint.Value     = tokens[index][0] == '-' ? false : true;
                    index = index + 1;
                    return(constraint);
                } catch { return(null); }

            case "similar":
            case "-similar":
            case "sim":
            case "-sim":
                try {
                    var constraint = new TwCommandConstraintInteger();
                    constraint.Attribute = TwCommandConstraintAttribute.Similar;
                    constraint.Relation  = GetRelation(tokens[index + 1]);
                    constraint.Value     = int.Parse(tokens[index + 2]);
                    index = index + 3;
                    return(constraint);
                } catch {
                    try {
                        var constraint = new TwCommandConstraintBoolEvent();
                        constraint.Attribute = TwCommandConstraintAttribute.Similar;
                        constraint.Value     = tokens[index][0] == '-' ? false : true;
                        index = index + 1;
                        return(constraint);
                    } catch { return(null); }
                }

            case "selected":
            case "-selected":
            case "sel":
            case "-sel":
                try {
                    var constraint = new TwCommandConstraintBool();
                    constraint.Attribute = TwCommandConstraintAttribute.Selected;
                    constraint.Value     = tokens[index][0] == '-' ? false : true;
                    index = index + 1;
                    return(constraint);
                } catch { return(null); }

            case "super":
                try {
                    var constraint = new TwCommandConstraintBool();
                    constraint.Attribute = TwCommandConstraintAttribute.Super;
                    constraint.Value     = tokens[index][0] == '-' ? false : true;
                    index = index + 1;
                    return(constraint);
                } catch { return(null); }

            case "notes":
                try {
                    var constraint = new TwCommandConstraintBool();
                    constraint.Attribute = TwCommandConstraintAttribute.Notes;
                    constraint.Value     = tokens[index][0] == '-' ? false : true;
                    index = index + 1;
                    return(constraint);
                } catch { return(null); }

            default:
                error = "Invalid constraint: " + BuildTokens(tokens, index);
                return(null);
            }
        }