本文整理汇总了C#中ValidationContext.LogWarning方法的典型用法代码示例。如果您正苦于以下问题:C# ValidationContext.LogWarning方法的具体用法?C# ValidationContext.LogWarning怎么用?C# ValidationContext.LogWarning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ValidationContext
的用法示例。
在下文中一共展示了ValidationContext.LogWarning方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidateCustomizedSettingsOverriddenByCustomizableState
internal void ValidateCustomizedSettingsOverriddenByCustomizableState(ValidationContext context)
{
try
{
if (this.IsCustomizationEnabled)
{
if ((this.IsCustomizable == CustomizationState.False)
&& (this.Policy.IsModified == true))
{
context.LogWarning(
string.Format(CultureInfo.CurrentCulture, Properties.Resources.Validate_CustomizedSettingsOverriddenByCustomizableState, this.Name),
Properties.Resources.Validate_CustomizedSettingsOverriddenByCustomizableStateCode, this);
}
}
}
catch (Exception ex)
{
tracer.Error(
ex,
Resources.ValidationMethodFailed_Error,
Reflector<CustomizableElementSchemaBase>.GetMethod(n => n.ValidateCustomizedSettingsOverriddenByCustomizableState(context)).Name);
throw;
}
}
示例2: Validate
public static void Validate(ValidationElementState state, ValidationContext context, ModelElement currentElement)
{
Guard.ArgumentNotNull(context, "context");
Guard.ArgumentNotNull(currentElement, "currentElement");
if (ShouldAbortValidation(context))
{
return;
}
try
{
InitializeFactory(context);
if (validatorFactory != null)
{
DoValidate(currentElement, context, CommonRuleSet);
DoValidate(currentElement, context, context.Categories.ToString());
ShowStatus(currentElement);
return;
}
// trace when no config service
context.LogWarning(Resources.NoValidationServiceAvailable, Constants.ValidationCode, currentElement);
}
catch (Exception ex)
{
context.LogFatal(LogEntry.ErrorMessageToString(ex), Constants.ValidationCode, currentElement);
Trace.TraceError(ex.ToString());
}
}
示例3: ValidateValidatorInPrimaryKey
private void ValidateValidatorInPrimaryKey(ValidationContext context)
{
if (KeyType == KeyType.PrimaryKey && IsValidatorSet())
{
context.LogWarning("Validators will be ignored in primary key.",
"AW001ValidateValidatorInPrimaryKeyError", this);
}
}
示例4: ValidateTransitionKey
private void ValidateTransitionKey(ValidationContext context, List<Dialog> dialogs)
{
var q = from d in dialogs
from s in d.States
from t in Transition.GetLinksToPredecessors(s.State)
where d.Initial == s.State
&& t.Key != d.Key
&& !t.CanNavigateBack
select new { t, d };
foreach(var t in q)
{
context.LogWarning(string.Format(Messages.TransitionKeyRename, t.t.Key, t.d.Key), "TransitionKeyRename", t.t);
}
}
示例5: ValidateValidatorInTimestamp
private void ValidateValidatorInTimestamp(ValidationContext context)
{
if (PropertyType == PropertyType.Timestamp && IsValidatorSet())
{
context.LogWarning("Validators will be ignored on timestamp property.",
"AW001ValidateValidatorInTimestampError", this);
}
}
示例6: ValidateNoInstantiationOnProductOnly
internal void ValidateNoInstantiationOnProductOnly(ValidationContext context)
{
try
{
var automationElement = this.Extends as IAutomationSettingsSchema;
var ownerElement = automationElement.Parent as IPatternSchema;
// Ensure not empty
if ((this.CreateElementOnUnfold == false) && (this.UnfoldOnElementCreated == false)
&& (ownerElement == null))
{
context.LogWarning(
string.Format(
CultureInfo.CurrentCulture,
Resources.Validate_TemplateSettingsNoInstantiationOnProductOnly,
this.Name),
Resources.Validate_TemplateSettingsNoInstantiationOnProductOnlyCode, this.Extends);
}
}
catch (Exception ex)
{
tracer.Error(
ex,
Resources.ValidationMethodFailed_Error,
Reflector<TemplateSettings>.GetMethod(n => n.ValidateNoInstantiationOnProductOnly(context)).Name);
throw;
}
}
示例7: ValidateCanResolveNonEmptyConditionsType
internal void ValidateCanResolveNonEmptyConditionsType(ValidationContext context, EventSettings settings)
{
Guard.NotNull(() => context, context);
Guard.NotNull(() => settings, settings);
try
{
var conditions = settings.ConditionSettings;
foreach (var condition in conditions.Where(s =>
!string.IsNullOrEmpty(s.TypeId) &&
s.FindBoundType<ICondition>(Conditions, context) == null))
{
context.LogWarning(string.Format(
CultureInfo.CurrentCulture,
Resources.Validate_CannotResolveType,
condition.TypeId,
settings.Name),
Resources.Validate_CannotResolveTypeCode,
settings.Extends);
}
// TODO: validate value providers for the condition bindings too:
// var conditionBindings = this.Settings.ConditionSettings.Select(x => this.BindingFactory.Create<ICondition>(x)).ToArray();
// then like in the CommandSettings.Validation.cs
}
catch (Exception ex)
{
tracer.Error(
ex,
Properties.Resources.ValidationMethodFailed_Error,
Reflector<EventSettingsValidations>.GetMethod(n => n.ValidateCanResolveNonEmptyConditionsType(null, null)).Name);
throw;
}
}
示例8: ValidateCanResolveNonEmptyEventId
internal void ValidateCanResolveNonEmptyEventId(ValidationContext context, EventSettings settings)
{
Guard.NotNull(() => context, context);
Guard.NotNull(() => settings, settings);
try
{
// Ensure not empty
if (!string.IsNullOrEmpty(settings.EventId) && GetEventType(settings.EventId, context) == null)
{
context.LogWarning(string.Format(
CultureInfo.CurrentCulture,
Resources.Validate_CannotResolveType,
settings.EventId,
settings.Name),
Resources.Validate_CannotResolveTypeCode,
settings.Extends);
}
}
catch (Exception ex)
{
tracer.Error(
ex,
Properties.Resources.ValidationMethodFailed_Error,
Reflector<EventSettingsValidations>.GetMethod(n => n.ValidateCanResolveNonEmptyEventId(null, null)).Name);
throw;
}
}
示例9: Validate
//.........这里部分代码省略.........
return;
}
// Ensure file is configured as 'Content'
if (!(string.Equals(item.Data.ItemType, BuildAction.Content.ToString(), StringComparison.OrdinalIgnoreCase)))
{
context.LogError(
string.Format(
CultureInfo.CurrentCulture,
Resources.Validate_GenerateModelingCodeCommandItemTypeShouldBeSetToContent,
settings.Name),
Resources.Validate_GenerateModelingCodeCommandItemTypeShouldBeSetToContentCode, settingsElement as ModelElement);
}
// Ensure file is 'IncludeInVSIX'
if (!(string.Equals(item.Data.IncludeInVSIX, Boolean.TrueString.ToUpperInvariant(), StringComparison.OrdinalIgnoreCase)))
{
if (String.IsNullOrEmpty(item.Data.IncludeInVSIXAs))
{
context.LogError(
string.Format(
CultureInfo.CurrentCulture,
Resources.Validate_GenerateModelingCodeCommandIIncludeInVSIXShouldBeSetToTrue,
settings.Name),
Resources.Validate_GenerateModelingCodeCommandIIncludeInVSIXShouldBeSetToTrueCode, settingsElement as ModelElement);
}
else
{
// Ensure the 'IncludeInVSIXAs' value matches TemplateUri value
var templateUriString = settings.GetPropertyValue<string>(Reflector<GenerateModelingCodeCommand>.GetPropertyName(u => u.TemplateUri));
if (!String.IsNullOrEmpty(templateUriString))
{
var templateFilename = TextTemplateUri.ParseFileName(new Uri(templateUriString));
if (!templateFilename.Equals(item.Data.IncludeInVSIXAs, StringComparison.OrdinalIgnoreCase))
{
context.LogError(
string.Format(
CultureInfo.CurrentCulture,
Resources.Validate_GenerateModelingCodeCommandIIncludeInVSIXAsShouldBeSameAsFile,
settings.Name),
Resources.Validate_GenerateModelingCodeCommandIIncludeInVSIXAsShouldBeSameAsFileCode, settingsElement as ModelElement);
}
}
}
}
else
{
// Ensure not both 'IncludeInVSIX' and 'IncludeInVSIXAs'
if (!String.IsNullOrEmpty(item.Data.IncludeInVSIXAs))
{
context.LogError(
string.Format(
CultureInfo.CurrentCulture,
Resources.Validate_GenerateModelingCodeCommandIIncludeInVSIXDuplicate,
settings.Name),
Resources.Validate_GenerateModelingCodeCommandIIncludeInVSIXDuplicateCode, settingsElement as ModelElement);
}
}
}
else
{
LogSolutionItemNotFound(context, settingsElement, settings);
return;
}
var targetFilename = settings.GetPropertyValue<string>(Reflector<GenerateModelingCodeCommand>.GetPropertyName(u => u.TargetFileName));
if (string.IsNullOrEmpty(targetFilename))
{
context.LogError(
string.Format(
CultureInfo.CurrentCulture,
Resources.Validate_GenerateModelingCodeCommandTargetFilenameEmpty,
settings.Name),
Resources.Validate_GenerateModelingCodeCommandTargetFilenameEmptyCode, settingsElement as ModelElement);
}
var isConfiguredOnProduct = ((settingsElement.Parent as IPatternSchema) != null);
var targetPath = settings.GetPropertyValue<string>(Reflector<GenerateModelingCodeCommand>.GetPropertyName(u => u.TargetPath));
if ((!string.IsNullOrEmpty(targetPath))
&& (targetPath.StartsWith(PathResolver.ResolveArtifactLinkCharacter, StringComparison.OrdinalIgnoreCase))
&& !isConfiguredOnProduct)
{
context.LogWarning(
string.Format(
CultureInfo.CurrentCulture,
Resources.Validate_GenerateModelingCodeCommandTargetPathStartsWithResolver,
settings.Name, targetPath, PathResolver.ResolveArtifactLinkCharacter),
Resources.Validate_GenerateModelingCodeCommandTargetPathStartsWithResolverCode, settingsElement as ModelElement);
}
}
catch (Exception ex)
{
tracer.Error(
ex,
Resources.ValidationMethodFailed_Error,
Reflector<GenerateModelingCodeCommandValidation>.GetMethod(n => n.Validate(null, null, null)).Name);
throw;
}
}
示例10: ValidateClassName
/// <summary>
/// 类验证
/// </summary>
/// <param name="context"></param>
/// <param name="classModel"></param>
public void ValidateClassName(ValidationContext context, IClass classModel)
{
List<string> attributeNames = new List<string>();
int CountOperation = classModel.OwnedOperations.Count();
if (CountOperation > 0)
{
context.LogWarning(
string.Format("class {0}中存在{1}个方法", classModel.Name, CountOperation),
"001", classModel);
}
if (classModel.OwningPackage == null)
{
context.LogError(
string.Format("class {0}不是在包中", classModel.Name),
"001", classModel);
}
foreach (Microsoft.VisualStudio.Uml.Classes.IProperty attribute in classModel.OwnedAttributes)
{
string name = attribute.Name;
if (!string.IsNullOrEmpty(name) && attributeNames.Contains(name.ToLower()))
{
context.LogError(
string.Format("类 '{0}'中已经存在属性{1}", classModel.Name, name),
"002", classModel);
}
attributeNames.Add(name.ToLower());
}
bool isExistModel = false;
var packages = classModel.GetModelStore().Root.NestedPackages;
foreach (IPackage package in packages)
{
isExistModel = isExistSameName(package, classModel);
if (isExistModel == true)
{
break;
}
}
if (isExistModel)
{
context.LogError(
string.Format("包{0}中的类{1}名称已经被使用,请修改!", classModel.OwningPackage.Name, classModel.Name),
"002", classModel);
}
}
示例11: ValidateDefinitionFeatureModelIsNotSet
public void ValidateDefinitionFeatureModelIsNotSet(ValidationContext context)
{
if (!this.IsReference && !string.IsNullOrEmpty(this.DefinitionFeatureModelFile)) {
context.LogWarning("Since feature '" + this.Name + "' is defined in this feature model, its Definition Feature Model File property is of no use and should be left blank.", "", this);
}
}
示例12: Validate
//.........这里部分代码省略.........
// var check = command.PascalName.ToLower();
// if (nameList.Contains(check))
// context.LogError(string.Format(ValidationHelper.ErrorTextDuplicateName, command.PascalName), string.Empty, command);
// else
// nameList.Add(check);
//}
//Check Composites
foreach (var composite in entity.Composites)
{
var check = composite.PascalName.ToLower();
if (nameList.Contains(check))
context.LogError(string.Format(ValidationHelper.ErrorTextDuplicateName, composite.PascalName), string.Empty, composite);
else
nameList.Add(check);
}
}
//Check Views
foreach (var view in this.Views.Where(x => x.IsGenerated))
{
var check = view.PascalName.ToLower();
if (nameList.Contains(check))
context.LogError(string.Format(ValidationHelper.ErrorTextDuplicateName, view.PascalName), string.Empty, view);
else
nameList.Add(check);
}
//Check Stored Procedures
foreach (var sp in this.StoredProcedures.Where(x => x.IsGenerated))
{
var check = sp.PascalName.ToLower();
if (nameList.Contains(check))
context.LogError(string.Format(ValidationHelper.ErrorTextDuplicateName, sp.PascalName), string.Empty, sp);
else
nameList.Add(check);
}
#endregion
#region Validate OutputTarget
if (!string.IsNullOrEmpty(this.OutputTarget))
{
try
{
var fi = new System.IO.FileInfo(System.IO.Path.Combine(@"c:\", this.OutputTarget));
}
catch (Exception)
{
context.LogError(ValidationHelper.ErrorTextOutputTargetInvalid, string.Empty, this);
}
}
#endregion
#region Tenant
if (this.Entities.Any(x => x.IsTenant))
{
if (!ValidationHelper.ValidCodeIdentifier(this.TenantColumnName))
context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifier, this.TenantColumnName), string.Empty, this);
if (!ValidationHelper.ValidCodeIdentifier(this.TenantPrefix))
context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifier, this.TenantPrefix), string.Empty, this);
}
#endregion
#region Version
if (Convert.ToInt32(this.Version.Split('.').FirstOrDefault()) < 0)
{
context.LogError(ValidationHelper.ErrorTextVersionNegative, string.Empty, this);
}
#endregion
#region CRUD
if (this.UseGeneratedCRUD)
{
context.LogWarning(ValidationHelper.ErrorTextGeneratedCRUD_EF4, string.Empty, this);
}
#endregion
if (string.IsNullOrEmpty(this.StoredProcedurePrefix))
{
context.LogError(ValidationHelper.ErrorTextInvalidStoredProcPrefix, string.Empty, this);
}
}
catch (Exception ex)
{
throw;
}
finally
{
nHydrate.Dsl.Custom.DebugHelper.StopTimer(timer, "Model Validate - Main");
}
}
示例13: ValidateEntities
public void ValidateEntities(ValidationContext context)
{
var timer = nHydrate.Dsl.Custom.DebugHelper.StartTimer();
try
{
#region Check for zero tables
if (this.Entities.Count(x => x.IsGenerated) == 0)
{
context.LogError(ValidationHelper.ErrorTextNoTables, string.Empty, this);
return;
}
#endregion
#region Verify that the name is valid
foreach (var item in this.Entities.Where(x => x.IsGenerated))
{
if (!ValidationHelper.ValidCodeIdentifier(item.PascalName) || !ValidationHelper.ValidEntityName(item.PascalName))
{
context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifier, item.Name), string.Empty, this);
}
foreach (var field in item.Fields)
{
if (!ValidationHelper.ValidCodeIdentifier(field.PascalName))
{
context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifier, field.Name), string.Empty, this);
}
}
}
#endregion
#region Check for duplicate names
var nameList = new Hashtable();
foreach (var table in this.Entities.Where(x => x.IsGenerated))
{
var name = table.Name.ToLower();
if (nameList.ContainsKey(name))
context.LogError(string.Format(ValidationHelper.ErrorTextDuplicateName, table.Name), string.Empty, this);
else
nameList.Add(name, string.Empty);
}
#endregion
#region Check for duplication relationship names
var duplicateList = new Dictionary<string, RelationshipChecker>();
var relationList = this.Store.ElementDirectory.AllElements.Where(x => x is EntityHasEntities).ToList().Cast<EntityHasEntities>();
foreach (var relation in relationList)
{
var childTable = relation.TargetEntity;
var entity = relation.SourceEntity;
var relationFields = this.RelationFields.Where(x => x.RelationID == relation.Id).ToList();
if (childTable != null && entity != null && childTable.IsGenerated && entity.IsGenerated)
{
var key = string.Empty;
if (StringHelper.Match(entity.Name, childTable.Name, true))
{
if (string.Compare(entity.Name, childTable.Name, false) < 0)
key = childTable.Name + "|" + relation.RoleName + "|" + entity.Name;
else
key = entity.Name + "|" + relation.RoleName + "|" + childTable.Name;
}
else
{
if (string.Compare(entity.Name, childTable.Name, false) < 0)
key = entity.Name + "|" + relation.RoleName + "|" + childTable.Name;
else
key = childTable.Name + "|" + relation.RoleName + "|" + entity.Name;
}
if (duplicateList.ContainsKey(key))
{
if (StringHelper.Match(entity.Name, childTable.Name, true))
duplicateList[key].TableList.Add(entity);
else duplicateList[key].TableList.Add(childTable);
}
else
{
var rc = new RelationshipChecker(relation);
if (string.Compare(entity.Name, childTable.Name, true) < 0)
rc.TableList.Add(childTable);
else rc.TableList.Add(entity);
duplicateList.Add(key, rc);
}
//Verify that a FK has an index on it
foreach (var field in relationFields)
{
var targetField = field.GetTargetField(relation);
if (targetField != null)
{
if (!childTable.Indexes.SelectMany(x => x.FieldList.Select(z => z.Id)).Any(x => x == targetField.Id))
context.LogWarning(string.Format(ValidationHelper.ErrorTextFKNeedIndex, childTable.Name + "." + targetField.Name), string.Empty, this);
}
}
}
}
//.........这里部分代码省略.........
示例14: ValidateModules
//.........这里部分代码省略.........
#region Warn that some views are in NO modules
foreach (var item in this.Views.Where(x => x.IsGenerated))
{
if (item.Modules.Count == 0)
{
context.LogError(string.Format(ValidationHelper.ErrorTextModuleItemNotInModule, item.Name), string.Empty, this);
}
}
#endregion
#region Warn that some functions are in NO modules
foreach (var item in this.Functions.Where(x => x.IsGenerated))
{
if (item.Modules.Count == 0)
{
context.LogError(string.Format(ValidationHelper.ErrorTextModuleItemNotInModule, item.Name), string.Empty, this);
}
}
#endregion
#region Verify that if an entity is in a module, at least one PKs is in the module too
foreach (var item in this.Entities.Where(x => x.IsGenerated))
{
if (item.PrimaryKeyFields.Count > 0)
{
foreach (var module in item.Modules)
{
var count = item.PrimaryKeyFields.Count(x => x.Modules.Contains(module));
if (count == 0)
context.LogError(string.Format(ValidationHelper.ErrorTextModuleEntityPKMismatch, item.Name, module.Name), string.Empty, this);
else if (item.PrimaryKeyFields.Count != count)
context.LogWarning(string.Format(ValidationHelper.WarningTextModuleEntityPKMismatch, item.Name, module.Name), string.Empty, this);
//foreach (var field in item.PrimaryKeyFields)
//{
// if (!field.Modules.Contains(module))
// {
// context.LogError(string.Format(ValidationHelper.ErrorTextModuleEntityPKMismatch, item.Name, module.Name), string.Empty, this);
// }
//}
}
}
}
#endregion
#region Validation Relations that are in NO module
foreach (var moduleLink in this.AllRelations.Cast<IModuleLink>().Where(x => !x.Modules.Any()))
{
context.LogWarning(ValidationHelper.WarningTextRelationNotInModule, string.Empty, (Microsoft.VisualStudio.Modeling.ModelElement)moduleLink);
}
#endregion
#region Find relations with parent/child in a module, but the relation is not present
foreach (var moduleLink in this.AllRelations.Cast<IModuleLink>().Where(x => x.Modules.Any()))
{
var relation = (EntityHasEntities)moduleLink;
//Find common modules for parent and child table
var moduleList = relation.ParentEntity.Modules.Intersect(relation.ChildEntity.Modules).ToList();
foreach (var module in moduleList)
{
示例15: Validate
//.........这里部分代码省略.........
#region Computed Column
if (this.IsCalculated)
{
if (this.Formula.Trim() == "")
{
context.LogError(string.Format(ValidationHelper.ErrorTextComputeColumnNoFormula, this.Name), string.Empty, this);
}
if (this.IsPrimaryKey)
{
context.LogError(string.Format(ValidationHelper.ErrorTextComputeColumnNoPK, this.Name), string.Empty, this);
}
}
if (!this.IsCalculated && !string.IsNullOrEmpty(this.Formula))
{
context.LogError(string.Format(ValidationHelper.ErrorTextComputeNonColumnHaveFormula, this.Name), string.Empty, this);
}
#endregion
#region Validate Defaults
if (!string.IsNullOrEmpty(this.Default))
{
if (!this.CanHaveDefault())
{
context.LogError(string.Format(ValidationHelper.ErrorTextColumnCannotHaveDefault, this.Name), string.Empty, this);
}
else if (!this.IsValidDefault())
{
context.LogWarning(string.Format(ValidationHelper.ErrorTextColumnInvalidDefault, this.Name), string.Empty, this);
}
}
#endregion
#region Check Decimals for common error
if (this.DataType == DataTypeConstants.Decimal)
{
if (this.Length == 1)
context.LogError(string.Format(ValidationHelper.ErrorTextDecimalColumnTooSmall, this.Name, this.Length.ToString()), string.Empty, this);
}
#endregion
#region Verify Metadata
var metaKeyList = new List<string>();
foreach (var item in this.FieldMetadata)
{
if (string.IsNullOrEmpty(item.Key) || metaKeyList.Contains(item.Key.ToLower()))
{
context.LogError(ValidationHelper.ErrorTextMetadataInvalid, string.Empty, this);
}
else
{
metaKeyList.Add(item.Key.ToString());
}
}
#endregion