Example #1
0
        internal void ValidateConditionsTypeIsNotEmpty(ValidationContext context, DragDropSettings 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)))
                {
                    context.LogError(
                        string.Format(CultureInfo.CurrentCulture, Resources.Validate_ConditionSettingsTypeIsNotEmpty, settings.Name),
                        Resources.Validate_ConditionSettingsTypeIsNotEmptyCode,
                        settings);
                }

                // 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 <DragDropSettingsValidations> .GetMethod(n => n.ValidateConditionsTypeIsNotEmpty(null, null)).Name);

                throw;
            }
        }
Example #2
0
        internal void ValidateWizardIdIsValid(ValidationContext context, DragDropSettings 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 <DragDropSettingsValidations> .GetMethod(n => n.ValidateWizardIdIsValid(null, null)).Name);

                throw;
            }
        }
        internal void ValidateCommandIdAndWizardIdIsNotEmpty(ValidationContext context, DragDropSettings 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_DragDropSettingsCommandIdAndWizardIdIsNotEmpty,
                            settings.Name),
                        Resources.Validate_DragDropSettingsCommandIdAndWizardIdIsNotEmptyCode, settings.Extends);
                }
            }
            catch (Exception ex)
            {
                tracer.Error(
                    ex,
                    Resources.ValidationMethodFailed_Error,
                    Reflector<DragDropSettingsValidations>.GetMethod(n => n.ValidateCommandIdAndWizardIdIsNotEmpty(null, null)).Name);

                throw;
            }
        }
            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<DragDropSettings>();
                });

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

                validationContext = new ValidationContext(ValidationCategories.Save, this.settings);
            }
Example #5
0
		private static void WritePropertiesAsElements(DslModeling::SerializationContext serializationContext, DragDropSettings element, global::System.Xml.XmlWriter writer)
		{
			// DropConditions
			if (!serializationContext.Result.Failed)
			{
				global::System.String propValue = element.DropConditions;
				if (!serializationContext.Result.Failed)
				{
					if (!string.IsNullOrEmpty(propValue))
					LibrarySerializationHelper.Instance.WriteElementString(serializationContext, element, writer, "dropConditions", propValue);
	
				}
			}
		} 
Example #6
0
		private static void ReadPropertiesFromElements(DslModeling::SerializationContext serializationContext, DragDropSettings element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				switch (reader.LocalName)
				{
					case "dropConditions":	// DropConditions
						if (reader.IsEmptyElement)
						{	// No serialized value, must be default one.
							DslModeling::SerializationUtilities.Skip(reader);  // Skip this tag.
						}
						else
						{
							string strDropConditions = LibrarySerializationHelper.Instance.ReadElementContentAsString(serializationContext, element, reader);
							global::System.String valueOfDropConditions;
							if (DslModeling::SerializationUtilities.TryGetValue<global::System.String>(serializationContext, strDropConditions, out valueOfDropConditions))
							{
								element.DropConditions = valueOfDropConditions;
							}
							else
							{	// Invalid property value, ignored.
								LibrarySerializationBehaviorSerializationMessages.IgnoredPropertyValue(serializationContext, reader, "dropConditions", typeof(global::System.String), strDropConditions);
							}
	
							DslModeling::SerializationUtilities.SkipToNextElement(reader);
						}
						break;
					default:
						return;  // Don't know this element.
				}
			}
		}
Example #7
0
        internal void ValidateCommandIdAndWizardIdIsNotEmpty(ValidationContext context, DragDropSettings 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_DragDropSettingsCommandIdAndWizardIdIsNotEmpty,
                            settings.Name),
                        Resources.Validate_DragDropSettingsCommandIdAndWizardIdIsNotEmptyCode, settings.Extends);
                }
            }
            catch (Exception ex)
            {
                tracer.Error(
                    ex,
                    Resources.ValidationMethodFailed_Error,
                    Reflector <DragDropSettingsValidations> .GetMethod(n => n.ValidateCommandIdAndWizardIdIsNotEmpty(null, null)).Name);

                throw;
            }
        }
        internal void ValidateCanResolveNonEmptyConditionsType(ValidationContext context, DragDropSettings 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<DragDropSettingsValidations>.GetMethod(n => n.ValidateCanResolveNonEmptyConditionsType(null, null)).Name);

                throw;
            }
        }
        internal void ValidateWizardIdIsValid(ValidationContext context, DragDropSettings 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<DragDropSettingsValidations>.GetMethod(n => n.ValidateWizardIdIsValid(null, null)).Name);

                throw;
            }
        }