Ejemplo n.º 1
0
            private void OnParseRequest(string rawValue, ref ControllerCollection childrenContainer, Global.ArgumentInfoCollection contentArguments)
            {
                MatchCollection mainPatternMatches = RegularExpression.Current.MainCapturePattern.Matches(rawValue);

                if (mainPatternMatches.Count == 0)
                {
                    childrenContainer.Add(new Renderless(0, rawValue, contentArguments));
                }
                else
                {
                    int lastIndex = 0;

                    Match mainSearchMatch;
                    // For Opening Brackets
                    Match  bracketOpenExamMatch;
                    string directiveType, directiveID;
                    // For Separator Brackets
                    Match bracketSeparatorExamMatch;
                    // For Closing Brackets
                    Match bracketCloseExamMatch;

                    IEnumerator remEnum = mainPatternMatches.GetEnumerator();

                    while (remEnum.MoveNext())
                    {
                        mainSearchMatch = (Match)remEnum.Current;

                        // Check till this match any renderless content exists
                        if (mainSearchMatch.Index > lastIndex)
                        {
                            childrenContainer.Add(
                                new Renderless(
                                    lastIndex,
                                    rawValue.Substring(lastIndex, mainSearchMatch.Index - lastIndex),
                                    contentArguments
                                    )
                                );
                            lastIndex = mainSearchMatch.Index;
                        }

                        // Exam For Bracketed Regex Result
                        bracketOpenExamMatch = RegularExpression.Current.BracketedControllerOpenPattern.Match(mainSearchMatch.Value);

                        if (bracketOpenExamMatch.Success)
                        {
                            directiveType = bracketOpenExamMatch.Result("${DirectiveType}");
                            directiveID   = bracketOpenExamMatch.Result("${ItemID}");

                            if (directiveID != null)
                            {
                                int        innerMatch       = 0;
                                List <int> separatorIndexes = new List <int>();

                                while (remEnum.MoveNext())
                                {
                                    Match mainSearchMatchExam = (Match)remEnum.Current;

                                    // Exam For Opening Bracketed Regex Result
                                    bracketOpenExamMatch =
                                        RegularExpression.Current.BracketedControllerOpenPattern.Match(mainSearchMatchExam.Value);
                                    // Check is Another Same Named Control Internally Opened Bracket
                                    if (bracketOpenExamMatch.Success &&
                                        string.Compare(directiveID, bracketOpenExamMatch.Result("${ItemID}")) == 0)
                                    {
                                        innerMatch += 1;

                                        continue;
                                    }

                                    // Exam For Separator Bracketed Regex Result
                                    bracketSeparatorExamMatch =
                                        RegularExpression.Current.BracketedControllerSeparatorPattern.Match(mainSearchMatchExam.Value);
                                    // Check is Same Named Highlevel Control Separator Bracket
                                    if (bracketSeparatorExamMatch.Success &&
                                        string.Compare(directiveID, bracketSeparatorExamMatch.Result("${ItemID}")) == 0 &&
                                        innerMatch == 0)
                                    {
                                        // Point the location of Separator Bracket index
                                        separatorIndexes.Add(mainSearchMatchExam.Index - mainSearchMatch.Index);

                                        continue;
                                    }

                                    // Exam For Closing Bracketed Regex Result
                                    bracketCloseExamMatch =
                                        RegularExpression.Current.BracketedControllerClosePattern.Match(mainSearchMatchExam.Value);
                                    // Check is Same Named Control Internally Closed Bracket
                                    if (bracketCloseExamMatch.Success &&
                                        string.Compare(directiveID, bracketCloseExamMatch.Result("${ItemID}")) == 0)
                                    {
                                        if (innerMatch > 0)
                                        {
                                            innerMatch -= 1;

                                            continue;
                                        }

                                        string modifierText         = string.Format("~{0}", mainSearchMatch.Index);
                                        string pointedOriginalValue =
                                            rawValue.Substring(mainSearchMatch.Index, (mainSearchMatchExam.Index + mainSearchMatchExam.Length) - mainSearchMatch.Index);

                                        pointedOriginalValue = pointedOriginalValue.Insert(pointedOriginalValue.Length - 1, modifierText);
                                        for (int idxID = separatorIndexes.Count - 1; idxID >= 0; idxID += -1)
                                        {
                                            pointedOriginalValue = pointedOriginalValue.Insert((separatorIndexes[idxID] + string.Format("}}:{0}", directiveID).Length), modifierText);
                                        }
                                        pointedOriginalValue = pointedOriginalValue.Insert(mainSearchMatch.Length - 2, modifierText);

                                        IController workingDirective = null;

                                        string directiveRawValue = string.Format("${0}:", (string.IsNullOrEmpty(directiveType) ? directiveID : directiveType));
                                        switch (DirectiveHelper.CaptureDirectiveType(directiveRawValue))
                                        {
                                        case DirectiveTypes.Control:
                                            workingDirective = ControlHelper.MakeControl(mainSearchMatch.Index, pointedOriginalValue, null, this.OnControlResolveRequest);

                                            break;

                                        case DirectiveTypes.InLineStatement:
                                            workingDirective = new InLineStatement(mainSearchMatch.Index, pointedOriginalValue, null);

                                            break;

                                        case DirectiveTypes.UpdateBlock:
                                            workingDirective = new UpdateBlock(mainSearchMatch.Index, pointedOriginalValue, null);

                                            break;

                                        case DirectiveTypes.EncodedExecution:
                                            workingDirective = new EncodedExecution(mainSearchMatch.Index, pointedOriginalValue, null);

                                            break;

                                        case DirectiveTypes.MessageBlock:
                                            workingDirective = new MessageBlock(mainSearchMatch.Index, pointedOriginalValue, null);

                                            break;

                                        case DirectiveTypes.PartialCache:
                                            workingDirective = new PartialCache(mainSearchMatch.Index, pointedOriginalValue, null);

                                            break;
                                        }

                                        if (workingDirective != null)
                                        {
                                            if (workingDirective is IDeploymentAccessRequires)
                                            {
                                                ((IDeploymentAccessRequires)workingDirective).DeploymentAccessRequested += this.OnDeploymentAccessRequest;
                                            }

                                            if (workingDirective is IInstanceRequires)
                                            {
                                                ((IInstanceRequires)workingDirective).InstanceRequested += this.OnInstanceRequest;
                                            }

                                            childrenContainer.Add(workingDirective);
                                        }

                                        lastIndex = (mainSearchMatchExam.Index + mainSearchMatchExam.Length);

                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            switch (ControllerHelper.CaptureControllerType(mainSearchMatch.Value))
                            {
                            case ControllerTypes.Property:
                                Property propertyDirective =
                                    new Property(mainSearchMatch.Index, mainSearchMatch.Value, contentArguments);
                                propertyDirective.InstanceRequested += this.OnInstanceRequest;

                                childrenContainer.Add(propertyDirective);

                                break;

                            case ControllerTypes.Directive:
                                IController workingDirective = null;

                                switch (DirectiveHelper.CaptureDirectiveType(mainSearchMatch.Value))
                                {
                                case DirectiveTypes.Control:
                                    workingDirective = ControlHelper.MakeControl(mainSearchMatch.Index, mainSearchMatch.Value, null, this.OnControlResolveRequest);

                                    break;

                                case DirectiveTypes.Template:
                                    workingDirective = new Template(mainSearchMatch.Index, mainSearchMatch.Value, null);

                                    break;

                                case DirectiveTypes.Translation:
                                    workingDirective = new Translation(mainSearchMatch.Index, mainSearchMatch.Value, null);

                                    break;

                                case DirectiveTypes.HashCodePointedTemplate:
                                    workingDirective = new HashCodePointedTemplate(mainSearchMatch.Index, mainSearchMatch.Value, null);

                                    break;

                                case DirectiveTypes.Execution:
                                    workingDirective = new Execution(mainSearchMatch.Index, mainSearchMatch.Value, null);

                                    break;

                                case DirectiveTypes.InLineStatement:
                                    workingDirective = new InLineStatement(mainSearchMatch.Index, mainSearchMatch.Value, null);

                                    break;

                                case DirectiveTypes.UpdateBlock:
                                    workingDirective = new UpdateBlock(mainSearchMatch.Index, mainSearchMatch.Value, null);

                                    break;

                                case DirectiveTypes.EncodedExecution:
                                    workingDirective = new EncodedExecution(mainSearchMatch.Index, mainSearchMatch.Value, null);

                                    break;

                                case DirectiveTypes.PartialCache:
                                    workingDirective = new PartialCache(mainSearchMatch.Index, mainSearchMatch.Value, null);

                                    break;
                                }

                                if (workingDirective != null)
                                {
                                    if (workingDirective is IDeploymentAccessRequires)
                                    {
                                        ((IDeploymentAccessRequires)workingDirective).DeploymentAccessRequested += this.OnDeploymentAccessRequest;
                                    }

                                    if (workingDirective is IInstanceRequires)
                                    {
                                        ((IInstanceRequires)workingDirective).InstanceRequested += this.OnInstanceRequest;
                                    }

                                    childrenContainer.Add(workingDirective);
                                }

                                break;
                            }

                            lastIndex = (mainSearchMatch.Index + mainSearchMatch.Value.Length);
                        }
                    }

                    if (rawValue.Length - lastIndex > 1)
                    {
                        childrenContainer.Add(
                            new Renderless(lastIndex, rawValue.Substring(lastIndex), contentArguments));
                    }
                }
            }