示例#1
0
        protected override void PrepareOperationLog(SchemaObjectOperationContext context)
        {
            SCOperationLog log = SCOperationLog.CreateLogFromEnvironment();

            log.ResourceID    = this._Owner.OwnerID;
            log.SchemaType    = this.ownerObj.SchemaType;
            log.OperationType = this.OperationType;
            log.Category      = this.ownerObj.Schema.Category;
            log.Subject       = string.Format("{0}: {1}",
                                              EnumItemDescriptionAttribute.GetDescription(this.OperationType), this.ownerObj.Name);

            log.SearchContent = this.ownerObj.ToFullTextString();

            context.Logs.Add(log);
        }
        protected override object DoOperation(SchemaObjectOperationContext context)
        {
            int deletedCount = 0;

            foreach (SCDeleteCandidate candidate in this._Candidates)
            {
                string objName = candidate.Object.Properties.GetValue("Name", string.Empty);

                try
                {
                    SCObjectOperations.Instance.DoOperation(SCObjectOperationMode.Delete, candidate.Object, candidate.Parent, candidate.DeletedByContainer);

                    ProcessProgress.Current.StatusText = string.Format("已删除\"{0}\"", objName);
                    ProcessProgress.Current.Increment();
                    ProcessProgress.Current.Response();

                    if (SCDataOperationLockContext.Current.Lock != null && (deletedCount) % 5 == 0)
                    {
                        SCDataOperationLockContext.Current.ExtendLock();
                    }

                    deletedCount++;
                }
                catch (System.Exception ex)
                {
                    throw new ApplicationException(string.Format("删除对象{0}({1})出错: {2}", objName, candidate.Object.ID, ex.Message));
                }
            }

            SCOperationLog log = SCOperationLog.CreateLogFromEnvironment();

            log.ResourceID    = this._Parent.ID;
            log.SchemaType    = this._Parent.SchemaType;
            log.OperationType = this.OperationType;
            log.Category      = this._Parent.Schema.Category;
            log.Subject       = string.Format("{0}: 总计应删除{1}中的 {2:#,##0} 个对象,实际删除{3:#,##0}个对象",
                                              EnumItemDescriptionAttribute.GetDescription(this.OperationType), this._Parent.Name,
                                              this._Candidates.Count.ToString(), deletedCount);
            log.SearchContent = this._Parent.ToFullTextString();

            context.Logs.Add(log);

            ProcessProgress.Current.StatusText = string.Format("总共删除了{0:#,##0}个对象", deletedCount);
            ProcessProgress.Current.Response();

            return(this._Parent);
        }
示例#3
0
        public void AddGroupExecutorTest()
        {
            Trace.CorrelationManager.ActivityId = UuidHelper.NewUuid();

            SCGroup group = SCObjectGenerator.PrepareGroupObject();

            SCObjectOperations.Instance.AddGroup(group, SCOrganization.GetRoot());

            SCGroup groupLoaded = (SCGroup)SchemaObjectAdapter.Instance.Load(group.ID);

            Assert.AreEqual(group.ID, groupLoaded.ID);

            SCOperationLog log = SCOperationLogAdapter.Instance.LoadByResourceID(group.ID).FirstOrDefault();

            Assert.IsNotNull(log);
            Assert.AreEqual(Trace.CorrelationManager.ActivityId.ToString(), log.CorrelationID);
        }
示例#4
0
        public void InsertLogTest()
        {
            Trace.CorrelationManager.ActivityId = UuidHelper.NewUuid();

            SCActionContext.Current.TimePoint = DateTime.Now.AddDays(-1).ToLocalTime();

            SCOperationLog log = SCOperationLog.CreateLogFromEnvironment();

            SCOperationLogAdapter.Instance.Insert(log);

            SCOperationLog logLoaded = SCOperationLogAdapter.Instance.Load(log.ID);

            Assert.IsNotNull(logLoaded);
            Assert.AreEqual(log.ID, logLoaded.ID);
            Assert.AreEqual(log.CorrelationID, logLoaded.CorrelationID);
            Assert.IsTrue(logLoaded.CreateTime.Subtract(SCActionContext.Current.TimePoint).TotalSeconds <= 1);
        }
示例#5
0
        public void AddUserOperationTest()
        {
            Trace.CorrelationManager.ActivityId = UuidHelper.NewUuid();

            SCUser user = SCObjectGenerator.PrepareUserObject();

            SCObjectOperations.Instance.DoOperation(SCObjectOperationMode.Add, user, null);

            SCUser userLoaded = (SCUser)SchemaObjectAdapter.Instance.Load(user.ID);

            Assert.AreEqual(user.ID, userLoaded.ID);

            SCOperationLog log = SCOperationLogAdapter.Instance.LoadByResourceID(user.ID).FirstOrDefault();

            Assert.IsNotNull(log);
            Assert.AreEqual(Trace.CorrelationManager.ActivityId.ToString(), log.CorrelationID);
        }
示例#6
0
        public void AddApplicationTest()
        {
            Trace.CorrelationManager.ActivityId = UuidHelper.NewUuid();

            SCApplication application = SCObjectGenerator.PrepareApplicationObject();

            SCObjectOperations.Instance.AddApplication(application);

            SCApplication appLoaded = (SCApplication)SchemaObjectAdapter.Instance.Load(application.ID);

            Assert.AreEqual(application.ID, appLoaded.ID);

            SCOperationLog log = SCOperationLogAdapter.Instance.LoadByResourceID(application.ID).FirstOrDefault();

            Assert.IsNotNull(log);
            Assert.AreEqual(Trace.CorrelationManager.ActivityId.ToString(), log.CorrelationID);
        }
示例#7
0
        protected override void PrepareOperationLog(SchemaObjectOperationContext context)
        {
            SCOperationLog log = SCOperationLog.CreateLogFromEnvironment();

            log.ResourceID    = this._Role.ID;
            log.SchemaType    = this._Role.SchemaType;
            log.OperationType = this.OperationType;
            log.Category      = this._Role.Schema.Category;


            log.Subject = string.Format("{0}: 替角色 {1} {2} 权限 {3}",
                                        EnumItemDescriptionAttribute.GetDescription(this.OperationType), this._Role.Name, (this._Relation.Status == SchemaObjectStatus.Normal ? "赋予" : "解除"),
                                        this._Permission.Name);

            log.SearchContent = this._Role.ToFullTextString() +
                                " " + this._Permission.ToFullTextString();

            context.Logs.Add(log);
        }
        protected override void PrepareOperationLog(SchemaObjectOperationContext context)
        {
            if (this.RelationExisted == false)
            {
                SCOperationLog log = SCOperationLog.CreateLogFromEnvironment();

                log.ResourceID    = this._Object.ID;
                log.SchemaType    = this._Object.SchemaType;
                log.OperationType = this.OperationType;
                log.Category      = this._Object.Schema.Category;
                log.Subject       = string.Format("{0}: {1} 从 {2} 至 {3}",
                                                  EnumItemDescriptionAttribute.GetDescription(this.OperationType), this._Object.Name,
                                                  this._OriginalOrganization.Name, this._TargetOrganization.Name);

                log.SearchContent = this._Object.ToFullTextString() +
                                    " " + this._OriginalOrganization.ToFullTextString() +
                                    " " + this._TargetOrganization.ToFullTextString();

                context.Logs.Add(log);
            }
            else
            {
                SCOperationLog log = SCOperationLog.CreateLogFromEnvironment();

                log.ResourceID    = this._Object.ID;
                log.SchemaType    = this._Object.SchemaType;
                log.OperationType = this.OperationType;
                log.Category      = this._Object.Schema.Category;
                log.Subject       = string.Format("{0}: {1} 从 {2} 至 {3}(跳过已经存在的关系)",
                                                  EnumItemDescriptionAttribute.GetDescription(this.OperationType), this._Object.Name,
                                                  this._OriginalOrganization.Name, this._TargetOrganization.Name);

                log.SearchContent = this._Object.ToFullTextString() +
                                    " " + this._OriginalOrganization.ToFullTextString() +
                                    " " + this._TargetOrganization.ToFullTextString();

                context.Logs.Add(log);
            }
        }
		public void Insert(SCOperationLog log)
		{
			if (log != null)
			{
				log.CreateTime = SCActionContext.Current.TimePoint;
				StringBuilder strB = new StringBuilder(256);

				strB.Append(ORMapping.GetInsertSql(log, this.GetMappingInfo(), TSqlBuilder.Instance));
				strB.Append(TSqlBuilder.Instance.DBStatementSeperator);
				strB.Append("SELECT SCOPE_IDENTITY()");

				Decimal newID = (Decimal)DbHelper.RunSqlReturnScalar(strB.ToString(), this.GetConnectionName());

				log.ID = Decimal.ToInt32(newID);
			}
		}