コード例 #1
0
        /// <summary>
        /// Creates UIMap instance from specified file.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        public static UIMapFile Create(string fileName)
        {
            UIMapFile uiMapFile = new UIMapFile();

            uiMapFile.Load(fileName);

            return(uiMapFile);
        }
コード例 #2
0
        /// <summary>
        /// Move UI object from other UIMap into current UIMap
        /// </summary>
        /// <param name="srcUIMapFile">The source UIMap file.</param>
        /// <param name="srcElementPath">The source element path.</param>
        /// <param name="destParentPath">Path of destination parent.</param>
        public void MoveUIObject(UIMapFile srcUIMapFile, string srcElementPath, string destParentPath)
        {
            // source element
            UIObject srcElement = srcUIMapFile.FindUIObject(srcElementPath);

            if (srcElement == null)
            {
                throw new NullReferenceException(String.Format("Could not find source UIObject with path '{0}'", srcElementPath));
            }

            // source element parent
            string srcParentPath = srcElementPath.Substring(0, srcElementPath.LastIndexOf('.'));

            // not supported to move actions between different files
            if (srcUIMapFile != this)
            {
                // find references in actions
                foreach (UITestAction action in srcUIMapFile.UITest.ExecuteActions.Actions)
                {
                    if ((action.UIObjectName != null) && (action.UIObjectName.StartsWith(srcElementPath)))
                    {
                        throw new NotSupportedException("Your source UIMap file contains actions referencing elements that are moved. This is not supported");
                    }
                }
            }

            if (srcElement is TopLevelElement)
            {
                // can only be moved to root
                if (destParentPath.Contains('.'))
                {
                    throw new ArgumentException(String.Format("A top level element ({0}) can only be moved to UIMap root", srcElementPath));
                }

                TopLevelElement srcTopLevelElement = (TopLevelElement)srcElement;
                UIMap           destUIMap          = this.UITest.Maps.Where(m => m.Id == destParentPath).FirstOrDefault();
                if (destUIMap == null)
                {
                    throw new NullReferenceException(String.Format("Could not find UIMap '{0}' in destination UIMap file", destParentPath));
                }

                UIMap srcUIMap = srcUIMapFile.UITest.Maps.Where(m => m.Id == srcParentPath).FirstOrDefault();
                if (srcUIMap == null)
                {
                    throw new NullReferenceException(String.Format("Could not find UIMap '{0}' in source UIMap file", srcParentPath));
                }

                TopLevelElement destTopLevelElement = destUIMap.TopLevelWindows.Where(t => t.Id == srcTopLevelElement.Id).FirstOrDefault();
                if (destTopLevelElement == null)
                {
                    // doesn't exist in destination, so simply move it
                    destUIMap.TopLevelWindows.Add(srcTopLevelElement);
                    srcUIMap.TopLevelWindows.Remove(srcTopLevelElement);
                }
                else
                {
                    // a top level element with same id already exists in destination, so we need to merge
                    RecursivelyMergeElements(srcTopLevelElement, destTopLevelElement);

                    srcUIMapFile.DeleteUIObject(srcElementPath);
                }

                this.IsModified         = true;
                srcUIMapFile.IsModified = true;
            }
            else
            {
                // just a "normal" UIObject (not top-level)

                UIObject srcParent = srcUIMapFile.FindUIObject(srcParentPath);
                if (srcParent == null)
                {
                    throw new NullReferenceException(String.Format("Could not find source parent UIObject with path '{0}'", srcParentPath));
                }

                // destination element parent
                UIObject destParent = this.FindUIObject(destParentPath);
                if (destParent == null)
                {
                    throw new NullReferenceException(String.Format("Could not find destination parent UIObject with path '{0}'", destParentPath));
                }

                // find references in actions and move them
                string destElementPath = String.Format("{0}.{1}", destParentPath, srcElement.Id);
                foreach (UITestAction action in this.UITest.ExecuteActions.Actions)
                {
                    if ((action.UIObjectName != null) && (action.UIObjectName.StartsWith(srcElementPath)))
                    {
                        action.UIObjectName = action.UIObjectName.Replace(srcElementPath, destElementPath);
                    }
                }

                // see if element already exists in destination (if so, we need to merge)
                UIObject destObject = destParent.Descendants.Where(d => d.Id == srcElement.Id).FirstOrDefault();
                if (destObject == null)
                {
                    // just move it
                    destParent.Descendants.Add(srcElement);
                    srcParent.Descendants.Remove(srcElement);
                }
                else
                {
                    // we need to recursively move elements
                    RecursivelyMergeElements(srcElement, destObject);
                    srcUIMapFile.DeleteUIObject(srcElementPath);
                }

                this.IsModified         = true;
                srcUIMapFile.IsModified = true;
            }
        }