Пример #1
0
        public static Action EnterTag(Request request, XmlNode templateNode, SubQuery query)
        {
            if (templateNode.NodeType != XmlNodeType.Element)
            {
                return(DoNothing);

                throw new NotImplementedException("EnterTag: " + templateNode.NodeType);
            }
            bool                needsUnwind = false;
            UndoStackHolder     thiz        = (UndoStackHolder)query ?? request;
            ISettingsDictionary dict        = query;

            if (dict == null && request != null)
            {
                dict = request.TargetSettings;
            }
            XmlAttributeCollection collection = templateNode.Attributes;

            EnterContext(request, query);
            if (collection == null || collection.Count <= 0)
            {
                return(() =>
                {
                    ExitContext(request, query);
                });
            }
            else
            {
                var    used           = new List <XmlAttribute>();
                string defaultElement = "";
                Action gmrerstore;
                gmrerstore = request.WithAttributesForUnwind(templateNode, ref defaultElement, used);
                int       uc          = used.Count;
                UndoStack savedValues = null;

                foreach (XmlAttribute node in collection)
                {
                    if (used.Contains(node))
                    {
                        continue;
                    }
                    bool   found;
                    string n = node.Name.ToLower();
                    switch (n)
                    {
                    case "state":
                    case "flag":
                    case "graph":
                    case "topic":
                    case "that":
                        break;

                    default:
                    {
                        lock (ReservedAttributes)
                        {
                            if (ReservedAttributes.Contains(n))
                            {
                                continue;
                            }
                            bool prev = NamedValuesFromSettings.UseLuceneForGet;
                            try
                            {
                                NamedValuesFromSettings.UseLuceneForGet = false;
                                if (!dict.containsSettingCalled(n))
                                {
                                    ReservedAttributes.Add(n);
                                    request.writeToLog("ReservedAttributes: {0}", n);
                                }
                                else
                                {
                                    if (!PushableAttributes.Contains(n))
                                    {
                                        PushableAttributes.Add(n);
                                        request.writeToLog("PushableAttributes: {0}", n);
                                    }
                                }
                            }
                            finally
                            {
                                NamedValuesFromSettings.UseLuceneForGet = prev;
                            }
                        }

                        // now require temp vars to s   ay  with_id="tempId"
                        // to set the id="tempid" teporarily while evalig tags
                        if (!n.StartsWith("with_"))
                        {
                            continue;
                        }
                        else
                        {
                            n = n.Substring(5);
                        }

                        Unifiable v = ReduceStar <Unifiable>(node.Value, query, dict, out found);
                        UndoStack.FindUndoAll(thiz, true);
                        savedValues = savedValues ?? UndoStack.GetStackFor(thiz);
                        //savedValues = savedValues ?? query.GetFreshUndoStack();
                        savedValues.pushValues(dict, n, v);
                        needsUnwind = true;
                    }
                    break;
                    }
                }

                // unwind

                return(() =>
                {
                    if (needsUnwind)
                    {
                        try
                        {
                            EnterContext(request, query);
                            if (savedValues != null)
                            {
                                savedValues.UndoAll();
                            }
                        }
                        catch (Exception ex)
                        {
                            request.writeToLog("ERROR " + ex);
                        }
                        finally
                        {
                            ExitContext(request, query);
                        }
                    }
                    ExitContext(request, query);
                    if (uc > 0)
                    {
                        gmrerstore();
                    }
                });
            }
        }
Пример #2
0
 public void UndoAll()
 {
     UndoStack.FindUndoAll(this, true);
 }