2015年12月30日 星期三

[VS/TFS] 連接TFS出現無法切換伺服器,忙碌中訊息/unable to switch server at this time, team explorer is busy

說明:
使用VS 2008安裝Team Explorer 2008與向上相容TFS 2010套件連接TFS 2010,在新增伺服器時,輸入TFS URL後,出現該錯誤訊息。


解法:
將輸入的URL最後的反斜線拿掉即可。例:http://[ServerName]:8080/tfs/,移除/
因為Team Explorer 2008比較舊,無法處理/,造成無法連線。
可參閱[1]:
Warning:  Although the Admin Console displays the URL with a final slash, "/", the older clients do not take handle the slash and will not connect.
It is possible to connect to the default Team Project Collection by providing the server name only. This method is limited, as it only allows connection to one of the Team Project Collections in a TFS Instance.


參考資料:
  1. http://blogs.msdn.com/b/team_foundation/archive/2010/04/13/compat-matrix-for-2010-rtm-team-foundation-server-to-team-explorer-2008-and-2005.aspx
  2. https://social.msdn.microsoft.com/Forums/zh-TW/7b912531-efee-470e-bcd1-0a3d44b814b5/unable-to-switch-servers-at-this-time-team-explorer-is-busy?forum=tfssetup
  3. http://blogs.msdn.com/b/jasonba/archive/2009/08/10/how-to-connect-to-a-tfs-2010-server-from-a-2008-team-explorer-client.aspx


[.NET/IIS] runtime修改ASP.NET專案的web.config,對request與session的影響?

說明:在Server上修改web.config或更改bin下的dll檔,對於request與session會有什麼影響?


參考如下:
會起新的Application Domain,Application Pool不動(working process不變)。

● app domain在卸除前,會處理完佇列中的request,新的request由新的app domain起來處理。
● in-process session會不見,因此建議將session存放於out-of-process,如session state server或DB。


參考資料:
https://blogs.msdn.microsoft.com/tess/2006/08/02/asp-net-case-study-lost-session-variables-and-appdomain-recycles/
http://huan-lin.blogspot.com/2010/11/app-pool-vs-app-domain.html
http://stackoverflow.com/questions/27705527/does-editing-a-web-config-file-trigger-an-overlapping-recycle-or-a-startstop-of


2015年11月26日 星期四

[.NET] VS錯誤訊息出現「重試次數超過10次。作業失敗。」、「由於另一個處理序正在使用檔案,所以無法存取該檔案」

說明:
使用VS 2010建置專案出現:
無法將 "obj\x86\Debug\xxx.exe" 複製到 "bin\Debug\xxx.exe"。
重試次數超過 10 次。作業失敗。
無法將檔案 "obj\x86\Debug\xxx.exe" 複製到 "bin\Debug\xxx.exe"。
由於另一個處理序正在使用檔案 'bin\Debug\xxx.exe',所以無法存取該檔案。


做法:
這是因為xxx.exe正在process中,將該開啓的程式關掉與關閉工作管理員-處理程序中的process,若還是不行,先清除專案再至Debug目錄下,將xxx.exe刪除再建置。

2015年11月11日 星期三

[.NET] Release建置卻無出現參考的dll檔

說明:使用VS 2010(.NET Framework 4.0),建置程式後,發現參考的dll沒進到Release資料夾內?


原因:因VS 2010加入參考多了內嵌Interop型別,預設為True,導致複製到本機變為False,因此無輸出dll至Release資料夾內,發行時造成某些功能無法正常運作。將內嵌Interop型別改回False,複製到本機即連動為True,重新建置即可。



2015年9月23日 星期三

[Mqtt broker] ssl3_read_bytes tlsv1 alert unknown ca

說明:使用mosquitto_sub指令想subscribe主題,Mosquitto broker卻出現ssl3_read_bytes tlsv1 alert unknown ca的錯誤訊息。


解法:
因產生CA憑證時的Organization Name與產生Server csr (certificate signing request)時的Organization Name輸入一樣,加上在localhost,可能導致衝突或無法辨識,將:
  • 產生CA憑證時的Organization Name修正為MqttCA,
  • 產生Server csr時的Organization Name修正為MqttServer即可。




[Mqtt broker] Mosquitto broker出現OpenSSL Error: SSL routines:SSL3_GET_RECORD:wrong version number

說明:使用Mosquitto_sub指令subscribe主題時,Mosquitto broker出現OpenSSL Error: SSL routines:SSL3_GET_RECORD:wrong version number訊息。


參考解法:
使用mosquitto_sub並使用TLS/SSL加密,漏掉--tls-version tlsv1或--cafile CA憑證路徑。

[Mqtt broker] 出現Unable to load server certificate. Check certfile.

說明:啟動Mosquitto broker出現Error: Unable to load server certificate "C:\OpenSSL-Win64\bin\PEM\srv.crt". Check certfile.


可能解法:
1. 產出broker憑證時,沒輸入最後的pass phrase。
2. 啟動broker時,輸入的pass phrase有誤。

2015年9月9日 星期三

[Mqtt broker] 使用Mosquitto broker出現遺失pthreadVC2.dll或SSLEAY32.dll的解法

說明:安裝完mosquitto broker後,執行mosquitto.exe想啟動Mqtt broker卻出現遺失SSLEAY32.dll,要重新安裝程式的對話視窗。或執行mosquitto_sub.exe想訂閱訊息,
也出現遺失pthreadVC2.dll的對話視窗。


解法:
原來在安裝mosquitto時,就有提示了。
下載Win32 OpenSSL vX.X.X Light安裝後,到安裝folder下複製ssleay32.dll到mosquitto的folder。而pthreadVC2.dll下載後一樣放至mosquitto的folder下即可。

















參考資料:
http://stackoverflow.com/questions/6534505/how-to-fix-libeay32-dll-was-not-found-error
http://guang.logdown.com/posts/235550-mqtt-mosquitto-teaching
https://slproweb.com/products/Win32OpenSSL.html
ftp://sources.redhat.com/pub/pthreads-win32/dll-latest/dll/x86/

2015年7月24日 星期五

[T-SQL] 互相轉換TimeStamp yyyyMMddhh24mmss與datetime做日期操作

說明:
1. 如何將yyyyMMddhh24mmss的字串在T-SQL中轉型為DateTime格式?
2. 如何將DateTime格式轉為yyyyMMddhh24mmss?

做法:
1. SELECT CAST(SUBSTRING(timestamp, 1, 8)+' '+SUBSTRING(timestamp, 9, 2)+':'+SUBSTRING(timestamp, 11, 2)+':'+SUBSTRING(timestamp, 13, 2) AS datetime)

轉型為DateTime後,即可使用DateAdd函式做處理,例:
DateAdd(hour, -2, datetime)

2. SELECT CONVERT(varchar(20), GETDATE(), 112) + REPLACE(CONVERT(varchar(8), GETDATE(), 108),':','');


參考資料:
https://jerry2yang.wordpress.com/2012/07/04/sql-%E5%AD%97%E4%B8%B2%E6%A8%A3%E5%BC%8F%E8%BD%89%E6%8F%9B%E7%82%BA%E6%97%A5%E6%9C%9F%E6%A0%BC%E5%BC%8F/
https://msdn.microsoft.com/zh-tw/library/ms186819(v=sql.120).aspx

[C#] 使用LINQ操作DataTable撈出Top N資料

說明:
使用LINQ找出DataTable內依欄位值最大的N筆資料


做法:
var TopN = (from row in dt.AsEnumerable() select row).OrderByDescending(x => x.Field<string>("Column")).Take(N);



參考資料:
http://stackoverflow.com/questions/5344805/linq-orderby-descending-query
http://www.dotblogs.com.tw/yc421206/archive/2014/07/14/145944.aspx
https://msdn.microsoft.com/zh-tw/library/bb552415(v=vs.110).aspx
http://stackoverflow.com/questions/10855/linq-query-on-a-datatable

[T-SQL] 如何產出0~0.9之間的亂數

說明:
如何產出0~0.9(小數位數1位)之間的亂數。


語法:
SELECT CAST(CAST(NEWID() AS binary(1))%10 AS float)/10

其中NEWID()會產生GUID(32個16進位),將之轉型為1 byte,因此值會在0-255之間,
mod 10後,值會在0-9之間,再除以10,值就會跑在0-0.9之間。


參考資料:
https://msdn.microsoft.com/zh-tw/library/ms190348(v=sql.120).aspx
http://caryhsu.blogspot.tw/2012/08/rand.html

2015年6月4日 星期四

[IOS/Swift] how to post data to RESTful WebService?

說明:
如何透過RESTful WebService來更新後台的資料?


語法:
var strURL = WS URL;
var request = NSMutableURLRequest(URL: NSURL(string: strURL));
request.HTTPMethod = "POST";
        
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) { (response, data, error) in
            
    if (response != nil)
    {
        var strResponse = NSString(data: data, encoding: NSUTF8StringEncoding);
        //replace the '\' of strResponse
        print(strResponse.stringByReplacingOccurrencesOfString("\"", withString: ""));
    }
}

2015年6月3日 星期三

[C#/Excel PIA] Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 8000401a The server process could not be started because the configured identity is incorrect. Check the username and password.

說明:
使用Excel PIA寫schedule job產出Excel,程式放在64 bits server上,執行出現該錯誤。


解法:
出現此錯誤,主要是COM元件的存取帳戶被設為Interactive,
因此程式執行時,需要有帳戶登入該server。看過網路上的解法,
打開Administrative Tools下的component service -> Computers -> DCOM Config,
找到Microsoft Excel Application或{00024500-0000-0000-C000-000000000046},
右鍵Properties,找到Security tab或identity tab,將帳戶加進去,
但我找不到Excel Application,試過在command line下mmc comexp.msc /32等方法,還是沒顯示,最後是在登錄檔,HKEY_CLASSES_ROOT\AppID\{00020812-0000-0000-C000-000000000046},將某個屬性值的Interactive改掉即可。


參考資料:
https://ovaismehboob.wordpress.com/2013/07/06/production-deployment-issues-when-asp-net-web-application-access-com-component/
http://blogs.technet.com/b/the_microsoft_excel_support_team_blog/archive/2012/11/12/microsoft-excel-does-not-appear-in-dcom-configuration-snap-in.aspx
https://msdn.microsoft.com/en-us/library/ms678426(VS.85).aspx
http://www.cnblogs.com/fengjunkuan/

2015年4月11日 星期六

[IOS/Swift] how to parse json from the webservice

說明:
json可以拆解成Array,以[]表示,例:[{"id": "#123", "name": "Apple"},{"id": "#321", "name": "Google"}]。
另一種是Object,以{"key": "value"}表示,如http://date.jsontest.com/提供的:
{
   "time": "03:53:25 AM",
   "milliseconds_since_epoch": 1362196405309,
   "date": "03-02-2013"
}

這兩種格式可分別使用Swift內建NSArray跟NSDictionary來Parse,那Array內又有Array該如何Parse呢?


做法:
假設有一json如下:
{
"Parents": [ {"id": "#123",
                       "name": "Daddy1",
                       "Children": [ {"c_id": "#124",
                                                "c_name": "kid1"},
                                           {"c_id": "#125",
                                                "c_name": "kid2"}]
                  },
                     {"id": "#234",
                       "name": "Daddy2",
                       "Children": [ {"c_id": "#235",
                                                "c_name": "kid1"},
                                           {"c_id": "#236",
                                                "c_name": "kid2"}]
                     },
                     {"id": "#345",
                       "name": "Daddy3",
                       "Children": [ {"c_id": "#346",
                                                "c_name": "kid1"},
                                           {"c_id": "#347",
                                                "c_name": "kid2"}]
                     }
                ]
}

var arrResult = json.objectForKey("Parents") as NSArray;
var row: NSDictionary;
var rowSub: NSDictionary;
var arrSubResult : NSArray;
var strID: String;
var strName: String;
var strC_ID: String;
var strC_Name: String;
var arrTotalResult = [DataModel]();


for var i=0 ; i < arrResult.count ; i++ {
 
    row = arrResult[i] as NSDictionary;
    arrSubResult = row.objectForKey("Children") as NSArray;

    strID = row["ID"] as String;
    strName = row["NAME"] as String;
 
    for var j=0 ; j < arrSubResult.count ; j++ {

        rowSub = arrSubResult[j] as NSDictionary;
        strC_ID = row["C_ID"] as String;
        strC_Name = row["C_NAME"] as String;

        //使用data model
        let data = DataModel(ID: self.strID, Name: self.strName, C_ID: self.strC_ID, C_Name: self.C_Name);
        arrTotalResult.append(data);
    }
}






2015年3月11日 星期三

[C#] Performance: 泛型 List V.S. ArrayList V.S. DataTable

說明:數值型別使用ArrayList(型別轉換為Object)會有裝箱與拆箱的問題,參考型別也需進行型別轉換,因此使用List<T>應有較佳的執行效率,而DataTable在擷取DB資料方便使用,但效能似乎較差? 使用StopWatch來簡單驗證(皆跑1000000次)。


Case1:
使用數值型別int做比較,List > ArrayList >> DataTable。








Case2:
使用參考型別string做比較,List ≒ ArrayList >> DataTable。



2015年2月2日 星期一

[git/gerrit] Mac OS使用git將文件push上gerrit的branch

說明:git是分散式版本控制系統之一,gerrit是以git專案為基的code review系統,記錄在Mac OS下如何將code push上gerrit的branch。


做法:
1. 安裝git(http://git-scm.com/)。

2. 啟用gerrit之帳戶與建立SSH key。可參閱以下網址:
http://git-scm.com/book/zh/v2/Git-on-the-Server-Generating-Your-SSH-Public-Key

3. 測試本地電腦跟gerrit連線ok後,開啟電腦上的終端機,輸入defaults write com.apple.finder AppleShowAllFiles TRUE並按下Enter,再輸入killall Finder然後送出,讓電腦顯示系統的隱藏檔案,方便後續操作.git裡的config檔。

4. 在終端機輸入git clone ssh://ssh_user_name@gerrit_url:29418/project_name.git。

5. 專案複製到本地電腦帳戶下資料夾後 -> 打開此專案,修改某行程式碼儲存後,可將該檔案commit -> 輸入commit message -> commit送出。

6. 回到終端機視窗,輸入cd ~/project_name/,進到該專案下 -> 輸入git status,檢視目前專案異動狀態。

7. 輸入scp -p -P 29418 ssh_user_name@gerrit_url:hooks/commit-msg .git/hooks/,可將每次commit所需的Change_Id自動加進去commit message,否則可能會出現ERROR: missing Change-Id in commit message的訊息。

8. 打開Finder,進到本機帳號下的Project,打開隱藏的.git資料夾 -> 打開裡面的.config檔,加入以下指令,增加gerrit用來review code的branch,
[remote "review"]
pushurl = ssh://ssh_user_name@gerrit_url:29418/project_name
push = refs/heads/master:refs/for/master

9. 最後在終端上輸入git push review,即可將code push上gerrit review
code的branch -> 進gerrit即可看到剛push上去的記錄。



參考資料:
https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/xcode_guide-continuous_integration/PublishYourCodetoaSourceRepository/PublishYourCodetoaSourceRepository.html
http://stackoverflow.com/questions/8845658/gerrit-error-when-change-id-in-commit-messages-are-missing
http://vimeo.com/23609339

2015年1月23日 星期五

[IOS/Swift] 在text field內左側放入圖片(put the pic inside the text field)

說明:想在text field內左側塞入一小圖,但又不想放在background占滿整個text field,該怎麼做?


做法:
在storyboard放入一text field,接著在viewDidLoad事件中,建構一UIImageView object,並給予初始位置與大小,在assign給text field的leftView的property。例:

let imageTest = UIImageView(image: UIImage(named: "xxx.png"));

imageTest.bounds = CGRect(x: 0, y:0, width: 20, height: 20);
txtTest.leftViewMode = UITextFieldViewMode.Always;
txtTest.leftView = ImageTest;


參考資料:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextField_Class/index.html
http://stackoverflow.com/questions/13508836/add-image-to-uitextfield-in-xcode

[Oracle] 使用單行函式(function)記錄

說明1:想把查詢出來的多列資料合併成一列(combine multiple rows into one row),該如何做?


做法:使用LISTAGG函式,語法:LISTAGG(column[, 'delimiter']) WITHIN GROUP (ORDER BY column),例:
SELECT LISTAGG(ITEM, ';') WITHIN GROUP (ORDER BY No) DISPLAY
FROM table;


參考資料:
//http://stackoverflow.com/questions/1076011/how-can-multiple-rows-be-concatenated-into-one-in-oracle-without-creating-a-stor



說明2:去除查詢資料的特定字元TRIM/LTRIM/RTRIM


語法:L(R)TRIM( string, [ trim_string ] );
TRIM( [ [ LEADING | TRAILING | BOTH ] trim_character FROM ] string )
例:
--remove . on the right side of DISPLAY
SELECT RTRIM(DISPLAY, '.')DISPLAY
FROM table


參考資料:
http://www.techonthenet.com/oracle/functions/trim.php
http://give.pixnet.net/blog/post/25491792-(%E8%BD%89%E8%BC%89)-oracle%E7%9A%84%E5%AD%97%E4%B8%B2%E8%99%95%E7%90%86