private EltraPluginCacheItem FindPluginInFileSystem(DeviceToolPayload payload) { EltraPluginCacheItem result = null; var pluginFilePath = GetPluginFilePath(GetPluginFileName(payload.Id)); try { if (File.Exists(pluginFilePath)) { if (payload.Mode == DeviceToolPayloadMode.Development) { result = UpdateCache(payload, pluginFilePath); } else { if (GetHashCodeFromFile(pluginFilePath, out var hashCode) && hashCode == payload.HashCode) { result = UpdateCache(payload, pluginFilePath); } } } } catch (Exception e) { MsgLogger.Exception($"{GetType().Name} - FindPluginInFileSystem", e); } return(result); }
private EltraPluginCacheItem FindPluginInCache(DeviceToolPayload payload) { EltraPluginCacheItem result = null; foreach (var pluginCacheItem in PluginCache) { if (payload.Mode == DeviceToolPayloadMode.Development) { if (pluginCacheItem.PayloadId == payload.Id) { result = pluginCacheItem; break; } } else { if (pluginCacheItem.HashCode == payload.HashCode) { result = pluginCacheItem; break; } } } return(result); }
internal async Task <bool> PayloadExists(DeviceToolPayload payload) { bool result = false; try { var query = HttpUtility.ParseQueryString(string.Empty); query["callerId"] = payload.ChannelId; query["nodeId"] = $"{payload.NodeId}"; query["uniqueId"] = payload.Id; query["hashCode"] = payload.HashCode; query["mode"] = $"{payload.Mode}"; query["type"] = $"{payload.Type}"; var url = UrlHelper.BuildUrl(Url, "api/description/payload-exists", query); result = await Transporter.Get(_identity, url, CancellationToken.None); } catch (Exception e) { MsgLogger.Exception($"{GetType().Name} - PayloadExists", e); } return(result); }
protected override bool UpdatePayloadContent(DeviceToolPayload payload) { bool result = false; if (payload.FileName == "EltraNavigoStreema.dll") { string path = Path.Combine(Environment.CurrentDirectory, _settings.NavigoPluginsPath, "EltraNavigoMPlayer.dll"); result = UpdatePayloadFromFile(path, payload); } return(result); }
private EltraPluginCacheItem UpdateCache(DeviceToolPayload payload, string fullPath) { EltraPluginCacheItem result = null; if (UpdatePluginCache(fullPath, payload)) { var cacheItem = FindPluginInCache(payload); if (cacheItem != null && cacheItem.Plugin != null) { var viewModels = cacheItem.Plugin.GetViewModels(); OnPluginAdded(payload, viewModels); result = cacheItem; } } return(result); }
internal async Task <bool> UploadPayload(DeviceToolPayload payload) { bool result = false; try { MsgLogger.WriteLine($"upload payload version='{payload.FileName}'"); var postResult = await Transporter.Post(_identity, Url, "api/description/payload-upload", payload.ToJson()); if (postResult.StatusCode == HttpStatusCode.OK) { result = true; } } catch (Exception e) { MsgLogger.Exception($"{GetType().Name} - Upload", e); } return(result); }
private bool PurgeToolFileSystem(DeviceToolPayload payload) { bool result = false; try { var pluginFilePath = GetPluginFilePath(payload.FileName); if (File.Exists(pluginFilePath)) { File.Delete(pluginFilePath); } result = true; } catch (Exception e) { MsgLogger.Exception($"{GetType().Name} - CleanupToolStorage", e); } return(result); }
private EltraPluginCacheItem FindPluginInFileSystem(DeviceToolPayload payload) { EltraPluginCacheItem result = null; try { var pluginFilePath = GetPluginFilePath(payload.FileName); if (Debugging) { var currentPathFileName = Path.GetFileName(pluginFilePath); var binFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var currentPathFullPath = Path.Combine(binFolder, currentPathFileName); if (File.Exists(currentPathFullPath)) { if (payload.Mode == DeviceToolPayloadMode.Development) { result = UpdateCache(payload, currentPathFullPath); } } else if (File.Exists(pluginFilePath)) { if (payload.Mode == DeviceToolPayloadMode.Development) { result = UpdateCache(payload, pluginFilePath); } } } } catch (Exception e) { MsgLogger.Exception($"{GetType().Name} - FindPluginInFileSystem", e); } return(result); }
private bool UpdatePluginCache(DeviceToolPayload payload) { bool result = false; var pluginFilePath = GetPluginFilePath(GetPluginFileName(payload.Id)); if (File.Exists(pluginFilePath)) { if (UpdatePluginCache(pluginFilePath, payload)) { var cacheItem = FindPluginInCache(payload); if (cacheItem != null && cacheItem.Plugin != null) { var viewModels = cacheItem.Plugin.GetViewModels(); OnPluginAdded(payload, viewModels); result = true; } } } return(result); }
private void OnPluginAdded(DeviceToolPayload payload, List <ToolViewModel> viewModels) { PluginAdded?.Invoke(payload, viewModels); }
private bool UpdatePluginCache(string assemblyPath, DeviceToolPayload payload) { bool result = false; try { MsgLogger.WriteDebug($"{GetType().Name} - UpdatePluginCache", $"load assembly - path = {assemblyPath}"); var theAssembly = Assembly.LoadFrom(assemblyPath); MsgLogger.WriteDebug($"{GetType().Name} - UpdatePluginCache", "load assembly - get types"); Type[] types = theAssembly.GetTypes(); MsgLogger.WriteDebug($"{GetType().Name} - UpdatePluginCache", $"load assembly - get types - count = {types.Length}"); foreach (Type t in types) { try { var type = t.GetInterface("EltraXamCommon.Plugins.IEltraNavigoPlugin"); MsgLogger.WriteDebug($"{GetType().Name} - UpdatePluginCache", $"type full name = {t.FullName}"); if (type != null && !string.IsNullOrEmpty(t.FullName)) { MsgLogger.WriteDebug($"{GetType().Name} - UpdatePluginCache", $"create instance $ {t.FullName}"); var assemblyInstace = theAssembly.CreateInstance(t.FullName, false); if (assemblyInstace is IEltraNavigoPlugin pluginInterface) { pluginInterface.DialogService = _dialogService; MsgLogger.WriteDebug($"{GetType().Name} - UpdatePluginCache", $"find payload {payload.FileName}"); if (FindPluginInCache(payload) == null) { var pluginCacheItem = new EltraPluginCacheItem() { FullPath = assemblyPath, HashCode = payload.HashCode, PayloadId = payload.Id, Plugin = pluginInterface }; PluginCache.Add(pluginCacheItem); MsgLogger.WriteDebug($"{GetType().Name} - UpdatePluginCache", $"add payload {payload.FileName} cache item"); } else { MsgLogger.WriteDebug($"{GetType().Name} - UpdatePluginCache", $"payload {payload.FileName} already added"); } result = true; break; } else { MsgLogger.WriteDebug($"{GetType().Name} - UpdatePluginCache", $"error: create instance $ {t.FullName} failed!"); } } } catch (Exception e) { MsgLogger.Exception($"{GetType().Name} - UpdatePluginCache [1]", e); } } } catch (Exception e) { MsgLogger.Exception($"{GetType().Name} - UpdatePluginCache [2]", e); } return(result); }
/// <summary> /// ToJson /// </summary> /// <param name="payload"></param> /// <returns></returns> public static string ToJson(this DeviceToolPayload payload) { return(JsonSerializer.Serialize(payload)); }
private bool UpdatePluginCache(string assemblyPath, DeviceToolPayload payload) { bool result = false; try { MsgLogger.WriteDebug($"{GetType().Name} - UpdatePluginCache", $"load assembly - path = {assemblyPath}"); var payloadPath = PluginStore.GetAssemblyFile(payload.Id); if (!string.IsNullOrEmpty(payloadPath)) { assemblyPath = payloadPath; } if (!string.IsNullOrEmpty(assemblyPath)) { var pluginAssembly = Assembly.LoadFrom(assemblyPath); MsgLogger.WriteDebug($"{GetType().Name} - UpdatePluginCache", "load assembly - get types"); Type[] types = pluginAssembly.GetTypes(); MsgLogger.WriteDebug($"{GetType().Name} - UpdatePluginCache", $"load assembly - get types - count = {types.Length}"); foreach (Type t in types) { try { var type = t.GetInterface("EltraXamCommon.Plugins.IEltraNavigoPluginService"); MsgLogger.WriteDebug($"{GetType().Name} - UpdatePluginCache", $"type full name = {t.FullName}"); if (type != null && !string.IsNullOrEmpty(t.FullName)) { MsgLogger.WriteDebug($"{GetType().Name} - UpdatePluginCache", $"create instance $ {t.FullName}"); var assemblyInstace = pluginAssembly.CreateInstance(t.FullName, false); string name = pluginAssembly.GetName().Name; string version = pluginAssembly.GetName().Version.ToString(); if (assemblyInstace is IEltraNavigoPluginService pluginService) { pluginService.DialogRequested += OnPluginInterfaceDialogRequested; MsgLogger.WriteDebug($"{GetType().Name} - UpdatePluginCache", $"find payload {payload.FileName}"); if (FindPluginInCache(payload) == null) { var pluginCacheItem = new EltraPluginCacheItem() { Name = name, FullPath = assemblyPath, HashCode = payload.HashCode, PayloadId = payload.Id, PluginService = pluginService, Version = version }; PluginCache.Add(pluginCacheItem); MsgLogger.WriteDebug($"{GetType().Name} - UpdatePluginCache", $"add payload {payload.FileName} cache item"); } else { MsgLogger.WriteDebug($"{GetType().Name} - UpdatePluginCache", $"payload {payload.FileName} already added"); } result = true; break; } else { MsgLogger.WriteDebug($"{GetType().Name} - UpdatePluginCache", $"error: create instance $ {t.FullName} failed!"); } } } catch (Exception e) { GC.Collect(); GC.WaitForPendingFinalizers(); MsgLogger.Exception($"{GetType().Name} - UpdatePluginCache [1]", e); } } } else { MsgLogger.WriteError($"{GetType().Name} - UpdatePluginCache", "assembly store returns empty element"); } } catch (Exception e) { GC.Collect(); GC.WaitForPendingFinalizers(); MsgLogger.Exception($"{GetType().Name} - UpdatePluginCache [2]", e); } return(result); }
internal Task <bool> UploadPayload(DeviceToolPayload payload) { return(DeviceControllerAdapter.UploadPayload(payload)); }
internal Task <bool> PayloadExists(DeviceToolPayload payload) { return(DeviceControllerAdapter.PayloadExists(payload)); }