[Visual Studio] 自訂 Item Template
為了方便自己以為建立coding standard, 制造一堆template 是其中一個方法. 有時候會copy and paste 一堆相類似的code再修改. 雖然能夠達到目的, 但費時失事. 所以Item Template 應運而生.
為了方便自己以為建立coding standard, 制造一堆template 是其中一個方法. 有時候會copy and paste 一堆相類似的code再修改. 雖然能夠達到目的, 但費時失事. 所以Item Template 應運而生.
現在security 越來越重要, 若一個project 要上production 前, 通常都會進行一次security scan, 以確保一定程度的measurement. OWASP 是一個非牟利團體定期向業界匯報當時常見的security issue, 而其中的security scanner 亦應運而生. 它會對網站進行一個intuition test, 從而找到漏洞. 網址: https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project
在development 時, 通常會分開不同的環境做deployment, 以避免混亂. 當database 有修改時, 為了方便去做counter-check 或migration, 找到了一個tools, 方便自己工作.
當在create model 時, 有機會assign value 到其相對應的class中之後做insert 動作. 但若在ORM 層面的話, 須要在所有child item inserted 後才可進行, 否則有機會throw exception. 為了應對這問題, 可以用以下方法做work-around: using (NotificationEntities entites = new NotificationEntities()) { entites.EMAILs.Add(email); entites.Database.ExecuteSqlCommand(“SET IDENTITY_INSERT [dbo].[EMAIL] ON”); entites.SaveChanges(); entites.Database.ExecuteSqlCommand(“SET IDENTITY_INSERT [dbo].[EMAIL] OFF”); } […]
在.net environment, 本身不支援UNC path, 若加上user name /password 設定, 總會throw exception. 網上找來一個class, 它是call windows dll 去進行連結. 若在windows environment 的話, 不失為一個好方法.
在顯示貨幣時, 每隔三個位, 都須要加一個”,”分隔, 在C# 可以自行implement 如下: public static string ConvertToCurrency(double value) { string result = String.Format(“{0:#,##0.##00}”,value); return result; }
部份內容須要儲存或傳送, 若plain text 的話會是一個考量, 故須要將它encode. public static string Base64Encode(string plainText) { var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText); return System.Convert.ToBase64String(plainTextBytes); } public static string Base64Decode(string base64EncodedData) { var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData); return System.Text.Encoding.UTF8.GetString(base64EncodedBytes); }
public boolean sendMail(EmailMessage emailMessage) { boolean result=false; try { // Generate Spring MIME message and send. // Get system properties Properties properties = System.getProperties(); if(ServerUtil.isWindows()) properties.setProperty(EMAIL_SMTP_HOSTNAME_WIN, smtpHostName); else properties.setProperty(EMAIL_SMTP_HOSTNAME_LINUX, smtpHostName); Session session = Session.getDefaultInstance(properties); MimeMessage […]
Quartz 是一個scheduler API, 可以讓program 於指定時間, 自動執行指令. 相對使用windows的schedule job 或Linux 的cron job, 它少了OS level 的dependency, 即是無須設定執行schedule job 的user account 等. 使用時, 須要implement 其Interface IJob. public class CheckUnsentEmailJob : IJob { public override void Execute(IJobExecutionContext context) { […]
在send email 前, 先講如何制造email object. 這裡用了一粒class 去包著須要send的內容. 故砌真. object 時, 這個method 可以定義為adapter 的implementation. private MailMessage createMailMessage(EMAIL email) { MailMessage mail = new MailMessage() { From = new MailAddress(email.FROM_EMAIL_ADDRESS), }; mail.To.Add(new MailAddress(email.TO_EMAIL_ADDRESS)); if (!string.IsNullOrEmpty(email.CC_EMAIL_ADDRESS)) mail.CC.Add(new MailAddress(email.CC_EMAIL_ADDRESS)); […]
Copyright © 2026 | MH Magazine WordPress Theme by MH Themes