Esempio n. 1
0
        public sealed override object Evaluate(NodeEvaluationContext evaluationContext)
        {
            var leftNodeValue = LeftNode.Evaluate(evaluationContext);

            if (leftNodeValue == DependencyProperty.UnsetValue)
            {
                return(DependencyProperty.UnsetValue);
            }

            NodeValueType leftNodeValueType = GetNodeValueType(leftNodeValue);

            if (leftNodeValueType == NodeValueType.Boolean)
            {
                // give base a chance to yield a result without evaluating the right node
                var result = this.DetermineResultPreRightEvaluation((bool)leftNodeValue);

                if (result.HasValue)
                {
                    return(result.Value);
                }
            }

            object rightNodeValue = RightNode.Evaluate(evaluationContext);

            if (rightNodeValue == DependencyProperty.UnsetValue)
            {
                return(DependencyProperty.UnsetValue);
            }

            NodeValueType rightNodeValueType = GetNodeValueType(rightNodeValue);

            exceptionHelper.ResolveAndThrowIf(leftNodeValueType != NodeValueType.Boolean || rightNodeValueType != NodeValueType.Boolean, "OperandsNotBoolean", OperatorSymbols, leftNodeValueType, rightNodeValueType);

            return(this.DetermineResultPostRightEvaluation((bool)leftNodeValue, (bool)rightNodeValue));
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
 public CastNode(Node node, NodeValueType targetType)
     : base(node)
 {
     Debug.Assert(Enum.IsDefined(typeof(NodeValueType), targetType));
     Debug.Assert(targetType != NodeValueType.Unknown);
     this.targetType = targetType;
 }
Esempio n. 4
0
        /**
         * @ 将IPListNode对象转换为JSON字符串
         * */
        public override void WriterJson(TextWriter writer)
        {
            writer.Write(Utilities.JSON_BRACKET_LEFT);
            int len = Count;

            for (int i = 0; i < len; i++)
            {
                var           item      = this[i];
                NodeValueType valueType = GetValueType(item.Value);
                string        keyName   = valueType.ToString().ToLower();

                if (valueType == (valueType & (NodeValueType.DICT | NodeValueType.ARRAY)))
                {
                    IPListNode node = (IPListNode)item;
                    node.WriterJson(writer);
                    string comma = Utilities.IsWriterComma(len, i, 1);
                    writer.Write(comma);
                }
                else
                {
                    FormatJson(writer, "", item);
                    string comma = Utilities.IsWriterComma(len, i, 1);
                    writer.Write(comma);
                }
            }
            writer.Write(Utilities.JSON_BRACKET_RIGHT);
        }
Esempio n. 5
0
        /**
         * @ 格式化值的输出
         * @ ht LdfHashtable对象
         * */
        protected virtual void FormatXml(XmlWriter writer, IPListNode ht)
        {
            string        result    = string.Empty;
            NodeValueType valueType = GetValueType(ht.Value);
            string        keyString = valueType.ToString().ToLower();

            writer.WriteStartElement(keyString);
            switch (valueType)
            {
            case NodeValueType.DATA:
                writer.WriteString(Convert.ToBase64String(ht.Value as byte[]));
                break;

            case NodeValueType.DATE:
                string plistDate = ht.Value.ObjToDateTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.ffffffZ");
                writer.WriteString(plistDate);
                break;

            //case "key":
            case NodeValueType.REAL:
            case NodeValueType.STRING:
            case NodeValueType.INTEGER:
                writer.WriteString(ht.Value.ToString());
                break;
            }
            writer.WriteEndElement();
        }
Esempio n. 6
0
        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();
            }
        }
Esempio n. 7
0
        private PacketNode PrepareBaseType(NodeValueType valueType, Type type, string name)
        {
            var node = _doc.CreateNode();

            _cur.Append(node);

            string typ = Framework.Assembly.GetTypeName(type);

            node.context.type      = typ;
            node.context.realType  = typ;
            node.context.name      = name;
            node.context.valueType = valueType;

            return(node);
        }
Esempio n. 8
0
        /**
         * @ 获取节点的值类型
         **/
        private void GetValueType(KeyValuePair <string, IPListNode> item, out NodeValueType valueType, out object objValue)
        {
            bool hasChildren = item.Value.HasChildren;

            objValue = null;
            if (hasChildren)
            {
                valueType = GetValueType(item.Value);
                objValue  = item.Value;
            }
            else
            {
                valueType = GetValueType(item.Value.Value);
                objValue  = item.Value.Value;
            }
        }
Esempio n. 9
0
        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);
            }
        }
Esempio n. 10
0
 public void SaveNodeValueType(NodeValueType model)
 {
     using (var db = GetDbContext())
     {
         if (model.ID > 0)
         {
             var entity = db.NodeValueTypes.FirstOrDefault(e => e.ID == model.ID);
             db.Entry(entity).CurrentValues.SetValues(model);
         }
         else
         {
             db.NodeValueTypes.Add(model);
         }
         db.SaveChanges();
         ClearValueCache();
     }
 }
Esempio n. 11
0
        /**
         * @ 把元素的值包装成接口 IPListNode 类型
         * */
        protected virtual IPListNode ParseNode(XElement reader)
        {
            string        key       = reader.Name.LocalName;
            NodeValueType valueType = key.ToUpper().ToEnum <NodeValueType>();
            IPListNode    node      = new PListDict();
            string        val       = string.Empty;

            switch (valueType)
            {
            case NodeValueType.DICT:
                node.ReaderXml(reader);
                break;

            case NodeValueType.ARRAY:
                node = new PListArray();
                node.ReaderXml(reader);
                break;

            case NodeValueType.DATE:
                node.Value = reader.Value.ToDateTime();
                break;

            case NodeValueType.DATA:
                node.Value = reader.Value.ToBytes();
                break;

            case NodeValueType.FALSE:
            case NodeValueType.TRUE:
                node.Value = valueType == NodeValueType.TRUE;
                break;

            case NodeValueType.REAL:
                node.Value = reader.Value.ToDecimal();
                break;

            case NodeValueType.INTEGER:
                node.Value = reader.Value.ToInt();
                break;

            default:
                node.Value = reader.Value;
                break;
            }
            return(node);
        }
Esempio n. 12
0
        /**
         * @ 根据传入的值给出 LdfValueType 类型
         * @ value要判断的值
         * */
        protected virtual NodeValueType GetValueType(object value)
        {
            NodeValueType vt = NodeValueType.STRING;

            if (value is PListArray)
            {
                vt = NodeValueType.ARRAY;
            }
            else if (value is PListDict)
            {
                vt = NodeValueType.DICT;
            }
            else if (value is string)
            {
                vt = NodeValueType.STRING;
            }
            else if (value is DateTime)
            {
                vt = NodeValueType.DATE;
            }
            else if (value is int || value is long)
            {
                vt = NodeValueType.INTEGER;
            }
            else if (value is decimal || value is float || value is double)
            {
                vt = NodeValueType.REAL;
            }
            else if (value is bool)
            {
                if (value.ObjToBoolean())
                {
                    vt = NodeValueType.TRUE;
                }
                else
                {
                    vt = NodeValueType.FALSE;
                }
            }

            return(vt);
        }
Esempio n. 13
0
        /**
         * @ 实现 IPListNode 接口
         * */
        public override void WriterXml(XmlWriter writer)
        {
            foreach (var item in properties)
            {
                NodeValueType valueType = GetValueType(item.Value);
                string        keyName   = valueType.ToString().ToLower();

                if (valueType == (valueType & (NodeValueType.DICT | NodeValueType.ARRAY)))
                {
                    writer.WriteStartElement(keyName);
                    IPListNode node = (IPListNode)item;
                    node.WriterXml(writer);
                    writer.WriteEndElement();
                }
                else
                {
                    FormatXml(writer, item);
                }
            }
        }
Esempio n. 14
0
        /**
         * @ 格式化值的输出
         * @ ht LdfHashtable对象
         * */
        protected virtual void FormatJson(TextWriter writer, string key, IPListNode ht)
        {
            string        result    = string.Empty;
            NodeValueType valueType = GetValueType(ht.Value);

            if (key.IsNotNullOrEmpty())
            {
                writer.Write(string.Format("{0}{1}{0}{2}", Utilities.JSON_QUOTES, key, Utilities.JSON_COLON));
            }
            string keyString = valueType.ToString().ToLower();

            switch (valueType)
            {
            case NodeValueType.DATA:
                string data = Convert.ToBase64String(ht.Value as byte[]);
                FormatJson(writer, data);
                break;

            case NodeValueType.DATE:
                long unixDate = ht.Value.ObjToLong();
                FormatJson(writer, unixDate);
                break;

            //case "key":
            case NodeValueType.STRING:
                FormatJson(writer, ht.Value);
                break;

            case NodeValueType.REAL:
            case NodeValueType.INTEGER:
                writer.Write(ht.Value);
                break;

            case NodeValueType.TRUE:
            case NodeValueType.FALSE:
                writer.Write(ht.Value.ObjToInt());
                break;
            }
        }
Esempio n. 15
0
        /**
         * @ 索引,区分 Hashtable 和 IList 对象
         * @ key 如果当前对象的值是 LdfHashtable 对象,则 key 应当为 hash key
         * @ 如果当前对象值类型为 IList,则自动将 key 转换成下标
         * */
        public override IPListNode this[string key]
        {
            get
            {
                IPListNode    plistNode = null;
                NodeValueType valueType = GetValueType(this.Value);
                if (valueType == NodeValueType.ARRAY && key.IsInt())
                {
                    IList list = this.Value as IList;
                    plistNode = list[key.ObjToInt()] as IPListNode;
                }
                else
                {
                    plistNode = properties[key];
                }

                return(plistNode);
            }
            set
            {
                value.Order     = Count + 1;
                properties[key] = value;
            }
        }
Esempio n. 16
0
        private PacketNode FindChildNode(PacketElement element, string name, Type type, NodeValueType valueType)
        {
            var children = _cur.children;

            return(children.Find((c) => {
                return c.context.name == name &&
                c.context.type == Framework.Assembly.GetTypeName(type) &&
                c.context.valueType == valueType;
            }));
        }
Esempio n. 17
0
 public static bool IsNumericalNodeValueType(NodeValueType nodeValueType)
 {
     Debug.Assert(Enum.IsDefined(typeof(NodeValueType), nodeValueType));
     return nodeValueType >= NodeValueType.Byte;
 }
Esempio n. 18
0
 public static bool IsIntegralNodeValueType(NodeValueType nodeValueType)
 {
     Debug.Assert(Enum.IsDefined(typeof(NodeValueType), nodeValueType));
     return (nodeValueType >= NodeValueType.Byte) && (nodeValueType <= NodeValueType.Int64);
 }
Esempio n. 19
0
        public string GetNodeValue(List<string> xpaths, NodeValueType nodeValueType,
            StartExpressionSeparator startExprSep, EndExpressionSeparator endExprSep, List<Replacement> lstReplacements)
        {
            string retVal = null;

            foreach (string xpath in xpaths)
            {
                retVal = GetNodeValue(xpath, nodeValueType, startExprSep, endExprSep, lstReplacements);
                if (retVal != null)
                    break;
            }

            return retVal;
        }
Esempio n. 20
0
        public string GetNodeValue(string xpath, NodeValueType nodeValueType,
            StartExpressionSeparator startExprSep, EndExpressionSeparator endExprSep, List<Replacement> lstReplacements)
        {
            string retVal = null;
            HtmlNode node = null;

            xpath = xpath.Trim();

            if (xpath == ".")
            {
                node = _anchorLstNodeColl[_anchorLstCurrIndex];
            }
            else
            {
                if (xpath.StartsWith("..")) // znaci da ide prema parentu po neki xpath axis (npr ../following-sibling ili ../preceding-sibling)
                {
                    if (_anchorLstNodeColl == null)
                    {
                        return null;
                    }

                    xpath = _anchorLstNodeColl[_anchorLstCurrIndex].XPath + "/" + xpath;    // u tom slucaju treba nadograditi postojeci
                }

                node = _htmlDoc.DocumentNode.SelectSingleNode(xpath);

                // WORKAROUND za slcaj da uleti tbody kojeg obicno nema, ali ga recimo firefox voli dodavati
                if (node == null && (xpath.Contains("/tbody[1]") || xpath.Contains("/tbody")))
                {
                    xpath = xpath.Replace("/tbody[1]", string.Empty);
                    xpath = xpath.Replace("/tbody", string.Empty);
                    node = _htmlDoc.DocumentNode.SelectSingleNode(xpath);
                }
            }

            if (node != null)
            {
                switch (nodeValueType)
                {
                    case NodeValueType.InnerText:
                        retVal = node.InnerText;
                        break;

                    case NodeValueType.InnerHtml:
                        retVal = node.InnerHtml;
                        break;

                    case NodeValueType.OuterHtml:
                        retVal = node.OuterHtml;
                        break;
                }

                // 1. PROCESUIRANJE StartExpressionSeparatora i EndExpressionSeparatora
                if (startExprSep != null)
                {
                    if (!startExprSep.ValidateSeparator(retVal))
                        return null;

                    retVal = startExprSep.ProcessValue(retVal);
                }

                if (endExprSep != null)
                {
                    if (!endExprSep.ValidateSeparator(retVal))
                        return null;

                    retVal = endExprSep.ProcessValue(retVal);
                }

                // 2. CISCENJE POVRATNE VRIJEDNOSTI
                // dekodira web znakove kao sto su '&lt;' i '&gt;', brise visestruko pojavljivanje novih redaka, pretvara tabove u space i brise spaceove ili navodnike sa pocetka i kraja
                retVal = HttpUtility.HtmlDecode(retVal);

                retVal = retVal.Replace("\r\n", "\n");
                retVal = retVal.Replace("\\r\\n", "\n");
                retVal = retVal.Replace("\\n", "\n");

                while (retVal.Contains("\n\n"))
                {
                    retVal = retVal.Replace("\n\n", "\n");
                }

                retVal = retVal.Replace("\t", " ");
                retVal = retVal.Replace("\\t", " ");

                retVal = retVal.Trim();
                retVal = retVal.Trim('"');
                retVal = retVal.Trim('\'');
                retVal = retVal.Trim();

                // 3. PROVODENJE REPLACEMENTA
                if(lstReplacements != null)
                {
                    foreach (Replacement rep in lstReplacements)
                    {
                        retVal = rep.Replace(retVal);
                    }
                }
            }

            return retVal;
        }
Esempio n. 21
0
 public ActionResult Edit(NodeValueType model)
 {
     Core.FormManager.SaveNodeValueType(model);
     return(JsonSuccessResult());
 }
Esempio n. 22
0
 public static bool IsIntegralNodeValueType(NodeValueType nodeValueType)
 {
     Debug.Assert(Enum.IsDefined(typeof(NodeValueType), nodeValueType));
     return((nodeValueType >= NodeValueType.Byte) && (nodeValueType <= NodeValueType.Int64));
 }
Esempio n. 23
0
 public static bool IsNumericalNodeValueType(NodeValueType nodeValueType)
 {
     Debug.Assert(Enum.IsDefined(typeof(NodeValueType), nodeValueType));
     return(nodeValueType >= NodeValueType.Byte);
 }