Esempio n. 1
0
        private TableLink CreateTableLink(PCAxis.Paxiom.PXMeta meta, string path)
        {
            ItemSelection cid = new ItemSelection(System.IO.Path.GetDirectoryName(path.Substring(System.Web.HttpContext.Current.Server.MapPath(Settings.Current.General.Paths.PxDatabasesPath).Length)), path.Substring(System.Web.HttpContext.Current.Server.MapPath(Settings.Current.General.Paths.PxDatabasesPath).Length));
            //TableLink tbl = new TableLink(meta.DescriptionDefault ? meta.Description : meta.Title ?? meta.Description, meta.Matrix, meta.DescriptionDefault ? meta.Description : meta.Title ?? meta.Description, cid.Menu, cid.Selection, meta.Description ?? "",
            //                          LinkType.PX, TableStatus.AccessibleToAll, null, "", "", meta.TableID ?? "",
            //                          PresCategory.Official);


            //TableLink tbl = new TableLink(!string.IsNullOrEmpty(meta.Description) ? meta.Description : meta.Title, meta.Matrix, !string.IsNullOrEmpty(meta.Description) ? meta.Description : meta.Title, path.Substring(System.Web.HttpContext.Current.Server.MapPath(Settings.Current.General.Paths.PxDatabasesPath).Length), meta.Description ?? "",
            //                              LinkType.PX, TableStatus.AccessibleToAll, null, "", "", meta.TableID ?? "",
            //                              PresCategory.Official);

            TableLink tbl = new TableLink(!string.IsNullOrEmpty(meta.Description) ? meta.Description : meta.Title, meta.Matrix, _sortOrder(meta, path), cid.Menu, cid.Selection, meta.Description ?? "", LinkType.PX, TableStatus.AccessibleToAll, null, "", "", meta.TableID ?? "", PresCategory.Official);

            int cellCount = 1;

            for (int i = 0; i < meta.Variables.Count; i++)
            {
                tbl.SetAttribute("Var" + (i + 1) + "Name", meta.Variables[i].Name);
                tbl.SetAttribute("Var" + (i + 1) + "Values", GetNames(meta.Variables[i]));
                tbl.SetAttribute("Var" + (i + 1) + "NumberOfValues", meta.Variables[i].Values.Count.ToString());
                cellCount *= meta.Variables[i].Values.Count;
            }

            System.IO.FileInfo info = new System.IO.FileInfo(path);
            tbl.SetAttribute("size", info.Length);
            tbl.SetAttribute("cells", cellCount.ToString());

            if (meta.AutoOpen)
            {
                tbl.SetAttribute("autoOpen", "true");
            }
            //TODO Use Data format
            //tbl.SetAttribute("updated", info.LastWriteTime.ToString());

            // Store dates in the PC-Axis date format
            tbl.SetAttribute("updated", info.LastWriteTime.ToString(PCAxis.Paxiom.PXConstant.PXDATEFORMAT));
            tbl.SetAttribute("modified", GetLastModified(meta));

            string lastUpdated = GetLastModified(meta);

            if (PxDate.IsPxDate(lastUpdated))
            {
                tbl.LastUpdated = PxDate.PxDateStringToDateTime(lastUpdated);
            }
            tbl.Published = info.LastWriteTime;

            return(tbl);
        }
Esempio n. 2
0
        private DateTime GetPublished(Document doc)
        {
            DateTime published    = DateTime.MinValue;
            string   publishedStr = doc.Get(SearchConstants.SEARCH_FIELD_PUBLISHED);

            if (!string.IsNullOrEmpty(publishedStr))
            {
                if (PxDate.IsPxDate(publishedStr))
                {
                    published = publishedStr.PxDateStringToDateTime();
                }
            }

            return(published);
        }
Esempio n. 3
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);
        }