public static ActionBase CreateAction(Page page, XElement xel, int actionIndex) { ActionTypeKind type; if (xel.Element("ActionType") == null || !Enum.TryParse(xel.Element("ActionType").Value, true, out type)) { throw new Exception("ActionType element is missing or invalid!"); } switch (type) { case ActionTypeKind.LoadPage: return new LoadPage(page, xel, actionIndex); case ActionTypeKind.PagePlaceHolder: return new PagePlaceHolder(page, xel, actionIndex); case ActionTypeKind.GetElementValue: return new GetElementValue(page, xel, actionIndex); case ActionTypeKind.BeginAnchorList: return new BeginAnchorList(page, xel, actionIndex); case ActionTypeKind.ClickElement: return new ClickElement(page, xel, actionIndex); case ActionTypeKind.EndList: return new EndList(page, xel, actionIndex); case ActionTypeKind.PageList: return new PageList(page, xel, actionIndex); case ActionTypeKind.ActionCommand: return new ActionCommand(page, xel, actionIndex); default: throw new Exception("Unknown ActionType!"); } }
public ClickElement(Page page, XElement xel, int actionIndex) : base(page, xel, actionIndex) { _xpaths = GetXPaths(); if (_xpaths.Count == 0 || xel.Element("DestinationPage") == null || !Int32.TryParse(xel.Element("DestinationPage").Value, out _destinationPage)) { throw new Exception("Error in ClickElement xml Action element."); } _startExprSep = GetStartExpSep(); _endExprSep = GetEndExpSep(); _nodeValueType = GetNodeValueType(); // ClickElement treba izvuci href iz targetiranog noda koji vodi na kliknuti link // po defaultu bi trebao pocinjati sa hreaf=", i zavrsiti sa " ukoliko Start i End Expression separatori nisu navedeni if (_startExprSep == null) { _startExprSep = new StartExpressionSeparator("href=\"", false, true); } if (_endExprSep == null) { _endExprSep = new EndExpressionSeparator("\"", false, true); } // isto tako po defaultu uzima NodevalueType OuterHtml ukoliko nije naveden if (_nodeValueType == null) _nodeValueType = NodeValueType.OuterHtml; }
public EndList(Page page, XElement xel, int actionIndex) : base(page, xel, actionIndex) { if(xel.Element("ListName") == null) { throw new Exception("Error in GetElementValue xml Action element"); } this.ListName = xel.Element("ListName").Value; // treba pronaci pripadajuci BeginAnchorList na ovoj stranici kako bi ExecuteAction poslao na njega. List<XElement> actions = (from els in _page.Xdoc.Descendants("Action") where Int32.Parse(els.Element("Page").Value) == _page.PageIndex select els).ToList(); for (int i = 0; i < actions.Count; ++i) { if (actions[i].Element("ActionType").Value == ActionTypeKind.BeginAnchorList.ToString() && actions[i].Element("ListName").Value == this.ListName) { _startListIndex = i; break; } } if (_startListIndex < 0) { throw new Exception("BeginAnchorList action not found for current EndList!"); } }
public PagePlaceHolder(Page page, XElement xel, int actionIndex) : base(page, xel, actionIndex) { if (xel.Element("BaseUrl") != null) { _baseUrl = xel.Element("BaseUrl").Value; } if (xel.Element("Encoding") == null) { throw new Exception("PagePlaceHolder is missing encoding element!"); } switch (xel.Element("Encoding").Value.ToLower()) { case "utf8": _encoding = Encoding.UTF8; break; case "default": _encoding = Encoding.Default; break; default: throw new Exception("Wrong Encoding type in PagePlaceHolder!"); } }
public GetElementValue(Page page, XElement xel, int actionIndex) : base(page, xel, actionIndex) { if (xel.Element("FieldName") == null) { throw new Exception("Error in GetElementValue xml Action element, missing FieldName!"); } _fieldName = xel.Element("FieldName").Value; _predefinedValue = GetPredefinedValue(); if (_predefinedValue == null) { _xpaths = GetXPaths(); if (_xpaths.Count == 0) { throw new Exception("Error in GetElementValue xml Action element, missing XPaths!"); } _nodeValueType = GetNodeValueType(); _startExprSep = GetStartExpSep(); _endExprSep = GetEndExpSep(); _lstReplacements = GetReplacements(); } }
public ActionCommand(Page page, XElement xel, int actionIndex) : base(page, xel, actionIndex) { if (xel.Element("CommandLine") == null) { throw new Exception("ActionCommand is missing CommandLine element!"); } _commandLine = xel.Element("CommandLine").Value; }
protected ActionBase(Page page, XElement xel, int actionIndex) { if ((xel.Element("ActionType") == null || !Enum.TryParse(xel.Element("ActionType").Value, true, out _actionType))) { throw new Exception("Error in PagePlaceHolder xml Action element"); } _page = page; _xel = xel; _actionIndex = actionIndex; }
public BeginAnchorList(Page page, XElement xel, int actionIndex) : base(page, xel, actionIndex) { _xpaths = GetXPaths(); if (_xpaths.Count == 0 || xel.Element("ListName") == null) { throw new Exception("Error in GetElementValue xml Action element"); } this._listName = xel.Element("ListName").Value; // pronaci odgovarajuci endlist element u xdocu ovog page-a List<XElement> actions = (from els in _page.Xdoc.Descendants("Action") where Int32.Parse(els.Element("Page").Value) == _page.PageIndex select els).ToList(); for (int i = 0; i < actions.Count; ++i) { if (actions[i].Element("ActionType").Value == ActionTypeKind.EndList.ToString() && actions[i].Element("ListName").Value == this._listName) { _endListIndex = i; break; } } if (_endListIndex == -1) { throw new Exception("EndList action not found for current BeginAnchorList!"); } // ukoliko je postavljeno postaviti zadnji index node-a koji ce se dohvacati // npr. ako idu jahte, jedrili, katamarane pa kasnije neki info tagovi indeksirati do tih info tagova if (xel.Element("ItemCounter") != null) { Int32.TryParse(xel.Element("ItemCounter").Value, out _lastNodeIndex); } // ukoliko je postavljeno pronaci postaviti prvi index node-a koji ce se dohvacati // npr. ako idu neki info tagovi pa onda jahte, jedrilice, katamarani... da se preskoce info nodovi if (xel.Element("ItemSkip") != null) { Int32.TryParse(xel.Element("ItemSkip").Value, out _startNodeIndex); } // postaviti konacne node indexe _lastNodeIndex += _startNodeIndex; _currentNodeIndex = _startNodeIndex; }
private List<string> _xpaths; // jel treba vise od jednog xpatha?! (se moze link na iducu straicu na nekoj od stranica pojavi u drugom xpathu?!) #endregion Fields #region Constructors public PageList(Page page, XElement xel, int actionIndex) : base(page, xel, actionIndex) { _xpaths = GetXPaths(); if (_xpaths.Count == 0) { throw new Exception("Error in PageList xml Action element. Missing XPath!"); } // pronaci LoadPage element na ovoj stranici List<XElement> actions = (from els in _page.Xdoc.Descendants("Action") where Int32.Parse(els.Element("Page").Value) == _page.PageIndex select els).ToList(); for (int i = 0; i < actions.Count; ++i) { if (actions[i].Element("ActionType").Value == ActionTypeKind.PagePlaceHolder.ToString()) { _pagePlaceHolderIndex = i; break; } } if (_pagePlaceHolderIndex < 0) { throw new Exception("LoadPage action not found for current PageList action!"); } _nodeValueType = GetNodeValueType(); _startExprSep = GetStartExpSep(); _endExprSep = GetEndExpSep(); // PageList treba izvuci href iz targetiranog noda koji vodi na iducu stranicu // po defaultu bi trebao pocinjati sa hreaf=", i zavrsiti sa " ukoliko Start i End Expression separatori nisu navedeni if (_startExprSep == null) { _startExprSep = new StartExpressionSeparator("href=\"", false, true); } if(_endExprSep == null) { _endExprSep = new EndExpressionSeparator("\"", false, true); } }
public LoadPage(Page page, XElement xel, int actionIndex) : base(page, xel, actionIndex) { if (xel.Element("PageUrl") == null) { throw new Exception("LoadPage is missing PageUrl element!"); } int destPag; if (xel.Element("DestinationPage") == null || !Int32.TryParse(xel.Element("DestinationPage").Value, out destPag)) { throw new Exception("Error in PagePlaceHolder xml Action element"); } _destinationPage = destPag; _pageUrl = xel.Element("PageUrl").Value; }