private IAutomationSettingsSchema AssertOnSaveEvent(bool verifySettings, IAutomationSettingsSchema command) { var event1 = this.container.AutomationSettings.FirstOrDefault(set => set.Name.Equals(Properties.Resources.ValidationExtension_OnSaveEventName)); Assert.NotNull(event1); var eventSettings = event1.GetExtensions <IEventSettings>().FirstOrDefault(); Assert.NotNull(eventSettings); if (verifySettings) { Assert.Equal(CustomizationState.False, event1.IsCustomizable); Assert.True(event1.IsSystem); Assert.Equal(eventSettings.EventId, typeof(IOnProductStoreSavedEvent).FullName); var commandSettings = command.GetExtensions <ICommandSettings>().FirstOrDefault(); Assert.NotNull(commandSettings); Assert.Equal(eventSettings.CommandId, commandSettings.Id); } return(event1); }
/// <summary> /// Called when validations are needed for the command /// </summary> /// <param name="context">Validation Context where to add validation errors</param> /// <param name="settingsElement">The settings element in the model being validated</param> /// <param name="settings">Settings for the command</param> public void Validate(Microsoft.VisualStudio.Modeling.Validation.ValidationContext context, IAutomationSettingsSchema settingsElement, ICommandSettings settings) { try { Guard.NotNull(() => settings, settings); var templateValidator = new TemplateValidator(settings.Name, new UnfoldVsTemplateCommand.UnfoldVsTemplateSettings { SanitizeName = settings.GetPropertyValue<bool>(Reflector<UnfoldVsTemplateCommand>.GetPropertyName(u => u.SanitizeName)), SyncName = settings.GetPropertyValue<bool>(Reflector<UnfoldVsTemplateCommand>.GetPropertyName(u => u.SyncName)), TemplateAuthoringUri = settings.GetPropertyValue<string>(Reflector<UnfoldVsTemplateCommand>.GetPropertyName(u => u.TemplateAuthoringUri)), TemplateUri = settings.GetPropertyValue<string>(Reflector<UnfoldVsTemplateCommand>.GetPropertyName(u => u.TemplateUri)), SettingsElement = settingsElement, OwnerElement = settings.Owner, }, context, ((ModelElement)settings).Store); templateValidator.ValidateCommandSettings(tracer); } catch (Exception ex) { tracer.Error( ex, Resources.ValidationMethodFailed_Error, Reflector<TemplateValidator>.GetMethod(n => n.ValidateCommandSettings(null)).Name); throw; } }
private static void LogSolutionItemNotFound(ValidationContext context, IAutomationSettingsSchema settingsElement, ICommandSettings settings) { if (!settings.Owner.Root.PatternModel.IsInTailorMode()) { //item not found error context.LogError( string.Format( CultureInfo.CurrentCulture, Resources.Validate_GenerateModelingCodeAuthoringUriIsInvalid, settings.Name), Resources.Validate_GenerateModelingCodeAuthoringUriIsInvalidCode, settingsElement as ModelElement); } }
/// <summary> /// Called to validate the design-time settings on the custom command /// </summary> /// <param name="context">Validation context to be assigned errors and warnings.</param> /// <param name="settingsElement">The settings element in the model being validated</param> /// <param name="settings">Settings for the command</param> public void Validate(Microsoft.VisualStudio.Modeling.Validation.ValidationContext context, IAutomationSettingsSchema settingsElement, ICommandSettings settings) { try { // TODO: Validate a setting on the command // Note that a propValue1 may still not have a value if it was configured with a ValueProvider. //var propValue1 = settings.GetOrCreatePropertyValue(Reflector<ShowElementTypePicker>.GetPropertyName(s => s.AProperty), String.Empty); //if (String.IsNullOrEmpty(propValue1)) //{ // context.LogError(String.Format(CultureInfo.CurrentCulture, // "{0} is configured with an invalid value for its 'AProperty'. This value must be valid.", settingsElement.Name), "1", settingsElement as ModelElement); //} } catch (Exception ex) { // Make error trace statement for the failure tracer.Error( "Validation rule ShowElementTypePickerValidation unexpectedly failed, error was: '{0}'", ex.Message); throw; } }
private IAutomationSettingsSchema AssertOnCustomEvent(bool verifySettings, IAutomationSettingsSchema command) { var event1 = this.container.AutomationSettings.FirstOrDefault(set => set.Name.Equals(Properties.Resources.ValidationExtension_OnCustomEventName)); Assert.NotNull(event1); var eventSettings = event1.GetExtensions<IEventSettings>().FirstOrDefault(); Assert.NotNull(eventSettings); if (verifySettings) { Assert.Equal(CustomizationState.False, event1.IsCustomizable); Assert.True(event1.IsSystem); Assert.Equal(eventSettings.EventId, this.validationExtension.ValidationOnCustomEvent); var commandSettings = command.GetExtensions<ICommandSettings>().FirstOrDefault(); Assert.NotNull(commandSettings); Assert.Equal(eventSettings.CommandId, commandSettings.Id); } return event1; }
/// <summary> /// Called to validate the design-time settings on the custom command /// </summary> /// <param name="context">Validation context to be assigned errors and warnings.</param> /// <param name="settingsElement">The settings element in the model being validated</param> /// <param name="settings">Settings for the command</param> public void Validate(Microsoft.VisualStudio.Modeling.Validation.ValidationContext context, IAutomationSettingsSchema settingsElement, ICommandSettings settings) { try { // TODO: Validate a setting on the command // Note that a propValue1 may still not have a value if it was configured with a ValueProvider. //var propValue1 = settings.GetOrCreatePropertyValue(Reflector<ShowEventSubscriptionPicker>.GetPropertyName(s => s.AProperty), String.Empty); //if (String.IsNullOrEmpty(propValue1)) //{ // context.LogError(String.Format(CultureInfo.CurrentCulture, // "{0} is configured with an invalid value for its 'AProperty'. This value must be valid.", settingsElement.Name), "1", settingsElement as ModelElement); //} } catch (Exception ex) { // Make error trace statement for the failure tracer.Error( "Validation rule ShowEventSubscriptionPickerValidation unexpectedly failed, error was: '{0}'", ex.Message); throw; } }
/// <summary> /// Called when validations are needed for the command /// </summary> /// <param name="context">Validation Context where to add validation errors</param> /// <param name="settingsElement">The settings element in the model being validated</param> /// <param name="settings">Settings for the command</param> public virtual void Validate(ValidationContext context, IAutomationSettingsSchema settingsElement, ICommandSettings settings) { Guard.NotNull(() => context, context); Guard.NotNull(() => settings, settings); try { var authoringUriString = settings.GetPropertyValue <string>(Reflector <GenerateModelingCodeCommand> .GetPropertyName(u => u.TemplateAuthoringUri)); if (!string.IsNullOrEmpty(authoringUriString)) { var authoringUri = new Uri(authoringUriString); var uriService = serviceProvider.GetService <IUriReferenceService>(); IItem item = null; try { item = uriService.ResolveUri <IItemContainer>(authoringUri).As <IItem>(); } catch (NotSupportedException) { LogSolutionItemNotFound(context, settingsElement, settings); return; } catch (UriFormatException) { LogSolutionItemNotFound(context, settingsElement, settings); 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; } }
/// <summary> /// Called when validations are needed for the command /// </summary> /// <param name="context">Validation Context where to add validation errors</param> /// <param name="settingsElement">The settings element in the model being validated</param> /// <param name="settings">Settings for the command</param> public void Validate(Microsoft.VisualStudio.Modeling.Validation.ValidationContext context, IAutomationSettingsSchema settingsElement, ICommandSettings settings) { try { Guard.NotNull(() => settings, settings); var templateValidator = new TemplateValidator(settings.Name, new UnfoldVsTemplateCommand.UnfoldVsTemplateSettings { SanitizeName = settings.GetPropertyValue <bool>(Reflector <UnfoldVsTemplateCommand> .GetPropertyName(u => u.SanitizeName)), SyncName = settings.GetPropertyValue <bool>(Reflector <UnfoldVsTemplateCommand> .GetPropertyName(u => u.SyncName)), TemplateAuthoringUri = settings.GetPropertyValue <string>(Reflector <UnfoldVsTemplateCommand> .GetPropertyName(u => u.TemplateAuthoringUri)), TemplateUri = settings.GetPropertyValue <string>(Reflector <UnfoldVsTemplateCommand> .GetPropertyName(u => u.TemplateUri)), SettingsElement = settingsElement, OwnerElement = settings.Owner, }, context, ((ModelElement)settings).Store); templateValidator.ValidateCommandSettings(tracer); } catch (Exception ex) { tracer.Error( ex, Resources.ValidationMethodFailed_Error, Reflector <TemplateValidator> .GetMethod(n => n.ValidateCommandSettings(null)).Name); throw; } }
/// <summary> /// Called when validations are needed for the command /// </summary> /// <param name="context">Validation Context where to add validation errors</param> /// <param name="settingsElement">The settings element in the model being validated</param> /// <param name="settings">Settings for the command</param> public virtual void Validate(ValidationContext context, IAutomationSettingsSchema settingsElement, ICommandSettings settings) { Guard.NotNull(() => context, context); Guard.NotNull(() => settings, settings); try { var authoringUriString = settings.GetPropertyValue<string>(Reflector<GenerateModelingCodeCommand>.GetPropertyName(u => u.TemplateAuthoringUri)); if (!string.IsNullOrEmpty(authoringUriString)) { var authoringUri = new Uri(authoringUriString); var uriService = serviceProvider.GetService<IUriReferenceService>(); IItem item = null; try { item = uriService.ResolveUri<IItemContainer>(authoringUri).As<IItem>(); } catch (NotSupportedException) { LogSolutionItemNotFound(context, settingsElement, settings); return; } catch (UriFormatException) { LogSolutionItemNotFound(context, settingsElement, settings); 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; } }