/// <summary> /// Gets the plugin by view type. /// </summary> public bool GetPluginByViewType(Type viewType, out PluginLogic pluginLogic) { if (viewType == null) { pluginLogic = null; return(false); } else { return(pluginByViewType.TryGetValue(viewType.FullName, out pluginLogic)); } }
/// <summary> /// Gets the plugin by code. /// </summary> public bool GetPlugin(string pluginCode, out PluginLogic pluginLogic) { if (string.IsNullOrEmpty(pluginCode)) { pluginLogic = null; return(false); } else { return(pluginMap.TryGetValue(pluginCode, out pluginLogic)); } }
/// <summary> /// Calls the GetUserReports method of the specified plugin. /// </summary> public List <MenuItem> GetUserReports(PluginLogic pluginLogic, User user, UserRights userRights) { ArgumentNullException.ThrowIfNull(pluginLogic, nameof(pluginLogic)); lock (pluginLock) { try { return(pluginLogic.GetUserReports(user, userRights)); } catch (Exception ex) { log.WriteError(ex, WebPhrases.ErrorInPlugin, nameof(GetUserReports), pluginLogic.Code); return(null); } } }
/// <summary> /// Adds the specified plugin to the lists. /// </summary> public void AddPlugin(PluginLogic pluginLogic) { ArgumentNullException.ThrowIfNull(pluginLogic, nameof(pluginLogic)); if (pluginMap.ContainsKey(pluginLogic.Code)) { log.WriteError(Locale.IsRussian ? "Невозможно добавить плагин с кодом {0}. Он уже существует." : "Unable to add plugin with code {0}. It already exists.", pluginLogic.Code); return; } plugins.Add(pluginLogic); pluginMap.Add(pluginLogic.Code, pluginLogic); if (pluginLogic.ViewSpecs != null) { foreach (ViewSpec viewSpec in pluginLogic.ViewSpecs) { if (!string.IsNullOrEmpty(viewSpec.TypeCode) && !viewSpecByCode.ContainsKey(viewSpec.TypeCode)) { viewSpecByCode.Add(viewSpec.TypeCode, viewSpec); } if (!string.IsNullOrEmpty(viewSpec.FileExtension)) { string ext = viewSpec.FileExtension.ToLowerInvariant(); if (!viewSpecByExt.ContainsKey(ext)) { viewSpecByExt.Add(ext, viewSpec); } } if (viewSpec.ViewType != null && !pluginByViewType.ContainsKey(viewSpec.ViewType.FullName)) { pluginByViewType.Add(viewSpec.ViewType.FullName, pluginLogic); } } } }
/// <summary> /// Gets a new instance of the plugin logic. /// </summary> public static bool GetPluginLogic(string directory, string pluginCode, IWebContext webContext, out PluginLogic pluginLogic, out string message) { string fileName = Path.Combine(directory, pluginCode + ".dll"); string typeName = string.Format("Scada.Web.Plugins.{0}.{0}Logic", pluginCode); try { if (File.Exists(fileName)) { Assembly assembly = Assembly.LoadFrom(fileName); Type type = assembly.GetType(typeName, true); pluginLogic = (PluginLogic)Activator.CreateInstance(type, webContext); message = string.Format(Locale.IsRussian ? "Плагин {0} {1} загружен из файла {2}" : "Plugin {0} {1} loaded from file {2}", pluginCode, assembly.GetName().Version, fileName); return(true); } else { pluginLogic = null; message = string.Format(Locale.IsRussian ? "Невозможно создать логику плагина {0}. Файл {1} не найден" : "Unable to create plugin logic {0}. File {1} not found", pluginCode, fileName); return(false); } } catch (Exception ex) { pluginLogic = null; message = string.Format(Locale.IsRussian ? "Ошибка при создании логики плагина {0} типа {1} из файла {2}: {3}" : "Error creating plugin logic {0} of type {1} from file {2}: {3}", pluginCode, typeName, fileName, ex.Message); return(false); } }