private static RatingScopeCollection ConvertToScopes(Dictionary <string, StudentCollection> stuCollList, ScopeType type) { RatingScopeCollection scopes = new RatingScopeCollection(); foreach (StudentCollection eachStus in stuCollList.Values) { string name = string.Empty; foreach (Student eachStu in eachStus.Values) { if (type == ScopeType.Class) { name = eachStu.ClassName; } else if (type == ScopeType.Dept) { name = eachStu.DeptName; } else if (type == ScopeType.GradeYear) { name = "年級:" + eachStu.GradeYear; } else { throw new ArgumentException("不支援此類型的排名範圍。(" + type.ToString() + ")"); } break; } scopes.Add(new RatingScope(eachStus, type, name)); } return(scopes); }
//TODO: include reference parameter validation public static string Validate(ScopeType scopeType, string[] scopeParameters, string[] referenceParameters) { string errors = ""; var parametersLength = minMaxParametersLength[scopeType.ToString()]; if (scopeParameters.Length < parametersLength.Item1 || scopeParameters.Length > parametersLength.Item2) { errors += "ScopeType {0} must have atleast {1} parameters and no more than {2} but it has {3}".FormatEx(scopeType.ToString(), parametersLength.Item1, parametersLength.Item2, scopeParameters.Length); } if (parametersLength.Item3 && (referenceParameters == null || referenceParameters.Length == 0)) { errors += "ScopeType {0} must havenon empty reference parameters".FormatEx(scopeType.ToString()); } return(errors); }
public Scope GetScope(ScopeType type) { if (Type == type) { return(this); } else if (Parent != null) { return(Parent.GetScope(type)); } else { throw new InternalError($"No scope found with type '{Type.ToString()}'"); } }
private static AttributeT FindAttribute <AttributeT>(ScopeType type) where AttributeT : Attribute { var fieldInfo = typeof(ScopeType).GetField(type.ToString()); var attributes = fieldInfo .GetCustomAttributes(typeof(AttributeT), false) .Cast <AttributeT>(); if (attributes == null) { return(null); } if (!attributes.Any()) { return(null); } return(attributes.First()); }
private static string GetKey(Student eachStudent, ScopeType scopeType) { string key; if (scopeType == ScopeType.Class) { key = eachStudent.RefClassID; } else if (scopeType == ScopeType.Dept) { key = eachStudent.RefDeptID + "_" + eachStudent.GradeYear; } else if (scopeType == ScopeType.GradeYear) { key = eachStudent.GradeYear; } else { throw new ArgumentException("不支援此類型的排名範圍。(" + scopeType.ToString() + ")"); } return(key); }
public bool IsValid(object Instance, ScopeType scopeType, List <string> ErrorMessageList, string Path = "") { string ErrorMessageTemplate = "{0} is {1} for {2} and must not be null or empty."; foreach (PropertyInfo prop in Instance.GetType().GetProperties()) { string PropertyRootPath = $"{Path}.{prop.Name}"; if (PropertyRootPath.StartsWith(".")) { PropertyRootPath = PropertyRootPath.Remove(0, 1); } var attrList = prop.GetCustomAttributes(typeof(RequiredScopeAttribute), true); if (attrList.Count() == 0) { throw new ApplicationException($"The property {PropertyRootPath} of type {Instance.GetType().Name} has no {nameof(RequiredScopeAttribute)}."); } else { var RequiredScopeAttributeOfScopeType = attrList.Cast <RequiredScopeAttribute>().ToList().SingleOrDefault(x => x.Scope == scopeType); if (RequiredScopeAttributeOfScopeType != null) { if (RequiredScopeAttributeOfScopeType.Required == RequiredType.Mandatory) { var type = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType; if (type == typeof(Laboratory)) { Laboratory Laboratory = prop.GetValue(Instance, null) as Laboratory; this.IsValid(Laboratory, scopeType, ErrorMessageList, PropertyRootPath); Laboratory.IsValidConditionalValidation(scopeType, ErrorMessageList, PropertyRootPath); } else if (type == typeof(Address)) { Address Address = prop.GetValue(Instance, null) as Address; this.IsValid(Address, scopeType, ErrorMessageList, PropertyRootPath); Address.IsValidConditionalValidation(scopeType, ErrorMessageList, PropertyRootPath); } else if (type == typeof(Code)) { Code Code = prop.GetValue(Instance, null) as Code; this.IsValid(Code, scopeType, ErrorMessageList, PropertyRootPath); Code.IsValidConditionalValidation(scopeType, ErrorMessageList, PropertyRootPath); } else if (type == typeof(Identifier)) { Identifier Identifier = prop.GetValue(Instance, null) as Identifier; this.IsValid(Identifier, scopeType, ErrorMessageList, PropertyRootPath); Identifier.IsValidConditionalValidation(scopeType, ErrorMessageList, PropertyRootPath); } else if (type == typeof(Name)) { Name Name = prop.GetValue(Instance, null) as Name; this.IsValid(Name, scopeType, ErrorMessageList, PropertyRootPath); Name.IsValidConditionalValidation(scopeType, ErrorMessageList, PropertyRootPath); } else if (type == typeof(Organisation)) { Organisation Organisation = prop.GetValue(Instance, null) as Organisation; this.IsValid(Organisation, scopeType, ErrorMessageList, PropertyRootPath); Organisation.IsValidConditionalValidation(scopeType, ErrorMessageList, PropertyRootPath); } else if (type == typeof(Panel)) { Panel Panel = prop.GetValue(Instance, null) as Panel; this.IsValid(Panel, scopeType, ErrorMessageList, PropertyRootPath); Panel.IsValidConditionalValidation(scopeType, ErrorMessageList, PropertyRootPath); } else if (type == typeof(PathologyReport)) { PathologyReport PathologyReport = prop.GetValue(Instance, null) as PathologyReport; this.IsValid(PathologyReport, scopeType, ErrorMessageList, PropertyRootPath); PathologyReport.IsValidConditionalValidation(scopeType, ErrorMessageList, PropertyRootPath); } else if (type == typeof(PathologyReportContainer)) { PathologyReportContainer PathologyReportContainer = prop.GetValue(Instance, null) as PathologyReportContainer; this.IsValid(PathologyReportContainer, scopeType, ErrorMessageList, PropertyRootPath); PathologyReportContainer.IsValidConditionalValidation(scopeType, ErrorMessageList, PropertyRootPath); } else if (type == typeof(Patient)) { Patient Patient = prop.GetValue(Instance, null) as Patient; this.IsValid(Patient, scopeType, ErrorMessageList, PropertyRootPath); Patient.IsValidConditionalValidation(scopeType, ErrorMessageList, PropertyRootPath); } else if (type == typeof(Provider)) { Provider Provider = prop.GetValue(Instance, null) as Provider; this.IsValid(Provider, scopeType, ErrorMessageList, PropertyRootPath); Provider.IsValidConditionalValidation(scopeType, ErrorMessageList, PropertyRootPath); } else if (type == typeof(Report)) { Report Report = prop.GetValue(Instance, null) as Report; this.IsValid(Report, scopeType, ErrorMessageList, PropertyRootPath); Report.IsValidConditionalValidation(scopeType, ErrorMessageList, PropertyRootPath); } else if (type == typeof(ReportType)) { ReportType ReportType = prop.GetValue(Instance, null) as ReportType; this.IsValid(ReportType, scopeType, ErrorMessageList, PropertyRootPath); ReportType.IsValidConditionalValidation(scopeType, ErrorMessageList, PropertyRootPath); } else if (type == typeof(Request)) { Request Request = prop.GetValue(Instance, null) as Request; this.IsValid(Request, scopeType, ErrorMessageList, PropertyRootPath); Request.IsValidConditionalValidation(scopeType, ErrorMessageList, PropertyRootPath); } else if (type == typeof(Result)) { Result Result = prop.GetValue(Instance, null) as Result; this.IsValid(Result, scopeType, ErrorMessageList, PropertyRootPath); Result.IsValidConditionalValidation(scopeType, ErrorMessageList, PropertyRootPath); } else if (type == typeof(ResultType)) { ResultType ResultType = prop.GetValue(Instance, null) as ResultType; this.IsValid(ResultType, scopeType, ErrorMessageList, PropertyRootPath); ResultType.IsValidConditionalValidation(scopeType, ErrorMessageList, PropertyRootPath); } else if (type == typeof(string)) { string Value = prop.GetValue(Instance, null) as string; if (string.IsNullOrWhiteSpace(Value)) { ErrorMessageList.Add(String.Format(ErrorMessageTemplate, PropertyRootPath, RequiredScopeAttributeOfScopeType.Required.ToString().ToLower(), scopeType.ToString())); } } else if (type == typeof(DateTime)) { string DateTimeString = prop.GetValue(Instance, null).ToString(); if (string.IsNullOrWhiteSpace(DateTimeString)) { ErrorMessageList.Add(String.Format(ErrorMessageTemplate, PropertyRootPath, RequiredScopeAttributeOfScopeType.Required.ToString().ToLower(), scopeType.ToString())); } } else if (type == typeof(DateTimeOffset)) { string DateTimeString = prop.GetValue(Instance, null).ToString(); if (string.IsNullOrWhiteSpace(DateTimeString)) { ErrorMessageList.Add(String.Format(ErrorMessageTemplate, PropertyRootPath, RequiredScopeAttributeOfScopeType.Required.ToString().ToLower(), scopeType.ToString())); } } else if (type.IsEnum) { string EnumValueString = prop.GetValue(Instance, null).ToString(); if (string.IsNullOrWhiteSpace(EnumValueString)) { ErrorMessageList.Add(String.Format(ErrorMessageTemplate, PropertyRootPath, RequiredScopeAttributeOfScopeType.Required.ToString().ToLower(), scopeType.ToString())); } } else if (type.GetTypeInfo().GenericTypeArguments[0] == typeof(Address)) { List <Address> AddressList = prop.GetValue(Instance, null) as List <Address>; for (int i = 0; i < AddressList.Count; i++) { string LoopPropertyRootPath = $"{PropertyRootPath}[{i.ToString()}]"; this.IsValid(AddressList[i], scopeType, ErrorMessageList, LoopPropertyRootPath); AddressList[i].IsValidConditionalValidation(scopeType, ErrorMessageList, LoopPropertyRootPath); } } else if (type.GetTypeInfo().GenericTypeArguments[0] == typeof(Identifier)) { List <Identifier> IdentifierList = prop.GetValue(Instance, null) as List <Identifier>; for (int i = 0; i < IdentifierList.Count; i++) { string LoopPropertyRootPath = $"{PropertyRootPath}[{i.ToString()}]"; this.IsValid(IdentifierList[i], scopeType, ErrorMessageList, LoopPropertyRootPath); IdentifierList[i].IsValidConditionalValidation(scopeType, ErrorMessageList, LoopPropertyRootPath); } } else if (type.GetTypeInfo().GenericTypeArguments[0] == typeof(Report)) { List <Report> ReportList = prop.GetValue(Instance, null) as List <Report>; for (int i = 0; i < ReportList.Count; i++) { string LoopPropertyRootPath = $"{PropertyRootPath}[{i.ToString()}]"; this.IsValid(ReportList[i], scopeType, ErrorMessageList, LoopPropertyRootPath); ReportList[i].IsValidConditionalValidation(scopeType, ErrorMessageList, LoopPropertyRootPath); } } else if (type.GetTypeInfo().GenericTypeArguments[0] == typeof(Result)) { List <Result> ResultList = prop.GetValue(Instance, null) as List <Result>; for (int i = 0; i < ResultList.Count; i++) { string LoopPropertyRootPath = $"{PropertyRootPath}[{i.ToString()}]"; this.IsValid(ResultList[i], scopeType, ErrorMessageList, LoopPropertyRootPath); ResultList[i].IsValidConditionalValidation(scopeType, ErrorMessageList, LoopPropertyRootPath); } } else { throw new ApplicationException($"Type of {type.Name} has not validation routine."); } } } else { throw new ApplicationException($"The property {Path}{prop.Name} of type {Instance.GetType().Name} has no {nameof(RequiredScopeAttribute)} of the {nameof(ScopeType)} of {scopeType.ToString()}."); } } } return(ErrorMessageList.Count == 0); }
public override string ToString() { return(string.Format("{0} reg: {1} symbol: {2} {3}", _type.ToString(), _regByName.Count, _symbolByName.Count, _defpos)); }
public static IScope CreateScope(ScopeType scopeType, params string[] scopeParameters) { var type = FindScopeType(scopeType.ToString()); return (IScope) Activator.CreateInstance(type, scopeParameters); }
protected override void ValidateRead(List <ValidationError> errors) { base.ValidateRead(errors); ADObjectId adobjectId = (null != base.OrganizationId) ? base.OrganizationId.ConfigurationUnit : null; if (this.User == null) { errors.Add(new PropertyValidationError(DirectoryStrings.UserIsMandatoryInRoleAssignment(this.Identity.ToString()), ExchangeRoleAssignmentSchema.User, null)); } else if (adobjectId != null && this.User.IsDescendantOf(adobjectId) && this.RoleAssigneeType != RoleAssigneeType.RoleAssignmentPolicy) { errors.Add(new PropertyValidationError(DirectoryStrings.WrongAssigneeTypeForPolicyOrPartnerApplication(this.Identity.ToString()), ExchangeRoleAssignmentSchema.User, null)); } if (this.RoleAssigneeType == RoleAssigneeType.RoleAssignmentPolicy && this.RoleAssignmentDelegationType != RoleAssignmentDelegationType.Regular) { errors.Add(new PropertyValidationError(DirectoryStrings.WrongDelegationTypeForPolicy(this.Identity.ToString()), ExchangeRoleAssignmentSchema.User, null)); } if (this.Role == null) { errors.Add(new PropertyValidationError(DirectoryStrings.RoleIsMandatoryInRoleAssignment(this.Identity.ToString()), ExchangeRoleAssignmentSchema.Role, null)); } ScopeType recipientWriteScope = (ScopeType)this.RecipientWriteScope; if (this.RecipientReadScope != recipientWriteScope && !RbacScope.IsScopeTypeSmaller(recipientWriteScope, this.RecipientReadScope)) { errors.Add(new ObjectValidationError(DirectoryStrings.RecipientWriteScopeNotLessThan(recipientWriteScope.ToString(), this.RecipientReadScope.ToString()), this.Identity, base.OriginatingServer)); } ScopeType configWriteScope = (ScopeType)this.ConfigWriteScope; if (this.ConfigReadScope != configWriteScope && !RbacScope.IsScopeTypeSmaller(configWriteScope, this.ConfigReadScope)) { errors.Add(new ObjectValidationError(DirectoryStrings.ConfigScopeNotLessThan(configWriteScope.ToString(), this.ConfigReadScope.ToString()), this.Identity, base.OriginatingServer)); } bool flag = this.CustomRecipientWriteScope == null || (string.IsNullOrEmpty(this.CustomRecipientWriteScope.DistinguishedName) && this.CustomRecipientWriteScope.ObjectGuid == Guid.Empty); RecipientWriteScopeType recipientWriteScope2 = this.RecipientWriteScope; switch (recipientWriteScope2) { case RecipientWriteScopeType.OU: case RecipientWriteScopeType.CustomRecipientScope: break; default: if (recipientWriteScope2 != RecipientWriteScopeType.ExclusiveRecipientScope) { if (!flag) { errors.Add(new ObjectValidationError(DirectoryStrings.CustomRecipientWriteScopeMustBeEmpty(this.RecipientWriteScope), this.Identity, base.OriginatingServer)); goto IL_25C; } goto IL_25C; } break; } if (flag) { errors.Add(new ObjectValidationError(DirectoryStrings.CustomRecipientWriteScopeCannotBeEmpty(this.RecipientWriteScope), this.Identity, base.OriginatingServer)); } if (this.RoleAssignmentDelegationType == RoleAssignmentDelegationType.DelegatingOrgWide) { errors.Add(new ObjectValidationError(DirectoryStrings.OrgWideDelegatingWriteScopeMustBeTheSameAsRoleImplicitWriteScope(this.RecipientWriteScope), this.Identity, base.OriginatingServer)); } IL_25C: bool flag2 = this.CustomConfigWriteScope == null || (string.IsNullOrEmpty(this.CustomConfigWriteScope.DistinguishedName) && this.CustomConfigWriteScope.ObjectGuid == Guid.Empty); switch (this.ConfigWriteScope) { case ConfigWriteScopeType.CustomConfigScope: case ConfigWriteScopeType.PartnerDelegatedTenantScope: case ConfigWriteScopeType.ExclusiveConfigScope: if (flag2) { errors.Add(new ObjectValidationError(DirectoryStrings.ConfigScopeCannotBeEmpty(this.ConfigWriteScope), this.Identity, base.OriginatingServer)); } if (this.RoleAssignmentDelegationType == RoleAssignmentDelegationType.DelegatingOrgWide) { errors.Add(new ObjectValidationError(DirectoryStrings.OrgWideDelegatingConfigScopeMustBeTheSameAsRoleImplicitWriteScope(this.ConfigWriteScope), this.Identity, base.OriginatingServer)); return; } return; } if (!flag2) { errors.Add(new ObjectValidationError(DirectoryStrings.ConfigScopeMustBeEmpty(this.ConfigWriteScope), this.Identity, base.OriginatingServer)); } }
/// <summary> /// 获取授权跳转链接地址 /// </summary> /// <param name="appId"></param> /// <param name="redirectUrl"></param> /// <param name="scope"></param> /// <param name="state"></param> /// <returns></returns> public string GetOAuthUrl(string redirectUrl, ScopeType scope, string state) { return(string.Format(authUrl, Setting.AppID, redirectUrl, scope.ToString(), state)); }
/// <summary> /// 引导用户授权的地址 /// </summary> /// <param name="st"></param> /// <returns></returns> public static string GetOAuthByScopeType(ScopeType st) { try { string url= string.Format(ReadCacheIfNullWriteBeforeWrite("GoToOauth2Url"), AppID, Oauth2RedirectUrl, st.ToString()); //LogHelper.WriteInfo(url); return url; } catch (Exception ex) { LogHelper.WriteFatal(ex.Message); throw ex; } }