Exemplo n.º 1
0
        public bool IsGrammarCorrect()
        {
            string[] splittedEntry = entry.Split('.');

            if (splittedEntry.Length != 2)
            {
                return(false);
                //throw new Exception("#Incorrect length of attr ref");
            }

            string declarationName = splittedEntry[0];
            string attrNameEntry   = splittedEntry[1];

            Synonym  synonym  = new Synonym(declarationName);
            AttrName attrName = new AttrName(attrNameEntry, declarationName, declarations);

            if (!synonym.IsGrammarCorrect())
            {
                return(false);
                //throw new Exception("#Incorrect synonym in attr ref: " + synonym.entry);
            }

            if (!attrName.IsGrammarCorrect())
            {
                return(false);
                //throw new Exception("#Incorrect attr name: " + attrName.entry);
            }

            refType = attrName.refType;
            return(true);
        }
Exemplo n.º 2
0
        public void ValidateAttrName_ShouldReturnFalse_WhenIncorrectDeclarationType(string attrName, string declarationName, string declarationType)
        {
            DeclarationsArray declarations = new DeclarationsArray();

            declarations.AddDeclaration(declarationType, declarationName);

            AbstractAuxiliaryGrammar attrNameValidator = new AttrName(attrName, declarationName, declarations);
            bool result = attrNameValidator.IsGrammarCorrect();

            Assert.False(result);
        }
Exemplo n.º 3
0
        public HtmlRadioGroup(string name, bool verbose, bool isPostBack)
            : base(verbose ? name : "")
        {
            attrName = new AttrName(name);

            attributes.Add(attrDisabled = new AttrDisabled());

            if (isPostBack)
            {
                events.Add(eventChange = new EventChange(string.Format("__doPostBack('{0}', '');", name)));
            }
        }
Exemplo n.º 4
0
        public HtmlInput(string idName, string name, string type)
            : base(idName)
        {
            attributes.Add(attrReadOnly = new AttrReadOnly());

            attributes.Add(attrDisabled = new AttrDisabled());

            attributes.Add(attrType = new AttrType(type));

            attributes.Add(attrName = new AttrName(name));

            attributes.Add(attrValue = new AttrValue());
        }
Exemplo n.º 5
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Compute a hash code for this object.
 /// </summary>
 /// <returns></returns>
 /// ------------------------------------------------------------------------------------
 public override int GetHashCode()
 {
     return((StyleName == null ? 0 : StyleName.GetHashCode()) +
            Context.GetHashCode() +
            (XmlTag == null ? 0 : XmlTag.GetHashCode()) +
            (AttrName == null ? 0 : AttrName.GetHashCode()) +
            (AttrValue == null ? 0 : AttrValue.GetHashCode()) +
            (AttrName2 == null ? 0 : AttrName2.GetHashCode()) +
            (AttrValue2 == null ? 0 : AttrValue2.GetHashCode()) +
            m_fIsCharStyle.GetHashCode() +
            IsHeading.GetHashCode() +
            CanEmbed.GetHashCode());
 }
Exemplo n.º 6
0
        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                string attrName    = AttrName.Get(context);
                object attrValue   = AttrValue.Get(context);
                Int32  timeOut     = TimeOut.Get(context);
                bool   isFoundFlag = false;

                UiElement         element = Common.GetValueOrDefault(context, this.Element, null);
                AutomationElement autoEle = element.NativeObject as AutomationElement;
                FrameworkAutomationElementBase baseFrame = autoEle.FrameworkAutomationElement;
                PropertyId[] ids       = autoEle.GetSupportedPropertiesDirect();
                PropertyId   currentId = null;
                for (int i = 0; i < ids.Length; i++)
                {
                    if (String.Equals(ids[i].Name, attrName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        currentId = ids[i];
                        break;
                    }
                }
                for (int i = 0; i < timeOut / 1000; i++)
                {
                    if (attrValue == baseFrame.GetPropertyValue(currentId))
                    {
                        isFoundFlag = true;
                        break;
                    }
                    Thread.Sleep(1000);
                }
                if (!isFoundFlag && !ContinueOnError.Get(context))
                {
                    SharedObject.Instance.Output(SharedObject.enOutputType.Error, "相应元素的属性值未匹配,获取属性失败");
                    throw new Exception("获取属性失败,过程中断");
                }
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "等待获取元素属性过程出错", e.Message);
                if (ContinueOnError.Get(context))
                {
                    return;
                }
                else
                {
                    throw e;
                }
            }
        }
Exemplo n.º 7
0
        public HtmlSelect(string name, bool multiple, bool isPostBack)
            : base(name)
        {
            attributes.Add(attrName = new AttrName(name));

            attributes.Add(attrDisabled = new AttrDisabled());

            attributes.Add(attrMultiple = new AttrMultiple(multiple));

            attributes.Add(attrSize = new AttrSize());

            if (isPostBack)
            {
                events.Add(eventChange = new EventChange(string.Format("__doPostBack('{0}', '');", name)));
            }
        }
Exemplo n.º 8
0
        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                var    selStr    = Selector.Get(context);
                object attrValue = null;
                string attrName  = AttrName.Get(context);

                UiElement element = Common.GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }
                AutomationElement autoEle = element.NativeObject as AutomationElement;
                FrameworkAutomationElementBase baseFrame = autoEle.FrameworkAutomationElement;
                PropertyId[] ids = autoEle.GetSupportedPropertiesDirect();
                for (int i = 0; i < ids.Length; i++)
                {
                    if (String.Equals(ids[i].Name, attrName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        attrValue = baseFrame.GetPropertyValue(ids[i]);
                        break;
                    }
                }
                if (attrValue == null)
                {
                    Result.Set(context, "");
                }
                else
                {
                    Result.Set(context, attrValue);
                }
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "获取元素属性失败", e.Message);
                if (ContinueOnError.Get(context))
                {
                    return;
                }
                else
                {
                    throw e;
                }
            }
        }
Exemplo n.º 9
0
        public HtmlSelect(string name, int size, bool isPostBack)
            : base(name)
        {
            attributes.Add(attrName = new AttrName(name));

            attributes.Add(attrDisabled = new AttrDisabled());

            attributes.Add(attrMultiple = new AttrMultiple(true));

            if (size < 1)
            {
                throw new ArgumentException();
            }
            else
            {
                attributes.Add(attrSize = new AttrSize(size));
            }

            if (isPostBack)
            {
                events.Add(eventChange = new EventChange(string.Format("__doPostBack('{0}', '');", name)));
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 保存供应商商品类型基础属性
        /// </summary>
        /// <param name="user"></param>
        /// <param name="typeName"></param>
        /// <returns></returns>
        public JsonResult SaveAttrName(SysUser user, AttrName attrName)
        {
            StateCode code = ServiceIoc.Get <AttrNameService>().Save(user.id, attrName);

            return(Json(GetResult(code)));
        }
Exemplo n.º 11
0
 /// <summary>
 /// 通知属性变化
 /// </summary>
 private void OnAttrChange(AttrName attrName, double newValue)
 {
     List<AttrChangeCallback> callbackList;
     if (attrChangeCallbackDict.TryGetValue(attrName, out callbackList))
     {
         callbackList = new List<AttrChangeCallback>(callbackList);
         int count = callbackList.Count;
         for (int i = 0; i < count; ++i)
         {
             AttrChangeCallback callback = callbackList[i];
             callback(newValue);
         }
     }
 }
Exemplo n.º 12
0
 /// <summary>
 /// 反注册属性变化时的回调函数
 /// </summary>
 public void UnrigisterAttrChangeCallback(AttrName attrName, AttrChangeCallback callback)
 {
     List<AttrChangeCallback> callbackList;
     if (attrChangeCallbackDict.TryGetValue(attrName, out callbackList))
         callbackList.Remove(callback);
 }
Exemplo n.º 13
0
 /// <summary>
 /// 根据AttrName设置属性值
 /// </summary>
 public void SetValue(AttrName attrName, double value)
 {
     switch (attrName)
     {
         case AttrName.Hp:
             Hp = value;
             break;
         case AttrName.MaxHpBase:
             MaxHpBase = value;
             break;
         case AttrName.MaxHpAddRate:
             MaxHpAddRate = value;
             break;
         case AttrName.AtkBase:
             AtkBase = value;
             break;
         case AttrName.AtkAddRate:
             AtkAddRate = value;
             break;
         case AttrName.DefBase:
             DefBase = value;
             break;
         case AttrName.DefAddRate:
             DefAddRate = value;
             break;
         case AttrName.AtkSpeedBase:
             AtkSpeedBase = value;
             break;
         case AttrName.AtkSpeedAddRate:
             AtkSpeedAddRate = value;
             break;
         case AttrName.AtkRangeBase:
             AtkRangeBase = (float)value;
             break;
         case AttrName.AtkRangeAddRate:
             AtkRangeAddRate = (float)value;
             break;
         case AttrName.MoveSpeedBase:
             MoveSpeedBase = (float)value;
             break;
         case AttrName.MoveSpeedAddRate:
             MoveSpeedAddRate = (float)value;
             break;
         default:
             Log.Error("非法的AttrName!", attrName);
             break;
     }
 }
Exemplo n.º 14
0
 /// <summary>
 /// 根据AttrName设置属性值
 /// </summary>
 public void AddValue(AttrName attrName, double value)
 {
     SetValue(attrName, GetValue(attrName) + value);
 }
Exemplo n.º 15
0
 public bool NameEquals(string arg)
 {
     return(AttrName.Equals(arg));
 }
Exemplo n.º 16
0
 /// <summary>
 /// 根据AttrName返回属性值
 /// </summary>
 public double GetValue(AttrName attrName)
 {
     switch (attrName)
     {
         case AttrName.Hp:
             return Hp;
         case AttrName.MaxHp:
             return MaxHp;
         case AttrName.MaxHpBase:
             return MaxHpBase;
         case AttrName.MaxHpAddRate:
             return MaxHpAddRate;
         case AttrName.Atk:
             return Atk;
         case AttrName.AtkBase:
             return AtkBase;
         case AttrName.AtkAddRate:
             return AtkAddRate;
         case AttrName.Def:
             return Def;
         case AttrName.DefBase:
             return DefBase;
         case AttrName.DefAddRate:
             return DefAddRate;
         case AttrName.AtkSpeed:
             return AtkSpeed;
         case AttrName.AtkSpeedBase:
             return AtkSpeedBase;
         case AttrName.AtkSpeedAddRate:
             return AtkSpeedAddRate;
         case AttrName.AtkRange:
             return AtkRange;
         case AttrName.AtkRangeBase:
             return AtkRangeBase;
         case AttrName.AtkRangeAddRate:
             return AtkRangeAddRate;
         case AttrName.MoveSpeed:
             return MoveSpeed;
         case AttrName.MoveSpeedBase:
             return MoveSpeedBase;
         case AttrName.MoveSpeedAddRate:
             return MoveSpeedAddRate;
         default:
             Log.Error("非法的AttrName!", attrName);
             return 0.0;
     }
 }
Exemplo n.º 17
0
 /// <summary>
 /// 注册属性变化时的回调函数
 /// </summary>
 public void RegisterAttrChangeCallback(AttrName attrName, AttrChangeCallback callback)
 {
     List<AttrChangeCallback> callbackList;
     if (attrChangeCallbackDict.TryGetValue(attrName, out callbackList))
     {
         if (callbackList.Contains(callback))
             return;
     }
     else
     {
         callbackList = new List<AttrChangeCallback>();
         attrChangeCallbackDict[attrName] = callbackList;
     }
     callbackList.Add(callback);
 }
Exemplo n.º 18
0
        private void AddAttribute(string prefix, string localName, string namespaceName)
        {
            int top = _attrCount++;
            if (top == _attrStack.Length)
            {
                AttrName[] newStack = new AttrName[top * 2];
                Array.Copy(_attrStack, 0, newStack, 0, top);
                _attrStack = newStack;
            }
            _attrStack[top].Set(prefix, localName, namespaceName);

            if (_attrCount < MaxAttrDuplWalkCount)
            {
                // check for duplicates
                for (int i = 0; i < top; i++)
                {
                    if (_attrStack[i].IsDuplicate(prefix, localName, namespaceName))
                    {
                        throw DupAttrException(prefix, localName);
                    }
                }
            }
            else
            {
                // reached the threshold -> add all attributes to hash table
                if (_attrCount == MaxAttrDuplWalkCount)
                {
                    if (_attrHashTable == null)
                    {
                        _attrHashTable = new Dictionary<string, int>(_hasher);
                    }
                    Debug.Assert(_attrHashTable.Count == 0);
                    for (int i = 0; i < top; i++)
                    {
                        AddToAttrHashTable(i);
                    }
                }

                // add last attribute to hash table and check for duplicates
                AddToAttrHashTable(top);
                int prev = _attrStack[top].prev;
                while (prev > 0)
                {
                    // indexes are stored incremented by 1, 0 means no entry
                    prev--;
                    if (_attrStack[prev].IsDuplicate(prefix, localName, namespaceName))
                    {
                        throw DupAttrException(prefix, localName);
                    }
                    prev = _attrStack[prev].prev;
                }
            }
        }
 private void AddAttribute(string prefix, string localName, string namespaceName)
 {
     int length = this.attrCount++;
     if (length == this.attrStack.Length)
     {
         AttrName[] destinationArray = new AttrName[length * 2];
         Array.Copy(this.attrStack, destinationArray, length);
         this.attrStack = destinationArray;
     }
     this.attrStack[length].Set(prefix, localName, namespaceName);
     if (this.attrCount < 14)
     {
         for (int i = 0; i < length; i++)
         {
             if (this.attrStack[i].IsDuplicate(prefix, localName, namespaceName))
             {
                 throw DupAttrException(prefix, localName);
             }
         }
     }
     else
     {
         if (this.attrCount == 14)
         {
             if (this.attrHashTable == null)
             {
                 this.attrHashTable = new Dictionary<string, int>(this.hasher);
             }
             for (int k = 0; k < length; k++)
             {
                 this.AddToAttrHashTable(k);
             }
         }
         this.AddToAttrHashTable(length);
         for (int j = this.attrStack[length].prev; j > 0; j = this.attrStack[j].prev)
         {
             j--;
             if (this.attrStack[j].IsDuplicate(prefix, localName, namespaceName))
             {
                 throw DupAttrException(prefix, localName);
             }
         }
     }
 }