StyleCop SA1208 排列Using時先放置System指示詞

在使用組合管理Using->移除並排序Using功能的時後,會依照字母的順序排序

StyleCop就會靠北說System開頭的命名空間要放在最上面
SA1208 : CSharp.Ordering : System using directives must be placed before all other using directives

工具->選項->文字編輯器->C#->進階-
排序Usning時先放置System指示詞勾起來就行了

angular-deferred-bootstrap

angular-deferred-bootstrap

angular-deferred-bootstrap是用來初始化angular應用程式的套件

安裝

1
bower install --save angular-deferred-bootstrap

用法

1
2
3
4
5
6
7
8
9
deferredBootstrapper.bootstrap({
  element: document.body,
  module: 'MyApp',
  resolve: {
    APP_CONFIG: ['$http', function ($http) {
      return $http.get('/api/demo-config');
    }]
  }
});

載入狀態css類別

  • deferred-bootstrap-loading while the data is loading
  • deferred-bootstrap-error if an error occurs in a resolve function and the app can not be bootstrapped
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#loading {
    display: none;
}
.deferred-bootstrap-loading #loading {
    display: block !important;
}

#error {
    display: none;
}

.deferred-bootstrap-error #error {
    display: block !important;
}

.loading-message{
    text-align:center;
    font-size:16pt;
}

載入狀態html

1
2
3
4
5
6
7
8
9
10
11
12
13
14

<div id="loading" class="side-body padding-top">
    <div class="progress progress-striped active">
        <div class="progress-bar" style="width: 100%;"></div>
    </div>
    <p class="loading-message">Loading, please wait...</p>
</div>

<div id="error" class="side-body padding-top">
    <div class="progress">
        <div class="progress-bar" style="width: 100%;"></div>
    </div>
    <p class="loading-message">Loading fail, please try again...</p>
</div>

angular-cron-jobs

angular-cron-jobs

angular-cron-jobs是用來轉換crontab語法的介面

安裝

1
bower install angular-cron-jobs

載入模組

1
angular.module('myApp', ['angular-cron-jobs']);

用法

  • output:輸出值
  • config:設定值
  • init:初始值
    1
    <cron-selection output="myOutput" config="myConfig" init="serverData"></cron-selection>

設定值

1
2
3
4
5
6
7
$scope.myConfig = {
    options: {
        allowWeek : false,
        allowMonth : false,
        allowYear : false
    }
}

C# 排程套件: Quartz

Quartz 套件

簡介

Quartz是個排程套件

安裝

1
$ install-package Quartz

建立Job

1
2
3
4
5
6
7
8
9
10
11
12
13
14
namespace ConsoleApplication1
{
    using System;
    using Quartz;

    [DisallowConcurrentExecution]
    internal class MyJob : IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            Console.WriteLine("do job");
        }
    }
}

建立排程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
namespace ConsoleApplication1
{
    using Quartz;
    using Quartz.Impl;

    internal class Program
    {
        private static void Main(string[] args)
        {
            // 建立排程器
            var schedulerFactory = new StdSchedulerFactory();
            var schedular = schedulerFactory.GetScheduler();

            // 建立Job
            IJobDetail job = JobBuilder.Create<MyJob>()
                .WithIdentity("MyJob")
                .Build();

            // 建立Trigger
            ITrigger trigger = TriggerBuilder.Create()
                .WithCronSchedule("0 0/1 * * * ?")
                .WithIdentity("MyJobTrigger")
                .Build();

            // Job配對Trigger
            schedular.ScheduleJob(job, trigger);

            // 啟動排程器
            schedular.Start();
        }
    }
}

注意事項

  • 排程是固定周期觸發,和Job的執行時間無關
  • 每次觸發都會重新建立一個全新的Job物件
  • 在Job上加入DisallowConcurrentExecution來限制每次只能執行一個Job

dbup - 資料庫更新工具

dbup是一個用來更新資料庫的工庫,只能往前更新,不能往後回復更新
dbup-consolescripts是用來新增一個年月日時分秒_檔名.sql的套件

新增一個Console專案

透過NuGet新增dbup和db-consolescripts套件

1
2
$ install-package dbup
$ install-package dbup-consolescripts

加入System.Configuration參考

新增連線字串

1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="utf-8" ?>
<configuration>

    <connectionStrings>
        <add name="DBConn" providerName="System.Data.SqlClient"
             connectionString="data source=(localdb)\ATCity;initial catalog=RankingSystem;trusted_connection=true;"/>
    </connectionStrings>
   
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
</configuration>

修改Program.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
namespace SGT.ATCity.RankingSystem.Database
{
    using System;
    using System.Configuration;
    using System.Reflection;
    using DbUp;

    public class Program
    {
        private static int Main(string[] args)
        {
            var connectionString = ConfigurationManager.ConnectionStrings["DBConn"].ConnectionString;
            var upgrader =
                DeployChanges.To
                    .SqlDatabase(connectionString)
                    .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
                    .LogToConsole()
                    .Build();

            var result = upgrader.PerformUpgrade();

            if (!result.Successful)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(result.Error);
                Console.ResetColor();
                return -1;
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Success!");
            Console.ResetColor();
            return 0;
        }
    }
}

新增SQL檔案

  • 透過套件管理器主控台執行New-Migration 名稱, 即可新增一個年月日時分秒_名稱的sql檔案
  • 檔案的順序很重要, 會影響呼叫的執行順序
  • 編輯要更新資料庫的SQL語法

按下F5執行資料庫更新

資料庫更新結果

  • 新增一個SchemaVersions資料表來記錄更新的記錄
  • 相同檔名只會執行一次

透過Application Request Route來做SSL offloading

Application Request Route

越來越多站台要開始使用SSL了, 記錄一下使用Application Request Route來做SSL offloading的用法

首先透過Web Platform Installer來安裝ARR

搜尋Application Request Routing, 找到後點安裝就行了

重新打開IIS會看到新增了Server Farms和ARR和URL Rewrite這幾個功能

先建立一個預設的站台來繫結https通訊協定

只有預設站台是HTTPS, 其他站台都是HTTP

建立一組Server Farms

建立一條路由規則來強制站台只能使用https通訊協定

建立第二條路由規則來處理SSL offloading路由到原來只繫結http的站台

http就會自動轉向https囉

Markdown語法簡介

Markdown語法簡介

標題

<span class="hljs-header"># H1</span>
<span class="hljs-header">## H2</span>
<span class="hljs-header">### H3</span>
<span class="hljs-header">#### H4</span>
<span class="hljs-header">##### H5</span>
<span class="hljs-header">###### H6</span>`</pre>

## 換行與段落
  • 一個換行字元會轉成換行&lt;br /&gt;
  • 兩個換行字元會轉成段落&lt;p&gt;&lt;/p&gt;

    `第一段
    第一行
    第二行

    第二段
    第一行
    第二行`

    字體

    `*斜體*
    **粗體**
    ***粗斜體***
    ~~刪除線~~`

    引言

    `> 用>和一個空白表示
    >> 多個>表示嵌套`

    水平分隔線

    `三個以上的星號、連字號、底線表示
    不能有空白或其他的文字
    ***
    ---
    ___`

    無序清單

    `* 星號加空白
        * 加Tab可嵌套清單
    + 加號也可以
    - 減號也可以`

    有序清單

    `1\. 格式為一個數字加小數點加空白
    2\. 數字本身順序不重要會自動遞增
        1\. 一樣用加Tab可以嵌套`

    超連結

    `* [行內連結](https://www.google.com)
    * [帶標題的行內連結](https://www.google.com "Google WebSite")
    * [參考連結][Google Link]
    [Google Link]: https://www.google.com`

    圖片

    `行內格式:
    ![圖片文字](01.png "圖片Alt")
    
    參考連結格式:
    ![圖片文字][logo]
    [logo]: 01.png "圖片Alt"`

    程式代碼與語法高亮

  • 單行代碼用一個`前後包起來

  • 多行代碼用三個`前後包起來
  • 語法高亮在符號後加入語法的名稱<pre>

    </pre><pre class="prettyprint">Console.WriteLine(“Hello”);`

    表格

    `冒號用來對齊的
    預設為靠左對齊
    放在右邊就是靠右對齊
    左右都放就是靠中對齊

    | 欄位一 | 欄位二 | 欄位三 |
    | ————- |————-:| :—–:|
    | col 3 is | right-aligned | $1600 |
    | col 2 is | centered | $12 |
    | zebra stripes | are neat | $1 |

    表示中要跳脫表格用到的符號,需要用html編碼的方式表示
    空白是&nbsp;
    |是&#124;

安裝gitbook-cli套件

安裝gitbook-cli套件

打開命令視窗

1
$ npm install gitbook-cli -g

到gitbook新增一本書

輸入書名

進入設定頁面

取得git路徑

1
https://git.gitbook.com/{username}/{bookname}.git

取得這本書的原始檔案

1
$ git clone https://git.gitbook.com/{username}/{bookname}.git bookdir

使用Visual Studio Code打開資料夾

在本地端觀看編輯後的結果

1
$ gitbook serve

輸入此次異動的訊息

同步記錄到gitbook

安裝NodeJS

安裝NodeJS

官網下載安裝程式

雙擊安裝程式開始安裝

接受授權條款

選擇安裝路徑

自訂安裝設定(使用預設值即可)

準備安裝

安裝中

安裝完成

安裝 git for windows

安裝Git for Windows

先到官網下載安裝程式

雙擊安裝程式開始安裝

選擇安裝路徑

選擇安裝元件

輸入開始功能表的資料夾名稱

調整環境路徑

設定文件的結尾符號

設定命令列模式

設定快取

開始安裝

安裝完成