コード例 #1
0
ファイル: Portal.cs プロジェクト: yhhno/nfx
        /// <summary>
        /// Makes portal from config.
        /// Due to the nature of Portal object there is no need to create other parametrized ctors
        /// </summary>
        protected Portal(IConfigSectionNode conf)
            : base(PortalHub.Instance)
        {
            const string PORTAL = "portal";

            m_Name = conf.AttrByName(Configuration.CONFIG_NAME_ATTR).Value;
            if (m_Name.IsNullOrWhiteSpace())
            {
              m_Name = this.GetType().Name;
              if (m_Name.EndsWith(PORTAL, StringComparison.OrdinalIgnoreCase) && m_Name.Length>PORTAL.Length)
               m_Name = m_Name.Substring(0, m_Name.Length-PORTAL.Length);
            }

            //Register with the Hub
            if (!PortalHub.Instance.m_Portals.Register( this ))
              throw new WaveException(StringConsts.PORTAL_HUB_INSTANCE_ALREADY_CONTAINS_PORTAL_ERROR.Args(m_Name));

            m_Description = conf.AttrByName(CONFIG_DESCR_ATTR).ValueAsString(m_Name);
            m_Offline = conf.AttrByName(CONFIG_OFFLINE_ATTR).ValueAsBool(false);
            m_Default = conf.AttrByName(CONFIG_DEFAULT_ATTR).ValueAsBool(false);

            var puri = conf.AttrByName(CONFIG_PRIMARY_ROOT_URI_ATTR).Value;

            try{ m_PrimaryRootUri = new Uri(puri, UriKind.Absolute); }
            catch(Exception error)
            {
              throw new WaveException(StringConsts.CONFIG_PORTAL_ROOT_URI_ERROR.Args(m_Name, error.ToMessageWithType()), error);
            }

            m_DisplayName = conf.AttrByName(CONFIG_DISPLAY_NAME_ATTR).Value;

            if (m_DisplayName.IsNullOrWhiteSpace())
              m_DisplayName = m_PrimaryRootUri.ToString();

            m_Themes = new Registry<Theme>();
            var nthemes = conf.Children.Where(c => c.IsSameName(CONFIG_THEME_SECTION));
            foreach(var ntheme in nthemes)
            {
              var theme = FactoryUtils.Make<Theme>(ntheme, args: new object[]{this, ntheme});
              if(!m_Themes.Register(theme))
            throw new WaveException(StringConsts.CONFIG_PORTAL_DUPLICATE_THEME_NAME_ERROR.Args(theme.Name, m_Name));
            }

            if (m_Themes.Count==0)
              throw new WaveException(StringConsts.CONFIG_PORTAL_NO_THEMES_ERROR.Args(m_Name));

            m_DefaultTheme = m_Themes.FirstOrDefault(t => t.Default);
            if (m_DefaultTheme==null)
              throw new WaveException(StringConsts.CONFIG_PORTAL_NO_DEFAULT_THEME_ERROR.Args(m_Name));

            m_ParentName = conf.AttrByName(CONFIG_PARENT_NAME_ATTR).Value;

            ConfigAttribute.Apply(this, conf);

            m_LocalizableContent = new Dictionary<string,string>(GetLocalizableContent(), StringComparer.InvariantCultureIgnoreCase);
            foreach(var atr in conf[CONFIG_LOCALIZATION_SECTION][CONFIG_CONTENT_SECTION].Attributes)
             m_LocalizableContent[atr.Name] = atr.Value;

            var gen = conf[CONFIG_RECORD_MODEL_SECTION];
            m_RecordModelGenerator = FactoryUtils.Make<Client.RecordModelGenerator>(gen,
                                                                                typeof(Client.RecordModelGenerator),
                                                                                new object[]{gen});

            m_RecordModelGenerator.ModelLocalization += recGeneratorLocalization;

            m_LocalizationData = conf[CONFIG_LOCALIZATION_SECTION];
            var msgFile = m_LocalizationData.AttrByName(CONFIG_MSG_FILE_ATTR).Value;
            if (msgFile.IsNotNullOrWhiteSpace())
            try
            {
               m_LocalizationData = Configuration.ProviderLoadFromFile(msgFile).Root;
            }
            catch(Exception fileError)
            {
               throw new WaveException(StringConsts.CONFIG_PORTAL_LOCALIZATION_FILE_ERROR.Args(m_Name, msgFile, fileError.ToMessageWithType()), fileError);
            }
        }
コード例 #2
0
ファイル: WorkContext.cs プロジェクト: yhhno/nfx
 /// <summary>
 /// DEVELOPERS do not use!
 /// A hack method needed in some VERY RARE cases, like serving an error page form the filter which is out of portal scope.
 /// </summary>
 public void ___InternalInjectPortal(Portal portal = null,
     Theme theme = null,
     WorkMatch match = null,
     JSONDataMap matchedVars = null)
 {
     m_Portal = portal;
                                              m_PortalTheme = theme;
                                              m_PortalMatch = match;
                                              m_PortalMatchedVars = matchedVars;
 }