internal IList <PluginItem> GetAllPluginItems()
        {
            List <PluginItem> items   = new List <PluginItem>();
            string            cfgFile = PluginConfigurationFileFullpath;

            if (!string.IsNullOrEmpty(cfgFile))
            {
                if (File.Exists(cfgFile))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(cfgFile);
                    if (doc.DocumentElement != null)
                    {
                        XmlNodeList nds = doc.DocumentElement.SelectNodes(XML_Item);
                        if (nds != null && nds.Count > 0)
                        {
                            foreach (XmlNode nd in nds)
                            {
                                PluginItem item = new PluginItem();
                                item.LoadFromXmlNode(nd);
                                if (item.PluginItemType != null && typeof(PluginType).IsAssignableFrom(item.PluginItemType))
                                {
                                    items.Add(item);
                                }
                            }
                        }
                    }
                }
            }
            return(items);
        }
Ejemplo n.º 2
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            _loading = true;
            int n = listBox1.SelectedIndex;

            if (n >= 0)
            {
                PluginItem pt = listBox1.Items[n] as PluginItem;
                if (pt != null)
                {
                    textBoxName.Text = pt.Name;
                }
            }
            _loading       = false;
            timer1.Enabled = true;
        }
Ejemplo n.º 3
0
 private void textBoxName_TextChanged(object sender, EventArgs e)
 {
     if (!_loading)
     {
         int n = listBox1.SelectedIndex;
         if (n >= 0)
         {
             PluginItem pt = listBox1.Items[n] as PluginItem;
             if (pt != null)
             {
                 pt.Name     = textBoxName.Text;
                 pt.Modified = true;
             }
         }
     }
 }
Ejemplo n.º 4
0
 private void updateList()
 {
     for (int i = 0; i < listBox1.Items.Count; i++)
     {
         PluginItem pt = listBox1.Items[i] as PluginItem;
         if (pt != null)
         {
             if (pt.Modified)
             {
                 pt.Modified = false;
                 listBox1.Items.RemoveAt(i);
                 listBox1.Items.Insert(i, pt);
                 listBox1.SetItemChecked(i, pt.Enabled);
             }
         }
     }
 }
Ejemplo n.º 5
0
        private void btNew_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Title  = string.Format(CultureInfo.InvariantCulture, "Select DLL file containing {0}", _pluginType.Name);
            dlg.Filter = "Dll files|*.dll";
            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                try
                {
                    Assembly a = XmlUtil.LoadAssembly(dlg.FileName, false);
                    if (a != null)
                    {
                        bool   bFound = false;
                        Type[] tps    = a.GetExportedTypes();
                        if (tps != null)
                        {
                            for (int i = 0; i < tps.Length; i++)
                            {
                                if (tps[i].IsInterface)
                                {
                                    continue;
                                }
                                if (tps[i].IsValueType)
                                {
                                    continue;
                                }
                                Type t = Type.GetType(tps[i].AssemblyQualifiedName);
                                if (_pluginType.IsAssignableFrom(t))
                                {
                                    bFound = true;
                                    bool bExists = false;
                                    for (int j = 0; j < listBox1.Items.Count; j++)
                                    {
                                        PluginItem pi = listBox1.Items[j] as PluginItem;
                                        if (pi != null)
                                        {
                                            if (pi.PluginItemType.Equals(t))
                                            {
                                                bExists = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (!bExists)
                                    {
                                        PluginItem pi = new PluginItem();
                                        pi.PluginItemType = t;
                                        pi.Name           = t.FullName;
                                        listBox1.Items.Add(pi, true);
                                    }
                                }
                            }
                        }
                        if (!bFound)
                        {
                            MessageBox.Show(this, string.Format(CultureInfo.InvariantCulture, "Plugin type [{0}] does not exist in assembly [{1}]", _pluginType.Name, dlg.FileName), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show(this, string.Format(CultureInfo.InvariantCulture, "Cannot load assembly from [{0}]", dlg.FileName), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception err)
                {
                    MessageBox.Show(this, err.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }