Ejemplo n.º 1
0
        internal void ValidateConditionsTypeIsNotEmpty(ValidationContext context, MenuSettings settings)
        {
            Guard.NotNull(() => context, context);
            Guard.NotNull(() => settings, settings);

            try
            {
                foreach (var condition in settings.ConditionSettings.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,
                    Resources.ValidationMethodFailed_Error,
                    Reflector <MenuSettingsValidations> .GetMethod(n => n.ValidateConditionsTypeIsNotEmpty(null, null)).Name);

                throw;
            }
        }
Ejemplo n.º 2
0
        internal void ValidateWizardIdIsValid(ValidationContext context, MenuSettings 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 <MenuSettingsValidations> .GetMethod(n => n.ValidateWizardIdIsValid(null, null)).Name);

                throw;
            }
        }
Ejemplo n.º 3
0
        internal void ValidateTextIsNotEmpty(ValidationContext context, MenuSettings settings)
        {
            Guard.NotNull(() => context, context);
            Guard.NotNull(() => settings, settings);

            try
            {
                // Ensure not empty
                if (string.IsNullOrEmpty(settings.Text))
                {
                    context.LogError(
                        string.Format(CultureInfo.CurrentCulture, Resources.Validate_MenuSettingsMenuTextIsNotEmpty, settings.Name),
                        Resources.Validate_MenuSettingsMenuTextIsNotEmptyCode,
                        settings.Extends);
                }

                // TODO: Ensure it still exists
            }
            catch (Exception ex)
            {
                tracer.Error(
                    ex,
                    Resources.ValidationMethodFailed_Error,
                    Reflector <MenuSettingsValidations> .GetMethod(n => n.ValidateTextIsNotEmpty(null, null)).Name);

                throw;
            }
        }
Ejemplo n.º 4
0
        internal void ValidateCommandIdAndWizardIdIsNotEmpty(ValidationContext context, MenuSettings 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_MenuSettingsCommandIdAndWizardIdIsNotEmpty,
                            settings.Name),
                        Resources.Validate_MenuSettingsCommandIdAndWizardIdIsNotEmptyCode, settings.Extends);
                }
            }
            catch (Exception ex)
            {
                tracer.Error(
                    ex,
                    Resources.ValidationMethodFailed_Error,
                    Reflector<MenuSettingsValidations>.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<MenuSettings>();
                });

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

                validationContext = new ValidationContext(ValidationCategories.Save, this.settings);
            }
Ejemplo n.º 6
0
        internal void ValidateIconIsEmptyOrValid(ValidationContext context, MenuSettings settings)
        {
            Guard.NotNull(() => context, context);
            Guard.NotNull(() => settings, settings);

            try
            {
                if (!string.IsNullOrEmpty(settings.Icon))
                {
                    var uriService   = ((IServiceProvider)settings.Store).GetService <IUriReferenceService>();
                    var resolvedIcon = uriService.ResolveUri <ResourcePack>(new Uri(settings.Icon));

                    if (resolvedIcon == null)
                    {
                        context.LogError(
                            string.Format(CultureInfo.CurrentCulture, Resources.Validate_MenuSettingsIconDoesNotPointToAValidFile, settings.Name),
                            Resources.Validate_MenuSettingsIconDoesNotPointToAValidFileCode,
                            settings);
                        return;
                    }

                    if (resolvedIcon.Type == ResourcePackType.ProjectItem)
                    {
                        var item = resolvedIcon.GetItem();
                        if (item.Data.ItemType != @"Resource")
                        {
                            context.LogError(
                                string.Format(CultureInfo.CurrentCulture, Resources.Validate_MenuSettingsIconIsNotAResource, settings.Name, item.Name),
                                Resources.Validate_MenuSettingsIconIsNotAResourceCode,
                                settings);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                tracer.Error(
                    ex,
                    Resources.ValidationMethodFailed_Error,
                    Reflector <MenuSettingsValidations> .GetMethod(n => n.ValidateIconIsEmptyOrValid(null, null)).Name);

                throw;
            }
        }
Ejemplo n.º 7
0
		private static void WritePropertiesAsElements(DslModeling::SerializationContext serializationContext, MenuSettings 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);
	
				}
			}
		} 
Ejemplo n.º 8
0
		private static void ReadPropertiesFromElements(DslModeling::SerializationContext serializationContext, MenuSettings 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.
				}
			}
		}
Ejemplo n.º 9
0
        internal void ValidateCommandIdAndWizardIdIsNotEmpty(ValidationContext context, MenuSettings 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_MenuSettingsCommandIdAndWizardIdIsNotEmpty,
                            settings.Name),
                        Resources.Validate_MenuSettingsCommandIdAndWizardIdIsNotEmptyCode, settings.Extends);
                }
            }
            catch (Exception ex)
            {
                tracer.Error(
                    ex,
                    Resources.ValidationMethodFailed_Error,
                    Reflector <MenuSettingsValidations> .GetMethod(n => n.ValidateCommandIdAndWizardIdIsNotEmpty(null, null)).Name);

                throw;
            }
        }
Ejemplo n.º 10
0
        internal void ValidateCanResolveNonEmptyConditionsType(ValidationContext context, MenuSettings 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 <MenuSettingsValidations> .GetMethod(n => n.ValidateCanResolveNonEmptyConditionsType(null, null)).Name);

                throw;
            }
        }
Ejemplo n.º 11
0
        internal void ValidateIconIsEmptyOrValid(ValidationContext context, MenuSettings settings)
        {
            Guard.NotNull(() => context, context);
            Guard.NotNull(() => settings, settings);

            try
            {
                if (!string.IsNullOrEmpty(settings.Icon))
                {
                    var uriService = ((IServiceProvider)settings.Store).GetService<IUriReferenceService>();
                    var resolvedIcon = uriService.ResolveUri<ResourcePack>(new Uri(settings.Icon));

                    if (resolvedIcon == null)
                    {
                        context.LogError(
                                string.Format(CultureInfo.CurrentCulture, Resources.Validate_MenuSettingsIconDoesNotPointToAValidFile, settings.Name),
                                Resources.Validate_MenuSettingsIconDoesNotPointToAValidFileCode,
                                settings);
                        return;
                    }

                    if (resolvedIcon.Type == ResourcePackType.ProjectItem)
                    {
                        var item = resolvedIcon.GetItem();
                        if (item.Data.ItemType != @"Resource")
                        {
                            context.LogError(
                                    string.Format(CultureInfo.CurrentCulture, Resources.Validate_MenuSettingsIconIsNotAResource, settings.Name, item.Name),
                                    Resources.Validate_MenuSettingsIconIsNotAResourceCode,
                                    settings);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                tracer.Error(
                    ex,
                    Resources.ValidationMethodFailed_Error,
                    Reflector<MenuSettingsValidations>.GetMethod(n => n.ValidateIconIsEmptyOrValid(null, null)).Name);

                throw;
            }
        }
Ejemplo n.º 12
0
        internal void ValidateCanResolveNonEmptyConditionsType(ValidationContext context, MenuSettings 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<MenuSettingsValidations>.GetMethod(n => n.ValidateCanResolveNonEmptyConditionsType(null, null)).Name);

                throw;
            }
        }
Ejemplo n.º 13
0
        internal void ValidateConditionsTypeIsNotEmpty(ValidationContext context, MenuSettings settings)
        {
            Guard.NotNull(() => context, context);
            Guard.NotNull(() => settings, settings);

            try
            {
                foreach (var condition in settings.ConditionSettings.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,
                    Resources.ValidationMethodFailed_Error,
                    Reflector<MenuSettingsValidations>.GetMethod(n => n.ValidateConditionsTypeIsNotEmpty(null, null)).Name);

                throw;
            }
        }
Ejemplo n.º 14
0
        internal void ValidateTextIsNotEmpty(ValidationContext context, MenuSettings settings)
        {
            Guard.NotNull(() => context, context);
            Guard.NotNull(() => settings, settings);

            try
            {
                // Ensure not empty
                if (string.IsNullOrEmpty(settings.Text))
                {
                    context.LogError(
                        string.Format(CultureInfo.CurrentCulture, Resources.Validate_MenuSettingsMenuTextIsNotEmpty, settings.Name),
                        Resources.Validate_MenuSettingsMenuTextIsNotEmptyCode,
                        settings.Extends);
                }

                // TODO: Ensure it still exists
            }
            catch (Exception ex)
            {
                tracer.Error(
                    ex,
                    Resources.ValidationMethodFailed_Error,
                    Reflector<MenuSettingsValidations>.GetMethod(n => n.ValidateTextIsNotEmpty(null, null)).Name);

                throw;
            }

        }
Ejemplo n.º 15
0
        internal void ValidateWizardIdIsValid(ValidationContext context, MenuSettings 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<MenuSettingsValidations>.GetMethod(n => n.ValidateWizardIdIsValid(null, null)).Name);

                throw;
            }
        }