Beispiel #1
0
        /// <summary>
        /// 根据ID校验对象一致性
        /// </summary>
        /// <param name="description">描述</param>
        /// <param name="errors">一个集合,如果发生错误,将错误添加到此集合 - 或 - <see langword="null"/>时,忽略此集合。</param>
        /// <param name="objects"></param>
        /// <param name="ids"></param>
        internal static void ValidateObjectsByIDs(string description, IBatchErrorAdapter errors, SchemaObjectCollection objects, IEnumerable <string> ids)
        {
            foreach (string id in ids)
            {
                try
                {
                    SchemaObjectBase obj = objects[id];

                    (obj == null).TrueThrow("类型{0},对象{1}不存在", description ?? "(未知)", id);
                    (obj.Status != SchemaObjectStatus.Normal).TrueThrow("类型{0},对象{1}已删除", description ?? obj.SchemaType, id);
                }
                catch (System.Exception ex)
                {
                    if (errors != null)
                    {
                        errors.AddError(ex);
                    }
                }
            }
        }
Beispiel #2
0
 public BatchExecutor(string[] src, string[] target)
 {
     this.errors   = this.InitErrorAdapter();
     this.keysFrom = src;
     this.keysTo   = target;
 }
Beispiel #3
0
        private static SchemaObjectCollection GetObjects(string[] keys, BatchExecuteCardinality cardinality, IBatchErrorAdapter errors)
        {
            SchemaObjectCollection result = null;

            if ((cardinality & BatchExecuteCardinality.Mandatory) == BatchExecuteCardinality.Mandatory)
            {
                // 至少含有一个
                if (keys == null || keys.Length == 0)
                {
                    throw new ArgumentOutOfRangeException("keys", keys, "需要至少一个对象");
                }
            }

            if ((cardinality & BatchExecuteCardinality.One) == BatchExecuteCardinality.One)
            {
                if (keys != null && keys.Length > 1)
                {
                    throw new ArgumentOutOfRangeException("keys", keys, "只能指定一个对象");
                }
            }

            if (keys != null && keys.Length > 0)
            {
                result = DbUtil.LoadAndCheckObjects("对象", errors, keys);
            }
            else
            {
                result = new SchemaObjectCollection();
            }

            return(result);
        }
		public BatchExecutor(string[] src, string[] target)
		{
			this.errors = this.InitErrorAdapter();
			this.keysFrom = src;
			this.keysTo = target;
		}
		private static SchemaObjectCollection GetObjects(string[] keys, BatchExecuteCardinality cardinality, IBatchErrorAdapter errors)
		{
			SchemaObjectCollection result = null;
			if ((cardinality & BatchExecuteCardinality.Mandatory) == BatchExecuteCardinality.Mandatory)
			{
				// 至少含有一个
				if (keys == null || keys.Length == 0)
				{
					throw new ArgumentOutOfRangeException("keys", keys, "需要至少一个对象");
				}
			}

			if ((cardinality & BatchExecuteCardinality.One) == BatchExecuteCardinality.One)
			{
				if (keys != null && keys.Length > 1)
				{
					throw new ArgumentOutOfRangeException("keys", keys, "只能指定一个对象");
				}
			}

			if (keys != null && keys.Length > 0)
			{
				result = DbUtil.LoadAndCheckObjects("对象", errors, keys);
			}
			else
			{
				result = new SchemaObjectCollection();
			}

			return result;
		}
Beispiel #6
0
        internal static SchemaObjectCollection LoadAndCheckObjects(string description, IBatchErrorAdapter errors, string[] idArray)
        {
            if (idArray.Length == 0)
            {
                throw new ArgumentOutOfRangeException("ids", "未指定任何ID");
            }

            InSqlClauseBuilder ib = new InSqlClauseBuilder("ID");

            ib.AppendItem(idArray);

            WhereSqlClauseBuilder wb = new WhereSqlClauseBuilder();

            wb.AppendItem("Status", (int)SchemaObjectStatus.Normal);

            SchemaObjectCollection result = PC.Adapters.SchemaObjectAdapter.Instance.Load(new ConnectiveSqlClauseCollection(ib, wb));

            ValidateObjectsByIDs(description, errors, result, idArray);
            return(result);
        }