public static void FuncClose(string PageName, string MethodName) { objReaderWriterLockSlim.EnterWriteLock(); try { string LogsPath = AppDomain.CurrentDomain.BaseDirectory; string baseDir = LogsPath; DateTime dateTime = DateTime.Now; string Year = dateTime.ToString("yyyy"); string Month = dateTime.ToString("MMM"); string LogFileName = dateTime.ToString("dd-MMM-yyyy") + ".txt"; string LogDirName = CommonObjects.GetCongifValue(ConfigKeys.LogDir); string LogFileDirName = CommonObjects.GetCongifValue(ConfigKeys.InformationLogDir); string InfoLogFilePath = Path.Combine(baseDir, LogDirName, LogFileDirName, Year, Month, LogFileName); if (!Directory.Exists(baseDir)) { Directory.CreateDirectory(baseDir); } if (!Directory.Exists(Path.Combine(baseDir, LogDirName))) { Directory.CreateDirectory(Path.Combine(baseDir, LogDirName)); } if (!Directory.Exists(Path.Combine(baseDir, LogDirName, LogFileDirName))) { Directory.CreateDirectory(Path.Combine(baseDir, LogDirName, LogFileDirName)); } if (!Directory.Exists(Path.Combine(baseDir, LogDirName, LogFileDirName, Year))) { Directory.CreateDirectory(Path.Combine(baseDir, LogDirName, LogFileDirName, Year)); } if (!Directory.Exists(Path.Combine(baseDir, LogDirName, LogFileDirName, Year, Month))) { Directory.CreateDirectory(Path.Combine(baseDir, LogDirName, LogFileDirName, Year, Month)); } if (File.Exists(InfoLogFilePath)) { RemoveFileReadOnly(InfoLogFilePath); using (StreamWriter writer = new StreamWriter(InfoLogFilePath, true)) { writer.WriteLine("ClassName : " + PageName + " MethodName " + MethodName); writer.WriteLine("-------------------Function Close-------------" + DateTime.Now); } } else { StreamWriter writer = File.CreateText(InfoLogFilePath); writer.WriteLine("ClassName : " + PageName + " MethodName " + MethodName); writer.WriteLine("-------------------Function Close-------------" + DateTime.Now); writer.Close(); } } catch (Exception ex) { } finally { objReaderWriterLockSlim.ExitWriteLock(); } }
public static byte[] Encrypt(byte[] bytesToEncrypt) { string key = CommonObjects.GetCongifValue(ConfigKeys.TripleDesKey); byte[] iv1 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider(); tdes.Mode = CipherMode.ECB; tdes.Key = Encoding.ASCII.GetBytes(key); tdes.IV = iv1; tdes.Padding = PaddingMode.Zeros; byte[] bufferFinalBlock = tdes.CreateEncryptor().TransformFinalBlock(bytesToEncrypt, 0, bytesToEncrypt.Length); return(bufferFinalBlock); }
public bool ValidateRequest(APICredentialsBLL objAPICredentials) { bool IsValidate = false; try { if (objAPICredentials.UserName == CommonObjects.GetCongifValue(ConfigKeys.UserName) && objAPICredentials.Password == CommonObjects.GetCongifValue(ConfigKeys.Password)) { IsValidate = true; } } catch (Exception) { throw; } return(IsValidate); }
public bool ValidateRequest(APICredentialsBLL objAPICredentials) { string funcName = "ValidateRequest"; bool IsValidate = false; Logger.Logger.Information(clsName, funcName, "objAPICredentials", JsonConvert.SerializeObject(objAPICredentials)); try { if (objAPICredentials.UserName == CommonObjects.GetCongifValue(ConfigKeys.UserName) && objAPICredentials.Password == CommonObjects.GetCongifValue(ConfigKeys.Password)) { IsValidate = true; } } catch (Exception ex) { Logger.Logger.WriteErrorLog(clsName, funcName, ex); throw; } Logger.Logger.Information(clsName, funcName, "IsValidate", IsValidate.ToString()); return(IsValidate); }
public static string Encrypt(string PlainText) { try { string key = CommonObjects.GetCongifValue(ConfigKeys.TripleDesKey); byte[] iv1 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; byte[] PlainTextArray = UTF8Encoding.UTF8.GetBytes(PlainText); byte[] keyArray = MD5.CreateMd5ByteArray(key); TripleDESCryptoServiceProvider TripleDes = new TripleDESCryptoServiceProvider(); TripleDes.Key = keyArray; TripleDes.Mode = CipherMode.ECB; TripleDes.Padding = PaddingMode.PKCS7; TripleDes.IV = iv1; ICryptoTransform cTransform = TripleDes.CreateEncryptor(); byte[] CipherString = cTransform.TransformFinalBlock(PlainTextArray, 0, PlainTextArray.Length); TripleDes.Clear(); return(Convert.ToBase64String(CipherString, 0, CipherString.Length)); } catch (Exception) { throw; } }
public static void Information(string PageName, string MethodName, params string[] parameters) { objReaderWriterLockSlim.EnterWriteLock(); try { string LogsPath = AppDomain.CurrentDomain.BaseDirectory; string baseDir = LogsPath; DateTime dateTime = DateTime.Now; string Year = dateTime.ToString("yyyy"); string Month = dateTime.ToString("MMM"); string LogFileName = dateTime.ToString("dd-MMM-yyyy") + ".txt"; string LogDirName = CommonObjects.GetCongifValue(ConfigKeys.LogDir); string LogFileDirName = CommonObjects.GetCongifValue(ConfigKeys.InformationLogDir); string InfoLogFilePath = Path.Combine(baseDir, LogDirName, LogFileDirName, Year, Month, LogFileName); if (!Directory.Exists(baseDir)) { Directory.CreateDirectory(baseDir); } if (!Directory.Exists(Path.Combine(baseDir, LogDirName))) { Directory.CreateDirectory(Path.Combine(baseDir, LogDirName)); } if (!Directory.Exists(Path.Combine(baseDir, LogDirName, LogFileDirName))) { Directory.CreateDirectory(Path.Combine(baseDir, LogDirName, LogFileDirName)); } if (!Directory.Exists(Path.Combine(baseDir, LogDirName, LogFileDirName, Year))) { Directory.CreateDirectory(Path.Combine(baseDir, LogDirName, LogFileDirName, Year)); } if (!Directory.Exists(Path.Combine(baseDir, LogDirName, LogFileDirName, Year, Month))) { Directory.CreateDirectory(Path.Combine(baseDir, LogDirName, LogFileDirName, Year, Month)); } if (File.Exists(InfoLogFilePath)) { RemoveFileReadOnly(InfoLogFilePath); using (StreamWriter writer = new StreamWriter(InfoLogFilePath, true)) { string parametersLine = string.Empty; foreach (string dict in parameters) { parametersLine = parametersLine + " " + dict; } if (!string.IsNullOrEmpty(parametersLine)) { writer.WriteLine("ClassName : " + PageName + " MethodName " + MethodName + " Information " + "Parameters : " + parametersLine); } } } else { StreamWriter writer = File.CreateText(InfoLogFilePath); string parametersLine = string.Empty; foreach (string dict in parameters) { parametersLine = parametersLine + " " + dict; } if (string.IsNullOrEmpty(parametersLine)) { writer.WriteLine("ClassName : " + PageName + " MethodName " + MethodName + " Information " + "Parameters : " + parametersLine); } writer.Close(); } } catch (Exception ex) { } finally { objReaderWriterLockSlim.ExitWriteLock(); } }
public ResponseDTO GetLogin(LoginRequestDTO request) { string funcName = "GetMemberLogin"; Logger.Logger.FuncOpen(clsName, funcName, "request", JsonConvert.SerializeObject(request)); ResponseDTO res = new ResponseDTO(); using (MarvelBLL objMarvelBLL = new MarvelBLL()) { try { APICredentialsBLL credentialsBLL = new APICredentialsBLL(); credentialsBLL.UserName = request.APICredentials.APIUserName; credentialsBLL.Password = request.APICredentials.APIPassword; if (!new CommonMethods().ValidateRequest(credentialsBLL)) { res.ResponseCode = ResponseCodes.Failed; res.ResponseMessage = ResponseMessages.InvalidCredentials; } else if (string.IsNullOrWhiteSpace(request.Email) || string.IsNullOrWhiteSpace(request.Password)) { res.ResponseCode = ResponseCodes.Failed; res.ResponseMessage = ResponseMessages.InvalidData; } else { APICredentialsBLL credentials = new APICredentialsBLL(); credentials.UserName = request.Email; credentials.Password = request.Password; DataTable dtRecord = new UsersBLL().GetLogin(objMarvelBLL, credentials); LoginResponse login = new LoginResponse(); if (dtRecord.Rows.Count > 0) { foreach (DataRow row in dtRecord.Rows) { login.UserID = int.Parse(row["UserID"].ToString()); login.Email = row["Email"].ToString(); login.UserName = row["UserName"].ToString(); login.FirstName = row["FirstName"].ToString(); login.LastName = row["LastName"].ToString(); login.IsActive = bool.Parse(row["IsActive"].ToString()); login.MobileNo = row["MobileNo"].ToString(); login.Gender = row["Gender"].ToString(); login.Country = row["Country"].ToString(); login.RoleID = int.Parse(row["RoleID"].ToString()); login.StatusID = int.Parse(row["StatusID"].ToString()); login.Role = row["Role"].ToString(); login.Status = row["Status"].ToString(); login.CNIC = row["CNIC"].ToString(); login.ImageUrl = CommonObjects.GetCongifValue(ConfigKeys.HostingURL) + row["ImageUrl"].ToString(); DateTime dt = DateTime.Parse(row["DateOfBirth"].ToString()); login.DateOfBirth = String.Format("{0:ddd, MMM d, yyyy}", dt); } res.ResponseCode = ResponseCodes.Success; res.ResponseMessage = ResponseMessages.Success; } else { res.ResponseCode = ResponseCodes.Success; res.ResponseMessage = ResponseMessages.LoginFailed; } res.ResponseData = new ResponseData(); res.ResponseData.LoginResp = login; } } catch (Exception ex) { Logger.Logger.WriteErrorLog(clsName, funcName, ex); res.ResponseCode = ResponseCodes.Failed; res.ResponseMessage = ex.Message; } } Logger.Logger.Information(clsName, funcName, "Response", JsonConvert.SerializeObject(res)); Logger.Logger.FuncClose(clsName, funcName); return(res); }