Esempio n. 1
0
 private IEnumerable <SceneNode> IncrementalTraverseWithSearchPath(SceneNode basisNode, DocumentNodeMarker rootMarker)
 {
     if (this.path.NumberOfSteps == 1)
     {
         SearchStep step = this.path.Step(0);
         if (step.Axis == SearchAxis.DocumentDescendant && (step.Predicate == null || (step.Predicate.AnalysisScope & (SearchScope)6) == step.Predicate.AnalysisScope))
         {
             SceneNode rootSceneNode = this.currentViewModel.GetSceneNode(rootMarker.Node);
             if (step.ContinuePredicate != null)
             {
                 for (DocumentNode node = rootMarker.Node; node != null && node != basisNode.DocumentNode; node = (DocumentNode)node.Parent)
                 {
                     if (!step.ContinuePredicate.Test(this.currentViewModel.GetSceneNode(node)))
                     {
                         yield break;
                     }
                 }
             }
             if (step.Predicate == null || step.Predicate.Test(rootSceneNode))
             {
                 yield return(rootSceneNode);
             }
             foreach (SceneNode sceneNode in this.path.Query(rootSceneNode))
             {
                 yield return(sceneNode);
             }
         }
     }
 }
Esempio n. 2
0
    private List <SearchStep> GetSearchParts(List <StatementPart> parts)
    {
        var result = new List <SearchStep>();

        foreach (var part in parts)
        {
            var step = new SearchStep(part);
            step.Level = _level;
            result.Add(step);
        }

        return(result);
    }
Esempio n. 3
0
        public QueryPlan GetPlan(string input)
        {
            var plan              = new QueryPlan();
            var items             = input.Split(';');
            var databaseStatement = string.Empty;
            var commandStatement  = string.Empty;

            if (items.Count() > 0)
            {
                databaseStatement = items[0];
                commandStatement  = items[1];
            }

            var databaseName = GetDatabaseName(databaseStatement);

            if (IsDDLStatment(input))
            {
                FrostIDDLStatement statement = GetDDLStatement(commandStatement, databaseName);

                if (string.IsNullOrEmpty(statement.DatabaseName))
                {
                    statement.DatabaseName = databaseName;
                }
                else
                {
                    databaseName = statement.DatabaseName;
                }
                plan = _planGenerator.GeneratePlan(statement, databaseName);
            }
            else
            {
                FrostIDMLStatement statement = GetDMLStatement(commandStatement, databaseName);
                statement.DatabaseName = databaseName;
                if (!statement.IsValid)
                {
                    var step = new SearchStep();
                    step.IsValid = false;
                    plan.Steps.Add(step);
                }
                else
                {
                    plan = _planGenerator.GeneratePlan(statement, databaseName);
                }
            }

            return(plan);
        }
Esempio n. 4
0
        public override void Start()
        {
            SearchStep searchStep = new SearchStep();

            searchStep.Start();
        }
Esempio n. 5
0
        /// <summary>
        /// Overrides the normal searching waits to take half as long as normal. useful through dynamic polymorphism
        /// </summary>
        protected override void AddSearchStep()
        {
            SearchStep searchStep = new SearchStep(finalStep.Location, SearchStep.defaultTime / 2, this, map);

            plannedActions.Add(searchStep);
        }
Esempio n. 6
0
        public void ChainUpdate(SceneViewModel viewModel, DocumentNodeMarkerSortedListBase newBasisNodes, IEnumerable <SceneNode> bonusBasisNodes, DocumentNodeChangeList damage, uint damageChangeStamp)
        {
            this.ValidateBasisNodeStateWithViewModel(viewModel);
            if (this.currentViewModel == null)
            {
                return;
            }
            SearchScope searchScope = (SearchScope)6;
            SearchScope scope       = this.path.Scope;
            bool        flag1       = (scope & searchScope) != scope;
            bool        flag2       = false;

            if (this.path.NumberOfSteps == 1)
            {
                SearchStep searchStep = this.path.Step(0);
                if (searchStep.Axis == SearchAxis.DocumentDescendant && (searchStep.Predicate.AnalysisScope & (SearchScope)6) == searchStep.Predicate.AnalysisScope)
                {
                    flag2 = true;
                }
            }
            if (newBasisNodes != null || bonusBasisNodes != null)
            {
                DocumentNodeMarkerSortedListOf <SceneNodeSubscription <basisT, pathT> .BasisNodeHolder> newBasisNodeList = new DocumentNodeMarkerSortedListOf <SceneNodeSubscription <basisT, pathT> .BasisNodeHolder>(newBasisNodes.Count);
                if (newBasisNodes != null)
                {
                    for (int index = 0; index < newBasisNodes.Count; ++index)
                    {
                        newBasisNodeList.Add(newBasisNodes.MarkerAt(index), (SceneNodeSubscription <basisT, pathT> .BasisNodeHolder)null);
                    }
                }
                if (bonusBasisNodes != null)
                {
                    foreach (SceneNode sceneNode in bonusBasisNodes)
                    {
                        newBasisNodeList.Add(sceneNode.DocumentNode.Marker, (SceneNodeSubscription <basisT, pathT> .BasisNodeHolder)null);
                    }
                }
                this.SetBasisNodesWorker(viewModel, newBasisNodeList);
            }
            foreach (DocumentNodeMarkerSortedListBase.IntersectionResult intersectionResult in this.pathNodeList.Intersect((DocumentNodeMarkerSortedListBase)damage, DocumentNodeMarkerSortedListBase.Flags.Contains))
            {
                this.OnPathNodeContentChanged(this.pathNodeList.ValueAt(intersectionResult.LeftHandSideIndex), damage.MarkerAt(intersectionResult.RightHandSideIndex), damage.ValueAt(intersectionResult.RightHandSideIndex));
            }
            if (flag1)
            {
                this.Recalculate(viewModel);
            }
            else
            {
                for (int index = this.basisNodeList.Count - 1; index >= 0; --index)
                {
                    if (this.basisNodeList.MarkerAt(index).IsDeleted)
                    {
                        this.RemoveBasisNode(index);
                    }
                    else if (flag2)
                    {
                        this.IncrementalRecalculateBasisNode(index, damage, damageChangeStamp);
                    }
                    else
                    {
                        this.RecalculateBasisNode(index);
                    }
                }
            }
        }
Esempio n. 7
0
    private BoolStep GetBoolStepFromStep(SearchStep step, string boolTerm, List <SearchStep> steps, List <BoolStep> boolSteps)
    {
        Console.WriteLine($"GetBoolStepFromStep: {step.Part.TextWithWhiteSpace}");

        var      stepParentText      = step.Part.StatementParentWithWhiteSpace;
        var      stepGrandParentText = step.Part.StatementGrandParentWithWhiteSpace;
        BoolStep boolStep            = null;

        // if the previous step has a BOOLEAN and is not part of a () grouping
        if (stepParentText.Contains(boolTerm) && !stepParentText.Contains("("))
        {
            boolStep          = new BoolStep();
            boolStep.Level    = _level;
            boolStep.Boolean  = boolTerm.Trim();
            boolStep.InputOne = step;
            int indexOfBool = stepParentText.IndexOf(boolTerm);

            // need to find the other half of the BOOL statement
            var otherTermText = stepParentText.Substring(indexOfBool);
            int i             = otherTermText.IndexOf(boolTerm);
            otherTermText = otherTermText.Remove(i, boolTerm.Length);
            var otherTerm = steps.Where(s => s.Part.TextWithWhiteSpace.Equals(otherTermText)).FirstOrDefault();
            if (otherTerm != null)
            {
                // make sure we don't already have a boolstep for ourselves
                if (otherTerm.Part.Text != step.Part.Text)
                {
                    boolStep.InputTwo = otherTerm;
                }
                else
                {
                    return(null);
                }
            }
        }

        // if the previous step has a boolean AND is part of a () grouping
        // AGE > 32
        if (stepParentText.Contains(boolTerm) && stepParentText.Contains("("))
        {
            var clauses      = stepParentText.Split('(', ')').ToList();
            var nextStep     = new BoolStep();
            var lastBoolStep = new BoolStep();
            foreach (var clause in clauses)
            {
                foreach (var b in boolSteps)
                {
                    if (b.BoolStepTextWithWhiteSpace.Contains(clause))
                    {
                        lastBoolStep      = b;
                        nextStep.InputOne = b;
                        nextStep.InputTwo = step;
                        break;
                    }
                }
            }

            var parse = stepParentText;
            parse = parse.Remove(parse.IndexOf(lastBoolStep.BoolStepTextWithWhiteSpace), lastBoolStep.BoolStepTextWithWhiteSpace.Length);
            parse = parse.Remove(parse.IndexOf(step.Part.TextWithWhiteSpace), step.Part.TextWithWhiteSpace.Length);
            if (parse.Contains(" AND "))
            {
                nextStep.Boolean = "AND";
            }
            if (parse.Contains(" OR "))
            {
                nextStep.Boolean = "OR";
            }
            nextStep.Level = _level++;
            nextStep.BoolStepTextWithWhiteSpace = stepParentText;
            boolStep = nextStep;
        }

        // if the previous step is part of a multi BOOLEAN (i.e. NAME = MEGAN)
        if (stepParentText.Equals(step.Part.TextWithWhiteSpace) && !stepGrandParentText.Equals(step.Part.TextWithWhiteSpace))
        {
            var totalBools = 0;
            var words      = stepGrandParentText.Split(" ").ToList();
            foreach (var word in words)
            {
                if (word.Equals("AND") || word.Equals("OR"))
                {
                    totalBools++;
                }
            }

            if (totalBools > 1)
            {
                // we know we are part of a multi BOOL operation at the same level and need to
                // find the previous bool operator(s) for the other terms
                foreach (var b in boolSteps)
                {
                    if (b.InputOne is SearchStep && b.InputTwo is SearchStep)
                    {
                        var input1 = (b.InputOne as SearchStep);
                        var input2 = (b.InputTwo as SearchStep);
                        if (stepGrandParentText.Contains(input1.Part.TextWithWhiteSpace) &&
                            stepGrandParentText.Contains(input2.Part.TextWithWhiteSpace))
                        {
                            // we need to link this boolstep to the next planstep
                            var nextStep = new BoolStep();
                            nextStep.Boolean  = boolTerm.Trim();
                            nextStep.Level    = _level++;
                            nextStep.InputOne = b;
                            nextStep.InputTwo = step;
                            var parse = stepGrandParentText;
                            parse = parse.Remove(parse.IndexOf(input1.Part.TextWithWhiteSpace), input1.Part.TextWithWhiteSpace.Length);
                            parse = parse.Remove(parse.IndexOf(b.Boolean), b.Boolean.Length);
                            parse = parse.Remove(parse.IndexOf(input2.Part.TextWithWhiteSpace), input2.Part.TextWithWhiteSpace.Length);
                            parse = parse.Remove(parse.IndexOf(step.Part.TextWithWhiteSpace), step.Part.TextWithWhiteSpace.Length);
                            if (parse.Contains(" AND "))
                            {
                                nextStep.Boolean = "AND";
                            }
                            if (parse.Contains(" OR "))
                            {
                                nextStep.Boolean = "OR";
                            }
                            nextStep.BoolStepTextWithWhiteSpace = stepGrandParentText;
                            boolStep = nextStep;
                            break;
                        }
                    }
                }
            }
            else if (totalBools == 1)
            {
                boolStep          = new BoolStep();
                boolStep.InputOne = steps[0];
                boolStep.InputTwo = steps[1];
                if (stepGrandParentText.Contains(" AND "))
                {
                    boolStep.Boolean = "AND";
                }
                if (stepGrandParentText.Contains(" OR "))
                {
                    boolStep.Boolean = "OR";
                }
            }
        }

        // we are an outermost term
        // NAME = BRIAN
        if (stepParentText.Equals(stepGrandParentText) && boolStep is null &&
            stepParentText != _clause.TextWithWhiteSpace
            )
        {
            if (boolSteps.Count > 0)
            {
                int maxLevel = boolSteps.Max(i => i.Level);
                var maxStep  = boolSteps.Where(i => i.Level == maxLevel).FirstOrDefault();
                if (maxStep != null)
                {
                    boolStep          = new BoolStep();
                    boolStep.InputOne = maxStep;
                    boolStep.InputTwo = step;
                    boolStep.Level    = maxLevel++;

                    // need to find the boolean operator
                    var text = _clause.TextWithWhiteSpace;
                    foreach (var k in steps)
                    {
                        if (k.Part == step.Part)
                        {
                            break;
                        }

                        int i = text.IndexOf(k.Part.TextWithWhiteSpace);
                        text = text.Remove(i, k.Part.TextWithWhiteSpace.Length);
                    }

                    var par = text.Split('(', ')').ToList();
                    par.RemoveAll(p => string.IsNullOrEmpty(p));
                    int previousItem = 0;

                    foreach (var r in par)
                    {
                        if (r == step.Part.TextWithWhiteSpace)
                        {
                            previousItem = par.IndexOf(r) - 1;
                        }
                    }

                    boolStep.Boolean = par[previousItem].Trim();
                }
            }
        }


        if (boolStep != null)
        {
            DebugBoolStep(boolStep);
        }

        return(boolStep);
    }