發表文章

目前顯示的是 2013的文章

Tips 在Visual Studio中要如何設定讓版本號可以自動變換(增量)

圖片
當程式開發到一個段落之後,通常我們會在Visual Studio當中,加上版本號碼,用來辨別release出去的軟體是哪一個版本,而在Visual Studio裡面,設定版本號碼的地方,直接打上『*』是不能夠輸入的,像是下圖 那麼應該怎麼設定呢?這時候要直接修改一下檔案內容 開啟之後,在最下方的地方修改成類似這個樣子 [ assembly :  AssemblyVersion ( "1.0.3.*" )] //[assembly: AssemblyFileVersion("1.2.0")] 記得AssemblyFileVersion這行要註解掉才會有用喔

[WPF] 如何取得觸發快顯功能表(右鍵選單)的來源控制項呢?

在WPF中,右鍵選單的功能是利用ContextMenu來達成,如果是用程式碼的方式來幫控制項添加右鍵選單,會大概是下面的方式                  Image   image   =   new   Image ();                  MenuItem   propertyMenu   =   new   MenuItem ();                  propertyMenu . Header   =   "Propertys..." ;                  propertyMenu . Click   +=   ImagePropertyMenu_Click ;                  image . ContextMenu   =   new   ContextMenu ();                  image . ContextMenu . Items . Add ( propertyMenu ); 在上面的程式碼中,可以看到在新增右鍵選單的同時,也將Click事件掛載上去了;事件掛載的程式碼會大約是這樣          static   void   ImagePropertyMenu_Click ( object   sender ,  RoutedEventArgs   e )         {              WinPropertys   propertyWindow   =   new   WinPropertys ();                           propertyWindow . ShowDialog ();         } 在一般的使用情形下,這沒有任何問題,如果只是單純的要呼叫顯示其他的window;但是如果是要做一個像是屬性設定的功能,例如以這個例子來說,我的來源控制項是一個Image,呼叫出來的新視窗中,我希望可以顯示出這個Image的寬度、高度、位置等資訊,那麼應該怎麼處理?在MenuItem的Click事件中,你可以看到不論是e.Source或是Sender,觸發這個事件的都是MenuItem,所以不能夠直接抓到觸發的來源控制項,這個時候就要利用下面的方式來抓取了       

WCF服務中如何同時啟用SOAP與REST兩種類型的服務端點

在WCF服務中,除了原先SOAP的服務外,我們也可以建立REST的服務類型,那如果說要在同一支服務當中,同時建立兩種的話應該要怎麼做呢?這邊先簡單筆記一下,之後有時間再來補齊 主要的方式就是要建立兩個EndPoint,一個給SOAP用,一個給REST用;而Interface的部分也要建立兩份,比如說REST的介面像是下面這樣     [ ServiceContract ]      public   interface   IRestfulService     {         #region  Member query         [ OperationContract ()]         [ WebGet ( UriTemplate   =   "/Members/Query/MemberId/{memberId}" ,  ResponseFormat   =   WebMessageFormat . Json ,  BodyStyle   =   WebMessageBodyStyle . Wrapped )]          Data . Member   restGetMemberByMemberId ( string   memberId );         [ OperationContract ()]         [ WebGet ( UriTemplate   =   "/Members/Query/CardUid/{cardUid}" ,  ResponseFormat   =   WebMessageFormat . Json )]          Data . Member   restGetMemberByCardUid ( string   cardUid );         [ OperationContract ()]         [ WebGet ( UriTemplate   =   "/Members/Query/Department/{departmentId}" ,  ResponseFormat   =   WebMessageFormat . Json )]          List < Data . M

[Android] 使用HttpGet加上基本驗證時,得到回應400 Bad Request

圖片
在Android的開發上,搭配Restful Service去取得資料時,通常會使用HttpClient加上HttpGet去向Server抓取資料來源,例如說下面這樣 try         {             HttpResponse response = client.execute(get);             StatusLine statusLine = response.getStatusLine();             if(statusLine.getStatusCode() == HttpStatus.SC_OK){                 HttpEntity entity = response.getEntity();                 ByteArrayOutputStream out = new ByteArrayOutputStream();                 entity.writeTo(out);                 out.close();                 result = out.toString();             }         }         catch (IOException ex){             result = null;         } 而在Restful Service的安全性上面,驗證方式通常會採用基本驗證(在header中加入驗證資訊)加上https來做(這篇不會提到https的部分);而加入驗證資訊的部分會像是這樣的方式 String encoding = Base64.encodeToString((userName+":"+userPwd).getBytes(), Base64.NO_WRAP );         HttpClient client = new DefaultHttpClient();         HttpGet get = new HttpGet(requestUrl);         get.addHeader("Authorization","Basic "+encoding);

System.Drawing.Bitmap要如何轉換成WPF中可用的ImageSource呢?

在一般情況下,如果我們有一些圖片需要顯示在WPF的應用程式中,通常我們會使用Image,以及指定Image.Source屬性,例如說下面這樣 img1.Source = new BitmapImage(new Uri(@"image file path", UriKind.RelativeOrAbsolute)); 利用這樣的方式,將圖片檔案顯示在Imagez上面;如果來源是byte array的話,會利用類似這樣的方式 System.IO.FileStream fs = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); fs.Close(); fs.Dispose(); System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer); BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = ms; bitmapImage.EndInit(); img1.Source = bitmapImage; 這樣就可以由byte陣列轉換成WPF中可以使用的圖片來源了,不過上面這段程式碼有個問題需要處理,在memoryStream的部分,上面並沒有看到Dispose的部分,這樣子不會產生一些記憶體耗用的狀況嗎?於是嘗試加上了MemortStream.Dispose的部分之後發現『疑?阿圖片怎麼顯示不出來了』,這個部分請參考一下 Conver

如何取得Serial port的friendly name

圖片
這邊筆記一下,一般情況來說,如果我們想要目前電腦中總共有那些Serialport可以使用的話,最常見的方式會是下面這樣             foreach (string name in SerialPort.GetPortNames())             {                 cboPortName.Items.Add(name);             } 不過如果說我們想要取得像是下圖紅框部分,比較"看的懂"(?) 的名稱的話,應該要怎麼做呢? 作法可以參考一下下面位置的相關程式碼 How to open a serial port by friendly name?

[android][Note] signing apk

這篇給自己筆記一下 在android開發上,應用程式(apk)都需要經過簽署,跟一般情況比較不同的是你可以用自我簽署的方式去做,不一定真的需要向信任的憑證機構去申請憑證。 而在開發上,在除錯模式(debug)下,IDE會自動幫你產生debug用的憑證,而debug的憑證會有時間的限制(預設是365天),時間到了在做debug的時候會發生錯誤,這個時候要把舊的憑證給刪除,詳細憑證相關的資訊可以參考下面這邊 Signing your application 部分原文 To fix this problem, simply delete the  debug.keystore  file. The default storage location for AVDs is in  ~/.android/  on OS X and Linux, in  C:\Documents and Settings\ \.android\  on Windows XP, and in  C:\Users\ \.android\  on Windows Vista and Windows 7.