using System; using System.Collections.Generic; using System.Linq; using System.Text; using AyaNova.PlugIn; using GZTW.AyaNova.BLL; using System.Data; using System.IO; using System.Windows.Forms; namespace AyaNova.Plugin.XTools { class XTools : IAyaNovaPlugin { #region IAyaNovaPlugin Members public string dbFile = ""; public DataSet ds = null; #region header stuff public string PluginName { get { return "XTools"; } } public string PluginVersion { get { return "7.6"; } } public string About { get { return "AyaNova XTools"; } } public Guid PluginID { get { return new Guid("{A18C735A-1D78-46c7-BEA6-0CF91E8A361F}"); } } public System.Drawing.Image PluginSmallIcon { get { return Resource1.Xtools16; } } public System.Drawing.Image PluginLargeIcon { get { return Resource1.Xtools32; } } public System.Resources.ResourceManager AyaNovaResourceManager { set { ; } } #endregion header stuff #region start / stop public bool Initialize(Version AyaNovaVersion, LocalizedTextTable localizedText) { //check for db file in same folder this plugin loaded from and if not found create one dbFile = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\xtools.xml"; if (File.Exists(dbFile)) { try { ds = new DataSet(); ds.ReadXml(dbFile, XmlReadMode.ReadSchema); } catch (Exception ex) { MessageBox.Show("XTools plugin failed to load dataset from " + dbFile + ", error: \r\n" + ex.Message); return false; } } else { //create it try { ds = new DataSet(); ds.Tables.Add(); ds.Tables[0].Columns.Add("Name", typeof(string)); ds.Tables[0].Columns.Add("URL", typeof(string)); //sample items ds.Tables[0].Rows.Add(new object[] { "AyaNova forum", "http://forum.ayanova.com" }); ds.Tables[0].Rows.Add(new object[] { "Calc", "%SystemRoot%\\system32\\calc.exe" }); ds.WriteXml(dbFile, XmlWriteMode.WriteSchema); } catch (Exception ex) { MessageBox.Show("XTools plugin failed to initialize and write new dataset to " + dbFile + ", error: \r\n" + ex.Message); return false; } } return true; } public void Close() { ; } #endregion start stop #region Show / menu options public bool SingleObjectMenuShow(RootObjectTypes objectType) { //Only show in main menu return objectType == RootObjectTypes.Nothing; } public bool MultipleObjectsMenuShow(RootObjectTypes objectType) { return false; } public List SingleObjectMenuOptions(RootObjectTypes objectType, object ayaNovaObject) { List l = new List(1); l.Add(new AyaNovaPluginMenuItem("CONFIGURE", "< Configure >", null, null)); #if(DEBUG) l.Add(new AyaNovaPluginMenuItem("TEST", "< Test >", null, null)); #endif DataView dv = ds.Tables[0].DefaultView; dv.Sort = "Name"; foreach (DataRowView drv in dv) { l.Add(new AyaNovaPluginMenuItem(drv["Name"].ToString(), drv["Name"].ToString(), null, null)); } return l; } public List MultipleObjectsMenuOptions(RootObjectTypes objectType) { return null; } #endregion show/options #region Commands public bool CommandSelectedForList(string commandKey, RootObjectTypes objectType, List objectIDList, object listObject) { return false; } public void CommandSelectedForSingleObject(string commandKey, RootObjectTypes objectType, object ayaNovaObject) { #if(DEBUG) if (commandKey == "TEST") { System.Diagnostics.Process.Start("AyaNova:3,6818c177-ef0f-47d4-a769-8019b3227870"); return; } #endif if (commandKey == "CONFIGURE") { new Configure(ds).ShowDialog(); ds.WriteXml(dbFile, XmlWriteMode.WriteSchema); } else foreach (DataRow dr in ds.Tables[0].Rows) { if (commandKey == dr["Name"].ToString()) { try { string sUrl = System.Environment.ExpandEnvironmentVariables(dr["URL"].ToString()); System.Diagnostics.Process.Start(sUrl); } catch (Exception ex) { MessageBox.Show("Unable to start the url, error was:\r\n" + ex.Message); } return; } } } #endregion commands #endregion } }