public bool SaveServiceRequestActivity() { _hpDataAccess = new HpDataAccess(_context); var lstSrActivity = _hpDataAccess.GetSrWithHpActivity(); if (lstSrActivity != null && lstSrActivity.Count > 0) { var auditLog = new AuditLogEntity(); auditLog.Module = Constants.Module.Batch; auditLog.Action = Constants.AuditAction.SubmitActivityToCARSystem; auditLog.IpAddress = ApplicationHelpers.GetClientIP(); _srFacade = new ServiceRequestFacade(); foreach (var sr in lstSrActivity) { // TODO :: Add new parameter: AuditLogEntity for Call CAR Web Service _srFacade.CreateServiceRequestActivity(auditLog, sr, true); //if (result.IsSuccess == false) //{ // Logger.Debug(string.Format("CreateServiceRequestActivity SrId:{0} ErrorMessage:{1} WarningMessages:{2} " // , sr.SrId.Value.ToString(), result.ErrorMessage, result.WarningMessages)); //} } } return(true); }
public bool ExportActivityHP(string filePath, string fileName) { _hpDataAccess = new HpDataAccess(_context); var activityList = _hpDataAccess.GetHpActivityExport(); return(ExportActivityHP(filePath, fileName, activityList)); }
public bool SaveHpActivity(List <HpActivityEntity> hpActivity, string fiActivity) { if (!string.IsNullOrWhiteSpace(fiActivity)) { _hpDataAccess = new HpDataAccess(_context); return(_hpDataAccess.SaveHpActivity(hpActivity)); } return(true); }
public bool SaveServiceRequestActivity() { _hpDataAccess = new HpDataAccess(_context); var lstSrActivity = _hpDataAccess.GetSrWithHpActivity(); if (lstSrActivity != null && lstSrActivity.Count > 0) { _srFacade = new ServiceRequestFacade(); foreach (var sr in lstSrActivity) { // TODO :: Add new parameter: AuditLogEntity for Call CAR Web Service _srFacade.CreateServiceRequestActivity(null, sr, true); //if (result.IsSuccess == false) //{ // Logger.Debug(string.Format("CreateServiceRequestActivity SrId:{0} ErrorMessage:{1} WarningMessages:{2} " // , sr.SrId.Value.ToString(), result.ErrorMessage, result.WarningMessages)); //} } } return(true); }
public List <HpActivityEntity> ReadFileHpActivity(string filePath, string fiPrefix, ref int numOfActivity, ref string fiActivity, ref bool isValidFile, ref string msgValidateFileError) { try { _hpDataAccess = new HpDataAccess(_context); IEnumerable <string> files = Directory.EnumerateFiles(filePath, string.Format(CultureInfo.InvariantCulture, "{0}*.txt", fiPrefix)); // lazy file system lookup if (files.Any()) { fiActivity = Path.GetFileName(files.First()); IEnumerable <string[]> results = StreamDataHelpers.ReadCsv(files.First()); #region "Validate file format" bool isValidFormat = false; int inx = 1; List <string> lstLengthNotMatch = new List <string>(); foreach (var source in results) { if (source.Length != Constants.ImportHp.LengthOfDetail) { lstLengthNotMatch.Add(string.Format(CultureInfo.InvariantCulture, "{0}", inx.ToString(CultureInfo.InvariantCulture))); } inx++; } if (lstLengthNotMatch.Count > 0 && lstLengthNotMatch.Count <= 5000) { Logger.DebugFormat("File:{0} Invalid format @line[{1}]", fiActivity, string.Join(",", lstLengthNotMatch.ToArray())); } else if (lstLengthNotMatch.Count > 0) { Logger.DebugFormat("File:{0} Invalid format {1} records", fiActivity, lstLengthNotMatch.Count.ToString(CultureInfo.InvariantCulture)); } isValidFormat = (lstLengthNotMatch.Count == 0); if (isValidFormat == false) { msgValidateFileError = string.Format(CultureInfo.InvariantCulture, " File name : {0} is invalid file format.", fiActivity); } if (isValidFormat == false) { // Move File string pathError = this.GetParameter(Constants.ParameterName.HPPathError); StreamDataHelpers.TryToCopy(string.Format(CultureInfo.InvariantCulture, "{0}\\{1}", filePath, fiActivity), string.Format(CultureInfo.InvariantCulture, "{0}\\{1}", pathError, fiActivity)); isValidFile = false; // ref value goto Outer; } #endregion var rx = new Regex(@".*SR;.*;\s*Status\s*:.*;\s*Contact\s*Mobile\s*#", RegexOptions.IgnoreCase | RegexOptions.Multiline); List <HpActivityEntity> hpActivity = (from source in results where !rx.IsMatch(source[5].NullSafeTrim()) select new HpActivityEntity { Channel = source[0].NullSafeTrim(), Type = source[1].NullSafeTrim(), Area = source[2].NullSafeTrim(), Status = source[3].NullSafeTrim(), Description = source[4].NullSafeTrim(), Comment = source[5].NullSafeTrim(), AssetInfo = source[6].NullSafeTrim(), ContactInfo = source[7].NullSafeTrim(), Ano = source[8].NullSafeTrim(), CallId = source[9].NullSafeTrim(), ContactName = source[10].NullSafeTrim(), ContactLastName = source[11].NullSafeTrim(), ContactPhone = source[12].NullSafeTrim(), DoneFlg = source[13].NullSafeTrim(), CreateDate = source[14].NullSafeTrim(), CreateBy = source[15].NullSafeTrim(), StartDate = source[16].NullSafeTrim(), EndDate = source[17].NullSafeTrim(), OwnerLogin = source[18].NullSafeTrim(), OwnerPerId = source[19].NullSafeTrim(), UpdateDate = source[20].NullSafeTrim(), UpdateBy = source[21].NullSafeTrim(), SrNo = source[22].NullSafeTrim(), CallFlg = source[23].NullSafeTrim(), EnqFlg = source[24].NullSafeTrim(), LocEnqFlg = source[25].NullSafeTrim(), DocReqFlg = source[26].NullSafeTrim(), PriIssuedFlg = source[27].NullSafeTrim(), AssetInspectFlg = source[28].NullSafeTrim(), PlanstartDate = source[29].NullSafeTrim(), ContactFax = source[30].NullSafeTrim(), ContactEmail = source[31].NullSafeTrim() }).ToList(); #region "Validate MaxLength" ValidationContext vc = null; int inxErr = 1; var lstErrMaxLength = new List <string>(); foreach (HpActivityEntity hp in hpActivity) { vc = new ValidationContext(hp, null, null); var validationResults = new List <ValidationResult>(); bool valid = Validator.TryValidateObject(hp, vc, validationResults, true); if (!valid) { hp.Error = validationResults.Select(x => x.ErrorMessage) .Aggregate((i, j) => i + Environment.NewLine + j); lstErrMaxLength.Add(string.Format(CultureInfo.InvariantCulture, "{0}", inxErr.ToString(CultureInfo.InvariantCulture))); } inxErr++; } if (lstErrMaxLength.Count > 0) { Logger.DebugFormat("File:{0} Invalid MaxLength @line[{1}]", fiActivity, string.Join(",", lstErrMaxLength.ToArray())); } if (hpActivity.Count(x => !string.IsNullOrWhiteSpace(x.Error)) > 0) { // Move File string pathError = this.GetParameter(Constants.ParameterName.HPPathError); StreamDataHelpers.TryToCopy(string.Format(CultureInfo.InvariantCulture, "{0}\\{1}", filePath, fiActivity), string.Format(CultureInfo.InvariantCulture, "{0}\\{1}", pathError, fiActivity)); //Logger.DebugFormat("File:{0} Invalid MaxLength", fiActivity); isValidFile = false; // ref value msgValidateFileError = string.Format(CultureInfo.InvariantCulture, " File name : {0} is invalid maxLength.", fiActivity); goto Outer; } #endregion numOfActivity = hpActivity.Count; return(hpActivity); } else { isValidFile = false; msgValidateFileError = "File not found."; } Outer: return(null); } catch (IOException ex) { Logger.Error("Exception occur:\n", ex); throw new CustomException("{0}: {1}", fiPrefix, ex.Message); } catch (Exception ex) { Logger.Error("Exception occur:\n", ex); throw; } finally { #region "Move file to PathSource" if (!string.IsNullOrEmpty(fiActivity)) { string hpPathSource = this.GetParameter(Constants.ParameterName.HpPathSource); StreamDataHelpers.TryToCopy(string.Format(CultureInfo.InvariantCulture, "{0}\\{1}", filePath, fiActivity), string.Format(CultureInfo.InvariantCulture, "{0}\\{1}", hpPathSource, fiActivity)); StreamDataHelpers.TryToDelete(string.Format(CultureInfo.InvariantCulture, "{0}\\{1}", filePath, fiActivity)); } #endregion } }
public bool SaveHpActivityComplete(ref int numOfComplete, ref int numOfError, ref string messageError) { _hpDataAccess = new HpDataAccess(_context); return(_hpDataAccess.SaveHpActivityComplete(ref numOfComplete, ref numOfError, ref messageError)); }