Exemplo n.º 1
0
        public static void FindUndoAll(object o, bool remove)
        {
            UndoStackHolder holder = AsUndoStackHolder(o);
            UndoStack       u;

            if (holder != null)
            {
                u = holder.UndoStackValue;
                if (u != null)
                {
                    u.UndoAll();
                    return;
                }
            }
            lock (ObjectUndoStacks)
            {
                if (ObjectUndoStacks.TryGetValue(o, out u))
                {
                    if (remove)
                    {
                        ObjectUndoStacks.Remove(o);
                    }
                    u.UndoAll();
                }
            }
        }
Exemplo n.º 2
0
        public static UndoStack GetStackFor(object o)
        {
            UndoStackHolder holder = AsUndoStackHolder(o);
            //holder.ToString();
            UndoStack u;

            if (holder != null)
            {
                u = holder.UndoStackValue;
                if (u != null)
                {
                    return(u);
                }
            }
            lock (ObjectUndoStacks)
            {
                if (!ObjectUndoStacks.TryGetValue(o, out u))
                {
                    u = ObjectUndoStacks[o] = new UndoStack(o);
                    if (holder != null)
                    {
                        holder.UndoStackValue = u;
                    }
                }
                return(u);
            }
        }
Exemplo n.º 3
0
        public static UndoStack FindStackFor(object o, bool remove)
        {
            if (o == null)
            {
                return(null);
            }
            UndoStack       u;
            UndoStackHolder holder = AsUndoStackHolder(o);

            holder.ToString();
            if (remove)
            {
                lock (ObjectUndoStacks)
                {
                    if (ObjectUndoStacks.TryGetValue(o, out u))
                    {
                        ObjectUndoStacks.Remove(o);
                        return(u);
                    }
                }
            }
            if (holder != null)
            {
                u = holder.UndoStackValue;
                if (u != null)
                {
                    return(u);
                }
            }

            return(null);
        }
Exemplo n.º 4
0
        public UndoStack(object o)
        {
            objext = o;
            UndoStackHolder holder = AsUndoStackHolder(o);

            holder.UndoStackValue = this;
            if (holder != null)
            {
                holder.UndoStackValue = this;
            }
        }
Exemplo n.º 5
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();
                    }
                });
            }
        }