Example #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, GSPluginDefaults.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);
        }
Example #2
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(GSPluginDefaults.ThemesPath);

            foreach (var descriptionFile in _fileProvider.GetFiles(themeDirectoryPath, GSPluginDefaults.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);
        }
        /// <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);
        }
Example #4
0
        /// <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(GSMediaDefaults.ImageThumbsPath), filter, false);

            foreach (var currentFileName in currentFiles)
            {
                var thumbFilePath = GetThumbLocalPath(currentFileName);
                _fileProvider.DeleteFile(thumbFilePath);
            }
        }
        /// <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 GSException("Backup directory not exists");
            }

            return(_fileProvider.GetFiles(path, $"*.{GSCommonDefaults.DbBackupFileExtension}")
                   .OrderByDescending(p => _fileProvider.GetLastWriteTime(p)).ToList());
        }
Example #6
0
        static PluginManager()
        {
            //we use the default file provider, since the DI isn't initialized yet
            _fileProvider = CommonHelper.DefaultFileProvider;

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

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

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

            if (_fileProvider.DirectoryExists(refsPathName))
            {
                _baseAppLibraries.AddRange(_fileProvider.GetFiles(refsPathName, "*.dll").Select(fi => _fileProvider.GetFileName(fi)));
            }
        }
Example #7
0
        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));
        }
Example #8
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);
                    }

                    //old loading stuff
                    //Assembly a = Assembly.ReflectionOnlyLoadFrom(dllPath);
                    //if (Matches(a.FullName) && !loadedAssemblyNames.Contains(a.FullName))
                    //{
                    //    App.Load(a.FullName);
                    //}
                }
                catch (BadImageFormatException ex)
                {
                    Trace.TraceError(ex.ToString());
                }
            }
        }