internal void ValidateCommandIdAndWizardIdIsNotEmpty(ValidationContext context, EventSettings settings)
        {
            Guard.NotNull(() => context, context);
            Guard.NotNull(() => settings, settings);

            try
            {
                // Ensure not empty
                if (settings.CommandId == Guid.Empty && settings.WizardId == Guid.Empty)
                {
                    context.LogError(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            Resources.Validate_EventSettingsCommandIdAndWizardIdIsNotEmpty,
                            settings.Name),
                        Resources.Validate_EventSettingsCommandIdAndWizardIdIsNotEmptyCode, settings.Extends);
                }
            }
            catch (Exception ex)
            {
                tracer.Error(
                    ex,
                    Resources.ValidationMethodFailed_Error,
                    Reflector<EventSettingsValidations>.GetMethod(n => n.ValidateCommandIdAndWizardIdIsNotEmpty(null, null)).Name);

                throw;
            }
        }
 public void Initialize()
 {
     this.store.TransactionManager.DoWithinTransaction(() =>
     {
         var patternModel = this.store.ElementFactory.CreateElement<PatternModelSchema>();
         var pattern = patternModel.Create<PatternSchema>();
         var automationSettings = pattern.Create<AutomationSettingsSchema>();
         this.settings = automationSettings.AddExtension<EventSettings>();
     });
 }
            public void InitializeContext()
            {
                this.store.TransactionManager.DoWithinTransaction(() =>
                {
                    var patternModel = this.store.ElementFactory.CreateElement<PatternModelSchema>();
                    var pattern = patternModel.Create<PatternSchema>();
                    var automationSettings = pattern.Create<AutomationSettingsSchema>();
                    this.settings = automationSettings.AddExtension<EventSettings>();
                });

                this.validator = new EventSettingsValidations(Mock.Of<INuPatternCompositionService>())
                {
                    ProjectTypeProvider = Mock.Of<INuPatternProjectTypeProvider>(),
                };

                validationContext = new ValidationContext(ValidationCategories.Save, this.settings);
            }
        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;
            }
        }
        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;
            }
        }
        internal void ValidateWizardIdIsValid(ValidationContext context, EventSettings settings)
        {
            Guard.NotNull(() => context, context);
            Guard.NotNull(() => settings, settings);

            try
            {
                if (settings.WizardId != Guid.Empty)
                {
                    if (!settings.Owner.GetAutomationSettings<IWizardSettings>().Any(c => c.Id.Equals(settings.WizardId)))
                    {
                        if (settings.Owner.IsInheritedFromBase &&
                            SettingsValidationHelper.TryToFixId<IWizardSettings>(settings.Store, settings.Owner, settings.WizardId, id => settings.WizardId = id))
                        {
                            return;
                        }

                        context.LogError(
                            string.Format(
                                CultureInfo.CurrentCulture,
                                Resources.Validate_WizardIsNotValid),
                            Resources.Validate_WizardIsNotValidCode, settings.Extends);
                    }
                }
            }
            catch (Exception ex)
            {
                tracer.Error(
                    ex,
                    Properties.Resources.ValidationMethodFailed_Error,
                    Reflector<EventSettingsValidations>.GetMethod(n => n.ValidateWizardIdIsValid(null, null)).Name);

                throw;
            }
        }
Beispiel #7
0
		private static void WritePropertiesAsElements(DslModeling::SerializationContext serializationContext, EventSettings element, global::System.Xml.XmlWriter writer)
		{
			// Conditions
			if (!serializationContext.Result.Failed)
			{
				global::System.String propValue = element.Conditions;
				if (!serializationContext.Result.Failed)
				{
					if (!string.IsNullOrEmpty(propValue))
					LibrarySerializationHelper.Instance.WriteElementString(serializationContext, element, writer, "conditions", propValue);
	
				}
			}
		} 
Beispiel #8
0
		private static void ReadPropertiesFromElements(DslModeling::SerializationContext serializationContext, EventSettings element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				switch (reader.LocalName)
				{
					case "conditions":	// Conditions
						if (reader.IsEmptyElement)
						{	// No serialized value, must be default one.
							DslModeling::SerializationUtilities.Skip(reader);  // Skip this tag.
						}
						else
						{
							string strConditions = LibrarySerializationHelper.Instance.ReadElementContentAsString(serializationContext, element, reader);
							global::System.String valueOfConditions;
							if (DslModeling::SerializationUtilities.TryGetValue<global::System.String>(serializationContext, strConditions, out valueOfConditions))
							{
								element.Conditions = valueOfConditions;
							}
							else
							{	// Invalid property value, ignored.
								LibrarySerializationBehaviorSerializationMessages.IgnoredPropertyValue(serializationContext, reader, "conditions", typeof(global::System.String), strConditions);
							}
	
							DslModeling::SerializationUtilities.SkipToNextElement(reader);
						}
						break;
					default:
						return;  // Don't know this element.
				}
			}
		}
Beispiel #9
0
        internal void ValidateCommandIdAndWizardIdIsNotEmpty(ValidationContext context, EventSettings settings)
        {
            Guard.NotNull(() => context, context);
            Guard.NotNull(() => settings, settings);

            try
            {
                // Ensure not empty
                if (settings.CommandId == Guid.Empty && settings.WizardId == Guid.Empty)
                {
                    context.LogError(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            Resources.Validate_EventSettingsCommandIdAndWizardIdIsNotEmpty,
                            settings.Name),
                        Resources.Validate_EventSettingsCommandIdAndWizardIdIsNotEmptyCode, settings.Extends);
                }
            }
            catch (Exception ex)
            {
                tracer.Error(
                    ex,
                    Resources.ValidationMethodFailed_Error,
                    Reflector <EventSettingsValidations> .GetMethod(n => n.ValidateCommandIdAndWizardIdIsNotEmpty(null, null)).Name);

                throw;
            }
        }
Beispiel #10
0
        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;
            }
        }