private void addPlugin_ToolStripButton_Click(object sender, EventArgs e)
        {
            PluginMetadataNewForm newForm = new PluginMetadataNewForm();
            MetadataType          newType = new MetadataType();


            var dialogResult = newForm.ShowDialog();

            if (dialogResult == DialogResult.OK)
            {
                newType.Title        = newForm.PluginDisplayName;
                newType.Name         = newForm.PluginName;
                newType.AssemblyName = newForm.PluginAssemblyName;

                if (newForm.PluginIcon != null)
                {
                    newType.Icon = newForm.PluginIcon.ToByteArray();
                }
                else
                {
                    newType.Icon = null;
                }
            }
            else if (dialogResult == DialogResult.Cancel)
            {
                // User Cancelled
                return;
            }


            if (EditEntry(newType, true) == DialogResult.OK)
            {
                _context.AddToMetadataTypes(newType);
                _pluginTypes.Add(newType);

                int index = plugin_RadGridView.Rows.Count - 1;
                //int nColumnIndex = 3;

                plugin_RadGridView.Rows[index].IsSelected = true;

                //In case if you want to scroll down as well.
                plugin_RadGridView.TableElement.ScrollToRow(index);
            }
        }
Exemplo n.º 2
0
        private bool InsertPluginTypes()
        {
            UpdateStatus("Enabling new plugins for this installation");

            try
            {
                using (EnterpriseTestContext context = new EnterpriseTestContext())
                {
                    List <MetadataType> currentPlugins = context.MetadataTypes.ToList();

                    string[] lines = File.ReadAllLines("PluginList.txt");
                    SendProgressStart(lines.Count());

                    for (int i = 0; i < lines.Count(); i++)
                    {
                        if (!string.IsNullOrEmpty(lines[i]) && !lines[i].StartsWith("//") && !lines[i].StartsWith("*"))
                        {
                            string[] items = lines[i].Split(',');
                            if (items.Length < 1)
                            {
                                SystemTrace.Instance.Error("Need at least 1 plugin name per line");
                            }
                            else
                            {
                                string name = items[0].Trim();

                                // default the title to the name if not specified
                                string title = (items.Length > 1 && !string.IsNullOrEmpty(items[1]) ? items[1].Trim() : name);

                                // default the group to blank if not specified
                                string group = (items.Length > 2 && !string.IsNullOrEmpty(items[2]) ? items[2].Trim() : string.Empty);

                                // default the icon to null if not specified
                                byte[] icon = (items.Length > 3 && !string.IsNullOrEmpty(items[3]) ? Convert.FromBase64String(items[3].Trim()) : null);

                                MetadataType type = new MetadataType()
                                {
                                    Name         = name,
                                    Title        = title,
                                    Group        = group,
                                    AssemblyName = "Plugin.{0}.dll".FormatWith(name),
                                    Icon         = icon
                                };

                                // Only add plugins if they are new
                                if (!currentPlugins.Any(x => x.Name.Equals(name)))
                                {
                                    if (!context.MetadataTypes.Any(x => x.Name.Equals(type.Name)))
                                    {
                                        foreach (var resourceType in context.ResourceTypes)
                                        {
                                            SystemTrace.Instance.Debug("Enabling {0}".FormatWith(type.Name));
                                            type.ResourceTypes.Add(resourceType);
                                        }

                                        SendProgressUpdate(i + 1);
                                        if (!context.MetadataTypes.Any(x => x.Name.Equals(type.Name)))
                                        {
                                            context.AddToMetadataTypes(type);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    context.SaveChanges();
                    SendProgressEnd();
                }
            }
            catch (Exception ex)
            {
                SendError(ex);
                return(false);
            }

            return(true);
        }