public ESI4TServiceResponse <IndexResponse> RemoveDocument(ESI4TServiceRequest <IndexRequest> query) { ESI4TLogger.WriteLog(ELogLevel.INFO, "Entering into method IndexService.RemoveDocument"); ESI4TServiceResponse <IndexResponse> serviceResponse = new ESI4TServiceResponse <IndexResponse>(); try { //serviceResponse.ServicePayload = new IndexResponse(); //serviceResponse.ServicePayload.Result = 1; ESI4TLogger.WriteLog(ELogLevel.INFO, "RemoveDocument is called publish is true1 "); IndexResponse resultValue; ESI4TIndexManager indexManager = new ESI4TIndexManager(query.ServicePayload.LanguageInRequest); resultValue = indexManager.RemoveDocument(query.ServicePayload); serviceResponse.ServicePayload = resultValue; ESI4TLogger.WriteLog(ELogLevel.INFO, "RemoveDocument is called publish is true 2"); } catch (Exception ex) { serviceResponse.ServicePayload = new IndexResponse(); serviceResponse.ServicePayload.Result = 0; serviceResponse.ServicePayload.ErrorMessage = "RemoveDocument is not called ispublish is false"; ESI4TLogger.WriteLog(ELogLevel.INFO, "RemoveDocument is not called ispublish is false"); string logString = ESI4TServiceConstants.LOG_MESSAGE + Environment.NewLine; string request = query != null?query.ToJSONText() : "Request = NULL"; logString = string.Concat(logString, string.Format("Service Request: {0}", request), Environment.NewLine, string.Format("{0}{1}", ex.Message, ex.StackTrace)); ESI4TLogger.WriteLog(ELogLevel.ERROR, logString); CatchException <IndexResponse>(ex, serviceResponse); } ESI4TLogger.WriteLog(ELogLevel.INFO, "Exiting from method IndexService.RemoveDocument"); return(serviceResponse); }
public static void HandleCustomException(Exception ex, string LogMessage) { ESI4TIndexingException ampEx = ex as ESI4TIndexingException; if (ampEx != null) { ESI4TLogger.WriteLog(ELogLevel.WARN, LogMessage); } else { ESI4TLogger.WriteLog(ELogLevel.ERROR, LogMessage); } }
public ESI4TIndexManager(string Langauge) { ESI4TLogger.WriteLog(ELogLevel.INFO, "Entering ESI4TIndexManager:" + Langauge); try { string elasticSearchURL = propConfiguration.GetString(ESI4TServicesConstants.elasticSearch_URL); ESI4TLogger.WriteLog(ELogLevel.INFO, "elasticSearch URL: " + elasticSearchURL); } catch (Exception ex) { ESI4TLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace); throw; } }
public DataContracts.IndexResponse AddDocument(IndexRequest query) { ESI4TLogger.WriteLog(ELogLevel.INFO, "Entering ESI4TIndexManager.AddDocument for TCM URI: " + query.ItemURI); DataContracts.IndexResponse response = new DataContracts.IndexResponse(); OperationResult result = OperationResult.Failure; try { XmlDocument doc = new XmlDocument(); string ID = string.Empty; doc.LoadXml(Utility.UpdateContentTypeXML(Regex.Replace(query.DCP.ToString(), @"\b'\b", ""))); string jsonText = JsonConvert.SerializeXmlNode(doc); // var bln = Deserialize<Esnews>(doc); var conString = ESI4TServicesConstants.elasticSearch_URL; ESI4TLogger.WriteLog(ELogLevel.INFO, "conString: " + conString); node = new Uri(conString); settings = new ConnectionSettings(node); settings.DefaultIndex("fromelasticstoweb8"); var client = new Nest.ElasticClient(settings); var indexResponse = client.LowLevel.Index <string>("fromelasticstoweb8", "esnews", jsonText); // var responseBool = client.Index(bln); result = OperationResult.Success; } catch (Exception ex) { string logString = ESI4TServiceConstants.LOG_MESSAGE + Environment.NewLine; logString = string.Concat(logString, Environment.NewLine, string.Format("{0}{1}", ex.Message, ex.StackTrace)); ESI4TLogger.WriteLog(ELogLevel.ERROR, logString); result = OperationResult.Failure; } response.Result = (int)result; ESI4TLogger.WriteLog(ELogLevel.INFO, "Exiting ESI4TIndexManager.AddDocument, Result: " + result.ToString()); return(response); }
/// <summary> /// Singleton ESI4TIndexManager static constructor /// </summary> static ESI4TIndexManager() { try { string ElasticIndexConfigPath = Utility.GetConfigurationValue("SearchIndexServiceConfig"); propConfiguration = ConfigurationManager.GetInstance().GetConfiguration(ElasticIndexConfigPath) as IPropertyConfiguration; containerLock = new object(); ESI4TLogger.WriteLog(ELogLevel.DEBUG, "Config Path: " + ElasticIndexConfigPath); } catch (Exception ex) { ESI4TLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace); throw ex; } ESI4TLogger.WriteLog(ELogLevel.DEBUG, "Exiting ESI4TIndexManager.ESI4TIndexManager()"); }
public ESI4TServiceResponse <IndexResponse> AddDocument(ESI4TServiceRequest <IndexRequest> query) { ESI4TLogger.WriteLog(ELogLevel.INFO, "Enter into method IndexService.AddDocumnet()"); ESI4TServiceResponse <IndexResponse> serviceResponse = new ESI4TServiceResponse <IndexResponse>(); try { string language = query.ServicePayload.LanguageInRequest; IndexResponse resultValue; ESI4TIndexManager indexManager = new ESI4TIndexManager(language); resultValue = indexManager.AddDocument(query.ServicePayload); ESI4TLogger.WriteLog(ELogLevel.INFO, "AddDocumnet is called publish is true"); serviceResponse.ServicePayload = resultValue; } catch (Exception ex) { serviceResponse.ServicePayload = new IndexResponse(); serviceResponse.ServicePayload.Result = 1; serviceResponse.ServicePayload.ErrorMessage = "AddDocumnet is not called ispublish is false"; ESI4TLogger.WriteLog(ELogLevel.INFO, "AddDocumnet is not called ispublish is false" + ex.Message); } return(serviceResponse); }
/// <summary> /// This method removes an index from Elastic /// </summary> /// <param name="query">IndexRequest containing delete criteria</param> /// <returns>IndexResponse indicating success or failure</returns> public DataContracts.IndexResponse RemoveDocument(IndexRequest query) { ESI4TLogger.WriteLog(ELogLevel.INFO, "Entering ESI4TIndexManager.RemoveDocument for TCM URI: " + query.ItemURI); DataContracts.IndexResponse response = new DataContracts.IndexResponse(); JavaScriptSerializer serializer = new JavaScriptSerializer(); serializer.MaxJsonLength = Int32.MaxValue; var webClient = new WebClient(); OperationResult result = OperationResult.Failure; try { XmlDocument doc = new XmlDocument(); string ID = query.ItemURI; string strId = "\"" + ID + "\""; var content = webClient.DownloadString(@"http://*****:*****@"\b'\b", ""))); foreach (var item in data) { var aa = item; if (aa.Key == "hits") { foreach (var item2 in aa.Value) { var aaaa = item2; if (aaaa.Key == "hits") { foreach (var item3 in aaaa.Value) { foreach (var item4 in item3) { if (item4.Key == "_id") { Id = item4.Key; idValue = item4.Value; } } } } } } } //var bln = Deserialize<Esnews>(doc); node = new Uri("http://localhost:9200"); settings = new ConnectionSettings(node); settings.DefaultIndex("fromelasticstoweb8"); var client = new Nest.ElasticClient(settings); var responseReturn = client.Delete <Esnews>(idValue, d => d .Index("fromelasticstoweb8") .Type("esnews")); result = OperationResult.Success; ESI4TLogger.WriteLog(ELogLevel.INFO, "Exit ESI4TIndexManager.RemoveDocument for TCM URI: " + query.ItemURI + " result " + result); } catch (Exception ex) { string logString = ESI4TServiceConstants.LOG_MESSAGE + Environment.NewLine; logString = string.Concat(logString, string.Format("Item URI : {0}", query.ItemURI), Environment.NewLine, string.Format("{0}{1}", ex.Message, ex.StackTrace)); ESI4TLogger.WriteLog(ELogLevel.ERROR, logString); result = OperationResult.Failure; } response.Result = (int)result; ESI4TLogger.WriteLog(ELogLevel.INFO, "Exiting ESI4TIndexManager.RemoveDocument, Result: " + result.ToString()); return(response); }
private static void LogException(ESI4TIndexingException ampException) { ESI4TLogger.WriteLog(ELogLevel.ERROR, ampException.Message + ", Code " + ampException.Code); }