背景

最近學了angular 入門實作,想要把之前寫的一個小工具翻成 angular 網站,
當時在製作 GitHub page 的時後卡了很久,
因為之前是用 Visual Studio 2015 Community 開 sln,然後再推上去,
結果資料夾層級讓那個路徑重複了好幾次,後來就放棄沒改了

現在好奇有沒有工具可以幫我簡單把 angular 專案建立到 github page 上
於是找了一下找到了教學文,他是使用angular-cli-ghpages這個套件,
基本上照著做沒有問題

Deploying an Angular App to Github Pages
https://alligator.io/angular/deploying-angular-app-github-pages/

但是要注意 github 最近出了私有模式,而 page 似乎不能給私有專案用(也是合理),
所以要開 public 的 repo。

還有推上去後他會自動建一個 branch 來放這些 build 過的檔案,
若在 ngh 後面接上指定 branch 的參數放上去,他會把舊的檔案都蓋掉,只放 build 後的檔案

實作

1.建立 GitHub repo,記得要是公開的

2.建立 angular 空白專案

1
$ ng new myNewProject

3.將專案的遠端分支登記為 GitHub 的 repo

1
$ git remote add origin <github git url>

4.將 ng 專案建置,並填入根目錄網址為 page 的網址

1
$ ng build --prod --base-href "https://<user-name>.github.io/<repo>/"

5.使用 angular-cli-ghpages 的指令建置 page

1
$ ngh

6.等他建好提示訊息就好啦

問題背景

某個 DB 處理會撈出訂單、訂單明細、品項主檔
訂單明細是訂單的導覽
品項主檔是訂單明細的導覽

想要在 LINQ 撈出來資料時就把相關資料也加進來,避免後面處理時才去連 DB
但是又不能.Include("訂單明細").Include("品項主檔")
不知道怎寫

解答

參考這篇
https://stackoverflow.com/questions/614809/entity-framework-include-navigation-of-another-navigation-property

1
.Include("訂單明細.品項主檔")

這樣就行了

說明

進行 DB schema 更新時使用 database project 的結構描述比較
但按下比較時狀態列出現目標無法使用的錯誤訊息
重開 vs2017 也沒用

解法

參考這裡
https://stackoverflow.com/questions/37463279/sql-schema-comparison-error-target-is-unavailable

將連線字串的帳號名稱格式改為加上伺服器名稱 **username@servername**
就成功了

最近在設定 Azure Function 的定時觸發類型程式的 CRON 運算式
寫好之後不太確定自己寫得到底對不對
研究了一下後有兩個做法

1. 本地偵錯模式
2. 用工具網站https://crontab.guru/

本地偵錯模式

本地執行後 Console 視窗上會寫目前執行中的 Timer Trigger Function 有哪些
以及列出這個 Function 之後會執行的五個時間點給你看,如圖:

crontab guru

網站網址:https://crontab.guru/

Azure Function 的 Timer Trigger 文件部分其實就有寫,時間運算式使用的是NCronTab 這個 LIB 來處理,所以就往「CRON 運算式 確認」的方向去 google,然後就找到這個網站,
雖然他比 Azure 少一層秒數的表達式,但也是可以提供一個參考,
直接把打好的表達式輸入進去,就可以看到你寫的會以怎樣的週期去執行:

不知道有沒有人做給 Azure Function 用的版本,不然還是比較方便


後來找到這個網站,正符合 Azure 的格式
Cron Expression Descriptor

需求描述

因為要做重構,需要找出有哪些邏輯是藏在 DTO 裡面的,
但 DTO 類別檔又很多,不想一個個找
所以就想寫個 console 程式來撈

做法

首先把要撈的 DLL 跟他相依的 DLL 都複製到要執行的排程執行檔輸出資料夾(通常是 bin\debug)

以下程式碼:

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
public class Worker {
public void DoWork () {
System.Reflection.Assembly service = Assembly.LoadFile (@"&lt;你要找的namespace所在的dll的絕對路徑&gt;.dll");
Type[] typelist = service.GetTypes ();
//你的類別名稱的特徵,例如找DTO就結尾是DTO
var nameHaveDtoTypes = typelist.Where (x => x.Name.ToUpper ().EndsWith ("DTO"));
foreach (var typeitem in nameHaveDtoTypes) {
if (typeitem.GetProperties ().Any (prop => !MightBeCouldBeMaybeAutoGeneratedInstanceProperty (prop))) {
//印到畫面跟輸出視窗
foreach (var prop in typeitem.GetProperties ().Where (prop => !MightBeCouldBeMaybeAutoGeneratedInstanceProperty (prop))) {
Console.WriteLine ($"{typeitem.Name},{prop.Name}");
System.Diagnostics.Debug.WriteLine ($"{typeitem.Name},{prop.Name}");
}
}
}
}
public bool MightBeCouldBeMaybeAutoGeneratedInstanceProperty (PropertyInfo info) {
bool mightBe = info.GetGetMethod ().GetCustomAttributes (typeof (CompilerGeneratedAttribute), true).Any ();
if (!mightBe) {
return false;
}
bool maybe = info.DeclaringType
.GetFields (BindingFlags.NonPublic | BindingFlags.Instance)
.Where (f => f.Name.Contains (info.Name))
.Where (f => f.Name.Contains ("BackingField"))
.Where (f => f.GetCustomAttributes (typeof (CompilerGeneratedAttribute), true).Any ())
.Any ();
return maybe;
}
}

參考:
1.LINE 群大神指點關鍵字CompilerGeneratedAttribute
這個是指在編譯成 DLL 時,單純 getter setter 的屬性上面會有這個 tag
https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.compilergeneratedattribute.aspx

2.How to find out if a property is an auto-implemented property with reflection?
https://stackoverflow.com/questions/2210309/how-to-find-out-if-a-property-is-an-auto-implemented-property-with-reflection?lq=1

最近版控系統完全轉到 git,但新手上路,很多指令還不是很熟,
所以寫一篇筆記方便查找

git clone &lt;target&gt; [&lt;folder name&gt;]
抓下目標到本地(執行位置),可指定新資料夾名稱

git add .
加入目前所有檔案到暫存變更

git commit [-m &lt;message&gt;]
簽入暫存變更帶上簽入訊息

git merge &lt;branch name&gt; --no-ff&nbsp;
做 merge 但不會 fast forword

git log --oneline --graph [-(數字)]
印出線圖 數字可限制印出幾個簽入內的

情境

一個 Grid,裡面的 row 是 template,
按鈕除了編輯刪除,其他按鈕案出來的視窗也是 template,
在 template 裡面還有套 template,然後都是 MVVM 去設定事件,
在最尾端的一個表單,要做表單驗證,
有一個欄位是 radio button,多選一,當選到某值時另一文字輸入框欄位就變必填

問題

如何在 MVVM 的 model 中套用這個特定的 required 驗證

解題過程

我原本找到去擴充 model binding 的 binder 方法的方向
https://stackoverflow.com/questions/15945755/set-tag-attribute-based-on-variable-value-with-kendo-binding/15947852#15947852
但他要做一個 html 元件的跟一個 widget 的,名字還有邏輯,沒搞太懂;

後來轉向套用 validator 在表單上,雖然不太 MVVM,但是可解的方法,
可是這個必填欄位不知為何在執行驗證時會跳
n[t].call is not a function
錯誤,後來發現 不能把 validator 用的物件放在你的 MVVM ViewModel
他在執行遍歷驗證時會抓到 observable 的一些屬性但無法辨識(例如_events)然後就跳那個錯誤,
我本來以為 MVVM 就是你用到的東西都塞 MODEL 裡就對了,不過這個情境應該不是這樣放…
再來是自訂驗證規則名稱的雷,
我原本取名PayAccountRequired,結果竟然讓 input 不是 required 也套上 required 屬性,整個鬼打牆找了很久,後來把規則名稱改成PayAccountRule,竟然就正常了….

從來沒想到這個驗證會讓我卡好幾個小時….

完成的範例
http://jsfiddle.net/o8ym26jj/2/

情境:
本來寫好一個上傳檔案功能,在本機開發的時候有設定虛擬路徑,檔案在
%USERPROFILE%\documents\IISExpress\config\applicationHost.config
結果最近在側的時候發現怎麼 metadata 都抓不到了,明明沒有改東西

解法
後來 debug 了半天發現我的檔案存放路徑不對,
就覺得是虛擬路徑失效的問題,又繼續查,
發現,其實因為中間我的 IDE 從 vs 2013 換到 vs2015,
結果 vs2015 好像有個問題就是他不吃上面路徑的設定擋了,
新的設定檔在專案資料夾內的.vs資料夾(是隱藏資料夾)裡的applicationHost.config
在同樣的區段去新增虛擬路徑就好了

REF: https://forums.asp.net/t/2067764.aspx?VS2015+IIS+Express+cannot+create+virtual+directories

背景

同事在寫的應用:一個 GRID 裡面有子 GRID
資料在展開 master row 時才會去抓
但不知道怎麼抓

#解法
我第一個想法是在 master grid 展開前先記住外面 row 的 uid,
再用 uid 反推 index,再用 index 去抓到 row,再抓到裡面的 grid,但很麻煩;

他研究很久後發現在 master grid 的 detailInit 事件做 detail grid 宣告,
detail grid 裡的 databound 事件
可以用

1
$(this.element[0]).data('kendoGrid');

來抓到裡面的 grid,簡單明瞭

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
SELECT
c.name '欄位名稱',
ep.value AS '欄位備註',
t.Name '欄位型態',
c.max_length '最大byte',
c.precision '總位數',
c.scale '小數位數',
c.is_nullable '是否可為空',
ISNULL(i.is_primary_key, 0) '是否是PK'
FROM
sys.columns c
INNER JOIN
sys.types t ON c.user_type_id = t.user_type_id
INNER JOIN sys.objects ON sys.objects.object_id = c.object_id
LEFT OUTER JOIN
sys.index_columns ic ON ic.object_id = c.object_id AND ic.column_id = c.column_id
LEFT OUTER JOIN
sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id
OUTER APPLY fn_listextendedproperty(default,
'SCHEMA', schema_name(sys.objects.schema_id),
'TABLE', sys.objects.name, 'COLUMN', c.name) ep
WHERE
c.object_id = OBJECT_ID('your table name')

ref:
https://stackoverflow.com/questions/2418527/sql-server-query-to-get-the-list-of-columns-in-a-table-along-with-data-types-no
https://devio.wordpress.com/2009/08/19/retrieving-table-and-column-descriptions-in-sql-server/

0%