Example #1
0
        public IActivity Parse(Queue <IXamlElement> token)
        {
            log.Debug(String.Format("Calling parse in activity '{0}'", name));
            // Debug
            initialTokenCount = token.Count;

            //Start Element
            token.Dequeue();

            // OPTIONAL Body
            while (!token.Peek().QName.Equals(this.QName) || !token.Peek().IsClosingElement)
            {
                // OPTIONAL <If.Then>
                if (token.Peek().QName.Equals(createQName("If.Then")))
                {
                    // Start Element
                    token.Dequeue();
                    // <Activity>
                    IActivity activity = moduleFactory.CreateActivity(token.Peek().QName);

                    if (activity != null)
                    {
                        innerThen = activity.Parse(token);
                    }
                    else
                    {
                        throw new ParseException(String.Format("No Module found for activity '{0}'", QName), initialTokenCount - token.Count, QName);
                    }
                    // End Element
                    token.Dequeue();
                }
                // OPTIONAL <If.Else>
                else if (token.Peek().QName.Equals(createQName("If.Else")))
                {
                    // Start Element
                    token.Dequeue();
                    // <Activity>
                    IActivity activity = moduleFactory.CreateActivity(token.Peek().QName);

                    if (activity != null)
                    {
                        innerElse = activity.Parse(token);
                    }
                    else
                    {
                        // TODO Error no match
                    }
                    // End Element
                    token.Dequeue();
                }
                else
                {
                    throw new ParseException(String.Format("Unexpected token found in activity '{0}'", QName), initialTokenCount - token.Count, QName);
                }
            }
            // End Element
            token.Dequeue();

            return(this);
        }
Example #2
0
        public IActivity Parse(Queue <IXamlElement> token)
        {
            log.Debug(String.Format("Calling parse in activity '{0}'", name));
            // Debug
            initialTokenCount = token.Count;

            //Start Element
            token.Dequeue();

            // OPTIONAL Body
            while (!token.Peek().QName.Equals(this.QName) || !token.Peek().IsClosingElement)
            {
                if (token.Peek().QName.Equals(createQName("Switch.Default")))
                {
                    // Start Element
                    token.Dequeue();
                    // <Activity>
                    IActivity activity = moduleFactory.CreateActivity(token.Peek().QName);

                    if (activity != null)
                    {
                        defaultActivity = activity.Parse(token);
                    }
                    else
                    {
                        throw new ParseException(String.Format("No Module found for activity '{0}'", QName), initialTokenCount - token.Count, QName);
                    }
                    // End Element
                    token.Dequeue();
                }
                else if (token.Peek().QName.Equals(createQName("Null", ns_x)))
                {
                    token.Dequeue();
                    token.Dequeue();
                    // Empty Case
                    caseActivities.Add(new Empty());
                }
                else
                {
                    // <Activity>
                    IActivity activity = moduleFactory.CreateActivity(token.Peek().QName);

                    if (activity != null)
                    {
                        caseActivities.Add(activity.Parse(token));
                    }
                    else
                    {
                        throw new ParseException(String.Format("No Module found for activity '{0}'", QName), initialTokenCount - token.Count, QName);
                    }
                }
            }
            // End Element
            token.Dequeue();

            return(this);
        }
Example #3
0
        public IActivity Parse(Queue <IXamlElement> token)
        {
            log.Debug(String.Format("Calling parse in activity '{0}'", name));
            // Debug
            initialTokenCount = token.Count;

            //Start Element
            token.Dequeue();

            while (!token.Peek().QName.Equals(this.QName) || !token.Peek().IsClosingElement)
            {
                IActivity activity = moduleFactory.CreateActivity(token.Peek().QName);

                if (activity != null)
                {
                    IActivity inner = activity.Parse(token);
                    innerActivities.Add(inner);
                }
                else
                {
                    throw new ParseException(String.Format("No Module found for activity '{0}'", QName), initialTokenCount - token.Count, QName);
                }
            }
            // End Element
            token.Dequeue();

            return(this);
        }
Example #4
0
        private String parseStep(Queue <IXamlElement> token)
        {
            FlowStep step = new FlowStep();
            // [Start] FlowStep
            IXamlElement elem = token.Dequeue();
            // Reference
            String reference;

            elem.Attributes.TryGetValue("x:Name", out reference);
            step.Id = reference;

            while (!token.Peek().QName.Equals(createQName("FlowStep")))
            {
                // Optional Key Tag in Switch
                if (token.Peek().QName.Equals(createQName("Key", ns_x)))
                {
                    token.Dequeue();

                    while (!token.Peek().QName.Equals(createQName("Key", ns_x)))
                    {
                        token.Dequeue();
                    }

                    token.Dequeue();
                }

                // Activity
                IActivity activity = moduleFactory.CreateActivity(token.Peek().QName);

                if (activity != null)
                {
                    IActivity inner = activity.Parse(token);
                    step.Action = inner;
                }
                else
                {
                    throw new ParseException(String.Format("No Module found for activity '{0}'", QName), initialTokenCount - token.Count, QName);
                }
                // Optional FlowStep.Next
                if (token.Peek().QName.Equals(createQName("FlowStep.Next")))
                {
                    // [Start] FlowStep.Next
                    token.Dequeue();
                    step.Next = parseNode(token);
                    // [End] FlowStep.Next
                    token.Dequeue();
                }
            }
            // [End] FlowStep
            token.Dequeue();

            steps.Add(step);
            return(step.Id);
        }
Example #5
0
        private void parseState(Queue <IXamlElement> token)
        {
            if (token.Peek().QName.Equals(createQName("State")))
            {
                // State
                SMState state = new SMState();
                states.Add(state);

                // [Start] State
                IXamlElement element = token.Dequeue();

                // Reference
                String reference = element.Attributes["x:Name"];
                state.Id = reference;
                // Final State
                String att;
                if (element.Attributes.TryGetValue("IsFinal", out att))
                {
                    if (att.Equals("True"))
                    {
                        state.Final = true;
                    }
                }

                while (!token.Peek().QName.Equals(createQName("State")))
                {
                    if (token.Peek().QName.Equals(createQName("State.Entry")))
                    {
                        // [Start] State.Entry
                        token.Dequeue();
                        // Activity
                        IActivity activity = moduleFactory.CreateActivity(token.Peek().QName);
                        if (activity != null)
                        {
                            state.Entry = activity.Parse(token);
                        }
                        else
                        {
                            throw new ParseException(String.Format("No Module found for activity '{0}'", QName), initialTokenCount - token.Count, QName);
                        }
                        // [End] State.Entry
                        token.Dequeue();
                    }
                    else if (token.Peek().QName.Equals(createQName("State.Exit")))
                    {
                        // [Start] State.Exit
                        token.Dequeue();
                        // Activity
                        IActivity activity = moduleFactory.CreateActivity(token.Peek().QName);
                        if (activity != null)
                        {
                            state.Exit = activity.Parse(token);
                        }
                        else
                        {
                            throw new ParseException(String.Format("No Module found for activity '{0}'", QName), initialTokenCount - token.Count, QName);
                        }
                        // [End] State.Exit
                        token.Dequeue();
                    }
                    else if (token.Peek().QName.Equals(createQName("State.Transitions")))
                    {
                        // [Start] State.Transitions
                        token.Dequeue();

                        // Transitions
                        while (!token.Peek().QName.Equals(createQName("State.Transitions")))
                        {
                            // Transition
                            state.Transitions.Add(parseTransition(token));
                        }
                        // [End] State.Transitions
                        token.Dequeue();
                    }
                    else
                    {
                        throw new ParseException(String.Format("Unknown tag found in activity '{0}'", QName), initialTokenCount - token.Count, QName);
                    }
                }

                // [End] State
                token.Dequeue();
            }
            else if (token.Peek().QName.Equals(createQName("Reference", ns_x)))
            {
                // [Start][End] Reference
                token.Dequeue();
                token.Dequeue();
            }
            else
            {
                throw new ParseException(String.Format("Unknown tag found in activity '{0}'", QName), initialTokenCount - token.Count, QName);
            }
        }
Example #6
0
        /// <summary>
        /// Parses the Token-Queue and returns an equivalent IActivity representation
        /// </summary>
        /// <exception cref="System.NullReferenceException">Thrown when ModuleFactory or Token-Queue is null</exception>
        /// <exception cref="System.InvalidOperationException">Thrown when Token-Queue is empty, but another token was expected</exception>
        /// <exception cref="WF2oWFN.API.ParseException">Thrown when an error occurs while parsing the Xaml tokens</exception>
        /// <returns>IActivity containing all parsed Activities</returns>
        public IActivity Parse()
        {
            // Activity AST
            IActivity activity = null;

            if (this.moduleFactory == null)
            {
                throw new NullReferenceException("No ModuleFactory was found");
            }
            if (this.tokens == null)
            {
                throw new NullReferenceException("No Token-Queue was found");
            }

            try
            {
                // [Start] Root Element
                IXamlElement startRoot = tokens.Dequeue();

                if (!RootTags.Contains(startRoot.QName))
                {
                    ParseException e = new ParseException(String.Format("No {0} or {1} was found", this.xaml, this.xamlx));
                    e.ElementNumber = initialTokenCount - tokens.Count;
                    e.Activity      = "Root";
                    throw e;
                }
                else
                {
                    // Inner activity
                    activity = moduleFactory.CreateActivity(tokens.Peek().QName);

                    if (activity == null)
                    {
                        ParseException e = new ParseException(String.Format("No Module found for activity '{0}'", tokens.Peek().QName));
                        e.ElementNumber = initialTokenCount - tokens.Count;
                        throw e;
                    }
                    else
                    {
                        // Parse inner activity
                        activity = activity.Parse(tokens);
                    }
                }

                // [End] Root Element
                if (tokens.Count == 1)
                {
                    IXamlElement endRoot = tokens.Dequeue();

                    if (!RootTags.Contains(endRoot.QName))
                    {
                        throw new ParseException(String.Format("No {0} or {1} end tag was found", this.xaml, this.xamlx), initialTokenCount, "Root");
                    }
                }
                else
                {
                    throw new ParseException(String.Format("Expected end tag, but still too many tokens in queue '{0}'", tokens.Count), initialTokenCount - tokens.Count, "Root");
                }

                return(activity);
            }
            catch (InvalidOperationException)
            {
                throw new ParseException("Expected token, but queue is empty", 1, "Root");
            }
        }