Exemple #1
0
        private PluginStore CreatePluginStore()
        {
            var pluginStore = new PluginStore()
            {
                LocalPath = LocalPath
            };

            pluginStore.Load();

            //remove previously stored plugins
            pluginStore.Purge();

            return(pluginStore);
        }
Exemple #2
0
        private async Task <bool> DownloadTool(UserIdentity identity, string payloadId, string hashCode, DeviceToolPayloadMode mode)
        {
            bool result = false;

            if (identity == null)
            {
                throw new Exception("Identity not defined!");
            }

            try
            {
                var assemblyPath = GetPluginFilePath(GetPluginFileName(Guid.NewGuid().ToString()));

                var query = HttpUtility.ParseQueryString(string.Empty);

                query["uniqueId"] = payloadId;
                query["hashCode"] = hashCode;
                query["mode"]     = $"{(int)mode}";

                var url = UrlHelper.BuildUrl(CloudAdapter.Url, "api/description/payload-download", query);

                var json = await CloudAdapter.Get(identity, url);

                if (!string.IsNullOrEmpty(json))
                {
                    var payload = json.TryDeserializeObject <DeviceToolPayload>();

                    if (payload != null)
                    {
                        var base64EncodedBytes = Convert.FromBase64String(payload.Content);

                        File.WriteAllBytes(assemblyPath, base64EncodedBytes);

                        PluginStore.Add(payloadId, assemblyPath);

                        PluginStore.Serialize();

                        result = true;
                    }
                }
            }
            catch (Exception e)
            {
                MsgLogger.Exception($"{GetType().Name} - DownloadTool", e);
            }

            return(result);
        }
Exemple #3
0
        private bool UpdatePluginCache(DeviceToolPayload payload)
        {
            bool result         = false;
            var  pluginFilePath = PluginStore.GetAssemblyFile(payload.Id);

            if (File.Exists(pluginFilePath))
            {
                if (UpdatePluginCache(pluginFilePath, payload))
                {
                    var cacheItem = FindPluginInCache(payload);

                    if (cacheItem != null && cacheItem.PluginService != null)
                    {
                        var viewModels = cacheItem.PluginService.GetViewModels();

                        OnPluginAdded(payload, viewModels);

                        result = true;
                    }
                }
            }

            return(result);
        }
Exemple #4
0
        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);
        }