Exemple #1
0
        /// <summary>
        /// Get description files
        /// </summary>
        /// <param name="pluginFolder">Plugin directory info</param>
        /// <returns>Original and parsed description files</returns>
        private static IEnumerable <KeyValuePair <string, PluginDescriptor> > GetDescriptionFilesAndDescriptors(string pluginFolder)
        {
            if (pluginFolder == null)
            {
                throw new ArgumentNullException(nameof(pluginFolder));
            }

            //create list (<file info, parsed plugin descritor>)
            var result = new List <KeyValuePair <string, PluginDescriptor> >();

            //add display order and path to list
            foreach (var descriptionFile in _fileProvider.GetFiles(pluginFolder, NopPluginDefaults.DescriptionFileName, false))
            {
                if (!IsPackagePluginFolder(_fileProvider.GetDirectoryName(descriptionFile)))
                {
                    continue;
                }

                //parse file
                var pluginDescriptor = GetPluginDescriptorFromFile(descriptionFile);

                //populate list
                result.Add(new KeyValuePair <string, PluginDescriptor>(descriptionFile, pluginDescriptor));
            }

            //sort list by display order. NOTE: Lowest DisplayOrder will be first i.e 0 , 1, 1, 1, 5, 10
            //it's required: https://www.nopcommerce.com/boards/t/17455/load-plugins-based-on-their-displayorder-on-startup.aspx
            result.Sort((firstPair, nextPair) => firstPair.Value.DisplayOrder.CompareTo(nextPair.Value.DisplayOrder));
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Copy the directory
        /// </summary>
        /// <param name="sourcePath">Path to the source directory</param>
        /// <param name="destinationPath">Path to the destination directory</param>
        /// <returns>A task that represents the completion of the operation</returns>
        protected virtual async Task CopyDirectoryAsync(string sourcePath, string destinationPath)
        {
            var directoryPath = GetFullPath(GetVirtualPath(sourcePath));

            if (!_fileProvider.DirectoryExists(directoryPath))
            {
                throw new Exception(GetLanguageResource("E_CopyDirInvalidPath"));
            }

            var newDirectoryPath = GetFullPath(GetVirtualPath($"{destinationPath.TrimEnd('/')}/{_fileProvider.GetDirectoryName(directoryPath)}"));

            if (_fileProvider.DirectoryExists(newDirectoryPath))
            {
                throw new Exception(GetLanguageResource("E_DirAlreadyExists"));
            }

            CopyDirectory(directoryPath, newDirectoryPath);

            await HttpContext.Response.WriteAsync(GetSuccessResponse());
        }
Exemple #3
0
        /// <summary>
        /// Get plugin logo URL
        /// </summary>
        /// <param name="pluginDescriptor">Plugin descriptor</param>
        /// <returns>Logo URL</returns>
        public virtual string GetPluginLogoUrl(PluginDescriptor pluginDescriptor)
        {
            var pluginDirectory = _fileProvider.GetDirectoryName(pluginDescriptor.OriginalAssemblyFile);

            if (string.IsNullOrEmpty(pluginDirectory))
            {
                return(null);
            }

            //check for supported extensions
            var logoExtension = NopPluginDefaults.SupportedLogoImageExtensions
                                .FirstOrDefault(ext => _fileProvider.FileExists(_fileProvider.Combine(pluginDirectory, $"{NopPluginDefaults.LogoFileName}.{ext}")));

            if (string.IsNullOrWhiteSpace(logoExtension))
            {
                return(null);
            }

            var storeLocation = _webHelper.GetStoreLocation();
            var logoUrl       = $"{storeLocation}{NopPluginDefaults.PathName}/" +
                                $"{_fileProvider.GetDirectoryNameOnly(pluginDirectory)}/{NopPluginDefaults.LogoFileName}.{logoExtension}";

            return(logoUrl);
        }
Exemple #4
0
        /// <summary>
        /// Get information about the uploaded items in the archive
        /// </summary>
        /// <param name="archivePath">Path to the archive</param>
        /// <returns>List of an uploaded item</returns>
        protected virtual IList <UploadedItem> GetUploadedItems(string archivePath)
        {
            using var archive = ZipFile.OpenRead(archivePath);
            //try to get the entry containing information about the uploaded items
            var uploadedItemsFileEntry = archive.Entries
                                         .FirstOrDefault(entry => entry.Name.Equals(NopPluginDefaults.UploadedItemsFileName, StringComparison.InvariantCultureIgnoreCase) &&
                                                         string.IsNullOrEmpty(_fileProvider.GetDirectoryName(entry.FullName)));

            if (uploadedItemsFileEntry == null)
            {
                return(null);
            }

            //read the content of this entry if exists
            using var unzippedEntryStream = uploadedItemsFileEntry.Open();
            using var reader = new StreamReader(unzippedEntryStream);
            return(JsonConvert.DeserializeObject <IList <UploadedItem> >(reader.ReadToEnd()));
        }