Example #1
0
        private List <ExtensionDescriptorEntry> AvailableExtensionsInFolder(string path, string extensionType, string manifestName, bool manifestIsOptional)
        {
            Logger.Information("开始寻找扩展在 '{0}'...", path);
            var subfolderPaths = _applicationFolder.ListDirectories(path);
            var localList      = new List <ExtensionDescriptorEntry>();

            foreach (var subfolderPath in subfolderPaths)
            {
                var extensionId  = Path.GetFileName(subfolderPath.TrimEnd('/', '\\'));
                var manifestPath = Path.Combine(subfolderPath, manifestName);
                try
                {
                    var entry = GetExtensionDescriptor(path, extensionId, extensionType, manifestPath, manifestIsOptional);
                    if (entry == null)
                    {
                        continue;
                    }

                    var descriptor = entry.Descriptor;
                    if (descriptor == null)
                    {
                        continue;
                    }

                    if (descriptor.Path != null && !descriptor.Path.IsValidUrlSegment())
                    {
                        Logger.Error(T("模块 '{0}' 不能被加载,因为它有一个无效的路径({1})。它被忽略。如果指定的路径必须是一个有效的URL分类。最好的办法是坚持使用字母和数字,不要加空格。"), extensionId, descriptor.Path);
                        continue;
                    }

                    if (descriptor.Path == null)
                    {
                        descriptor.Path = descriptor.Name.IsValidUrlSegment()
                                              ? descriptor.Name
                                              : entry.Id;
                    }

                    localList.Add(entry);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "模块 '{0}' 不能被加载。它被忽略。", extensionId);
#if DEBUG
                    throw;
#endif
                }
            }
            Logger.Information("完成扩展寻找在 '{0}': {1}", path, string.Join(", ", localList.Select(d => d.Id)));
            return(localList);
        }