Пример #1
0
        private static TInterface CreateExtension <TInterface>(IElementContainer target, string name, Guid productId, string toolkitId,
                                                               Func <Action <IProduct>, bool, IProduct> elementFactory,
                                                               Action <TInterface> initializer = null, bool raiseInstantiateEvents = true)
            where TInterface : class
        {
            Guard.NotNull(() => target, target);
            Guard.NotNullOrEmpty(() => name, name);
            Guard.NotNullOrEmpty(() => toolkitId, toolkitId);

            if (initializer == null)
            {
                initializer = e => { }
            }
            ;

            GetToolkitInterfaceAttributeOrThrow(typeof(TInterface));
            using (var transaction = target.BeginTransaction())
            {
                var element = elementFactory(e =>
                {
                    e.DefinitionId = productId;
                    e.ExtensionId  = toolkitId;
                    e.InstanceName = name;
                }, raiseInstantiateEvents);

                var interfaceLayer = GetInterfaceLayer <TInterface, IProduct>(element);
                initializer(interfaceLayer);

                transaction.Commit();

                return(interfaceLayer);
            }
        }
Пример #2
0
        /// <summary>
        /// Initializes the fields and properties of the composite using reflection to
        /// find elements within the container.
        /// </summary>
        /// <param name="container">The element container within which to find elements, or null if not available</param>
        protected void InitializeContents(IElementContainer container)
        {
            InitializedMember[] members = GetInitializedMembers(GetType());

            foreach (var member in members)
                member.Initialize(this, container);
        }
Пример #3
0
        public static void Input <T>(this IElementContainer container, Expression <Func <T, object> > input, object value)
        {
            var id = GetElementName(input);

            if (value is DateTime)
            {
                var calendareButton = TryFindCalendareButton(container, id);
                if (calendareButton == null)
                {
                    container.TextField(Find.ById((string)id)).Value = value.ToString();
                }
                else
                {
                    EnterIntoCalendar(calendareButton, (DateTime)value);
                }
            }
            else if (value is bool)
            {
                container.CheckBox(Find.ById((string)id)).Checked = (bool)value;
            }
            else
            {
                container.TextField(Find.ById((string)id)).Value = value.ToString();
            }
        }
        /// <summary>
        /// Returns the instance name for the element container.
        /// </summary>
        /// <returns></returns>
        public static string GetInstanceName(this IElementContainer container)
        {
            var view = container as IView;

            if (view != null)
            {
                // If only single view, then no view distinction required.
                if (view.Product.Info.Views.Count() == 1)
                {
                    return(view.Product.InstanceName);
                }
                else
                {
                    // Distinguish the view.
                    return(string.Format(CultureInfo.CurrentCulture, Resources.ElementContainerExtensions_ViewInstanceNameFormat,
                                         view.Product.InstanceName, view.Info.DisplayName));
                }
            }

            var abstractElement = container as IAbstractElement;

            if (abstractElement != null)
            {
                return(abstractElement.InstanceName);
            }

            throw new InvalidOperationException(Resources.ElementContainerExtensions_UnknownElementContainer);
        }
Пример #5
0
 public DynamicElementTests()
 {
     visitor = Substitute.For<IDynamicElementVisitor>();
     element = Substitute.For<IElementContainer>();
     factory = Substitute.For<IElementFactory>();
     graphDecorator = Substitute.For<Func<BaseDynamicElement, BaseDynamicElement>>();
     sut = new DynamicElement(element, factory, graphDecorator);
 }
Пример #6
0
 private void RegisterUserWithAddress(Client client, IElementContainer browser)
 {
     ClickLink("Новый пользователь");
     browser.CheckBox(Find.ByName("sendClientCard")).Checked = true;
     browser.TextField(Find.ByName("mails")).TypeText("*****@*****.**");
     browser.TextField(Find.ByName("address.Value")).TypeText("TestAddress");
     FillRequiredFields();
 }
Пример #7
0
 internal static TInterface CreateExtension <TInterface>(IElementContainer target, string name, Guid productId, string toolkitId, Action <TInterface> initializer = null, bool raiseInstantiateEvents = true)
     where TInterface : class
 {
     return(CreateExtension <TInterface>(
                target,
                name, productId, toolkitId,
                target.CreateExtension,
                initializer,
                raiseInstantiateEvents));
 }
Пример #8
0
 internal static TInterface CreateCollection <TInterface>(IElementContainer target, string name, Action <TInterface> initializer = null, bool raiseInstantiateEvents = true)
     where TInterface : class
 {
     return(CreateAbstractElement <ICollection, TInterface>(
                target,
                name,
                target.CreateCollection,
                initializer,
                raiseInstantiateEvents));
 }
Пример #9
0
 public ElementVisual(IElementContainer elementContainer)
 {
     using (var context = RenderOpen())
     {
         foreach (var element in elementContainer.Elements)
         {
             RenderManager.Render(context, element);
         }
     }
 }
Пример #10
0
 public DynamicElement(IElementContainer element, IElementFactory elementFactory,
     Func<BaseDynamicElement, BaseDynamicElement> graphDecorator)
 {
     if (element == null)
     {
         throw new ArgumentNullException(nameof(element));
     }
     if (elementFactory == null)
     {
         throw new ArgumentNullException(nameof(elementFactory));
     }
     if (graphDecorator == null)
     {
         throw new ArgumentNullException(nameof(graphDecorator));
     }
     this.element = element;
     this.elementFactory = elementFactory;
     this.graphDecorator = graphDecorator;
 }
Пример #11
0
 private static void GetTribe(bool ownTribe,
     IElementContainer table,
     TableInfo tableInfo,
     int index)
 {
     Image image = table.TableRows[1].TableCells[index].Images[0];
     if (image.Exists)
     {
         string className = image.ClassName;
         Tribes tribe;
         if (className.ToLowerInvariant().Equals("unit u1"))
         {
             tribe = Tribes.Romans;
         }
         else if (className.ToLowerInvariant().Equals("unit u11"))
         {
             tribe = Tribes.Teutons;
         }
         else if (className.ToLowerInvariant().Equals("unit u21"))
         {
             tribe = Tribes.Gauls;
         }
         else if (className.ToLowerInvariant().Equals("unit u31"))
         {
             tribe = Tribes.Nature;
         }
         else
         {
             tribe = Tribes.Monsters;
         }
         if (ownTribe)
         {
             tableInfo.OwnTribe = tribe;
         }
         else
         {
             tableInfo.Tribe = tribe;
         }
     }
 }
        private static Element CreateElement(IElementContainer parent, string elementName, Cardinality cardinality = Cardinality.OneToOne, Action<Element> initializer = null)
        {
            var element = CreateElement(parent, elementName, cardinality);

            if (initializer != null)
            {
                initializer(element);
            }

            return element;
        }
        private void AddDecendantElementsEntries(IElementContainer container, string containerPath = null, IInstanceBase originatingChild = null)
        {
            Guard.NotNull(() => container, container);

            // Maybe one or more instances of different element types (filter the originatingchild instance) to prevent infinite recursion back down to a descendant element.
            foreach (var childElementGroup in container.Elements.Where(e => e != originatingChild).GroupBy(e => e.DefinitionName))
            {
                var groupIndex = 0;

                foreach (var childElement in childElementGroup)
                {
                    string elementPath = GetPluralizedElementPath(childElement, groupIndex);
                    if (!string.IsNullOrEmpty(containerPath))
                    {
                        elementPath = GetPropertyKey(containerPath, elementPath);
                    }

                    AddSelfEntries(childElement, elementPath);
                    AddDecendantElementsEntries(childElement, elementPath);
                    groupIndex++;
                }
            }

            // Maybe one or more instances of different extension types (filter the originatingchild instance) to prevent infinite recursion.
            foreach (var childExtensionGroup in container.Extensions.Where(e => e != originatingChild).GroupBy(e => e.DefinitionName))
            {
                var groupIndex = 0;

                foreach (var childExtension in childExtensionGroup)
                {
                    var extensionPoint = container.Info.ExtensionPoints
                        .FirstOrDefault(ep => childExtension.Info.ProvidedExtensionPoints.FirstOrDefault(x => x.ExtensionPointId == ep.RequiredExtensionPointId) != null);
                    if (extensionPoint != null)
                    {
                        string elementPath = GetPluralizedExtensionPath(extensionPoint, groupIndex);
                        if (!string.IsNullOrEmpty(containerPath))
                        {
                            elementPath = GetPropertyKey(containerPath, elementPath);
                        }

                        AddSelfEntries(childExtension, elementPath);
                        groupIndex++;
                    }
                }
            }
        }
Пример #14
0
 private static void GetBounty(IElementContainer table,
     TableInfo tableInfo)
 {
     TableBody tableBodyGoods = table.TableBody(Find.ByClass("goods"));
     int[] goods = new int[4];
     tableInfo.Carry = "0/0";
     if (tableBodyGoods.Exists)
     {
         string[] resources = tableBodyGoods.TableRows[0].TableCells[0].Divs[0].Text.Split('|');
         for (int i = 0; i < 4; i++)
         {
             goods[i] = Misc.String2Number(resources[i].Trim());
         }
         Div div = tableBodyGoods.TableRows[0].TableCells[0].Divs[1];
         tableInfo.Carry = div.Exists ? div.Text : "0/0";
     }
     tableInfo.Goods = goods;
 }
        private static Element CreateElement(IElementContainer parent, string elementName, Cardinality cardinality)
        {
            var child = (Element)parent.CreateElement();
            var elementInstanceCount = parent.Elements.Where(e => e.DefinitionName == elementName).Count() + 1;

            child.DefinitionName = elementName;
            child.InstanceName = elementName + elementInstanceCount.ToString();
            child.Info = Mock.Of<IElementInfo>(ei => ei.Name == elementName && ei.CodeIdentifier == elementName && ei.Cardinality == cardinality);

            var property = CreateProperty(child, elementName + "Property1", elementName + "Value1");

            return child;
        }
Пример #16
0
            public void Initialize(object instance, IElementContainer container)
            {
                if (container != null)
                {
                    Component component = finder.FindComponent(ValueType, container);

                    if (component != null)
                    {
                        foreach (var decorator in decorators)
                            decorator.Decorate(component);
                    }

                    SetValue(instance, component);
                }
                else
                {
                    SetValue(instance, null);
                }
            }
            public void InitLabelIdsWithMatchingText(IElementContainer domContainer)
            {
                _labelIdsWithMatchingText = new Dictionary<string, bool>();

                var labels = domContainer.Labels.Filter(e => _comparer.Compare(e.Text));

                foreach (var label in labels)
                {
                    var forElementWithId = label.For;
                    if (string.IsNullOrEmpty(forElementWithId)) continue;
                    _labelIdsWithMatchingText.Add(forElementWithId, true);
                }
            }
Пример #18
0
 private static void GetReportOwner(IElementContainer tableCell,
     TableInfo tableInfo)
 {
     if (tableCell.Links.Count == 0)
     {
         GetEmptyNames(tableInfo);
         return;
     }
     tableInfo.Name = tableCell.Links[0].Text;
     string defenderIdLink = tableCell.Links[0].Url;
     Regex regDefenderId = new Regex(@"spieler.php.uid=([0-9]{0,9})");
     if (regDefenderId.IsMatch(defenderIdLink))
     {
         Match mc = regDefenderId.Matches(defenderIdLink)[0];
         tableInfo.Id = Misc.String2Number(mc.Groups[1].Value.Trim());
     }
     tableInfo.VillageName = tableCell.Links[1].Text;
     string defenderVillageIdLink = tableCell.Links[1].Url;
     Regex regDefenderVillageId = new Regex(@"karte.php.d=([0-9]{0,9})&c=");
     if (regDefenderVillageId.IsMatch(defenderVillageIdLink))
     {
         Match mc = regDefenderVillageId.Matches(defenderVillageIdLink)[0];
         tableInfo.VillageId = Misc.String2Number(mc.Groups[1].Value.Trim());
     }
 }
 /// <inheritdoc />
 public override Component FindComponent(Type componentType, IElementContainer container)
 {
     return ComponentFinder.FindComponent(componentType, container, GetConstraint());
 }
Пример #20
0
 private BaseDynamicElement DynamicElementFor(IElementContainer child) => graphDecorator(
     new DynamicToXElementBackwardHandler(
         new DynamicToXmlBackwardHandler(new DynamicElement(child, elementFactory, graphDecorator))));
Пример #21
0
		//----------------------------------------------------------------------
		//  Now we recursively decend the Mobile/Item hierarchy, allowing sub
		//  containment (when it makes sense):
		//----------------------------------------------------------------------
		private static void AddRecursiveMobilesAndItems(
			XmlNode parentNode,
			XmlNode childNode,
			IElementContainer elementContainer
			)
		{
			bool reject = false;
			string probability = "1.0";
			string pick = "";
			string n = "1";
			string id = "0";
			string forceAttack = "false";
			string effectStr = "None";

			try { probability = childNode.Attributes["p"].Value; }
			catch { }
			try { n = childNode.Attributes["n"].Value; }
			catch { }
			try { id = childNode.Attributes["id"].Value; }
			catch { }
			try { forceAttack = childNode.Attributes["forceAttack"].Value; }
			catch { }
			try { effectStr = childNode.Attributes["effect"].Value; }
			catch { }

			string[] effectOptions = effectStr.Split( ':' );
			string effect = effectOptions[0];
			string effectHue = "0";
			if( effectOptions.Length > 1 ) effectHue = effectOptions[1];

			try { pick = childNode.Attributes["pick"].Value; }
			catch
			{
				Console.WriteLine( "Attempted to add an element without a pick at {0}. IGNORING.",
					childNode.Attributes["lineNumber"].Value
					);
				return;
			}

			if( parentNode.Name == "Item" && childNode.Name == "Mobile" ) reject = true;

			//------------------------------------------------------------------
			//  I anticpate more rejection reasons; in any case, the message is decoupled 
			//  entirely from the reason...
			//------------------------------------------------------------------

			if( reject )
			{
				Console.WriteLine(
					"RandomEncounters: Tried to add {0} \"{1}\" to {2} at {3}. THIS IS ILLEGAL. IGNORED.",
					childNode.Name,
					pick,
					parentNode.Name,
					childNode.Attributes["lineNumber"].Value
					);
				return;
			}

			string[] tokens = n.Split( new Char[] { ':' } ); // splits to min:max, or just n if no ':'

			EncounterElement newElement =
				new EncounterElement(
					childNode,
					probability,
					pick,
					id,
					tokens[0],
					(tokens.Length > 1 ? tokens[1] : tokens[0]),
					forceAttack,
					effect,
					effectHue
					);

			XmlNodeList subNodes = childNode.SelectNodes( "Mobile | Item | Prop" );

			//----------------------------------------------
			// Now iterate over subelements
			//----------------------------------------------
			foreach( XmlNode subNode in subNodes )
			{
				if( subNode.Name == "Prop" ) AddProp( childNode, subNode, newElement );

				else AddRecursiveMobilesAndItems(
					childNode,
					subNode,
					newElement
					);
			}

			elementContainer.AddElement( newElement );
		}
Пример #22
0
 private TableInfo GetInfo(IElementContainer table,
     bool isAttacker)
 {
     TableCell tableCell = table.TableRows[0].TableCells[1];
     TableInfo tableInfo = new TableInfo();
     if (tableCell.Links.Count == 2)
     {
         GetReportOwner(tableCell, tableInfo);
         GetUnitInfo(table, tableInfo, isAttacker);
         GetBounty(table, tableInfo);
     }
     else
     {
         tableInfo.Reinforcements = true;
         GetEmptyNames(tableInfo);
         GetTribe(false, table, tableInfo, 1);
         GetUnitInfo(table, tableInfo, isAttacker);
     }
     return tableInfo;
 }
 /// <summary>
 /// Finds a component of the specified type within a container.
 /// </summary>
 /// <param name="componentType">The component type, not null.</param>
 /// <param name="container">The container, not null.</param>
 /// <returns>The component that was found, or null if not found.</returns>
 public abstract Component FindComponent(Type componentType, IElementContainer container);
Пример #24
0
 private void GetUnitInfo(IElementContainer table,
     TableInfo tableInfo,
     bool isAttacker)
 {
     TableBody tableBodyUnits = table.TableBody(Find.ByClass("units"));
     const int total = 11;
     int[] troops = new int[total];
     int[] casualties = new int[total];
     int[] prisoners = new int[total];
     if (tableBodyUnits.Exists)
     {
         if (tableBodyUnits.TableRows.Count == 2)
         {
             GetTribe(true, table, tableInfo, 0);
         }
         else
         {
             GetTribe(true, table, tableInfo, 1);
         }
         foreach (TableRow tableRow in tableBodyUnits.TableRows)
         {
             string header = tableRow.Text;
             if (!(header.Length > 1))
             {
                 continue;
             }
             if (isAttacker)
             {
                 if (header.StartsWith(gameData.Settings.Reports.RowAttackerTroops))
                 {
                     troops = GetTroops(tableRow);
                 }
                 if (header.StartsWith(gameData.Settings.Reports.RowAttackerPrisoners))
                 {
                     prisoners = GetTroops(tableRow);
                 }
                 if (header.StartsWith(gameData.Settings.Reports.RowAttackerCasualties))
                 {
                     casualties = GetTroops(tableRow);
                 }
             }
             else
             {
                 if (header.StartsWith(gameData.Settings.Reports.RowDefenderTroops))
                 {
                     troops = GetTroops(tableRow);
                 }
                 if (header.StartsWith(gameData.Settings.Reports.RowDefenderCasualties))
                 {
                     casualties = GetTroops(tableRow);
                 }
             }
         }
         tableInfo.Troops = troops;
         tableInfo.Casualties = casualties;
         tableInfo.Prisoners = prisoners;
     }
 }