/// <summary>
        /// Ensures specified command is either: present and configured correctly on the element, or removed from element, based on the evaluation of the given function.
        /// </summary>
        public static CommandSettings EnsureCommandAutomation <TCommand>(this IPatternElementSchema container, string instanceName, Func <bool> exists) where TCommand : ICommand
        {
            var settings = container.GetAutomationSettings <CommandSettings>(instanceName);

            if (exists() == true)
            {
                // Create a new instance of not already exists.
                if (settings == null)
                {
                    settings = PatternElementSchemaExtensions.CreateSystemAutomationSettings <CommandSettings>(container, instanceName);
                }

                // Update properties
                if (settings != null)
                {
                    settings.TypeId = typeof(TCommand).FullName;
                }
            }
            else
            {
                // Delete existing command
                if (settings != null)
                {
                    settings.Extends.Delete();
                    return(null);
                }
            }

            return(settings);
        }
        /// <summary>
        /// Ensures specified event is either: present and configured correctly on the element, or removed from element, based on the evaluation of the given function.
        /// </summary>
        public static EventSettings EnsureEventLaunchPoint(this IPatternElementSchema container, string eventTypeName, string instanceName, CommandSettings command, Func <bool> exists)
        {
            var settings = container.GetAutomationSettings <EventSettings>(instanceName);

            if (exists() == true)
            {
                // Create a new instance of not already exists.
                if (settings == null)
                {
                    settings = PatternElementSchemaExtensions.CreateSystemAutomationSettings <EventSettings>(container, instanceName);
                }

                // Update properties
                if (settings != null)
                {
                    settings.EventId = eventTypeName;
                    if (command != null)
                    {
                        settings.CommandId = command.Id;
                    }
                }
            }
            else
            {
                // Delete existing instance
                if (settings != null)
                {
                    settings.Extends.Delete();
                    return(null);
                }
            }

            return(settings);
        }
示例#3
0
        internal static bool TryToFixId <TSettings>(Store store, IPatternElementSchema elementSchema, Guid elementId, Action <Guid> idFixer) where TSettings : IAutomationSettings
        {
            bool isIdFixed = false;

            var patternModel = GetRootElement(store);

            var manager = store.GetService <IPatternManager>();

            var toolkit = manager.InstalledToolkits.FirstOrDefault(i => i.Id.Equals(patternModel.BaseId));

            if (toolkit != null)
            {
                var baseSettings = toolkit.Schema.FindAll <TSettings>().FirstOrDefault(set => set.Id.Equals(elementId));

                if (baseSettings != null)
                {
                    var settings = elementSchema.GetAutomationSettings <TSettings>().FirstOrDefault(s => s.Name.Equals(baseSettings.Name));

                    if (settings != null)
                    {
                        idFixer(settings.Id);
                        isIdFixed = true;
                    }
                }
            }

            return(isIdFixed);
        }
示例#4
0
        /// <summary>
        /// Ensures the associated commands and launchpoint automation are created and configured correctly.
        /// </summary>
        internal void EnsureValidationExtensionAutomation()
        {
            IPatternElementSchema element = this.Extends as IPatternElementSchema;

            // Configure the open command.
            var validateCommand = element.EnsureCommandAutomation <ValidateElementCommand>(
                Resources.ValidationExtension_ValidateCommandName,
                () => (this.ValidationOnBuild || this.ValidationOnMenu || this.ValidationOnSave || !String.IsNullOrEmpty(this.ValidationOnCustomEvent)));

            if (validateCommand != null)
            {
                validateCommand.SetPropertyValue <ValidateElementCommand, bool>(cmd => cmd.ValidateDescendants, true);
            }

            // Configure events.
            element.EnsureEventLaunchPoint <IOnProductStoreSavedEvent>(Resources.ValidationExtension_OnSaveEventName, validateCommand,
                                                                       () => this.ValidationOnSave);
            element.EnsureEventLaunchPoint <IOnBuildStartedEvent>(Resources.ValidationExtension_OnBuildEventName, validateCommand,
                                                                  () => this.ValidationOnBuild);
            element.EnsureEventLaunchPoint(this.ValidationOnCustomEvent, Resources.ValidationExtension_OnCustomEventName, validateCommand,
                                           () => !String.IsNullOrEmpty(this.ValidationOnCustomEvent));

            // Configure menu.
            element.EnsureMenuLaunchPoint(Resources.ValidationExtension_OnMenuContextMenuName, validateCommand,
                                          Resources.ValidationExtension_OnMenuMenuItemText, null,
                                          () => this.ValidationOnMenu);
        }
示例#5
0
 private static bool ShouldSyncName(IPatternElementSchema pattern)
 {
     return(pattern.GetAutomationSettings <ITemplateSettings>().Any(t => t.SyncName) ||
            pattern.GetAutomationSettings <ICommandSettings>().Any(c => c.TypeId == typeof(UnfoldVsTemplateCommand).ToString() &&
                                                                   c.Properties.Any(p => p.Name == Reflector <UnfoldVsTemplateCommand> .GetPropertyName(u => u.SyncName) && string.Equals(p.Value, true.ToString(), StringComparison.OrdinalIgnoreCase))) ||
            pattern.GetAutomationSettings <ICommandSettings>().Any(c => c.TypeId == typeof(GenerateProductCodeCommand).ToString() &&
                                                                   c.Properties.Any(p => p.Name == Reflector <GenerateProductCodeCommand> .GetPropertyName(u => u.SyncName) && string.Equals(p.Value, true.ToString(), StringComparison.OrdinalIgnoreCase))));
 }
示例#6
0
 private static bool ShouldSyncName(IPatternElementSchema pattern)
 {
     return pattern.GetAutomationSettings<ITemplateSettings>().Any(t => t.SyncName)
         || pattern.GetAutomationSettings<ICommandSettings>().Any(c => c.TypeId == typeof(UnfoldVsTemplateCommand).ToString()
             && c.Properties.Any(p => p.Name == Reflector<UnfoldVsTemplateCommand>.GetPropertyName(u => u.SyncName) && string.Equals(p.Value, true.ToString(), StringComparison.OrdinalIgnoreCase)))
         || pattern.GetAutomationSettings<ICommandSettings>().Any(c => c.TypeId == typeof(GenerateProductCodeCommand).ToString()
             && c.Properties.Any(p => p.Name == Reflector<GenerateProductCodeCommand>.GetPropertyName(u => u.SyncName) && string.Equals(p.Value, true.ToString(), StringComparison.OrdinalIgnoreCase)));
 }
 /// <summary>
 /// Creates the settings for associating guidance, that are also not customizable.
 /// </summary>
 public static TSettings CreateSystemAutomationSettings <TSettings>(this IPatternElementSchema container, string settingsName)
     where TSettings : ExtensionElement, IAutomationSettings
 {
     return(container.CreateAutomationSettings <TSettings>(settingsName, schema =>
     {
         schema.IsCustomizable = CustomizationState.False;
         schema.IsSystem = true;
     }));
 }
        /// <summary>
        /// Gets the automation settings by name.
        /// </summary>
        /// <typeparam name="TSettings">The type of the settings.</typeparam>
        /// <param name="element">The automation settings container schema.</param>
        /// <param name="settingsName">Name of the settings.</param>
        public static TSettings GetAutomationSettings <TSettings>(this IPatternElementSchema element, string settingsName)
            where TSettings : IAutomationSettings
        {
            Guard.NotNull(() => element, element);
            Guard.NotNull(() => settingsName, settingsName);

            return((from cs in element.AutomationSettings
                    where cs.Name.Equals(settingsName, StringComparison.OrdinalIgnoreCase)
                    let setting = cs.As <TSettings>()
                                  where setting != null
                                  select(TSettings) setting)
                   .FirstOrDefault());
        }
示例#9
0
        private static readonly string guidanceIconPath = ""; //"Resources/CommandShowGuidance.png";

        /// <summary>
        /// Ensures the associated commands and launchpoint automation are created and configured correctly.
        /// </summary>
        internal void EnsureGuidanceExtensionAutomation()
        {
            IPatternElementSchema element            = this.Extends as IPatternElementSchema;
            Func <bool>           existanceCondition = () => !string.IsNullOrEmpty(this.ExtensionId);

            // Configure the instantiate command, event.
            var instantiateCommand = element.EnsureCommandAutomation <InstantiateGuidanceWorkflowCommand>(Properties.Resources.GuidanceExtension_InstantiateCommandName,
                                                                                                          existanceCondition);

            if (instantiateCommand != null)
            {
                instantiateCommand.SetPropertyValue <InstantiateGuidanceWorkflowCommand, string>(cmd => cmd.ExtensionId, this.ExtensionId);
                instantiateCommand.SetPropertyValue <InstantiateGuidanceWorkflowCommand, string>(cmd => cmd.DefaultInstanceName, this.GuidanceInstanceName);
                instantiateCommand.SetPropertyValue <InstantiateGuidanceWorkflowCommand, bool>(cmd => cmd.SharedInstance, this.GuidanceSharedInstance);
                instantiateCommand.SetPropertyValue <InstantiateGuidanceWorkflowCommand, bool>(cmd => cmd.ActivateOnInstantiation, this.GuidanceActivateOnCreation);
            }

            element.EnsureEventLaunchPoint <IOnElementInstantiatedEvent>(Properties.Resources.GuidanceExtension_InstantiateEventName,
                                                                         instantiateCommand, () => !String.IsNullOrEmpty(this.ExtensionId));

            // Configure the activate command and menu.
            var activateCommand = element.EnsureCommandAutomation <ActivateGuidanceWorkflowCommand>(Properties.Resources.GuidanceExtension_ActivateCommandName,
                                                                                                    existanceCondition);

            var activateMenu = element.EnsureMenuLaunchPoint(Resources.GuidanceExtension_ActivateContextMenuName,
                                                             activateCommand, Resources.GuidanceExtension_ActivateMenuItemText, guidanceIconPath,
                                                             existanceCondition);

            if (activateMenu != null)
            {
                // Set the conditions
                activateMenu.Conditions = BindingSerializer.Serialize(
                    new List <ConditionBindingSettings>
                {
                    new ConditionBindingSettings
                    {
                        TypeId     = typeof(ElementReferenceExistsCondition).FullName,
                        Properties =
                        {
                            new PropertyBindingSettings
                            {
                                Name  = Reflector <ElementReferenceExistsCondition> .GetPropertyName(cond => cond.Kind),
                                Value = ReferenceKindConstants.GuidanceTopic
                            },
                        }
                    }
                });
            }
        }
示例#10
0
        /// <summary>
        /// Ensures the associated commands and launchpoint automation are created and configured correctly.
        /// </summary>
        internal static void EnsureSyncNameExtensionAutomation(IPatternElementSchema pattern)
        {
            // Configure the sync command and menu.
            var syncCommand = pattern.EnsureCommandAutomation<SynchArtifactNameCommand>(
                Resources.SyncNameExtension_SyncNameCommandName,
                () => ShouldSyncName(pattern));

            syncCommand.SetPropertyValue<SynchArtifactNameCommand, string>(s => s.ReferenceTag, SynchArtifactNameCommand.FilteredReferenceTagValue);

            // Configure the sync event.
            pattern.EnsureEventLaunchPoint<IOnElementPropertyChangedEvent>(
                Resources.SyncNameExtension_SyncNameEventName,
                syncCommand,
                () => ShouldSyncName(pattern));
        }
示例#11
0
        /// <summary>
        /// Ensures the associated commands and launchpoint automation are created and configured correctly.
        /// </summary>
        internal static void EnsureSyncNameExtensionAutomation(IPatternElementSchema pattern)
        {
            // Configure the sync command and menu.
            var syncCommand = pattern.EnsureCommandAutomation <SynchArtifactNameCommand>(
                Resources.SyncNameExtension_SyncNameCommandName,
                () => ShouldSyncName(pattern));

            syncCommand.SetPropertyValue <SynchArtifactNameCommand, string>(s => s.ReferenceTag, SynchArtifactNameCommand.FilteredReferenceTagValue);

            // Configure the sync event.
            pattern.EnsureEventLaunchPoint <IOnElementPropertyChangedEvent>(
                Resources.SyncNameExtension_SyncNameEventName,
                syncCommand,
                () => ShouldSyncName(pattern));
        }
示例#12
0
            public void Initialize()
            {
                ElementSchema element = null;

                this.store = new Store(VsIdeTestHostContext.ServiceProvider,
                                       new[] { typeof(CoreDesignSurfaceDomainModel), typeof(PatternModelDomainModel), typeof(LibraryDomainModel) });

                this.store.TransactionManager.DoWithinTransaction(() =>
                {
                    this.store.ElementFactory.CreateElement <PatternModelSchema>();
                    element = this.store.ElementFactory.CreateElement <ElementSchema>();
                });

                this.guidanceExtension = element.GetExtensions <IGuidanceExtension>().FirstOrDefault();
                this.container         = element as IPatternElementSchema;
            }
            public void Initialize()
            {
                PatternSchema product = null;

                this.store = new Store(VsIdeTestHostContext.ServiceProvider,
                    new Type[] { typeof(CoreDesignSurfaceDomainModel), typeof(PatternModelDomainModel), typeof(LibraryDomainModel) });

                this.store.TransactionManager.DoWithinTransaction(() =>
                {
                    var patternModel = this.store.ElementFactory.CreateElement<PatternModelSchema>();
                    product = patternModel.Create<PatternSchema>();
                });

                this.validationExtension = product.GetExtensions<IValidationExtension>().FirstOrDefault();
                this.container = product as IPatternElementSchema;
            }
            public void Initialize()
            {
                PatternSchema product = null;

                this.store = new Store(VsIdeTestHostContext.ServiceProvider,
                                       new Type[] { typeof(CoreDesignSurfaceDomainModel), typeof(PatternModelDomainModel), typeof(LibraryDomainModel) });

                this.store.TransactionManager.DoWithinTransaction(() =>
                {
                    var patternModel = this.store.ElementFactory.CreateElement <PatternModelSchema>();
                    product          = patternModel.Create <PatternSchema>();
                });

                this.validationExtension = product.GetExtensions <IValidationExtension>().FirstOrDefault();
                this.container           = product as IPatternElementSchema;
            }
            public void Initialize()
            {
                ElementSchema element = null;

                this.store = new Store(VsIdeTestHostContext.ServiceProvider,
                    new[] { typeof(CoreDesignSurfaceDomainModel), typeof(PatternModelDomainModel), typeof(LibraryDomainModel) });

                this.store.TransactionManager.DoWithinTransaction(() =>
                {
                    this.store.ElementFactory.CreateElement<PatternModelSchema>();
                    element = this.store.ElementFactory.CreateElement<ElementSchema>();
                });

                this.guidanceExtension = element.GetExtensions<IGuidanceExtension>().FirstOrDefault();
                this.container = element as IPatternElementSchema;
            }
        public static TSettings CreateAutomationSettings <TSettings>(this IPatternElementSchema container, string settingsName,
                                                                     Action <IAutomationSettingsSchema> initializer = null)
            where TSettings : class, IAutomationSettings
        {
            TSettings automationSettings = default(TSettings);

            container.CreateAutomationSettingsSchema(aes =>
            {
                var aesMel         = (ModelElement)aes;
                var classInfo      = aesMel.Store.DomainDataDirectory.DomainClasses.Where(c => typeof(TSettings).IsAssignableFrom(c.ImplementationClass)).FirstOrDefault();
                automationSettings = aesMel.AddExtension(classInfo) as TSettings;

                aes.Name           = settingsName;
                aes.AutomationType = classInfo.DisplayName;
                aes.Classification = automationSettings.Classification;

                if (initializer != null)
                {
                    initializer(aes);
                }
            });

            return(automationSettings);
        }
        /// <summary>
        /// Ensures specified menu is either: present and configured correctly on the element, or removed from element, based on the evaluation of the given function.
        /// </summary>
        public static MenuSettings EnsureMenuLaunchPoint(this IPatternElementSchema container, string instanceName, CommandSettings command, string menuText, string iconPath, Func <bool> exists)
        {
            var settings = container.GetAutomationSettings <MenuSettings>(instanceName);

            if (exists() == true)
            {
                // Create a new instance of not already exists.
                if (settings == null)
                {
                    settings = PatternElementSchemaExtensions.CreateSystemAutomationSettings <MenuSettings>(container, instanceName);
                }

                // Update properties
                if (settings != null)
                {
                    settings.Text      = menuText;
                    settings.SortOrder = 10000; // This to make it large enough to sink to bottom of other menus
                    settings.Icon      = FormatIconPath(iconPath);
                    if (command != null)
                    {
                        settings.CommandId = command.Id;
                    }
                }
            }
            else
            {
                // Delete existing instance
                if (settings != null)
                {
                    settings.Extends.Delete();
                    return(null);
                }
            }

            return(settings);
        }
 /// <summary>
 /// Ensures specified event is either: present and configured correctly on the element, or removed from element, based on the evaluation of the given function.
 /// </summary>
 public static EventSettings EnsureEventLaunchPoint <TEvent>(this IPatternElementSchema container, string instanceName, CommandSettings command, Func <bool> exists) where TEvent : IObservableEvent
 {
     return(EnsureEventLaunchPoint(container, typeof(TEvent).FullName, instanceName, command, exists));
 }
        /// <summary>
        /// Ensures specified variable property is either: present and configured correctly on the element, or removed from element, based on the evaluation of the given function.
        /// </summary>
        public static IPropertySchema EnsureVariablePropertyForAutomation <TTypeConverter>(this IPatternElementSchema container, string instanceName, string description, string displayName, string category, Func <bool> exists) where TTypeConverter : TypeConverter
        {
            var instantiateProperty = container.Properties.FirstOrDefault <IPropertySchema>(prop => prop.Name == instanceName);

            if (exists() == true)
            {
                // Create a new instance of not already exists.
                if (instantiateProperty == null)
                {
                    instantiateProperty = container.CreatePropertySchema(prop =>
                    {
                        prop.Name           = instanceName;
                        prop.IsVisible      = true;
                        prop.IsReadOnly     = false;
                        prop.IsCustomizable = CustomizationState.False;
                        prop.IsSystem       = true;
                    });
                }

                // Update properties
                if (instantiateProperty != null)
                {
                    instantiateProperty.DisplayName = displayName;
                    instantiateProperty.Description = description;
                    instantiateProperty.Category    = category;
                    var converterType = typeof(TTypeConverter);
                    instantiateProperty.TypeConverterTypeName = converterType.FullName + @", " + converterType.Assembly.FullName.Split(',')[0];
                }
            }
            else
            {
                // Delete existing instance
                if (instantiateProperty != null)
                {
                    container.DeletePropertySchema(instantiateProperty);
                    return(null);
                }
            }

            return(instantiateProperty);
        }
        /// <summary>
        /// Gets the settings.
        /// </summary>
        /// <typeparam name="TSettings">The type of the settings.</typeparam>
        /// <param name="element">The container.</param>
        public static IEnumerable <TSettings> GetAutomationSettings <TSettings>(this IPatternElementSchema element) where TSettings : IAutomationSettings
        {
            Guard.NotNull(() => element, element);

            return(element.AutomationSettings.Select(s => s.As <TSettings>()).Where(t => t != null));
        }