2016年12月28日 星期三

.Net Core HttpClient GetAsAsync執行時過慢問題

參考文章: HttpClient.GetAsync is slow in dnxcore50 compared to dnx461

MVC 5就用過 HttpClient,一切正常,但在開發 Line Bot時用 HttpClient呼叫已經在服務的 API時就發生斷片問題,但也不是常常發生,本來以為是我程式寫法的問題,後來追蹤時發現會一直卡在 GetAsAsync,所以上網也找到相關文章,其建議是在產生 HttpClient時先新增一個 HttpClientHandler並把其 attribute UseProxy設為 false, 這樣應該可以改善速度的問題,改寫之後果然不會再發生過慢的問題了。

2016年12月26日 星期一

Use Line Bot to search extensions and MVPN numbers of the enterprise

Last time I shared my first Line Bot 使用 ASP.Net Core Web API 實作 Line Bot webhook callback. It is a funny bot to show what kind of person is by entering a name. if you enter a name "Catton", it would answer "He is a handsome man."

Because of first bot, it gave me a inspiration to develop another Lin Bot that could facilitate to contact  other colleagues easily. Especially for the enterprise that already has implemention of MVPN.

First of all, here is the wiki to introduce what is MVPN, Mobile virtual private network.  You can dial a short number, maybe 5 or 4 digits, to communicate the colleague whose mobile phone is in your enterprise MVPN group.

Inside the enterprise, I can build a web to search someone's extension or MVPN number by entering name, employee number or department name. Here is the screenshot of web-searching.




















2016年12月18日 星期日

使用 asp.net core實作一個類 google blog的網站



 

之前有分享過 試作 CKEditor 圖片選擇器 ( image upload ),利用 ckeditor和客制 image picker
來達成圖片選取,但是圖片的處理、儲存還沒實作完成,最近剛好寫完預算系統,所以利用空檔來繼續完成這個部份,完成工作內容如下:

2016年12月7日 星期三

ASP.NET Core Render View to String in Controller

參考文章:
ASP.NET Core Render View to String
Render a Razor View containing a URL to a string in ASP.NET Core

這個目的是直接在 controller直接產生 partial view的字串再回傳至 view ajax result,然後直接把某個 element換掉或作內文休改,這種方式當然也有其它的方式達成,但直接在 contorller內產生 view string也是可以試試,因為在 Asp.net MVC 5也有類似的作法或是直接使用 westwind的 library。但在 Asp.net Core就不能直接拿來用。所以參考上面的分享文章就可以達到目的了。

AntiXss Library for Asp.Net Core

之前在 Asp.Net MVC 5時會使用 微軟的 AntiXSS Library
而在 Core專案的 Library,我有找到一個叫 SmallCode.AspNetCore.AntiXSS
這個 library不只在 controller內使用 HtmlFilter.Instance.SanitizeHtml 方法還在 view有提供 tag helper @Html.Sanitized可以使用。 如果需要的話可以使用 nuget下載使用。

2016年11月22日 星期二

Asp.Net Core MVC Paging使用了 cloudscribe.Web.Pagination

之前開發 MVC 5專案參考了 ASP.NET MVC 資料分頁 MVCPaging 2.0 應用分享文章,使用了 MVCPaging開發分頁需要的程式,但到 Core之後 MVCPaing官網建議要使用   cloudscribe.Web.Pagination library。

使用 Nuget安裝後要先設定
Startup.cs 要加上 services.AddCloudscribePagination();
_ViewImports.cshtml 要加上@addTagHelper "*, cloudscribe.Web.Pagination"

程式是最大的改變應該是在 View的部份,原本在顯示 page info的部份改寫如下:

<cs-pager asp-action="Index" asp-controller="Paging" 
     cs-pagenumber-param="page" 
     cs-paging-pagenumber="@Model.PageNumber" 
     cs-paging-pagesize="@Model.PageSize" 
     cs-paging-totalitems="@Model.TotalItemCount">
</cs-pager>

測試後的結果應該是沒問題,後續還是要測試每個 tag attribute




2016年11月21日 星期一

Connect(); // 2016


Connect(); // 2016

Xamarin.Forms有 Previewer了

分享文章:Live XAML Previewing with the Xamarin.Forms Previewer官方 Xamarin.Forms Previewer

在今天 10月參加 Microsoft Tech Summit 台北場次,第二天有幾場是關於 Xamarin,我就參加其中的一場 (An Overview of the Microsoft Application Platform for Developers),講師有介紹目前開發 Xamarin專案可以有兩種選擇方式一種就是 Xamarin.Forms,另一種是  Platform-specific,Xamarin.Forms Guides的 Is Xamarin.Forms right for your project?小節上有建議。

那場演講上有提供 platform-specific的專案是可以有 GUI工具可以拉元件進行設計,但 Xamarin.Form的方式就沒有,所以會後就問講師 David Carmona Xamarin Forms是否未來也會有 GUI的設計方式,他的回答說應該會有吧,不過不知道那時會出現,想不到今天就看到這篇文章,我只能說除了 Docker之外,愈來愈愛 C#了。

開啟 previewer: View(檢視) - Other windows(其它視窗) - Xamarin.Forms Previewer

2016年11月10日 星期四

再見了 Web.config,Asp.Net Core使用了 appsettings.json

官網:Asp.Net Core Configuration

其它連結:
The New Configuration Model in ASP.NET Core
No ConfigurationManager in ASP.NET Core

長久以來,不管是 Asp.Net MVC或是 Form的開發,一定要使用到 Web.config,而在程式碼內就會使用到 ConfigurationManager來取得資料庫連線字串 (ConnectionStrings)或是自定變數,但是在 Core已經不採用這樣的方式了,所以要參考上面的文章,要自訂類別,在 startup.cs內來儲存 appsettings.json的變數,而在 controller才可以利用系統 DI方式取得想要的設定值,雖然一開始可能不太適應,但萬事起頭難,用久就會習慣了。

2016年9月29日 星期四

Kafka Docker Images

目前有在 docker hub找到兩個 images都可以在 docker machine和 CentOS7上實作成功。

一個為 spotify/docker-kafka,這個把 zookeeper和 kafka整合在一個 images內,測試應該最適合測試或資料量不大使用。    另一個為 wurstmeister/kafka-docker,這一個是把 zookeeper和 kafka分開在不同的 image, 使用 docker compose並建立獨立的 Networking,可以建立多個 brokers,應該適合正式區上使用。


2016年8月2日 星期二

我的第 3個 Asp.Net Core Docker Image - 實作 Docker 1.12 Swarn Mode

利用 我的第二個 Asp.Net Core Docker Image 使用 SVN + Jenkins 的方式,首先先建立一個 docker machine, 再依據 Docker Conference Day 1的影片來實作 Docker Swarm Service Manager and Worker,一下子就成功了,非常容易、非常快速、簡單。大家可以試試。


2016年7月21日 星期四

我的第 2個 Asp.Net Core Docker Image 使用 SVN + Jenkins


 using docker

在 第一個 Asp.Net Core Docker Image的分享有用 Docker Tools for Visual Studio 2015 - Preview產生 Docker Image,但我想要作一點不一樣的事,目的很簡單,就是希望可以程式更新完之後,就可以完成自動產生 Docker image和建立 container,完成相關佈署。

依據這一本書的建議,利用 Jenkins來達到我想要的目的。相關的實作目前已完成第一步自動產生 docker file,再來就是要作實作建立 container的部份囉,等實作成功再來分享我的步驟。

真的不得不說, Docker是天上給予我最好的禮物了~~~

2016年7月7日 星期四

我的第 1個 Asp.Net Core Docker Image

解決了安裝  Docker Tools for Visual Studio 2015 - Preview的問題後,馬上把我的專案放到 docker,我採取的方式是在自己電腦上,所以本機要裝 docker toolbox,windows 10的用戶可以直接裝 docker for windows的版本,我參考的文件如下:

偵錯本機 Docker 容器中的應用程式
把 ASP.NET Core 應用程式裝進 Docker 裡 – 使用 Docker Tools for Visual Studio 2015

如果沒有 powershell的話,要先裝 Windows Management Framework
如果你跟我一樣使用 docker toolbox的話要先把一個 docker machine virtualbox VM先 start, ,而且在專案檔案 \Properties\Docker.props上給定 DockerMachineName的值才行

這樣應該就可以了~~~~





2016年7月5日 星期二

ASP.NET Core 1.0 所碰到的問題

Announcing ASP.NET Core 1.0 6/27正式版出爐,因為之前 preview 2的版本在執行時, 載入javascript file時會一直出現 502 bad gateway的訊息,但在 MVC 5就不會出現這種情況,所以就試試安裝正式版的 Core 1.0 。

首先要先更新 VS 2015至  update 3的版本,才可以下載 .NET Core 1.0 for Visual Studio

安裝完之後,之前開發 Core的方案建議重新建立新的。執行後也就沒什麼問題了。
但是發現一個 Nuget元件  RouteJs 執行時出現錯誤(但在 preview 2是正常的),
一個 tool  Docker Tools for Visual Studio 2015 - Preview無法安裝成功 ,

目前正在努力上網找答案中~~~~

2016.07.07 Docker Tools for Visual Studio 2015 - Preview可以安裝成功,只要先安裝 Windows Management Framework 即可。



2016年6月24日 星期五

ASP.NET Core ASP.Net 5 Tutorial for Beginners

Asp.net 5 介紹,入學者可以從這邊開始,跟 MVC 5有很大的不同。一切都要重頭開始囉~~


2016年6月3日 星期五

文章分享 2015’s Top & Best HTML5 Animation Tools For Designers

文章來源:2015’s Top & Best HTML5 Animation Tools For Designers

如果只要作出簡單的 banner or gif  可以用 html5maker

如果要有像以前作 flash所使用的 flash professional作出一個比較有變化的動作可以使用如下工具

Online
Animatron

本機程式
radiapp (目前只支援 Mac OS)
Google Web Designer
Hippo Studios


2016年4月21日 星期四

mongoDB .Net Driver 使用 MapReduce

目前有一個需求,在 mongoDB的一個 collection,有一個屬性 created_date記錄資料建立時的日期,我希望利用這個屬性,以30天為一個單位找出每個間隔日期,在關連式資料庫會使用如下 SQL來完成需求:

SELECT CONVERT(varchar(10), DATEADD(d, (datediff(d,GETDATE(),created_date) /30)*30,GETDATE()),111)
 FROM [DATA].[dbo].[expense]
 group by CONVERT(varchar(10), DATEADD(d, (datediff(d,GETDATE(),created_date) /30)*30,GETDATE()),111)

這樣捉出來的資料如下:
2015/12/23
2015/10/24
2015/11/23

而我的專案是 ASP.Net MVC 5,所以有使用 mongoDB .Net Driver 2.2,一開始利用 LINQ寫法如下:
 var query = fRepo.GetAll().GroupBy(x =>
             DateTime.Now.AddDays(((int)(DateTime.Now.Subtract(DateTime.ParseExact(x.Date, "yyyy/MM/dd", System.Globalization.CultureInfo.InvariantCulture)).TotalDays) / Day30) * (-1 * Day30)).ToString("yyyy/MM/dd")
      
           ).Select(x => new DayPeriod { date1 =x.Key) }).OrderBy(x => x);

2016年3月31日 星期四

Docker for Mac and Windows Beta

文章來源:Docker for Mac and Windows Beta: the simplest way to use Docker on your laptop

之前在 windows上是使用 docker toolbox安裝 docker machine,再產生 virtualbox的 docker machine vm,以後就不用囉,有興趣的朋友可以試試

2016年3月11日 星期五

Java script chart

參考文章:15 JavaScript Libraries for Creating Beautiful Charts

這篇文章可以找到很多 chart元件可以使用,但有一些是沒有圖的物件,是要再額外再引用其它 library才可以。有的元件並非完全免費,有商業的版本,我測試後的分享如下:

ChartJS 目前專案有在使用,免費,目前版本 1.0.2,直接好用(但我更懷念那時開發 Flex程式就有內建的 Chart,那才是好用),今年應該會出 V2的版本

Chartist 還沒使用過,應該也是免費,但官網的 demo還不錯,可以試試

Google Chart 應該很多人在用,直接引用網路上的 library即可

Highcharts 商業用途必需收費,動畫方面表現好

Fusioncharts 商業用途也是要收費,使用免費版會有浮水印

Amcharts 有免費版但畫面都會出現官網連結,圖很多可以試試

CanvasJS 商業用途也是要收費,強調速度快

Angular-FusionCharts Angular + Funcsioncharts,有使用 Angular可以直接試試

2016年3月1日 星期二

Docker Cloud 發表

新聞連結:Announcing Docker Cloud
文件:Docker Cloud Documentation
入口: cloud.docker.com
論壇:forums docker cloud
先來測試吧~~~


.Net MongoDB Driver 學習文件

.NET MongoDB Driver Documentation (2.2),有在用 C#和 MongoDB開發相關系統的,這邊可以找到如何用 LINQ和其它技巧加速你的開發

MongoDB 管理工具

MongoDB Integration and Tools Admin UIs  , 2016 Best MongoDB GUI 這邊有介紹多個管理工具,第三方的大部份都是用 Node.js寫的,目前我只用過 NoSQL Manager for MongoDB試用版,因為它是 windows的,裝了就可以用,跟你使用 PL/SQL Developer連 Oracle DB是差不多的。如果不想直接下指令的可以參考看看,當然還有更強大的功能可以管你的 mongoDBs.

2016 Best MongoDB GUI

2016年2月4日 星期四

Docker Machine安裝 Redmine 後使用上的問題

原本使用 Docker Machine建一個 RancherOS 4.1的 VM,然後在 VM上再使用 docker建立 Redmine,參考如下:sameersbn/docker-redmine,之前安裝 MongoDB, ODOO也沒有發生過這樣的情況。

在安裝時都沒有任何問題,一開始也可以正常使用直到我把 docker machine作 stop再 start就無法開啟了,使用 docker logs就會看到 verify_gemfile_dependencies_are_found!': Could not find gem 'rails (= 4.2.0) ruby' in the gems..........的訊息。 參考 docker-redmine/issues/91

就算換了較舊的版本也是這樣,最後的作法就是放棄 Docker Machine的方式,直接建立一個 CentOS 7的 VM(install instruction),再安裝 Docker後,再利用 Docker安裝 Redmine就正常了,關掉 VM再重啟也不會發生開啟失敗的問題了。