Exemple #1
0
        public static SchemaObjectBase ToSchemaObject(this ClientSchemaObjectBase clientObj, bool validateID)
        {
            clientObj.NullCheck("clientObj");
            clientObj.SchemaType.CheckStringIsNullOrEmpty("SchemaType");

            var config             = SchemaDefine.GetSchemaConfig(clientObj.SchemaType);
            SchemaObjectBase scObj = (SchemaObjectBase)config.CreateInstance();

            scObj.ID = clientObj.ID;

            if (validateID && clientObj.ID.IsNullOrEmpty())
            {
                throw new InvalidOperationException("客户端对象ID不存在");
            }

            scObj.Status           = (SchemaObjectStatus)clientObj.Status;
            scObj.CreateDate       = clientObj.CreateDate;
            scObj.VersionStartTime = clientObj.VersionStartTime;
            scObj.VersionEndTime   = clientObj.VersionEndTime;

            scObj.Properties.CopyFrom(clientObj.Properties);

            if (clientObj.Creator != null)
            {
                scObj.Creator = (IUser)OguBase.CreateWrapperObject(clientObj.Creator.ID, SchemaType.Users);
            }

            return(scObj);
        }
Exemple #2
0
        /// <summary>
        /// 解除某人的秘书关系
        /// </summary>
        /// <param name="secretary"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public SCSecretaryRelation RemoveSecretaryFromUser(SCUser secretary, SCUser user)
        {
            SCMemberRelativeExecutor executor = new SCMemberRelativeExecutor(SCOperationType.RemoveSecretaryFromUser, user, secretary)
            {
                OverrideExistedRelation = true, NeedStatusCheck = this.NeedValidationAndStatusCheck, NeedContainerStatusCheck = this.NeedValidationAndStatusCheck
            };

            if (this._NeedCheckPermissions)
            {
                var hereParents  = secretary.CurrentParentRelations;
                var thereParents = user.CurrentParentRelations;
                var hereIds      = (from p in hereParents where p.Status == SchemaObjectStatus.Normal select p.ParentID).ToArray();
                var thereIds     = (from p in thereParents where p.Status == SchemaObjectStatus.Normal select p.ParentID).ToArray();

                CheckPermissions(SCOperationType.RemoveSecretaryFromUser, SchemaDefine.GetSchema("Organizations"), "UpdateChildren", hereIds);
                CheckPermissions(SCOperationType.RemoveSecretaryFromUser, SchemaDefine.GetSchema("Organizations"), "UpdateChildren", thereIds);
            }
            executor.Relation.Status = SchemaObjectStatus.Deleted;

            SCSecretaryRelation result = null;

            ExecuteWithActions(SCOperationType.RemoveSecretaryFromUser, () => SCActionContext.Current.DoActions(() => result = (SCSecretaryRelation)executor.Execute()));

            return(result);
        }
        public static void Output(this SchemaDefine schema, TextWriter writer, int indent = 0)
        {
            string indentChars = new string('\t', indent);

            writer.WriteLine("{0}Schema Name={1}", indentChars, schema.Name);

            if (schema.Properties.Count > 0)
            {
                indent++;

                WriteLine(writer, "Begin Schemas", indent);

                indent++;
                schema.Properties.ForEach(pd => pd.Output(writer, indent));
                indent--;

                WriteLine(writer, "End Schemas", indent);
            }

            if (schema.PermissionSet.Count > 0)
            {
                indent++;

                WriteLine(writer, "Begin PermissionSet", indent);

                indent++;
                schema.PermissionSet.ForEach(pd => pd.Output(writer, indent));
                indent--;

                WriteLine(writer, "End PermissionSet", indent);
            }
        }
Exemple #4
0
 private void CheckPermissions(SCOperationType opType, SchemaDefine schemaInfo, string permissionName, params string[] containerIDs)
 {
     if (NeedCheckPermissionAndCurrentUserIsNotSupervisor && DeluxePrincipal.Current.HasPermissions(permissionName, containerIDs) == false)
     {
         throw SCAclPermissionCheckException.CreateException(opType, schemaInfo, permissionName);
     }
 }
Exemple #5
0
        /// <summary>
        /// 根据模式类型,查询ID类型和ID和时间点检索对象
        /// </summary>
        /// <param name="schemaType">表示模式类型的字符串</param>
        /// <param name="idType">表示ID类型的<see cref="SnapshotQueryIDType"/>值之一</param>
        /// <param name="id">对象的ID</param>
        /// <param name="timePoint"></param>
        /// <returns></returns>
        public SchemaObjectBase LoadByID(string schemaType, SnapshotQueryIDType idType, string id, DateTime timePoint)
        {
            schemaType.CheckStringIsNullOrEmpty("schemaType");
            id.CheckStringIsNullOrEmpty("id");

            SchemaDefine schema = SchemaDefine.GetSchema(schemaType);

            var timeConditon = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint, "SN.");

            WhereSqlClauseBuilder whereBuilder = new WhereSqlClauseBuilder();

            EnumItemDescriptionAttribute attr = EnumItemDescriptionAttribute.GetAttribute(idType);

            whereBuilder.AppendItem("SN." + attr.ShortName, id);

            string sql = string.Format("SELECT SO.* FROM SC.SchemaObject SO INNER JOIN {0} SN ON SO.ID = SN.ID WHERE {1}",
                                       schema.SnapshotTable, new ConnectiveSqlClauseCollection(whereBuilder, timeConditon).ToSqlString(TSqlBuilder.Instance));

            DataTable table = DbHelper.RunSqlReturnDS(sql, this.GetConnectionName()).Tables[0];

            SchemaObjectBase result = null;

            if (table.Rows.Count > 0)
            {
                result = SchemaExtensions.CreateObject(schemaType);

                result.FromString((string)table.Rows[0]["Data"]);
                ORMapping.DataRowToObject(table.Rows[0], result);
            }

            return(result);
        }
Exemple #6
0
        /// <summary>
        /// 设置用户的默认组织
        /// </summary>
        /// <param name="user"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        public SCRelationObject SetUserDefaultOrganization(SCUser user, SCOrganization parent)
        {
            SCOrganizationRelativeExecutor executor =
                new SCOrganizationRelativeExecutor(SCOperationType.SetUserDefaultOrganization, parent, user)
            {
                OverrideExistedRelation = true, OverrideDefault = true, NeedStatusCheck = this.NeedValidationAndStatusCheck, NeedParentStatusCheck = this.NeedValidationAndStatusCheck
            };

            SCRelationObject result = executor.Relation;

            if (executor.RelationExisted)
            {
                if (this._NeedCheckPermissions)
                {
                    var currentDefault = user.CurrentParentRelations.Where(r => r.Default && r.Status == SchemaObjectStatus.Normal).FirstOrDefault();
                    if (currentDefault != null)
                    {
                        CheckPermissions(SCOperationType.SetUserDefaultOrganization, SchemaDefine.GetSchema("Organizations"), "UpdateChildren", currentDefault.ParentID);
                    }

                    CheckPermissions(SCOperationType.SetUserDefaultOrganization, SchemaDefine.GetSchema("Organizations"), "UpdateChildren", executor.Relation.ParentID);
                }

                executor.Relation.Default = true;
                ExecuteWithActions(SCOperationType.SetUserDefaultOrganization, () => SCActionContext.Current.DoActions(() => result = (SCRelationObject)executor.Execute()));
            }

            return(result);
        }
Exemple #7
0
        /// <summary>
        /// 替换对象的图片属性
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="propertyName"></param>
        /// <param name="image"></param>
        /// <returns></returns>
        public SchemaObjectBase UpdateObjectImageProperty(SchemaObjectBase obj, string propertyName, ImageProperty image)
        {
            SCUpdateObjectImageExecutor executor = new SCUpdateObjectImageExecutor(SCOperationType.UpdateObjectImage, obj, propertyName, image)
            {
                NeedStatusCheck = true
            };

            string ownerID = obj.Properties.GetValue("OwnerID", string.Empty);

            if (ownerID.IsNotEmpty())
            {
                if (this._NeedCheckPermissions)
                {
                    CheckPermissions(SCOperationType.UpdateObjectImage, SchemaDefine.GetSchema("Organizations"), "UpdateChildren", ownerID);
                }
            }
            else
            {
                if (this._NeedCheckPermissions)
                {
                    CheckOrganizationChildrenPermissions(SCOperationType.UpdateObjectImage, "UpdateChildren", obj);
                }
            }

            SchemaObjectBase result = null;

            ExecuteWithActions(SCOperationType.UpdateObjectImage, () => SCActionContext.Current.DoActions(() => result = (SchemaObjectBase)executor.Execute()));

            return(result);
        }
Exemple #8
0
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            string schemaType = Request.QueryString["schemaType"];

            this.lblSchemaName.Text      = schemaType;
            this.propRepeater.DataSource = SchemaDefine.GetSchema(schemaType).Properties;
            this.propRepeater.DataBind();
        }
Exemple #9
0
        public ClientPropertyDefine[] GetSchemaPropertyDefinition(string schemaType)
        {
            var definitions = SchemaDefine.GetSchema(schemaType).Properties;

            ClientPropertyDefine[] results = new ClientPropertyDefine[definitions.Count];

            for (int i = 0; i < results.Length; i++)
            {
                results[i] = definitions[i].ToClientPropertyDefine();
            }

            return(results);
        }
Exemple #10
0
        public SchemaObjectBase DeleteUser(SCUser user, SCOrganization parent, bool deletedByContainer)
        {
            SchemaObjectStatus targetStatus = deletedByContainer ? SchemaObjectStatus.DeletedByContainer : SchemaObjectStatus.Deleted;
            SCOperationType    op           = SCOperationType.None;

            SCExecutorBase executor = null;

            if (parent == null)
            {
                op = SCOperationType.DeleteUser;

                if (this._NeedCheckPermissions)
                {
                    CheckPermissions(op, SchemaDefine.GetSchema("Organizations"), "DeleteChildren", user.OwnerID);
                }

                user.Status = targetStatus;

                executor = new SCObjectExecutor(op, user)
                {
                    NeedDeleteRelations = true, NeedValidation = false, NeedDeleteMemberRelations = this.NeedValidationAndStatusCheck, NeedStatusCheck = this.NeedValidationAndStatusCheck
                };
            }
            else
            {
                op = SCOperationType.RemoveUserFromOrganization;

                if (this._NeedCheckPermissions)
                {
                    CheckPermissions(op, parent.Schema, "DeleteChildren", parent.ID);
                }

                executor = new SCOrganizationRelativeExecutor(op, parent, user)
                {
                    OverrideExistedRelation = true, NeedValidation = false, NeedStatusCheck = this.NeedValidationAndStatusCheck, NeedParentStatusCheck = this.NeedValidationAndStatusCheck
                };

                if (((SCOrganizationRelativeExecutor)executor).Relation != null)
                {
                    ((SCOrganizationRelativeExecutor)executor).Relation.Status = targetStatus;
                }
            }

            SchemaObjectBase result = null;

            ExecuteWithActions(op, () => SCActionContext.Current.DoActions(() => result = (SchemaObjectBase)executor.Execute()));

            return(result);
        }
        public void Prepare(VersionedSchemaObjectBase obj)
        {
            if (obj is SCMemberRelation)
            {
                SCMemberRelation mr = (SCMemberRelation)obj;

                ObjectSchemaConfigurationElement containerConfig = SchemaDefine.GetSchemaConfig(mr.ContainerSchemaType);
                ObjectSchemaConfigurationElement memberConfig    = SchemaDefine.GetSchemaConfig(mr.MemberSchemaType);

                if (containerConfig != null && memberConfig != null)
                {
                    if (containerConfig.IsUsersContainer && memberConfig.IsUsersContainerMember)
                    {
                        SCActionContext.Current.Context["UserAndContainerSnapshotRelation"] = mr;
                    }
                }
            }
        }
Exemple #12
0
        public void Prepare(VersionedSchemaObjectBase obj)
        {
            if (obj is SCMemberRelation)
            {
                SCMemberRelation mr = (SCMemberRelation)obj;

                ObjectSchemaConfigurationElement containerConfig = SchemaDefine.GetSchemaConfig(mr.ContainerSchemaType);
                ObjectSchemaConfigurationElement memberConfig    = SchemaDefine.GetSchemaConfig(mr.MemberSchemaType);

                if (containerConfig != null && memberConfig != null)
                {
                    if (containerConfig.Name == "AUAdminScopes" && memberConfig.Category == "AUScopeItems")
                    {
                        SCActionContext.Current.Context["ItemAndContainerSnapshotRelation"] = mr;
                    }
                }
            }
        }
		/// <summary>
		/// 
		/// </summary>
		/// <param name="opType"></param>
		/// <param name="permissionName"></param>
		public static SCAclPermissionCheckException CreateException(SCOperationType opType, SchemaDefine schemaInfo, string permissionName)
		{
			string opDesp = EnumItemDescriptionAttribute.GetDescription(opType);

			SCAclPermissionItem permissionInfo = schemaInfo.PermissionSet[permissionName];

			string permissionDesp = string.Empty;

			if (permissionInfo != null)
			{
				permissionDesp = permissionInfo.Description;

				if (permissionDesp.IsNullOrEmpty())
					permissionDesp = permissionInfo.Name;
			}

			return new SCAclPermissionCheckException(string.Format("不能执行\"{0}\"操作,您没有\"{0}\"权限", opDesp, permissionDesp));
		}
Exemple #14
0
        public SchemaObjectBase ChangeOwner(SCBase obj, SCOrganization targetOrg)
        {
            SCChangeOwnerExecutor executor = new SCChangeOwnerExecutor(SCOperationType.ChangeOwner, obj, targetOrg)
            {
                NeedStatusCheck = this.NeedValidationAndStatusCheck
            };

            if (this._NeedCheckPermissions)
            {
                CheckPermissions(SCOperationType.ChangeOwner, SchemaDefine.GetSchema("Organizations"), "DeleteChildren", obj.Properties.GetValue("OwnerID", string.Empty));
                CheckPermissions(SCOperationType.ChangeOwner, targetOrg.Schema, "AddChildren", targetOrg.ID);
            }

            SchemaObjectBase result = null;

            ExecuteWithActions(SCOperationType.ChangeOwner, () => SCActionContext.Current.DoActions(() => result = (SchemaObjectBase)executor.Execute()));

            return(result);
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            string schemaType = this.Request["schemaType"];

            this.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            this.scopeRepeater.DataSource = this.Scopes;
            this.scopeRepeater.DataBind();
            this.schemaLabel.InnerText    = this.AUSchemaObject.DisplayName;
            this.schemUnitLabel.InnerText = this.AdminUnitObject.DisplayName;
            string paraPattern = "schemaType=" + schemaType + "&unitId=" + this.AdminUnitObject.ID;

            this.lnkToCondition.NavigateUrl = "AUScopesCondition.aspx?" + paraPattern;
            this.lnkToConst.NavigateUrl     = "AUScopesConst.aspx?" + paraPattern;
            this.lnkToPreview.NavigateUrl   = "AUScopes.aspx?" + paraPattern;
            this.lblSchemaName.Text         = schemaType;
            this.propRepeater.DataSource    = SchemaDefine.GetSchema(schemaType).Properties;
            this.propRepeater.DataBind();
        }
Exemple #16
0
        public void GetSchemaPerformanceTest()
        {
            var schemaElem = ObjectSchemaSettings.GetConfig().Schemas[0];

            Stopwatch sw = new Stopwatch();

            sw.Start();
            try
            {
                for (int i = 0; i < 100000; i++)
                {
                    SchemaDefine schema = SchemaDefine.GetSchema(schemaElem.Name);
                }
            }
            finally
            {
                sw.Stop();

                Console.WriteLine("经过时间{0:#,##0}毫秒", sw.ElapsedMilliseconds);
            }
        }
        /// <summary>
        /// 执行校验
        /// </summary>
        /// <param name="objectToValidate">属性值,这里应该是FullPath的值</param>
        /// <param name="currentObject">属性的容器对象,这里应该是SCRelationObject</param>
        /// <param name="key">属性名,这里应该是FullPath</param>
        /// <param name="validateResults">校验结果</param>
        protected override void DoValidate(object objectToValidate, object currentObject, string key, ValidationResults validateResults)
        {
            SCRelationObject relation = currentObject as SCRelationObject;

            if (relation != null)
            {
                string fullPath = (string)objectToValidate;

                if (fullPath.IsNotEmpty())
                {
                    SchemaDefine schema = SchemaDefine.GetSchema(relation.ChildSchemaType);

                    if (schema.FullPathValidationMethod == SCRelationFullPathValidationMethod.UniqueInParent)
                    {
                        DoFullPathValidate(relation, fullPath, key, validateResults);
                    }
                }

                if (relation.ID == relation.ParentID)
                {
                    RecordValidationResult(validateResults, "无效的关系,此关系的父子对象为同一ID,这是不允许的。", relation, key);
                }
            }
        }
		private void CheckPermissions(SCOperationType opType, SchemaDefine schemaInfo, string permissionName, params string[] containerIDs)
		{
			if (NeedCheckPermissionAndCurrentUserIsNotSupervisor && DeluxePrincipal.Current.HasPermissions(permissionName, containerIDs) == false)
				throw SCAclPermissionCheckException.CreateException(opType, schemaInfo, permissionName);
		}
Exemple #19
0
 protected string GetSchemaName(string key)
 {
     return(SchemaDefine.GetSchemaConfig(key).Description);
 }
Exemple #20
0
        private SCAclPermissionCheckException CreateAclException(AUOperationType opType, SchemaDefine schemaInfo, string permissionName)
        {
            string opDesp = EnumItemDescriptionAttribute.GetDescription(opType);

            SCAclPermissionItem permissionInfo = schemaInfo.PermissionSet[permissionName];

            string permissionDesp = string.Empty;

            if (permissionInfo != null)
            {
                permissionDesp = permissionInfo.Description;

                if (permissionDesp.IsNullOrEmpty())
                {
                    permissionDesp = permissionInfo.Name;
                }
            }

            return(new SCAclPermissionCheckException(string.Format("不能执行\"{0}\"操作,您没有\"{0}\"权限", opDesp, permissionDesp)));
        }