예제 #1
0
        public void ReplaceItemsWith(SCConditionCollection source, string ownerID, string type)
        {
            DateTime ve = SNTPClient.AdjustedTime;
            DateTime vm = new DateTime(9999, 9, 9);

            //合并时,先将已经删除的过滤,将剩下的设置成删除,添加新的项目。
            int i = 0;

            while (i < this.Count)
            {
                if (this[i].Status != SchemaObjectStatus.Normal)
                {
                    this.RemoveAt(i);
                }
                else
                {
                    this[i].Status         = SchemaObjectStatus.Deleted;
                    this[i].VersionEndTime = ve;
                    i++;
                }
            }

            for (i = 0; i < source.Count; i++)
            {
                var item = source[i];
                item.SortID           = i + 1;
                item.OwnerID          = ownerID;
                item.Type             = type;
                item.VersionEndTime   = vm;
                item.VersionStartTime = ve;
                this.Add(item);
            }
        }
예제 #2
0
        /// <summary>
        /// 按照类型筛选出条件集合
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public SCConditionCollection GetConditionsByType(string type)
        {
            SCConditionCollection result = new SCConditionCollection();

            foreach (SCCondition condition in this)
            {
                if (condition.Type == type)
                {
                    result.Add(condition);
                }
            }

            return(result);
        }
        private void FilterUsersByConditions(SCConditionCollection conditions, SchemaObjectCollection result, string description)
        {
            ProcessProgress.Current.MaxStep += conditions.Count;
            ProcessProgress.Current.Response();

            foreach (SCCondition condition in conditions)
            {
                if (condition.Condition.IsNotEmpty() && condition.Status == SchemaObjectStatus.Normal)
                {
                    try
                    {
                        foreach (SCUser user in this.Context.AllObjects)
                        {
                            this.Context.CurrentObject = user;

                            try
                            {
                                //计算表达式
                                object booleanResult = ExpressionParser.Calculate(condition.Condition, new CalculateUserFunction(CalculateUserFunction), this.Context);
                                if ((booleanResult is bool) == false)
                                {
                                    throw new FormatException("指定的表达式未能解析为Bool值:" + Environment.NewLine + condition.Condition);
                                }

                                if ((bool)booleanResult)
                                {
                                    result.AddNotExistsItem(user);
                                }
                            }
                            finally
                            {
                                this.Context.CurrentObject = null;
                            }
                        }
                    }
                    catch (ParsingException ex)
                    {
                        ProcessProgress.Current.Error.WriteLine("解析{0}的条件{1}出错: {2}", description, condition.Condition, ex.Message);
                    }
                }
            }

            ProcessProgress.Current.Increment();
            ProcessProgress.Current.Response();
        }