Exemple #1
0
        static ApplicationPartManagerExtensions()
        {
            //we use the default file provider, since the DI isn't initialized yet
            _fileProvider = CommonHelper.DefaultFileProvider;

            _baseAppLibraries = new List <string>();

            //get all libraries from /bin/{version}/ directory
            _baseAppLibraries.AddRange(_fileProvider.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll")
                                       .Select(fileName => _fileProvider.GetFileName(fileName)));

            //get all libraries from base site directory
            if (!AppDomain.CurrentDomain.BaseDirectory.Equals(Environment.CurrentDirectory, StringComparison.InvariantCultureIgnoreCase))
            {
                _baseAppLibraries.AddRange(_fileProvider.GetFiles(Environment.CurrentDirectory, "*.dll")
                                           .Select(fileName => _fileProvider.GetFileName(fileName)));
            }

            //get all libraries from refs directory
            var refsPathName = _fileProvider.Combine(Environment.CurrentDirectory, NopPluginDefaults.RefsPathName);

            if (_fileProvider.DirectoryExists(refsPathName))
            {
                _baseAppLibraries.AddRange(_fileProvider.GetFiles(refsPathName, "*.dll")
                                           .Select(fileName => _fileProvider.GetFileName(fileName)));
            }
        }
Exemple #2
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 #3
0
        /// <summary>
        /// Get all themes
        /// </summary>
        /// <returns>List of the theme descriptor</returns>
        public IList <ThemeDescriptor> GetThemes()
        {
            if (_themeDescriptors != null)
            {
                return(_themeDescriptors);
            }

            //load all theme descriptors
            _themeDescriptors = new List <ThemeDescriptor>();

            var themeDirectoryPath = _fileProvider.MapPath(NopPluginDefaults.ThemesPath);

            foreach (var descriptionFile in _fileProvider.GetFiles(themeDirectoryPath, NopPluginDefaults.ThemeDescriptionFileName, false))
            {
                var text = _fileProvider.ReadAllText(descriptionFile, Encoding.UTF8);
                if (string.IsNullOrEmpty(text))
                {
                    continue;
                }

                //get theme descriptor
                var themeDescriptor = GetThemeDescriptorFromText(text);

                //some validation
                if (string.IsNullOrEmpty(themeDescriptor?.SystemName))
                {
                    throw new Exception($"A theme descriptor '{descriptionFile}' has no system name");
                }

                _themeDescriptors.Add(themeDescriptor);
            }

            return(_themeDescriptors);
        }
Exemple #4
0
        public async System.Threading.Tasks.Task HandleEventAsync(EntityDeletedEvent <ProductPicture> eventMessage)
        {
            // Is this an ABC product with an ABC Item Number?
            var pad = await _productAbcDescriptionService.GetProductAbcDescriptionByProductIdAsync(eventMessage.Entity.ProductId);

            if (pad == null)
            {
                return;
            }

            // Is there a picture in product_images?
            var abcProductImagePath = _nopFileProvider.GetFiles("wwwroot/product_images", $"{pad.AbcItemNumber}_large.*").FirstOrDefault();

            if (abcProductImagePath == null)
            {
                return;
            }

            // Are they the same picture? If so delete.
            var nopPictureBinary = await _pictureService.GetPictureBinaryByPictureIdAsync(eventMessage.Entity.PictureId);

            var fileSystemBinary = await _nopFileProvider.ReadAllBytesAsync(abcProductImagePath);

            if (nopPictureBinary.BinaryData.SequenceEqual(fileSystemBinary))
            {
                _nopFileProvider.DeleteFile(abcProductImagePath);
                await _logger.InformationAsync($"Deleted image `{abcProductImagePath}` (image deleted in NOP)");
            }
        }
Exemple #5
0
        /// <summary>
        /// Makes sure matching assemblies in the supplied folder are loaded in the app domain.
        /// </summary>
        /// <param name="directoryPath">
        /// The physical path to a directory containing dlls to load in the app domain.
        /// </param>
        protected virtual void LoadMatchingAssemblies(string directoryPath)
        {
            var loadedAssemblyNames = new List <string>();

            foreach (var a in GetAssemblies())
            {
                loadedAssemblyNames.Add(a.FullName);
            }

            if (!_fileProvider.DirectoryExists(directoryPath))
            {
                return;
            }

            foreach (var dllPath in _fileProvider.GetFiles(directoryPath, "*.dll"))
            {
                try
                {
                    var an = AssemblyName.GetAssemblyName(dllPath);
                    if (Matches(an.FullName) && !loadedAssemblyNames.Contains(an.FullName))
                    {
                        App.Load(an);
                    }
                }
                catch (BadImageFormatException ex)
                {
                    Trace.TraceError(ex.ToString());
                }
            }
        }
        /// <summary>
        /// Delete temp files of this customer in OrderPayments directory
        /// </summary>
        public void ClearOrderPaymentsFiles(int customerId)
        {
            var searchBy = "*{" + customerId + "}*.html";
            var files    = _nopFileProvider.GetFiles($"{_webHostEnvironment.WebRootPath}\\{KuveytTurkDefaults.OrderPaymentsDirectory}", searchBy);

            foreach (var file in files)
            {
                _nopFileProvider.DeleteFile(file);
            }
        }
Exemple #7
0
        /// <summary>
        /// Get files in the passed directory
        /// </summary>
        /// <param name="directoryPath">Path to the files directory</param>
        /// <param name="type">Type of the files</param>
        /// <returns>List of paths to the files</returns>
        protected virtual List <string> GetFiles(string directoryPath, string type)
        {
            if (type == "#")
            {
                type = string.Empty;
            }

            var files = new List <string>();

            foreach (var fileName in _fileProvider.GetFiles(directoryPath))
            {
                if (string.IsNullOrEmpty(type) || GetFileType(_fileProvider.GetFileExtension(fileName)) == type)
                {
                    files.Add(fileName);
                }
            }

            return(files);
        }
        /// <summary>
        /// Delete picture thumbs
        /// </summary>
        /// <param name="picture">Picture</param>
        protected virtual void DeletePictureThumbs(Picture picture)
        {
            var filter       = $"{picture.Id:0000000}*.*";
            var currentFiles = _fileProvider.GetFiles(_fileProvider.GetAbsolutePath(NopMediaDefaults.ImageThumbsPath), filter, false);

            foreach (var currentFileName in currentFiles)
            {
                var thumbFilePath = GetThumbLocalPath(currentFileName);
                _fileProvider.DeleteFile(thumbFilePath);
            }
        }
Exemple #9
0
        /// <summary>
        /// Gets all backup files
        /// </summary>
        /// <returns>Backup file collection</returns>
        public virtual IList <string> GetAllBackupFiles()
        {
            var path = GetBackupDirectoryPath();

            if (!_fileProvider.DirectoryExists(path))
            {
                throw new NopException("Backup directory not exists");
            }

            return(_fileProvider.GetFiles(path, $"*.{NopCommonDefaults.DbBackupFileExtension}")
                   .OrderByDescending(p => _fileProvider.GetLastWriteTime(p)).ToList());
        }
Exemple #10
0
        /// <summary>
        /// Gets all backup files
        /// </summary>
        /// <returns>Backup file collection</returns>
        public virtual IList <string> GetAllBackupFiles()
        {
            var path = GetBackupDirectoryPath();

            if (!_fileProvider.DirectoryExists(path))
            {
                throw new IOException("Backup directory not exists");
            }

            return(_fileProvider.GetFiles(path, "*.bak")
                   .OrderByDescending(p => _fileProvider.GetLastWriteTime(p)).ToList());
        }
Exemple #11
0
        /// <summary>
        /// Initializes theme provider
        /// </summary>
        protected virtual void Initialize()
        {
            if (_themeDescriptors != null)
            {
                return;
            }

            //prevent multi loading data
            lock (_locker)
            {
                //data can be loaded while we waited
                if (_themeDescriptors != null)
                {
                    return;
                }

                //load all theme descriptors
                _themeDescriptors =
                    new Dictionary <string, ThemeDescriptor>(StringComparer.InvariantCultureIgnoreCase);

                var themeDirectoryPath = _fileProvider.MapPath(NopPluginDefaults.ThemesPath);
                foreach (var descriptionFile in _fileProvider.GetFiles(themeDirectoryPath,
                                                                       NopPluginDefaults.ThemeDescriptionFileName, false))
                {
                    var text = _fileProvider.ReadAllText(descriptionFile, Encoding.UTF8);
                    if (string.IsNullOrEmpty(text))
                    {
                        continue;
                    }

                    //get theme descriptor
                    var themeDescriptor = GetThemeDescriptorFromText(text);

                    //some validation
                    if (string.IsNullOrEmpty(themeDescriptor?.SystemName))
                    {
                        throw new Exception($"A theme descriptor '{descriptionFile}' has no system name");
                    }

                    _themeDescriptors.TryAdd(themeDescriptor.SystemName, themeDescriptor);
                }
            }
        }
        public virtual IActionResult MaintenanceDeleteFiles(MaintenanceModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMaintenance))
            {
                return(AccessDeniedView());
            }

            var startDateValue = model.DeleteExportedFiles.StartDate == null ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.DeleteExportedFiles.StartDate.Value, _dateTimeHelper.CurrentTimeZone);

            var endDateValue = model.DeleteExportedFiles.EndDate == null ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.DeleteExportedFiles.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            model.DeleteExportedFiles.NumberOfDeletedFiles = 0;

            foreach (var fullPath in _fileProvider.GetFiles(_fileProvider.GetAbsolutePath(EXPORT_IMPORT_PATH)))
            {
                try
                {
                    var fileName = _fileProvider.GetFileName(fullPath);
                    if (fileName.Equals("index.htm", StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    var info = _fileProvider.GetFileInfo(_fileProvider.Combine(EXPORT_IMPORT_PATH, fileName));
                    var lastModifiedTimeUtc = info.LastModified.UtcDateTime;
                    if ((!startDateValue.HasValue || startDateValue.Value < lastModifiedTimeUtc) &&
                        (!endDateValue.HasValue || lastModifiedTimeUtc < endDateValue.Value))
                    {
                        _fileProvider.DeleteFile(fullPath);
                        model.DeleteExportedFiles.NumberOfDeletedFiles++;
                    }
                }
                catch (Exception exc)
                {
                    ErrorNotification(exc, false);
                }
            }

            return(View(model));
        }