private static long GetSortOrder(IAutomationExtension automation)
        {
            Guard.NotNull(() => automation, automation);

            var menu = automation as IAutomationMenuCommand;
            return menu != null ? menu.SortOrder : 0;
        }
        private static string GetCaption(IAutomationExtension automation)
        {
            Guard.NotNull(() => automation, automation);

            var menu = automation as IMenuCommand;
            return automation != null ? menu.Text : null;
        }
        private static string GetImagePath(IAutomationExtension automation)
        {
            Guard.NotNull(() => automation, automation);

            var menu = automation as IAutomationMenuCommand;
            return menu != null ? menu.IconPath : null;
        }
        private static string GetCaption(IAutomationExtension automation)
        {
            Guard.NotNull(() => automation, automation);

            var menu = automation as IMenuCommand;

            return(menu != null ? menu.Text : null);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AutomationMenuOptionViewModel"/> class.
 /// </summary>
 /// <param name="automation">The menu execution behavior.</param>
 public AutomationMenuOptionViewModel(IAutomationExtension automation)
     : base(GetCaption(automation))
 {
     this.Command = new AutomationCommand(this, automation);
     this.ImagePath = ((IAutomationMenuCommand)automation).IconPath;
     this.IconType = string.IsNullOrEmpty(this.ImagePath) ? IconType.None : IconType.Image;
     this.SortOrder = ((IAutomationMenuCommand)automation).SortOrder;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AutomationMenuOptionViewModel"/> class.
 /// </summary>
 /// <param name="automation">The menu execution behavior.</param>
 /// <param name="caption">The caption.</param>
 /// <param name="imagePath">The path to the icon.</param>
 /// <param name="sortOrder">The sort order for the menu entry.</param>
 public AutomationMenuOptionViewModel(IAutomationExtension automation, string caption, string imagePath, long sortOrder)
     : base(caption)
 {
     Command = new AutomationCommand(this, automation);
     ImagePath = imagePath;
     IconType = string.IsNullOrEmpty(ImagePath) ? IconType.None : IconType.Image;
     SortOrder = sortOrder;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AutomationMenuOptionViewModel"/> class.
 /// </summary>
 /// <param name="automation">The menu execution behavior.</param>
 public AutomationMenuOptionViewModel(IAutomationExtension automation)
     : base(GetCaption(automation))
 {
     this.Command   = new AutomationCommand(this, automation);
     this.ImagePath = ((IAutomationMenuCommand)automation).IconPath;
     this.IconType  = string.IsNullOrEmpty(this.ImagePath) ? IconType.None : IconType.Image;
     this.SortOrder = ((IAutomationMenuCommand)automation).SortOrder;
 }
        private static string GetImagePath(IAutomationExtension automation)
        {
            Guard.NotNull(() => automation, automation);

            var menu = automation as IAutomationMenuCommand;

            return(menu != null ? menu.IconPath : null);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AutomationMenuOptionViewModel"/> class.
 /// </summary>
 /// <param name="automation">The menu execution behavior.</param>
 /// <param name="caption">The caption.</param>
 /// <param name="imagePath">The path to the icon.</param>
 /// <param name="sortOrder">The sort order for the menu entry.</param>
 public AutomationMenuOptionViewModel(IAutomationExtension automation, string caption, string imagePath, long sortOrder)
     : base(caption)
 {
     Command   = new AutomationCommand(this, automation);
     ImagePath = imagePath;
     IconType  = string.IsNullOrEmpty(ImagePath) ? IconType.None : IconType.Image;
     SortOrder = sortOrder;
 }
        private static long GetSortOrder(IAutomationExtension automation)
        {
            Guard.NotNull(() => automation, automation);

            var menu = automation as IAutomationMenuCommand;

            return(menu != null ? menu.SortOrder : 0);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UnfoldScope"/> class.
        /// </summary>
        public UnfoldScope(IAutomationExtension <IAutomationSettings> originatingAutomation, ReferenceTag artifactReferenceTag, string templateUri)
        {
            Guard.NotNull(() => originatingAutomation, originatingAutomation);
            Guard.NotNull(() => artifactReferenceTag, artifactReferenceTag);
            Guard.NotNullOrEmpty(() => templateUri, templateUri);

            this.parentScope = scopes.Peek();

            scopes.Push(this);
            this.templateUri  = templateUri;
            this.Automation   = originatingAutomation;
            this.ReferenceTag = artifactReferenceTag;
            tracer.Verbose(Resources.UnfoldScope_Initialized, templateUri);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UnfoldScope"/> class.
        /// </summary>
        public UnfoldScope(IAutomationExtension<IAutomationSettings> originatingAutomation, ReferenceTag artifactReferenceTag, string templateUri)
        {
            Guard.NotNull(() => originatingAutomation, originatingAutomation);
            Guard.NotNull(() => artifactReferenceTag, artifactReferenceTag);
            Guard.NotNullOrEmpty(() => templateUri, templateUri);

            this.parentScope = scopes.Peek();

            scopes.Push(this);
            this.templateUri = templateUri;
            this.Automation = originatingAutomation;
            this.ReferenceTag = artifactReferenceTag;
            tracer.Verbose(Resources.UnfoldScope_Initialized, templateUri);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Adds the automation extension to the context
        /// </summary>
        /// <param name="context"></param>
        /// <param name="extension"></param>
        public static void AddAutomation(this IDynamicBindingContext context, IAutomationExtension extension)
        {
            Guard.NotNull(() => context, context);
            Guard.NotNull(() => extension, extension);

            context.AddExport(extension);
            context.AddExportsFromInterfaces(extension);
            context.AddExportsFromInterfaces(extension.Owner);

            var mel = extension.Owner as ModelElement;

            if (mel != null)
            {
                context.AddExport(mel);
            }
        }
            public AutomationCommand(MenuOptionViewModel parent, IAutomationExtension automation)
            {
                this.parent     = parent;
                this.automation = automation;
                menu            = automation as IMenuCommand;
                status          = automation as ICommandStatus ?? new NullQueryStatus();

                parent.IsVisible = menu == null || menu.Visible;
                parent.IsEnabled = menu == null || menu.Enabled;

                var propertyChanged = automation as INotifyPropertyChanged;

                if (propertyChanged != null)
                {
                    propertyChanged.PropertyChanged += OnMenuPropertyChanged;
                }
            }
            public AutomationCommand(MenuOptionViewModel parent, IAutomationExtension automation)
            {
                this.parent = parent;
                this.automation = automation;
                this.menu = (IMenuCommand)automation;
                this.status = automation as ICommandStatus ?? new NullQueryStatus();

                parent.IsVisible = this.menu.Visible;
                parent.IsEnabled = this.menu.Enabled;

                var propertyChanged = automation as INotifyPropertyChanged;

                if (propertyChanged != null)
                {
                    propertyChanged.PropertyChanged += this.OnMenuPropertyChanged;
                }
            }
Ejemplo n.º 16
0
        /// <summary>
        /// Adds an automation extension to the pattern
        /// </summary>
        /// <param name="extension">The extension to add</param>
        public void AddAutomationExtension(IAutomationExtension extension)
        {
            var initializable = extension as ISupportInitialize;

            if (initializable != null)
            {
                initializable.BeginInit();
            }

            this.BindingContext.CompositionService.SatisfyImportsOnce(extension);

            if (initializable != null)
            {
                initializable.EndInit();
            }

            AutomationExtensions.Add(extension);
        }
        /// <summary>
        /// Attemps to resolve the given <paramref name="automationReferenceId"/> and
        /// <typeparamref name="TAutomation"/> type to a configured automation
        /// extension on in the same container as the given <paramref name="automationExtension"/>.
        /// </summary>
        /// <typeparam name="TAutomation">The type of the automation to look up.</typeparam>
        /// <param name="automationExtension">The automation extension that references another automation extension by name.</param>
        /// <param name="automationReferenceId">Name of the automation extension.</param>
        public static TAutomation ResolveAutomationReference <TAutomation>(this IAutomationExtension automationExtension, Guid automationReferenceId)
            where TAutomation : IAutomationExtension
        {
            Guard.NotNull(() => automationExtension, automationExtension);
            Guard.NotNull(() => automationExtension.Owner, automationExtension.Owner);
            Guard.NotNull(() => automationExtension.Owner.Info, automationExtension.Owner.Info);

            // We must lookup the name of the extension from the id on its setting,
            // as the setting name becomes the extension name.
            return
                ((from info in automationExtension.Owner.Info.AutomationSettings
                  from extension in automationExtension.Owner.AutomationExtensions
                  where info.Name == extension.Name
                  let setting = info.As <IAutomationSettings>()
                                where setting != null && setting.Id == automationReferenceId
                                select extension)
                 .OfType <TAutomation>()
                 .FirstOrDefault());
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AutomationMenuOptionViewModel"/> class.
 /// </summary>
 /// <param name="automation">The menu execution behavior.</param>
 public AutomationMenuOptionViewModel(IAutomationExtension automation)
     : this(automation, GetCaption(automation), GetImagePath(automation), GetSortOrder(automation))
 {
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Creates the dynamic context and adds the extension and its owner as dynamic context values.
        /// </summary>
        public static IDynamicBindingContext CreateDynamicContext <T>(this IDynamicBinding <T> binding, IAutomationExtension extension)
            where T : class
        {
            Guard.NotNull(() => binding, binding);
            Guard.NotNull(() => extension, extension);

            var context = binding.CreateDynamicContext();

            context.AddAutomation(extension);

            return(context);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AutomationMenuOptionViewModel"/> class.
 /// </summary>
 /// <param name="automation">The menu execution behavior.</param>
 public AutomationMenuOptionViewModel(IAutomationExtension automation)
     : this(automation, GetCaption(automation), GetImagePath(automation), GetSortOrder(automation))
 {
 }