Beispiel #1
0
        public static MenuObject Create(Item item)
        {
            if (item is null)
            {
                return(null);
            }

            MenuObject menu = new MenuObject();

            menu.ID       = item.ID;
            menu.MenuType = item.GetType();

            if (item is PxMenuItem)
            {
                PxMenuItem mi = (PxMenuItem)item;
                menu.HasSubItems = mi.HasSubItems;

                if (menu.HasSubItems)
                {
                    menu.MetaList = GetMetaList(mi);
                }
            }
            else
            {
                menu.HasSubItems = false;
            }

            return(menu);
        }
Beispiel #2
0
 public static IEnumerable <MetaList> GetMetaList(this PxMenuItem item)
 {
     return(item.SubItems.Select(i => new MetaList
     {
         Id = i.ID.Selection.Replace('\\', '/'),
         Text = i.Text,
         Type = i.GetMetaListType(),
         Updated = i is TableLink ? (((TableLink)i).Published) : null
     }));
 }
Beispiel #3
0
        public void BeginNewLevel(string id)
        {
            string name = System.IO.Path.GetFileNameWithoutExtension(id);

            foreach (var language in _languages)
            {
                ItemSelection cid     = new ItemSelection(System.IO.Path.GetDirectoryName(id.Substring(System.Web.HttpContext.Current.Server.MapPath(Settings.Current.General.Paths.PxDatabasesPath).Length)), id.Substring(System.Web.HttpContext.Current.Server.MapPath(Settings.Current.General.Paths.PxDatabasesPath).Length));
                PxMenuItem    newItem = new PxMenuItem(null, name, "", name, cid.Menu, cid.Selection, "");
                _currentItems[language].AddSubItem(newItem);
                _currentItems[language] = newItem;
                _links.Add(newItem, new List <string>());
            }
        }
Beispiel #4
0
        /// <summary>
        /// Returns a list of metadata for the specified item
        /// </summary>
        /// <param name="item"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        private IEnumerable <MetaList> GetMetaList(HttpContext context, PxMenuItem item)
        {
            // Logs usage
            _usageLogger.Info(String.Format("url={0}, type=metadata, caller={1}, cached=false", context.Request.RawUrl, context.Request.UserHostAddress));

            return(item.SubItems.Select(i => new MetaList
            {
                Id = i.ID.Selection.Replace('\\', '/'),
                Text = i.Text,
                Type = GetMetaListType(i),
                Updated = i is TableLink ? (((TableLink)i).Published) : null
            }));
        }
Beispiel #5
0
        /// <summary>
        /// Creates all the root nodes for each language
        /// </summary>
        /// <param name="path"></param>
        public void BeginBuild(string path, DatabaseLogger logger)
        {
            _logger4Net.InfoFormat("Start building menu for {0}", path);
            _logger = logger;
            //TODO set use Date format
            _rootPath = System.IO.Path.GetDirectoryName(path) + "\\";
            _databaseName = System.IO.Path.GetFileName(path);
            _logger(new DatabaseMessage() { MessageType = DatabaseMessage.BuilderMessageType.Information, Message = "Menu build started " + DateTime.Now.ToString() });
            string folderName = System.IO.Path.GetFileNameWithoutExtension(path);
            foreach (var language in _languages)
            {
                PxMenuItem root = new PxMenuItem(null, System.IO.Path.GetDirectoryName(path), folderName, folderName, folderName, path, "");
                _languageRoots.Add(language, root);
                _currentItems.Add(language, root);
                _links.Add(root, new List<string>());
            }

        }
Beispiel #6
0
 private bool HasLinks(PxMenuItem item)
 {
     for (int i = 0; i < item.SubItems.Count; i++)
     {
         Item itm = item.SubItems[i];
         if (itm is Link)
         {
             return(true);
         }
         else if (itm is PxMenuItem)
         {
             if (HasLinks((PxMenuItem)itm))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #7
0
        /// <summary>
        /// Creates all the root nodes for each language
        /// </summary>
        /// <param name="path"></param>
        public void BeginBuild(string path, DatabaseLogger logger)
        {
            _logger4Net.InfoFormat("Start building menu for {0}", path);
            _logger = logger;
            //TODO set use Date format
            _logger(new DatabaseMessage()
            {
                MessageType = DatabaseMessage.BuilderMessageType.Information, Message = "Menu build started " + DateTime.Now.ToString()
            });
            string folderName = System.IO.Path.GetFileNameWithoutExtension(path);

            foreach (var language in _languages)
            {
                PxMenuItem root = new PxMenuItem(null, System.IO.Path.GetDirectoryName(path), folderName, folderName, folderName, path, "");
                _languageRoots.Add(language, root);
                _currentItems.Add(language, root);
                _links.Add(root, new List <string>());
            }
        }
Beispiel #8
0
 public void EndNewLevel(string id)
 {
     foreach (var language in _languages)
     {
         PxMenuItem item = _currentItems[language];
         if (item.Parent == null)
         {
             _currentItems[language] = _languageRoots[language];
         }
         else
         {
             _currentItems[language] = (PxMenuItem)item.Parent;
         }
         //there is no tables or other links remove node
         if (!HasLinks(item))
         {
             _currentItems[language].SubItems.Remove(item);
         }
     }
 }
Beispiel #9
0
        /// <summary>
        /// Sets the current selection and retrieves the items subitems.
        /// </summary>
        /// <param name="menu">The menu of the item to select</param>
        /// <param name="selection">The selection of the item to select</param>
        /// <returns></returns>
        public override bool SetCurrentItemBySelection(string menu, string selection)
        {
            if (base.SetCurrentItemBySelection(menu, selection))
            {
                Item item = RootItem.FindSelection(menu, selection);

                if (item is PxMenuItem)
                {
                    PxMenuItem menuItem = (PxMenuItem)item;
                    if (!menuItem.HasBeenLoaded())
                    {
                        Load(menuItem);
                    }
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Beispiel #10
0
        /// <summary>
        /// Checks if a link shall be added or not. If this check is not done a link may be added
        /// twice for the default language - which is wrong.
        /// </summary>
        /// <param name="path">Path to the .link-file</param>
        /// <param name="itm">MenuItem object that the link shall be added to</param>
        /// <returns></returns>
        private bool CheckIfLinkShallBeAdded(string path, PxMenuItem itm)
        {
            string filename = System.IO.Path.GetFileNameWithoutExtension(path);
            int    index    = filename.IndexOf("_");


            if ((index != -1) && (index > 0))
            {
                //Remove the language-specific part of the filename (for example: "_en" or "_sv")
                filename = filename.Substring(0, index);
            }

            if (_links[itm].Contains(filename))
            {
                return(false);
            }
            else
            {
                _links[itm].Add(filename);
                return(true);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Constructor to be called from sub classses.
        /// </summary>
        /// <param name="parameterChar">Char used to indicate binding variables in database. This value should in NO WAY originate from the GUI!</param>
        /// <param name="language">Language code for this context</param>
        /// <param name="initializationFunction">Function for initializing this instance</param>
        protected DatamodelMenu(char parameterChar, string language, DatamodelMenuInitialization initializationFunction)
        {
            log.DebugFormat("Creating instance with parameterchar, language: {0}, {1}", parameterChar, language);

            Language           = language;
            this.ParameterChar = parameterChar;

            if (initializationFunction != null)
            {
                log.Debug("Initialization supplied.");
                initializationFunction(this);
            }

            if (AlterSQL != null)
            {
                log.Debug("AlterSQL supplied.");
                OverrideSQL = AlterSQL(SQL);
            }

            RootItem = new PxMenuItem(this, "", "", "", RootSelection.Menu, RootSelection.Selection, "");
            SetCurrentItemBySelection(RootSelection.Menu, RootSelection.Selection);
        }
Beispiel #12
0
        /// <summary>
        /// Recursively traverse the database to add all tables as Document objects into the index
        /// </summary>
        /// <param name="itm">Current node in database to add Document objects for</param>
        /// <param name="writer">IndexWriter object</param>
        /// <param name="path">Path within the database for this node</param>
        private void TraverseDatabase(PCAxis.Web.Core.Enums.DatabaseType dbType, PxMenuItem itm, IndexWriter writer, string path)
        {
            PCAxis.Menu.Item       newItem;
            PCAxis.Menu.PxMenuBase db = _menuMethod(_database, itm.ID, _language, out newItem);
            PxMenuItem             m  = (PxMenuItem)newItem;

            if (m == null)
            {
                return;
            }

            foreach (var item in m.SubItems)
            {
                if (item is PxMenuItem)
                {
                    TraverseDatabase(dbType, item as PxMenuItem, writer, path + "/" + item.ID.Selection);
                }
                else if (item is TableLink)
                {
                    IndexTable(dbType, (TableLink)item, path, writer);
                }
            }
        }
Beispiel #13
0
        private Item parseXml(XElement element)
        {
            Item item = null;

            switch (element.Name.ToString())
            {
            case "MenuItem":
                item =
                    new PxMenuItem(
                        this,
                        element.Element("Text").Value,
                        element.Element("TextShort").Value,
                        element.Attribute("sortCode").Value,
                        element.Parent.Attribute("selection") != null ? element.Parent.Attribute("selection").Value : "",
                        element.Attribute("selection").Value,
                        element.Element("Description").Value
                        );

                XName[] subItemLabels = new XName[] { "MenuItem", "Headline", "Link" };

                item.Cast <PxMenuItem>().AddSubItemRange(
                    from e in element.Elements()
                    where subItemLabels.Contains(e.Name)
                    select parseXml(e)
                    );

                break;

            case "Headline":
                item =
                    new Headline(
                        element.Element("Text").Value,
                        element.Element("TextShort").Value,
                        element.Attribute("sortCode").Value,
                        element.Parent.Attribute("selection").Value,
                        element.Attribute("selection").Value,
                        element.Element("Description").Value
                        );

                break;

            case "Link":
                item =
                    new TableLink(
                        element.Element("Text").Value,
                        element.Element("TextShort").Value,
                        element.Attribute("sortCode").Value,
                        element.Parent.Attribute("selection").Value,
                        element.Attribute("selection").Value,
                        element.Element("Description").Value,
                        element.Attribute("type").Value.ToEnum <LinkType>(),
                        element.Attribute("status").Value == "" ? TableStatus.NotSet : (TableStatus)element.Attribute("status").Value[0],
                        element.Element("Published").Value == "" ? null : (DateTime?)DateTime.Parse(element.Element("Published").Value),
                        element.Element("LastUpdated").Value == "" ? null : (DateTime?)DateTime.Parse(element.Element("LastUpdated").Value),
                        element.Element("StartTime").Value,
                        element.Element("EndTime").Value,
                        element.Attribute("tableId").Value,
                        element.Attribute("category").Value == "" ? PresCategory.NotSet : (PresCategory)element.Attribute("category").Value[0]
                        );

                foreach (XElement a in element.Elements("Attribute"))
                {
                    item.Cast <Link>().SetAttribute(a.Attribute("name").Value, a.Value);
                }

                break;

            case "Url":
                item =
                    new Url(
                        element.Element("Text").Value,
                        element.Attribute("sortCode").Value,
                        element.Parent.Attribute("selection").Value,
                        element.Attribute("selection").Value,
                        element.Element("Description").Value,
                        element.Attribute("category").Value == "" ? PresCategory.NotSet : (PresCategory)element.Attribute("category").Value[0],
                        element.Element("Url").Value,
                        element.Attribute("linkPres").Value == "" ? LinkPres.NotSet : (LinkPres)element.Attribute("linkPres").Value[0]
                        );

                foreach (XElement a in element.Elements("Attribute"))
                {
                    item.Cast <Link>().SetAttribute(a.Attribute("name").Value, a.Value);
                }

                break;

            default:
                break;
            }

            if (item.IsNotOfType <Url>())
            {
                foreach (Url u in element.Elements("Url").Select(e => parseXml(e)))
                {
                    if (u != null)
                    {
                        item.AddUrl(u);
                    }
                }
            }

            item.ID.Menu = element.Parent.Attribute("selection") != null?element.Parent.Attribute("selection").Value : "";

            if (Restriction == null || Restriction(item))
            {
                if (AlterItemBeforeStorage != null)
                {
                    AlterItemBeforeStorage(item);
                }

                return(item);
            }
            else
            {
                return(null);
            }
        }
Beispiel #14
0
        private Item itemFromRow(DataRow row)
        {
            Item item;

            if (row["PRESENTATION"].ToString().ToUpper() == "P")
            {
                item =
                    new Headline(
                        row["PRESTEXT"].ToString(),
                        row["PRESTEXTS"].ToString(),
                        row["SORTCODE"].ToString(),
                        row["MENU"].ToString(),
                        row["SELECTION"].ToString(),
                        row["DESCRIPTION"].ToString()
                        );
            }
            else if (row["ITEMTYPE"].ToString() == "table")
            {
                item =
                    new TableLink(
                        row["PRESTEXT"].ToString(),
                        row["PRESTEXTS"].ToString(),
                        row["SORTCODE"].ToString(),
                        row["MENU"].ToString(),
                        row["SELECTION"].ToString(),
                        row["DESCRIPTION"].ToString(),
                        LinkType.Table,
                        row["TABLESTATUS"].ToString() == "" ? TableStatus.NotSet : (TableStatus)row["TABLESTATUS"].ToString().ToUpper()[0],
                        row["PUBLISHED"].ToString() == "" ? null : (DateTime?)DateTime.Parse(row["PUBLISHED"].ToString()),
                        row["LASTUPDATED"].ToString() == "" ? null : (DateTime?)DateTime.Parse(row["LASTUPDATED"].ToString()),
                        row["STARTTIME"].ToString(),
                        row["ENDTIME"].ToString(),
                        row["TABLEID"].ToString(),
                        row["CATEGORY"].ToString() == "" ? PresCategory.NotSet : (PresCategory)row["CATEGORY"].ToString().ToUpper()[0]
                        );
            }
            else if (row["ITEMTYPE"].ToString() == "menu")
            {
                item =
                    new PxMenuItem(
                        this,
                        row["PRESTEXT"].ToString(),
                        row["PRESTEXTS"].ToString(),
                        row["SORTCODE"].ToString(),
                        row["MENU"].ToString(),
                        row["SELECTION"].ToString(),
                        row["DESCRIPTION"].ToString()
                        );
            }
            else if (row["ITEMTYPE"].ToString() == "url")
            {
                item =
                    new Url(
                        row["PRESTEXT"].ToString(),
                        row["SORTCODE"].ToString(),
                        row["MENU"].ToString(),
                        row["LINKID"].ToString(),
                        row["DESCRIPTION"].ToString(),
                        (PresCategory)row["CATEGORY"].ToString().ToUpper()[0],
                        row["LINKURL"].ToString(),
                        (LinkPres)row["LINKPRES"].ToString().ToUpper()[0]
                        );
            }
            else
            {
                throw new Exceptions.NotValidItemFromDatabaseException("Row from database not valid for item creation.");
            }

            item.ID.Menu = row["MENU"].ToString();

            if (Restriction(item))
            {
                if (AlterItemBeforeStorage != null)
                {
                    AlterItemBeforeStorage(item);
                }

                return(item);
            }
            else
            {
                return(null);
            }
        }
Beispiel #15
0
        /// <summary>
        /// Loads properties and subitems for a certain MenuItem.
        /// </summary>
        /// <param name="menuItem">The item to update</param>
        /// <param name="numberOfLevels">Number of levels to retrieve from the database - overrides property NumberOfLevels</param>
        /// <returns></returns>
        protected void Load(PxMenuItem menuItem, int numberOfLevels)
        {
            //if (menuItem.HasSubItems)
            //    throw new ItemHasBeenLoadedException("DatamodelMenu does not allow subsequent loads on its MenuItems.");

            if (menuItem.HasBeenLoaded())
            {
                throw new ItemHasBeenLoadedException("DatamodelMenu does not allow subsequent loads on its MenuItems.");
            }

            menuItem.HasBeenLoaded(true);

            DataTable dataTable = GetDataTableBySelection(menuItem.ID.Menu, menuItem.ID.Selection, numberOfLevels, SQL, Parameters);

            List <Item> items = itemCollection(dataTable);

            Item self = null;

            if (menuItem.ID.Selection != "START")
            {
                self = items.FirstOrDefault(i => i is PxMenuItem && i.ID.ToString().Equals(menuItem.ID.ToString(), StringComparison.OrdinalIgnoreCase));

                if (self == null)
                {
                    menuItem.ID.Set("", "");
                    return;
                }

                menuItem.Text      = self.Text;
                menuItem.TextShort = self.TextShort;
                menuItem.SortCode  = self.SortCode;
                menuItem.ID.Set(self.ID.Values);
                menuItem.Description = self.Description;

                items.Remove(self);
            }

            PxMenuItem parent = null;

            for (int i = 0; i < items.Count; i++)
            {
                Item item = items[i];

                if (item.ID.Menu.Equals(menuItem.ID.Selection))
                {
                    parent = menuItem;
                }
                else if (item.ID.Menu != parent.ID.Selection)
                {
                    Item tempParent = items.Take(i).Last(x => x.ID.Selection.Equals(item.ID.Menu));

                    if (tempParent.IsNotOfType <PxMenuItem>())
                    {
                        if (tempParent.ID.Selection.Equals(item.ID.Menu))
                        {
                            throw new Exceptions.DatamodelMenuExtractedDataErrorException("Non-menu type item has subitem. Not allowed.");
                        }
                        else
                        {
                            throw new Exceptions.DatamodelMenuExtractedDataErrorException("Unable to find items parent in extracted data.");
                        }
                    }

                    parent = tempParent.Cast <PxMenuItem>();
                }

                if (parent == null)
                {
                    throw new Exceptions.DatamodelMenuExtractedDataErrorException("Unable to find items parent in extracted data.");
                }

                //TODO: Test Url?
                if (item is Url && !parent.Urls.Any(u => u.ID.Equals(item.ID)))
                {
                    parent.AddUrl(item.Cast <Url>());
                }
                else
                {
                    parent.HasBeenLoaded(true);
                    parent.AddSubItem(item);
                }
            }
        }
Beispiel #16
0
 /// <summary>
 /// Loads properties and subitems for a certain MenuItem.
 /// </summary>
 /// <param name="menuItem">The item to update</param>
 protected void Load(PxMenuItem menuItem)
 {
     Load(menuItem, NumberOfLevels);
 }
Beispiel #17
0
 public void BeginNewLevel(string id)
 {
     string name = System.IO.Path.GetFileNameWithoutExtension(id);
     foreach (var language in _languages)
     {
         ItemSelection cid = new ItemSelection(System.IO.Path.GetDirectoryName(id.Substring(_rootPath.Length)), id.Substring(_rootPath.Length));
         PxMenuItem newItem = new PxMenuItem(null, name, "", name, cid.Menu, cid.Selection, "");
         _currentItems[language].AddSubItem(newItem);
         _currentItems[language] = newItem;
         _links.Add(newItem, new List<string>());
     }
 }
Beispiel #18
0
        /// <summary>
        /// Checks if a link shall be added or not. If this check is not done a link may be added 
        /// twice for the default language - which is wrong.
        /// </summary>
        /// <param name="path">Path to the .link-file</param>
        /// <param name="itm">MenuItem object that the link shall be added to</param>
        /// <returns></returns>
        private bool CheckIfLinkShallBeAdded(string path, PxMenuItem itm)
        {
            string filename = System.IO.Path.GetFileNameWithoutExtension(path);
            int index = filename.IndexOf("_");


            if ((index != -1) && (index > 0))
            {
                //Remove the language-specific part of the filename (for example: "_en" or "_sv")
                filename = filename.Substring(0, index);
            }

            if (_links[itm].Contains(filename))
            {
                return false;
            }
            else
            {
                _links[itm].Add(filename);
                return true;
            }
        }
Beispiel #19
0
 //TODO
 /// <summary>
 ///
 /// </summary>
 /// <param name="i"></param>
 /// <returns></returns>
 public static bool HasBeenLoaded(this PxMenuItem i)
 {
     return(i.HasAttribute("HasBeenLoaded") && i.GetAttribute <bool>("HasBeenLoaded"));
 }
Beispiel #20
0
 //TODO
 /// <summary>
 ///
 /// </summary>
 /// <param name="i"></param>
 /// <param name="value"></param>
 public static void HasBeenLoaded(this PxMenuItem i, bool value)
 {
     i.SetAttribute("HasBeenLoaded", value);
 }
Beispiel #21
0
 private bool HasLinks(PxMenuItem item)
 {
     for (int i = 0; i < item.SubItems.Count; i++)
     {
         Item itm = item.SubItems[i];
         if (itm is Link)
         {
             return true;
         }
         else if (itm is PxMenuItem)
         {
             if (HasLinks((PxMenuItem)itm))
             {
                 return true;
             }
         }
     }
     return false;
 }