Exemplo n.º 1
0
        private static string GetServerCode(string userId, string markedCode, Func <IEnumerable <UIMenuItem> > getServerCode)
        {
            ArgumentAssert.IsNotNullOrEmpty(markedCode, "markedCode");

            string fileName = GetMenuFileName(userId, markedCode);

            if (File.Exists(fileName))
            {
                return(File.ReadAllText(fileName));
            }

            UIMenu menu = new UIMenu(getServerCode());
            var    code = menu.ToJSON();

            try
            {
                WriteText(fileName, code);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
            return(code);
        }
        public XmlnsDefinitionAttribute(string xamlNamespace, string clrNamespace, string assemblyName)
        {
            ArgumentAssert.IsNotNullOrEmpty(xamlNamespace, "xamlNamespace");
            ArgumentAssert.IsNotNullOrEmpty(clrNamespace, "clrNamespace");
            ArgumentAssert.IsNotNullOrEmpty(assemblyName, "assemblyName");

            this.XamlNamespace = xamlNamespace;
            this.ClrNamespace  = clrNamespace;
            this.AssemblyName  = assemblyName;
        }
        public ChangeNameExpression(string exp)
        {
            int index = exp.IndexOf("=>");  //转换成员名称

            if (index > 0)
            {
                _findExp = exp.Substring(0, index).Trim();
                _name    = exp.Substring(index + 2).Trim();
            }

            ArgumentAssert.IsNotNullOrEmpty(_findExp, "findExp");
            ArgumentAssert.IsNotNullOrEmpty(_name, "name");
        }
Exemplo n.º 4
0
        /// <summary>
        /// 通过定义的代码来初始化脚本事件的定义
        /// </summary>
        /// <param name="defineCode"></param>
        public ScriptEventDefine(string defineCode)
        {
            ArgumentAssert.IsNotNullOrEmpty(defineCode, "defineCode");

            var pos = defineCode.IndexOf(":");

            if (pos > -1)
            {
                this.OriginalName = defineCode.Substring(0, pos);
                this.ClientName   = defineCode.Substring(pos + 1);
            }
            else
            {
                this.OriginalName = this.ClientName = defineCode;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="memberName"></param>
        private void BeginAssign(string memberName)
        {
            ArgumentAssert.IsNotNullOrEmpty(memberName, "memberName");

            var target = _evalStack.Peek();

            if (target.ItemType != ItemType.Reference)
            {
                throw new InvalidOperationException("此操作执行之前,请加载引用类型对象到计算堆栈上");
            }

            if (target.Type == null)
            {
                throw new InvalidOperationException("此操作执行之前,请加确保对象已加载到计算堆栈上");
            }

            BeginAssign(GetFieldOrProperty(target.Type, memberName));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 该方法用于更改成员的值
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="findExp"></param>
        /// <param name="valueFindExp"></param>
        /// <param name="transformValue"></param>
        public void ChangeValue(DTObject dto, string findExp, string valueFindExp, Func <object, object> transformValue)
        {
            ArgumentAssert.IsNotNullOrEmpty(findExp, "findExp");
            ArgumentAssert.IsNotNullOrEmpty(valueFindExp, "valueFindExp");

            //1.找出需要赋值的目标成员
            var targets = dto.FindEntities(findExp, false);

            if (targets.Length == 0)
            {
                dto.SetValue(findExp, string.Empty);                      //如果没有成员,就自动生成
            }
            targets = dto.FindEntities(findExp, false);


            var valueExpression = _getValueExpression(valueFindExp);

            foreach (var target in targets)
            {
                var parent = target.Parent as DTEObject;
                if (parent == null)
                {
                    throw new DTOException("预期之外的错误," + valueExpression.FindExp);
                }

                var parentDTO = valueExpression.StartRoot ? dto : DTOPool.CreateObject(parent, dto.IsReadOnly, dto.IsPinned);

                //2.找出值,值是在目标成员所在的对象下进行查找的
                var entities = parentDTO.FindEntities(valueExpression.FindExp, false);
                if (entities.Length == 1)
                {
                    //获取值
                    var ve       = entities[0];
                    var newValue = GetValue(ve, transformValue, dto.IsReadOnly);
                    if (newValue == null)
                    {
                        throw new DTOException("预期之外的数据转换," + valueExpression.FindExp);
                    }


                    //目标值是唯一的,这个时候要进一步判断
                    var valueObjParent = ve.Parent.Parent as DTEList;         //这是值所在的对象的父亲
                    //if (valueObjFather != null && ve!=target)  //如果值所在的对象处在集合中,并且不是自身对自身赋值,那么还是要以集合形式赋值
                    if (valueObjParent != null && ve.Parent != target.Parent) //如果值所在的对象处在集合中,并且不是自身对象对自身对象赋值,那么还是要以集合形式赋值
                    {
                        //以集合赋值
                        SetValue(target, new object[] { newValue }, valueExpression.FindExp);
                    }
                    else
                    {
                        //赋单值
                        SetValue(target, newValue, valueExpression.FindExp);
                    }
                }
                else if (entities.Length > 1)
                {
                    //如果目标值是多个,那么是集合类型,这时候需要收集所有转换后的值,再赋值
                    List <object> values = new List <object>(entities.Length);
                    foreach (var e in entities)
                    {
                        var newValue = GetValue(e, transformValue, dto.IsReadOnly);
                        if (newValue == null)
                        {
                            throw new DTOException("预期之外的数据转换," + valueExpression.FindExp);
                        }
                        values.Add(newValue);
                    }

                    SetValue(target, values, valueExpression.FindExp);
                }
                else
                {
                    //值为0,需要判断是否为数组
                }
            }
        }
 public StaticExtension(string path)
 {
     ArgumentAssert.IsNotNullOrEmpty(path, "path");
     Init(path);
 }