2016年1月11日星期一
用 Synology 的 Docker 運行 ASP.NET 5 試行 Simple WebSocket.
在家都有隻 Synology 的 NAS. 知道 DSM 可運行 Docker 就當然要試一下.
輕鬆地從 Package Manager 找 Docker 就可以.
安裝後就可以從 Docker Hub 找 "aspnet" 就找到 Microsoft/aspnet
輕鬆地從 Package Manager 找 Docker 就可以.
安裝時選擇所需的版本. 我選用了 1.0.0-rc1-update1.
當下載後, 就可以係 Image 中找到已下載的 Image.
這裡可以選 Launch with Wizard.
Step 1: Container Name 同加一個 Port. 主要將 NAS 的 Port 指到 Container 的 Port.
Step 2: Default 就可以.
Step 3: 這裡需要 Advanced Settings 主要將一個 Folder 指入 Container. 用作將要放的 ASP.NET Web 放到 Container 中, 如下.
完成後就可以開始這個 Container.
進入 Home Folder (我將 Project Files 指到 Home)
運行一次 dnu restore (Restore 所需的套件)後, 就可以 dnx web 去運行.
但我沒有加入相關的 config. 這裡直接加入 Options.
dnx web --server.urls http://0.0.0.0:5000 預設是 localhost:5000. 外部不能連入. 所以改成 0.0.0.0:5000
這樣就可以直接連入 NAS 的 50080 Port. 之前 Step 1 指定的. 同樣可以運行這個簡單的 WebSocket.
2016年1月10日星期日
簡單試作 ASP.NET 5 RC1 WebSocket
基本上都己經更新了 Visual Studio 2015, 更新到最新 Stable 版的 DNX.
新開一個 ASP.NET 5 Project.
主要用的的套件是: "Microsoft.AspNet.WebSockets.Server": "1.0.0-rc1-final"
當加入 Microsoft.AspNet.WebSockets.Server 就可以在 Startup.cs 用 app.UseWebSockets();
因為只是單純測試 WebSocket 所以都在 Startup 直接制作一個 Echo WebSocket.
以上的 Simple 沒有處理多個封包的合併, 同時也沒有處理回應的實際應有的長度, 所以回應會是 1024 Bytes.
加入頁面用作 WebSocket Client 測試.
簡單幾句 new WebSocket(); Handle "onmessage". 再用 websocket.send("Message") 就可以.
再用 Debugger 就可以看到來回的訊息.
從此可以見 Browser 送出的 5 Bytes Message, 回來因沒有正確 Create ArraySegment 所以看到 1024 Bytes.
加入正確的 ArraySegment Size 如下, 在回覆前創建一個新的 ArraySegment.
再從 Debugger 查看.
可以看見來回都是 5 Bytes.
2015年11月5日星期四
Copy-VMFile (Copy file from Host to Virtual Machine)
剛剛在 Compile 緊 Linux Kernel 4.3 才發現原來 HyperV Tools 已經有 hv_fcopy_daemon. 這個 Daemon 就是可以支援由 Host 找 File 到 Guest. 當然都要 Enable Guest Services.
簡單一句 PowerShell
Copy-VMFile "VM NAME" -SourcePath "[FILE PATH]" -DestinationPath "[DEST PATH]" -FileSource Host
這樣比以前方便許多, 以往都只是用 FTP / SFTP 等方法抄去 VM.
2015年10月2日星期五
2015年9月12日星期六
2015年8月27日星期四
初試用 OpenSCAD 劃 ActionCam 3D 架.
之前劃 3D Model 去印都係用 Sketchup 劃, 近兩日才認識這個 OpenSCAD http://www.openscad.org/ 加上想做個 ActionCAM 立體拍片架, 所以就小試牛刀.
相比用 Sketchup. 寫 Script 對我來說相對容易同好玩.
這種做法是參考網上的 GoPro 3D.
OpenSCAD File:
相比用 Sketchup. 寫 Script 對我來說相對容易同好玩.
OpenSCAD Model
這種做法是參考網上的 GoPro 3D.
OpenSCAD File:
module sjcambase() {
difference() {
cube([70,52,30]);
translate([5,5,5]) {
linear_extrude(26) {
square([60,42]);
}
}
translate([10+11,15+5+11,-1]) {
linear_extrude(7) {
circle(d=22);
}
}
translate([6+5+43,6+5+23,-1]) {
linear_extrude(7) {
circle(d=12);
}
}
translate([8 + 5 + 40,5+42+5+1,8+5 + 6]) {
rotate([90,0,0]) {
linear_extrude(7) {
circle(d=16);
}
}
}
translate([5+60-1,5,5+13]) {
cube([3,42, 8]);
}
}
}
difference() {
union() {
translate([70,52+(42-15-11-5-1),0]) {
rotate([0,0,180]) {
sjcambase();
}
}
translate([65,0,0]) {
sjcambase();
}
}
translate([65-1,11+4,5]) {
cube([7,42-10, 26]);
}
}
以上謹對應我手上的 ActionCAM. 別的 Action CAM 有需要修改大少及按鈕位置.
2013年3月25日星期一
試用 Expression 於執得時生產 Function
大部份時間只會用 LINQ Expression 去進行 Data Query. 今日試下用 Expression 去生產 Function.
下面係今日試制的代碼:
public void Test()
{
var Param1 = Expression.Parameter(typeof(String), "a");
var Method1 = typeof(String).GetMethod("Trim", new Type[] { });
var CallMethod1 = Expression.Call(Param1, Method1);
Expression> Ex;
Ex = Expression.Lambda>(CallMethod1, Param1);
String Msg = " ABC ";
String Result = Ex.Compile().Invoke(Msg);
}
以上代碼會產生一句類似 a=>a.Trim() 的 LINQ Expression 再 Compile 成 Function
Msg = "ABC"
Result = "ABC";
var Param1.... 創建一個 LINQ Parameter "a"
var Method1.... 用 Reflection 去找找 String 的 Trim() Method.
var CallMethod1.... 創建 LINQ Expression 的 Body "a.Trim()"
Ex = Expression.Lambda..... 用 Parameter "a" 同 a.Trim() 建立 LINQ Expression "a=>a.Trim()"
最後 Ex.Compile() 就會成 Func 而非 Expression>.
Invoke 一次就可以將 Msg 進行 Trim() 的動作.
這裡可以用 Func 這個 Type 去記住動態生產出來的 Function 不用次次進行 Compile.
當然我會更懶地用 Dynamic Language Runtime 進行以下動作.
dynamic MethodObj = new ExpandoObject();
MethodObj.CustomMethod1 = Ex.Compile();
String Result = MethodObj.CustomMethod1(Msg);
這樣就可以直接調用 MethodObj 的 CustomMethod1 就進行 Trim 的動作.
當然 Trim 又可需要這麼煩的動作. 這只是一個最簡單運用 Expression 進行生產代碼的方法.
下面係今日試制的代碼:
public void Test()
{
var Param1 = Expression.Parameter(typeof(String), "a");
var Method1 = typeof(String).GetMethod("Trim", new Type[] { });
var CallMethod1 = Expression.Call(Param1, Method1);
Expression
Ex = Expression.Lambda
String Msg = " ABC ";
String Result = Ex.Compile().Invoke(Msg);
}
以上代碼會產生一句類似 a=>a.Trim() 的 LINQ Expression 再 Compile 成 Function
Msg = "
Result = "ABC";
var Param1.... 創建一個 LINQ Parameter "a"
var Method1.... 用 Reflection 去找找 String 的 Trim() Method.
var CallMethod1.... 創建 LINQ Expression 的 Body "a.Trim()"
Ex = Expression.Lambda..... 用 Parameter "a" 同 a.Trim() 建立 LINQ Expression "a=>a.Trim()"
最後 Ex.Compile() 就會成 Func
Invoke 一次就可以將 Msg 進行 Trim() 的動作.
這裡可以用 Func
當然我會更懶地用 Dynamic Language Runtime 進行以下動作.
dynamic MethodObj = new ExpandoObject();
MethodObj.CustomMethod1 = Ex.Compile();
String Result = MethodObj.CustomMethod1(Msg);
這樣就可以直接調用 MethodObj 的 CustomMethod1 就進行 Trim 的動作.
當然 Trim 又可需要這麼煩的動作. 這只是一個最簡單運用 Expression 進行生產代碼的方法.
訂閱:
文章 (Atom)






















