From c5867327d214a2be0e488056132a62ac8533c3fc Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Tue, 31 Mar 2020 14:54:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Controller=E8=8E=B7=E5=8F=96M?= =?UTF-8?q?odelMetadata=E7=9A=84=E6=89=A9=E5=B1=95=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=8CXamarinApp=E5=8D=87=E7=BA=A7=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E5=8C=85=E5=B9=B6=E4=BD=BF=E7=94=A8Application.Current.Propert?= =?UTF-8?q?ies=E8=BF=9B=E8=A1=8C=E9=85=8D=E7=BD=AE=E8=AF=BB=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 55ff3bd01cd455cba1a57ae46c248d1b6e7164e2 --- .../Extensions/ControllerExtensions.cs | 14 ++++++++++++++ .../UserCenter/Application/Models/RegisterModel.cs | 12 ++++++------ projects/UserCenter/Controllers/HomeController.cs | 10 +++++++--- .../Properties/AndroidManifest.xml | 8 +++++--- .../XamarinApp.Android/XamarinApp.Android.csproj | 4 ++-- .../XamarinApp.iOS/XamarinApp.iOS.csproj | 4 ++-- projects/XamarinApp/XamarinApp/MainPage.xaml.cs | 13 ++++++------- projects/XamarinApp/XamarinApp/XamarinApp.csproj | 4 ++-- 8 files changed, 44 insertions(+), 25 deletions(-) create mode 100644 projects/Infrastructure/Extensions/ControllerExtensions.cs diff --git a/projects/Infrastructure/Extensions/ControllerExtensions.cs b/projects/Infrastructure/Extensions/ControllerExtensions.cs new file mode 100644 index 00000000..afbd7865 --- /dev/null +++ b/projects/Infrastructure/Extensions/ControllerExtensions.cs @@ -0,0 +1,14 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ModelBinding; +using Microsoft.Extensions.DependencyInjection; + +namespace Infrastructure.Extensions +{ + public static class ControllerExtensions + { + public static ModelMetadata GetModelMetadata(this ControllerBase controller) + { + return controller.HttpContext.RequestServices.GetRequiredService().GetMetadataForType(typeof(T)); + } + } +} \ No newline at end of file diff --git a/projects/UserCenter/Application/Models/RegisterModel.cs b/projects/UserCenter/Application/Models/RegisterModel.cs index 97f081dc..00bffe74 100644 --- a/projects/UserCenter/Application/Models/RegisterModel.cs +++ b/projects/UserCenter/Application/Models/RegisterModel.cs @@ -6,20 +6,20 @@ using Microsoft.AspNetCore.Mvc; namespace Application.Models { - [Display(Name = "邮箱注册")] + //[Display(Name = "邮箱注册")] public class RegisterModel { [Required(ErrorMessage = nameof(RequiredAttribute))] [RegularExpression("^[a-zA-Z0-9]+$", ErrorMessage = "用户名只能由数字和字母组成")] [StringLength(30, MinimumLength = 5, ErrorMessage = "用户名长度为5-30")] - [Display(Name = "用户名")] + //[Display(Name = "用户名")] [Remote("UserNameNotUsed", "Account", ErrorMessage = "用户名已存在")] public string UserName { get; set; } [Required(ErrorMessage = nameof(RequiredAttribute))] [StringLength(100, MinimumLength = 6, ErrorMessage = "密码长度范围为{2}-{1}")] [DataType(DataType.Password)] - [Display(Name = "登录密码")] + //[Display(Name = "登录密码")] public string Password { get; set; } [DataType(DataType.Password)] @@ -30,19 +30,19 @@ namespace Application.Models [Required(ErrorMessage = nameof(RequiredAttribute))] [DataType(DataType.EmailAddress)] [RegularExpression(@"^\w+@\w+\.\w+$", ErrorMessage = "邮箱格式错误")] - [Display(Name = "邮箱")] + //[Display(Name = "邮箱")] [Remote("EmailNotUsed", "Account", ErrorMessage = "邮箱已占用")] public string Email { get; set; } [UIHint("CodeCaptcha")] [CodeCaptchaAttribute] [Required(ErrorMessage = nameof(RequiredAttribute))] - [Display(Name = "验证码")] + //[Display(Name = "验证码")] public string CodeCaptcha { get; set; } [MustBeTrue(ErrorMessage = nameof(MustBeTrueAttribute))] [AdditionalMetadata("用户服务协议", "/")] - [Display(Name = "我阅读并同意")] + //[Display(Name = "我阅读并同意")] [UIHint("MustBeTrue")] public bool AgreeWith { get; set; } } diff --git a/projects/UserCenter/Controllers/HomeController.cs b/projects/UserCenter/Controllers/HomeController.cs index 87da6fb9..dd77877a 100644 --- a/projects/UserCenter/Controllers/HomeController.cs +++ b/projects/UserCenter/Controllers/HomeController.cs @@ -1,11 +1,13 @@ -using System.Linq; +using Application.Domain.Entities; +using Application.Models; using Infrastructure.Data; +using Infrastructure.Extensions; +using Infrastructure.Resources; using Infrastructure.Security; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Localization; -using Application.Domain.Entities; -using Infrastructure.Resources; +using System.Linq; namespace UserCenter.Controllers { @@ -28,6 +30,8 @@ namespace UserCenter.Controllers public IActionResult Index() { + //var modelMetadata = this.GetModelMetadata(); + //var json = modelMetadata.ToJson(); return View(this._siteRepo.ReadOnlyTable().ToList()); } } diff --git a/projects/XamarinApp/XamarinApp.Android/Properties/AndroidManifest.xml b/projects/XamarinApp/XamarinApp.Android/Properties/AndroidManifest.xml index cdb5380a..43c05d42 100644 --- a/projects/XamarinApp/XamarinApp.Android/Properties/AndroidManifest.xml +++ b/projects/XamarinApp/XamarinApp.Android/Properties/AndroidManifest.xml @@ -1,6 +1,8 @@  - - - + + + + + \ No newline at end of file diff --git a/projects/XamarinApp/XamarinApp.Android/XamarinApp.Android.csproj b/projects/XamarinApp/XamarinApp.Android/XamarinApp.Android.csproj index 00b8dc97..818e21bf 100644 --- a/projects/XamarinApp/XamarinApp.Android/XamarinApp.Android.csproj +++ b/projects/XamarinApp/XamarinApp.Android/XamarinApp.Android.csproj @@ -54,8 +54,8 @@ - - + + diff --git a/projects/XamarinApp/XamarinApp.iOS/XamarinApp.iOS.csproj b/projects/XamarinApp/XamarinApp.iOS/XamarinApp.iOS.csproj index 51a743a5..ad32b77e 100644 --- a/projects/XamarinApp/XamarinApp.iOS/XamarinApp.iOS.csproj +++ b/projects/XamarinApp/XamarinApp.iOS/XamarinApp.iOS.csproj @@ -127,8 +127,8 @@ - - + + diff --git a/projects/XamarinApp/XamarinApp/MainPage.xaml.cs b/projects/XamarinApp/XamarinApp/MainPage.xaml.cs index 34a27d38..61a19d06 100644 --- a/projects/XamarinApp/XamarinApp/MainPage.xaml.cs +++ b/projects/XamarinApp/XamarinApp/MainPage.xaml.cs @@ -1,6 +1,5 @@ using System; using System.ComponentModel; -using System.IO; using System.Threading.Tasks; using Xamarin.Forms; @@ -9,18 +8,18 @@ namespace XamarinApp [DesignTimeVisible(false)] public partial class MainPage : ContentPage { - private string _configFile; - private string _baseUrl = "http://192.168.1.8"; + private const string baseUrlKey = "baseUrl"; + private string _baseUrl; public MainPage() { InitializeComponent(); this.option.Source = ImageSource.FromResource($"{this.GetType().Assembly.GetName().Name}.Images.options.png"); - this._configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "config.txt"); - if (!File.Exists(this._configFile)) + if (!Application.Current.Properties.ContainsKey(baseUrlKey)) { - File.WriteAllText(this._configFile, this._baseUrl); + Application.Current.Properties[baseUrlKey] = "http://192.168.1.8"; } + this._baseUrl = Application.Current.Properties[baseUrlKey] as string; this.webView.Source = this._baseUrl; this.Appearing += MainPage_Appearing; } @@ -47,8 +46,8 @@ namespace XamarinApp var input = await DisplayPromptAsync("服务器", "配置服务器地址", "确定", "取消", this._baseUrl, keyboard: Keyboard.Url, initialValue: this._baseUrl); if (!string.IsNullOrEmpty(input)) { + Application.Current.Properties[baseUrlKey] = input; this._baseUrl = input; - File.WriteAllText(this._configFile, this._baseUrl); this.webView.Source = this._baseUrl; } } diff --git a/projects/XamarinApp/XamarinApp/XamarinApp.csproj b/projects/XamarinApp/XamarinApp/XamarinApp.csproj index 16621c14..7224610d 100644 --- a/projects/XamarinApp/XamarinApp/XamarinApp.csproj +++ b/projects/XamarinApp/XamarinApp/XamarinApp.csproj @@ -19,7 +19,7 @@ - - + + \ No newline at end of file