/**
         * Tries to find a usage of the variable and returns the maximum depth of the relevant
         * element inside of the structure.
         * @param command  the Command to start traversal with
         * @return an int >= 0 or null if not found at all
         */
        public int checkDepth(ICommandWithWhere command)
        {
            if (command is IConstruct)
            {
                // Check head of Construct
                foreach (ITripleTemplate template in ((IConstruct)command).getTemplates())
                {
                    if (containsVar(template))
                    {
                        result = 0;
                    }
                }
            }
            else if (command is IModify)
            {
                IResource modify = command;
                if (templateContainsVar(modify.getObject(SP.PropertyInsertPattern)))
                {
                    result = 0;
                }
                if (templateContainsVar(modify.getObject(SP.PropertyDeletePattern)))
                {
                    result = 0;
                }
            }

            IElementList where = command.getWhere();
            if (where != null)
            {
                walker = new ElementWalkerWithDepth(el, ex);
                walker.visit(where);
            }

            return(result);
        }
Beispiel #2
0
        private void InstallHTMLHooks(Win32HookMsgEventArgs evt)
        {
            String       searchCondition   = String.Format("{0}!=1", CatStudioConstants.HOOKED_BY_REC_ATTR);
            IElementList rootElemNotHooked = this.twebstBrowser.FindAllElements("html", searchCondition);

            try
            {
                for (int i = 0; i < rootElemNotHooked.length; ++i)
                {
                    IElement       crntElem = rootElemNotHooked[i];
                    IHTMLDocument3 doc3     = (IHTMLDocument3)crntElem.nativeElement.document;
                    IHTMLWindow2   wnd      = ((IHTMLDocument2)doc3).parentWindow;

                    doc3.attachEvent("onclick", new HtmlHandler(this.OnHtmlClick, wnd));
                    doc3.attachEvent("onmouseup", new HtmlHandler(this.OnHtmlMouseUp, wnd));
                    crntElem.SetAttribute(CatStudioConstants.HOOKED_BY_REC_ATTR, "1");
                }

                InstallHTMLHooksForOnchange();
            }
            catch
            {
                // Can not properly install html hooks.
            }
        }
        private static List <SimplePropertyPath> getPropertyPaths(INode resource, IElementList where, Dictionary <IResource, IResource> varBindings)
        {
            PropertyPathsGetter getter = new PropertyPathsGetter(where, varBindings);

            getter.run();
            return(new List <SimplePropertyPath>(getter.getResults()));
        }
Beispiel #4
0
        /**
         * Creates a new Optional as a blank node in a given Model.
         * @param model  the Model to create the OPTIONAL in
         * @param elements  the elements of the OPTIONAL
         * @return a new Optional
         */
        public static IOptional createOptional(SpinProcessor model, IElementList elements)
        {
            IOptional optional = (IOptional)model.CreateResource(SP.ClassOptional).As(typeof(OptionalImpl));

            optional.AddProperty(SP.PropertyElements, elements);
            return(optional);
        }
Beispiel #5
0
        /**
         * Creates a new Minus as a blank node in a given Model.
         * @param model  the Model to create the MINUS in
         * @param elements  the elements of the MINUS
         * @return a new Minus
         */
        public static IMinus createMinus(SpinProcessor model, IElementList elements)
        {
            IMinus minus = (IMinus)model.CreateResource(SP.ClassMinus).As(typeof(MinusImpl));

            minus.AddProperty(SP.PropertyElements, elements);
            return(minus);
        }
Beispiel #6
0
        /**
         * Creates a new NotExists as a blank node in a given Model.
         * @param model  the Model to create the NOT EXISTS in
         * @param elements  the elements of the NOT EXISTS
         * @return a new NotExists
         */
        public static INotExists createNotExists(SpinProcessor model, IElementList elements)
        {
            INotExists notExists = (INotExists)model.CreateResource(SP.ClassNotExists).As(typeof(NotExistsImpl));

            notExists.AddProperty(SP.PropertyElements, elements);
            return(notExists);
        }
Beispiel #7
0
        /**
         * Creates an Ask query for a given WHERE clause.
         * @param model  the Model to create the Ask (blank node) in
         * @param where  the elements of the WHERE clause
         * @return the new Ask query
         */
        public static IAsk createAsk(SpinProcessor model, IElementList where)
        {
            IAsk ask = (IAsk)model.CreateResource(SP.ClassAsk).As(typeof(AskImpl));

            ask.AddProperty(SP.PropertyWhere, where);
            return(ask);
        }
Beispiel #8
0
        private void InstallHTMLHooksForOnchange()
        {
            // Install onchange hook for <input type=password, text, file>.
            String       searchCondition    = String.Format("{0}!=1", CatStudioConstants.HOOKED_BY_REC_ATTR);
            IElementList inputElemNotHooked = this.twebstBrowser.FindAllElements("input", searchCondition);

            for (int i = 0; i < inputElemNotHooked.length; ++i)
            {
                IHTMLElement2 crntNativeElem2 = (IHTMLElement2)inputElemNotHooked[i].nativeElement;
                String        inputType       = ((IHTMLInputElement)crntNativeElem2).type.ToLower();
                IHTMLElement  crntElem        = (IHTMLElement)crntNativeElem2;

                if (("text" == inputType) || ("password" == inputType) || ("file" == inputType))
                {
                    IHTMLWindow2 wnd = ((IHTMLDocument2)crntElem.document).parentWindow;
                    crntNativeElem2.attachEvent("onchange", new HtmlHandler(this.OnHtmlChange, wnd));
                }

                crntElem.setAttribute(CatStudioConstants.HOOKED_BY_REC_ATTR, "1", 0);
            }

            // Install onchange hook for <select>.
            IElementList selectElemNotHooked = this.twebstBrowser.FindAllElements("select", searchCondition);

            InstalHTMLHookOnList(selectElemNotHooked, "onchange");

            // Install onchange hook for <textarea>.
            IElementList textAreaElemNotHooked = this.twebstBrowser.FindAllElements("textarea", searchCondition);

            InstalHTMLHookOnList(textAreaElemNotHooked, "onchange");
        }
Beispiel #9
0
        /**
         * Creates a new UNION element as a blank node in a given Model.
         * @param model  the Model to create the Union in
         * @param elements  the elements
         * @return a new Union
         */
        public static IUnion createUnion(SpinProcessor model, IElementList elements)
        {
            IUnion union = (IUnion)model.CreateResource(SP.ClassUnion).As(typeof(UnionImpl));

            union.AddProperty(SP.PropertyElements, elements);
            return(union);
        }
Beispiel #10
0
        public static IService createService(SpinProcessor model, INode serviceURI, IElementList elements)
        {
            IService service = (IService)model.CreateResource(SP.ClassService).As(typeof(ServiceImpl));

            service.AddProperty(SP.PropertyServiceURI, serviceURI);
            service.AddProperty(SP.PropertyElements, elements);
            return(service);
        }
Beispiel #11
0
        // [WMR 20160802] NEW - TODO
        // For partial expansion of a single (complex) element

        /// <summary>Given a list of element definitions, expand the definition of a single element.</summary>
        /// <param name="elements">A <see cref="StructureDefinition.SnapshotComponent"/> or <see cref="StructureDefinition.DifferentialComponent"/> instance.</param>
        /// <param name="element">The element to expand. Should be part of <paramref name="elements"/>.</param>
        /// <returns>A new, expanded list of <see cref="ElementDefinition"/> instances.</returns>
        /// <exception cref="ArgumentException">The specified element is not contained in the list.</exception>
        public IList <ElementDefinition> ExpandElement(IElementList elements, ElementDefinition element)
        {
            if (elements == null)
            {
                throw Error.ArgumentNull("elements");
            }
            return(ExpandElement(elements.Element, element));
        }
Beispiel #12
0
        private void InstalHTMLHookOnList(IElementList elemList, String evtName)
        {
            for (int i = 0; i < elemList.length; ++i)
            {
                IHTMLElement2 crntNativeElem2 = (IHTMLElement2)elemList[i].nativeElement;
                IHTMLElement  crntElem        = (IHTMLElement)crntNativeElem2;
                IHTMLWindow2  wnd             = ((IHTMLDocument2)crntElem.document).parentWindow;

                crntNativeElem2.attachEvent(evtName, new HtmlHandler(this.OnHtmlChange, wnd));
                crntElem.setAttribute(CatStudioConstants.HOOKED_BY_REC_ATTR, "1", 0);
            }
        }
Beispiel #13
0
 private static void repairChoiceBug(IElementList original)
 {
     foreach (var elem in original.Element)
     {
         if (!elem.Type.IsNullOrEmpty())
         {
             var typeName = elem.Type.First().Code;
             if (elem.Path.ToUpper().EndsWith(typeName.ToUpper()) && elem.Path.Length > typeName.Length &&
                 elem.Path[elem.Path.Length - typeName.Length - 1] != '.' && !elem.IsExtension() &&
                 elem.Path != "ValueSet.lockedDate")
             {
                 elem.Path = elem.Path.Substring(0, elem.Path.Length - typeName.Length) + "[x]";
             }
         }
     }
 }
Beispiel #14
0
        protected void printNestedElementList(ISparqlPrinter p, INode predicate)
        {
            p.print(" {");
            p.println();
            IResource elementsRaw = getObject(predicate);

            if (elementsRaw != null)
            {
                IElementList elements = (IElementList)elementsRaw.As(typeof(ElementListImpl));
                p.setIndentation(p.getIndentation() + 1);
                elements.Print(p);
                p.setIndentation(p.getIndentation() - 1);
            }
            p.printIndentation(p.getIndentation());
            p.print("}");
        }
        /// <summary>
        /// Rewrites the Path's of the elements in a structure so they are based on the given path: the root
        /// of the given structure will become the given path, it's children will be relocated below that path
        /// </summary>
        /// <param name="root">The structure that will be rebased on the path</param>
        /// <param name="path">The path to rebase the structure on</param>
        public static void Rebase(this IElementList root, string path)
        {
            var nav = new ElementNavigator(root.Element);

            if (nav.MoveToFirstChild())
            {
                var newPaths = new List <string>()
                {
                    path
                };

                rebaseChildren(nav, path, newPaths);

                var snapshot = root.Element;

                // Can only change the paths after navigating the tree, otherwise the
                // navigation functions (which are based on the paths) won't function correctly
                for (var i = 0; i < root.Element.Count; i++)
                {
                    root.Element[i].Path = newPaths[i];
                }
            }
        }
 private static void repairChoiceBug(IElementList original)
 {
     foreach (var elem in original.Element)
     {
         if (!elem.Type.IsNullOrEmpty())
         {
             var typeName = elem.Type.First().Code;
             if (elem.Path.ToUpper().EndsWith(typeName.ToUpper()) && elem.Path.Length > typeName.Length 
                 && elem.Path[elem.Path.Length-typeName.Length-1] != '.' && !elem.IsExtension() &&
                 elem.Path!="ValueSet.lockedDate")
             {
                 elem.Path = elem.Path.Substring(0, elem.Path.Length - typeName.Length) + "[x]";
             }
         }
     }
 }
 /// <summary>Returns the root element from the specified element list, if available, or <c>null</c>.</summary>
 public static ElementDefinition GetRootElement(this IElementList elements)
 {
     return(elements?.Element?.FirstOrDefault(e => e.IsRootElement()));
 }
 /// <summary>
 /// Rewrites the Path's of the elements in a structure so they are based on the given path: the root
 /// of the given structure will become the given path, it's children will be relocated below that path
 /// </summary>
 /// <param name="root">The structure that will be rebased on the path</param>
 /// <param name="path">The path to rebase the structure on</param>
 public static void Rebase(this IElementList root, string path)
 {
     Rebase(root.Element, path);
 }
Beispiel #19
0
        private int ComputeIndex(RecEventArgs evt, String twebstTagName, String attr, String attrVal)
        {
            try
            {
                String           uniqueValue     = DateTime.Now.ToString();
                IHTMLElement     htmlTarget      = evt.TargetElement;
                String           searchCondition = null;
                IElementList     elements        = null;
                bool             isInnerText     = (attr == "innertext");
                ICustomRecording customRec       = this.languageGenerator as ICustomRecording;

                htmlTarget.setAttribute(CatStudioConstants.FIND_INDEX_HELPER_ATTR, uniqueValue, 0);

                if ((attr != null) && (attrVal != null) && !isInnerText)
                {
                    searchCondition = String.Format("{0}={1}", attr, attrVal);

                    if ((customRec == null) || !customRec.LocalIndex)
                    {
                        elements = evt.Browser.FindAllElements(twebstTagName, searchCondition);
                    }
                    else
                    {
                        ICore    core       = CoreWrapper.Instance;
                        IElement targetElem = core.AttachToNativeElement(evt.TargetElement);

                        // Search only elements in current frame.
                        elements = targetElem.parentFrame.FindChildrenElements(twebstTagName, searchCondition);
                    }
                }
                else
                {
                    if ((customRec == null) || !customRec.LocalIndex)
                    {
                        elements = evt.Browser.FindAllElements(twebstTagName, "");
                    }
                    else
                    {
                        ICore    core       = CoreWrapper.Instance;
                        IElement targetElem = core.AttachToNativeElement(evt.TargetElement);

                        // Search only elements in current frame.
                        elements = targetElem.parentFrame.FindChildrenElements(twebstTagName, "");
                    }
                }

                int index  = 0;
                int length = elements.length;

                if (length <= 1)
                {
                    return(0);
                }

                if (!isInnerText)
                {
                    for (int i = 0; i < length; ++i)
                    {
                        String findIndexAttrValue = (String)elements[i].GetAttribute(CatStudioConstants.FIND_INDEX_HELPER_ATTR);

                        if (uniqueValue == findIndexAttrValue)
                        {
                            index = i;
                            break;
                        }
                    }
                }
                else
                {
                    // Watir uses innerText but Twebst does not search for innerText.
                    for (int i = 0; i < length; ++i)
                    {
                        String findIndexAttrValue = (String)elements[i].GetAttribute(CatStudioConstants.FIND_INDEX_HELPER_ATTR);
                        if (uniqueValue == findIndexAttrValue)
                        {
                            break;
                        }

                        if (attrVal == elements[i].nativeElement.innerText)
                        {
                            index++;
                        }
                    }
                }

                return(index);
            }
            catch
            {
                // Something went wrong, give up using index.
                return(0);
            }
        }
Beispiel #20
0
        private void InstalHTMLHookOnList(IElementList elemList, String evtName)
        {
            for (int i = 0; i < elemList.length; ++i)
            {
                IHTMLElement2 crntNativeElem2 = (IHTMLElement2)elemList[i].nativeElement;
                IHTMLElement  crntElem        = (IHTMLElement)crntNativeElem2;
                IHTMLWindow2  wnd             = ((IHTMLDocument2)crntElem.document).parentWindow;

                crntNativeElem2.attachEvent(evtName, new HtmlHandler(this.OnHtmlChange, wnd));
                crntElem.setAttribute(CatStudioConstants.HOOKED_BY_REC_ATTR, "1", 0);
            }
        }
Beispiel #21
0
 public SelectSerializableComponentWindow(IElementList <Type> elementList)
 {
     this.elementList = elementList;
     classTypes       = getListOfType <SaveableComponent>();
 }