public SwMacroFeatureDefinition()
        {
            string provider = "";

            this.GetType().TryGetAttribute <MissingDefinitionErrorMessage>(a =>
            {
                provider = a.Message;
            });

            m_Provider = provider;

            var svcColl = new ServiceCollection();

            svcColl.AddOrReplace <IXLogger>(() => new TraceLogger($"xCad.MacroFeature.{this.GetType().FullName}"));
            svcColl.AddOrReplace <IIconsCreator>(() => new BaseIconsCreator());

            ConfigureServices?.Invoke(this, svcColl);
            OnConfigureServices(svcColl);

            m_SvcProvider = svcColl.CreateProvider();

            m_Logger = m_SvcProvider.GetService <IXLogger>();

            CustomFeatureDefinitionInstanceCache.RegisterInstance(this);

            var iconsConv = m_SvcProvider.GetService <IIconsCreator>();

            iconsConv.KeepIcons   = true;
            iconsConv.IconsFolder = MacroFeatureIconInfo.GetLocation(this.GetType());
            TryCreateIcons(iconsConv);
        }
        private void TryCreateIcons()
        {
            var iconsConverter = new IconsConverter(
                MacroFeatureIconInfo.GetLocation(this.GetType()), false);

            IIcon regIcon  = null;
            IIcon highIcon = null;
            IIcon suppIcon = null;

            this.GetType().TryGetAttribute <IconAttribute>(a =>
            {
                regIcon  = a.Regular;
                highIcon = a.Highlighted;
                suppIcon = a.Suppressed;
            });

            if (regIcon == null)
            {
                //TODO: load default
            }

            if (highIcon == null)
            {
                highIcon = regIcon;
            }

            if (suppIcon == null)
            {
                suppIcon = regIcon;
            }

            //Creation of icons may fail if user doesn't have write permissions or icon is locked
            try
            {
                iconsConverter.ConvertIcon(regIcon, true);
                iconsConverter.ConvertIcon(suppIcon, true);
                iconsConverter.ConvertIcon(highIcon, true);
                iconsConverter.ConvertIcon(regIcon, false);
                iconsConverter.ConvertIcon(suppIcon, false);
                iconsConverter.ConvertIcon(highIcon, false);
            }
            catch
            {
            }
        }
Esempio n. 3
0
        private void TryCreateIcons()
        {
            var iconsConverter = new IconsConverter(
                MacroFeatureIconInfo.GetLocation(this.GetType()), false);

            System.Drawing.Image icon = null;

            this.GetType().TryGetAttribute <IconAttribute>(a =>
            {
                icon = IconsConverter.FromXImage(a.Icon);
            });

            if (icon == null)
            {
                icon = IconsConverter.FromXImage(Defaults.Icon);
            }

            //TODO: create different icons for highlighted and suppressed
            var regular     = icon;
            var highlighted = icon;
            var suppressed  = icon;

            //Creation of icons may fail if user doesn't have write permissions or icon is locked
            try
            {
                iconsConverter.ConvertIcon(new MacroFeatureIcon(icon, MacroFeatureIconInfo.RegularName));
                iconsConverter.ConvertIcon(new MacroFeatureIcon(highlighted, MacroFeatureIconInfo.HighlightedName));
                iconsConverter.ConvertIcon(new MacroFeatureIcon(suppressed, MacroFeatureIconInfo.SuppressedName));
                iconsConverter.ConvertIcon(new MacroFeatureHighResIcon(icon, MacroFeatureIconInfo.RegularName));
                iconsConverter.ConvertIcon(new MacroFeatureHighResIcon(highlighted, MacroFeatureIconInfo.HighlightedName));
                iconsConverter.ConvertIcon(new MacroFeatureHighResIcon(suppressed, MacroFeatureIconInfo.SuppressedName));
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }
Esempio n. 4
0
        private void TryCreateIcons()
        {
            var iconsConverter = new IconsConverter(
                MacroFeatureIconInfo.GetLocation(this.GetType()), false);

            MacroFeatureIcon regIcon  = null;
            MacroFeatureIcon highIcon = null;
            MacroFeatureIcon suppIcon = null;

            this.GetType().TryGetAttribute <FeatureIconAttribute>(a =>
            {
                regIcon  = a.Regular;
                highIcon = a.Highlighted;
                suppIcon = a.Suppressed;
            });

            if (regIcon == null)
            {
                Image icon = null;

                this.GetType().TryGetAttribute <Common.Attributes.IconAttribute>(a =>
                {
                    icon = a.Icon;
                });

                if (icon == null)
                {
                    icon = Resources.default_icon;
                }

                regIcon = new MasterIcon(MacroFeatureIconInfo.RegularName)
                {
                    Icon = icon
                };
            }

            if (highIcon == null)
            {
                highIcon = regIcon.Clone(MacroFeatureIconInfo.HighlightedName);
            }

            if (suppIcon == null)
            {
                suppIcon = regIcon.Clone(MacroFeatureIconInfo.SuppressedName);
            }

            //Creation of icons may fail if user doesn't have write permissions or icon is locked
            try
            {
                iconsConverter.ConvertIcon(regIcon, true);
                iconsConverter.ConvertIcon(suppIcon, true);
                iconsConverter.ConvertIcon(highIcon, true);
                iconsConverter.ConvertIcon(regIcon, false);
                iconsConverter.ConvertIcon(suppIcon, false);
                iconsConverter.ConvertIcon(highIcon, false);
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }