示例#1
0
 /// <summary>
 /// 配置模型验证
 /// </summary>
 public static void ConfigValidation()
 {
     Model.Fluent <UserInfo>()
     .Required(item => item.Account, "账号不能为空")
     .Length(item => item.Account, 10, 5, "账号为{0}到{1}个字符")
     .Required(item => item.Password, "密码不能为空")
     .Length(item => item.Password, 12, 6, "密码为{0}到{1}个字符");
 }
示例#2
0
        static void Main(string[] args)
        {
            Console.Title = "通讯服务器";
            while (Directory.Exists("js") == false)
            {
                Directory.SetCurrentDirectory("../");
            }

            Model.Fluent <UserInfo>()
            .Required(item => item.Account, "账号不能为空")
            .Length(item => item.Account, 10, 5, "账号为{0}到{1}个字符")
            .Required(item => item.Password, "密码不能为空")
            .Length(item => item.Password, 12, 6, "密码为{0}到{1}个字符");

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("请将项目下的cert\\openssl.pfx安装为信任,否则浏览器和客户端不信任");
            Console.ForegroundColor = ConsoleColor.Gray;


            var listener = new TcpListener();

            Console.WriteLine("Use<HttpMiddleware>");
            listener.Use <HttpMiddleware>().GlobalFilters.Add(new HttpGlobalFilter());

            Console.WriteLine("Use<JsonWebSocketMiddleware>");
            listener.Use <JsonWebSocketMiddleware>().GlobalFilters.Add(new WebSockeGlobalFilter());

            Console.WriteLine("Use<FastMiddleware>");
            listener.Use <FastMiddleware>().GlobalFilters.Add(new FastGlobalFilter());

            Console.WriteLine("UsePlug<WebSocketPlug>");
            listener.UsePlug <WebSocketPlug>();

            Console.WriteLine("UseSSL<cert\\openssl.pfx>");
            var cert = new X509Certificate2("cert\\openssl.pfx", "123456");

            listener.UseSSL(cert);

            Console.WriteLine("Listening port 443");
            listener.Start(443);

            try
            {
                Process.Start("https://localhost");
            }
            catch (Exception)
            {
                Console.WriteLine("请在浏览器访问 https://localhost");
            }
            Console.Read();
            listener.Dispose();
        }