예제 #1
0
        private Image GetImage(Type plugin, bool small = false)
        {
            // Default logo (no-logo)
            var thisAssembly = Assembly.GetExecutingAssembly();
            var logoStream   = thisAssembly.GetManifestResourceStream(small ? "XrmToolBox.Images.nologo32.png" : "XrmToolBox.Images.nologo.png");

            if (logoStream == null)
            {
                throw new Exception("Unable to find no-logo stream!");
            }

            var logo = Image.FromStream(logoStream);

            // Old method
            var pluginControl = (IMsCrmToolsPluginUserControl)PluginManager.CreateInstance(plugin.Assembly.Location, plugin.FullName);

            if (pluginControl.PluginLogo != null)
            {
                logo = pluginControl.PluginLogo;
            }

            // Replace by new method if available
            var b64 = AssemblyAttributeHelper.GetStringAttributeValue(plugin.Assembly, small ? "SmallBase64Image" : "BigBase64Image");

            if (b64.Length > 0)
            {
                var bytes = Convert.FromBase64String(b64);
                var ms    = new MemoryStream(bytes, 0, bytes.Length);
                ms.Write(bytes, 0, bytes.Length);
                logo = Image.FromStream(ms);
                ms.Close();
            }

            return(logo);
        }
예제 #2
0
        private void DisplayOnePlugin(Type plugin, ref int top, int width, int count = -1)
        {
            var title   = plugin.GetTitle();
            var desc    = plugin.GetDescription();
            var author  = plugin.GetCompany();
            var version = plugin.Assembly.GetName().Version.ToString();

            var backColor      = AssemblyAttributeHelper.GetColor(plugin.Assembly, typeof(BackgroundColorAttribute));
            var primaryColor   = AssemblyAttributeHelper.GetColor(plugin.Assembly, typeof(PrimaryFontColorAttribute));
            var secondaryColor = AssemblyAttributeHelper.GetColor(plugin.Assembly, typeof(SecondaryFontColorAttribute));

            if (currentOptions.DisplayLargeIcons)
            {
                var pm = new PluginModel(GetImage(plugin), title, desc, author, version, backColor, primaryColor, count)
                {
                    Left  = 4,
                    Top   = top,
                    Width = width,
                    Tag   = plugin,
                };

                pm.Clicked += PluginClicked;
                this.Invoke(new Action(() =>
                {
                    this.HomePageTab.Controls.Add(pm);
                }));
                top += 104;
            }
            else
            {
                var pm = new SmallPluginModel(GetImage(plugin, true), title, desc, author, version, backColor, primaryColor, secondaryColor, count)
                {
                    Left  = 4,
                    Top   = top,
                    Width = width,
                    Tag   = plugin,
                };

                pm.Clicked += PluginClicked;
                this.Invoke(new Action(() =>
                {
                    this.HomePageTab.Controls.Add(pm);
                }));
                top += 54;
            }
        }
예제 #3
0
        private PluginModel CreateModel <T>(Type plugin, ref int top, int width, int count)
            where T : PluginModel
        {
            var pm = (T)this.pManager.PluginsControls.FirstOrDefault(t => (Type)t.Tag == plugin && t is T);

            if (pm == null)
            {
                var title   = plugin.GetTitle();
                var desc    = plugin.GetDescription();
                var author  = plugin.GetCompany();
                var version = plugin.Assembly.GetName().Version.ToString();

                var backColor      = AssemblyAttributeHelper.GetColor(plugin.Assembly, typeof(BackgroundColorAttribute));
                var primaryColor   = AssemblyAttributeHelper.GetColor(plugin.Assembly, typeof(PrimaryFontColorAttribute));
                var secondaryColor = AssemblyAttributeHelper.GetColor(plugin.Assembly, typeof(SecondaryFontColorAttribute));

                var args = new Type[]
                {
                    typeof(Image),
                    typeof(string),
                    typeof(string),
                    typeof(string),
                    typeof(string),
                    typeof(Color),
                    typeof(Color),
                    typeof(Color),
                    typeof(int)
                };

                var vals = new object[]
                {
                    GetImage(plugin),
                    title,
                    desc,
                    author,
                    version,
                    backColor,
                    primaryColor,
                    secondaryColor,
                    count
                };

                var ctor = typeof(T).GetConstructor(args);
                pm = (T)ctor.Invoke(vals);

                pm.Tag      = plugin;
                pm.Clicked += PluginClicked;

                this.pManager.PluginsControls.Add(pm);
            }

            var localTop = top;

            this.Invoke(new Action(() =>
            {
                pm.Left  = 4;
                pm.Top   = localTop;
                pm.Width = width;
            }));
            top += pm.Height + 4;

            return(pm);
        }