public void InitializeContext() { this.textTemplateFile = this.solution.Find<IItem>().First(); this.store.TransactionManager.DoWithinTransaction(() => { var patternModel = this.store.ElementFactory.CreateElement<PatternModelSchema>(); var pattern = patternModel.Create<PatternSchema>(); var view = pattern.CreateViewSchema(); var parent = view.CreateElementSchema(); this.element = parent.CreateAutomationSettingsSchema() as AutomationSettingsSchema; this.settings = element.AddExtension<CommandSettings>(); this.settings.TypeId = typeof(GenerateModelingCodeCommand).Name; ((ICommandSettings)this.settings).Properties.Add(new PropertyBindingSettings { Name = Reflector<GenerateModelingCodeCommand>.GetPropertyName(u => u.TargetFileName) }); ((ICommandSettings)this.settings).Properties.Add(new PropertyBindingSettings { Name = Reflector<GenerateModelingCodeCommand>.GetPropertyName(u => u.TargetPath) }); ((ICommandSettings)this.settings).Properties.Add(new PropertyBindingSettings { Name = Reflector<GenerateModelingCodeCommand>.GetPropertyName(u => u.TemplateAuthoringUri) }); ((ICommandSettings)this.settings).Properties.Add(new PropertyBindingSettings { Name = Reflector<GenerateModelingCodeCommand>.GetPropertyName(u => u.TemplateUri) }); }); this.serviceProvider = new Mock<IServiceProvider>(); this.uriService = new Mock<IUriReferenceService>(); this.serviceProvider.Setup(sp => sp.GetService(typeof(IUriReferenceService))).Returns(this.uriService.Object); this.validation = new GenerateModelingCodeCommandValidation { serviceProvider = this.serviceProvider.Object, }; this.validationContext = new ValidationContext(ValidationCategories.Custom, this.settings); }
internal void ValidateTypeIsNotEmpty(ValidationContext context, CommandSettings settings) { Guard.NotNull(() => context, context); Guard.NotNull(() => settings, settings); try { // Ensure not empty if (string.IsNullOrEmpty(settings.TypeId)) { context.LogError( string.Format( CultureInfo.CurrentCulture, Resources.Validate_CommandSettingsTypeIsNotEmpty, settings.Name), Resources.Validate_CommandSettingsTypeIsNotEmptyCode, settings.Extends); } } catch (Exception ex) { tracer.Error( ex, Resources.ValidationMethodFailed_Error, Reflector<CommandSettingsValidations>.GetMethod(n => n.ValidateTypeIsNotEmpty(null, null)).Name); throw; } }
public void InitializeContext() { this.store.TransactionManager.DoWithinTransaction(() => { var patternModel = this.store.ElementFactory.CreateElement<PatternModelSchema>(); this.product = patternModel.Create<PatternSchema>(); var automationSettings = product.Create<AutomationSettingsSchema>(); this.settings = automationSettings.AddExtension<CommandSettings>(); }); validationContext = new ValidationContext(ValidationCategories.Save, this.settings); this.validators = new CommandSettingsValidations(Mock.Of<INuPatternCompositionService>()); }
private static void WritePropertiesAsElements(DslModeling::SerializationContext serializationContext, CommandSettings element, global::System.Xml.XmlWriter writer) { // Properties if (!serializationContext.Result.Failed) { global::System.String propValue = element.Properties; if (!serializationContext.Result.Failed) { if (!string.IsNullOrEmpty(propValue)) LibrarySerializationHelper.Instance.WriteElementString(serializationContext, element, writer, "properties", propValue); } } }
private static void ReadPropertiesFromElements(DslModeling::SerializationContext serializationContext, CommandSettings element, global::System.Xml.XmlReader reader) { while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element) { switch (reader.LocalName) { case "properties": // Properties if (reader.IsEmptyElement) { // No serialized value, must be default one. DslModeling::SerializationUtilities.Skip(reader); // Skip this tag. } else { string strProperties = LibrarySerializationHelper.Instance.ReadElementContentAsString(serializationContext, element, reader); global::System.String valueOfProperties; if (DslModeling::SerializationUtilities.TryGetValue<global::System.String>(serializationContext, strProperties, out valueOfProperties)) { element.Properties = valueOfProperties; } else { // Invalid property value, ignored. LibrarySerializationBehaviorSerializationMessages.IgnoredPropertyValue(serializationContext, reader, "properties", typeof(global::System.String), strProperties); } DslModeling::SerializationUtilities.SkipToNextElement(reader); } break; default: return; // Don't know this element. } } }
internal void ValidateCommands(ValidationContext context, CommandSettings settings) { Guard.NotNull(() => context, context); Guard.NotNull(() => settings, settings); foreach (var validator in Validators[settings.TypeId]) { validator.Value.Validate(context, settings.Extends as IAutomationSettingsSchema, settings); } }