Exemplo n.º 1
0
        /// <summary>
        /// Create search index for the selected database. One index per site language will be created.
        /// </summary>
        /// <param name="database"></param>
        private void CreateIndex(string database)
        {
            if (string.IsNullOrEmpty(database))
            {
                return;
            }

            PXWeb.DatabaseSettings    db          = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.GetDatabase(database);
            PXWeb.SearchIndexSettings searchIndex = (PXWeb.SearchIndexSettings)db.SearchIndex;

            // Check that the status has not been changed by another system before updating it
            if (searchIndex.Status != SearchIndexStatusType.Indexing)
            {
                searchIndex.Status = SearchIndexStatusType.WaitingCreate;
                db.Save();

                if (PXWeb.Settings.Current.Features.General.BackgroundWorkerEnabled)
                {
                    // Wake up the background worker if it is asleep
                    BackgroundWorker.PxWebBackgroundWorker.WakeUp();
                }
            }

            ReadSettings();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Check if it is possible to create new search index
        /// </summary>
        /// <param name="o">Database object</param>
        /// <returns>Search index status string</returns>
        protected bool CheckIndexStatus(object o)
        {
            DatabaseInfo dbInfo = (DatabaseInfo)o;

            if (dbInfo == null)
            {
                return(false);
            }

            if (!PXWeb.Settings.Current.Database.ContainsKey(dbInfo.Id))
            {
                return(true);
            }

            PXWeb.DatabaseSettings db = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.Database[dbInfo.Id];
            if (db == null)
            {
                return(false);
            }

            PXWeb.SearchIndexSettings searchIndex = (PXWeb.SearchIndexSettings)db.SearchIndex;
            if (searchIndex == null)
            {
                return(false);
            }

            if (searchIndex.Status == SearchIndexStatusType.Indexing ||
                searchIndex.Status == SearchIndexStatusType.WaitingCreate ||
                searchIndex.Status == SearchIndexStatusType.WaitingUpdate)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get string representing the status of the search index associated with the database
        /// </summary>
        /// <param name="o">Database object</param>
        /// <returns>Search index status string</returns>
        protected string IndexStatus(object o)
        {
            DatabaseInfo dbInfo = (DatabaseInfo)o;

            if (dbInfo == null)
            {
                return("");
            }

            if (!PXWeb.Settings.Current.Database.ContainsKey(dbInfo.Id))
            {
                // Handle unselected CNMM databases without a database folder
                return("");
            }

            //PXWeb.DatabaseSettings db = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.Database[dbInfo.Id];
            PXWeb.DatabaseSettings db = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.GetDatabase(dbInfo.Id);
            if (db == null)
            {
                return("");
            }

            PXWeb.SearchIndexSettings searchIndex = (PXWeb.SearchIndexSettings)db.SearchIndex;
            if (searchIndex == null)
            {
                return("");
            }

            if (searchIndex.Status == SearchIndexStatusType.Indexed)
            {
                return(searchIndex.IndexUpdated.PxDate(true));
            }

            return(searchIndex.Status.ToString());
        }
Exemplo n.º 4
0
        public HttpResponseMessage RebuildMenu(string database, bool languageDependent = true, string sortBy = "Title", bool buildSearchIndex = true)
        {
            var statusCode = HttpStatusCode.Created;
            List <DatabaseMessage> result = null;

            _logger.Info("RebuildMenu - started");
            try
            {
                string path;

                path = System.Web.HttpContext.Current.Server.MapPath(Settings.Current.General.Paths.PxDatabasesPath);
                path = System.IO.Path.Combine(path, database);


                result = AdminTool.GenerateDatabase(path, languageDependent, sortBy);

                // Clear all caches
                PXWeb.Management.PxContext.CacheController.Clear();

                //Force that databases are read again
                PXWeb.DatabasesSettings databases = (PXWeb.DatabasesSettings)PXWeb.Settings.Current.General.Databases;
                databases.ResetDatabases();

                if (PXWeb.Settings.Current.Features.General.SearchEnabled && buildSearchIndex)
                {
                    PXWeb.DatabaseSettings    db          = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.GetDatabase(database);
                    PXWeb.SearchIndexSettings searchIndex = (PXWeb.SearchIndexSettings)db.SearchIndex;

                    // Check that the status has not been changed by another system before updating it
                    if (searchIndex.Status != SearchIndexStatusType.Indexing)
                    {
                        searchIndex.Status = SearchIndexStatusType.WaitingCreate;
                        db.Save();

                        BackgroundWorker.PxWebBackgroundWorker.HandleSearchIndex(database);
                    }
                }
                _logger.Info("RebuildMenu - finished without error");
            }
            catch (Exception e)
            {
                statusCode = HttpStatusCode.InternalServerError;
                _logger.Error(e.Message);
            }
            return(Request.CreateResponse(statusCode, result));
        }
Exemplo n.º 5
0
        private void InitializeSearch()
        {
            pxSearch.RedirectOnSearch = true;
            if (PXWeb.Settings.Current.Features.General.SearchEnabled == false)
            {
                pxSearch.Visible = false;
                return;
            }

            IPxUrl url = RouteInstance.PxUrlProvider.Create(null);

            //PXWeb.DatabaseSettings db = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.GetDatabase(url.Database);
            PXWeb.DatabaseSettings    db          = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.GetDatabaseSettings(url.Database);
            PXWeb.SearchIndexSettings searchIndex = (PXWeb.SearchIndexSettings)db.SearchIndex;

            if (searchIndex.Status == SearchIndexStatusType.NotIndexed)
            {
                pxSearch.Visible = false;
            }
        }
Exemplo n.º 6
0
        protected void btnGenerate_Click(object sender, EventArgs e)
        {
            string path;

            path = Server.MapPath(Settings.Current.General.Paths.PxDatabasesPath);
            path = System.IO.Path.Combine(path, cboSelectDb.SelectedValue);

            bool langDependent = false;

            if (string.Compare(cboLanguageDependent.SelectedValue, "true", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                langDependent = true;
            }

            // Clear all caches
            PXWeb.Management.PxContext.CacheController.Clear();

            grdResult.DataSource = AdminTool.GenerateDatabase(path, langDependent, cboSortOrder.SelectedValue);
            grdResult.DataBind();

            //Force that databases are read again
            PXWeb.DatabasesSettings databases = (PXWeb.DatabasesSettings)PXWeb.Settings.Current.General.Databases;
            databases.ResetDatabases();

            if (PXWeb.Settings.Current.Features.General.SearchEnabled)
            {
                if (chkCreateIndex.Checked)
                {
                    PXWeb.DatabaseSettings    db          = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.GetDatabase(cboSelectDb.SelectedValue);
                    PXWeb.SearchIndexSettings searchIndex = (PXWeb.SearchIndexSettings)db.SearchIndex;

                    // Check that the status has not been changed by another system before updating it
                    if (searchIndex.Status != SearchIndexStatusType.Indexing)
                    {
                        searchIndex.Status = SearchIndexStatusType.WaitingCreate;
                        db.Save();
                    }
                    InfoBox.Visible = true;
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Check if search index shall be created for database (SearchIndex.Status = Waiting). If so create the search index
        /// </summary>
        /// <param name="database">Database id</param>
        public static void HandleSearchIndex(string database)
        {
            if (_run == false)
            {
                return;
            }

            PXWeb.DatabaseSettings    db          = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.GetDatabase(database);
            PXWeb.SearchIndexSettings searchIndex = (PXWeb.SearchIndexSettings)db.SearchIndex;

            _logger.InfoFormat("HandleSearchIndex called for database:{0}", database);
            if (searchIndex.Status == SearchIndexStatusType.WaitingCreate)
            {
                CreateSearchIndex(database);
            }
            else if (searchIndex.Status == SearchIndexStatusType.WaitingUpdate)
            {
                UpdateSearchIndex(database);
            }
            else
            {
                _logger.InfoFormat("No action taken for  database:{0}", database);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Update search index
        /// </summary>
        /// <param name="database"></param>
        private static void UpdateSearchIndex(string database)
        {
            _activity = "Updating search index for the " + database + " database";

            bool success = true;

            PXWeb.DatabaseSettings    db          = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.GetDatabase(database);
            PXWeb.SearchIndexSettings searchIndex = (PXWeb.SearchIndexSettings)db.SearchIndex;
            DateTime dateFrom;

            // Get start values. If something goes wrong we may need to restore these values
            SearchIndexStatusType startStatus = searchIndex.Status;
            string startUpdated = searchIndex.IndexUpdated;

            if (PxDate.IsPxDate(searchIndex.IndexUpdated))
            {
                dateFrom = PxDate.PxDateStringToDateTime(searchIndex.IndexUpdated);
            }
            else
            {
                dateFrom = DateTime.Now;
            }

            try
            {
                searchIndex.Status = SearchIndexStatusType.Indexing;
                db.Save();

                foreach (LanguageSettings lang in PXWeb.Settings.Current.General.Language.SiteLanguages)
                {
                    List <PCAxis.Search.TableUpdate> lst = searchIndex.UpdateMethod.GetUpdatedTables(dateFrom, "ssd_extern_test", lang.Name);

                    if (lst.Count > 0)
                    {
                        if (SearchManager.Current.UpdateIndex(database, lang.Name, lst))
                        {
                            _logger.Info("Successfully updated the " + database + " - " + lang.Name + " search index");
                        }
                        else
                        {
                            _logger.Error("Failed to update the " + database + " - " + lang.Name + " search index");
                            success = false;
                            return;
                        }
                    }
                }

                if (success)
                {
                    searchIndex.Status       = SearchIndexStatusType.Indexed;
                    searchIndex.IndexUpdated = DateTime.Now.ToString(PXConstant.PXDATEFORMAT);
                    _logger.Info("Search index was successfully updated for the '" + database + "' database");
                }
                else
                {
                    // Restore values...
                    searchIndex.Status       = startStatus;
                    searchIndex.IndexUpdated = startUpdated;
                    _logger.Error("Failed to update search index for the '" + database + "' database");
                }

                db.Save();
            }
            catch (Exception ex)
            {
                _logger.Error("Error when updating the search index for the '" + database + "' database : " + ex.Message);

                // Restore values...
                searchIndex.Status       = startStatus;
                searchIndex.IndexUpdated = startUpdated;
                db.Save();
            }

            // Force reload of database settings
            db = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.GetDatabase(database);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Create new search index
        /// </summary>
        /// <param name="database"></param>
        private static void CreateSearchIndex(string database)
        {
            _activity = "Creating search index for the " + database + " database";

            bool success = true;

            PXWeb.DatabaseSettings    db          = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.GetDatabase(database);
            PXWeb.SearchIndexSettings searchIndex = (PXWeb.SearchIndexSettings)db.SearchIndex;

            // Get start values. If something goes wrong we may need to restore these values
            SearchIndexStatusType startStatus = searchIndex.Status;
            string startUpdated = searchIndex.IndexUpdated;

            searchIndex.Status = SearchIndexStatusType.Indexing;
            db.Save();

            try
            {
                foreach (LanguageSettings lang in PXWeb.Settings.Current.General.Language.SiteLanguages)
                {
                    DatabaseInfo dbi = PXWeb.Settings.Current.General.Databases.GetDatabase(database);
                    if (dbi.HasLanguage(lang.Name))
                    {
                        if (SearchManager.Current.CreateIndex(database, lang.Name))
                        {
                            _logger.Info("Successfully created the " + database + " - " + lang.Name + " search index");
                        }
                        else
                        {
                            _logger.Error("Failed to create the " + database + " - " + lang.Name + " search index");
                            //success = false;
                            //return;
                        }
                    }
                }

                if (success)
                {
                    searchIndex.Status       = SearchIndexStatusType.Indexed;
                    searchIndex.IndexUpdated = DateTime.Now.ToString(PXConstant.PXDATEFORMAT);
                    _logger.Info("Search index was successfully created for the '" + database + "' database");
                }
                else
                {
                    // Restore values...
                    searchIndex.Status       = startStatus;
                    searchIndex.IndexUpdated = startUpdated;
                    _logger.Error("Failed to create search index for the '" + database + "' database");
                }

                db.Save();
            }
            catch (Exception ex)
            {
                _logger.Error("Error when creating search index for the '" + database + "' database : " + ex.Message);
                _logger.Error("Details", ex);

                // Restore values...
                searchIndex.Status       = startStatus;
                searchIndex.IndexUpdated = startUpdated;
                db.Save();
            }

            // Force reload of database settings
            db = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.GetDatabase(database);
        }