예제 #1
0
파일: MenuBuilder.cs 프로젝트: trygu/PxWeb
 public void NewItem(object item, string path)
 {
     if (item is AliasItem)
     {
         AliasItem alias = (AliasItem)item;
         if (Array.IndexOf(_languages, alias.Language) >= 0)
         {
             if (_currentItems[alias.Language].Text == _currentItems[alias.Language].SortCode)
             {
                 _currentItems[alias.Language].SortCode = alias.Alias;
             }
             _currentItems[alias.Language].Text = alias.Alias;
         }
     }
     else if (item is LinkItem)
     {
         LinkItem itm = (LinkItem)item;
         if (Array.IndexOf(_languages, itm.Language) >= 0)
         {
             if (CheckIfLinkShallBeAdded(path, _currentItems[itm.Language]))
             {
                 //Url url = new Url(itm.Text, "", path, "", PresCategory.NotSet, itm.Location, LinkPres.NotSet);
                 Url url = new Url(itm.Text, "", "MENU_TEST", itm.Location, "", PresCategory.NotSet, itm.Location, LinkPres.NotSet);
                 _currentItems[itm.Language].SubItems.Add(url);
             }
         }
     }
     else if (item is MenuSortItem)
     {
         MenuSortItem sort = item as MenuSortItem;
         if (Array.IndexOf(_languages, sort.Language) >= 0)
         {
             _currentItems[sort.Language].SortCode = sort.SortString;
         }
     }
     else if (item is PCAxis.Paxiom.PXMeta)
     {
         PCAxis.Paxiom.PXMeta meta = (PCAxis.Paxiom.PXMeta)item;
         foreach (var language in _languages)
         {
             if (meta.HasLanguage(language))
             {
                 meta.SetLanguage(language);
                 TableLink tbl = CreateTableLink(meta, path);
                 _currentItems[language].AddSubItem(tbl);
             }
             else
             {
                 if (!_languageDependent)
                 {
                     if (meta.HasLanguage(Settings.Current.General.Language.DefaultLanguage))
                     {
                         meta.SetLanguage(Settings.Current.General.Language.DefaultLanguage);
                     }
                     else
                     {
                         meta.SetLanguage("default");
                     }
                     TableLink tbl = CreateTableLink(meta, path);
                     _currentItems[language].AddSubItem(tbl);
                 }
             }
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Reads the link file and creates a LinkItem object representing the link
        /// </summary>
        /// <param name="path">The path to the link file</param>
        /// <returns>A LinkItem</returns>
        /// <remarks>
        /// If the link file do not have a language specified in the name then the
        /// default language specified in the settings will be used
        /// </remarks>
        public object Handle(string path, DatabaseLogger logger)
        {
            string fileName    = System.IO.Path.GetFileNameWithoutExtension(path);
            int    splittIndex = fileName.IndexOf('_');

            LinkItem link = new LinkItem();

            if (splittIndex < 0)
            {
                //No underscore in the file name use the default language
                link.Language = Settings.Current.General.Language.DefaultLanguage;
            }
            else
            {
                link.Language = fileName.Substring(splittIndex + 1);
            }

            string linkData;

            try
            {
                linkData = ReadAll(path);
            }
            catch (System.IO.IOException ex)
            {
                logger(new DatabaseMessage()
                {
                    MessageType = DatabaseMessage.BuilderMessageType.Error, Message = "Could not read file " + path
                });
                _logger.Warn(ex.ToString());
                return(null);
            }

            //Find the second "
            splittIndex = linkData.IndexOf('"', 1);

            //No second " corrupted link file
            if (splittIndex < 0)
            {
                logger(new DatabaseMessage()
                {
                    MessageType = DatabaseMessage.BuilderMessageType.Warning, Message = "Corrupt link file " + path
                });
                return(null);
            }

            //Find the real splittIndex
            splittIndex = linkData.IndexOf(',', splittIndex);

            //No , after the second " corrupted link file
            if (splittIndex < 0)
            {
                logger(new DatabaseMessage()
                {
                    MessageType = DatabaseMessage.BuilderMessageType.Warning, Message = "Corrupt link file " + path
                });
                return(null);
            }

            link.Text     = TidyString(linkData.Substring(0, splittIndex)).Trim('"');
            link.Location = TidyString(linkData.Substring(splittIndex + 1)).Trim('"');

            return(link);
        }