From a3955f9ae28716037af77de2ec1180635320348a Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Mon, 13 Jul 2020 13:46:17 +0800 Subject: [PATCH 001/140] Introduce AbpFileExtensionContentTypeProvider. --- ...lFileSystemApplicationBuilderExtensions.cs | 20 +- .../AbpAspNetCoreContentOptions.cs | 402 +++++++++++++++++- .../AbpFileExtensionContentTypeProvider.cs | 39 ++ 3 files changed, 440 insertions(+), 21 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/VirtualFileSystem/AbpFileExtensionContentTypeProvider.cs diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/VirtualFileSystemApplicationBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/VirtualFileSystemApplicationBuilderExtensions.cs index 0557c37380..da9f65059f 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/VirtualFileSystemApplicationBuilderExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/VirtualFileSystemApplicationBuilderExtensions.cs @@ -1,18 +1,22 @@ -using Microsoft.Extensions.DependencyInjection; +using System; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp.AspNetCore.VirtualFileSystem; namespace Microsoft.AspNetCore.Builder { public static class VirtualFileSystemApplicationBuilderExtensions { - public static IApplicationBuilder UseVirtualFiles(this IApplicationBuilder app) + public static IApplicationBuilder UseVirtualFiles(this IApplicationBuilder app, Action configure = null) { - return app.UseStaticFiles( - new StaticFileOptions - { - FileProvider = app.ApplicationServices.GetRequiredService() - } - ); + var staticFileOptions = new StaticFileOptions + { + FileProvider = app.ApplicationServices.GetRequiredService(), + ContentTypeProvider = app.ApplicationServices.GetRequiredService() + }; + + configure?.Invoke(staticFileOptions); + + return app.UseStaticFiles(staticFileOptions); } } } diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/VirtualFileSystem/AbpAspNetCoreContentOptions.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/VirtualFileSystem/AbpAspNetCoreContentOptions.cs index ce6e454f54..f4b7d631cc 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/VirtualFileSystem/AbpAspNetCoreContentOptions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/VirtualFileSystem/AbpAspNetCoreContentOptions.cs @@ -1,14 +1,401 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; namespace Volo.Abp.AspNetCore.VirtualFileSystem { public class AbpAspNetCoreContentOptions { + public Dictionary ContentTypeMaps { get; } + public List AllowedExtraWebContentFolders { get; } + public List AllowedExtraWebContentFileExtensions { get; } public AbpAspNetCoreContentOptions() { + ContentTypeMaps = new Dictionary(StringComparer.OrdinalIgnoreCase) + { + {".323", "text/h323"}, + {".3g2", "video/3gpp2"}, + {".3gp2", "video/3gpp2"}, + {".3gp", "video/3gpp"}, + {".3gpp", "video/3gpp"}, + {".aac", "audio/aac"}, + {".aaf", "application/octet-stream"}, + {".aca", "application/octet-stream"}, + {".accdb", "application/msaccess"}, + {".accde", "application/msaccess"}, + {".accdt", "application/msaccess"}, + {".acx", "application/internet-property-stream"}, + {".adt", "audio/vnd.dlna.adts"}, + {".adts", "audio/vnd.dlna.adts"}, + {".afm", "application/octet-stream"}, + {".ai", "application/postscript"}, + {".aif", "audio/x-aiff"}, + {".aifc", "audio/aiff"}, + {".aiff", "audio/aiff"}, + {".appcache", "text/cache-manifest"}, + {".application", "application/x-ms-application"}, + {".art", "image/x-jg"}, + {".asd", "application/octet-stream"}, + {".asf", "video/x-ms-asf"}, + {".asi", "application/octet-stream"}, + {".asm", "text/plain"}, + {".asr", "video/x-ms-asf"}, + {".asx", "video/x-ms-asf"}, + {".atom", "application/atom+xml"}, + {".au", "audio/basic"}, + {".avi", "video/x-msvideo"}, + {".axs", "application/olescript"}, + {".bas", "text/plain"}, + {".bcpio", "application/x-bcpio"}, + {".bin", "application/octet-stream"}, + {".bmp", "image/bmp"}, + {".c", "text/plain"}, + {".cab", "application/vnd.ms-cab-compressed"}, + {".calx", "application/vnd.ms-office.calx"}, + {".cat", "application/vnd.ms-pki.seccat"}, + {".cdf", "application/x-cdf"}, + {".chm", "application/octet-stream"}, + {".class", "application/x-java-applet"}, + {".clp", "application/x-msclip"}, + {".cmx", "image/x-cmx"}, + {".cnf", "text/plain"}, + {".cod", "image/cis-cod"}, + {".cpio", "application/x-cpio"}, + {".cpp", "text/plain"}, + {".crd", "application/x-mscardfile"}, + {".crl", "application/pkix-crl"}, + {".crt", "application/x-x509-ca-cert"}, + {".csh", "application/x-csh"}, + {".css", "text/css"}, + {".csv", "application/octet-stream"}, + {".cur", "application/octet-stream"}, + {".dcr", "application/x-director"}, + {".deploy", "application/octet-stream"}, + {".der", "application/x-x509-ca-cert"}, + {".dib", "image/bmp"}, + {".dir", "application/x-director"}, + {".disco", "text/xml"}, + {".dlm", "text/dlm"}, + {".doc", "application/msword"}, + {".docm", "application/vnd.ms-word.document.macroEnabled.12"}, + {".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"}, + {".dot", "application/msword"}, + {".dotm", "application/vnd.ms-word.template.macroEnabled.12"}, + {".dotx", "application/vnd.openxmlformats-officedocument.wordprocessingml.template"}, + {".dsp", "application/octet-stream"}, + {".dtd", "text/xml"}, + {".dvi", "application/x-dvi"}, + {".dvr-ms", "video/x-ms-dvr"}, + {".dwf", "drawing/x-dwf"}, + {".dwp", "application/octet-stream"}, + {".dxr", "application/x-director"}, + {".eml", "message/rfc822"}, + {".emz", "application/octet-stream"}, + {".eot", "application/vnd.ms-fontobject"}, + {".eps", "application/postscript"}, + {".etx", "text/x-setext"}, + {".evy", "application/envoy"}, + {".fdf", "application/vnd.fdf"}, + {".fif", "application/fractals"}, + {".fla", "application/octet-stream"}, + {".flr", "x-world/x-vrml"}, + {".flv", "video/x-flv"}, + {".gif", "image/gif"}, + {".gtar", "application/x-gtar"}, + {".gz", "application/x-gzip"}, + {".h", "text/plain"}, + {".hdf", "application/x-hdf"}, + {".hdml", "text/x-hdml"}, + {".hhc", "application/x-oleobject"}, + {".hhk", "application/octet-stream"}, + {".hhp", "application/octet-stream"}, + {".hlp", "application/winhlp"}, + {".hqx", "application/mac-binhex40"}, + {".hta", "application/hta"}, + {".htc", "text/x-component"}, + {".htm", "text/html"}, + {".html", "text/html"}, + {".htt", "text/webviewhtml"}, + {".hxt", "text/html"}, + {".ical", "text/calendar"}, + {".icalendar", "text/calendar"}, + {".ico", "image/x-icon"}, + {".ics", "text/calendar"}, + {".ief", "image/ief"}, + {".ifb", "text/calendar"}, + {".iii", "application/x-iphone"}, + {".inf", "application/octet-stream"}, + {".ins", "application/x-internet-signup"}, + {".isp", "application/x-internet-signup"}, + {".IVF", "video/x-ivf"}, + {".jar", "application/java-archive"}, + {".java", "application/octet-stream"}, + {".jck", "application/liquidmotion"}, + {".jcz", "application/liquidmotion"}, + {".jfif", "image/pjpeg"}, + {".jpb", "application/octet-stream"}, + {".jpe", "image/jpeg"}, + {".jpeg", "image/jpeg"}, + {".jpg", "image/jpeg"}, + {".js", "application/javascript"}, + {".json", "application/json"}, + {".jsx", "text/jscript"}, + {".latex", "application/x-latex"}, + {".lit", "application/x-ms-reader"}, + {".lpk", "application/octet-stream"}, + {".lsf", "video/x-la-asf"}, + {".lsx", "video/x-la-asf"}, + {".lzh", "application/octet-stream"}, + {".m13", "application/x-msmediaview"}, + {".m14", "application/x-msmediaview"}, + {".m1v", "video/mpeg"}, + {".m2ts", "video/vnd.dlna.mpeg-tts"}, + {".m3u", "audio/x-mpegurl"}, + {".m4a", "audio/mp4"}, + {".m4v", "video/mp4"}, + {".man", "application/x-troff-man"}, + {".manifest", "application/x-ms-manifest"}, + {".map", "text/plain"}, + {".markdown", "text/markdown"}, + {".md", "text/markdown"}, + {".mdb", "application/x-msaccess"}, + {".mdp", "application/octet-stream"}, + {".me", "application/x-troff-me"}, + {".mht", "message/rfc822"}, + {".mhtml", "message/rfc822"}, + {".mid", "audio/mid"}, + {".midi", "audio/mid"}, + {".mix", "application/octet-stream"}, + {".mmf", "application/x-smaf"}, + {".mno", "text/xml"}, + {".mny", "application/x-msmoney"}, + {".mov", "video/quicktime"}, + {".movie", "video/x-sgi-movie"}, + {".mp2", "video/mpeg"}, + {".mp3", "audio/mpeg"}, + {".mp4", "video/mp4"}, + {".mp4v", "video/mp4"}, + {".mpa", "video/mpeg"}, + {".mpe", "video/mpeg"}, + {".mpeg", "video/mpeg"}, + {".mpg", "video/mpeg"}, + {".mpp", "application/vnd.ms-project"}, + {".mpv2", "video/mpeg"}, + {".ms", "application/x-troff-ms"}, + {".msi", "application/octet-stream"}, + {".mso", "application/octet-stream"}, + {".mvb", "application/x-msmediaview"}, + {".mvc", "application/x-miva-compiled"}, + {".nc", "application/x-netcdf"}, + {".nsc", "video/x-ms-asf"}, + {".nws", "message/rfc822"}, + {".ocx", "application/octet-stream"}, + {".oda", "application/oda"}, + {".odc", "text/x-ms-odc"}, + {".ods", "application/oleobject"}, + {".oga", "audio/ogg"}, + {".ogg", "video/ogg"}, + {".ogv", "video/ogg"}, + {".ogx", "application/ogg"}, + {".one", "application/onenote"}, + {".onea", "application/onenote"}, + {".onetoc", "application/onenote"}, + {".onetoc2", "application/onenote"}, + {".onetmp", "application/onenote"}, + {".onepkg", "application/onenote"}, + {".osdx", "application/opensearchdescription+xml"}, + {".otf", "font/otf"}, + {".p10", "application/pkcs10"}, + {".p12", "application/x-pkcs12"}, + {".p7b", "application/x-pkcs7-certificates"}, + {".p7c", "application/pkcs7-mime"}, + {".p7m", "application/pkcs7-mime"}, + {".p7r", "application/x-pkcs7-certreqresp"}, + {".p7s", "application/pkcs7-signature"}, + {".pbm", "image/x-portable-bitmap"}, + {".pcx", "application/octet-stream"}, + {".pcz", "application/octet-stream"}, + {".pdf", "application/pdf"}, + {".pfb", "application/octet-stream"}, + {".pfm", "application/octet-stream"}, + {".pfx", "application/x-pkcs12"}, + {".pgm", "image/x-portable-graymap"}, + {".pko", "application/vnd.ms-pki.pko"}, + {".pma", "application/x-perfmon"}, + {".pmc", "application/x-perfmon"}, + {".pml", "application/x-perfmon"}, + {".pmr", "application/x-perfmon"}, + {".pmw", "application/x-perfmon"}, + {".png", "image/png"}, + {".pnm", "image/x-portable-anymap"}, + {".pnz", "image/png"}, + {".pot", "application/vnd.ms-powerpoint"}, + {".potm", "application/vnd.ms-powerpoint.template.macroEnabled.12"}, + {".potx", "application/vnd.openxmlformats-officedocument.presentationml.template"}, + {".ppam", "application/vnd.ms-powerpoint.addin.macroEnabled.12"}, + {".ppm", "image/x-portable-pixmap"}, + {".pps", "application/vnd.ms-powerpoint"}, + {".ppsm", "application/vnd.ms-powerpoint.slideshow.macroEnabled.12"}, + {".ppsx", "application/vnd.openxmlformats-officedocument.presentationml.slideshow"}, + {".ppt", "application/vnd.ms-powerpoint"}, + {".pptm", "application/vnd.ms-powerpoint.presentation.macroEnabled.12"}, + {".pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"}, + {".prf", "application/pics-rules"}, + {".prm", "application/octet-stream"}, + {".prx", "application/octet-stream"}, + {".ps", "application/postscript"}, + {".psd", "application/octet-stream"}, + {".psm", "application/octet-stream"}, + {".psp", "application/octet-stream"}, + {".pub", "application/x-mspublisher"}, + {".qt", "video/quicktime"}, + {".qtl", "application/x-quicktimeplayer"}, + {".qxd", "application/octet-stream"}, + {".ra", "audio/x-pn-realaudio"}, + {".ram", "audio/x-pn-realaudio"}, + {".rar", "application/octet-stream"}, + {".ras", "image/x-cmu-raster"}, + {".rf", "image/vnd.rn-realflash"}, + {".rgb", "image/x-rgb"}, + {".rm", "application/vnd.rn-realmedia"}, + {".rmi", "audio/mid"}, + {".roff", "application/x-troff"}, + {".rpm", "audio/x-pn-realaudio-plugin"}, + {".rtf", "application/rtf"}, + {".rtx", "text/richtext"}, + {".scd", "application/x-msschedule"}, + {".sct", "text/scriptlet"}, + {".sea", "application/octet-stream"}, + {".setpay", "application/set-payment-initiation"}, + {".setreg", "application/set-registration-initiation"}, + {".sgml", "text/sgml"}, + {".sh", "application/x-sh"}, + {".shar", "application/x-shar"}, + {".sit", "application/x-stuffit"}, + {".sldm", "application/vnd.ms-powerpoint.slide.macroEnabled.12"}, + {".sldx", "application/vnd.openxmlformats-officedocument.presentationml.slide"}, + {".smd", "audio/x-smd"}, + {".smi", "application/octet-stream"}, + {".smx", "audio/x-smd"}, + {".smz", "audio/x-smd"}, + {".snd", "audio/basic"}, + {".snp", "application/octet-stream"}, + {".spc", "application/x-pkcs7-certificates"}, + {".spl", "application/futuresplash"}, + {".spx", "audio/ogg"}, + {".src", "application/x-wais-source"}, + {".ssm", "application/streamingmedia"}, + {".sst", "application/vnd.ms-pki.certstore"}, + {".stl", "application/vnd.ms-pki.stl"}, + {".sv4cpio", "application/x-sv4cpio"}, + {".sv4crc", "application/x-sv4crc"}, + {".svg", "image/svg+xml"}, + {".svgz", "image/svg+xml"}, + {".swf", "application/x-shockwave-flash"}, + {".t", "application/x-troff"}, + {".tar", "application/x-tar"}, + {".tcl", "application/x-tcl"}, + {".tex", "application/x-tex"}, + {".texi", "application/x-texinfo"}, + {".texinfo", "application/x-texinfo"}, + {".tgz", "application/x-compressed"}, + {".thmx", "application/vnd.ms-officetheme"}, + {".thn", "application/octet-stream"}, + {".tif", "image/tiff"}, + {".tiff", "image/tiff"}, + {".toc", "application/octet-stream"}, + {".tr", "application/x-troff"}, + {".trm", "application/x-msterminal"}, + {".ts", "video/vnd.dlna.mpeg-tts"}, + {".tsv", "text/tab-separated-values"}, + {".ttc", "application/x-font-ttf"}, + {".ttf", "application/x-font-ttf"}, + {".tts", "video/vnd.dlna.mpeg-tts"}, + {".txt", "text/plain"}, + {".u32", "application/octet-stream"}, + {".uls", "text/iuls"}, + {".ustar", "application/x-ustar"}, + {".vbs", "text/vbscript"}, + {".vcf", "text/x-vcard"}, + {".vcs", "text/plain"}, + {".vdx", "application/vnd.ms-visio.viewer"}, + {".vml", "text/xml"}, + {".vsd", "application/vnd.visio"}, + {".vss", "application/vnd.visio"}, + {".vst", "application/vnd.visio"}, + {".vsto", "application/x-ms-vsto"}, + {".vsw", "application/vnd.visio"}, + {".vsx", "application/vnd.visio"}, + {".vtx", "application/vnd.visio"}, + {".wasm", "application/wasm"}, + {".wav", "audio/wav"}, + {".wax", "audio/x-ms-wax"}, + {".wbmp", "image/vnd.wap.wbmp"}, + {".wcm", "application/vnd.ms-works"}, + {".wdb", "application/vnd.ms-works"}, + {".webm", "video/webm"}, + {".webp", "image/webp"}, + {".wks", "application/vnd.ms-works"}, + {".wm", "video/x-ms-wm"}, + {".wma", "audio/x-ms-wma"}, + {".wmd", "application/x-ms-wmd"}, + {".wmf", "application/x-msmetafile"}, + {".wml", "text/vnd.wap.wml"}, + {".wmlc", "application/vnd.wap.wmlc"}, + {".wmls", "text/vnd.wap.wmlscript"}, + {".wmlsc", "application/vnd.wap.wmlscriptc"}, + {".wmp", "video/x-ms-wmp"}, + {".wmv", "video/x-ms-wmv"}, + {".wmx", "video/x-ms-wmx"}, + {".wmz", "application/x-ms-wmz"}, + {".woff", "application/font-woff"}, // https://www.w3.org/TR/WOFF/#appendix-b + {".woff2", "font/woff2"}, // https://www.w3.org/TR/WOFF2/#IMT + {".wps", "application/vnd.ms-works"}, + {".wri", "application/x-mswrite"}, + {".wrl", "x-world/x-vrml"}, + {".wrz", "x-world/x-vrml"}, + {".wsdl", "text/xml"}, + {".wtv", "video/x-ms-wtv"}, + {".wvx", "video/x-ms-wvx"}, + {".x", "application/directx"}, + {".xaf", "x-world/x-vrml"}, + {".xaml", "application/xaml+xml"}, + {".xap", "application/x-silverlight-app"}, + {".xbap", "application/x-ms-xbap"}, + {".xbm", "image/x-xbitmap"}, + {".xdr", "text/plain"}, + {".xht", "application/xhtml+xml"}, + {".xhtml", "application/xhtml+xml"}, + {".xla", "application/vnd.ms-excel"}, + {".xlam", "application/vnd.ms-excel.addin.macroEnabled.12"}, + {".xlc", "application/vnd.ms-excel"}, + {".xlm", "application/vnd.ms-excel"}, + {".xls", "application/vnd.ms-excel"}, + {".xlsb", "application/vnd.ms-excel.sheet.binary.macroEnabled.12"}, + {".xlsm", "application/vnd.ms-excel.sheet.macroEnabled.12"}, + {".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}, + {".xlt", "application/vnd.ms-excel"}, + {".xltm", "application/vnd.ms-excel.template.macroEnabled.12"}, + {".xltx", "application/vnd.openxmlformats-officedocument.spreadsheetml.template"}, + {".xlw", "application/vnd.ms-excel"}, + {".xml", "text/xml"}, + {".xof", "x-world/x-vrml"}, + {".xpm", "image/x-xpixmap"}, + {".xps", "application/vnd.ms-xpsdocument"}, + {".xsd", "text/xml"}, + {".xsf", "text/xml"}, + {".xsl", "text/xml"}, + {".xslt", "text/xml"}, + {".xsn", "application/octet-stream"}, + {".xtp", "application/octet-stream"}, + {".xwd", "image/x-xwindowdump"}, + {".z", "application/x-compress"}, + {".zip", "application/x-zip-compressed"}, + }; + AllowedExtraWebContentFolders = new List { "/Pages", @@ -16,18 +403,7 @@ namespace Volo.Abp.AspNetCore.VirtualFileSystem "/Themes" }; - AllowedExtraWebContentFileExtensions = new List - { - ".js", - ".css", - ".png", - ".jpg", - ".jpeg", - ".woff", - ".woff2", - ".tff", - ".otf" - }; + AllowedExtraWebContentFileExtensions = ContentTypeMaps.Select(x => x.Key).ToList(); } } } diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/VirtualFileSystem/AbpFileExtensionContentTypeProvider.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/VirtualFileSystem/AbpFileExtensionContentTypeProvider.cs new file mode 100644 index 0000000000..82ca1c5539 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/VirtualFileSystem/AbpFileExtensionContentTypeProvider.cs @@ -0,0 +1,39 @@ +using Microsoft.AspNetCore.StaticFiles; +using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.AspNetCore.VirtualFileSystem +{ + public class AbpFileExtensionContentTypeProvider : IContentTypeProvider, ITransientDependency + { + protected AbpAspNetCoreContentOptions Options { get; } + + public AbpFileExtensionContentTypeProvider(IOptions abpAspNetCoreContentOptions) + { + Options = abpAspNetCoreContentOptions.Value; + } + + public bool TryGetContentType(string subpath, out string contentType) + { + var extension = GetExtension(subpath); + if (extension == null) + { + contentType = null; + return false; + } + + return Options.ContentTypeMaps.TryGetValue(extension, out contentType); + } + + protected virtual string GetExtension(string path) + { + if (string.IsNullOrWhiteSpace(path)) + { + return null; + } + + var index = path.LastIndexOf('.'); + return index < 0 ? null : path.Substring(index); + } + } +} From 9fcc3a123ada4d3f5f39a6dd1c9b6cd5656abc21 Mon Sep 17 00:00:00 2001 From: Richard Forrest Date: Wed, 15 Jul 2020 10:43:05 +0100 Subject: [PATCH 002/140] Add details on the correct use of unit of work in event handlers --- docs/en/Distributed-Event-Bus.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/en/Distributed-Event-Bus.md b/docs/en/Distributed-Event-Bus.md index 947b0f3142..0f2900e988 100644 --- a/docs/en/Distributed-Event-Bus.md +++ b/docs/en/Distributed-Event-Bus.md @@ -178,8 +178,11 @@ That's all. You can inject any service and perform any required logic here. A single event handler class can **subscribe to multiple events** but implementing the `IDistributedEventHandler` interface for each event type. +In your handler if you call a methods on a Repository you may find that you get an `ObjectDisposedException` being thrown. This will be because the unit of work being used by the Repository has been disposed in another context e.g. an ASP.net controller action. You will need to create a specific unit of work for your `HandleEventAsync` method. You can either use the `IUnitOfWorkManager.Begin` method or use the `UnitOfWorkAttribute` on the method. See the [Unit of work document](Unit-of-work.md) for more details. + > The handler class must be registered to the dependency injection (DI). The sample above uses the `ITransientDependency` to accomplish it. See the [DI document](Dependency-Injection.md) for more options. + ## Pre-Defined Events ABP Framework **automatically publishes** distributed events for **create, update and delete** operations for an [entity](Entities.md) once you configure it. From 5ef60faa8c1e24de09afea17667625e47b37b90f Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Mon, 20 Jul 2020 08:56:48 +0800 Subject: [PATCH 003/140] Introduce BasicAggregateRoot base class Resolve #4808 --- .../Volo/Abp/Domain/Entities/AggregateRoot.cs | 76 +-------------- .../Abp/Domain/Entities/BasicAggregateRoot.cs | 95 +++++++++++++++++++ 2 files changed, 98 insertions(+), 73 deletions(-) create mode 100644 framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/BasicAggregateRoot.cs diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs index b0c20131ef..09af979e93 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs @@ -9,9 +9,7 @@ using Volo.Abp.ObjectExtending; namespace Volo.Abp.Domain.Entities { [Serializable] - public abstract class AggregateRoot : Entity, - IAggregateRoot, - IGeneratesDomainEvents, + public abstract class AggregateRoot : BasicAggregateRoot, IHasExtraProperties, IHasConcurrencyStamp { @@ -20,9 +18,6 @@ namespace Volo.Abp.Domain.Entities [DisableAuditing] public virtual string ConcurrencyStamp { get; set; } - private readonly ICollection _localEvents = new Collection(); - private readonly ICollection _distributedEvents = new Collection(); - protected AggregateRoot() { ConcurrencyStamp = Guid.NewGuid().ToString("N"); @@ -30,36 +25,6 @@ namespace Volo.Abp.Domain.Entities this.SetDefaultsForExtraProperties(); } - protected virtual void AddLocalEvent(object eventData) - { - _localEvents.Add(eventData); - } - - protected virtual void AddDistributedEvent(object eventData) - { - _distributedEvents.Add(eventData); - } - - public virtual IEnumerable GetLocalEvents() - { - return _localEvents; - } - - public virtual IEnumerable GetDistributedEvents() - { - return _distributedEvents; - } - - public virtual void ClearLocalEvents() - { - _localEvents.Clear(); - } - - public virtual void ClearDistributedEvents() - { - _distributedEvents.Clear(); - } - public virtual IEnumerable Validate(ValidationContext validationContext) { return ExtensibleObjectValidator.GetValidationErrors( @@ -70,9 +35,7 @@ namespace Volo.Abp.Domain.Entities } [Serializable] - public abstract class AggregateRoot : Entity, - IAggregateRoot, - IGeneratesDomainEvents, + public abstract class AggregateRoot : BasicAggregateRoot, IHasExtraProperties, IHasConcurrencyStamp { @@ -81,9 +44,6 @@ namespace Volo.Abp.Domain.Entities [DisableAuditing] public virtual string ConcurrencyStamp { get; set; } - private readonly ICollection _localEvents = new Collection(); - private readonly ICollection _distributedEvents = new Collection(); - protected AggregateRoot() { ConcurrencyStamp = Guid.NewGuid().ToString("N"); @@ -99,36 +59,6 @@ namespace Volo.Abp.Domain.Entities this.SetDefaultsForExtraProperties(); } - protected virtual void AddLocalEvent(object eventData) - { - _localEvents.Add(eventData); - } - - protected virtual void AddDistributedEvent(object eventData) - { - _distributedEvents.Add(eventData); - } - - public virtual IEnumerable GetLocalEvents() - { - return _localEvents; - } - - public virtual IEnumerable GetDistributedEvents() - { - return _distributedEvents; - } - - public virtual void ClearLocalEvents() - { - _localEvents.Clear(); - } - - public virtual void ClearDistributedEvents() - { - _distributedEvents.Clear(); - } - public virtual IEnumerable Validate(ValidationContext validationContext) { return ExtensibleObjectValidator.GetValidationErrors( @@ -137,4 +67,4 @@ namespace Volo.Abp.Domain.Entities ); } } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/BasicAggregateRoot.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/BasicAggregateRoot.cs new file mode 100644 index 0000000000..42b0ba1320 --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/BasicAggregateRoot.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace Volo.Abp.Domain.Entities +{ + [Serializable] + public abstract class BasicAggregateRoot : Entity, + IAggregateRoot, + IGeneratesDomainEvents + { + private readonly ICollection _distributedEvents = new Collection(); + private readonly ICollection _localEvents = new Collection(); + + public virtual IEnumerable GetLocalEvents() + { + return _localEvents; + } + + public virtual IEnumerable GetDistributedEvents() + { + return _distributedEvents; + } + + public virtual void ClearLocalEvents() + { + _localEvents.Clear(); + } + + public virtual void ClearDistributedEvents() + { + _distributedEvents.Clear(); + } + + protected virtual void AddLocalEvent(object eventData) + { + _localEvents.Add(eventData); + } + + protected virtual void AddDistributedEvent(object eventData) + { + _distributedEvents.Add(eventData); + } + } + + [Serializable] + public abstract class BasicAggregateRoot : Entity, + IAggregateRoot, + IGeneratesDomainEvents + { + private readonly ICollection _distributedEvents = new Collection(); + private readonly ICollection _localEvents = new Collection(); + + protected BasicAggregateRoot() + { + + } + + protected BasicAggregateRoot(TKey id) + : base(id) + { + + } + + public virtual IEnumerable GetLocalEvents() + { + return _localEvents; + } + + public virtual IEnumerable GetDistributedEvents() + { + return _distributedEvents; + } + + public virtual void ClearLocalEvents() + { + _localEvents.Clear(); + } + + public virtual void ClearDistributedEvents() + { + _distributedEvents.Clear(); + } + + protected virtual void AddLocalEvent(object eventData) + { + _localEvents.Add(eventData); + } + + protected virtual void AddDistributedEvent(object eventData) + { + _distributedEvents.Add(eventData); + } + } +} From 8d87d539d7c701831a27d4667df9f11c66a38803 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 23 Jul 2020 15:41:44 +0300 Subject: [PATCH 004/140] Docs module: added alternative way (using branches) to get versions resolves https://github.com/abpframework/abp/issues/4845 --- .../Docs/Admin/Projects/CreateProjectDto.cs | 3 +- .../Volo/Docs/Admin/Projects/ProjectDto.cs | 3 +- .../Docs/Admin/Projects/UpdateProjectDto.cs | 3 +- .../DocsAdminWebAutoMapperProfile.cs | 6 +- .../Docs/Admin/Projects/Create.cshtml.cs | 13 +++- .../Pages/Docs/Admin/Projects/Edit.cshtml.cs | 15 ++++- .../Projects/GithubVersionProviderSource.cs | 8 +++ .../Volo.Docs.Domain/Volo.Docs.Domain.csproj | 3 +- .../GitHub/Documents/GithubDocumentSource.cs | 59 ++++++++++++++----- .../Documents/GithubRepositoryManager.cs | 15 +++-- .../Documents/IGithubRepositoryManager.cs | 4 +- .../Documents/Version/GithubBranchProvider.cs | 28 +++++++++ .../Version/GithubReleaseProvider.cs | 28 +++++++++ .../GitHub/Documents/Version/GithubVersion.cs | 7 +++ .../Version/GithubVersionProviderFactory.cs | 34 +++++++++++ .../Version/IGithubVersionProvider.cs | 10 ++++ .../Version/IGithubVersionProviderFactory.cs | 9 +++ .../Documents}/Version/IVersionHelper.cs | 4 +- .../Version/SemanticVersionHelper.cs | 4 +- .../Pages/Documents/Project/Index.cshtml | 6 +- .../Pages/Documents/Project/Index.cshtml.cs | 37 ++++++------ .../Pages/Documents/Search.cshtml.cs | 33 ++++++----- .../src/Volo.Docs.Web/Volo.Docs.Web.csproj | 1 - .../Volo/Docs/DocsTestBase.cs | 30 +++------- 24 files changed, 270 insertions(+), 93 deletions(-) create mode 100644 modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Projects/GithubVersionProviderSource.cs create mode 100644 modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubBranchProvider.cs create mode 100644 modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubReleaseProvider.cs create mode 100644 modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersion.cs create mode 100644 modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersionProviderFactory.cs create mode 100644 modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProvider.cs create mode 100644 modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProviderFactory.cs rename modules/docs/src/{Volo.Docs.Web => Volo.Docs.Domain/Volo/Docs/GitHub/Documents}/Version/IVersionHelper.cs (65%) rename modules/docs/src/{Volo.Docs.Web => Volo.Docs.Domain/Volo/Docs/GitHub/Documents}/Version/SemanticVersionHelper.cs (92%) diff --git a/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/CreateProjectDto.cs b/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/CreateProjectDto.cs index eb603b334c..0918e19d8e 100644 --- a/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/CreateProjectDto.cs +++ b/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/CreateProjectDto.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Volo.Docs.Projects; namespace Volo.Docs.Admin.Projects { @@ -26,4 +27,4 @@ namespace Volo.Docs.Admin.Projects public Dictionary ExtraProperties { get; set; } } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/ProjectDto.cs b/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/ProjectDto.cs index c71f34e357..b624a1f187 100644 --- a/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/ProjectDto.cs +++ b/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/ProjectDto.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Volo.Abp.Application.Dtos; +using Volo.Docs.Projects; namespace Volo.Docs.Admin.Projects { @@ -29,4 +30,4 @@ namespace Volo.Docs.Admin.Projects public Dictionary ExtraProperties { get; set; } } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/UpdateProjectDto.cs b/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/UpdateProjectDto.cs index 9e94cec66e..f2d3c218c8 100644 --- a/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/UpdateProjectDto.cs +++ b/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/UpdateProjectDto.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Volo.Docs.Projects; namespace Volo.Docs.Admin.Projects { @@ -22,4 +23,4 @@ namespace Volo.Docs.Admin.Projects public Dictionary ExtraProperties { get; set; } } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.Admin.Web/DocsAdminWebAutoMapperProfile.cs b/modules/docs/src/Volo.Docs.Admin.Web/DocsAdminWebAutoMapperProfile.cs index ca430cdaad..83f993d1e8 100644 --- a/modules/docs/src/Volo.Docs.Admin.Web/DocsAdminWebAutoMapperProfile.cs +++ b/modules/docs/src/Volo.Docs.Admin.Web/DocsAdminWebAutoMapperProfile.cs @@ -15,7 +15,11 @@ namespace Volo.Docs.Admin CreateMap().Ignore(x => x.ExtraProperties); CreateMap () - .Ignore(x => x.GitHubAccessToken).Ignore(x => x.GitHubRootUrl).Ignore(x => x.GitHubUserAgent); + .Ignore(x => x.GitHubAccessToken) + .Ignore(x => x.GitHubRootUrl) + .Ignore(x => x.GitHubUserAgent) + .Ignore(x => x.GithubVersionProviderSource) + .Ignore(x => x.VersionBranchPrefix); CreateMap(); CreateMap(); diff --git a/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Create.cshtml.cs b/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Create.cshtml.cs index 506b674ba5..3f5b847538 100644 --- a/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Create.cshtml.cs +++ b/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Create.cshtml.cs @@ -62,7 +62,9 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects { {nameof(GithubProject.GitHubRootUrl), GithubProject.GitHubRootUrl}, {nameof(GithubProject.GitHubUserAgent), GithubProject.GitHubUserAgent}, - {nameof(GithubProject.GitHubAccessToken), GithubProject.GitHubAccessToken} + {nameof(GithubProject.GitHubAccessToken), GithubProject.GitHubAccessToken}, + {nameof(GithubProject.GithubVersionProviderSource), GithubProject.GithubVersionProviderSource}, + {nameof(GithubProject.VersionBranchPrefix), GithubProject.VersionBranchPrefix} }; return dto; @@ -118,6 +120,13 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects [DisplayOrder(10002)] [StringLength(64)] public string GitHubUserAgent { get; set; } + + [DisplayOrder(10003)] + public GithubVersionProviderSource GithubVersionProviderSource { get; set; } = GithubVersionProviderSource.Releases; + + [DisplayOrder(10004)] + [StringLength(64)] + public string VersionBranchPrefix { get; set; } } } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs b/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs index ef1762c460..6530c7ec66 100644 --- a/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs +++ b/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs @@ -62,7 +62,9 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects { {nameof(GithubProject.GitHubRootUrl), GithubProject.GitHubRootUrl}, {nameof(GithubProject.GitHubUserAgent), GithubProject.GitHubUserAgent}, - {nameof(GithubProject.GitHubAccessToken), GithubProject.GitHubAccessToken} + {nameof(GithubProject.GitHubAccessToken), GithubProject.GitHubAccessToken}, + {nameof(GithubProject.GithubVersionProviderSource), GithubProject.GithubVersionProviderSource}, + {nameof(GithubProject.VersionBranchPrefix), GithubProject.VersionBranchPrefix} }; return dto; @@ -75,6 +77,8 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects GithubProject.GitHubAccessToken = (string) dto.ExtraProperties[nameof(GithubProject.GitHubAccessToken)]; GithubProject.GitHubRootUrl = (string) dto.ExtraProperties[nameof(GithubProject.GitHubRootUrl)]; GithubProject.GitHubUserAgent = (string) dto.ExtraProperties[nameof(GithubProject.GitHubUserAgent)]; + GithubProject.GithubVersionProviderSource = (GithubVersionProviderSource) dto.ExtraProperties[nameof(GithubProject.GithubVersionProviderSource)]; + GithubProject.VersionBranchPrefix = (string) dto.ExtraProperties[nameof(GithubProject.VersionBranchPrefix)]; } public abstract class EditProjectViewModelBase @@ -125,6 +129,13 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects [DisplayOrder(10002)] [StringLength(64)] public string GitHubUserAgent { get; set; } + + [DisplayOrder(10003)] + public GithubVersionProviderSource GithubVersionProviderSource { get; set; } = GithubVersionProviderSource.Releases; + + [DisplayOrder(10004)] + [StringLength(64)] + public string VersionBranchPrefix { get; set; } } } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Projects/GithubVersionProviderSource.cs b/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Projects/GithubVersionProviderSource.cs new file mode 100644 index 0000000000..4773ecf74d --- /dev/null +++ b/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Projects/GithubVersionProviderSource.cs @@ -0,0 +1,8 @@ +namespace Volo.Docs.Projects +{ + public enum GithubVersionProviderSource + { + Releases, + Branches + } +} diff --git a/modules/docs/src/Volo.Docs.Domain/Volo.Docs.Domain.csproj b/modules/docs/src/Volo.Docs.Domain/Volo.Docs.Domain.csproj index 1042aeec0e..a0da321cae 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo.Docs.Domain.csproj +++ b/modules/docs/src/Volo.Docs.Domain/Volo.Docs.Domain.csproj @@ -21,8 +21,9 @@ + - + diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs index 1da1ab1f9d..b15e85bd8b 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs @@ -9,6 +9,7 @@ using Volo.Docs.GitHub.Projects; using Volo.Docs.Projects; using Octokit; using Volo.Abp; +using Volo.Docs.GitHub.Documents.Version; using Volo.Extensions; using Project = Volo.Docs.Projects.Project; @@ -22,11 +23,13 @@ namespace Volo.Docs.GitHub.Documents private readonly IGithubRepositoryManager _githubRepositoryManager; private readonly IGithubPatchAnalyzer _githubPatchAnalyzer; + private readonly IVersionHelper _versionHelper; - public GithubDocumentSource(IGithubRepositoryManager githubRepositoryManager, IGithubPatchAnalyzer githubPatchAnalyzer) + public GithubDocumentSource(IGithubRepositoryManager githubRepositoryManager, IGithubPatchAnalyzer githubPatchAnalyzer, IVersionHelper versionHelper) { _githubRepositoryManager = githubRepositoryManager; _githubPatchAnalyzer = githubPatchAnalyzer; + _versionHelper = versionHelper; } public virtual async Task GetDocumentAsync(Project project, string documentName, string languageCode, string version, DateTime? lastKnownSignificantUpdateTime = null) @@ -172,7 +175,7 @@ namespace Volo.Docs.GitHub.Documents * Getting file commits usually throws "Resource temporarily unavailable" or "Network is unreachable" * This is a trival information and running this inside try-catch is safer. */ - + try { return await GetFileCommitsAsync(project, version, project.GetGitHubInnerUrl(languageCode, documentName)); @@ -221,15 +224,19 @@ namespace Volo.Docs.GitHub.Documents public async Task> GetVersionsAsync(Project project) { + var url = project.GetGitHubUrl(); + var ownerName = GetOwnerNameFromUrl(url); + var repositoryName = GetRepositoryNameFromUrl(url); + var githubVersionProviderSource = GetGithubVersionProviderSource(project); + List versions; try { - versions = (await GetReleasesAsync(project)) - .OrderByDescending(r => r.PublishedAt) + versions = (await _githubRepositoryManager.GetVersionsAsync(ownerName, repositoryName, project.GetGitHubAccessTokenOrNull(), githubVersionProviderSource)) .Select(r => new VersionInfo { - Name = r.TagName, - DisplayName = r.TagName + Name = r.Name, + DisplayName = r.Name }).ToList(); } catch (Exception ex) @@ -239,14 +246,42 @@ namespace Volo.Docs.GitHub.Documents versions = new List(); } - if (!versions.Any() && !string.IsNullOrEmpty(project.LatestVersionBranchName)) + if (githubVersionProviderSource == GithubVersionProviderSource.Branches && project.ExtraProperties.ContainsKey("VersionBranchPrefix")) { - versions.Add(new VersionInfo { DisplayName = "1.0.0", Name = project.LatestVersionBranchName }); + var prefix = (string) project.ExtraProperties["VersionBranchPrefix"]; + + if (!string.IsNullOrEmpty(prefix)) + { + versions = versions.Where(v => v.Name.StartsWith(prefix)).ToList(); + versions.ForEach(v=> v.Name.Substring(prefix.Length)); + versions.ForEach(v=> v.DisplayName.Substring(prefix.Length)); + } + + versions = _versionHelper.OrderByDescending(versions); + } + + if(githubVersionProviderSource == GithubVersionProviderSource.Releases) + { + if (!versions.Any() && !string.IsNullOrEmpty(project.LatestVersionBranchName)) + { + versions.Add(new VersionInfo { DisplayName = "1.0.0", Name = project.LatestVersionBranchName }); + } + else + { + versions = _versionHelper.OrderByDescending(versions); + } } return versions; } + private GithubVersionProviderSource GetGithubVersionProviderSource(Project project) + { + return project.ExtraProperties.ContainsKey("GithubVersionProviderSource") + ? (GithubVersionProviderSource) project.ExtraProperties["GithubVersionProviderSource"] + : GithubVersionProviderSource.Releases; + } + public async Task GetResource(Project project, string resourceName, string languageCode, string version) { var rawRootUrl = CalculateRawRootUrlWithLanguageCode(project.GetGitHubUrl(version), languageCode); @@ -277,14 +312,6 @@ namespace Volo.Docs.GitHub.Documents return languageConfig; } - private async Task> GetReleasesAsync(Project project) - { - var url = project.GetGitHubUrl(); - var ownerName = GetOwnerNameFromUrl(url); - var repositoryName = GetRepositoryNameFromUrl(url); - return await _githubRepositoryManager.GetReleasesAsync(ownerName, repositoryName, project.GetGitHubAccessTokenOrNull()); - } - private async Task> GetFileCommitsAsync(Project project, string version, string filename) { var url = project.GetGitHubUrl(); diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubRepositoryManager.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubRepositoryManager.cs index ef21353236..8d99e360ef 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubRepositoryManager.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubRepositoryManager.cs @@ -6,6 +6,8 @@ using System.Net.Http.Headers; using System.Threading.Tasks; using Octokit; using Octokit.Internal; +using Volo.Docs.GitHub.Documents.Version; +using Volo.Docs.Projects; using ProductHeaderValue = Octokit.ProductHeaderValue; namespace Volo.Docs.GitHub.Documents @@ -15,10 +17,12 @@ namespace Volo.Docs.GitHub.Documents public const string HttpClientName = "GithubRepositoryManagerHttpClientName"; private readonly IHttpClientFactory _clientFactory; + private readonly IGithubVersionProviderFactory _githubVersionProviderFactory; - public GithubRepositoryManager(IHttpClientFactory clientFactory) + public GithubRepositoryManager(IHttpClientFactory clientFactory, IGithubVersionProviderFactory githubVersionProviderFactory) { _clientFactory = clientFactory; + _githubVersionProviderFactory = githubVersionProviderFactory; } public async Task GetFileRawStringContentAsync(string rawUrl, string token, string userAgent) @@ -32,11 +36,12 @@ namespace Volo.Docs.GitHub.Documents using var httpClient = CreateHttpClient(token, userAgent); return await httpClient.GetByteArrayAsync(new Uri(rawUrl)); } - - public async Task> GetReleasesAsync(string name, string repositoryName, string token) + + public async Task> GetVersionsAsync(string name, string repositoryName, string token, GithubVersionProviderSource githubVersionProviderSource) { - var client = GetGitHubClient(name, token); - return await client.Repository.Release.GetAll(name, repositoryName); + var _provider = _githubVersionProviderFactory.Create(githubVersionProviderSource); + + return await _provider.GetVersions(name, repositoryName, token); } public async Task> GetFileCommitsAsync(string name, string repositoryName, string version, string filename, string token) diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/IGithubRepositoryManager.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/IGithubRepositoryManager.cs index 67536fc559..12f3bc4ef2 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/IGithubRepositoryManager.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/IGithubRepositoryManager.cs @@ -4,6 +4,8 @@ using System.Text; using System.Threading.Tasks; using Octokit; using Volo.Abp.DependencyInjection; +using Volo.Docs.GitHub.Documents.Version; +using Volo.Docs.Projects; namespace Volo.Docs.GitHub.Documents { @@ -13,7 +15,7 @@ namespace Volo.Docs.GitHub.Documents Task GetFileRawByteArrayContentAsync(string rawUrl, string token, string userAgent); - Task> GetReleasesAsync(string name, string repositoryName, string token); + Task> GetVersionsAsync(string name, string repositoryName, string token, GithubVersionProviderSource githubVersionProviderSource); Task> GetFileCommitsAsync(string name, string repositoryName, string version, string filename, string token); diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubBranchProvider.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubBranchProvider.cs new file mode 100644 index 0000000000..06a02b96a6 --- /dev/null +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubBranchProvider.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Octokit; +using Octokit.Internal; +using Volo.Abp.DependencyInjection; + +namespace Volo.Docs.GitHub.Documents.Version +{ + public class GithubBranchProvider : IGithubVersionProvider, ITransientDependency + { + public async Task> GetVersions(string name, string repositoryName, string token) + { + var client = GetGitHubClient(name, token); + var branches = await client.Repository.Branch.GetAll(name, repositoryName); + + return branches.Select(b => new GithubVersion {Name = b.Name}).ToList(); + } + + private static GitHubClient GetGitHubClient(string name, string token) + { + return token.IsNullOrWhiteSpace() + ? new GitHubClient(new ProductHeaderValue(name)) + : new GitHubClient(new ProductHeaderValue(name), new InMemoryCredentialStore(new Credentials(token))); + } + } +} diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubReleaseProvider.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubReleaseProvider.cs new file mode 100644 index 0000000000..0425a3cb28 --- /dev/null +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubReleaseProvider.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Octokit; +using Octokit.Internal; +using Volo.Abp.DependencyInjection; + +namespace Volo.Docs.GitHub.Documents.Version +{ + public class GithubReleaseProvider : IGithubVersionProvider, ITransientDependency + { + public async Task> GetVersions(string name, string repositoryName, string token) + { + var client = GetGitHubClient(name, token); + var releases = await client.Repository.Release.GetAll(name, repositoryName); + + return releases.Select(r => new GithubVersion {Name = r.TagName}).ToList(); + } + + private static GitHubClient GetGitHubClient(string name, string token) + { + return token.IsNullOrWhiteSpace() + ? new GitHubClient(new ProductHeaderValue(name)) + : new GitHubClient(new ProductHeaderValue(name), new InMemoryCredentialStore(new Credentials(token))); + } + } +} diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersion.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersion.cs new file mode 100644 index 0000000000..5c3e98aac0 --- /dev/null +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersion.cs @@ -0,0 +1,7 @@ +namespace Volo.Docs.GitHub.Documents.Version +{ + public class GithubVersion + { + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersionProviderFactory.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersionProviderFactory.cs new file mode 100644 index 0000000000..48bc2fe678 --- /dev/null +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersionProviderFactory.cs @@ -0,0 +1,34 @@ +using System; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.DependencyInjection; +using Volo.Docs.Projects; + +namespace Volo.Docs.GitHub.Documents.Version +{ + public class GithubVersionProviderFactory : IGithubVersionProviderFactory, ITransientDependency + { + public IServiceProvider ServiceProvider { get; } + + public GithubVersionProviderFactory(IServiceProvider serviceProvider) + { + ServiceProvider = serviceProvider; + } + public IGithubVersionProvider Create(GithubVersionProviderSource source) + { + Type serviceType; + + switch (source) + { + case GithubVersionProviderSource.Branches: + serviceType = typeof(GithubBranchProvider); + break; + case GithubVersionProviderSource.Releases: + default: + serviceType = typeof(GithubReleaseProvider); + break; + } + + return (IGithubVersionProvider)ServiceProvider.GetRequiredService(serviceType); + } + } +} diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProvider.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProvider.cs new file mode 100644 index 0000000000..429e2ec34b --- /dev/null +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProvider.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Volo.Docs.GitHub.Documents.Version +{ + public interface IGithubVersionProvider + { + Task> GetVersions(string name, string repositoryName, string token); + } +} diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProviderFactory.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProviderFactory.cs new file mode 100644 index 0000000000..5236e52fbd --- /dev/null +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProviderFactory.cs @@ -0,0 +1,9 @@ +using Volo.Docs.Projects; + +namespace Volo.Docs.GitHub.Documents.Version +{ + public interface IGithubVersionProviderFactory + { + IGithubVersionProvider Create(GithubVersionProviderSource source); + } +} diff --git a/modules/docs/src/Volo.Docs.Web/Version/IVersionHelper.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IVersionHelper.cs similarity index 65% rename from modules/docs/src/Volo.Docs.Web/Version/IVersionHelper.cs rename to modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IVersionHelper.cs index f3fd202155..67bed57093 100644 --- a/modules/docs/src/Volo.Docs.Web/Version/IVersionHelper.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IVersionHelper.cs @@ -1,13 +1,13 @@ using System.Collections.Generic; using Volo.Docs.Projects; -namespace Volo.Docs.Version +namespace Volo.Docs.GitHub.Documents.Version { public interface IVersionHelper { List OrderByDescending(List versions); - List OrderByDescending(List versions); + List OrderByDescending(List versions); bool IsPreRelease(string version); } diff --git a/modules/docs/src/Volo.Docs.Web/Version/SemanticVersionHelper.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/SemanticVersionHelper.cs similarity index 92% rename from modules/docs/src/Volo.Docs.Web/Version/SemanticVersionHelper.cs rename to modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/SemanticVersionHelper.cs index c60abaccea..cad8c3c180 100644 --- a/modules/docs/src/Volo.Docs.Web/Version/SemanticVersionHelper.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/SemanticVersionHelper.cs @@ -5,7 +5,7 @@ using NuGet.Versioning; using Volo.Abp.DependencyInjection; using Volo.Docs.Projects; -namespace Volo.Docs.Version +namespace Volo.Docs.GitHub.Documents.Version { public class SemanticVersionHelper : IVersionHelper, ITransientDependency { @@ -14,7 +14,7 @@ namespace Volo.Docs.Version return versions.OrderByDescending(v=> SemanticVersion.Parse(NormalizeVersion(v)), new VersionComparer()).ToList(); } - public List OrderByDescending(List versions) + public List OrderByDescending(List versions) { return versions.OrderByDescending(v => SemanticVersion.Parse(NormalizeVersion(v.Name)), new VersionComparer()).ToList(); } diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml index 71c7d4790c..bd76814461 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml @@ -53,7 +53,7 @@