private void loadPlugins() { pluginList = new BindingList <PluginDescription>(); List <string> osapdFiles = new List <string>(); string[] pluginFile = Directory.GetFiles(osae.APIpath + "\\AddIns", "*.osapd", SearchOption.AllDirectories); osapdFiles.AddRange(pluginFile); foreach (string path in osapdFiles) { if (!string.IsNullOrEmpty(path)) { PluginDescription desc = new PluginDescription(); desc.Deserialize(path); desc.Status = "Stopped"; desc.Enabled = false; List <OSAE.OSAEObject> objs = osae.GetObjectsByType(desc.Type); foreach (OSAE.OSAEObject o in objs) { if (osae.GetObjectPropertyValue(o.Name, "Computer Name").Value == osae.ComputerName || desc.Type == o.Name) { desc.Name = o.Name; if (o.Enabled == 1) { desc.Enabled = true; } desc.Status = o.State.Value; } } pluginList.Add(desc); } } dgLocalPlugins.ItemsSource = pluginList; }
void OnUnchecked(object sender, RoutedEventArgs e) { try { PluginDescription pd = (PluginDescription)dgLocalPlugins.SelectedItem; logging.AddToLog("unchecked: " + pd.Name, true); Thread thread = new Thread(() => messageHost(OSAEWCFMessageType.PLUGIN, "ENABLEPLUGIN|" + pd.Name + "|False")); thread.Start(); logging.AddToLog("Sending message: " + "ENABLEPLUGIN|" + pd.Name + "|False", true); if (myService.Status == ServiceControllerStatus.Running) { foreach (PluginDescription plugin in pluginList) { if (plugin.Name == pd.Name && plugin.Name != null) { plugin.Status = "Stopping..."; } } } OSAEObject obj = OSAEObjectManager.GetObjectByName(pd.Name); OSAEObjectManager.ObjectUpdate(obj.Name, obj.Name, obj.Description, obj.Type, obj.Address, obj.Container, 0); } catch (Exception ex) { logging.AddToLog("Error disabling plugin: " + ex.Message, true); } }
void OnChecked(object sender, RoutedEventArgs e) { try { PluginDescription pd = (PluginDescription)dgLocalPlugins.SelectedItem; osae.AddToLog("checked: " + pd.Name, true); if (wcfObj.State == CommunicationState.Opened) { Thread thread = new Thread(() => messageHost("plugin", "ENABLEPLUGIN|" + pd.Name + "|True")); thread.Start(); osae.AddToLog("Sending message: " + "ENABLEPLUGIN|" + pd.Name + "|True", true); if (myService.Status == ServiceControllerStatus.Running) { foreach (PluginDescription plugin in pluginList) { if (plugin.Name == pd.Name && plugin.Name != null) { plugin.Status = "Starting..."; } } } } OSAE.OSAEObject obj = osae.GetObjectByName(pd.Name); osae.ObjectUpdate(obj.Name, obj.Name, obj.Description, obj.Type, obj.Address, obj.Container, 1); } catch (Exception ex) { osae.AddToLog("Error enabling plugin: " + ex.Message, true); } }
void OnUnchecked(object sender, RoutedEventArgs e) { try { PluginDescription pd = (PluginDescription)dgLocalPlugins.SelectedItem; this.Log.Info("Updating Object: " + pd.Name + ", Setting Enabled=False"); OSAEObject obj = OSAEObjectManager.GetObjectByName(pd.Name); OSAEObjectManager.ObjectUpdate(obj.Name, obj.Name, obj.Alias, obj.Description, obj.Type, obj.Address, obj.Container, 0); // NetworkComms.SendObject("Plugin", "127.0.0.1", 10051, pd.Name + "|False"); // this.Log.Info("Sending message: " + "ENABLEPLUGIN|" + pd.Name + "|False"); // if (myService.Status == ServiceControllerStatus.Running) // { // foreach (PluginDescription plugin in pluginList) // { // if (plugin.Name == pd.Name && plugin.Name != null) // { // plugin.Status = "Stopping..."; // } // } // } } catch (Exception ex) { this.Log.Error("Error disabling plugin", ex); } }
void OnChecked(object sender, RoutedEventArgs e) { try { if (dgLocalPlugins.SelectedItem != null) { PluginDescription pd = (PluginDescription)dgLocalPlugins.SelectedItem; this.Log.Info("checked: " + pd.Name); NetworkComms.SendObject("Plugin", "127.0.0.1", 10000, pd.Name + "|True"); this.Log.Info("Sending message: " + "ENABLEPLUGIN|" + pd.Name + "|True"); if (myService.Status == ServiceControllerStatus.Running) { foreach (PluginDescription plugin in pluginList) { if (plugin.Name == pd.Name && plugin.Name != null) { plugin.Status = "Starting..."; } } } OSAEObject obj = OSAEObjectManager.GetObjectByName(pd.Name); OSAEObjectManager.ObjectUpdate(obj.Name, obj.Name, obj.Description, obj.Type, obj.Address, obj.Container, 1); } } catch (Exception ex) { this.Log.Error("Error enabling plugin ", ex); } }
/// <summary> /// Unistalls a plugin /// </summary> /// <param name="desc">The information about the plugin to be deleted</param> /// <returns>true if deleted false otherwise</returns> public bool UninstallPlugin(PluginDescription desc) { bool returnValue = false; Thread thread = new Thread(() => messageHost(OSAEWCFMessageType.PLUGIN, "ENABLEPLUGIN|" + desc.Type + "|False")); thread.Start(); Thread.Sleep(2000); string exePath = Path.GetDirectoryName(Application.ExecutablePath); string pluginFolder = exePath + "/Plugins/" + desc.Path; if (Directory.Exists(pluginFolder)) { if (deleteFolder(pluginFolder)) { returnValue = true; } else { returnValue = false; } if (Directory.Exists(pluginFolder)) { returnValue = false; } } else { returnValue = true; } return(returnValue); }
private void dgLocalPlugins_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { gbPluginInfo.Visibility = System.Windows.Visibility.Visible; DataGrid dg = (DataGrid)sender; PluginDescription p = (PluginDescription)dg.SelectedItems[0]; lblAuthor.Content = "by " + p.Author; txbkDescription.Text = p.Description; lblPluginName.Content = p.Type; lblVersion.Content = p.Version; if (p.WikiUrl != string.Empty) { hypWiki.NavigateUri = new Uri(p.WikiUrl); txblWiki.Visibility = System.Windows.Visibility.Visible; } else { txblWiki.Visibility = System.Windows.Visibility.Hidden; } string pluginPath = Common.ApiPath + "\\Plugins\\" + p.Path + "\\"; string[] paths = System.IO.Directory.GetFiles(pluginPath, "Screenshot*"); logging.AddToLog("Plugin path: " + pluginPath, true); logging.AddToLog("paths length: " + paths.Length.ToString(), true); if (paths.Length > 0) { // load the image, specify CacheOption so the file is not locked var image = new BitmapImage(); image.BeginInit(); image.CacheOption = BitmapCacheOption.OnLoad; image.UriSource = new Uri(paths[0]); image.EndInit(); imgPlugin.Stretch = Stretch.Fill; imgPlugin.Source = image; } else { imgPlugin.Source = null; } } catch (Exception ex) { logging.AddToLog("Error loading details: " + ex.Message, true); } }
private void loadPlugins() { pluginList = new BindingList <PluginDescription>(); List <string> osapdFiles = new List <string>(); string[] pluginFile = Directory.GetFiles(Common.ApiPath + "\\Plugins", "*.osapd", SearchOption.AllDirectories); osapdFiles.AddRange(pluginFile); foreach (string path in osapdFiles) { if (!string.IsNullOrEmpty(path)) { PluginDescription desc = new PluginDescription(); desc.Deserialize(path); desc.Status = "Stopped"; desc.Enabled = false; OSAEObjectCollection objs = OSAEObjectManager.GetObjectsByType(desc.Type); foreach (OSAEObject o in objs) { if (OSAEObjectPropertyManager.GetObjectPropertyValue(o.Name, "Computer Name").Value == Common.ComputerName || desc.Type == o.Name) { desc.Name = o.Name; if (o.Enabled == 1) { desc.Enabled = true; } if (o.State.Value == "ON") { desc.Status = "Running"; } else if (o.State.Value == "OFF") { desc.Status = "Stopped"; } else { desc.Status = o.State.Value; } } } pluginList.Add(desc); logging.AddToLog("Plugin found: Name:" + desc.Name + " Desc ID: " + desc.ID, true); } } dgLocalPlugins.ItemsSource = pluginList; }
/// <summary> /// Unistalls a plugin /// </summary> /// <param name="desc">The information about the plugin to be deleted</param> /// <returns>true if deleted false otherwise</returns> public static bool UninstallPlugin(PluginDescription desc) { bool returnValue = false; string exePath = Path.GetDirectoryName(Application.ExecutablePath); string pluginFolder = exePath + "/AddIns/" + desc.Path; if (Directory.Exists(pluginFolder)) { deleteFolder(pluginFolder); returnValue = true; if (Directory.Exists(pluginFolder)) { returnValue = false; } } return(returnValue); }
/// <summary> /// Unistalls a plugin /// </summary> /// <param name="desc">The information about the plugin to be deleted</param> /// <returns>true if deleted false otherwise</returns> public bool UninstallPlugin(PluginDescription desc) { bool returnValue = false; string ip = "localhost"; if (ip == "localhost") { ip = Common.LocalIPAddress(); } NetworkComms.SendObject("Plugin", ip, 10051, desc.Type + "|False"); Thread.Sleep(2000); string exePath = Path.GetDirectoryName(Application.ExecutablePath); string pluginFolder = exePath + "/Plugins/" + desc.Path; if (Directory.Exists(pluginFolder)) { if (deleteFolder(pluginFolder)) { returnValue = true; } else { returnValue = false; } if (Directory.Exists(pluginFolder)) { returnValue = false; } } else { returnValue = true; } return(returnValue); }
public bool InstallPlugin(string PluginPackagePath, ref string ErrorText) { string exePath = Path.GetDirectoryName(Application.ExecutablePath); if (Directory.Exists(exePath + "/tempDir/")) { Directory.Delete(exePath + "/tempDir/", true); } PluginDescription desc = new PluginDescription(); string tempfolder = exePath + "/tempDir/"; string zipFileName = Path.GetFullPath(PluginPackagePath); string DescPath = null; bool NoError = true; ICSharpCode.SharpZipLib.Zip.FastZip fastZip = new ICSharpCode.SharpZipLib.Zip.FastZip(); try { fastZip.ExtractZip(zipFileName, tempfolder, null); // find all included plugin descriptions and install the plugins List <string> osapdFiles = new List <string>(); List <string> sqlFiles = new List <string>(); string[] pluginFile = Directory.GetFiles(tempfolder, "*.osapd", SearchOption.TopDirectoryOnly); osapdFiles.AddRange(pluginFile); string[] sqlFile = Directory.GetFiles(tempfolder, "*.sql", SearchOption.TopDirectoryOnly); sqlFiles.AddRange(sqlFile); if (osapdFiles.Count == 0) { MessageBox.Show("No plugin description files found."); return(false); } if (osapdFiles.Count > 1) { MessageBox.Show("More than one plugin description file found."); return(false); } if (osapdFiles.Count == 1) { DescPath = osapdFiles[0]; } if (!string.IsNullOrEmpty(DescPath)) { desc.Deserialize(DescPath); //NoError = desc.VerifyInstall(ref ErrorText); //uninstall previous plugin and delete the folder if (UninstallPlugin(desc)) { // get the plugin folder path string pluginFolder = desc.Path; if (!string.IsNullOrEmpty(pluginFolder)) //only extract valid plugins { string[] files = System.IO.Directory.GetFiles(tempfolder); string ConnectionString = string.Format("Uid={0};Pwd={1};Server={2};Port={3};Database={4};allow user variables=true", Common.DBUsername, Common.DBPassword, Common.DBConnection, Common.DBPort, Common.DBName); MySql.Data.MySqlClient.MySqlConnection connection = new MySql.Data.MySqlClient.MySqlConnection(ConnectionString); connection.Open(); foreach (string s in sqlFile) { try { MySql.Data.MySqlClient.MySqlScript script = new MySql.Data.MySqlClient.MySqlScript(connection, File.ReadAllText(s)); script.Execute(); } catch (Exception ex) { this.Log.Error("Error running sql script: " + s, ex); } } System.IO.Directory.Move(tempfolder, exePath + "/Plugins/" + pluginFolder); //Check if we are running a x64 bit architecture (This is a silly way to do it since I am not sure if every 64 bit machine has this directory...) bool is64bit = Environment.Is64BitOperatingSystem; //Do a check for any x64 assemblies, and prompt the user to install them if they are running a 64 bit machine if (is64bit && (desc.x64Assemblies.Count > 0)) { /* x64 assemblies generally have the same name as their x32 counterparts when referenced by the OSA app * however they are packaged as "filename.ext.x64" so we will replace the 32bit file which is installed by * default with the 64bit versioin with the same filename.ext */ if (MessageBox.Show( "You are running an x64 architecture and this plugin has specific assemblies built for 64bit machines." + " It is highly recommended that you install the 64bit versions to ensure proper compatibility", "Install 64bit Assemblies?", MessageBoxButtons.YesNo) == DialogResult.Yes) { //Install the 64bit assemblies over the 32 bit ones... string[] x64files = System.IO.Directory.GetFiles(exePath + "/Plugins/" + pluginFolder, "*.x64"); foreach (string str in x64files) { string destFile = System.IO.Path.Combine(exePath + "/Plugins/" + pluginFolder + "/", System.IO.Path.GetFileNameWithoutExtension(str)); //Copy it to the new destination overwriting the old file if it exists System.IO.File.Copy(str, destFile, true); } } } //Delete all the files with .x64 extensions since they aren't needed anymore string[] delfiles = System.IO.Directory.GetFiles(exePath + "/Plugins/" + pluginFolder, "*.x64"); foreach (string str in delfiles) { System.IO.File.Delete(str); } this.Log.Info("Sending message to service to load plugin."); } } else { return(false); } } } catch (Exception ex) { MessageBox.Show("catch: " + ex.Message); return(false); } if (Directory.Exists(exePath + "/tempDir/")) { deleteFolder(exePath + "/tempDir/"); } OSAEMethodManager.MethodQueueAdd("SERVICE-" + Common.ComputerName, "RELOAD PLUGINS", "", "", "Plugin Installer"); return(NoError); }
public static bool InstallPlugin(string PluginPackagePath, ref string ErrorText) { OSAE.OSAE osae = new OSAE.OSAE("Plugin Installer"); string exePath = Path.GetDirectoryName(Application.ExecutablePath); if (Directory.Exists(exePath + "/tempDir/")) { Directory.Delete(exePath + "/tempDir/", true); } PluginDescription desc = new PluginDescription(); string tempfolder = exePath + "/tempDir/"; string zipFileName = Path.GetFullPath(PluginPackagePath); string DescPath = null; bool NoError = true; FastZip fastZip = new FastZip(); //try //{ fastZip.ExtractZip(zipFileName, tempfolder, null); // find all included plugin descriptions and install the plugins List<string> osapdFiles = new List<string>(); List<string> sqlFiles = new List<string>(); string[] pluginFile = Directory.GetFiles(tempfolder, "*.osapd", SearchOption.TopDirectoryOnly); osapdFiles.AddRange(pluginFile); string[] sqlFile = Directory.GetFiles(tempfolder, "*.sql", SearchOption.TopDirectoryOnly); sqlFiles.AddRange(sqlFile); if (osapdFiles.Count == 0) { MessageBox.Show("No plugin description files found."); return false; } if (osapdFiles.Count > 1) { MessageBox.Show("More than one plugin description file found."); return false; } if (osapdFiles.Count == 1) { DescPath = osapdFiles[0]; } if (!string.IsNullOrEmpty(DescPath)) { desc.Deserialize(DescPath); //NoError = desc.VerifyInstall(ref ErrorText); //uninstall previous plugin and delete the folder bool u = UninstallPlugin(desc); // get the plugin folder path string pluginFolder = desc.Path; if (!string.IsNullOrEmpty(pluginFolder)) //only extract valid plugins { //Directory.CreateDirectory(exePath + "/Plugins/" + pluginFolder); string[] files = System.IO.Directory.GetFiles(tempfolder); // Copy the files and overwrite destination files if they already exist. //foreach (string s in files) //{ // string fileName = System.IO.Path.GetFileName(s); // if (desc.AdditionalAssemblies.Contains(fileName)) // { // string destFile = System.IO.Path.Combine(exePath + "/", fileName); // System.IO.File.Copy(s, destFile, true); // } //} string ConnectionString = string.Format("Uid={0};Pwd={1};Server={2};Port={3};Database={4};allow user variables=true", osae.DBUsername, osae.DBPassword, osae.DBConnection, osae.DBPort, osae.DBName); MySql.Data.MySqlClient.MySqlConnection connection = new MySql.Data.MySqlClient.MySqlConnection(ConnectionString); connection.Open(); foreach (string s in sqlFile) { try { MySql.Data.MySqlClient.MySqlScript script = new MySql.Data.MySqlClient.MySqlScript(connection,File.ReadAllText(s)); script.Execute(); } catch (Exception ex) { osae.AddToLog("Error running sql script: " + s + " | " + ex.Message, true); } } System.IO.Directory.Move(tempfolder, exePath + "/AddIns/" + pluginFolder); //Check if we are running a x64 bit architecture (This is a silly way to do it since I am not sure if every 64 bit machine has this directory...) bool is64bit = Environment.Is64BitOperatingSystem; //Do a check for any x64 assemblies, and prompt the user to install them if they are running a 64 bit machine if (is64bit && (desc.x64Assemblies.Count > 0)) { /* x64 assemblies generally have the same name as their x32 counterparts when referenced by the OSA app * however they are packaged as "filename.ext.x64" so we will replace the 32bit file which is installed by * default with the 64bit versioin with the same filename.ext */ if (MessageBox.Show( "You are running an x64 architecture and this plugin has specific assemblies built for 64bit machines." + " It is highly recommended that you install the 64bit versions to ensure proper compatibility", "Install 64bit Assemblies?", MessageBoxButtons.YesNo) == DialogResult.Yes) { //Install the 64bit assemblies over the 32 bit ones... string[] x64files = System.IO.Directory.GetFiles(exePath + "/AddIns/" + pluginFolder, "*.x64"); foreach (string str in x64files) { string destFile = System.IO.Path.Combine(exePath + "/AddIns/" + pluginFolder + "/", System.IO.Path.GetFileNameWithoutExtension(str)); //Copy it to the new destination overwriting the old file if it exists System.IO.File.Copy(str, destFile, true); } } } //Delete all the files with .x64 extensions since they aren't needed anymore string[] delfiles = System.IO.Directory.GetFiles(exePath + "/AddIns/" + pluginFolder, "*.x64"); foreach (string str in delfiles) System.IO.File.Delete(str); osae.AddToLog("Sending message to service to load plugin.", true); using (MySql.Data.MySqlClient.MySqlCommand command = new MySql.Data.MySqlClient.MySqlCommand()) { command.CommandText = "CALL osae_sp_method_queue_add (@pobject,@pmethod,@pparameter1,@pparameter2,@pfromobject,@pdebuginfo);"; command.Parameters.AddWithValue("@pobject", "SERVICE-" + osae.ComputerName); command.Parameters.AddWithValue("@pmethod", "LOAD PLUGIN"); command.Parameters.AddWithValue("@pparameter1", ""); command.Parameters.AddWithValue("@pparameter2", ""); command.Parameters.AddWithValue("@pfromobject", ""); command.Parameters.AddWithValue("@pdebuginfo", ""); try { osae.RunQuery(command); } catch (Exception ex) { osae.AddToLog("Error adding LOAD PLUGIN method: " + command.CommandText + " - error: " + ex.Message, true); } } } } //} //catch (Exception ex) //{ // MessageBox.Show("catch: " + ex.Message); // return false; //} if (Directory.Exists(exePath + "/tempDir/")) { deleteFolder(exePath + "/tempDir/"); } osae.MethodQueueAdd("SERVICE-" + osae.ComputerName, "RELOAD PLUGINS", "", ""); return NoError; }
/// <summary> /// Unistalls a plugin /// </summary> /// <param name="desc">The information about the plugin to be deleted</param> /// <returns>true if deleted false otherwise</returns> public static bool UninstallPlugin(PluginDescription desc) { bool returnValue = false; string exePath = Path.GetDirectoryName(Application.ExecutablePath); string pluginFolder = exePath + "/AddIns/" + desc.Path; if (Directory.Exists(pluginFolder)) { deleteFolder(pluginFolder); returnValue = true; if (Directory.Exists(pluginFolder)) returnValue = false; } return returnValue; }
private void loadPlugins() { pluginList = new BindingList<PluginDescription>(); List<string> osapdFiles = new List<string>(); string[] pluginFile = Directory.GetFiles(osae.APIpath + "\\AddIns", "*.osapd", SearchOption.AllDirectories); osapdFiles.AddRange(pluginFile); foreach (string path in osapdFiles) { if (!string.IsNullOrEmpty(path)) { PluginDescription desc = new PluginDescription(); desc.Deserialize(path); desc.Status = "Stopped"; desc.Enabled = false; List<OSAE.OSAEObject> objs = osae.GetObjectsByType(desc.Type); foreach (OSAE.OSAEObject o in objs) { if (osae.GetObjectPropertyValue(o.Name, "Computer Name").Value == osae.ComputerName || desc.Type == o.Name) { desc.Name = o.Name; if (o.Enabled == 1) desc.Enabled = true; desc.Status = o.State.Value; } } pluginList.Add(desc); } } dgLocalPlugins.ItemsSource = pluginList; }
private void loadPlugins() { pluginList = new BindingList <PluginDescription>(); List <string> osapdFiles = new List <string>(); string[] pluginFile = Directory.GetFiles(Common.ApiPath + "\\Plugins", "*.osapd", SearchOption.AllDirectories); osapdFiles.AddRange(pluginFile); bool bFoundObject = false; foreach (string path in osapdFiles) { if (!string.IsNullOrEmpty(path)) { bFoundObject = false; PluginDescription desc = new PluginDescription(); desc.Deserialize(path); desc.Status = "No Object"; desc.Enabled = false; this.Log.Info(desc.Type + ": Plugin DLL found, Desc ID = " + desc.ID); OSAEObjectCollection objs = OSAEObjectManager.GetObjectsByType(desc.Type); foreach (OSAEObject o in objs) { if (OSAEObjectPropertyManager.GetObjectPropertyValue(o.Name, "Computer Name").Value == Common.ComputerName || desc.Type == o.Name) { desc.Name = o.Name; bFoundObject = true; if (o.Enabled == 1) { desc.Enabled = true; } if (o.State.Value == "ON") { desc.Status = "Running"; } else if (o.State.Value == "OFF") { desc.Status = "Stopped"; } else { desc.Status = o.State.Value; } this.Log.Info(desc.Type + ": Plugin Object found, Object Name = " + o.Name); pluginList.Add(desc); } } // Here we try to create the Object if none was found above, we need a valid Object Type for this. if (bFoundObject == false) { this.Log.Info(desc.Type + ": Plugin Object Missing!"); bool bObjectTypeExists = OSAEObjectTypeManager.ObjectTypeExists(desc.Type); if (bObjectTypeExists) { this.Log.Info(desc.Type + ": Valid Object Type found. Attempting to create Object..."); OSAEObjectManager.ObjectAdd(desc.Type, desc.Type, desc.Type + " plugin's Object", desc.Type, "", "SYSTEM", false); OSAEObject obj = OSAEObjectManager.GetObjectByName(desc.Type); if (obj != null) { desc.Name = obj.Name; desc.Enabled = false; if (obj.State.Value == "ON") { desc.Status = "Running"; } else if (obj.State.Value == "OFF") { desc.Status = "Stopped"; } else { desc.Status = obj.State.Value; } this.Log.Info(desc.Type + ": Plugin Object now found!"); pluginList.Add(desc); } } else { this.Log.Info(desc.Type + ": NO Valid Object Type found! I cannot create an Object! Please run Install.sql for this plugin."); } } } } dgLocalPlugins.ItemsSource = pluginList; }