Giter Site home page Giter Site logo

blog's Introduction

Hi there 👋

blog's People

Contributors

venux avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

blog's Issues

ASP.NET Core基本原理概况

ASP.NET Core fundamentals overview

ASP.NET Core应用只是个简单的创建Web Server的控制台应用程序。

using System;
using Microsoft.AspNetCore.Hosting;

namespace aspnetcoreapp
{
    public class Program
    {
        var host=new WebHostBuilder()
            .UserKestrel()
            .UseStartup<Startup>()
            .Build();

            host.Run();
    }
}

说明:

  • WebHostBuilder使用建造者模式创建Web Application Host;
  • WebHostBuilder-UseIISIntegration:使用IIS或IIS Express作为宿主容器;
  • WebHostBuilder-UseContentRoot:指明程序根目录(root content directory);
  • WebHostBuilder-Build:创建IWebHost对象用来寄宿(host)应用程序;
  • WebHostBuilder-Run:启动应用程序,开始监听HTTP请求。

1 Startup

WebHostBuilder对象的UseStartup方法用来指明应用程序的Startup类。

  • 该类主要用来定义请求处理管道(Request Handing Pipeline)及配置服务(Services Configure);
  • 该类必须为public类型;
  • 该类默认包含以下两方法,应用启动时被调用(called);
    • ConfigureServices(可选)定义应用程序所需要的服务;
    • Configure(必须)指明应用如何响应HTTP请求,通过依赖注入在IApplicationBuilder中注入中间件(middleware)来配置请求管道。
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
        }
    
        public void Configure(IApplicationBuilder app)
        {
        }
    }
  • ASP.NET Core应用需要一个Startup类,默认情况下命名为Startup,可通过UseStartup方法指定自定义的Startup类名;
  • 在不同的环境下可定义不同的Startup类,运行时(runtime)会自动选择合适的Startup
  • 若在WebHost配置选项中指明startupAssembly,则宿主会加载对应程序集,并在其中搜索StartupStartup[Environment]的对象的类型,参见StartupLoader类的FindStartupType
    //查找程序集的Startup类        
    public static Type FindStartupType(string startupAssemblyName, string environmentName)
    {
        if (string.IsNullOrEmpty(startupAssemblyName))
        {
            throw new ArgumentException(
                string.Format("A startup method, startup type or startup assembly is required. If specifying an assembly, '{0}' cannot be null or empty.",
                nameof(startupAssemblyName)),
                nameof(startupAssemblyName));
        }
    
        var assembly = Assembly.Load(new AssemblyName(startupAssemblyName));
        if (assembly == null)
        {
            throw new InvalidOperationException(String.Format("The assembly '{0}' failed to load.", startupAssemblyName));
        }
    
        var startupNameWithEnv = "Startup" + environmentName;
        var startupNameWithoutEnv = "Startup";
    
        // Check the most likely places first
        var type =
            assembly.GetType(startupNameWithEnv) ??
            assembly.GetType(startupAssemblyName + "." + startupNameWithEnv) ??
            assembly.GetType(startupNameWithoutEnv) ??
            assembly.GetType(startupAssemblyName + "." + startupNameWithoutEnv);
    
        if (type == null)
        {
            // Full scan
            var definedTypes = assembly.DefinedTypes.ToList();
    
            var startupType1 = definedTypes.Where(info => info.Name.Equals(startupNameWithEnv, StringComparison.Ordinal));
            var startupType2 = definedTypes.Where(info => info.Name.Equals(startupNameWithoutEnv, StringComparison.Ordinal));
    
            var typeInfo = startupType1.Concat(startupType2).FirstOrDefault();
            if (typeInfo != null)
            {
                type = typeInfo.AsType();
            }
        }
    
        if (type == null)
        {
            throw new InvalidOperationException(String.Format("A type named '{0}' or '{1}' could not be found in assembly '{2}'.",
                startupNameWithEnv,
                startupNameWithoutEnv,
                startupAssemblyName));
        }
    
        return type;
    }       
  • Startup类的构造函数可通过依赖注入(Dependency Injection)注入相关依赖项;
    • IHostingEnvironment:添加配置;
    • ILoggerFactory:设置日志;
    • 待添加

2 Services

3 Middleware

4 Servers

5 Content root

6 Web root

7 Configuration

8 Environments

9 .NET Core vs .NET Framework runtime

10 Additional

Working with multiple environments

多环境工作

ASPNETCORE_ENVIRONMENT 环境变量

  • Development 开发环境

  • Staging 预发布、部署上线前的最终测试环境、生产环境的物理镜像

  • Production 生产环境(安全性、高性能、稳健性)

    • 开启缓存
    • 客户端资源 bundledminifiedCDN
    • 关闭 diagnostic ErrorPages
    • 开启 friendly error pages
    • 开启 production loggingmonitoring
    • ...

注:

  • Windows 不区分大小写,Linux 默认区分大小写。

  • 设置:右键项目属性-调试-环境变量,另在 ~\Properties\launchSettings.json 可看到具体配置。

    • launchSettings.json 存储的变量可访问到,不安全,禁止存放加密信息,使用 Secret Manager 存放加密信息。
  • 本机设置

    • 临时:set ASPNETCORE_ENVIRONMENT=Development
    • 永久:环境变量-ASPNETCORE_ENVIRONMENT=Development

【UML Distilled】学习笔记

UML Distilled-Martin Fowler

Chapter 3. Class Diagrams: The Essentials

类图 Class Diagrams

  • 类图主要用于描述系统中的类型及其相关联的事物。它用于展示类的属性和操作以及关联的相关约束。 A class diagram describes the types of objects in the system and the various kinds of static relationships that exist among them. Class diagrams also show the properties and operations of a class and the constraints that apply to the way objects are connected. The UML uses the term feature as a general term that covers properties and operations of a class.

属性 Properties

  • 属性用于表示类的结构特性。 Properties represent structural features of a class.
  • 在类图框中用一行属性符号用于表示属性。The attribute notation describes a property as a line of text within the class box itself.
    • visibility name: type multiplicity = default {property-string}
      • visibility:可见性,public(+)或者private(-);
      • name:属性名称(只有名称必选);
      • type:属性类型;
      • multiplicity:重数,表明属性关联的对象数量;
        • 1:1个(默认值,虽然1是默认值,但在缺少重数标识的情况下不能将其假定为1。所以如果重要的话,显示指明重数。);
        • 0..1:0个或1个;
        • * :0个或多个;
        • n..m:N个至M个;
        • Optional:下界为0;
        • Mandatory:下界为1或者更大;
        • Single-valued:上界为1;
        • Multivalued:上界大于1;
      • default:默认值;
      • {property-string}:属性描述字符,用于添加额外的自定义属性描述,如readonly,ordered,unique等。

关联 Associations

  • 两个类图之间用实线关联,由源类指向目标类。
    qq 20170314224939

Markdown学习笔记

Markdown学习示例

什么是Markdown

Markdown是一种在web显示带样式风格文本的方式。你能通过它控制文本的字体样式、插入图片、插入列表等。通常,Markdown使用一些特殊的非字母符号来作为语法规则,如#等。
你能在Github上大部分地方使用Markdown。

  • Gists
  • Issues的评论、Pull Requests
  • .md或.markdown后缀名的文件

示例

  1. 这是一个文本;
  2. 粗体
  3. 斜体
  4. 我的Github
  5. 列表
    • 无序列表1
    • 无序列表2
      • 无序列表21
      • 无序列表22
  6. 图片Image
  7. 引用

Hello,World!-Coder

语法

见上文

H1

H2

H3

H4

H5
H6

I think you should use an
<addr> element here instead.

Github特殊风格

语法高亮

function Test(args){
	if(args){
		console.log(args);
	}	
}
public class Test
{
	static void Main()
	{
		Console.WriteLine("Hello,World!");		
	}
}

任务列表

  • 1. 已完成任务,支持列表,@mentions, #refs, links, formatting, and tags supported
  • 2. 未完成任务

表格

表头一 表头2
11 12
21 22

SHA引用

5e0b770018f87bd7fafecb7b3920cda8a30d4740

Issue引用

#1

圈人

@venux @cdll

自动识别网址

http://www.cnblogs.com

删除线

删除

Emoji

👍

锚点

锚点测试

【Git】同步Fork项目的命令操作

syncing-a-fork

1. git remote -v

查看当前Fork项目已配置的远程仓库(List the current configured remote repository for your fork)

2. git remote add upstream url

指定将要同步Fork项目的一个远程上游仓库(Specify a new remote upstream repository that will be synced with the fork.)

3. git remote -v

再次查看

4. git fetch upstream

拉取上游仓库的所有分支和更改记录,mater分支提交记录会在本地分支中保存。(Fetch the branches and their respective commits from the upstream repository. Commits to master will be stored in a local branch, upstream/master.)

5. git checkout master

迁出本地master分支(Check out your fork's local master branch.)

6. git merge upstream/master

将上游仓库的master分支更改记录合并到本地master分支中,即同步且不会丢失本地更改记录。(Merge the changes from upstream/master into your local master branch. This brings your fork's master branch into sync with the upstream repository, without losing your local changes.)

Redis学习笔记

redis入门

键值对

  • SET TESTKEY "TESTVALUE",设置键值对TESTKEY-"TESTVALUE",返回OK;
  • GET TESTKEY,获取键TESTKEY的值(获取不存在的键的值返回nil,即空);
  • DEL TESTKEY,删除键为TESTKEY的键值对,成功返回1;
  • EXISTS TESTKEY,键是否存在,0否1是
  • TYPE TESTKEY,返回键的类型,如string、list等,若键不存在返回None;
  • INCR TESTKEY,自动加一,成功返回结果(若TESTKEY不是int值,则报错)注意:INCR命令是原子操作(即不会被线程调度机制打断的操作);
  • SETNX TEST1 'TESTVALUE',若键不存在则设置,若键存在则不设置,成功返回1,失败返回0;
  • EXPIRE TESTKEY 120,设置键TESTKEY有效期120秒(等同于 SET TESTKEY 'TESTVALUE' EX 120);
  • PERSIST TESTKEY,取消TESTKEY的有效期,1成功0失败
  • TTL TESTKEY,查看键TESTKEY剩余有效期,-2表示键已过期不存在,-1表示永不过期,若重下SET TESTKEY,则状态重置为-1;

数据结构

列表(list)有序、可重复

  • RPUSH TESTLIST "ITEM1" "ITEM2" "ITEM3" ... "ITEMN",插入多项到列表尾部,返回列表子项个数;
  • LPUSH TESTLIST "ITEM2",插入一项到列表头部,返回列表子项个数;
  • LRANGE TESTLIST 0 -1,列出列表子项,参数1表示从第0个开始,参数2表示到第N个(-1表示最后);
  • LLEN TESTLIST,获取列表子项个数;
  • LPOP TESTLIST,移除列表头部项,返回项的值;
  • RPOP TESTLIST,移除列表尾部项,返回项的值;
  • 工具命令BRPOP TESTLIST 0、BLPOP,阻塞版本的取元素,若LIST为空,仅在规定时间(0代表永久)内有新元素加入时候取出,而不是返回NULL;
    • 客户端按顺序执行,第一个取得先等其他客户端加入元素,以此类推;
    • 与RPOP相比,返回值是不同的:它是一个两元素数组,因为它也包括键的名称,因为BRPOP和BLPOP能够阻止等待来自多个列表的元素。
    • 如果超时,则返回NULL。
    • RPOPLPUSH更适合命令创建安全的队列,BRPOPLPUSH阻塞版本
  • LTRIM TESTLIST 0 2,只保留前3项,丢弃之后的元素;

集合(set)无序、不可重复

  • SADD TESTSET "ITEM1" "ITEM2" "ITEM3" ... "ITEMN",插入一项到集合中,返回1表示成功,若已有该项则返回0;
  • SREM TESTSET "ITEM1",从集合中移除指定项,返回1表示成功,若无该项则返回0;
  • SISMEMBER TESTSET "ITEM1",验证指定项是否在集合中,0否1是;
  • SMEMBERS TESTSET,列出集合项
  • SUNION TESTSET1 TEST2 ... TESTN,取多个集合并集(无序无重复项);
  • SINTER TESTSET1 TEST2 ... TESTN,取多个集合交集
  • SUNIONSTORE TESTSETALL TESTSET1 TESTSET2 ...TESTSETN,将多个集合并集保存至TESTSETALL
  • SCARD TESETSET1,获取集合元素个数
  • SPOP TESTSET1,随机取一个集合元素,移除集合
  • SRANDMEMBER TESTSET1,随机取一个集合元素,不移除集合

有序集合(sorted set)有序、不可重复

  • ZADD TESTSORTSET 3 "C",3为关联值,用于排序,float;
  • ZRANGE TESTSORTLIST 0 -1 [withscores],列出有序集合子项,参数1表示从第0个开始,参数2表示到第N个(-1表示最后),[withscores]可选,是否列出score项;
  • ZREVRANGE TESTSORTLIST 0,-1,反向列出有序集合元素;
  • ZRANK TESTSORTLIST 'C',查找指定元素的位置;
  • ZREVRANK TESTSORTLIST 'C',反向查找指定元素的位置;

哈希(Hashes)用于保存对象

  • HSET obj name 'venux';HSET obj age '27';HSET obj email '[email protected]',保存一个obj对象,单个属性存放用户名、年龄、email。
  • HMSET obj name 'venux' age '27' email '[email protected]',保存一个obj对象,多个属性存放用户名、年龄、email。
  • HGETALL obj,获取obj对象
  • HGET obj name,获取obj对象的name属性
  • HINCRBY obj age 10,给obj对象的age属性加10,Hash字段中数值类型使用同等的字符串表示,并能通过HINCRBY(原子操作)累加

介绍Redis数据结构和抽象

Redis支持的数据结构

  1. Binary-safe strings;
  2. Lists:按插入顺序排序的列表,基于链表;
  3. Sets:无序、唯一的集合;
  4. Sorted sets:有序、唯一的有序集合,用一个称为scroe的float字段存放排序值;
  5. Hashes:一系列属性合集,即对象,字段名和值都为strings;
  6. Bit arrays (or simply bitmaps):二进制数组;
  7. HyperLogLogs:this is a probabilistic data structure which is used in order to estimate the cardinality of a set(概率性数据结构,用于评估集合的基数).

Redis keys

  • 空字符串也是有效的key值;
  • 太长的key不好,若key代表的对象本身过长,使用hash(如SHA1)后的值作为key值;
  • 太短的key值也不好,如使用user:1000:followers替代u1000flw,这样可读性更良好;
  • 尽量(坚持)使用模式,一个良好的模式object-type:id,通常使用:-.分割。例如user:1000comment:1234:reply.tocomment:1234:reply-to
  • 键最大容量为512MB。

Redis Strings

  • 键值都为string类型,和Memcached一样,string作为唯一的数据类型;
  • 值也可用于保存图片资源,只要格式本质是string(如二进制),且大小不能超出512M;
  • SET命令选项:SET TESTKEY "TESTVALUE" nx/xx,nx代表如果键已存在,则SET失败;反之xx表示,如果键已存在则成功;
  • INCR TESTKEY:将string作为int值累加一并保存新值,DECR减; INCRBY TESTKEY 10:加10,DECRBY减; (其实是同一个底层命令不同表示方式);
  • GETSET:先获取旧值后设置新值(有点儿像i++);
  • MSET A 10 B 20 C 30;MGET A B C;MSET或MGET(返回一个Array)同时操作多个键值对ABC;

Redis expires(有效期)

  1. 精度可以说秒或毫秒;
  2. 本质上精度都是毫秒;
  3. 当Redis server停止时,过期的数据也会保存到磁盘中,Redis只是给key加了个有效期的属性;

Redis Lists

注意区分链表(Linked Lists)和数组(Array)。

  • Redis Lists本质是链表,在存储上不连续,优点插入时间复杂度为常量即O(1),缺点索引查找O(n)。
  • 数组指一系列元素的集合,在存储上是连续的,优点索引查找时间复杂度为常量即O(1),缺点插入O(n)。

适用场景

  1. 记录社交网络最后一个提交更新;
  2. 消息队列等;

Bitmaps(位图不是一个确切的数据类型)

  1. SETBIT BITKEY 10 1,设置BITKEY键的值的第10位为1;
  2. GETBIT BITKEY 10,获取BITKEY键的值的第10位;

适用场景

  1. 任何实时分析情况;
  2. 高效高性能存储boolean信息,通过各位0或1直接判断各种状态;

HyperLogLogs(估算各类分布概率)

  1. PFADD HLLTEST a b c d;插入元素;
  2. PFCOUNT HLLTEST;查询个数

适用场景

  1. 例如统计每天用户查询不同关键词的数目

【资源】.NET开源项目

ABP

nopCommerce

nopCommerce is the best open-source e-commerce shopping cart. nopCommerce is available for free. Today it's the best and most popular ASP.NET ecommerce software. It has been downloaded more than 1.8 million times!

Castle Windsor

Castle Windsor is a best of breed, mature Inversion of Control container available for .NET.

[图解HTTP]第1章.基础知识

基础知识

1

应用层

决定向用户提供应用服务时通信的活动。
TCP/IP协议簇内预存了各类通用的应用服务,如FTP文件传输协议,DNS域名系统服务。HTTP协议也在该层。

传输层

对上层应用层提供处于网络连接中两台计算机间的数据传输。
在传输层有两个性质不同的协议:TCP(Transmission Control Protocol,传输控制协议)和UDP(User Data Protocol,用户数据报协议)。

网络层

处理在网络上流动的数据包(网络传输的最小数据单位),该层规定了通过怎样的路径到达对方计算机,并把数据包传送给对方。

链路层

用来处理连接网络的硬件部分,包括控制操作系统,硬件设备驱动,网络适配器(网卡)及光纤等物理可见部分。

IP协议

IP(Internet Protocol)网际协议位于网络层。TCP/IP协议簇中的IP指的就是网际协议。
作用是把各种数据包发送给对方,而要确保发送正确需满足各类条件,其中两个重要的就是IP地址和MAC(Media Access Control Address)地址。
IP地址指明节点被分配的地址,MAC地址指网卡的固定地址,可配对。IP地址可变换而MAC地址基本不变。

ARP协议

ARP(Address Resolution Protocol)协议是一种用以解析地址的协议,根据通信方的IP地址反查出对应的MAC地址。

TCP协议

TCP协议位于传输层,提供可靠的字节流服务。采用三次握手(three-way handshaking)策略:发送端先发送带SYN(synchronize)标志的数据包给对方,接收端接受到后回传一个带SYN/ACK(acknowledgement)标志的数据包确认,最后,发送端回传ACK标志的数据包,表示握手结束。

DNS服务

DNS(Domain Name System)服务用于域名到IP地址之间解析,位于应用层。
2

URI(Uniform Resource Identifier)统一资源标识符

由某个协议方案表示的资源的定位标识符。

Uniform

规定统一的格式可方便处理多种不同类型的资源,而不用根据上下文环境来识别资源指定的访问方式。

Resource

资源的定义是可标识的任何东西。

Identifier

表示可标识的对象,即标识符。

URL(Uniform Resource Locator)统一资源定位符

资源的地点,是URI的子集。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.