Пример #1
0
        public void AddComponentToCache(Controller c, AME.Model.Model model, int topID, int parentID, int id, string type, string baseType, int linkID, string name, string linkType, string desc, Component.eComponentType eType, String lastValidateAddParentXPath, List<ComponentFunction> lastSchemaValuesValidateAdd)
        {
            String key = CreateCacheKey(topID, topID, linkType);
            if (!this.Contains(model, key))
            {
                ComponentOptions full = new ComponentOptions();
                full.CompParams = true;
                full.ClassInstanceInfo = true;
                full.SubclassInstanceInfo = true;
                full.LinkParams = true;
                XmlDocument doc2 = c._GetComponentsXmlDoc(topID, topID, linkType, full);
                AddCacheDocument(model, key, doc2);
                // This occurs at the -end- of a connect that would normally cause a cache add.
                // However, we haven't seen the document before, and the connect has already gone through to the DB.
                // This means the document we just retrieved above to initially populate the cache (c_.GetCompnentsXmlDoc)
                // already contains the item we're looking to add with this call.  So we should actually just return.
                // If we continue as below we will see doubles for the first items added under a linktype.
                // Because the cache is similarly populated (outside of this call) when a linktype is fetched, this side effect usually occurs with programmatic creation
                // where no data has been fetched / used yet, but links are being created and items are being added to the cache.

                // grab the element we're interested in (including children)
                XmlElement alreadyPresent = (XmlElement)doc2.SelectSingleNode(lastValidateAddParentXPath + createComponentXPath(id).Substring(1)); // remove the first slash in the //Component

                // bug fix - add to other link types as well
                addToOtherLinkTypes(key, c, model, alreadyPresent, id, linkID, linkType, lastValidateAddParentXPath);

                return;
            }
            XmlDocument doc = documentCache[model][key];
            XmlElement createForCache;
            DataTable childCheck = model.GetChildComponentLinks(id, linkType);
            if (childCheck.Rows.Count > 0)
            {
                ComponentOptions full = new ComponentOptions();
                full.CompParams = true;
                full.ClassInstanceInfo = true;
                full.SubclassInstanceInfo = true;
                full.LinkParams = true;
                XmlDocument thisCompDoc = (XmlDocument)c._GetComponentsXmlDoc(topID, id, linkType, full);
                XmlNode findChild = thisCompDoc.SelectSingleNode("/Components/Component");
                // set the link ID - the get call doesn't have enough information to do this for the top component
                int lID = c.GetLinkID(parentID, id, linkType);
                XmlAttribute attrLinkID = thisCompDoc.CreateAttribute(XmlSchemaConstants.Display.Component.LinkID);
                attrLinkID.Value = ""+lID;
                findChild.Attributes.Append(attrLinkID);

                // link parameters?
                IXPathNavigable linkParameters = c.GetParametersForLink(lID);

                if (linkParameters != null)
                {
                    XmlNode insert = ((XmlNode)linkParameters).SelectSingleNode(XmlSchemaConstants.Display.sLinkParameters);
                    insert = thisCompDoc.ImportNode(insert, true);
                    findChild.AppendChild(insert);
                }
   
                findChild = doc.ImportNode(findChild, true);
                createForCache = (XmlElement)findChild;
            }
            else
            {
                createForCache = CreateCacheElement(c, doc, id, linkID, type, baseType, name, desc, eType, lastSchemaValuesValidateAdd);
            }
 
            c.AddChildAtXPath(doc, lastValidateAddParentXPath, createForCache, false);
            
            // find other documents with the same linktype = e.g. display ID based
            addToOtherLinkTypes(key, c, model, createForCache, id, linkID, linkType, lastValidateAddParentXPath);
        }
Пример #2
0
        private void addToOtherLinkTypes(String key, Controller c, AME.Model.Model model, XmlElement createForCache, int id, int linkID, string linkType, string lastValidateAddParentXPath)
        {
            XmlDocument doc;
            // find other documents with the same linktype = e.g. display ID based
            foreach (String documentKey in documentCache[model].Keys)
            {
                String parsedLinkType = parseLinkType(documentKey);
                if (parsedLinkType.Equals(linkType) && documentKey != key)
                {
                    doc = documentCache[model][documentKey];
                    try
                    {
                        createForCache = (XmlElement)doc.ImportNode(createForCache, true);
                        c.AddChildAtXPath(doc, lastValidateAddParentXPath, createForCache, false);
                    }
                    catch (Exception) { } // parent didn't exist - ok to skip
                }
            }

            if (!componentXPaths[model].ContainsKey(id))
            {
                componentXPaths[model].Add(id, XPathExpression.Compile(createComponentXPath(id)));
            }

            if (!linkXPaths[model].ContainsKey(linkID))
            {
                linkXPaths[model].Add(linkID, XPathExpression.Compile(createLinkXPath(linkID)));
            }
        }