Beispiel #1
0
        public MI4TServiceResponse <IndexResponse> RemoveDocument(MI4TServiceRequest <IndexRequest> query)
        {
            MI4TLogger.WriteLog(ELogLevel.INFO, "Entering into method IndexService.RemoveDocument");
            MI4TServiceResponse <IndexResponse> serviceResponse = new MI4TServiceResponse <IndexResponse>();

            try
            {
                //serviceResponse.ServicePayload = new IndexResponse();
                //serviceResponse.ServicePayload.Result = 1;
                MI4TLogger.WriteLog(ELogLevel.INFO, "RemoveDocument is  called publish is true1 ");

                IndexResponse    resultValue;
                MI4TIndexManager indexManager = new MI4TIndexManager(query.ServicePayload.LanguageInRequest);
                resultValue = indexManager.RemoveDocument(query.ServicePayload);
                serviceResponse.ServicePayload = resultValue;
                MI4TLogger.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";
                MI4TLogger.WriteLog(ELogLevel.INFO, "RemoveDocument is not called ispublish is false");
                string logString = MI4TServiceConstants.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));
                MI4TLogger.WriteLog(ELogLevel.ERROR, logString);
                CatchException <IndexResponse>(ex, serviceResponse);
            }
            MI4TLogger.WriteLog(ELogLevel.INFO, "Exiting from method IndexService.RemoveDocument");
            return(serviceResponse);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="uriList"></param>
        /// <returns></returns>
        public static List <XmlDocument> GetComponents(string[] uriList)
        {
            List <XmlDocument> componentList = null;

            if (uriList != null && uriList.Length > 0)
            {
                componentList = new List <XmlDocument>();
                foreach (string uri in uriList)
                {
                    try
                    {
                        XmlDocument doc = GetComponent(uri);
                        if (doc != null)
                        {
                            componentList.Add(doc);
                        }
                    }
                    catch (Exception ex)
                    {
                        //Log Warning Here and just move
                        MI4TLogger.WriteLog(ELogLevel.WARN, "Error in getting component list: " + ex.Message + ex.StackTrace);
                    }
                }
                return(componentList);
            }
            else
            {
                return(componentList);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new Link instance and returnes this as a string
        /// </summary>
        /// <param name="title">Attribute to include in the link as string</param>
        /// //example<a href="..">title</a>
        /// <param name="tcmuri">tcmUri of the Component as string</param>
        /// <returns>url string</returns>
        public static string ComponentLinkMethod(string tcmuri)
        {
            MI4TLogger.WriteLog(ELogLevel.INFO, "Entering method TridionDataHelper.ComponentLinkMethod");
            ComponentLink componentLink = null;
            Link          link          = null;
            int           publicationID;
            String        linkUrl = string.Empty;

            try
            {
                publicationID = TridionDataHelper.GetContentRepositoryId(tcmuri);
                MI4TLogger.WriteLog(ELogLevel.DEBUG, "Publication ID: " + publicationID);
                componentLink = new ComponentLink(publicationID);
                link          = componentLink.GetLink(tcmuri);
                MI4TLogger.WriteLog(ELogLevel.DEBUG, "ComponentLink: " + link);
                if (link.IsResolved)
                {
                    linkUrl = link.Url;
                }
                MI4TLogger.WriteLog(ELogLevel.INFO, "Link URL : " + linkUrl);
            }
            catch (Exception ex)
            {
                MI4TLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace);
            }
            finally
            {
                componentLink.Dispose();
                componentLink = null;
                link          = null;
            }

            MI4TLogger.WriteLog(ELogLevel.INFO, "Exiting method TridionDataHelper.ComponentLinkMethod");
            return(linkUrl);
        }
Beispiel #4
0
        /// <summary>
        /// GetContentRepositoryId shall return the Publication Id from TCM URI
        /// </summary>
        /// <param name="URI"></param>
        /// <returns></returns>
        public static int GetContentRepositoryId(string URI)
        {
            int contentRepositoryId;

            if (!string.IsNullOrEmpty(URI))
            {
                // Todo: optimize regex expression
                Regex tcmURIPattern          = new Regex(TCM_URI_PATTERN);
                Regex tcmURIComponentPattern = new Regex(TCM_URI_COMPONENT_PATTERN);
                if (!(tcmURIPattern.IsMatch(URI)) && !(tcmURIComponentPattern.IsMatch(URI)))
                {
                    string logString = "An error has occurred. The request trace is: " + Environment.NewLine;
                    logString = string.Concat(logString, string.Format("Invalid Item URI:{0}", URI));
                    MI4TLogger.WriteLog(ELogLevel.WARN, logString);
                    throw new MI4TIndexingException(TCM_URI_INVALID_CODE, TCM_URI_INVALID_VALUE);
                }
                TCMURI uri = new TCMURI(URI);
                contentRepositoryId = uri.GetPublicationId();
            }
            else
            {
                contentRepositoryId = 0;
            }
            return(contentRepositoryId);
        }
Beispiel #5
0
        public IndexResponse AddDocument(IndexRequest query)
        {
            MI4TLogger.WriteLog(ELogLevel.INFO,
                                "Entering MI4TIndexManager.AddDocument for TCM URI: " +
                                query.ItemURI);

            IndexResponse response = new 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", "")));
                var bln = Deserialize <MongoDBModel>(doc);

                var conString = propConfiguration.GetString(MI4TServicesConstants.mongoDB_URL);
                MI4TLogger.WriteLog(ELogLevel.INFO, "conString: " +
                                    conString);
                /// creating MongoClient
                var client = new MongoClient(conString);

                ///Get the database
                var DB = client.GetDatabase(propConfiguration.GetString(MI4TServicesConstants.dbName));
                MI4TLogger.WriteLog(ELogLevel.INFO, "dbName: " +
                                    propConfiguration.GetString(MI4TServicesConstants.dbName));

                ///Get the collcetion from the DB in which you want to insert the data
                var collection = DB.GetCollection <MongoDBModel>(propConfiguration.GetString(MI4TServicesConstants.tableName));
                MI4TLogger.WriteLog(ELogLevel.INFO, "tableName: " +
                                    propConfiguration.GetString(MI4TServicesConstants.tableName));
                //var filter = Builders<MongoDBModel>.Filter.Eq("ItemURI", bln.ItemURI);
                //var result11 =  collection.Find(filter).ToListAsync();

                ///Insert data in to MongoDB
                collection.InsertOne(bln);
                result = OperationResult.Success;
            }
            catch (Exception ex)
            {
                string logString = MI4TServiceConstants.LOG_MESSAGE + Environment.NewLine;

                logString = string.Concat(logString,
                                          Environment.NewLine,
                                          string.Format("{0}{1}", ex.Message, ex.StackTrace));

                MI4TLogger.WriteLog(ELogLevel.ERROR, logString);
                result = OperationResult.Failure;
            }
            response.Result = (int)result;
            MI4TLogger.WriteLog(ELogLevel.INFO,
                                "Exiting MI4TIndexManager.AddDocument, Result: " +
                                result.ToString());

            return(response);
        }
Beispiel #6
0
        public static void HandleCustomException(Exception ex, string LogMessage)
        {
            MI4TIndexingException ampEx = ex as MI4TIndexingException;

            if (ampEx != null)
            {
                MI4TLogger.WriteLog(ELogLevel.WARN, LogMessage);
            }
            else
            {
                MI4TLogger.WriteLog(ELogLevel.ERROR, LogMessage);
            }
        }
Beispiel #7
0
 public MI4TIndexManager(string Langauge)
 {
     MI4TLogger.WriteLog(ELogLevel.INFO, "Entering MI4TIndexManager:" +
                         Langauge);
     try
     {
         string MongoDBURL = propConfiguration.GetString(MI4TServicesConstants.mongoDB_URL);
         MI4TLogger.WriteLog(ELogLevel.INFO, "Mongo URL: " + MongoDBURL);
     }
     catch (Exception ex)
     {
         MI4TLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace);
         throw;
     }
 }
Beispiel #8
0
 /// <summary>
 /// Singleton MI4TIndexManager static constructor
 /// </summary>
 static MI4TIndexManager()
 {
     try
     {
         string MongoDBIndexConfigPath = Utility.GetConfigurationValue("SearchIndexServiceConfig");
         propConfiguration = ConfigurationManager.GetInstance().GetConfiguration(MongoDBIndexConfigPath)
                             as IPropertyConfiguration;
         containerLock = new object();
         MI4TLogger.WriteLog(ELogLevel.DEBUG, "Config Path: " + MongoDBIndexConfigPath);
     }
     catch (Exception ex)
     {
         MI4TLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace);
         throw ex;
     }
     MI4TLogger.WriteLog(ELogLevel.DEBUG, "Exiting MI4TIndexManager.MI4TIndexManager()");
 }
Beispiel #9
0
        /// <summary>
        /// This method removes an index from Mongo
        /// </summary>
        /// <param name="query">IndexRequest containing delete criteria</param>
        /// <returns>IndexResponse indicating success or failure</returns>
        public IndexResponse RemoveDocument(IndexRequest query)
        {
            MI4TLogger.WriteLog(ELogLevel.INFO, "Entering MI4TIndexManager.RemoveDocument for TCM URI: " +
                                query.ItemURI);
            IndexResponse response = new IndexResponse();

            OperationResult result = OperationResult.Failure;

            try
            {
                MongoServerSettings settings = new MongoServerSettings();
                settings.Server = new MongoServerAddress("localhost", 27017);
                // Create server object to communicate with our server
                MongoServer server = new MongoServer(settings);

                MongoDatabase myDB = server.GetDatabase("customerDatabase");

                MongoCollection <BsonDocument> records = myDB.GetCollection <BsonDocument>("article");
                var query1 = Query.EQ("ItemURI", query.ItemURI);
                records.Remove(query1);

                result = OperationResult.Success;
                MI4TLogger.WriteLog(ELogLevel.INFO, "Exit MI4TIndexManager.RemoveDocument for TCM URI: " +
                                    query.ItemURI + " result " + result);
            }
            catch (Exception ex)
            {
                string logString = MI4TServiceConstants.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));
                MI4TLogger.WriteLog(ELogLevel.ERROR, logString);
                result = OperationResult.Failure;
            }

            response.Result = (int)result;

            MI4TLogger.WriteLog(ELogLevel.INFO,
                                "Exiting MI4TIndexManager.RemoveDocument, Result: " +
                                result.ToString());

            return(response);
        }
Beispiel #10
0
        public MI4TServiceResponse <IndexResponse> AddDocument(MI4TServiceRequest <IndexRequest> query)
        {
            MI4TLogger.WriteLog(ELogLevel.INFO, "Enter into method IndexService.AddDocumnet()");
            MI4TServiceResponse <IndexResponse> serviceResponse = new MI4TServiceResponse <IndexResponse>();

            try
            {
                string        language = query.ServicePayload.LanguageInRequest;
                IndexResponse resultValue;

                MI4TIndexManager indexManager = new MI4TIndexManager(language);
                resultValue = indexManager.AddDocument(query.ServicePayload);
                MI4TLogger.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";
                MI4TLogger.WriteLog(ELogLevel.INFO, "AddDocumnet is not called ispublish is false" + ex.Message);
            }
            return(serviceResponse);
        }
Beispiel #11
0
        public Stream GetContentFromMongoDB(MI4TServiceRequest <SearchRequest> request)
        {
            string resultJSON = string.Empty;

            MI4TLogger.WriteLog(ELogLevel.INFO, "Entering into GetContentFromMongoDB");
            try
            {
                if (request != null && request.ServicePayload != null)
                {
                    string MongoDBIndexConfigPath = Utility.GetConfigurationValue("IndexServiceConfig");
                    propConfiguration = ConfigurationManager.GetInstance().GetConfiguration(MongoDBIndexConfigPath)
                                        as IPropertyConfiguration;
                    containerLock = new object();
                    string result           = string.Empty;
                    var    connectionString = propConfiguration.GetString(MI4TServicesConstants.mongoDB_URL);
                    var    client           = new MongoClient(connectionString);
                    var    server           = client.GetServer();
                    var    database         = server.GetDatabase(propConfiguration.GetString(MI4TServicesConstants.dbName));
                    var    collection       = database.GetCollection <MongoDBModelSearch>(propConfiguration.GetString(MI4TServicesConstants.tableName));

                    var andList = new List <IMongoQuery>();
                    foreach (DictionaryEntry entry in request.ServicePayload.Filters)
                    {
                        MI4TLogger.WriteLog(ELogLevel.INFO, "Reading request.ServicePayload.Filters");
                        switch (request.ServicePayload.QueryType.ToUpper())
                        {
                        case "AND":
                            andList.Add(Query.EQ(entry.Key.ToString(), entry.Value.ToString()));
                            break;

                        case "OR":
                            andList.Add(Query.Or(Query.EQ(entry.Key.ToString(), entry.Value.ToString())));
                            break;

                        default:
                            andList.Add(Query.Not(Query.EQ(entry.Key.ToString(), entry.Value.ToString())));
                            break;
                        }
                    }
                    var query = Query.And(andList);
                    MI4TLogger.WriteLog(ELogLevel.INFO, "Query generated");
                    //Map/Reduce
                    var map =
                        "function() {" +
                        "    for (var key in this) {" +
                        "        emit(key, { count : 1 });" +
                        "    }" +
                        "}";

                    var reduce =
                        "function(key, emits) {" +
                        "    total = 0;" +
                        "    for (var i in emits) {" +
                        "        total += emits[i].count;" +
                        "    }" +
                        "    return { count : total };" +
                        "}";

                    var mr = collection.MapReduce(map, reduce);
                    foreach (var document in mr.GetResults())
                    {
                        document.ToJson();
                    }

                    MI4TLogger.WriteLog(ELogLevel.INFO, "Calling collection.FindOne(query)");
                    //  var entity = collection.Find(query).ToListAsync();
                    var result1 = collection.FindAs <MongoDBModelSearch>(query);
                    resultJSON = result1.ToJson();

                    MI4TLogger.WriteLog(ELogLevel.INFO, "OUTPUT: " + resultJSON);
                }
            }
            catch (Exception ex)
            {
                MI4TLogger.WriteLog(ELogLevel.ERROR, "ERROR: " + ex.Message + ex.StackTrace);
            }
            return(new MemoryStream(Encoding.UTF8.GetBytes(resultJSON)));
        }
Beispiel #12
0
 private static void LogException(MI4TIndexingException ampException)
 {
     MI4TLogger.WriteLog(ELogLevel.ERROR, ampException.Message + ", Code " + ampException.Code);
 }