コード例 #1
0
        /// <summary>
        /// 合并用户信息,一个事物内更新所有的
        /// </summary>
        /// <param name="users"></param>
        public void BatchMerge(string containerID, string containerSchemaType, SchemaObjectCollection users)
        {
            containerID.CheckStringIsNullOrEmpty("containerID");
            containerSchemaType.CheckStringIsNullOrEmpty("containerSchemaType");
            users.NullCheck("users");

            SameContainerItemAndContainerSnapshotCollection existedData = this.LoadByContainerID(containerID);

            SameContainerItemAndContainerSnapshotCollection insertData = GetInsertData(containerID, containerSchemaType, existedData, users);
            SameContainerItemAndContainerSnapshotCollection updateData = GetUpdateData(containerID, containerSchemaType, existedData, users);

            string sqlInsert = this.PrepareUpdateSql(insertData);
            string sqlUpdate = this.PrepareUpdateSql(updateData);

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                DateTime dtInsert = (DateTime)DbHelper.RunSqlReturnScalar(sqlInsert, this.GetConnectionName());

                SCActionContext.Current.TimePoint.IsMinValue(() => SCActionContext.Current.TimePoint = dtInsert);

                DateTime dtUpdate = (DateTime)DbHelper.RunSqlReturnScalar(sqlUpdate, this.GetConnectionName());

                SCActionContext.Current.TimePoint.IsMinValue(() => SCActionContext.Current.TimePoint = dtUpdate);

                scope.Complete();
            }
        }
コード例 #2
0
        private static SameContainerItemAndContainerSnapshotCollection GetUpdateData(string containerID, string containerSchemaType, SameContainerItemAndContainerSnapshotCollection existedData, SchemaObjectCollection users)
        {
            SameContainerItemAndContainerSnapshotCollection updatedInfo = new SameContainerItemAndContainerSnapshotCollection();

            foreach (ItemAndContainerSnapshot uacs in existedData)
            {
                if (users.ContainsKey(uacs.ItemID))
                {
                    //原来是已删除的,现在改为Normal
                    if (uacs.Status != SchemaObjectStatus.Normal)
                    {
                        uacs.Status = SchemaObjectStatus.Normal;
                        updatedInfo.Add(uacs);
                    }
                }
                else
                {
                    //现在不存在了,状态需要改为已删除
                    uacs.Status = SchemaObjectStatus.Deleted;
                    updatedInfo.Add(uacs);
                }
            }

            return(updatedInfo);
        }
コード例 #3
0
        /// <summary>
        /// 合并用户信息
        /// </summary>
        /// <param name="objects"></param>
        public void Merge(string containerID, string containerSchemaType, SchemaObjectCollection objects)
        {
            containerID.CheckStringIsNullOrEmpty("containerID");
            containerSchemaType.CheckStringIsNullOrEmpty("containerSchemaType");
            objects.NullCheck("objects");

            SameContainerItemAndContainerSnapshotCollection existedData = this.LoadByContainerID(containerID);

            SameContainerItemAndContainerSnapshotCollection insertData = GetInsertData(containerID, containerSchemaType, existedData, objects);
            SameContainerItemAndContainerSnapshotCollection updateData = GetUpdateData(containerID, containerSchemaType, existedData, objects);

            ProcessProgress.Current.MaxStep += insertData.Count;
            ProcessProgress.Current.MaxStep += updateData.Count;

            ExecUpdateSeperately(insertData);
            ExecUpdateSeperately(updateData);
        }
コード例 #4
0
        private void ExecUpdateSeperately(SameContainerItemAndContainerSnapshotCollection data)
        {
            foreach (ItemAndContainerSnapshot obj in data)
            {
                string sql = PrepareOneUpdateSql(obj);

                using (TransactionScope scope = TransactionScopeFactory.Create())
                {
                    DateTime dtUpdate = (DateTime)DbHelper.RunSqlReturnScalar(sql, this.GetConnectionName());

                    SCActionContext.Current.TimePoint.IsMinValue(() => SCActionContext.Current.TimePoint = dtUpdate);

                    scope.Complete();
                }

                ProcessProgress.Current.Increment();
                ProcessProgress.Current.Response();
            }
        }
コード例 #5
0
		private void ExecUpdateSeperately(SameContainerItemAndContainerSnapshotCollection data)
		{
			foreach (ItemAndContainerSnapshot obj in data)
			{
				string sql = PrepareOneUpdateSql(obj);

				using (TransactionScope scope = TransactionScopeFactory.Create())
				{
					DateTime dtUpdate = (DateTime)DbHelper.RunSqlReturnScalar(sql, this.GetConnectionName());

					SCActionContext.Current.TimePoint.IsMinValue(() => SCActionContext.Current.TimePoint = dtUpdate);

					scope.Complete();
				}

				ProcessProgress.Current.Increment();
				ProcessProgress.Current.Response();
			}
		}
コード例 #6
0
        private static SameContainerItemAndContainerSnapshotCollection GetInsertData(string containerID, string containerSchemaType, SameContainerItemAndContainerSnapshotCollection existedData, SchemaObjectCollection items)
        {
            SameContainerItemAndContainerSnapshotCollection newInfo = new SameContainerItemAndContainerSnapshotCollection();

            foreach (SchemaObjectBase item in items)
            {
                if (existedData.ContainsKey(item.ID) == false && newInfo.ContainsKey(item.ID) == false)
                {
                    ItemAndContainerSnapshot uacs = new ItemAndContainerSnapshot();

                    uacs.ContainerID         = containerID;
                    uacs.ContainerSchemaType = containerSchemaType;
                    uacs.ItemID         = item.ID;
                    uacs.ItemSchemaType = item.SchemaType;
                    uacs.Status         = SchemaObjectStatus.Normal;

                    newInfo.Add(uacs);
                }
            }

            return(newInfo);
        }
コード例 #7
0
        /// <summary>
        /// 根据Container来加载ItemAndContainerSnapshot的信息
        /// </summary>
        /// <param name="containerID"></param>
        /// <param name="timePoint"></param>
        /// <returns></returns>
        public SameContainerItemAndContainerSnapshotCollection LoadByContainerID(string containerID, DateTime timePoint)
        {
            containerID.CheckStringIsNullOrEmpty("containerID");

            ConnectiveSqlClauseCollection timePointBuilder = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint);

            WhereSqlClauseBuilder whereBuilder = new WhereSqlClauseBuilder();

            whereBuilder.AppendItem("ContainerID", containerID);

            ConnectiveSqlClauseCollection connectiveBuilder = new ConnectiveSqlClauseCollection(whereBuilder, timePointBuilder);

            string sql = string.Format("SELECT * FROM {0} WHERE {1}",
                                       this.GetLoadingTableName(timePoint), connectiveBuilder.ToSqlString(TSqlBuilder.Instance));

            SameContainerItemAndContainerSnapshotCollection result = new SameContainerItemAndContainerSnapshotCollection();

            using (DbContext context = DbContext.GetContext(this.GetConnectionName()))
            {
                using (IDataReader reader = DbHelper.RunSqlReturnDR(sql, this.GetConnectionName()))
                {
                    while (reader.Read())
                    {
                        ItemAndContainerSnapshot item = new ItemAndContainerSnapshot();

                        ORMapping.DataReaderToObject(reader, item);

                        if (result.ContainsKey(item.ItemID) == false)
                        {
                            result.Add(item);
                        }
                    }
                }
            }

            return(result);
        }
コード例 #8
0
		private static SameContainerItemAndContainerSnapshotCollection GetUpdateData(string containerID, string containerSchemaType, SameContainerItemAndContainerSnapshotCollection existedData, SchemaObjectCollection users)
		{
			SameContainerItemAndContainerSnapshotCollection updatedInfo = new SameContainerItemAndContainerSnapshotCollection();

			foreach (ItemAndContainerSnapshot uacs in existedData)
			{
				if (users.ContainsKey(uacs.ItemID))
				{
					//原来是已删除的,现在改为Normal
					if (uacs.Status != SchemaObjectStatus.Normal)
					{
						uacs.Status = SchemaObjectStatus.Normal;
						updatedInfo.Add(uacs);
					}
				}
				else
				{
					//现在不存在了,状态需要改为已删除
					uacs.Status = SchemaObjectStatus.Deleted;
					updatedInfo.Add(uacs);
				}
			}

			return updatedInfo;
		}
コード例 #9
0
		private static SameContainerItemAndContainerSnapshotCollection GetInsertData(string containerID, string containerSchemaType, SameContainerItemAndContainerSnapshotCollection existedData, SchemaObjectCollection items)
		{
			SameContainerItemAndContainerSnapshotCollection newInfo = new SameContainerItemAndContainerSnapshotCollection();

			foreach (SchemaObjectBase item in items)
			{
				if (existedData.ContainsKey(item.ID) == false && newInfo.ContainsKey(item.ID) == false)
				{
					ItemAndContainerSnapshot uacs = new ItemAndContainerSnapshot();

					uacs.ContainerID = containerID;
					uacs.ContainerSchemaType = containerSchemaType;
					uacs.ItemID = item.ID;
					uacs.ItemSchemaType = item.SchemaType;
					uacs.Status = SchemaObjectStatus.Normal;

					newInfo.Add(uacs);
				}
			}

			return newInfo;
		}
コード例 #10
0
		/// <summary>
		/// 根据Container来加载ItemAndContainerSnapshot的信息
		/// </summary>
		/// <param name="containerID"></param>
		/// <param name="timePoint"></param>
		/// <returns></returns>
		public SameContainerItemAndContainerSnapshotCollection LoadByContainerID(string containerID, DateTime timePoint)
		{
			containerID.CheckStringIsNullOrEmpty("containerID");

			ConnectiveSqlClauseCollection timePointBuilder = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint);

			WhereSqlClauseBuilder whereBuilder = new WhereSqlClauseBuilder();

			whereBuilder.AppendItem("ContainerID", containerID);

			ConnectiveSqlClauseCollection connectiveBuilder = new ConnectiveSqlClauseCollection(whereBuilder, timePointBuilder);

			string sql = string.Format("SELECT * FROM {0} WHERE {1}",
				this.GetLoadingTableName(timePoint), connectiveBuilder.ToSqlString(TSqlBuilder.Instance));

			SameContainerItemAndContainerSnapshotCollection result = new SameContainerItemAndContainerSnapshotCollection();

			using (DbContext context = DbContext.GetContext(this.GetConnectionName()))
			{
				using (IDataReader reader = DbHelper.RunSqlReturnDR(sql, this.GetConnectionName()))
				{
					while (reader.Read())
					{
						ItemAndContainerSnapshot item = new ItemAndContainerSnapshot();

						ORMapping.DataReaderToObject(reader, item);

						if (result.ContainsKey(item.ItemID) == false)
							result.Add(item);
					}
				}
			}

			return result;
		}