private void OnPluginConnected(PluginInstance pluginInstance, ISMAPlugin plugin) { LogTo.Information($"Connected {pluginInstance.Denomination} {pluginInstance.Package.Id}."); pluginInstance.OnConnected(plugin); }
public CollectionConfigurationService(SMCollection collection, ISMAPlugin plugin) { _collection = collection; _subDir = plugin.AssemblyName; EnsureFolderExists(); }
/// <inheritdoc /> public string GetPluginResourcePath(ISMAPlugin plugin) { var path = SMA.Collection.GetSMAPluginsFolder(plugin); DirectoryEx.EnsureExists(path); return(path); }
public static string GetSMAPluginsFilePath( this SMCollection collection, ISMAPlugin plugin, string fileName) { return(collection.GetFilePath(SMAConst.Paths.CollectionSMAFolder, SMAConst.Paths.CollectionPluginsFolder, plugin.Id.ToString("D"), fileName)); }
public static string GetSMAPluginsFolder( this SMCollection collection, ISMAPlugin plugin = null) { return(plugin != null ? collection.GetFilePath(SMAConst.Paths.CollectionSMAFolder, SMAConst.Paths.CollectionPluginsFolder, plugin.Id.ToString("D")) : collection.GetFilePath(SMAConst.Paths.CollectionSMAFolder, SMAConst.Paths.CollectionPluginsFolder)); }
public void OnConnected(ISMAPlugin plugin) { Status = PluginStatus.Connected; Plugin = plugin; if (Metadata.IsDevelopment) { Metadata.DisplayName = plugin.Name; } ConnectedEvent.Set(); }
/// <inheritdoc /> public CollectionFile Create(ISMAPlugin plugin, int elementId, Action <Stream> streamWriter, string extension, string crc32 = null) { return(Service.Create(plugin, elementId, streamWriter, extension, crc32)); }
private static FileStream EnsurePluginConf(ISMAPlugin plugin, Type confType, FileAccess fileAccess) { string filePath = Path.Combine(SMAConst.Paths.ConfigPath, plugin.Id.ToString("D")); if (!DirectoryEx.EnsureExists(filePath)) { return(null); } filePath = Path.Combine(filePath, confType.Name); return(File.Open(filePath, fileAccess == FileAccess.Read ? FileMode.OpenOrCreate : FileMode.Create, fileAccess)); }
private static async Task <T> Load <T>(ISMAPlugin requester) { try { using (var stream = EnsurePluginConf(requester, typeof(T), FileAccess.Read)) using (var reader = new StreamReader(stream)) return(JsonConvert.DeserializeObject <T>(await reader.ReadToEndAsync().ConfigureAwait(false))); } catch (Exception ex) { // TODO: Log return(default(T)); } }
/// <inheritdoc /> public int DeleteByElementId(int elementId, ISMAPlugin plugin = null) { Query query = Query.EQ("ElementId", elementId); if (plugin != null) { query = Query.And(query, Query.EQ("PluginId", plugin.Id)); } return(Delete(DbFiles.Find(query))); }
public IEnumerable <CollectionFile> ForElement(int elementId, ISMAPlugin plugin = null) { Query query = Query.EQ("ElementId", elementId); if (plugin != null) { query = Query.And(query, Query.EQ("PluginId", plugin.Id)); } return(DbFiles.Find(query).Select(FromDbFile)); }
private static async Task <bool> Save <T>(ISMAPlugin requester, T config) { try { using (var stream = EnsurePluginConf(requester, typeof(T), FileAccess.Write)) using (var writer = new StreamWriter(stream)) await writer.WriteAsync(JsonConvert.SerializeObject(config, Formatting.Indented)).ConfigureAwait(false); return(true); } catch (Exception ex) { // TODO: Log return(false); } }
public bool InjectPropertyDependencies(ISMAPlugin plugin, ISuperMemoAssistant sma, ISMAPluginManager pluginMgr, Guid sessionGuid, bool isDevelopment) { bool smaSet = false; bool mgrSet = false; bool guidSet = false; var type = plugin.GetType(); while (type != null && type != typeof(ISMAPlugin)) { var props = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (var prop in props) { if (SMAInterfaceTypes.Contains(prop.PropertyType)) { prop.SetValue(plugin, sma /*Convert.ChangeType(sma, prop.PropertyType)*/); smaSet = true; } else if (PluginMgrInterfaceTypes.Contains(prop.PropertyType)) { prop.SetValue(plugin, pluginMgr /*Convert.ChangeType(pluginMgr, prop.PropertyType)*/); mgrSet = true; } else if (prop.PropertyType == typeof(Guid)) { prop.SetValue(plugin, sessionGuid); guidSet = true; } else if (prop.PropertyType == typeof(bool) && prop.Name is "IsDevelopmentPlugin") { prop.SetValue(plugin, isDevelopment); } } type = type.BaseType; } return(smaSet && mgrSet && guidSet); }
/// <inheritdoc /> public int DeleteByElementId(int elementId, ISMAPlugin plugin = null) { return(Service.DeleteByElementId(elementId, plugin)); }
public ConfigurationService(ISMAPlugin plugin) { Plugin = plugin; }
/// <inheritdoc /> public int DeleteByPlugin(ISMAPlugin plugin = null) { return(Service.DeleteByPlugin(plugin ?? Plugin)); }
public PluginConfigurationService(ISMAPlugin plugin) { Plugin = plugin; EnsureFolderExists(); }
public PluginHost( string pluginPackageName, Guid sessionGuid, string smaChannelName, Process smaProcess, bool isDev) { // Connect to SMA var pluginMgr = RemotingServicesEx.ConnectToIpcServer <ISMAPluginManager>(smaChannelName); if (pluginMgr == null) { Exit(HostConst.ExitIpcConnectionError); return; } // Get required assemblies name IEnumerable <string> pluginAssemblies; IEnumerable <string> dependenciesAssemblies; if (isDev) { var homePath = new DirectoryPath(AppDomain.CurrentDomain.BaseDirectory); var pluginFilePath = homePath.CombineFile(pluginPackageName + ".dll"); pluginAssemblies = new List <string> { pluginFilePath.FullPath }; dependenciesAssemblies = new List <string>(); } else if (pluginMgr.GetAssembliesPathsForPlugin( sessionGuid, out pluginAssemblies, out dependenciesAssemblies) == false) { Exit(HostConst.ExitCouldNotGetAssembliesPaths); return; } // Setup assembly resolution AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve; // Load & create plugin _plugin = LoadAssembliesAndCreatePluginInstance( dependenciesAssemblies, pluginAssemblies); if (_plugin == null) { Exit(HostConst.ExitNoPluginTypeFound); return; } // Connect plugin to SMA var sma = pluginMgr.ConnectPlugin( _plugin.ChannelName, sessionGuid); if (sma == null) { Exit(HostConst.ExitCouldNotConnectPlugin); return; } // Inject properties InjectPropertyDependencies(_plugin, sma, pluginMgr, sessionGuid, isDev); _plugin.OnInjected(); // Start monitoring SMA process if (StartMonitoringSMAProcess(smaProcess) == false) { Exit(HostConst.ExitParentExited); } }
public PluginCollectionFSService(ISMAPlugin plugin, ICollectionFSService service) { Plugin = plugin; Service = service; }
/// <inheritdoc /> public string GetPluginResourcePath(ISMAPlugin plugin) { return(Service.GetPluginResourcePath(plugin)); }
/// <inheritdoc /> public IEnumerable <CollectionFile> ForElement(int elementId, ISMAPlugin plugin = null) { return(Service.ForElement(elementId, plugin)); }
/// <inheritdoc /> public IEnumerable <CollectionFile> ForPlugin(ISMAPlugin plugin = null) { return(Service.ForPlugin(plugin ?? Plugin)); }
/// <inheritdoc /> public int DeleteByPlugin([NotNull] ISMAPlugin plugin) { return(Delete(DbFiles.Find(f => f.PluginId == plugin.Id))); }
public CollectionFile Create( [NotNull] ISMAPlugin requester, int elementId, [NotNull] Action <Stream> streamWriter, string extension, string crc32 = null) { if (elementId <= 0) { return(null); } CollectionFSFile dbFile = null; try { extension = extension?.TrimStart('.'); dbFile = new CollectionFSFile { ElementId = elementId, Extension = extension ?? string.Empty, PluginId = requester.Id }; dbFile.Id = DbFiles.Insert(dbFile).AsInt32; CollectionFile colFile = FromDbFile(dbFile); DirectoryEx.EnsureExists(Path.GetDirectoryName(colFile.Path)); using (var stream = File.Open(colFile.Path, System.IO.FileMode.Create, FileAccess.ReadWrite)) streamWriter(stream); if (crc32 != null) { var fsCrc32 = FileEx.GetCrc32(colFile.Path); if (fsCrc32 != crc32) { throw new IOException($"CRC32 did not match for file {colFile.Path}. Expected {crc32}, got {fsCrc32}"); } } return(colFile); } catch (Exception ex) { LogTo.Error(ex, "CollectionFS: Create threw an exception."); try { if (dbFile != null) { DbFiles.Delete(dbFile.Id); } } catch (Exception dbEx) { LogTo.Error(dbEx, "CollectionFS: Create threw an exception. Exception's DB cleanup code threw an exception"); } throw; } }
/// <inheritdoc /> public IEnumerable <CollectionFile> ForPlugin([NotNull] ISMAPlugin plugin) { return(DbFiles.Find(f => f.PluginId == plugin.Id).Select(FromDbFile)); }
public static LiteDatabase OpenDatabase(SMCollection collection, ISMAPlugin plugin) { var dbPath = collection.GetSMAPluginsFilePath(plugin, SMAConst.Files.CollectionPluginDatabaseFileName); return(new LiteDatabase(dbPath)); }