public static DateTime ToEnDateTime(string date, string time) { try { int temp2 = 0; int year = int.Parse(date.Substring(0, temp2 = date.IndexOf("/", 0))); int tempindex = temp2 + 1; int month = int.Parse(date.Substring(tempindex, (temp2 = date.IndexOf("/", tempindex)) - tempindex)); tempindex = temp2 + 1; int day = int.Parse(date.Substring(tempindex, date.Length - tempindex)); temp2 = 0; int hour = int.Parse(time.Substring(0, temp2 = time.IndexOf(":", 0))); tempindex = temp2 + 1; int minute = int.Parse(time.Substring(tempindex, (temp2 = time.IndexOf(":", tempindex)) - tempindex)); tempindex = temp2 + 1; int second = int.Parse(time.Substring(tempindex, time.Length - tempindex)); return(_persianAssistante.ToDateTime(year, month, day, hour, minute, second, 0)); } catch (Exception ex) { Debuging.Error(ex, "To En DateTime Function"); return(DateTime.MinValue); } }
public static string DecryptTripleDES(string strEncrypted, string strKey) { string decryptData = ""; try { TripleDESCryptoServiceProvider objDESCrypto = new TripleDESCryptoServiceProvider(); MD5CryptoServiceProvider objHashMD5 = new MD5CryptoServiceProvider(); byte[] byteHash, byteBuff; string strTempKey = strKey; byteHash = objHashMD5.ComputeHash(Encoding.UTF8.GetBytes(strTempKey)); objDESCrypto.Key = byteHash; objDESCrypto.Mode = CipherMode.ECB; //CBC, CFB byteBuff = Convert.FromBase64String(strEncrypted); string strDecrypted = Encoding.UTF8.GetString(objDESCrypto.CreateDecryptor() .TransformFinalBlock(byteBuff, 0, byteBuff.Length)); decryptData = strDecrypted; } catch (Exception ex) { Debuging.Error(ex, "DecryptTripleDES"); } return(decryptData); }
public static ActionResult SendEmail(string smtpHost, string from, string to, string body, string subject, string fromPassword) { ActionResult result = new ActionResult(); try { if (!IsValidEmail(to) || !IsValidEmail(@from)) { throw new LocalException("EmailAddress is wrong", "آدرس ایمیل صحیح نیست", "toEmailAddress", to, "fromEmailAddress", @from); } MailMessage message = new MailMessage(@from, to, subject, body) { BodyEncoding = Encoding.UTF8, IsBodyHtml = true, DeliveryNotificationOptions = DeliveryNotificationOptions.None, Priority = MailPriority.High, SubjectEncoding = Encoding.UTF8 }; SmtpClient client = new SmtpClient(smtpHost); //example:"mto-foods.ir" client.Credentials = new NetworkCredential(@from, fromPassword); client.Send(message); result.IsSuccess = true; result.ResultMessage = MessageText.SUCCESS; } catch (LocalException ex) { Debuging.Warning(ex, "SendEmail Function"); result.IsSuccess = false; result.EnglishMessage = ex.Message; result.ResultMessage = ex.ResultMessage; } catch (Exception ex) { ex.Data.Add("From", @from); ex.Data.Add("To", to); ex.Data.Add("Body", body); ex.Data.Add("Subject", subject); Debuging.Error(ex, "SendEmail Function"); result.IsSuccess = false; result.EnglishMessage = ex.Message; result.ResultMessage = MessageText.UNKNOWN_ERROR; } return(result); }
public static DateTime ToEnDate(this string value) { try { int temp2 = 0; int year = int.Parse(value.Substring(0, temp2 = value.IndexOf("/", 0))); int tempindex = temp2 + 1; int month = int.Parse(value.Substring(tempindex, (temp2 = value.IndexOf("/", tempindex)) - tempindex)); tempindex = temp2 + 1; int day = int.Parse(value.Substring(tempindex, value.Length - tempindex)); return(_persianAssistante.ToDateTime(year, month, day, 0, 0, 0, 0)); } catch (Exception ex) { Debuging.Error(ex, "To En Date Function"); return(DateTime.MinValue); } }
public static void DownloadFile(string strURL) { try { // string strURL = Server.MapPath(filePath); WebClient req = new WebClient(); HttpResponse response = HttpContext.Current.Response; response.Clear(); response.ClearContent(); response.ClearHeaders(); response.Buffer = true; response.AddHeader("Content-Disposition", "attachment;filename=\"" + strURL + "\""); byte[] data = req.DownloadData(strURL); response.BinaryWrite(data); response.End(); } catch (Exception ex) { Debuging.Error(ex, "Utility.DownloadFile"); } }