Example #1
0
        /// <summary>
        /// Save plugin descriptor to the plugin description file
        /// </summary>
        /// <param name="pluginDescriptor">Plugin descriptor</param>
        public static void SavePluginInfoParser(PluginInfoParser pluginDescriptor)
        {
            if (pluginDescriptor == null)
            {
                throw new ArgumentException(nameof(pluginDescriptor));
            }

            //get the description file path
            if (pluginDescriptor.AssemblyFileName == null)
            {
                throw new Exception($"Cannot load original assembly path for {pluginDescriptor.AssemblyFileName} plugin.");
            }

            var filePath = _fileProvider.Combine(_fileProvider.GetDirectoryName(pluginDescriptor.AssemblyFileName), PluginDefaults.DescriptionFileName);

            if (!_fileProvider.FileExists(filePath))
            {
                throw new Exception($"Description file for {pluginDescriptor.Name} plugin does not exist. {filePath}");
            }

            //save the file
            var text = JsonConvert.SerializeObject(pluginDescriptor, Formatting.Indented);

            _fileProvider.WriteAllText(filePath, text, Encoding.UTF8);
        }
Example #2
0
        /// <summary>
        /// Delete plugin directory from disk storage
        /// </summary>
        /// <param name="pluginDescriptor">Plugin descriptor</param>
        /// <returns>True if plugin directory is deleted, false if not</returns>
        public static bool DeletePlugin(PluginInfoParser pluginDescriptor)
        {
            //no plugin descriptor set
            if (pluginDescriptor == null)
            {
                return(false);
            }

            //check whether plugin is installed
            if (pluginDescriptor.IsInstalled)
            {
                return(false);
            }

            var directoryName = _fileProvider.GetDirectoryName(pluginDescriptor.AssemblyFileName);

            if (_fileProvider.DirectoryExists(directoryName))
            {
                _fileProvider.DeleteDirectory(directoryName);
            }

            return(true);
        }