Beispiel #1
0
        static void Main(string[] args)
        {
            var factory = new ElementFactory();

            Console.WriteLine(factory.CreateElement("hs/top", "Welcome!"));
            Console.WriteLine(factory.CreateElement("ps/main", "This is the main section."));
            Console.WriteLine(factory.CreateElement("ps/sub", "This is a sub-section."));
        }
        /// <summary>
        /// Creates a new instance of the given element, with the given name.
        /// </summary>
        public static TModelElement CreateElement <TModelElement>(this ElementFactory factory, string name) where TModelElement : ModelElement
        {
            Guard.NotNull(() => factory, factory);

            var field = typeof(TModelElement).GetField(
                "DomainClassId",
                BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);

            if (field != null)
            {
                var id           = (Guid)field.GetValue(null);
                var modelElement = factory.CreateElement(id) as TModelElement;

                if (!string.IsNullOrEmpty(name))
                {
                    string tryName;
                    if (DomainClassInfo.TryGetName(modelElement, out tryName))
                    {
                        DomainClassInfo.SetName(modelElement, name);
                    }
                }

                return(modelElement);
            }

            return(default(TModelElement));
        }
        /// <summary>
        /// Creates view element
        /// </summary>
        /// <param name="widget">Widget to show</param>
        /// <param name="style">Style of widget</param>
        /// <returns>View element</returns>
        protected T CreateElement(ElementManager widget, Y style)
        {
            T element = _elementFactory.CreateElement(widget, style);

            ElementIndex.Add(widget.Identifier, element);
            return(element);
        }
Beispiel #4
0
    public IEnumerable <DiffAction> CreateDiff(IEnumerable <ProjectTask> tasks)
    {
        var elements = tasks.Select(task => _elementFactory.CreateElement(task));
        var actions  = elements.Select(element => _actionFactory.CreateAction(element));

        return(actions);
    }
        public void CreatePageSection()
        {
            using (ShimsContext.Create())
            {
                ElementGenerator.Fakes.ShimExtensions.ToKebabString = s => s;

                var factory = new ElementFactory();

                string element = factory.CreateElement("ps/3", "Hello World");

                Assert.Equal("<PageSection class='level-3'>Hello World</PageSection>", element);
            }
        }
Beispiel #6
0
 void IDeserializationFixupListener.PhaseCompleted(int phase, Store store)
 {
     if (phase == myPhase)
     {
         foreach (ORMModel model in store.ElementDirectory.FindElements <ORMModel>())
         {
             int        knownTypesCount = (int)PortableDataType.UserDefined;
             DataType[] knownTypes      = new DataType[knownTypesCount];
             LinkedElementCollection <DataType> currentDataTypes = model.DataTypeCollection;
             int startingCount = currentDataTypes.Count;
             for (int i = 0; i < startingCount; ++i)
             {
                 DataType existingType = currentDataTypes[i];
                 int      currentIndex = (int)existingType.PortableDataType;
                 if (currentIndex >= 0 && currentIndex < knownTypesCount)
                 {
                     Debug.Assert(knownTypes[currentIndex] == null);
                     knownTypes[currentIndex] = existingType;
                 }
             }
             ElementFactory factory = store.ElementFactory;
             for (int i = 0; i < knownTypesCount; ++i)
             {
                 if (null == knownTypes[i])
                 {
                     Type newType = null;
                     if (i < typeArray.Length)
                     {
                         newType = typeArray[i];
                     }
                     Debug.Assert(newType != null);
                     DomainObjectIdAttribute newTypeDomainObjectIdAttribute = (DomainObjectIdAttribute)newType.GetCustomAttributes(typeof(DomainObjectIdAttribute), false)[0];
                     DataType newDataType = (DataType)factory.CreateElement(newTypeDomainObjectIdAttribute.Id);
                     newDataType.Model = model;
                     knownTypes[i]     = newDataType;
                 }
             }
             // Cache these for later use
             model.myPortableTypes = knownTypes;
         }
     }
 }
Beispiel #7
0
        public static IEnumerable <WatiN.Core.Element> XPath(this IElementContainer elementContainer, string xpath)
        {
            DomContainer domContainer = null;

            // TODO: Test that contextNode works
            var container = "document";

            var document = elementContainer as Document;

            if (document != null)
            {
                domContainer = document.DomContainer;
            }

            var element = elementContainer as WatiN.Core.Element;

            if (element != null)
            {
                container    = element.NativeElement.GetJavaScriptElementReference();
                domContainer = element.DomContainer;
            }

            if (domContainer == null)
            {
                return(Enumerable.Empty <WatiN.Core.Element>());
            }

            if (domContainer.Eval("window.jsxpath") == "undefined")
            {
                var script = "window.jsxpath = { targetFrame: undefined, exportInstaller: false, useNative: true, useInnerText: true };" +
                             Resources.javascript_xpath;
                domContainer.RunScript(script);
            }

            // TODO: This escaping will fail if the string is already escaped
            var code = string.Format("document.___WATINRESULT = document.evaluate('{0}', {1}, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);", xpath.Replace("'", @"\'"), container);

            domContainer.RunScript(code);

            return(from nativeElement in new JScriptXPathResultEnumerator((IEDocument)domContainer.NativeDocument, "___WATINRESULT")
                   select ElementFactory.CreateElement(domContainer, nativeElement));
        }