public Plugin(string assemblyName, string assemblyType, AppDomain domain, string location, string clientAppendage = "") { PluginDescription desc = new PluginDescription(); List <string> osapdFiles = new List <string>(); string[] pluginFile = Directory.GetFiles(location, "*.osapd", SearchOption.AllDirectories); osapdFiles.AddRange(pluginFile); foreach (string path in osapdFiles) { if (!string.IsNullOrEmpty(path)) { desc = new PluginDescription(); desc.Deserialize(path); _pluginVersion = desc.Version; _pluginAuthor = desc.Author; } } _pluginType = desc.Type; //the following won't work, it is just whether it is a cient or not _pluginName = _pluginType; if (clientAppendage.Length > 0) { _pluginName = _pluginName + "-" + clientAppendage; } _assemblyType = assemblyType; _assemblyName = assemblyName; _domain = domain; _location = location; _latestAvailableVersion = ""; }
public OSAEUserControl(string assemblyName, string assemblyType, AppDomain domain, string location) { PluginDescription desc = new PluginDescription(); List<string> osaudFiles = new List<string>(); string[] pluginFile = Directory.GetFiles(location, "*.osaud", SearchOption.AllDirectories); osaudFiles.AddRange(pluginFile); foreach (string path in osaudFiles) { if (!string.IsNullOrEmpty(path)) { desc = new PluginDescription(); desc.Deserialize(path); _userControlVersion = desc.Version; } } _userControlType = desc.Type; _userControlName = PluginManager.GetPluginName(_userControlType, Common.ComputerName); _assemblyType = assemblyType; _assemblyName = assemblyName; _domain = domain; _latestAvailableVersion = string.Empty; }
public Plugin(string assemblyName, string assemblyType, AppDomain domain, string location) { PluginDescription desc = new PluginDescription(); List <string> osapdFiles = new List <string>(); string[] pluginFile = Directory.GetFiles(location, "*.osapd", SearchOption.AllDirectories); osapdFiles.AddRange(pluginFile); foreach (string path in osapdFiles) { if (!string.IsNullOrEmpty(path)) { desc = new PluginDescription(); desc.Deserialize(path); _pluginVersion = desc.Version; } } _pluginType = desc.Type; _pluginName = PluginManager.GetPluginName(_pluginType, Common.ComputerName); _assemblyType = assemblyType; _assemblyName = assemblyName; _domain = domain; _location = location; _latestAvailableVersion = string.Empty; }
public OSAEUserControl(string assemblyName, string assemblyType, AppDomain domain, string location) { PluginDescription desc = new PluginDescription(); List <string> osaudFiles = new List <string>(); string[] pluginFile = Directory.GetFiles(location, "*.osaud", SearchOption.AllDirectories); osaudFiles.AddRange(pluginFile); foreach (string path in osaudFiles) { if (!string.IsNullOrEmpty(path)) { desc = new PluginDescription(); desc.Deserialize(path); _userControlVersion = desc.Version; } } _userControlType = desc.Type; _userControlName = _userControlType; _assemblyType = assemblyType; _assemblyName = assemblyName; _domain = domain; _latestAvailableVersion = string.Empty; }
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; desc.Status = o.State.Value; } } pluginList.Add(desc); //logging.AddToLog("Plugin found: Name:" + desc.Name + " Desc ID: " + desc.ID, true); } } gvPlugins.DataSource = pluginList; gvPlugins.DataBind(); }
public Plugin(string assemblyName, string assemblyType, AppDomain domain, string location, string clientAppendage = "") { PluginDescription desc = new PluginDescription(); List<string> osapdFiles = new List<string>(); string[] pluginFile = Directory.GetFiles(location, "*.osapd", SearchOption.AllDirectories); osapdFiles.AddRange(pluginFile); foreach (string path in osapdFiles) { if (!string.IsNullOrEmpty(path)) { desc = new PluginDescription(); desc.Deserialize(path); _pluginVersion = desc.Version; _pluginAuthor = desc.Author; } } _pluginType = desc.Type; //the following won't work, it is just whether it is a cient or not _pluginName = _pluginType; if (clientAppendage.Length > 0) _pluginName = _pluginName + "-" + clientAppendage; _assemblyType = assemblyType; _assemblyName = assemblyName; _domain = domain; _location = location; _latestAvailableVersion = ""; }
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; if (desc.WikiUrl.Trim() == "") { desc.WikiUrl = "http://www.opensourceautomation.com/wiki/index.php?title=Plugins"; } 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 desc.Status = "Stopped"; } } pluginList.Add(desc); Log.Info("Plugin found: Name:" + desc.Name + " Desc ID: " + desc.ID); } } // TODO: Load all other objects with base type of PLUGIN. These objects represent plugins on client instances. Maybe make a separate grid since it wont be able to load the osapd files on the clients checkForUpdates(); gvPlugins.DataSource = pluginList; gvPlugins.DataBind(); }
private List<string> GetInstalledPlugins() { List<string> pluginNames = new List<string>(); 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); pluginNames.Add(desc.Type); } } return pluginNames; }
public bool InstallPlugin(string PluginPackagePath, ref string ErrorText) { string exePath = OSAE.Common.ApiPath; 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> osaudFiles = new List<string>(); List<string> sqlFiles = new List<string>(); List<string> ctrlFiles = new List<string>(); List<string> aspcsFiles = new List<string>(); string[] pluginFile = Directory.GetFiles(tempfolder, "*.osaud", SearchOption.TopDirectoryOnly); osaudFiles.AddRange(pluginFile); string[] sqlFile = Directory.GetFiles(tempfolder, "*.sql", SearchOption.TopDirectoryOnly); sqlFiles.AddRange(sqlFile); string[] ctrlFile = Directory.GetFiles(tempfolder, "*.ascx", SearchOption.TopDirectoryOnly); ctrlFiles.AddRange(ctrlFile); string[] aspcsFile = Directory.GetFiles(tempfolder, "*.ascx.cs", SearchOption.TopDirectoryOnly); aspcsFiles.AddRange(aspcsFile); if (osaudFiles.Count == 0) { MessageBox.Show("No User Control description files found."); return false; } if (osaudFiles.Count > 1) { MessageBox.Show("More than one User Control description file found."); return false; } if (ctrlFiles.Count == 0 || aspcsFiles.Count == 0) { MessageBox.Show("No WebUI User Control Files found."); return false; } if (osaudFiles.Count == 1) DescPath = osaudFiles[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) { Log.Error("Error running sql script: " + s, ex); } } string newControlFolder = exePath +"/UserControls/" + pluginFolder; System.IO.Directory.Move(tempfolder, newControlFolder); if(ctrlFiles.Count > 0 && aspcsFiles.Count > 0) { string newWebUIFolder = exePath + "/Plugins/Web Server/wwwroot/controls/usercontrols/" + pluginFolder; System.IO.Directory.CreateDirectory(newWebUIFolder); System.IO.File.Move(newControlFolder + "/ctrlUserControl.ascx",newWebUIFolder + "/ctrlUserControl.ascx"); System.IO.File.Move(newControlFolder + "/ctrlUserControl.ascx.cs", newWebUIFolder + "/ctrlUserControl.ascx.cs"); } //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 + "/UserControls/" + pluginFolder, "*.x64"); foreach (string str in x64files) { string destFile = System.IO.Path.Combine(exePath + "/UserControls/" + 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 + "/UserControls/" + pluginFolder, "*.x64"); foreach (string str in delfiles) System.IO.File.Delete(str); } } else return false; } } catch (Exception ex) { MessageBox.Show("catch: " + ex.Message); return false; } if (Directory.Exists(exePath + "/tempDir/")) deleteFolder(exePath + "/tempDir/"); return NoError; }