private ParseFileResult ParseEntry(ZipArchiveEntry entry, IFieldDataPlugin plugin, LocationInfo locationInfo) { using (var entryStream = entry.Open()) using (var reader = new BinaryReader(entryStream)) using (var memoryStream = new MemoryStream(reader.ReadBytes((int)entry.Length))) { var proxyLog = ProxyLog.Create(Log, plugin, entry); var result = locationInfo == null ? plugin.ParseFile(memoryStream, ResultsAppender, proxyLog) : plugin.ParseFile(memoryStream, locationInfo, ResultsAppender, proxyLog); switch (result.Status) { case ParseFileStatus.CannotParse: result = ParseFileResult.CannotParse($"{proxyLog.Prefix}: {result.ErrorMessage}"); break; case ParseFileStatus.SuccessfullyParsedButDataInvalid: result = ParseFileResult.SuccessfullyParsedButDataInvalid($"{proxyLog.Prefix}: {result.ErrorMessage}"); break; } return(result); } }
public static string GetPluginFolderName(IFieldDataPlugin plugin) { var folder = Path.GetDirectoryName(plugin.GetType().Assembly.Location); // ReSharper disable once AssignNullToNotNullAttribute return(new DirectoryInfo(folder) .Name); }
private Dictionary <string, string> GetPluginSettings(IFieldDataPlugin plugin) { var pluginFolderName = PluginLoader.GetPluginFolderName(plugin); if (Context.PluginSettings.TryGetValue(pluginFolderName, out var settings)) { return(settings); } var targetSettingGroup = $"FieldDataPluginConfig-{pluginFolderName}"; // We ask for all settings and filter the results in-memory to avoid a 404 GroupNameNotFound exception when no configuration exist return(Client.Provisioning.Get(new GetSettings()) .Results .Where(setting => setting.Group.Equals(targetSettingGroup, StringComparison.InvariantCultureIgnoreCase)) .ToDictionary( setting => setting.Key, setting => setting.Value, StringComparer.InvariantCultureIgnoreCase)); }
private void ResolveAssemblyPath() { AllowReflectionLoadsFromAssemblyFolder(); if (!string.IsNullOrEmpty(Context.AssemblyPath)) { var assembly = LoadAssembly(Context.AssemblyPath, message => Log.Error($"Can't load '{Context.AssemblyPath}': {message}")); if (assembly == null) { throw new ExpectedException($"Can't load plugin assembly."); } Plugin = FindAllPluginImplementations(assembly).Single(); return; } Plugin = GetSinglePluginOrThrow(); Context.AssemblyPath = Plugin.GetType().GetAssemblyPath(); }
public static ProxyLog Create(ILog log, IFieldDataPlugin plugin, ZipArchiveEntry entry) { return(new ProxyLog(log, plugin, entry)); }
private ProxyLog(ILog log, IFieldDataPlugin plugin, ZipArchiveEntry entry) { Log = log; Prefix = $"{PluginLoader.GetPluginNameAndVersion(plugin)} - '{entry.FullName}'"; }
public LoadedPlugin(IFieldDataPlugin plugin, PluginManifest manifest, string path) { Plugin = plugin; Manifest = manifest; Path = path; }
public static string GetPluginNameAndVersion(IFieldDataPlugin plugin) { var pluginType = plugin.GetType(); return($"{pluginType.FullName} v{GetTypeVersion(pluginType)}"); }
public LoadedPlugin(IFieldDataPlugin plugin, PluginManifest manifest) { Plugin = plugin; Manifest = manifest; }