private SCSimpleRelationBase PrepareRelationObject(SchemaObjectBase container, SchemaObjectBase member) { SCSimpleRelationBase relation = null; AUCommon.DoDbAction(() => { relation = SCMemberRelationAdapter.Instance.Load(container.ID, member.ID); }); if (relation == null) { relation = CreateRelation(container, member); } else { if (relation.Status == SchemaObjectStatus.Normal) { this._RelationExisted = true; } else { relation.Status = SchemaObjectStatus.Normal; } } return(relation); }
protected override void PrepareData(AUObjectOperationContext context) { this._OriginalRelation = this._Object.GetCurrentVeryParentRelation(); if (this._OriginalRelation == null || this._OriginalRelation.Status != SchemaObjectStatus.Normal) { throw new AUObjectValidationException("未找到此管理单元对应的上级关系"); } AUCommon.DoDbAction(() => { this._SourceObject = this._OriginalRelation.Parent; this._ActualTarget = this._Target ?? SchemaObjectAdapter.Instance.Load(this._Object.AUSchemaID); }); if (this._SourceObject == null || this._SourceObject.Status != SchemaObjectStatus.Normal) { throw new AUObjectValidationException("未找到此管理单元对应的上级对象"); } if (this._OriginalRelation.ParentID == this._ActualTarget.ID) { throw new AUObjectValidationException("此管理单元已经属于目标管理单元,无需移动。"); } AUCommon.DoDbAction(() => { this._TargetRelation = PrepareTargetRelation(this._ActualTarget, this._Object); this._NeedGenerateFullPaths = (this._Object is ISCRelationContainer) && (((ISCRelationContainer)this._Object).CurrentChildren.Count > 0); Validate(); }); }
public SCAclMemberCollection LoadMembers(IConnectiveSqlClause condition, DateTime timePoint) { ConnectiveSqlClauseCollection timePointBuilder = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint); ConnectiveSqlClauseCollection connectiveBuilder = new ConnectiveSqlClauseCollection(condition, timePointBuilder); string sql = string.Format( "SELECT * FROM {0} WHERE {1} ORDER BY SortID", this.GetLoadingTableName(timePoint), connectiveBuilder.ToSqlString(TSqlBuilder.Instance)); SCAclMemberCollection result = new SCAclMemberCollection(); AUCommon.DoDbAction(() => { using (DbContext context = DbContext.GetContext(this.GetConnectionName())) { using (IDataReader reader = DbHelper.RunSqlReturnDR(sql, this.GetConnectionName())) { ORMapping.DataReaderToCollection(result, reader); } } }); return(result); }
protected override object DoOperation(AUObjectOperationContext context) { if (this._RelationExisted == false) { if (this._OriginalRelation.Status == SchemaObjectStatus.Normal) { this._OriginalRelation.Status = SchemaObjectStatus.Deleted; AUCommon.DoDbAction(() => SchemaRelationObjectAdapter.Instance.UpdateStatus(this._OriginalRelation, SchemaObjectStatus.Deleted)); } AUCommon.DoDbAction(() => SchemaRelationObjectAdapter.Instance.Update(this._TargetRelation)); //if (this.NeedChangeOwner) // SchemaObjectAdapter.Instance.Update(this._Object); if (this._NeedGenerateFullPaths) { AUCommon.DoDbAction(() => SCToDoJobListAdapter.Instance.Insert(SCToDoJob.CreateGenerateFullPathsJob(this._Object))); } } return(this._TargetRelation); }
/// <summary> /// 生成所有的用户容器下的用户信息快照 /// </summary> public void GenerateAllItemAndContainerSnapshot() { ProcessProgress.Current.MinStep = 0; ProcessProgress.Current.MaxStep = 100; ProcessProgress.Current.CurrentStep = 0; ProcessProgress.Current.StatusText = string.Format("正在加载所有管理范围"); ProcessProgress.Current.Response(); Stopwatch sw = new Stopwatch(); sw.Start(); try { AUCommon.DoDbAction(() => { SchemaObjectCollection containers = AUCommon.DoDbProcess <SchemaObjectCollection>(() => PC.Adapters.SchemaObjectAdapter.Instance.LoadBySchemaType(new string[] { AUCommon.SchemaAUAdminScope }, DateTime.MinValue)); containers.Sort((c1, c2) => string.Compare(c1.SchemaType, c2.SchemaType, true)); ProcessProgress.Current.StatusText = string.Format("加载所有管理范围完成,总共{0}个对象", containers.Count); ProcessProgress.Current.MaxStep = containers.Count; ProcessProgress.Current.Response(); containers.ForEach(c => this.GenerateOneItemAndContainerSnapshot((IAdminScopeItemContainer)c)); }); } finally { sw.Stop(); } ProcessProgress.Current.StatusText = string.Format("计算人员完成,耗时{0:#,##0.00}秒", sw.Elapsed.TotalSeconds); ProcessProgress.Current.Response(); }
public AUSchemaCategory LoadByID(string id, DateTime timePoint) { var conditions = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint); WhereSqlClauseBuilder where = new WhereSqlClauseBuilder(); where.AppendItem("ID", id); conditions.Add(where); AUSchemaCategory cate = null; AUCommon.DoDbAction(() => { using (DbContext context = DbContext.GetContext(this.GetConnectionName())) { VersionedObjectAdapterHelper.Instance.FillData(ORMapping.GetMappingInfo(typeof(AUSchemaCategory)).TableName, conditions, this.GetConnectionName(), reader => { if (reader.Read()) { cate = new AUSchemaCategory(); ORMapping.DataReaderToObject <AUSchemaCategory>(reader, cate); } }); } }); return(cate); }
/// <summary> /// 生成用户容器下的管理范围信息快照 /// </summary> /// <param name="containers"></param> public void GenerateItemAndContainerSnapshot(IEnumerable <SchemaObjectBase> containers) { ProcessProgress.Current.MinStep = 0; ProcessProgress.Current.MaxStep = containers.Count(); ProcessProgress.Current.CurrentStep = 0; Stopwatch sw = new Stopwatch(); sw.Start(); try { AUCommon.DoDbAction(() => { foreach (IAdminScopeItemContainer container in containers) { this.GenerateOneItemAndContainerSnapshot(container); } }); } finally { sw.Stop(); } ProcessProgress.Current.CurrentStep = ProcessProgress.Current.MaxStep; ProcessProgress.Current.StatusText = string.Format("计算完成,耗时{0:#,##0.00}秒", sw.Elapsed.TotalSeconds); ProcessProgress.Current.Response(); }
protected override void CheckStatus() { AUCommon.DoDbAction(() => { List <SchemaObjectBase> dataToBeChecked = new List <SchemaObjectBase>(); if (this.NeedStatusCheck) { dataToBeChecked.Add(this.Data); } if (this.NeedParentStatusCheck && this.inputParent != null) { dataToBeChecked.Add(this.inputParent); } dataToBeChecked.Add(this.schema); CheckObjectStatus(dataToBeChecked.ToArray()); if (this.NeedDuplicateRelationCheck) { var allParentRelations = this.Data.CurrentParentRelations; var relationToSchema = (from r in allParentRelations where r.ParentSchemaType == AUCommon.SchemaAUSchema select r).FirstOrDefault(); var relationToUnit = (from u in allParentRelations where u.ParentSchemaType == AUCommon.SchemaAdminUnit select u).FirstOrDefault(); if (this.inputParent != null) { //添加下级管理单元 if (relationToSchema != null) { throw new SCStatusCheckException(string.Format("对象\"{0}\"已经是顶级管理单元了,不能再添加到别的管理单元中", AUCommon.DisplayNameFor(this.Data))); } else if (relationToUnit != null && (relationToUnit.ID != this.Data.ID || relationToUnit.ParentID != inputParent.ID)) { throw new SCStatusCheckException(string.Format("对象\"{0}\"已经属于另一管理单元{1}了,不能再添加到其他管理单元", AUCommon.DisplayNameFor(this.Data))); } } else { //顶级管理单元 if (relationToSchema != null) { if (relationToSchema.ParentID != schema.ID) { throw new SCStatusCheckException(string.Format("对象\"{0}\"已经是顶级管理单元了,不能再添加到别的管理单元中", AUCommon.DisplayNameFor(this.Data))); } } else if (relationToUnit != null) { throw new SCStatusCheckException(string.Format("对象\"{0}\"已经属于另一管理单元{1}了,不能作为顶级管理单元", AUCommon.DisplayNameFor(this.Data))); } } } }); }
protected override void PrepareData(AUObjectOperationContext context) { AUCommon.DoDbAction(() => { this.schema = (AUSchema)SchemaObjectAdapter.Instance.Load(((AdminUnit)Data).AUSchemaID); if (this.schema == null || this.schema.Status != SchemaObjectStatus.Normal) { throw new AUObjectValidationException(AUCommon.DisplayNameFor((AdminUnit)this.Data) + "管理单元的SchemaID无效,无法找到对应的Schema。"); } }); this.PrepareRelationObject(); base.PrepareData(context); var oldObject = (AdminUnit)SCActionContext.Current.OriginalObject; if (oldObject != null && oldObject.AUSchemaID != this.schema.ID) { throw new AUObjectValidationException("一旦创建,不能以任何方式修改AdminUnit的AUSchema属性"); } this.existingSchemaRoles = Adapters.AUSnapshotAdapter.Instance.LoadAUSchemaRoles(schema.ID, false, DateTime.MinValue); this.existingUnitRoles = Adapters.AUSnapshotAdapter.Instance.LoadAURoles(new string[] { this.Data.ID }, new string[0], false, DateTime.MinValue); this.existingUnitScopes = Adapters.AUSnapshotAdapter.Instance.LoadAUScope(this.Data.ID, false, DateTime.MinValue); this.pendingActions.Clear(); PrepareRolesAndScopes(); }
protected void SaveClick(object sender, EventArgs e) { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "ResetSubmitButton", "top.SubmitButton.resetAllStates();", true); if (string.IsNullOrWhiteSpace(this.alterKey.Text) == false) { this.Data.ID = this.alterKey.Text; } try { Util.EnsureOperationSafe(); SchemaObjectBase parent = null; if (string.IsNullOrEmpty(this.currentParentID.Value) == false) { AUCommon.DoDbAction(() => parent = SchemaObjectAdapter.Instance.Load(this.currentParentID.Value)); } Facade.InstanceWithPermissions.DoOperation(this.OperationMode, this.Data, parent); WebUtility.ResponseCloseWindowScriptBlock(); ScriptManager.RegisterClientScriptBlock(this.panelContainer, this.GetType(), "master", "top.window.close();", true); } catch (System.Exception ex) { WebUtility.ShowClientError(ex.GetRealException()); } }
private void PrepareScopesForAdd() { var scopeNames = this.schema.Scopes.Split(AUCommon.Spliter, StringSplitOptions.RemoveEmptyEntries); foreach (string name in scopeNames) { AUAdminScope existingScope = AUCommon.FindMatchScope(this.existingUnitScopes, name); AUAdminScope inputScope = this.InputAdminScopes != null?AUCommon.FindMatchScope(this.InputAdminScopes, name) : null; if (inputScope != null && existingScope != null && inputScope.ID != existingScope.ID) { throw new AUObjectException(string.Format("导入的管理范围{0}与现有管理范围{1}的ID不一致,导致无法继续执行导入。", inputScope.ID, existingScope.ID)); } if (existingScope == null) { if (inputScope == null) { inputScope = new AUAdminScope() { ID = UuidHelper.NewUuidString(), ScopeSchemaType = name } } ; pendingActions.Add(new AddMemberAction((AdminUnit)this.Data, inputScope)); } else if (existingScope.Status != SchemaObjectStatus.Normal) { pendingActions.Add(new EnableMemberAction((AdminUnit)this.Data, existingScope)); } } }
public ClientAURole GetAURoleBySchemaRoleID(string unitID, string schemaRoleID, bool normalOnly) { unitID.NullCheck("unitID"); schemaRoleID.NullCheck("schemaRoleID"); AURole result = null; var unit = AUCommon.DoDbProcess(() => (AdminUnit)SchemaObjectAdapter.Instance.Load(unitID)); if (unit != null && normalOnly) { unit = unit.Status == SchemaObjectStatus.Normal ? unit : null; } if (unit != null) { var schemaRole = (AUSchemaRole)AUCommon.DoDbProcess(() => SchemaObjectAdapter.Instance.Load(schemaRoleID)); if (schemaRole != null && normalOnly) { schemaRole = schemaRole.Status == SchemaObjectStatus.Normal ? schemaRole : null; } if (schemaRole != null) { result = AUSnapshotAdapter.Instance.LoadAURole(schemaRole.ID, unitID, normalOnly, SimpleRequestSoapMessage.Current.TimePoint); } } return(result != null ? (ClientAURole)result.ToClientSchemaObject() : null); }
internal static T GetEffectiveObject <T>(string id, bool normalOnly) where T : SchemaObjectBase { if (id == null) { throw new ArgumentNullException("id"); } T result = null; AUCommon.DoDbAction(() => { result = (T)PC.Adapters.SchemaObjectAdapter.Instance.Load(id); }); if (result == null) { throw new ObjectNotFoundException(string.Format("未找到指定ID:{0} 的 {1} 类型的对象。", id, typeof(T).Name)); } if (normalOnly && result.Status != SchemaObjectStatus.Normal) { throw new ObjectNotFoundException(string.Format("{0} 无效,对象为已经删除。", result is SCBase ? (result as SCBase).ToDescription() : result.ID)); } return(result); }
private string GetUnitFullPath(string unitID) { return(AUCommon.DoDbProcess(() => { var relation = PC.Adapters.SchemaRelationObjectAdapter.Instance.LoadByObjectID(new string[] { unitID }).Where(m => m.ChildSchemaType == AUCommon.SchemaAdminUnit && m.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal && (m.ParentSchemaType == AUCommon.SchemaAdminUnit || m.ParentSchemaType == AUCommon.SchemaAUSchema)).FirstOrDefault(); return relation != null ? relation.FullPath : string.Empty; })); }
/// <summary> /// 根据userID和一组ContainerID,加载该Member所拥有的权限 /// </summary> /// <param name="userID"></param> /// <param name="containerIDs"></param> /// <returns></returns> public SCContainerAndPermissionCollection LoadCurrentContainerAndPermissions(string userID, IEnumerable <string> containerIDs) { var ids = containerIDs.ToArray(); SCContainerAndPermissionCollection result = null; var roleIDs = (from r in new OguUser(userID).Roles.GetAllRoles() select r.ID).ToArray(); if (ids.Length > 0 && roleIDs.Length > 0) { var timeConditon1 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder("A."); var condition = new WhereSqlClauseBuilder(); condition.AppendItem("A.Status", (int)SchemaObjectStatus.Normal); InSqlClauseBuilder inSql = new InSqlClauseBuilder("A.ContainerID"); inSql.AppendItem(ids); InSqlClauseBuilder inSqlRole = new InSqlClauseBuilder("A.MemberID"); inSqlRole.AppendItem(roleIDs); var sql = string.Format( "SELECT A.* FROM SC.Acl_Current A WHERE {0} ORDER BY SortID ", new ConnectiveSqlClauseCollection(timeConditon1, condition, inSql, inSqlRole).ToSqlString(TSqlBuilder.Instance)); result = new SCContainerAndPermissionCollection(); AUCommon.DoDbAction(() => { using (DbContext context = DbContext.GetContext(this.GetConnectionName())) { using (IDataReader reader = DbHelper.RunSqlReturnDR(sql, this.GetConnectionName())) { while (reader.Read()) { string containerID = (string)reader["ContainerID"]; string permission = (string)reader["ContainerPermission"]; if (result.ContainsKey(containerID, permission) == false) { result.Add(new SCContainerAndPermission() { ContainerID = containerID, ContainerPermission = permission }); } } } } }); return(result); } else { result = new SCContainerAndPermissionCollection(); } return(result); }
public ClientSchemaObjectBase[] GetContainers(string id, string[] containerSchemaTypes, bool normalOnly) { id.NullCheck("id"); string[] containers = AUCommon.DoDbProcess(() => SCMemberRelationAdapter.Instance.LoadByMemberID(id, containerSchemaTypes, normalOnly, SimpleRequestSoapMessage.Current.TimePoint).ToContainerIDArray()); return(GetObjectByIDInner(containers, containerSchemaTypes, normalOnly)); }
public ClientSchemaObjectBase[] GetChildren(string id, string[] childSchemaTypes, bool normalOnly) { childSchemaTypes.NullCheck("childSchemaTypes"); string[] childrenIds = AUCommon.DoDbProcess(() => SchemaRelationObjectAdapter.Instance.LoadByParentID(id, normalOnly, SimpleRequestSoapMessage.Current.TimePoint).ToIDArray()); return(GetObjectByIDInner(childrenIds, childSchemaTypes, normalOnly)); }
public ClientSchemaMember[] GetMemberships(string containerID, string[] memberSchemaTypes, bool normalOnly) { containerID.NullCheck("id"); memberSchemaTypes.NullCheck("memberSchemaTypes"); var memberships = AUCommon.DoDbProcess(() => SCMemberRelationAdapter.Instance.LoadByContainerID(containerID, memberSchemaTypes, normalOnly, SimpleRequestSoapMessage.Current.TimePoint)); return(memberships.ToClientSchemaObjectBaseObjectArray <SCSimpleRelationBase, ClientSchemaMember>()); }
public static void ClearUp() { AUCommon.DoDbAction(() => { using (DbContext context = DbContext.GetContext(AUCommon.DBConnectionName)) { DbHelper.RunSql("EXEC SC.ClearAllData", AUCommon.DBConnectionName); } }); }
protected void GenSchemaTable(object sender, EventArgs e) { SchemaDefineCollection schemas = SchemaExtensions.CreateSchemasDefineFromConfiguration(); AUCommon.DoDbAction(() => { using (TransactionScope scope = TransactionScopeFactory.Create()) { schemas.ForEach(schema => SchemaDefineAdapter.Instance.Update(schema)); scope.Complete(); } }); }
protected override void InitializeParent() { var relation = AUCommon.DoDbProcess(() => SchemaRelationObjectAdapter.Instance.LoadByObjectID(this.ObjectID, AUCommon.SchemaAdminUnit).Find(m => m.Status == SchemaObjectStatus.Normal)); if (relation != null) { this.ParentID = relation.ParentID; } else { this.ParentID = string.Empty; } }
/// <summary> /// 断开容器与成员的关系(不影响成员对象) /// </summary> /// <param name="obj"></param> public void ClearContainer(SchemaObjectBase obj) { AUCommon.DoDbAction(() => { var memberRelations = PC.Adapters.SCMemberRelationAdapter.Instance.LoadByContainerID(obj.ID, DateTime.MinValue); foreach (var item in memberRelations) { if (item.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal) { PC.Adapters.SCMemberRelationAdapter.Instance.UpdateStatus(item, Schemas.SchemaProperties.SchemaObjectStatus.Deleted); } } }); }
private static void ValidateCodeName(string codeName, string parentID, ValidationResult result) { if (string.IsNullOrEmpty(codeName)) { result.CodeNameValidationResult = "代码名称不得为空"; result.Passed = false; } else { var codeNameValid = AUCommon.DoDbProcess <bool>(() => CodeNameUniqueValidatorFacade.Validate(codeName, "SomeNewID", AUCommon.SchemaAdminUnit, parentID, false, false, DateTime.MinValue)); result.Passed &= codeNameValid; result.CodeNameValidationResult = codeNameValid ? "通过" : string.Format("指定的代码名称 {0} 已经被其他对象使用,请使用其他名称。", codeName); } }
public ClientSchemaObjectBase[] GetParents(string id, string[] parentSchemaTypes, bool normalOnly) { parentSchemaTypes.NullCheck("parentSchemaTypes"); var parentRelations = AUCommon.DoDbProcess(() => SchemaRelationObjectAdapter.Instance.LoadByObjectID(id, normalOnly == false, SimpleRequestSoapMessage.Current.TimePoint)); string[] ids = new string[parentRelations.Count]; for (int i = 0; i < ids.Length; i++) { ids[i] = parentRelations[i].ParentID; } return(GetObjectByIDInner(ids, parentSchemaTypes, normalOnly)); }
private SCAclContainer PrepareAclContainer(AdminUnit parent, AdminUnit currentData) { SCAclContainer result = null; if (currentData is ISCAclContainer) { result = new SCAclContainer(currentData); if (parent != null) { AUCommon.DoDbAction(() => result.Members.CopyFrom(AUAclAdapter.Instance.LoadByContainerID(parent.ID, DateTime.MinValue))); } } return(result); }
protected void LoadObject(string id) { AUCommon.DoDbAction(() => { this.Data = SchemaObjectAdapter.Instance.Load(id); }); this.sceneAdapter = PropertyEditorSceneAdapter.Create(this.Data.SchemaType); this.sceneAdapter.ObjectID = this.Data.ID; this.sceneAdapter.Mode = SCObjectOperationMode.Update; this.currentSchemaType.Value = this.Data.SchemaType; // this.CurrentSchemaType = this.Data.SchemaType; this.OperationMode = SCObjectOperationMode.Update; }
private static SchemaObjectBase GetUnitParent(AdminUnit unit, bool allowNull) { SchemaObjectBase parent = null; var parentRelaion = unit.GetCurrentVeryParentRelation(); if (parentRelaion != null) { AUCommon.DoDbAction(() => { parent = parentRelaion.Parent; }); } else if (allowNull == false) { throw new AUObjectException("此管理单元没有任何父级,这可能是数据存在错误或此管理单元未添加到系统。"); } return(parent); }
private TCollection LoadSchemaObjects<TKey, TCollection>(string sql) where TCollection : SchemaObjectEditableKeyedCollectionBase<TKey, TCollection>, new() where TKey : SchemaObjectBase { TCollection result = new TCollection(); AUCommon.DoDbAction(() => { using (DbContext context = DbContext.GetContext(this.GetConnectionName())) { result.LoadFromDataView(DbHelper.RunSqlReturnDS(sql, this.GetConnectionName()).Tables[0].DefaultView); } }); return result; }
protected override void PrepareData(AUObjectOperationContext context) { AUCommon.DoDbAction(() => { actualSchemaRole = (AUSchemaRole)SchemaObjectAdapter.Instance.Load(schemaRole.ID); if (actualSchemaRole.Status != Schemas.SchemaProperties.SchemaObjectStatus.Normal) { throw new AUStatusCheckException(actualSchemaRole, this.OperationType); } this.actualUnit = (AdminUnit)SchemaObjectAdapter.Instance.Load(this.unit.ID); if (this.actualUnit == null || this.actualUnit.Status != Schemas.SchemaProperties.SchemaObjectStatus.Normal) { throw new AUStatusCheckException(actualUnit, this.OperationType); } this.actualUnitRole = Adapters.AUSnapshotAdapter.Instance.LoadAURole(actualSchemaRole.ID, actualUnit.ID, true, DateTime.MinValue); if (actualUnitRole == null || actualUnitRole.Status != Schemas.SchemaProperties.SchemaObjectStatus.Normal) { throw new AUStatusCheckException(actualUnitRole, this.OperationType); } var roleMemberRelations = SCMemberRelationAdapter.Instance.LoadByContainerID(this.actualUnitRole.ID); Dictionary <string, SCUser> userDic = users.ToDictionary(m => m.ID); foreach (var item in roleMemberRelations) { if (item.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal) { if (userDic.ContainsKey(item.ID)) { userDic.Remove(item.ID); } else { pendingActions.Add(new RemoveRelationAction(item)); } } } foreach (SCUser user in userDic.Values) { pendingActions.Add(new AddRelationAction(this.actualUnitRole, user)); } }); }
public AUOperationLogCollection Load(IConnectiveSqlClause sqlClause) { AUOperationLogCollection result = null; AUCommon.DoDbAction(() => { VersionedObjectAdapterHelper.Instance.FillData(GetMappingInfo().TableName, sqlClause, this.GetConnectionName(), (view) => { result = new AUOperationLogCollection(); ORMapping.DataViewToCollection(result, view); }); }); return(result); }