private static void PopulateESGIndex(ElasticClient client) { var dt = new DLEsgEngagementDetails().GetAllEngagements(); foreach (DataRow dr in dt.Rows) { client.Index(new ESGSearch { ESGId = Convert.ToInt32(dr["ESG_Engagement_ID"]), ESGComments = dr["REMARKS"].ToString(), ESGNextSteps = dr["Next_Step"].ToString() }, p => p.Index("esgsearch")); } }
private static void PopulateLearningCenterIndex(ElasticClient client) { var directory = @"\\stovsvr3484\LearningCenterUploadRpt"; //System.Configuration.ConfigurationManager.AppSettings["CallReportPath"].ToString(); var callReportsCollection = Directory.GetFiles(directory); //this will fetch all files //callReportsCollection.ToList().AddRange(Directory.GetFiles(directory, "*.doc")); ConcurrentBag <string> reportsBag = new ConcurrentBag <string>(callReportsCollection); int i = 0; var learningDocElastic = new DLEsgEngagementDetails().GetLearingDocs();//.AsEnumerable();//.Take(50).CopyToDataTable(); try { //Parallel.ForEach(reportsBag, callReport => Array.ForEach(callReportsCollection, callReport => { var base64File = Convert.ToBase64String(File.ReadAllBytes(callReport)); var fileSavedName = callReport.Replace(directory, "").Replace(@"\", ""); // var dt = dLCallReportSearch.GetCallFileName(fileSavedName.Replace("'", "''"));//replace the ' in a file name with ''; var rows = learningDocElastic.Select("FILENAME like '%" + fileSavedName.Replace("'", "''") + "'"); //var rows = from l in learningDocElastic.AsEnumerable() where l.Field<string>("FileName").Equals(fileSavedName, StringComparison.OrdinalIgnoreCase) select l; if (rows != null && rows.Count() > 0) { var row = rows.FirstOrDefault(); //foreach (DataRow row in rows) //{ i++; client.Index(new LearningCenter { Id = i, LearningDetailsId = Convert.ToInt32(row["ID"].ToString()), Path = row["FilePath"].ToString(), Title = row["FileName"].ToString(), Author = row["Author"].ToString(), UploadDate = string.IsNullOrEmpty(row["UploadDate"].ToString()) ? (DateTime?)null : Convert.ToDateTime(row["UploadDate"].ToString()), Headline = row["Headline"].ToString(), DocumentType = row["DocType"].ToString(), SectorCode = row["SectorCode"].ToString(), SectorName = row["SectorName"].ToString(), Content = base64File }, p => p.Pipeline("attachments")); //} } }); } catch (Exception ex) { throw ex; } }