├── .gitignore ├── DotNetCoreAdDemo └── DotNetCoreAdDemo │ ├── ADHelper.cs │ ├── DotNetCoreAdDemo.csproj │ ├── LdapExtension.cs │ ├── Org.cs │ ├── Program.cs │ └── User.cs ├── DotNetCoreApiSample ├── DotNetCoreApiSample.sln └── DotNetCoreApiSample │ ├── Controllers │ ├── ResultDemoController.cs │ ├── ValidationDemoController.cs │ └── ValuesController.cs │ ├── DotNetCoreApiSample.csproj │ ├── Filters │ ├── ApiResultFilterAttribute.cs │ ├── CustomExceptionAttribute.cs │ └── ValidateModelAttribute.cs │ ├── Models │ ├── BaseResultModel.cs │ ├── CustomExceptionResult.cs │ ├── CustomExceptionResultModel.cs │ ├── ValidationFailedResult.cs │ └── ValidationFailedResultModel.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Startup.cs │ ├── appsettings.Development.json │ └── appsettings.json ├── DotNetCoreRedisDemo └── DotNetCoreRedisDemo │ ├── DotNetCoreRedisDemo.csproj │ └── Program.cs ├── LICENSE ├── NetCoreConfigDemo ├── .dockerignore ├── NetCoreConfigDemo.sln ├── NetCoreConfigDemo │ ├── App.Config │ ├── App.json │ ├── NetCoreConfigDemo.csproj │ ├── Program.cs │ └── user.cs ├── NetCoreConfigWebDemo │ ├── Controllers │ │ └── HomeController.cs │ ├── Models │ │ └── ErrorViewModel.cs │ ├── NetCoreConfigWebDemo.csproj │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── RedisConfig.cs │ ├── Startup.cs │ ├── UserInfo.cs │ ├── Views │ │ ├── Home │ │ │ ├── About.cshtml │ │ │ ├── Contact.cshtml │ │ │ ├── Index.cshtml │ │ │ └── Privacy.cshtml │ │ ├── Shared │ │ │ ├── Error.cshtml │ │ │ ├── _CookieConsentPartial.cshtml │ │ │ ├── _Layout.cshtml │ │ │ └── _ValidationScriptsPartial.cshtml │ │ ├── _ViewImports.cshtml │ │ └── _ViewStart.cshtml │ ├── appsettings.Development.json │ ├── appsettings.json │ ├── userinfo.json │ └── wwwroot │ │ ├── css │ │ ├── site.css │ │ └── site.min.css │ │ ├── favicon.ico │ │ ├── images │ │ ├── banner1.svg │ │ ├── banner2.svg │ │ └── banner3.svg │ │ ├── js │ │ ├── site.js │ │ └── site.min.js │ │ └── lib │ │ ├── bootstrap │ │ ├── .bower.json │ │ ├── LICENSE │ │ └── dist │ │ │ ├── css │ │ │ ├── bootstrap-theme.css │ │ │ ├── bootstrap-theme.css.map │ │ │ ├── bootstrap-theme.min.css │ │ │ ├── bootstrap-theme.min.css.map │ │ │ ├── bootstrap.css │ │ │ ├── bootstrap.css.map │ │ │ ├── bootstrap.min.css │ │ │ └── bootstrap.min.css.map │ │ │ ├── fonts │ │ │ ├── glyphicons-halflings-regular.eot │ │ │ ├── glyphicons-halflings-regular.svg │ │ │ ├── glyphicons-halflings-regular.ttf │ │ │ ├── glyphicons-halflings-regular.woff │ │ │ └── glyphicons-halflings-regular.woff2 │ │ │ └── js │ │ │ ├── bootstrap.js │ │ │ ├── bootstrap.min.js │ │ │ └── npm.js │ │ ├── jquery-validation-unobtrusive │ │ ├── .bower.json │ │ ├── jquery.validate.unobtrusive.js │ │ └── jquery.validate.unobtrusive.min.js │ │ ├── jquery-validation │ │ ├── .bower.json │ │ ├── LICENSE.md │ │ └── dist │ │ │ ├── additional-methods.js │ │ │ ├── additional-methods.min.js │ │ │ ├── jquery.validate.js │ │ │ └── jquery.validate.min.js │ │ └── jquery │ │ ├── .bower.json │ │ └── dist │ │ ├── jquery.js │ │ ├── jquery.min.js │ │ └── jquery.min.map ├── NetCoreEnvironmentDemo │ ├── Dockerfile │ ├── NetCoreEnvironmentDemo.csproj │ └── Program.cs ├── NetCoreRedisConfigDemo │ ├── NetCoreRedisConfigDemo.csproj │ ├── Program.cs │ ├── RedisConfigExtension.cs │ ├── RedisConfigProvider.cs │ └── RedisConfigSource.cs ├── docker-compose.dcproj ├── docker-compose.override.yml └── docker-compose.yml ├── Office2PDF ├── .vscode │ ├── launch.json │ └── tasks.json ├── Office2PDF.csproj ├── Office2PDF.sln └── Office2PDF │ ├── App.config │ ├── Common │ ├── APIHelper.cs │ ├── GridFSOperationManager.cs │ ├── Interface │ │ ├── IFileOperationManager.cs │ │ └── IPowerPointConverter.cs │ ├── Model │ │ ├── FileByteInfo.cs │ │ └── FileInfo.cs │ ├── MySQLHelper.cs │ └── PowerPointConverter.cs │ ├── Extension │ ├── AttributeExtension.cs │ ├── Convertor.cs │ └── ObjectExtension.cs │ ├── MQ │ ├── MQManager.cs │ ├── MessageModel │ │ ├── FileMessage.cs │ │ └── Messages.cs │ └── RabbitMQProxyConfig │ │ ├── RabbitMqConfig.cs │ │ └── RabbitMqQueueAttribute.cs │ ├── Office2PDF.csproj │ ├── Program.cs │ └── Properties │ └── launchSettings.json ├── RabbitMQDLXDemo ├── Consumer │ ├── Consumer.csproj │ └── Program.cs └── Producter │ ├── Producer.csproj │ └── Program.cs ├── RedisLockDemo ├── RedisLockConsoleApp1 │ ├── Program.cs │ └── RedisLockConsoleApp1.csproj ├── RedisLockConsoleApp2 │ ├── Program.cs │ └── RedisLockConsoleApp2.csproj ├── RedisLockDemo.sln └── RedisLockLib │ ├── MySQLHelper.cs │ ├── RedisLockLib.csproj │ └── SeqNo.cs ├── UpdateOcelotConfig ├── Client │ ├── Client.csproj │ └── Program.cs ├── IdentityService │ ├── AnonymousGrantValidator.cs │ ├── Config.cs │ ├── Controllers │ │ └── ValuesController.cs │ ├── IdentityService.csproj │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Startup.cs │ ├── appsettings.Development.json │ ├── appsettings.json │ └── tempkey.rsa ├── UpdateOcelotConfig.sln └── WebAPIGetway │ ├── Ocelot.json │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Startup.cs │ ├── WebAPIGetway.csproj │ ├── appsettings.Development.json │ └── appsettings.json └── VueSample └── hello-world ├── README.md ├── babel.config.js ├── dist ├── Dockerfile ├── css │ ├── app.6af8ca07.css │ ├── chunk-96d74ff0.9f02239b.css │ └── chunk-vendors.728eb7d9.css ├── favicon.ico ├── fonts │ ├── element-icons.535877f5.woff │ └── element-icons.732389de.ttf ├── img │ └── logo.82b9c7a5.png ├── index.html └── js │ ├── app.bc39e0c0.js │ ├── app.bc39e0c0.js.map │ ├── chunk-2d0ac3bd.bf4d9a0e.js │ ├── chunk-2d0ac3bd.bf4d9a0e.js.map │ ├── chunk-96d74ff0.98d44380.js │ ├── chunk-96d74ff0.98d44380.js.map │ ├── chunk-vendors.cf179395.js │ └── chunk-vendors.cf179395.js.map ├── package-lock.json ├── package.json ├── public ├── favicon.ico └── index.html ├── src ├── App.vue ├── assets │ └── logo.png ├── common │ └── http.js ├── components │ ├── home.vue │ ├── login.vue │ └── top-bar.vue ├── main.js ├── routers │ └── router.js └── services │ └── login.service.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | Thumbs.db 2 | *.obj 3 | *.exe 4 | *.pdb 5 | *.user 6 | *.aps 7 | *.pch 8 | *.vspscc 9 | *_i.c 10 | *_p.c 11 | *.ncb 12 | *.suo 13 | *.sln.docstates 14 | *.tlb 15 | *.tlh 16 | *.bak 17 | *.cache 18 | *.ilk 19 | *.log 20 | *.txt 21 | [Bb]in 22 | [Dd]ebug*/ 23 | *.lib 24 | *.sbr 25 | obj/ 26 | [Rr]elease*/ 27 | _ReSharper*/ 28 | [Tt]est[Rr]esult* 29 | *.vssscc 30 | $tf*/ 31 | *.orig 32 | packages 33 | 34 | 35 | .vs 36 | .vs/ 37 | .vs/config/applicationhost.config 38 | 39 | 40 | .DS_Store 41 | node_modules 42 | /dist 43 | 44 | # local env files 45 | .env.local 46 | .env.*.local 47 | 48 | # Log files 49 | npm-debug.log* 50 | yarn-debug.log* 51 | yarn-error.log* 52 | 53 | # Editor directories and files 54 | .idea 55 | .vscode 56 | *.suo 57 | *.ntvs* 58 | *.njsproj 59 | *.sln 60 | *.sw? 61 | -------------------------------------------------------------------------------- /DotNetCoreAdDemo/DotNetCoreAdDemo/ADHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Novell.Directory.Ldap; 4 | 5 | namespace DotNetCoreAdDemo 6 | { 7 | public class ADHelper 8 | { 9 | private LdapConnection _connection; 10 | private string[] _adPaths; 11 | private string _adHost; 12 | private Org _org; 13 | private User _user; 14 | public bool ADConnect() 15 | { 16 | _adHost = "192.168.16.160"; 17 | string adAdminUserName = "administrator"; 18 | string adAdminPassword = "123456"; 19 | _adPaths =new string[] { "OU=oec2003,DC=COM,DC=cn" }; 20 | 21 | if ((string.IsNullOrEmpty(_adHost) || string.IsNullOrEmpty(adAdminUserName)) || 22 | string.IsNullOrEmpty(adAdminPassword)) 23 | { 24 | return false; 25 | } 26 | try 27 | { 28 | _connection = new LdapConnection(); 29 | _connection.Connect(_adHost, LdapConnection.DEFAULT_PORT); 30 | _connection.Bind(adAdminUserName, adAdminPassword); 31 | } 32 | catch 33 | { 34 | return false; 35 | } 36 | 37 | return true; 38 | } 39 | 40 | public List GetRootEntries(string[] adPathes, string host) 41 | { 42 | List list = new List(); 43 | foreach (string path in adPathes) 44 | { 45 | if (!string.IsNullOrEmpty(host)) 46 | { 47 | LdapEntry entry = _connection.Read(path); 48 | list.Add(entry); 49 | } 50 | } 51 | return list; 52 | } 53 | 54 | public bool Sync() 55 | { 56 | ADConnect(); 57 | 58 | if (_connection == null) 59 | { 60 | throw new Exception("AD连接错误,请确认AD相关信息配置正确!"); 61 | } 62 | bool result = true; 63 | List entryList = this.GetRootEntries(_adPaths, _adHost); 64 | _org = new Org(); 65 | _user = new User(); 66 | Org rootOrg = _org.GetRootOrg(); 67 | foreach (LdapEntry entry in entryList) 68 | { 69 | SyncDirectoryEntry(entry, rootOrg, entry); 70 | } 71 | 72 | return result; 73 | } 74 | 75 | private void SyncDirectoryEntry(LdapEntry rootEntry, Org parentOrg, LdapEntry currentEntry) 76 | { 77 | List entryList = currentEntry.Children(_connection); 78 | foreach (LdapEntry entry in entryList) 79 | { 80 | if (entry.IsOrganizationalUnit()) 81 | { 82 | Org org = this.SyncOrgFromEntry(rootEntry, parentOrg, entry); 83 | this.SyncDirectoryEntry(rootEntry, org, entry); 84 | } 85 | else if (entry.IsUser()) 86 | { 87 | this.SyncUserFromEntry(rootEntry, parentOrg, entry); 88 | } 89 | } 90 | } 91 | 92 | private Org SyncOrgFromEntry(LdapEntry rootEntry, Org parentOrg, LdapEntry entry) 93 | { 94 | string orgId = entry.Guid().ToLower(); 95 | Org org = this._org.GetOrgById(orgId) as Org; 96 | if (org != null) 97 | { 98 | if (entry.ContainsAttr("ou")) 99 | { 100 | org.Name = entry.getAttribute("ou").StringValue + string.Empty; 101 | } 102 | //设置其他属性的值 103 | _org.UpdateOrg(org); 104 | return org; 105 | } 106 | org = new Org 107 | { 108 | Id = orgId, 109 | ParentId = parentOrg.Id, 110 | }; 111 | 112 | //设置其他属性的值 113 | this._org.AddOrg(org); 114 | return org; 115 | } 116 | 117 | private User SyncUserFromEntry(LdapEntry rootEntry, Org parentOrg, LdapEntry entry) 118 | { 119 | string userId = entry.Guid().ToLower(); 120 | User user = this._user.GetUserById(userId); 121 | if (user != null) 122 | { 123 | user.ParentId = parentOrg.Id; 124 | //设置其他属性的值 125 | this._user.UpdateUser(user); 126 | 127 | return user; 128 | } 129 | user = new User 130 | { 131 | Id = userId, 132 | ParentId = parentOrg.Id 133 | }; 134 | //设置其他属性的值 135 | this._user.AddUser(user); 136 | return user; 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /DotNetCoreAdDemo/DotNetCoreAdDemo/DotNetCoreAdDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /DotNetCoreAdDemo/DotNetCoreAdDemo/LdapExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Novell.Directory.Ldap; 4 | 5 | namespace DotNetCoreAdDemo 6 | { 7 | public static class LdapExtension 8 | { 9 | public static string Guid(this LdapEntry entry) 10 | { 11 | var bytes = (byte[])(entry.getAttribute("objectGUID").ByteValue as object); 12 | var guid = new Guid(bytes); 13 | return guid.ToString(); 14 | } 15 | 16 | public static List Children(this LdapEntry entry, LdapConnection connection) 17 | { 18 | //string filter = "(&(objectclass=user))"; 19 | List entryList = new List(); 20 | LdapSearchResults lsc = connection.Search(entry.DN, LdapConnection.SCOPE_ONE, "objectClass=*", null, false); 21 | if (lsc == null) return entryList; 22 | 23 | while (lsc.HasMore()) 24 | { 25 | LdapEntry nextEntry = null; 26 | try 27 | { 28 | nextEntry = lsc.Next(); 29 | 30 | if (nextEntry.IsUser() || nextEntry.IsOrganizationalUnit()) 31 | { 32 | entryList.Add(nextEntry); 33 | } 34 | } 35 | catch (LdapException e) 36 | { 37 | continue; 38 | } 39 | } 40 | return entryList; 41 | } 42 | 43 | public static List ObjectClass(this LdapEntry entry) 44 | { 45 | List list = new List(); 46 | byte[][] bytes = (byte[][])(entry.getAttribute("objectClass").ByteValueArray as object); 47 | for (var i = 0; i < bytes.Length; i++) 48 | { 49 | string str = System.Text.Encoding.Default.GetString(bytes[i]); 50 | list.Add(str.ToLower()); 51 | } 52 | return list; 53 | } 54 | 55 | public static bool IsUser(this LdapEntry entry) 56 | { 57 | return entry.ObjectClass().Contains("user"); 58 | } 59 | 60 | public static bool IsOrganizationalUnit(this LdapEntry entry) 61 | { 62 | return entry.ObjectClass().Contains("organizationalunit"); 63 | } 64 | 65 | public static DateTime WhenChanged(this LdapEntry entry) 66 | { 67 | string value = entry.getAttribute("whenChanged").StringValue; 68 | if (value.Split('.').Length > 1) 69 | { 70 | value = value.Split('.')[0]; 71 | } 72 | DateTime whenChanged = DateTime.ParseExact(value, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); 73 | return whenChanged; 74 | } 75 | 76 | public static bool ContainsAttr(this LdapEntry entry, string attrName) 77 | { 78 | LdapAttribute ldapAttribute = new LdapAttribute(attrName); 79 | return entry.getAttributeSet().Contains(ldapAttribute); 80 | } 81 | 82 | public static string AttrStringValue(this LdapEntry entry, string attrName) 83 | { 84 | if (!entry.ContainsAttr(attrName)) 85 | { 86 | return string.Empty; 87 | } 88 | return entry.getAttribute(attrName).StringValue; 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /DotNetCoreAdDemo/DotNetCoreAdDemo/Org.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace DotNetCoreAdDemo 3 | { 4 | public class Org 5 | { 6 | public string Id { get; set; } 7 | public string ParentId { get; set; } 8 | public string Name { get; set; } 9 | 10 | public bool AddOrg(Org org) 11 | { 12 | //数据库操作 13 | return true; 14 | } 15 | public bool UpdateOrg(Org org) 16 | { 17 | //数据库操作 18 | return true; 19 | } 20 | public Org GetRootOrg() 21 | { 22 | //获取根Org 23 | return new Org(); 24 | } 25 | public Org GetOrgById(string id) 26 | { 27 | //根据Id获取Org 28 | return new Org(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /DotNetCoreAdDemo/DotNetCoreAdDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DotNetCoreAdDemo 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | ADHelper helper = new ADHelper(); 10 | helper.Sync(); 11 | 12 | Console.WriteLine("Success"); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /DotNetCoreAdDemo/DotNetCoreAdDemo/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace DotNetCoreAdDemo 3 | { 4 | public class User 5 | { 6 | public string Id { get; set; } 7 | public string ParentId { get; set; } 8 | public string Name { get; set; } 9 | 10 | public bool AddUser(User user) 11 | { 12 | //数据库操作 13 | return true; 14 | } 15 | public bool UpdateUser(User user) 16 | { 17 | //数据库操作 18 | return true; 19 | } 20 | public User GetUserById(string id) 21 | { 22 | //根据Id获取Org 23 | return new User(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /DotNetCoreApiSample/DotNetCoreApiSample.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetCoreApiSample", "DotNetCoreApiSample\DotNetCoreApiSample.csproj", "{37C05AD4-4F0C-43FD-BDA3-CB06C0898572}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {37C05AD4-4F0C-43FD-BDA3-CB06C0898572}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {37C05AD4-4F0C-43FD-BDA3-CB06C0898572}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {37C05AD4-4F0C-43FD-BDA3-CB06C0898572}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {37C05AD4-4F0C-43FD-BDA3-CB06C0898572}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | EndGlobal 18 | -------------------------------------------------------------------------------- /DotNetCoreApiSample/DotNetCoreApiSample/Controllers/ResultDemoController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace DotNetCoreApiSample.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | public class ResultDemoController : Controller 11 | { 12 | [HttpGet] 13 | public IActionResult GetUserCode() 14 | { 15 | return Ok("oec2003"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DotNetCoreApiSample/DotNetCoreApiSample/Controllers/ValidationDemoController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Mvc; 7 | 8 | namespace DotNetCoreApiSample.Controllers 9 | { 10 | [Route("api/[controller]")] 11 | public class ValidationDemoController : Controller 12 | { 13 | [HttpPost] 14 | public IActionResult AddUser([FromBody]User user) 15 | { 16 | //业务代码 17 | return Ok(); 18 | } 19 | } 20 | 21 | public class User 22 | { 23 | [Required(ErrorMessage = "用户Code不能为空")] 24 | public string Code { get; set; } 25 | [Required(ErrorMessage = "用户名称不能为空")] 26 | public string Name { get; set; } 27 | [Required(ErrorMessage = "用户年龄不能为空")] 28 | [Range(1, 100, ErrorMessage = "年龄必须介于1~100之间")] 29 | public int Age { get; set; } 30 | public string Address { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /DotNetCoreApiSample/DotNetCoreApiSample/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace DotNetCoreApiSample.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | [ApiController] 11 | public class ValuesController : ControllerBase 12 | { 13 | // GET api/values 14 | [HttpGet] 15 | public ActionResult> Get() 16 | { 17 | return new string[] { "value1", "value2" }; 18 | } 19 | 20 | // GET api/values/5 21 | [HttpGet("{id}")] 22 | public ActionResult Get(int id) 23 | { 24 | return "value"; 25 | } 26 | 27 | // POST api/values 28 | [HttpPost] 29 | public void Post([FromBody] string value) 30 | { 31 | } 32 | 33 | // PUT api/values/5 34 | [HttpPut("{id}")] 35 | public void Put(int id, [FromBody] string value) 36 | { 37 | } 38 | 39 | // DELETE api/values/5 40 | [HttpDelete("{id}")] 41 | public void Delete(int id) 42 | { 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /DotNetCoreApiSample/DotNetCoreApiSample/DotNetCoreApiSample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.1 5 | 6 | 7 | 8 | bin\Debug\netcoreapp2.1\DotNetCoreApiSample.xml 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /DotNetCoreApiSample/DotNetCoreApiSample/Filters/ApiResultFilterAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using DotNetCoreApiSample.Models; 3 | using Microsoft.AspNetCore.Mvc; 4 | using Microsoft.AspNetCore.Mvc.Filters; 5 | 6 | namespace DotNetCoreApiSample.Filters 7 | { 8 | public class ApiResultFilterAttribute : ActionFilterAttribute 9 | { 10 | public override void OnActionExecuting(ActionExecutingContext context) 11 | { 12 | base.OnActionExecuting(context); 13 | } 14 | public override void OnResultExecuting(ResultExecutingContext context) 15 | { 16 | if (context.Result is ValidationFailedResult) 17 | { 18 | var objectResult = context.Result as ObjectResult; 19 | context.Result = objectResult; 20 | } 21 | else 22 | { 23 | var objectResult = context.Result as ObjectResult; 24 | context.Result = new OkObjectResult(new BaseResultModel(code: 200, result: objectResult.Value)); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /DotNetCoreApiSample/DotNetCoreApiSample/Filters/CustomExceptionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using DotNetCoreApiSample.Models; 4 | using Microsoft.AspNetCore.Mvc.Filters; 5 | 6 | namespace DotNetCoreApiSample.Filters 7 | { 8 | public class CustomExceptionAttribute : IExceptionFilter 9 | { 10 | public void OnException(ExceptionContext context) 11 | { 12 | HttpStatusCode status = HttpStatusCode.InternalServerError; 13 | 14 | //处理各种异常 15 | 16 | context.ExceptionHandled = true; 17 | context.Result = new CustomExceptionResult((int)status, context.Exception); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DotNetCoreApiSample/DotNetCoreApiSample/Filters/ValidateModelAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using DotNetCoreApiSample.Models; 4 | using Microsoft.AspNetCore.Mvc; 5 | using Microsoft.AspNetCore.Mvc.Filters; 6 | using Newtonsoft.Json; 7 | 8 | namespace DotNetCoreApiSample.Filters 9 | { 10 | public class ValidateModelAttribute : ActionFilterAttribute 11 | { 12 | public override void OnActionExecuting(ActionExecutingContext context) 13 | { 14 | if (!context.ModelState.IsValid) 15 | { 16 | context.Result = new ValidationFailedResult(context.ModelState); 17 | } 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DotNetCoreApiSample/DotNetCoreApiSample/Models/BaseResultModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace DotNetCoreApiSample.Models 3 | { 4 | public class BaseResultModel 5 | { 6 | public BaseResultModel(int? code = null, string message = null, 7 | object result = null, ReturnStatus returnStatus = ReturnStatus.Success) 8 | { 9 | this.Code = code; 10 | this.Result = result; 11 | this.Message = message; 12 | this.ReturnStatus = returnStatus; 13 | } 14 | public int? Code { get; set; } 15 | 16 | public string Message { get; set; } 17 | 18 | public object Result { get; set; } 19 | 20 | public ReturnStatus ReturnStatus { get; set; } 21 | } 22 | public enum ReturnStatus 23 | { 24 | Success = 1, 25 | Fail = 0, 26 | ConfirmIsContinue = 2, 27 | Error = 3 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /DotNetCoreApiSample/DotNetCoreApiSample/Models/CustomExceptionResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.AspNetCore.Mvc; 3 | 4 | namespace DotNetCoreApiSample.Models 5 | { 6 | public class CustomExceptionResult:ObjectResult 7 | { 8 | public CustomExceptionResult(int? code, Exception exception) 9 | : base(new CustomExceptionResultModel(code, exception)) 10 | { 11 | StatusCode = code; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DotNetCoreApiSample/DotNetCoreApiSample/Models/CustomExceptionResultModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | 4 | namespace DotNetCoreApiSample.Models 5 | { 6 | public class CustomExceptionResultModel:BaseResultModel 7 | { 8 | public CustomExceptionResultModel(int? code, Exception exception) 9 | { 10 | Code = code; 11 | Message = exception.InnerException != null ? 12 | exception.InnerException.Message : 13 | exception.Message; 14 | Result = exception.Message; 15 | ReturnStatus = ReturnStatus.Error; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DotNetCoreApiSample/DotNetCoreApiSample/Models/ValidationFailedResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.AspNetCore.Http; 3 | using Microsoft.AspNetCore.Mvc; 4 | using Microsoft.AspNetCore.Mvc.ModelBinding; 5 | 6 | namespace DotNetCoreApiSample.Models 7 | { 8 | public class ValidationFailedResult: ObjectResult 9 | { 10 | 11 | public ValidationFailedResult(ModelStateDictionary modelState) 12 | : base(new ValidationFailedResultModel(modelState)) 13 | { 14 | StatusCode = StatusCodes.Status422UnprocessableEntity; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DotNetCoreApiSample/DotNetCoreApiSample/Models/ValidationFailedResultModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using Microsoft.AspNetCore.Mvc.ModelBinding; 4 | using Newtonsoft.Json; 5 | 6 | namespace DotNetCoreApiSample.Models 7 | { 8 | public class ValidationFailedResultModel : BaseResultModel 9 | { 10 | public ValidationFailedResultModel(ModelStateDictionary modelState) 11 | { 12 | Code = 422; 13 | Message = "参数不合法"; 14 | Result = modelState.Keys 15 | .SelectMany(key => modelState[key].Errors.Select(x => new ValidationError(key, x.ErrorMessage))) 16 | .ToList(); 17 | ReturnStatus = ReturnStatus.Fail; 18 | } 19 | } 20 | 21 | public class ValidationError 22 | { 23 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] 24 | public string Field { get; } 25 | public string Message { get; } 26 | public ValidationError(string field, string message) 27 | { 28 | Field = field != string.Empty ? field : null; 29 | Message = message; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /DotNetCoreApiSample/DotNetCoreApiSample/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace DotNetCoreApiSample 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateWebHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .UseUrls("http://*:5000"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /DotNetCoreApiSample/DotNetCoreApiSample/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:19559", 8 | "sslPort": 44328 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "api/values", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "DotNetCoreApiSample": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "api/values", 24 | "environmentVariables": { 25 | "ASPNETCORE_ENVIRONMENT": "Development" 26 | }, 27 | "applicationUrl": "https://localhost:5001;http://localhost:5000" 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /DotNetCoreApiSample/DotNetCoreApiSample/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using DotNetCoreApiSample.Filters; 6 | using Microsoft.AspNetCore.Builder; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.AspNetCore.HttpsPolicy; 9 | using Microsoft.AspNetCore.Mvc; 10 | using Microsoft.Extensions.Configuration; 11 | using Microsoft.Extensions.DependencyInjection; 12 | using Microsoft.Extensions.Logging; 13 | using Microsoft.Extensions.Options; 14 | 15 | namespace DotNetCoreApiSample 16 | { 17 | public class Startup 18 | { 19 | public Startup(IConfiguration configuration) 20 | { 21 | Configuration = configuration; 22 | } 23 | 24 | public IConfiguration Configuration { get; } 25 | 26 | // This method gets called by the runtime. Use this method to add services to the container. 27 | public void ConfigureServices(IServiceCollection services) 28 | { 29 | services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); 30 | 31 | services.AddSwaggerGen(options => 32 | { 33 | options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info 34 | { 35 | Version = "v1", 36 | Title = "DotNet Core WebAPI文档" 37 | }); 38 | 39 | }); 40 | 41 | services.AddMvc(options => 42 | { 43 | options.Filters.Add(); 44 | options.Filters.Add(); 45 | options.Filters.Add(); 46 | }); 47 | } 48 | 49 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 50 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 51 | { 52 | if (env.IsDevelopment()) 53 | { 54 | app.UseDeveloperExceptionPage(); 55 | } 56 | else 57 | { 58 | app.UseHsts(); 59 | } 60 | 61 | app.UseHttpsRedirection(); 62 | 63 | 64 | app.UseSwagger(); 65 | app.UseSwaggerUI(c => 66 | { 67 | c.SwaggerEndpoint("/swagger/v1/swagger.json", "DotNet Core WebAPI文档"); 68 | }); 69 | 70 | app.UseMvc(); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /DotNetCoreApiSample/DotNetCoreApiSample/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /DotNetCoreApiSample/DotNetCoreApiSample/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning" 5 | } 6 | }, 7 | "AllowedHosts": "*" 8 | } 9 | -------------------------------------------------------------------------------- /DotNetCoreRedisDemo/DotNetCoreRedisDemo/DotNetCoreRedisDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /DotNetCoreRedisDemo/DotNetCoreRedisDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using CSRedis; 4 | 5 | namespace DotNetCoreRedisDemo 6 | { 7 | class Program 8 | { 9 | static void Main(string[] args) 10 | { 11 | string redisServerIP = "172.16.0.13"; 12 | string redisServerPort = "6380"; 13 | string redisPassword = ""; 14 | bool isSentinelMode = false; 15 | 16 | string connectionString = GetRedisConnectionString(redisServerIP, redisServerPort, redisPassword,0, "", isSentinelMode); 17 | //哨兵模式 18 | if (isSentinelMode) 19 | { 20 | redisServerIP = "172.16.0.13,172.16.0.13"; //哨兵IP列表 21 | redisServerPort = "26379,26380"; 22 | List connectionList = GetRedisConnectionList(redisServerIP, redisServerPort); 23 | CSRedisClient csredis = new CSRedisClient(connectionString, connectionList.ToArray()); 24 | RedisHelper.Initialization(csredis);//初始化 25 | } 26 | else 27 | { 28 | //普通模式,连接主库 29 | CSRedisClient csredis = new CSRedisClient(connectionString); 30 | RedisHelper.Initialization(csredis);//初始化 31 | } 32 | Console.WriteLine("Hello World!"); 33 | } 34 | 35 | private static List GetRedisConnectionList(string ips, string ports) 36 | { 37 | List connectionList = new List(); 38 | 39 | for (int i = 0; i < ips.Split(',').Length; i++) 40 | { 41 | string ip = ips.Split(',')[i]; 42 | string port = ports.Split(',')[i]; 43 | 44 | connectionList.Add($"{ip}:{port}"); 45 | } 46 | 47 | return connectionList; 48 | } 49 | 50 | private static string GetRedisConnectionString(string ip, string port, string password, int database, string masterName, bool isSentinelMode) 51 | { 52 | 53 | string connctionString; 54 | 55 | if (isSentinelMode) 56 | { 57 | masterName = string.IsNullOrWhiteSpace(masterName) ? "mymaster" : masterName; 58 | connctionString = $"{masterName},defaultDatabase={database},poolsize=50,connectTimeout=200,ssl=false,writeBuffer=10240,prefix=S2"; 59 | if (!string.IsNullOrWhiteSpace(password)) 60 | { 61 | connctionString = $"{masterName},password={password},defaultDatabase={database},poolsize=50,connectTimeout=200,ssl=false,writeBuffer=10240,prefix=S2"; 62 | } 63 | } 64 | else 65 | { 66 | connctionString = $"{ip}:{port},defaultDatabase={database},poolsize=50,ssl=false,writeBuffer=10240,prefix=S2"; 67 | if (!string.IsNullOrWhiteSpace(password)) 68 | { 69 | connctionString = $"{ip}:{port},password={password},defaultDatabase={database},poolsize=50,ssl=false,writeBuffer=10240,prefix=S2"; 70 | } 71 | } 72 | 73 | return connctionString; 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 oec2003 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/.dockerignore: -------------------------------------------------------------------------------- 1 | .dockerignore 2 | .env 3 | .git 4 | .gitignore 5 | .vs 6 | .vscode 7 | docker-compose.yml 8 | docker-compose.*.yml 9 | */bin 10 | */obj 11 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigDemo.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetCoreConfigDemo", "NetCoreConfigDemo\NetCoreConfigDemo.csproj", "{7B941B6E-75E3-417C-85D0-99A648CF3E80}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetCoreConfigWebDemo", "NetCoreConfigWebDemo\NetCoreConfigWebDemo.csproj", "{E1CA436C-FB1B-4577-A225-9BA75890ACA1}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetCoreRedisConfigDemo", "NetCoreRedisConfigDemo\NetCoreRedisConfigDemo.csproj", "{EBDF81D4-7A9D-423A-ABCF-A8C80CF3960A}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetCoreEnvironmentDemo", "NetCoreEnvironmentDemo\NetCoreEnvironmentDemo.csproj", "{4511D629-8BEB-4C4A-9E7D-05F817B5479A}" 11 | EndProject 12 | Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{28ED9C86-976B-4DA6-B01F-A9CDF697DF81}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {7B941B6E-75E3-417C-85D0-99A648CF3E80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {7B941B6E-75E3-417C-85D0-99A648CF3E80}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {7B941B6E-75E3-417C-85D0-99A648CF3E80}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {7B941B6E-75E3-417C-85D0-99A648CF3E80}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {E1CA436C-FB1B-4577-A225-9BA75890ACA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {E1CA436C-FB1B-4577-A225-9BA75890ACA1}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {E1CA436C-FB1B-4577-A225-9BA75890ACA1}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {E1CA436C-FB1B-4577-A225-9BA75890ACA1}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {EBDF81D4-7A9D-423A-ABCF-A8C80CF3960A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {EBDF81D4-7A9D-423A-ABCF-A8C80CF3960A}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {EBDF81D4-7A9D-423A-ABCF-A8C80CF3960A}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {EBDF81D4-7A9D-423A-ABCF-A8C80CF3960A}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {4511D629-8BEB-4C4A-9E7D-05F817B5479A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {4511D629-8BEB-4C4A-9E7D-05F817B5479A}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {4511D629-8BEB-4C4A-9E7D-05F817B5479A}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {4511D629-8BEB-4C4A-9E7D-05F817B5479A}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {28ED9C86-976B-4DA6-B01F-A9CDF697DF81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {28ED9C86-976B-4DA6-B01F-A9CDF697DF81}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {28ED9C86-976B-4DA6-B01F-A9CDF697DF81}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {28ED9C86-976B-4DA6-B01F-A9CDF697DF81}.Release|Any CPU.Build.0 = Release|Any CPU 40 | EndGlobalSection 41 | EndGlobal 42 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigDemo/App.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigDemo/App.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "oec2003" 3 | } 4 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigDemo/NetCoreConfigDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | 7 | 8 | 9 | Project 10 | name=oec2005 11 | true 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Always 23 | 24 | 25 | 26 | 27 | Always 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Extensions.Configuration; 3 | using System.Collections.Generic; 4 | namespace NetCoreConfigDemo 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | var dic = new Dictionary() { { "name","oec2003"}}; 11 | var builder = new ConfigurationBuilder() 12 | .AddInMemoryCollection(dic) 13 | .AddJsonFile("App.json") 14 | .AddCommandLine(args); 15 | 16 | var configration = builder.Build(); 17 | Console.WriteLine($"name:{configration["name"]}"); 18 | 19 | Console.ReadLine(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigDemo/user.cs: -------------------------------------------------------------------------------- 1 | namespace NetCoreConfigDemo 2 | { 3 | public class user 4 | { 5 | public const string TableName="t_user"; 6 | } 7 | } -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.Options; 3 | 4 | namespace NetCoreConfigWebDemo.Controllers 5 | { 6 | public class HomeController : Controller 7 | { 8 | //private UserInfo _userInfo; 9 | //public HomeController(IOptions options) 10 | //{ 11 | // _userInfo = options.Value; 12 | //} 13 | 14 | public IActionResult Index() 15 | { 16 | //return View(_userInfo); 17 | return View(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NetCoreConfigWebDemo.Models 4 | { 5 | public class ErrorViewModel 6 | { 7 | public string RequestId { get; set; } 8 | 9 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 10 | } 11 | } -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/NetCoreConfigWebDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace NetCoreConfigWebDemo 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateWebHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:36715", 7 | "sslPort": 44354 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "NetCoreConfigWebDemo": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/RedisConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace NetCoreConfigWebDemo 3 | { 4 | public class RedisConfig 5 | { 6 | public string HostName { get; set; } 7 | public int Port { get; set; } 8 | public string Password { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.AspNetCore.HttpsPolicy; 9 | using Microsoft.AspNetCore.Mvc; 10 | using Microsoft.Extensions.Configuration; 11 | using Microsoft.Extensions.DependencyInjection; 12 | 13 | namespace NetCoreConfigWebDemo 14 | { 15 | public class Startup 16 | { 17 | public Startup(IConfiguration configuration) 18 | { 19 | Configuration = configuration; 20 | } 21 | 22 | public IConfiguration Configuration { get; } 23 | 24 | // This method gets called by the runtime. Use this method to add services to the container. 25 | public void ConfigureServices(IServiceCollection services) 26 | { 27 | services.Configure(options => 28 | { 29 | options.CheckConsentNeeded = context => true; 30 | options.MinimumSameSitePolicy = SameSiteMode.None; 31 | }); 32 | 33 | services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); 34 | 35 | //注册UserInfo类 36 | services.Configure(Configuration.GetSection("UserInfo")); 37 | } 38 | 39 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 40 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 41 | { 42 | if (env.IsDevelopment()) 43 | { 44 | app.UseDeveloperExceptionPage(); 45 | } 46 | else 47 | { 48 | app.UseExceptionHandler("/Home/Error"); 49 | app.UseHsts(); 50 | } 51 | 52 | app.UseHttpsRedirection(); 53 | app.UseStaticFiles(); 54 | app.UseCookiePolicy(); 55 | 56 | app.UseMvc(routes => 57 | { 58 | routes.MapRoute( 59 | name: "default", 60 | template: "{controller=Home}/{action=Index}/{id?}"); 61 | }); 62 | 63 | //var userInfo = new UserInfo(); 64 | //Configuration.GetSection("UserInfo").Bind(userInfo); 65 | 66 | //Console.WriteLine($"Name:{userInfo.UserName}"); 67 | //Console.WriteLine($"Age:{userInfo.Age}"); 68 | //Console.WriteLine($"Address:{userInfo.Address}"); 69 | 70 | Console.WriteLine($"RedisHostName:{userInfo.Address}"); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/UserInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace NetCoreConfigWebDemo 3 | { 4 | public class UserInfo 5 | { 6 | public string UserName { get; set; } 7 | 8 | public int Age { get; set; } 9 | 10 | public string Address { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/Views/Home/About.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "About"; 3 | } 4 |

@ViewData["Title"]

5 |

@ViewData["Message"]

6 | 7 |

Use this area to provide additional information.

8 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/Views/Home/Contact.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Contact"; 3 | } 4 |

@ViewData["Title"]

5 |

@ViewData["Message"]

6 | 7 |
8 | One Microsoft Way
9 | Redmond, WA 98052-6399
10 | P: 11 | 425.555.0100 12 |
13 | 14 |
15 | Support: Support@example.com
16 | Marketing: Marketing@example.com 17 |
18 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @using Microsoft.Extensions.Options; 2 | @inject IOptionsSnapshot userInfo;
@{ 3 | ViewData["Title"] = "Home Page"; 4 | }



UserInfo

5 |
  • UserName:@userInfo.Value.UserName
  • Age:@userInfo.Value.Age
  • Address:@userInfo.Value.Address
6 | 7 | @*

UserInfo

8 |
    9 | 10 |
  • UserName:@Model.UserName
  • 11 |
  • Age:@Model.Age
  • 12 |
  • Address:@Model.Address
  • 13 |
*@ 14 | 15 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/Views/Home/Privacy.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Privacy Policy"; 3 | } 4 |

@ViewData["Title"]

5 | 6 |

Use this page to detail your site's privacy policy.

7 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model ErrorViewModel 2 | @{ 3 | ViewData["Title"] = "Error"; 4 | } 5 | 6 |

Error.

7 |

An error occurred while processing your request.

8 | 9 | @if (Model.ShowRequestId) 10 | { 11 |

12 | Request ID: @Model.RequestId 13 |

14 | } 15 | 16 |

Development Mode

17 |

18 | Swapping to Development environment will display more detailed information about the error that occurred. 19 |

20 |

21 | Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application. 22 |

23 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/Views/Shared/_CookieConsentPartial.cshtml: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Http.Features 2 | 3 | @{ 4 | var consentFeature = Context.Features.Get 5 | (); 6 | var showBanner = !consentFeature?.CanTrack ?? false; 7 | var cookieString = consentFeature?.CreateConsentCookie(); 8 | } 9 | 10 | @if (showBanner) 11 | { 12 | 34 | 42 | } 43 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | @ViewData["Title"] - NetCoreConfigWebDemo 7 | 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | 19 | 20 | 40 | 41 | 42 | 43 |
44 | @RenderBody() 45 |
46 |
47 |

© 2018 - NetCoreConfigWebDemo

48 |
49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 69 | 70 | 71 | 72 | @RenderSection("Scripts", required: false) 73 | 74 | 75 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 12 | 18 | 19 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using NetCoreConfigWebDemo 2 | @using NetCoreConfigWebDemo.Models 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning" 5 | } 6 | }, 7 | "AllowedHosts": "*", 8 | //下面为新添加的内容 9 | "UserInfo": { 10 | "UserName": "oec2003", 11 | "Age": "36", 12 | "Address": "wuhan china" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/userinfo.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "oec2003", 3 | "age": "18", 4 | "address": "wuhan china" 5 | } 6 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/css/site.css: -------------------------------------------------------------------------------- 1 | /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification\ 2 | for details on configuring this project to bundle and minify static web assets. */ 3 | body { 4 | padding-top: 50px; 5 | padding-bottom: 20px; 6 | } 7 | 8 | /* Wrapping element */ 9 | /* Set some basic padding to keep content from hitting the edges */ 10 | .body-content { 11 | padding-left: 15px; 12 | padding-right: 15px; 13 | } 14 | 15 | /* Carousel */ 16 | .carousel-caption p { 17 | font-size: 20px; 18 | line-height: 1.4; 19 | } 20 | 21 | /* Make .svg files in the carousel display properly in older browsers */ 22 | .carousel-inner .item img[src$=".svg"] { 23 | width: 100%; 24 | } 25 | 26 | /* QR code generator */ 27 | #qrCode { 28 | margin: 15px; 29 | } 30 | 31 | /* Hide/rearrange for smaller screens */ 32 | @media screen and (max-width: 767px) { 33 | /* Hide captions */ 34 | .carousel-caption { 35 | display: none; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/css/site.min.css: -------------------------------------------------------------------------------- 1 | body{padding-top:50px;padding-bottom:20px}.body-content{padding-left:15px;padding-right:15px}.carousel-caption p{font-size:20px;line-height:1.4}.carousel-inner .item img[src$=".svg"]{width:100%}#qrCode{margin:15px}@media screen and (max-width:767px){.carousel-caption{display:none}} -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oec2003/StudySamples/7cea1b5b3b4c7028eaddddc3d6fc4aa73d12d8f1/NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/favicon.ico -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/images/banner1.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/images/banner2.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/images/banner3.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/js/site.js: -------------------------------------------------------------------------------- 1 | // Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2 | // for details on configuring this project to bundle and minify static web assets. 3 | 4 | // Write your JavaScript code. 5 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/js/site.min.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oec2003/StudySamples/7cea1b5b3b4c7028eaddddc3d6fc4aa73d12d8f1/NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/js/site.min.js -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/lib/bootstrap/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bootstrap", 3 | "description": "The most popular front-end framework for developing responsive, mobile first projects on the web.", 4 | "keywords": [ 5 | "css", 6 | "js", 7 | "less", 8 | "mobile-first", 9 | "responsive", 10 | "front-end", 11 | "framework", 12 | "web" 13 | ], 14 | "homepage": "http://getbootstrap.com", 15 | "license": "MIT", 16 | "moduleType": "globals", 17 | "main": [ 18 | "less/bootstrap.less", 19 | "dist/js/bootstrap.js" 20 | ], 21 | "ignore": [ 22 | "/.*", 23 | "_config.yml", 24 | "CNAME", 25 | "composer.json", 26 | "CONTRIBUTING.md", 27 | "docs", 28 | "js/tests", 29 | "test-infra" 30 | ], 31 | "dependencies": { 32 | "jquery": "1.9.1 - 3" 33 | }, 34 | "version": "3.3.7", 35 | "_release": "3.3.7", 36 | "_resolution": { 37 | "type": "version", 38 | "tag": "v3.3.7", 39 | "commit": "0b9c4a4007c44201dce9a6cc1a38407005c26c86" 40 | }, 41 | "_source": "https://github.com/twbs/bootstrap.git", 42 | "_target": "v3.3.7", 43 | "_originalSource": "bootstrap", 44 | "_direct": true 45 | } -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/lib/bootstrap/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2011-2016 Twitter, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oec2003/StudySamples/7cea1b5b3b4c7028eaddddc3d6fc4aa73d12d8f1/NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oec2003/StudySamples/7cea1b5b3b4c7028eaddddc3d6fc4aa73d12d8f1/NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oec2003/StudySamples/7cea1b5b3b4c7028eaddddc3d6fc4aa73d12d8f1/NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oec2003/StudySamples/7cea1b5b3b4c7028eaddddc3d6fc4aa73d12d8f1/NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/lib/bootstrap/dist/js/npm.js: -------------------------------------------------------------------------------- 1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment. 2 | require('../../js/transition.js') 3 | require('../../js/alert.js') 4 | require('../../js/button.js') 5 | require('../../js/carousel.js') 6 | require('../../js/collapse.js') 7 | require('../../js/dropdown.js') 8 | require('../../js/modal.js') 9 | require('../../js/tooltip.js') 10 | require('../../js/popover.js') 11 | require('../../js/scrollspy.js') 12 | require('../../js/tab.js') 13 | require('../../js/affix.js') -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/lib/jquery-validation-unobtrusive/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery-validation-unobtrusive", 3 | "homepage": "https://github.com/aspnet/jquery-validation-unobtrusive", 4 | "version": "3.2.9", 5 | "_release": "3.2.9", 6 | "_resolution": { 7 | "type": "version", 8 | "tag": "v3.2.9", 9 | "commit": "a91f5401898e125f10771c5f5f0909d8c4c82396" 10 | }, 11 | "_source": "https://github.com/aspnet/jquery-validation-unobtrusive.git", 12 | "_target": "^3.2.9", 13 | "_originalSource": "jquery-validation-unobtrusive", 14 | "_direct": true 15 | } -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js: -------------------------------------------------------------------------------- 1 | // Unobtrusive validation support library for jQuery and jQuery Validate 2 | // Copyright (C) Microsoft Corporation. All rights reserved. 3 | // @version v3.2.9 4 | !function(a){"function"==typeof define&&define.amd?define("jquery.validate.unobtrusive",["jquery.validation"],a):"object"==typeof module&&module.exports?module.exports=a(require("jquery-validation")):jQuery.validator.unobtrusive=a(jQuery)}(function(a){function e(a,e,n){a.rules[e]=n,a.message&&(a.messages[e]=a.message)}function n(a){return a.replace(/^\s+|\s+$/g,"").split(/\s*,\s*/g)}function t(a){return a.replace(/([!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~])/g,"\\$1")}function r(a){return a.substr(0,a.lastIndexOf(".")+1)}function i(a,e){return 0===a.indexOf("*.")&&(a=a.replace("*.",e)),a}function o(e,n){var r=a(this).find("[data-valmsg-for='"+t(n[0].name)+"']"),i=r.attr("data-valmsg-replace"),o=i?a.parseJSON(i)!==!1:null;r.removeClass("field-validation-valid").addClass("field-validation-error"),e.data("unobtrusiveContainer",r),o?(r.empty(),e.removeClass("input-validation-error").appendTo(r)):e.hide()}function d(e,n){var t=a(this).find("[data-valmsg-summary=true]"),r=t.find("ul");r&&r.length&&n.errorList.length&&(r.empty(),t.addClass("validation-summary-errors").removeClass("validation-summary-valid"),a.each(n.errorList,function(){a("
  • ").html(this.message).appendTo(r)}))}function s(e){var n=e.data("unobtrusiveContainer");if(n){var t=n.attr("data-valmsg-replace"),r=t?a.parseJSON(t):null;n.addClass("field-validation-valid").removeClass("field-validation-error"),e.removeData("unobtrusiveContainer"),r&&n.empty()}}function l(e){var n=a(this),t="__jquery_unobtrusive_validation_form_reset";if(!n.data(t)){n.data(t,!0);try{n.data("validator").resetForm()}finally{n.removeData(t)}n.find(".validation-summary-errors").addClass("validation-summary-valid").removeClass("validation-summary-errors"),n.find(".field-validation-error").addClass("field-validation-valid").removeClass("field-validation-error").removeData("unobtrusiveContainer").find(">*").removeData("unobtrusiveContainer")}}function u(e){var n=a(e),t=n.data(v),r=a.proxy(l,e),i=f.unobtrusive.options||{},u=function(n,t){var r=i[n];r&&a.isFunction(r)&&r.apply(e,t)};return t||(t={options:{errorClass:i.errorClass||"input-validation-error",errorElement:i.errorElement||"span",errorPlacement:function(){o.apply(e,arguments),u("errorPlacement",arguments)},invalidHandler:function(){d.apply(e,arguments),u("invalidHandler",arguments)},messages:{},rules:{},success:function(){s.apply(e,arguments),u("success",arguments)}},attachValidation:function(){n.off("reset."+v,r).on("reset."+v,r).validate(this.options)},validate:function(){return n.validate(),n.valid()}},n.data(v,t)),t}var m,f=a.validator,v="unobtrusiveValidation";return f.unobtrusive={adapters:[],parseElement:function(e,n){var t,r,i,o=a(e),d=o.parents("form")[0];d&&(t=u(d),t.options.rules[e.name]=r={},t.options.messages[e.name]=i={},a.each(this.adapters,function(){var n="data-val-"+this.name,t=o.attr(n),s={};void 0!==t&&(n+="-",a.each(this.params,function(){s[this]=o.attr(n+this)}),this.adapt({element:e,form:d,message:t,params:s,rules:r,messages:i}))}),a.extend(r,{__dummy__:!0}),n||t.attachValidation())},parse:function(e){var n=a(e),t=n.parents().addBack().filter("form").add(n.find("form")).has("[data-val=true]");n.find("[data-val=true]").each(function(){f.unobtrusive.parseElement(this,!0)}),t.each(function(){var a=u(this);a&&a.attachValidation()})}},m=f.unobtrusive.adapters,m.add=function(a,e,n){return n||(n=e,e=[]),this.push({name:a,params:e,adapt:n}),this},m.addBool=function(a,n){return this.add(a,function(t){e(t,n||a,!0)})},m.addMinMax=function(a,n,t,r,i,o){return this.add(a,[i||"min",o||"max"],function(a){var i=a.params.min,o=a.params.max;i&&o?e(a,r,[i,o]):i?e(a,n,i):o&&e(a,t,o)})},m.addSingleVal=function(a,n,t){return this.add(a,[n||"val"],function(r){e(r,t||a,r.params[n])})},f.addMethod("__dummy__",function(a,e,n){return!0}),f.addMethod("regex",function(a,e,n){var t;return!!this.optional(e)||(t=new RegExp(n).exec(a),t&&0===t.index&&t[0].length===a.length)}),f.addMethod("nonalphamin",function(a,e,n){var t;return n&&(t=a.match(/\W/g),t=t&&t.length>=n),t}),f.methods.extension?(m.addSingleVal("accept","mimtype"),m.addSingleVal("extension","extension")):m.addSingleVal("extension","extension","accept"),m.addSingleVal("regex","pattern"),m.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url"),m.addMinMax("length","minlength","maxlength","rangelength").addMinMax("range","min","max","range"),m.addMinMax("minlength","minlength").addMinMax("maxlength","minlength","maxlength"),m.add("equalto",["other"],function(n){var o=r(n.element.name),d=n.params.other,s=i(d,o),l=a(n.form).find(":input").filter("[name='"+t(s)+"']")[0];e(n,"equalTo",l)}),m.add("required",function(a){"INPUT"===a.element.tagName.toUpperCase()&&"CHECKBOX"===a.element.type.toUpperCase()||e(a,"required",!0)}),m.add("remote",["url","type","additionalfields"],function(o){var d={url:o.params.url,type:o.params.type||"GET",data:{}},s=r(o.element.name);a.each(n(o.params.additionalfields||o.element.name),function(e,n){var r=i(n,s);d.data[r]=function(){var e=a(o.form).find(":input").filter("[name='"+t(r)+"']");return e.is(":checkbox")?e.filter(":checked").val()||e.filter(":hidden").val()||"":e.is(":radio")?e.filter(":checked").val()||"":e.val()}}),e(o,"remote",d)}),m.add("password",["min","nonalphamin","regex"],function(a){a.params.min&&e(a,"minlength",a.params.min),a.params.nonalphamin&&e(a,"nonalphamin",a.params.nonalphamin),a.params.regex&&e(a,"regex",a.params.regex)}),m.add("fileextensions",["extensions"],function(a){e(a,"extension",a.params.extensions)}),a(function(){f.unobtrusive.parse(document)}),f.unobtrusive}); -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/lib/jquery-validation/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery-validation", 3 | "homepage": "https://jqueryvalidation.org/", 4 | "repository": { 5 | "type": "git", 6 | "url": "git://github.com/jquery-validation/jquery-validation.git" 7 | }, 8 | "authors": [ 9 | "Jörn Zaefferer " 10 | ], 11 | "description": "Form validation made easy", 12 | "main": "dist/jquery.validate.js", 13 | "keywords": [ 14 | "forms", 15 | "validation", 16 | "validate" 17 | ], 18 | "license": "MIT", 19 | "ignore": [ 20 | "**/.*", 21 | "node_modules", 22 | "bower_components", 23 | "test", 24 | "demo", 25 | "lib" 26 | ], 27 | "dependencies": { 28 | "jquery": ">= 1.7.2" 29 | }, 30 | "version": "1.17.0", 31 | "_release": "1.17.0", 32 | "_resolution": { 33 | "type": "version", 34 | "tag": "1.17.0", 35 | "commit": "fc9b12d3bfaa2d0c04605855b896edb2934c0772" 36 | }, 37 | "_source": "https://github.com/jzaefferer/jquery-validation.git", 38 | "_target": "^1.17.0", 39 | "_originalSource": "jquery-validation", 40 | "_direct": true 41 | } -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/lib/jquery-validation/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright Jörn Zaefferer 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreConfigWebDemo/wwwroot/lib/jquery/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery", 3 | "main": "dist/jquery.js", 4 | "license": "MIT", 5 | "ignore": [ 6 | "package.json" 7 | ], 8 | "keywords": [ 9 | "jquery", 10 | "javascript", 11 | "browser", 12 | "library" 13 | ], 14 | "homepage": "https://github.com/jquery/jquery-dist", 15 | "version": "3.3.1", 16 | "_release": "3.3.1", 17 | "_resolution": { 18 | "type": "version", 19 | "tag": "3.3.1", 20 | "commit": "9e8ec3d10fad04748176144f108d7355662ae75e" 21 | }, 22 | "_source": "https://github.com/jquery/jquery-dist.git", 23 | "_target": "^3.3.1", 24 | "_originalSource": "jquery", 25 | "_direct": true 26 | } -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreEnvironmentDemo/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM microsoft/aspnetcore 2 | COPY . /app 3 | WORKDIR /app 4 | EXPOSE 80/tcp 5 | ENTRYPOINT ["dotnet", "NetCoreEnvironmentDemo.dll"] 6 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreEnvironmentDemo/NetCoreEnvironmentDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.0 6 | ../docker-compose.dcproj 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Always 18 | 19 | 20 | 21 | 22 | Always 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreEnvironmentDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NetCoreEnvironmentDemo 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | string name = Environment.GetEnvironmentVariable("name"); 10 | string age = Environment.GetEnvironmentVariable("age"); 11 | 12 | Console.WriteLine($"name:{name}"); 13 | Console.WriteLine($"age:{age}"); 14 | Console.ReadLine(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreRedisConfigDemo/NetCoreRedisConfigDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreRedisConfigDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Extensions.Configuration; 3 | 4 | namespace NetCoreRedisConfigDemo 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | var builder = new ConfigurationBuilder() 11 | .AddRedisConfig(); 12 | var configration = builder.Build(); 13 | Console.WriteLine($"HostName:{configration["HostName"]}"); 14 | Console.WriteLine($"Port:{configration["Port"]}"); 15 | Console.WriteLine($"Password:{configration["Password"]}"); 16 | Console.ReadLine(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreRedisConfigDemo/RedisConfigExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Extensions.Configuration; 3 | 4 | namespace NetCoreRedisConfigDemo 5 | { 6 | 7 | public static class RedisConfigExtension 8 | { 9 | public static IConfigurationBuilder AddRedisConfig(this IConfigurationBuilder builder) 10 | { 11 | return builder.Add(new RedisConfigSource()); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreRedisConfigDemo/RedisConfigProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Extensions.Configuration; 3 | using System.Collections.Generic; 4 | namespace NetCoreRedisConfigDemo 5 | { 6 | public class RedisConfigProvider:ConfigurationProvider 7 | { 8 | public RedisConfigProvider() 9 | { 10 | } 11 | public override void Load() 12 | { 13 | Dictionary dic = new Dictionary() 14 | { 15 | {"HostName","localhost"}, 16 | {"Port","6379"}, 17 | {"Password","123456"} 18 | }; 19 | 20 | Data = dic; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/NetCoreRedisConfigDemo/RedisConfigSource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Extensions.Configuration; 3 | 4 | namespace NetCoreRedisConfigDemo 5 | { 6 | public class RedisConfigSource : IConfigurationSource 7 | { 8 | public IConfigurationProvider Build(IConfigurationBuilder builder) 9 | { 10 | return new RedisConfigProvider(); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/docker-compose.dcproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 2.1 5 | Linux 6 | {28ED9C86-976B-4DA6-B01F-A9CDF697DF81} 7 | 8 | 9 | 10 | docker-compose.yml 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/docker-compose.override.yml: -------------------------------------------------------------------------------- 1 | version: '3.4' 2 | -------------------------------------------------------------------------------- /NetCoreConfigDemo/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.4' 2 | 3 | services: 4 | netcoreenvironmentdemo: 5 | image: netcoreenvironmentdemo 6 | build: 7 | context: . 8 | dockerfile: NetCoreEnvironmentDemo/Dockerfile 9 | -------------------------------------------------------------------------------- /Office2PDF/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // 使用 IntelliSense 了解相关属性。 3 | // 悬停以查看现有属性的描述。 4 | // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": ".NET Core Launch (console)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | "program": "${workspaceFolder}/Office2PDF/bin/Debug/netcoreapp2.1/Office2PDF.dll", 13 | "args": [], 14 | "cwd": "${workspaceFolder}/Office2PDF", 15 | "console": "internalConsole", 16 | "stopAtEntry": false, 17 | "internalConsoleOptions": "openOnSessionStart" 18 | }, 19 | { 20 | "name": ".NET Core Attach", 21 | "type": "coreclr", 22 | "request": "attach", 23 | "processId": "${command:pickProcess}" 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /Office2PDF/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/Office2PDF/Office2PDF.csproj" 11 | ], 12 | "problemMatcher": "$msCompile" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /Office2PDF/Office2PDF.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Office2PDF/Office2PDF.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2026 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Office2PDF", "Office2PDF\Office2PDF.csproj", "{B2369F84-4181-4FB4-BCDC-E3B3A4991B7E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {B2369F84-4181-4FB4-BCDC-E3B3A4991B7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {B2369F84-4181-4FB4-BCDC-E3B3A4991B7E}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {B2369F84-4181-4FB4-BCDC-E3B3A4991B7E}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {B2369F84-4181-4FB4-BCDC-E3B3A4991B7E}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {38F817D1-5695-4B75-B406-1059C6971142} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Office2PDF/Office2PDF/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Office2PDF/Office2PDF/Common/APIHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http; 3 | 4 | namespace Office2PDF.Common 5 | { 6 | public class APIHelper 7 | { 8 | public static string RunApiPost(string apiRootUrl,string requestUri, HttpContent context) 9 | { 10 | using (var client = new HttpClient()) 11 | { 12 | client.BaseAddress = new Uri(apiRootUrl); 13 | 14 | var result = client.PostAsync(requestUri, context).Result.Content.ReadAsStringAsync().Result; 15 | return result; 16 | } 17 | } 18 | 19 | public static string RunApiGet(string apiRootUrl,string requestUrl) 20 | { 21 | using (var client = new HttpClient()) 22 | { 23 | client.BaseAddress = new Uri(apiRootUrl); 24 | var result = client.GetStringAsync(requestUrl).Result; 25 | return result; 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Office2PDF/Office2PDF/Common/GridFSOperationManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using MongoDB.Driver.GridFS; 4 | using System.Collections.Generic; 5 | using MongoDB.Bson; 6 | using MongoDB.Driver; 7 | using System.Linq; 8 | using System.Configuration; 9 | 10 | namespace Office2PDF.Common 11 | { 12 | public class GridFSOperationManager : IFileOperationManager 13 | { 14 | private IMongoDatabase _db; 15 | private string _dbName; 16 | private string _hostName; 17 | private int _port; 18 | private int _chunkSize; 19 | private GridFSBucket _gridFs; 20 | 21 | public GridFSOperationManager() 22 | { 23 | Init(); 24 | } 25 | 26 | private void Init() 27 | { 28 | _hostName = ConfigurationManager.AppSettings["MongoHostName"]; 29 | _dbName = ConfigurationManager.AppSettings["MongoDBName"]; 30 | 31 | int.TryParse((ConfigurationManager.AppSettings["MongoPort"] + string.Empty), out _port); 32 | int.TryParse((ConfigurationManager.AppSettings["MongoChunkSize"] + string.Empty), out _chunkSize);//261120 33 | 34 | List mongoServerAddress = new List(); 35 | if (!string.IsNullOrEmpty(_hostName)) 36 | { 37 | foreach (string address in _hostName.Split(',')) 38 | { 39 | mongoServerAddress.Add(new MongoServerAddress(address, _port)); 40 | } 41 | 42 | MongoClientSettings mcs = new MongoClientSettings(); 43 | mcs.Servers = mongoServerAddress; 44 | MongoClient mc = new MongoClient(mcs); 45 | 46 | _db = mc.GetDatabase(_dbName); 47 | _gridFs = new GridFSBucket(_db); 48 | } 49 | else 50 | { 51 | Console.WriteLine("Can't find MongoHostName!!!"); 52 | } 53 | } 54 | 55 | 56 | private FileInfo AddFile(Stream fileStream, string fileName) 57 | { 58 | var briefInfo = new FileInfo(); 59 | GridFSUploadOptions options = new GridFSUploadOptions(); 60 | options.ChunkSizeBytes = _chunkSize; 61 | ObjectId id = _gridFs.UploadFromStream(fileName, fileStream, options); 62 | briefInfo = GetFileInfo(id.ToString()); 63 | 64 | return briefInfo; 65 | } 66 | 67 | private static byte[] StreamToBytes(Stream stream) 68 | { 69 | if (stream == null) 70 | { 71 | return null; 72 | } 73 | byte[] bytes = new byte[stream.Length]; 74 | stream.Read(bytes, 0, bytes.Length); 75 | // 设置当前流的位置为流的开始 76 | stream.Seek(0, SeekOrigin.Begin); 77 | return bytes; 78 | } 79 | 80 | public Stream BytesToStream(byte[] bytes) 81 | { 82 | Stream stream = new MemoryStream(bytes); 83 | return stream; 84 | } 85 | 86 | public string GetMD5Hash(Stream stream) 87 | { 88 | string result = ""; 89 | string hashData = ""; 90 | byte[] arrbytHashValue; 91 | System.Security.Cryptography.MD5CryptoServiceProvider md5Hasher = 92 | new System.Security.Cryptography.MD5CryptoServiceProvider(); 93 | 94 | try 95 | { 96 | arrbytHashValue = md5Hasher.ComputeHash(stream);//计算指定Stream 对象的哈希值 97 | //由以连字符分隔的十六进制对构成的String,其中每一对表示value 中对应的元素;例如“F-2C-4A” 98 | hashData = System.BitConverter.ToString(arrbytHashValue); 99 | //替换- 100 | hashData = hashData.Replace("-", ""); 101 | result = hashData; 102 | } 103 | catch (System.Exception ex) 104 | { 105 | //记录日志 106 | Console.WriteLine(ex.Message); 107 | } 108 | 109 | return result; 110 | } 111 | 112 | public FileInfo AddFile(Stream fileStream, string fileName, bool isCheckExist=true) 113 | { 114 | if (!isCheckExist) 115 | { 116 | return AddFile(fileStream, fileName); 117 | } 118 | 119 | var result = new FileInfo(); 120 | byte[] bytes = StreamToBytes(fileStream); 121 | //如果md5相同 着不需要再上传 122 | string md5 = GetMD5Hash(fileStream); 123 | string id = IsExist(md5.ToLower()); 124 | if (string.IsNullOrEmpty(id)) 125 | { 126 | var oldStream = BytesToStream(bytes); 127 | result = AddFile(oldStream, fileName); 128 | } 129 | else 130 | { 131 | result = GetFileInfo(id); 132 | } 133 | return result; 134 | } 135 | 136 | public bool DeleteFile(string fileId) 137 | { 138 | _gridFs.Delete(ObjectId.Parse(fileId)); 139 | return true; 140 | } 141 | 142 | public string IsExist(string tag) 143 | { 144 | string id = ""; 145 | GridFSFindOptions options = new GridFSFindOptions(); 146 | options.Limit = 1; 147 | var filter = MongoDB.Driver.Builders.Filter.Eq("md5", tag); 148 | var filterDefintion = FilterDefinition.Empty; 149 | 150 | var objFile = _gridFs.Find(filter, options); 151 | if (objFile == null) 152 | return id; 153 | var files = objFile.ToList(); 154 | 155 | if (files.Count > 0) 156 | { 157 | id = files.FirstOrDefault().Id.ToString(); 158 | } 159 | return id; 160 | } 161 | 162 | public Stream GetFile(string fileId) 163 | { 164 | //ObjectId id = ObjectId.Parse(fileId); 165 | //byte[] fileByte = _gridFs.DownloadAsBytes(id); 166 | //return BytesToStream(fileByte); 167 | return GetStream(fileId); 168 | } 169 | public Stream GetStream(string fileId) 170 | { 171 | try 172 | { 173 | ObjectId id = ObjectId.Parse(fileId); 174 | return _gridFs.OpenDownloadStream(id, new GridFSDownloadOptions() 175 | { 176 | Seekable = true 177 | }); 178 | } 179 | catch (Exception ex) 180 | { 181 | return null; 182 | } 183 | 184 | } 185 | public string GetFileName(string fileId) 186 | { 187 | ObjectId id = ObjectId.Parse(fileId); 188 | var fileInfo = GetGridFSFileInfo(id); 189 | if (fileInfo != null) 190 | { 191 | return fileInfo.Filename; 192 | } 193 | return string.Empty; 194 | } 195 | 196 | private GridFSFileInfo GetGridFSFileInfo(ObjectId id) 197 | { 198 | var filter = MongoDB.Driver.Builders.Filter.Eq("_id", id); 199 | var fileInfo = _gridFs.Find(filter).ToList(); 200 | return fileInfo.FirstOrDefault(); 201 | } 202 | 203 | public string GetMD5(string fileId) 204 | { 205 | ObjectId id = ObjectId.Parse(fileId); 206 | var fileInfo = GetGridFSFileInfo(id); 207 | if (fileInfo != null) 208 | { 209 | return fileInfo.MD5; 210 | } 211 | return string.Empty; 212 | } 213 | 214 | 215 | public FileInfo GetFileInfo(string fileId) 216 | { 217 | var result = new FileInfo(); 218 | var fileInfo = GetGridFSFileInfo(ObjectId.Parse(fileId)); 219 | if (fileInfo != null) 220 | { 221 | result.Md5 = fileInfo.MD5; 222 | result.FileId = fileInfo.Id.ToString(); 223 | result.Length = fileInfo.Length; 224 | result.UploadDateTime = fileInfo.UploadDateTime; 225 | result.FileName = fileInfo.Filename; 226 | } 227 | return result; 228 | } 229 | 230 | public FileByteInfo DownloadFile(string fileId) 231 | { 232 | FileByteInfo retFile = new FileByteInfo(); 233 | retFile.Bytes= StreamToBytes(this.GetFile(fileId)); 234 | 235 | if (retFile == null || retFile.Bytes == null) 236 | throw new GridFSFileNotFoundException(fileId); 237 | 238 | retFile.FileName = GetFileName(fileId); 239 | retFile.ContentType = Path.GetExtension(retFile.FileName).ToLower(); 240 | return retFile; 241 | } 242 | } 243 | } 244 | -------------------------------------------------------------------------------- /Office2PDF/Office2PDF/Common/Interface/IFileOperationManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | namespace Office2PDF.Common 5 | { 6 | public interface IFileOperationManager 7 | { 8 | FileInfo AddFile(Stream fileStream, string fileName, bool isCheckExist=true); 9 | FileByteInfo DownloadFile(string fileId); 10 | bool DeleteFile(string fileId); 11 | string IsExist(string tag); 12 | Stream GetFile(string fileId); 13 | Stream GetStream(string fileId); 14 | string GetFileName(string fileId); 15 | 16 | string GetMD5(string fileId); 17 | 18 | FileInfo GetFileInfo(string fileId); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Office2PDF/Office2PDF/Common/Interface/IPowerPointConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Office2PDF.Common 6 | { 7 | interface IPowerPointConverter 8 | { 9 | bool OnWork(MQ.Messages message = null); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Office2PDF/Office2PDF/Common/Model/FileByteInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Office2PDF.Common 3 | { 4 | public class FileByteInfo 5 | { 6 | public string FileName { get; set; } 7 | public string ContentType { get; set; } 8 | 9 | public Byte[] Bytes { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /Office2PDF/Office2PDF/Common/Model/FileInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Office2PDF.Common 6 | { 7 | [Serializable()] 8 | public class FileInfo 9 | { 10 | public virtual string FileName { get; set; } 11 | public virtual string FileId { get; set; } 12 | public virtual string Md5 { get; set; } 13 | 14 | public virtual long Length { get; set; } 15 | 16 | public virtual DateTime UploadDateTime { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Office2PDF/Office2PDF/Common/PowerPointConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Office2PDF.MQ; 5 | using Office2PDF.Messages; 6 | using System.Diagnostics; 7 | using System.IO; 8 | using System.Configuration; 9 | 10 | namespace Office2PDF.Common 11 | { 12 | public class PowerPointConverter : IPowerPointConverter 13 | { 14 | IFileOperationManager fileOperation; 15 | 16 | public PowerPointConverter() 17 | { 18 | fileOperation = new GridFSOperationManager(); 19 | } 20 | 21 | private bool SaveToFile(Stream stream,string path) 22 | { 23 | try 24 | { 25 | byte[] sourceBuffer = new Byte[stream.Length]; 26 | stream.Read(sourceBuffer, 0, sourceBuffer.Length); 27 | stream.Seek(0, SeekOrigin.Begin); 28 | 29 | using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write)) 30 | { 31 | fs.Write(sourceBuffer, 0, sourceBuffer.Length); 32 | fs.Close(); 33 | } 34 | } 35 | catch (Exception ex) 36 | { 37 | Console.WriteLine("读取PPT源文件到本地失败:" + ex.Message); 38 | return false; 39 | } 40 | return true; 41 | } 42 | 43 | private FileInfo UploadFile(string path,string destName) 44 | { 45 | if (!File.Exists(path)) 46 | return null; 47 | 48 | byte[] bytes = null; 49 | using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) 50 | { 51 | bytes = new byte[fileStream.Length]; 52 | fileStream.Read(bytes, 0, bytes.Length); 53 | } 54 | 55 | if (bytes == null) 56 | return null; 57 | Stream stream = new MemoryStream(bytes); 58 | return fileOperation.AddFile(stream, destName, true); 59 | } 60 | public bool OnWork(MQ.Messages Message) 61 | { 62 | PowerPointConvertMessage message = (PowerPointConvertMessage)Message; 63 | string sourcePath = string.Empty; 64 | string destPath = string.Empty; 65 | try 66 | { 67 | if(message == null) 68 | return false; 69 | Stream sourceStream = fileOperation.GetFile(message.FileInfo.FileId); 70 | string filename = message.FileInfo.FileId; 71 | string extension = System.IO.Path.GetExtension(message.FileInfo.FileName); 72 | sourcePath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), filename + extension); 73 | destPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), string.Format("{0}.pdf", filename)); 74 | 75 | if (!SaveToFile(sourceStream, sourcePath)) 76 | return false; 77 | var psi = new ProcessStartInfo("libreoffice", string.Format("--invisible --convert-to pdf {0}", filename + extension)) { RedirectStandardOutput = true }; 78 | // 启动 79 | var proc = Process.Start(psi); 80 | if (proc == null) 81 | { 82 | Console.WriteLine("不能执行."); 83 | return false; 84 | } 85 | else 86 | { 87 | Console.WriteLine("-------------开始执行--------------"); 88 | //开始读取 89 | using (var sr = proc.StandardOutput) 90 | { 91 | while (!sr.EndOfStream) 92 | { 93 | Console.WriteLine(sr.ReadLine()); 94 | } 95 | if (!proc.HasExited) 96 | { 97 | proc.Kill(); 98 | } 99 | } 100 | Console.WriteLine("---------------执行完成------------------"); 101 | Console.WriteLine($"退出代码 : {proc.ExitCode}"); 102 | } 103 | } 104 | catch (Exception ex) 105 | { 106 | Console.WriteLine(ex.Message); 107 | return false; 108 | } 109 | finally 110 | { 111 | if (File.Exists(destPath)) 112 | { 113 | var destFileInfo = UploadFile(destPath, string.Format("{0}.pdf", Path.GetFileNameWithoutExtension(message.FileInfo.FileName))); 114 | } 115 | if (File.Exists(destPath)) 116 | { 117 | System.IO.File.Delete(destPath); 118 | } 119 | } 120 | return true; 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /Office2PDF/Office2PDF/Extension/AttributeExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace Office2PDF.Extension 5 | { 6 | public static class AttributeExtension 7 | { 8 | public static T GetAttribute(this object obj) where T : class 9 | { 10 | return obj.GetType().GetAttribute(); 11 | } 12 | public static T GetAttribute(this Type type) where T : class 13 | { 14 | Attribute customAttribute = type.GetCustomAttribute(typeof(T)); 15 | if (customAttribute.IsNotNull()) 16 | { 17 | return (customAttribute as T); 18 | } 19 | return default(T); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Office2PDF/Office2PDF/Extension/Convertor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Runtime.Serialization.Formatters.Binary; 4 | 5 | namespace Office2PDF.Extension 6 | { 7 | public class Convertor 8 | { 9 | /// 10 | /// 二进制反序列化:byte=>实体object 11 | /// 12 | /// 13 | /// 14 | /// 15 | public static object ByteArrayToObject(byte[] SerializedObj, bool ThrowException) 16 | { 17 | if (SerializedObj == null) 18 | { 19 | return null; 20 | } 21 | try 22 | { 23 | BinaryFormatter formatter = new BinaryFormatter(); 24 | MemoryStream serializationStream = new MemoryStream(SerializedObj); 25 | return formatter.Deserialize(serializationStream); 26 | } 27 | catch (Exception exception) 28 | { 29 | if (ThrowException) 30 | { 31 | throw exception; 32 | } 33 | return null; 34 | } 35 | } 36 | 37 | /// 38 | /// 二进制序列化:实体=》byte 39 | /// 40 | /// 41 | /// 42 | /// 43 | public static byte[] ObjectToByteArray(object Obj, bool ThrowException) 44 | { 45 | if (Obj == null) 46 | { 47 | return null; 48 | } 49 | try 50 | { 51 | BinaryFormatter formatter = new BinaryFormatter(); 52 | MemoryStream serializationStream = new MemoryStream(); 53 | formatter.Serialize(serializationStream, Obj); 54 | return serializationStream.ToArray(); 55 | } 56 | catch (Exception exception) 57 | { 58 | if (ThrowException) 59 | { 60 | throw exception; 61 | } 62 | return null; 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Office2PDF/Office2PDF/Extension/ObjectExtension.cs: -------------------------------------------------------------------------------- 1 | namespace Office2PDF.Extension 2 | { 3 | public static class ObjectExtension 4 | { 5 | public static bool IsNotNull(this object obj) 6 | { 7 | return (obj != null); 8 | } 9 | public static bool IsNull(this object obj) 10 | { 11 | return (obj == null); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Office2PDF/Office2PDF/MQ/MessageModel/FileMessage.cs: -------------------------------------------------------------------------------- 1 | using Office2PDF.Common; 2 | using Office2PDF.MQ; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Office2PDF.Messages 8 | { 9 | [Serializable] 10 | [MQ.RabbitMq("PptConvertMessageQueue", ExchangeName = "PptConvertMessageExchange", IsProperties = false)] 11 | public class PowerPointConvertMessage : MQ.Messages 12 | { 13 | private MessageType _MessageType; 14 | 15 | private FileInfo _FileInfo; 16 | 17 | public PowerPointConvertMessage() : base(2) 18 | { 19 | } 20 | 21 | public PowerPointConvertMessage(MessageEmergencyType MessageEmergency, MessageType MessageType, FileInfo fileInfo) : base((int)MessageEmergency) 22 | { 23 | this._MessageType = MessageType; 24 | this._FileInfo = fileInfo; 25 | } 26 | 27 | public override string ToString() 28 | { 29 | return base.ToString(); 30 | } 31 | 32 | public new MessageEmergencyType MessageEmergency 33 | { 34 | get 35 | { 36 | return (MessageEmergencyType)base.MessageEmergency; 37 | } 38 | } 39 | 40 | public FileInfo FileInfo 41 | { 42 | get 43 | { 44 | return this._FileInfo; 45 | } 46 | } 47 | 48 | public override string MessageCatalogID 49 | { 50 | get 51 | { 52 | return this._FileInfo.FileId; 53 | } 54 | } 55 | 56 | public MessageType MessageType 57 | { 58 | get 59 | { 60 | return this._MessageType; 61 | } 62 | } 63 | 64 | public bool IsTempStorage { get; set; } = false; 65 | } 66 | 67 | [Serializable()] 68 | public enum MessageType 69 | { 70 | ActivateInstance = 3, 71 | ForwardInstance = 2, 72 | OriginateInstance = 0, 73 | ConvertFile = -1 74 | } 75 | 76 | public enum MessageEmergencyType 77 | { 78 | Lowest, 79 | Low, 80 | Normal, 81 | High, 82 | Highest 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /Office2PDF/Office2PDF/MQ/MessageModel/Messages.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Office2PDF.MQ 6 | { 7 | [System.Serializable] 8 | public abstract class Messages 9 | { 10 | public Messages(int MessageEmergency) 11 | { 12 | this.MessageEmergency = MessageEmergency; 13 | } 14 | 15 | public abstract string MessageCatalogID { get; } 16 | 17 | public int MessageEmergency { get; set; } 18 | 19 | public string MessageID { get; set; } 20 | 21 | public bool Serialized { get; set; } 22 | 23 | public string[] ParticipativeIds { get; set; } 24 | 25 | public string Queues { get; set; } 26 | 27 | public string Exchange { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Office2PDF/Office2PDF/MQ/RabbitMQProxyConfig/RabbitMqConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Office2PDF.MQ 4 | { 5 | /// 6 | /// 7 | /// 8 | public class MqConfig 9 | { 10 | public string Host { get; set; } 11 | public ushort HeartBeat { get; set; } 12 | public bool AutomaticRecoveryEnabled { get; set; } 13 | public TimeSpan NetworkRecoveryInterval { get; set; } 14 | public string UserName { get; set; } 15 | public string Password { get; set; } 16 | 17 | public string Port { get; set; } 18 | 19 | } 20 | 21 | /// 22 | /// 死信队列实体 23 | /// 24 | [RabbitMq("dead-letter-{Queue}", ExchangeName = "dead-letter-{exchange}")] 25 | public class DeadLetterQueue 26 | { 27 | public string Body { get; set; } 28 | 29 | public string Exchange { get; set; } 30 | 31 | public string Queue { get; set; } 32 | 33 | public string RoutingKey { get; set; } 34 | 35 | public int RetryCount { get; set; } 36 | 37 | public string ExceptionMsg { get; set; } 38 | 39 | public DateTime CreateDateTime { get; set; } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Office2PDF/Office2PDF/MQ/RabbitMQProxyConfig/RabbitMqQueueAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Office2PDF.MQ 6 | { 7 | public class RabbitMqAttribute : Attribute 8 | { 9 | public RabbitMqAttribute(string queueName) 10 | { 11 | QueueName = queueName ?? string.Empty; 12 | } 13 | 14 | /// 15 | /// 交换机名称 16 | /// 17 | public string ExchangeName { get; set; } 18 | 19 | /// 20 | /// 队列名称 21 | /// 22 | public string QueueName { get; private set; } 23 | 24 | /// 25 | /// 是否持久化 26 | /// 27 | public bool IsProperties { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Office2PDF/Office2PDF/Office2PDF.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | Office2PDF.Program 7 | Office2PDF 8 | Office2PDF.Office2PDF 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | System.Web 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Office2PDF/Office2PDF/Program.cs: -------------------------------------------------------------------------------- 1 | using Office2PDF.Messages; 2 | using Office2PDF.MQ; 3 | using System; 4 | using System.Threading; 5 | using System.Configuration; 6 | using Office2PDF.Common; 7 | 8 | namespace Office2PDF 9 | { 10 | class Program 11 | { 12 | static IPowerPointConverter converter = new PowerPointConverter(); 13 | static void Main(string[] args) 14 | { 15 | var mqManager = new MQManager(new MqConfig 16 | { 17 | AutomaticRecoveryEnabled = true, 18 | HeartBeat = 60, 19 | NetworkRecoveryInterval = new TimeSpan(60), 20 | 21 | Host = ConfigurationManager.AppSettings["mqhostname"], 22 | UserName = ConfigurationManager.AppSettings["mqusername"], 23 | Password = ConfigurationManager.AppSettings["mqpassword"], 24 | Port = ConfigurationManager.AppSettings["mqport"] 25 | }); 26 | 27 | if (mqManager != null && mqManager.Connected) 28 | { 29 | Console.WriteLine("RabbitMQ连接初始化成功。"); 30 | Console.WriteLine("RabbitMQ消息接收中..."); 31 | 32 | mqManager.Subscribe(message => 33 | { 34 | if (message != null) 35 | { 36 | converter.OnWork(message); 37 | Console.WriteLine(message.FileInfo); 38 | } 39 | }); 40 | } 41 | else 42 | { 43 | Console.WriteLine("RabbitMQ连接初始化失败,请检查连接。"); 44 | Console.ReadLine(); 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Office2PDF/Office2PDF/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "Office2PDF.Office2PDF": { 4 | "commandName": "Project", 5 | "environmentVariables": { 6 | "mqport": "5673", 7 | "mqhostname": "192.168.16.160", 8 | "mqpassword": "000000", 9 | "mqusername": "Ican" 10 | } 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /RabbitMQDLXDemo/Consumer/Consumer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /RabbitMQDLXDemo/Consumer/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using RabbitMQ.Client; 6 | using RabbitMQ.Client.Events; 7 | 8 | namespace Consumer 9 | { 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | var factory = new ConnectionFactory() { HostName = "127.0.0.1", UserName = "oec2003", Password = "123456" }; 15 | using (var connection = factory.CreateConnection()) 16 | using (var channel = connection.CreateModel()) 17 | { 18 | channel.QueueDeclare("queue-2", false, false, false, null); 19 | var consumer = new EventingBasicConsumer(channel); 20 | consumer.Received += (model, ea) => 21 | { 22 | var body = ea.Body; 23 | var message = Encoding.UTF8.GetString(body); 24 | Console.WriteLine("已接收: {0}", message); 25 | }; 26 | channel.BasicConsume("queue-2", false, consumer); 27 | } 28 | Console.ReadLine(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /RabbitMQDLXDemo/Producter/Producer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /RabbitMQDLXDemo/Producter/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using RabbitMQ.Client; 5 | 6 | namespace Producer 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | var factory = new ConnectionFactory() { HostName = "127.0.0.1", UserName = "oec2003", Password = "123456" }; 13 | using (var connection = factory.CreateConnection()) 14 | while (Console.ReadLine() != null) 15 | { 16 | using (var channel = connection.CreateModel()) 17 | { 18 | var arguments = new Dictionary(); 19 | arguments.Add("x-dead-letter-exchange", "exchange-2"); 20 | arguments.Add("x-dead-letter-routing-key", "rk-2"); 21 | 22 | channel.QueueDeclare("queue-1",true,false,false,arguments); 23 | 24 | channel.ExchangeDeclare("exchange-2", "direct"); 25 | channel.QueueDeclare("queue-2", false, false, false, null); 26 | channel.QueueBind("queue-2", "exchange-2", "rk-2", null); 27 | 28 | var message = "Hello oec2003!"; 29 | var body = Encoding.UTF8.GetBytes(message); 30 | 31 | var properties = channel.CreateBasicProperties(); 32 | properties.Persistent = true; 33 | properties.Expiration = "5000"; 34 | 35 | channel.BasicPublish("", "queue-1", properties, body); 36 | Console.WriteLine($"发送: {message}"); 37 | } 38 | } 39 | Console.ReadKey(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /RedisLockDemo/RedisLockConsoleApp1/Program.cs: -------------------------------------------------------------------------------- 1 | using RedisLockLib; 2 | using System; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | namespace RedisLockConsoleApp1 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | SeqNo.InitRedis(); 13 | Task.Run(() => 14 | { 15 | for (int i = 0; i < 50; i++) 16 | { 17 | Console.WriteLine($"Thread1:SeqNo:{SeqNo.GetSeqNoByRedisLock()}"); 18 | } 19 | }); 20 | 21 | Task.Run(() => 22 | { 23 | for (int i = 0; i < 50; i++) 24 | { 25 | Console.WriteLine($"Thread2:SeqNo:{SeqNo.GetSeqNoByRedisLock()}"); 26 | } 27 | }); 28 | Console.ReadLine(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /RedisLockDemo/RedisLockConsoleApp1/RedisLockConsoleApp1.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /RedisLockDemo/RedisLockConsoleApp2/Program.cs: -------------------------------------------------------------------------------- 1 | using RedisLockLib; 2 | using System; 3 | using System.Threading.Tasks; 4 | 5 | namespace RedisLockConsoleApp2 6 | { 7 | class Program 8 | { 9 | static void Main(string[] args) 10 | { 11 | SeqNo.InitRedis(); 12 | Task.Run(() => 13 | { 14 | for (int i = 0; i < 50; i++) 15 | { 16 | Console.WriteLine($"Thread1:SeqNo:{SeqNo.GetSeqNoByRedisLock()}"); 17 | } 18 | }); 19 | 20 | Task.Run(() => 21 | { 22 | for (int i = 0; i < 50; i++) 23 | { 24 | Console.WriteLine($"Thread2:SeqNo:{SeqNo.GetSeqNoByRedisLock()}"); 25 | } 26 | }); 27 | 28 | Console.ReadLine(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /RedisLockDemo/RedisLockConsoleApp2/RedisLockConsoleApp2.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /RedisLockDemo/RedisLockDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29123.88 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RedisLockLib", "RedisLockLib\RedisLockLib.csproj", "{281D0907-703C-4E26-9009-FD2A505AE7C5}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RedisLockConsoleApp1", "RedisLockConsoleApp1\RedisLockConsoleApp1.csproj", "{B2B2446C-5E4A-4A34-809B-EF1B625D2D33}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RedisLockConsoleApp2", "RedisLockConsoleApp2\RedisLockConsoleApp2.csproj", "{730B7172-4D69-47E2-9F1E-E21875617CED}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {281D0907-703C-4E26-9009-FD2A505AE7C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {281D0907-703C-4E26-9009-FD2A505AE7C5}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {281D0907-703C-4E26-9009-FD2A505AE7C5}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {281D0907-703C-4E26-9009-FD2A505AE7C5}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {B2B2446C-5E4A-4A34-809B-EF1B625D2D33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {B2B2446C-5E4A-4A34-809B-EF1B625D2D33}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {B2B2446C-5E4A-4A34-809B-EF1B625D2D33}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {B2B2446C-5E4A-4A34-809B-EF1B625D2D33}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {730B7172-4D69-47E2-9F1E-E21875617CED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {730B7172-4D69-47E2-9F1E-E21875617CED}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {730B7172-4D69-47E2-9F1E-E21875617CED}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {730B7172-4D69-47E2-9F1E-E21875617CED}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {E3E37E9D-B0EB-4D5C-A6C6-DDCC0CC2AB31} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /RedisLockDemo/RedisLockLib/RedisLockLib.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /RedisLockDemo/RedisLockLib/SeqNo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | 4 | namespace RedisLockLib 5 | { 6 | public class SeqNo 7 | { 8 | private readonly static object _myLock = new object(); 9 | private static CSRedis.CSRedisClient _redisClient=null; 10 | 11 | public static string GetSeqNoNoLock() 12 | { 13 | string connectionStr = "server = localhost; user id = oec2003; password = 123456; database = seqno_test"; 14 | string getSeqNosql = "select num from seqno where code='order'"; 15 | string updateSeqNoSql = "update seqno set num=num+1 where code='order'"; 16 | 17 | var seqNo = MySQLHelper.ExecuteScalar(connectionStr, System.Data.CommandType.Text, getSeqNosql); 18 | MySQLHelper.ExecuteNonQuery(connectionStr, System.Data.CommandType.Text, updateSeqNoSql); 19 | 20 | return seqNo.ToString(); 21 | } 22 | 23 | public static string GetSeqNoByLock() 24 | { 25 | string connectionStr = "server = localhost; user id = oec2003; password = 123456; database = seqno_test"; 26 | string getSeqNosql = "select num from seqno where code='order'"; 27 | string updateSeqNoSql = "update seqno set num=num+1 where code='order'"; 28 | var seqNo = string.Empty; 29 | try 30 | { 31 | Monitor.Enter(_myLock); 32 | seqNo = MySQLHelper.ExecuteScalar(connectionStr, System.Data.CommandType.Text, getSeqNosql).ToString(); 33 | 34 | MySQLHelper.ExecuteNonQuery(connectionStr, System.Data.CommandType.Text, updateSeqNoSql); 35 | 36 | Monitor.Exit(_myLock); 37 | } 38 | catch 39 | { 40 | Monitor.Exit(_myLock); 41 | } 42 | 43 | return seqNo.ToString(); 44 | } 45 | 46 | public static string GetSeqNoByRedisLock() 47 | { 48 | string connectionStr = "server = localhost; user id = oec2003; password = 123456; database = seqno_test"; 49 | string getSeqNosql = "select num from seqno where code='order'"; 50 | string updateSeqNoSql = "update seqno set num=num+1 where code='order'"; 51 | 52 | var seqNo=string.Empty; 53 | using (_redisClient.Lock("test", 5000)) 54 | { 55 | seqNo = MySQLHelper.ExecuteScalar(connectionStr, System.Data.CommandType.Text, getSeqNosql).ToString(); 56 | 57 | MySQLHelper.ExecuteNonQuery(connectionStr, System.Data.CommandType.Text, updateSeqNoSql); 58 | } 59 | return seqNo; 60 | } 61 | 62 | public static void InitRedis() 63 | { 64 | _redisClient = new CSRedis.CSRedisClient("localhost:6379,password=,defaultDatabase=8,poolsize=50,ssl=false,writeBuffer=10240,prefix=oec2003"); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /UpdateOcelotConfig/Client/Client.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /UpdateOcelotConfig/Client/Program.cs: -------------------------------------------------------------------------------- 1 | using IdentityModel.Client; 2 | using Newtonsoft.Json; 3 | using Ocelot.Configuration.File; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Net.Http; 7 | using System.Net.Http.Headers; 8 | using System.Threading.Tasks; 9 | 10 | namespace Client 11 | { 12 | class Program 13 | { 14 | static void Main(string[] args) => MainAsync().GetAwaiter().GetResult(); 15 | private static async Task MainAsync() 16 | { 17 | //需要修改的配置 18 | var configuration = new FileConfiguration 19 | { 20 | ReRoutes = new List 21 | { 22 | new FileReRoute 23 | { 24 | DownstreamPathTemplate = "/api/values", 25 | DownstreamHostAndPorts = new List 26 | { 27 | new FileHostAndPort 28 | { 29 | Host ="localhost", 30 | Port = 10001, 31 | }, 32 | new FileHostAndPort 33 | { 34 | Host ="localhost", 35 | Port = 10002, 36 | } 37 | }, 38 | DownstreamScheme = "http", 39 | UpstreamPathTemplate = "/c/api/values", 40 | UpstreamHttpMethod = new List { "Get","Post" } 41 | } 42 | }, 43 | GlobalConfiguration = new FileGlobalConfiguration 44 | { 45 | BaseUrl = "http://localhost:10000/" 46 | } 47 | }; 48 | 49 | // 从元数据中发现客户端 50 | var disco = await DiscoveryClient.GetAsync("http://localhost:9500"); 51 | 52 | // 请求令牌 53 | var tokenClient = new TokenClient(disco.TokenEndpoint, "client", "secret"); 54 | var tokenResponse = await tokenClient.RequestClientCredentialsAsync("s2api"); 55 | 56 | if (tokenResponse.IsError) 57 | { 58 | Console.WriteLine(tokenResponse.Error); 59 | return; 60 | } 61 | 62 | var client = new HttpClient(); 63 | client.SetBearerToken(tokenResponse.AccessToken); 64 | 65 | HttpContent content = new StringContent(JsonConvert.SerializeObject(configuration)); 66 | content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); 67 | 68 | var response = await client.PostAsync("http://localhost:10000/admin/configuration", content); 69 | 70 | Console.WriteLine("update ocelot config sucess"); 71 | Console.ReadLine(); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /UpdateOcelotConfig/IdentityService/AnonymousGrantValidator.cs: -------------------------------------------------------------------------------- 1 | using IdentityServer4.Validation; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Security.Claims; 6 | using System.Threading.Tasks; 7 | 8 | namespace IdentityService 9 | { 10 | public class AnonymousGrantValidator : IExtensionGrantValidator 11 | { 12 | private readonly ITokenValidator _validator; 13 | 14 | public AnonymousGrantValidator(ITokenValidator validator) 15 | { 16 | _validator = validator; 17 | } 18 | 19 | public string GrantType => "anonymous"; 20 | 21 | public async Task ValidateAsync(ExtensionGrantValidationContext context) 22 | { 23 | //var userToken = context.Request.Raw.Get("token"); 24 | 25 | //if (string.IsNullOrEmpty(userToken)) 26 | //{ 27 | // context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant); 28 | // return; 29 | //} 30 | 31 | //var result = await _validator.ValidateAccessTokenAsync(userToken); 32 | //if (result.IsError) 33 | //{ 34 | // context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant); 35 | // return; 36 | //} 37 | 38 | // get user's identity 39 | //var sub = result.Claims.FirstOrDefault(c => c.Type == "sub").Value; 40 | 41 | var claims = new List() { new Claim("role", GrantType) }; // Claim 用于配置服务站点 [Authorize("anonymous")] 42 | context.Result = new GrantValidationResult(GrantType, GrantType, claims); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /UpdateOcelotConfig/IdentityService/Config.cs: -------------------------------------------------------------------------------- 1 | using IdentityServer4.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace IdentityService 8 | { 9 | public class Config 10 | { 11 | public static IEnumerable GetApiResources() 12 | { 13 | return new List 14 | { 15 | new ApiResource("s2api", "My API") 16 | }; 17 | } 18 | public static IEnumerable GetClients() 19 | { 20 | return new List 21 | { 22 | new Client 23 | { 24 | ClientId = "client", 25 | // 没有交互性用户,使用 clientid/secret 实现认证。 26 | AllowedGrantTypes =GrantTypes.ClientCredentials, 27 | // 用于认证的密码 28 | ClientSecrets = 29 | { 30 | new Secret("secret".Sha256()) 31 | }, 32 | // 客户端有权访问的范围(Scopes) 33 | AllowedScopes = { "s2api" } 34 | } 35 | }; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /UpdateOcelotConfig/IdentityService/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace IdentityService.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | public class ValuesController : Controller 11 | { 12 | // GET api/values 13 | [HttpGet] 14 | public IEnumerable Get() 15 | { 16 | return new string[] { "value1", "value2" }; 17 | } 18 | 19 | // GET api/values/5 20 | [HttpGet("{id}")] 21 | public string Get(int id) 22 | { 23 | return "value"; 24 | } 25 | 26 | // POST api/values 27 | [HttpPost] 28 | public void Post([FromBody]string value) 29 | { 30 | } 31 | 32 | // PUT api/values/5 33 | [HttpPut("{id}")] 34 | public void Put(int id, [FromBody]string value) 35 | { 36 | } 37 | 38 | // DELETE api/values/5 39 | [HttpDelete("{id}")] 40 | public void Delete(int id) 41 | { 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /UpdateOcelotConfig/IdentityService/IdentityService.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /UpdateOcelotConfig/IdentityService/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace IdentityService 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /UpdateOcelotConfig/IdentityService/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:9500/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "api/values", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "IdentityService": { 20 | "commandName": "Project", 21 | "launchUrl": "api/values", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | }, 25 | "applicationUrl": "http://localhost:9500/" 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /UpdateOcelotConfig/IdentityService/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Logging; 10 | using Microsoft.Extensions.Options; 11 | 12 | namespace IdentityService 13 | { 14 | public class Startup 15 | { 16 | public Startup(IConfiguration configuration) 17 | { 18 | Configuration = configuration; 19 | } 20 | 21 | public IConfiguration Configuration { get; } 22 | 23 | // This method gets called by the runtime. Use this method to add services to the container. 24 | public void ConfigureServices(IServiceCollection services) 25 | { 26 | services.AddIdentityServer() 27 | .AddDeveloperSigningCredential() 28 | .AddInMemoryApiResources(Config.GetApiResources()) 29 | .AddInMemoryClients(Config.GetClients()); 30 | } 31 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 32 | { 33 | if (env.IsDevelopment()) 34 | { 35 | app.UseDeveloperExceptionPage(); 36 | } 37 | 38 | app.UseIdentityServer(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /UpdateOcelotConfig/IdentityService/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /UpdateOcelotConfig/IdentityService/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /UpdateOcelotConfig/IdentityService/tempkey.rsa: -------------------------------------------------------------------------------- 1 | {"KeyId":"fa970eca50d8227fb2cc9b7b355ac532","Parameters":{"D":"XFcf68l5WZUL6lnGrX1H4SWMeC2ybuMtq+9TnkJ/iKvfocbnxa/2zJu7zPIPxc6ZqYhIrY2flOyZDQZaHyFNb1DVZOtWjhPgoE3qSU4r7FdW7OktCRpdpm3ve6SEppGTcBpXt0gTqNHK38+OTaKy0vfEOSBOqdPdeT2f/at4XMZIAyhyCbRP4b9iWOA6O92oPtFHiey4n4M9zJnGYM5/kBJyQN2z0KTqy6LnMJdO2MwPpSaQ/ggHhRuIvMTGNj4UsMcL04q+/TIfxd75Qa7gQKiTwUDjbD5X5buHSJlH4pyTYXn+bwnwX+AmRP0naKgukYqLbYTKXmHzU3U+3suJdQ==","DP":"AdtoJeHMMFsNcs42lXXnnFdaJHBc3+4025IYUT4z4gleX9wG8LL50YpcJb87zASrTM8fBnw21WIo1q9Vb1Af5D5pTFztnwn2DdgeP1rYr7D+U5/eft4v8VAh0LdIPmwDI8TGe7rR1Qa+r1+Dlcy8eIX65fsamtgLL7m9bK5mhqM=","DQ":"BVpij98uqJmwyFUJTdPotyBTPR5+zcZ5/Qd+924e7yyFD+SIHaxNC1YJG+8rz/zPL79HqGtQr0YJiVPzTMbspj+Y7g5MreuZTnA0ohBXC6VxNu9B2ElPgYot4qZPv4lQZX4xHmj4/MJP+PjrF3ZKSh+B4loWNTm4x3NXU63rG4U=","Exponent":"AQAB","InverseQ":"liuFBRyX/kRYJrGOCZBNOBgEunL16P5R5t9U+zb4lMwbagWbXBV+vLYr4VsaI3PlcFPM+da8eA1dCnTWognYvZgiqW+qYC+Zxjv5teY21sN9RhHjms738vbwwdmyeNSm7AFhA4i1aijjTZyB9Lkz4qi9o0CVOLK25Qcbcq032fc=","Modulus":"yt3N5A2I06UMDVVRu/JrGl3Yjmfgu78gmBw2dK1vFSp5K5dIUqgM8jJX98/Yhe3I/hpdXgPNhvuUiXksris0e3VTgZS934fYbEEAsDy8B2iCi+8GZU9lQxRUSR2rXBMjHz5254yM2aTO+C+PhYfpdi7vUPkBDoQieTePTKNpneghkQtaiNfMYjUtsc595KJs9um9tH2xx4rB6DFEbKHEELganKal5mbete+YIS2cnb6vIDHuEa8qtjytrBgmu4aAhN2BbFpZOlndyf6LsRP1qQlXNm8it/v3NbYYPw6hcPN6lof7zSE4ao01R+s2apjE2mgfhkhBzCLTC3nIL5xFFQ==","P":"1qYnaSy6/WZm4LGdbQgovvejzMHVsQY5sPde96gDuFNC7MRPyq9qVd2Lj7+uZHF4UI6ZVP1vVq9IK2v2W+gptEjvpOZB5241MGNfB0Qx6GChAz+3MJ5kAdb4tRhc4A8nLndPPYpplM3A1+gNPDHJfF2mleYT16hsQW8i9KIuhW8=","Q":"8fKRK71baliFH79RXcldZu/SWf6S8FYdkszMnEOB0UtAsNVGqCada4i6yVGFrXvLIfrzlpgHhOT0PEpDN9R3jlghe82i0crl4HzVrNbh+9lPg8p3RLTAl20B6W+mo1JC4QfgU7Ofji1TjyoH1d8eFjWsSiWHHgBamfltpGm3g7s="}} -------------------------------------------------------------------------------- /UpdateOcelotConfig/UpdateOcelotConfig.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2024 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "Client\Client.csproj", "{5556B6D4-4FF3-44AB-8F0C-8590A3A01F77}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityService", "IdentityService\IdentityService.csproj", "{DBD7C0D0-0F5F-4369-8BC3-06B9E1D71CC2}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebAPIGetway", "WebAPIGetway\WebAPIGetway.csproj", "{A7630226-C865-4E68-BBF2-6B97CD2DD761}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {5556B6D4-4FF3-44AB-8F0C-8590A3A01F77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {5556B6D4-4FF3-44AB-8F0C-8590A3A01F77}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {5556B6D4-4FF3-44AB-8F0C-8590A3A01F77}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {5556B6D4-4FF3-44AB-8F0C-8590A3A01F77}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {DBD7C0D0-0F5F-4369-8BC3-06B9E1D71CC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {DBD7C0D0-0F5F-4369-8BC3-06B9E1D71CC2}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {DBD7C0D0-0F5F-4369-8BC3-06B9E1D71CC2}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {DBD7C0D0-0F5F-4369-8BC3-06B9E1D71CC2}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {A7630226-C865-4E68-BBF2-6B97CD2DD761}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {A7630226-C865-4E68-BBF2-6B97CD2DD761}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {A7630226-C865-4E68-BBF2-6B97CD2DD761}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {A7630226-C865-4E68-BBF2-6B97CD2DD761}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {5F60ABFA-D53D-46F8-A1DF-C659EF833EC8} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /UpdateOcelotConfig/WebAPIGetway/Ocelot.json: -------------------------------------------------------------------------------- 1 | { 2 | "ReRoutes": [ 3 | { 4 | "DownstreamPathTemplate": "/api/values", 5 | "DownstreamScheme": "http", 6 | "DownstreamHostAndPorts": [ 7 | { 8 | "Host": "localhost", 9 | "Port": 10001 10 | } 11 | ], 12 | "UpstreamPathTemplate": "/a/api/values", 13 | "UpstreamHttpMethod": [ "Get" ] 14 | } 15 | ], 16 | "GlobalConfiguration": { 17 | "BaseUrl": "http://localhost:10000/" 18 | } 19 | } -------------------------------------------------------------------------------- /UpdateOcelotConfig/WebAPIGetway/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | using Ocelot.DependencyInjection; 11 | 12 | namespace WebAPIGetway 13 | { 14 | public class Program 15 | { 16 | public static void Main(string[] args) 17 | { 18 | BuildWebHost(args).Run(); 19 | 20 | Console.ReadLine(); 21 | } 22 | 23 | public static IWebHost BuildWebHost(string[] args) => 24 | WebHost.CreateDefaultBuilder(args) 25 | //add ocelot json config file 26 | .ConfigureAppConfiguration((hostingContext, builder) => 27 | { 28 | builder 29 | .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath) 30 | .AddJsonFile("Ocelot.json") 31 | .AddEnvironmentVariables(); 32 | }) 33 | .UseStartup() 34 | .UseUrls("http://*:10000") 35 | .Build(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /UpdateOcelotConfig/WebAPIGetway/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:10000/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "Executable", 13 | "commandLineArgs": "name=oec2003", 14 | "launchBrowser": true, 15 | "launchUrl": "api/values", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "WebAPIGetway": { 21 | "commandName": "Project", 22 | "launchUrl": "api/values", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | }, 26 | "applicationUrl": "http://localhost:10000/" 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /UpdateOcelotConfig/WebAPIGetway/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using IdentityServer4.AccessTokenValidation; 6 | using Microsoft.AspNetCore.Builder; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.DependencyInjection; 10 | using Microsoft.Extensions.Logging; 11 | using Microsoft.Extensions.Options; 12 | using Ocelot.DependencyInjection; 13 | using Ocelot.Middleware; 14 | 15 | namespace WebAPIGetway 16 | { 17 | public class Startup 18 | { 19 | public Startup(IConfiguration configuration) 20 | { 21 | Configuration = configuration; 22 | } 23 | 24 | public IConfiguration Configuration { get; } 25 | 26 | public void ConfigureServices(IServiceCollection services) 27 | { 28 | Action options = o => 29 | { 30 | //IdentityService认证服务的地址 31 | o.Authority = "http://localhost:9500"; 32 | //IdentityService项目中Config类中定义的ApiName 33 | o.ApiName = "s2api"; // 34 | o.RequireHttpsMetadata = false; 35 | o.SupportedTokens = SupportedTokens.Both; 36 | //IdentityService项目中Config类中定义的Secret 37 | o.ApiSecret = "secret"; 38 | }; 39 | 40 | services.AddOcelot() 41 | .AddAdministration("/admin", options); 42 | } 43 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 44 | { 45 | if (env.IsDevelopment()) 46 | { 47 | app.UseDeveloperExceptionPage(); 48 | } 49 | 50 | app.UseOcelot().Wait(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /UpdateOcelotConfig/WebAPIGetway/WebAPIGetway.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /UpdateOcelotConfig/WebAPIGetway/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /UpdateOcelotConfig/WebAPIGetway/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /VueSample/hello-world/README.md: -------------------------------------------------------------------------------- 1 | # hello-world 2 | 3 | ## Project setup 4 | ``` 5 | yarn install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | yarn run serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | yarn run build 16 | ``` 17 | 18 | ### Run your tests 19 | ``` 20 | yarn run test 21 | ``` 22 | 23 | ### Lints and fixes files 24 | ``` 25 | yarn run lint 26 | ``` 27 | 28 | ### Customize configuration 29 | See [Configuration Reference](https://cli.vuejs.org/config/). 30 | -------------------------------------------------------------------------------- /VueSample/hello-world/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/app' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /VueSample/hello-world/dist/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:latest 2 | COPY . /usr/share/nginx/html/ 3 | EXPOSE 80 4 | CMD ["nginx", "-g", "daemon off;"] 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /VueSample/hello-world/dist/css/app.6af8ca07.css: -------------------------------------------------------------------------------- 1 | #app{font-family:Avenir,Helvetica,Arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-align:center;color:#2c3e50;margin-top:60px} -------------------------------------------------------------------------------- /VueSample/hello-world/dist/css/chunk-96d74ff0.9f02239b.css: -------------------------------------------------------------------------------- 1 | .header[data-v-06bef803]{background-color:#0078d7;color:#f0f8ff;padding-left:0;height:48px} -------------------------------------------------------------------------------- /VueSample/hello-world/dist/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oec2003/StudySamples/7cea1b5b3b4c7028eaddddc3d6fc4aa73d12d8f1/VueSample/hello-world/dist/favicon.ico -------------------------------------------------------------------------------- /VueSample/hello-world/dist/fonts/element-icons.535877f5.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oec2003/StudySamples/7cea1b5b3b4c7028eaddddc3d6fc4aa73d12d8f1/VueSample/hello-world/dist/fonts/element-icons.535877f5.woff -------------------------------------------------------------------------------- /VueSample/hello-world/dist/fonts/element-icons.732389de.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oec2003/StudySamples/7cea1b5b3b4c7028eaddddc3d6fc4aa73d12d8f1/VueSample/hello-world/dist/fonts/element-icons.732389de.ttf -------------------------------------------------------------------------------- /VueSample/hello-world/dist/img/logo.82b9c7a5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oec2003/StudySamples/7cea1b5b3b4c7028eaddddc3d6fc4aa73d12d8f1/VueSample/hello-world/dist/img/logo.82b9c7a5.png -------------------------------------------------------------------------------- /VueSample/hello-world/dist/index.html: -------------------------------------------------------------------------------- 1 | hello-world
    -------------------------------------------------------------------------------- /VueSample/hello-world/dist/js/app.bc39e0c0.js: -------------------------------------------------------------------------------- 1 | (function(e){function t(t){for(var r,o,c=t[0],i=t[1],l=t[2],f=0,s=[];f\n \n

    登录

    \n \n \n \n \n \n \n

    {{ errorMessage }}

    \n \n 登录\n \n
    \n\n\n","import mod from \"-!../../node_modules/cache-loader/dist/cjs.js??ref--12-0!../../node_modules/thread-loader/dist/cjs.js!../../node_modules/babel-loader/lib/index.js!../../node_modules/cache-loader/dist/cjs.js??ref--0-0!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./login.vue?vue&type=script&lang=js&\"; export default mod; export * from \"-!../../node_modules/cache-loader/dist/cjs.js??ref--12-0!../../node_modules/thread-loader/dist/cjs.js!../../node_modules/babel-loader/lib/index.js!../../node_modules/cache-loader/dist/cjs.js??ref--0-0!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./login.vue?vue&type=script&lang=js&\"","import { render, staticRenderFns } from \"./login.vue?vue&type=template&id=2843af86&scoped=true&\"\nimport script from \"./login.vue?vue&type=script&lang=js&\"\nexport * from \"./login.vue?vue&type=script&lang=js&\"\n\n\n/* normalize component */\nimport normalizer from \"!../../node_modules/vue-loader/lib/runtime/componentNormalizer.js\"\nvar component = normalizer(\n script,\n render,\n staticRenderFns,\n false,\n null,\n \"2843af86\",\n null\n \n)\n\nexport default component.exports"],"sourceRoot":""} -------------------------------------------------------------------------------- /VueSample/hello-world/dist/js/chunk-96d74ff0.98d44380.js: -------------------------------------------------------------------------------- 1 | (window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-96d74ff0"],{"0b62":function(e,n,t){},c3b0:function(e,n,t){"use strict";t.r(n);var a=function(){var e=this,n=e.$createElement,t=e._self._c||n;return t("el-container",{attrs:{id:"main-view"}},[t("el-header",{staticClass:"header"},[t("top-bar",{attrs:{code:e.loginName},on:{change_name:e.changeName}})],1),t("el-main",[e._v("\n 这是正文部分,欢迎: "+e._s(e.loginName)+"\n ")])],1)},c=[],o=function(){var e=this,n=e.$createElement,t=e._self._c||n;return t("div",[e._v("这是网站的头部, 欢迎:"+e._s(e.code)+" \n"),t("el-button",{attrs:{type:"primary"},on:{click:e.changeName}},[e._v("改变名称")])],1)},r=[],i={name:"top-bar",props:{code:String},methods:{changeName:function(){return this.$emit("change_name","oec2003")}}},s=i,u=t("2877"),l=Object(u["a"])(s,o,r,!1,null,"0f12cf04",null),m=l.exports,h={name:"home",data:function(){return{loginName:this.$route.query.code}},components:{TopBar:m},methods:{changeName:function(e){this.loginName=e}}},f=h,d=(t("e257"),Object(u["a"])(f,a,c,!1,null,"06bef803",null));n["default"]=d.exports},e257:function(e,n,t){"use strict";var a=t("0b62"),c=t.n(a);c.a}}]); 2 | //# sourceMappingURL=chunk-96d74ff0.98d44380.js.map -------------------------------------------------------------------------------- /VueSample/hello-world/dist/js/chunk-96d74ff0.98d44380.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["webpack:///./src/components/home.vue?ea89","webpack:///./src/components/top-bar.vue?4059","webpack:///src/components/top-bar.vue","webpack:///./src/components/top-bar.vue?7376","webpack:///./src/components/top-bar.vue","webpack:///src/components/home.vue","webpack:///./src/components/home.vue?2c2c","webpack:///./src/components/home.vue?5c7e","webpack:///./src/components/home.vue?8569"],"names":["render","_vm","this","_h","$createElement","_c","_self","attrs","staticClass","loginName","on","changeName","_v","_s","staticRenderFns","code","component"],"mappings":"gJAAA,IAAIA,EAAS,WAAa,IAAIC,EAAIC,KAASC,EAAGF,EAAIG,eAAmBC,EAAGJ,EAAIK,MAAMD,IAAIF,EAAG,OAAOE,EAAG,eAAe,CAACE,MAAM,CAAC,GAAK,cAAc,CAACF,EAAG,YAAY,CAACG,YAAY,UAAU,CAACH,EAAG,UAAU,CAACE,MAAM,CAAC,KAAON,EAAIQ,WAAWC,GAAG,CAAC,YAAcT,EAAIU,eAAe,GAAGN,EAAG,UAAU,CAACJ,EAAIW,GAAG,sBAAsBX,EAAIY,GAAGZ,EAAIQ,WAAW,WAAW,IAChVK,EAAkB,GCDlB,EAAS,WAAa,IAAIb,EAAIC,KAASC,EAAGF,EAAIG,eAAmBC,EAAGJ,EAAIK,MAAMD,IAAIF,EAAG,OAAOE,EAAG,MAAM,CAACJ,EAAIW,GAAG,eAAeX,EAAIY,GAAGZ,EAAIc,MAAM,QAAQV,EAAG,YAAY,CAACE,MAAM,CAAC,KAAO,WAAWG,GAAG,CAAC,MAAQT,EAAIU,aAAa,CAACV,EAAIW,GAAG,WAAW,IAC9O,EAAkB,GCItB,GACE,KAAF,UACE,MAAF,CACI,KAAJ,QAEE,QAAF,CACI,WADJ,WAEM,OAAN,uCCZiV,I,YCO7UI,EAAY,eACd,EACA,EACA,GACA,EACA,KACA,WACA,MAIa,EAAAA,E,QCLf,GACE,KAAF,OACE,KAFF,WAGI,MAAJ,CACM,UAAN,yBAGE,WAAF,CACI,OAAJ,GAEE,QAAF,CACI,WADJ,SACA,GACM,KAAN,eCzB8U,ICQ1U,G,UAAY,eACd,EACAhB,EACAc,GACA,EACA,KACA,WACA,OAIa,e,2CCnBf,yBAAge,EAAG","file":"js/chunk-96d74ff0.98d44380.js","sourcesContent":["var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('el-container',{attrs:{\"id\":\"main-view\"}},[_c('el-header',{staticClass:\"header\"},[_c('top-bar',{attrs:{\"code\":_vm.loginName},on:{\"change_name\":_vm.changeName}})],1),_c('el-main',[_vm._v(\"\\n 这是正文部分,欢迎: \"+_vm._s(_vm.loginName)+\"\\n \")])],1)}\nvar staticRenderFns = []\n\nexport { render, staticRenderFns }","var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',[_vm._v(\"这是网站的头部, 欢迎:\"+_vm._s(_vm.code)+\" \\n\"),_c('el-button',{attrs:{\"type\":\"primary\"},on:{\"click\":_vm.changeName}},[_vm._v(\"改变名称\")])],1)}\nvar staticRenderFns = []\n\nexport { render, staticRenderFns }","\n\n","import mod from \"-!../../node_modules/cache-loader/dist/cjs.js??ref--12-0!../../node_modules/thread-loader/dist/cjs.js!../../node_modules/babel-loader/lib/index.js!../../node_modules/cache-loader/dist/cjs.js??ref--0-0!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./top-bar.vue?vue&type=script&lang=js&\"; export default mod; export * from \"-!../../node_modules/cache-loader/dist/cjs.js??ref--12-0!../../node_modules/thread-loader/dist/cjs.js!../../node_modules/babel-loader/lib/index.js!../../node_modules/cache-loader/dist/cjs.js??ref--0-0!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./top-bar.vue?vue&type=script&lang=js&\"","import { render, staticRenderFns } from \"./top-bar.vue?vue&type=template&id=0f12cf04&scoped=true&\"\nimport script from \"./top-bar.vue?vue&type=script&lang=js&\"\nexport * from \"./top-bar.vue?vue&type=script&lang=js&\"\n\n\n/* normalize component */\nimport normalizer from \"!../../node_modules/vue-loader/lib/runtime/componentNormalizer.js\"\nvar component = normalizer(\n script,\n render,\n staticRenderFns,\n false,\n null,\n \"0f12cf04\",\n null\n \n)\n\nexport default component.exports","\n\n\n\n","import mod from \"-!../../node_modules/cache-loader/dist/cjs.js??ref--12-0!../../node_modules/thread-loader/dist/cjs.js!../../node_modules/babel-loader/lib/index.js!../../node_modules/cache-loader/dist/cjs.js??ref--0-0!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./home.vue?vue&type=script&lang=js&\"; export default mod; export * from \"-!../../node_modules/cache-loader/dist/cjs.js??ref--12-0!../../node_modules/thread-loader/dist/cjs.js!../../node_modules/babel-loader/lib/index.js!../../node_modules/cache-loader/dist/cjs.js??ref--0-0!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./home.vue?vue&type=script&lang=js&\"","import { render, staticRenderFns } from \"./home.vue?vue&type=template&id=06bef803&scoped=true&\"\nimport script from \"./home.vue?vue&type=script&lang=js&\"\nexport * from \"./home.vue?vue&type=script&lang=js&\"\nimport style0 from \"./home.vue?vue&type=style&index=0&id=06bef803&lang=css&scoped=true&\"\n\n\n/* normalize component */\nimport normalizer from \"!../../node_modules/vue-loader/lib/runtime/componentNormalizer.js\"\nvar component = normalizer(\n script,\n render,\n staticRenderFns,\n false,\n null,\n \"06bef803\",\n null\n \n)\n\nexport default component.exports","import mod from \"-!../../node_modules/mini-css-extract-plugin/dist/loader.js??ref--6-oneOf-1-0!../../node_modules/css-loader/index.js??ref--6-oneOf-1-1!../../node_modules/vue-loader/lib/loaders/stylePostLoader.js!../../node_modules/postcss-loader/src/index.js??ref--6-oneOf-1-2!../../node_modules/cache-loader/dist/cjs.js??ref--0-0!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./home.vue?vue&type=style&index=0&id=06bef803&lang=css&scoped=true&\"; export default mod; export * from \"-!../../node_modules/mini-css-extract-plugin/dist/loader.js??ref--6-oneOf-1-0!../../node_modules/css-loader/index.js??ref--6-oneOf-1-1!../../node_modules/vue-loader/lib/loaders/stylePostLoader.js!../../node_modules/postcss-loader/src/index.js??ref--6-oneOf-1-2!../../node_modules/cache-loader/dist/cjs.js??ref--0-0!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./home.vue?vue&type=style&index=0&id=06bef803&lang=css&scoped=true&\""],"sourceRoot":""} -------------------------------------------------------------------------------- /VueSample/hello-world/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hello-world", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "axios": "^0.19.0", 12 | "core-js": "^2.6.5", 13 | "element-ui": "^2.12.0", 14 | "vue": "^2.6.10", 15 | "vue-router": "^3.1.3" 16 | }, 17 | "devDependencies": { 18 | "@vue/cli-plugin-babel": "^3.11.0", 19 | "@vue/cli-plugin-eslint": "^3.11.0", 20 | "@vue/cli-service": "^3.11.0", 21 | "babel-eslint": "^10.0.1", 22 | "eslint": "^5.16.0", 23 | "eslint-plugin-vue": "^5.0.0", 24 | "vue-template-compiler": "^2.6.10" 25 | }, 26 | "eslintConfig": { 27 | "root": true, 28 | "env": { 29 | "node": true 30 | }, 31 | "extends": [ 32 | "plugin:vue/essential", 33 | "eslint:recommended" 34 | ], 35 | "rules": {}, 36 | "parserOptions": { 37 | "parser": "babel-eslint" 38 | } 39 | }, 40 | "postcss": { 41 | "plugins": { 42 | "autoprefixer": {} 43 | } 44 | }, 45 | "browserslist": [ 46 | "> 1%", 47 | "last 2 versions" 48 | ] 49 | } 50 | -------------------------------------------------------------------------------- /VueSample/hello-world/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oec2003/StudySamples/7cea1b5b3b4c7028eaddddc3d6fc4aa73d12d8f1/VueSample/hello-world/public/favicon.ico -------------------------------------------------------------------------------- /VueSample/hello-world/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | hello-world 9 | 10 | 11 | 14 |
    15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /VueSample/hello-world/src/App.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 13 | 14 | 24 | -------------------------------------------------------------------------------- /VueSample/hello-world/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oec2003/StudySamples/7cea1b5b3b4c7028eaddddc3d6fc4aa73d12d8f1/VueSample/hello-world/src/assets/logo.png -------------------------------------------------------------------------------- /VueSample/hello-world/src/common/http.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | axios.defaults.headers.post['Content-Type'] = 'application/json'; 3 | axios.defaults.baseURL = ""; 4 | export default { 5 | async GET(url, responseType) { 6 | try { 7 | const res = await axios.get(url, { 8 | responseType: responseType ? responseType : 'json', 9 | params: { 10 | random: new Date().getTime() 11 | } 12 | }); 13 | return successHandle(res); 14 | } catch (error) { 15 | return errorHandle(error); 16 | } 17 | }, 18 | async POST(url, parameters, responseType) { 19 | try { 20 | const res = await axios.post(url, parameters, { 21 | responseType: responseType ? responseType : 'json', 22 | }); 23 | if (responseType === "blob") { 24 | return res; 25 | } else { 26 | return successHandle(res); 27 | } 28 | } catch (error) { 29 | return errorHandle(error); 30 | } 31 | }, 32 | } 33 | 34 | function successHandle(res) { 35 | 36 | const data = res.data; 37 | if (data.hasOwnProperty('Code')) { 38 | data.Success = (data.Code === HttpCode.Success && data.Status === HttpStatus.Success); 39 | } 40 | return data; 41 | } 42 | 43 | function errorHandle(error) { 44 | let meesage = '后台异常'; 45 | if (error && error.request) { 46 | const status = error.request.status; 47 | if (status == 0) { 48 | meesage = '未请求到网络连接'; 49 | } 50 | } 51 | return { 52 | Success: false, 53 | Message: meesage 54 | } 55 | } 56 | 57 | const HttpCode = { 58 | Success: 200, 59 | ValidateFailed: 203, 60 | Error: 500, 61 | }; 62 | const HttpStatus = { 63 | Fail: 0, 64 | Success: 1, 65 | ConfirmIsContinue: 2, 66 | Error: 3 67 | }; -------------------------------------------------------------------------------- /VueSample/hello-world/src/components/home.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 31 | 39 | -------------------------------------------------------------------------------- /VueSample/hello-world/src/components/login.vue: -------------------------------------------------------------------------------- 1 | 22 | 92 | -------------------------------------------------------------------------------- /VueSample/hello-world/src/components/top-bar.vue: -------------------------------------------------------------------------------- 1 | 5 | 18 | -------------------------------------------------------------------------------- /VueSample/hello-world/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | import Element from 'element-ui'; 4 | import 'element-ui/lib/theme-chalk/index.css'; 5 | import router from './routers/router' 6 | Vue.config.productionTip = false 7 | Vue.use(Element, { size: 'small', zIndex: 3000 }); 8 | new Vue({ 9 | router, 10 | render: h => h(App), 11 | }).$mount('#app') -------------------------------------------------------------------------------- /VueSample/hello-world/src/routers/router.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | import Router from "vue-router"; 3 | Vue.use(Router); 4 | const router = new Router({ 5 | mode: 'history', 6 | routes: [{ 7 | path: "/", 8 | component: () => 9 | import ("@/components/home.vue") 10 | }, { 11 | path: "/login", 12 | name: "login", 13 | component: () => 14 | import ("@/components/login.vue") 15 | }, 16 | { 17 | path: "*", 18 | redirect: "/" 19 | } 20 | ] 21 | }) 22 | export default router; -------------------------------------------------------------------------------- /VueSample/hello-world/src/services/login.service.js: -------------------------------------------------------------------------------- 1 | import http from '@/common/http' 2 | 3 | const LoginService = { 4 | 5 | login: async function(code, password) { 6 | let res = await http.POST('/api/Login', { 7 | Code: code || '', 8 | Pwd: password || '' 9 | }) 10 | if (res.Success && res.Result.Result) { 11 | // 登录成功后的处理 12 | 13 | } else { 14 | res.Success = false; 15 | res.Message = res.Result.Message; 16 | } 17 | return res; 18 | } 19 | } 20 | export default LoginService --------------------------------------------------------------------------------