Esempio n. 1
0
                                      //20150403 DKh added support for include pragmas
                                      private ConfigSectionNode calculateEffectiveAppConfig(string appName)
                                      {
                                          var pragmasDisabled = Metabank.RootConfig.AttrByName(Metabank.CONFIG_APP_CONFIG_INCLUDE_PRAGMAS_DISABLED_ATTR).ValueAsBool(false);
                                          var includePragma   = Metabank.RootConfig.AttrByName(Metabank.CONFIG_APP_CONFIG_INCLUDE_PRAGMA_ATTR).Value;


                                          var conf = new MemoryConfiguration();

                                          conf.CreateFromNode(Metabank.RootAppConfig);
                                          conf.Application = this.Metabank.SkyApp;

                                          var result = conf.Root;

                                          if (!pragmasDisabled)
                                          {
                                              result.ProcessAllExistingIncludes("root", includePragma);
                                          }

                                          var derivation = new List <configLevel>();

                                          #region build derivation chain --------------------------------------------------------------------------
                                          //Role level
                                          var role = this.Role;

                                          if (!role.AppNames.Any(an => INVSTRCMP.Equals(an, appName)))
                                          {
                                              throw new MetabaseException(StringConsts.METABASE_HOST_ROLE_APP_MISMATCH_ERROR.Args(appName, RoleName));
                                          }

                                          derivation.Add(new configLevel(role, role.AnyAppConfig));

                                          //App level
                                          var app = Metabank.CatalogApp.Applications[appName];
                                          if (app == null)
                                          {
                                              throw new MetabaseException(StringConsts.METABASE_BAD_HOST_APP_ERROR.Args(appName));
                                          }

                                          derivation.Add(new configLevel(app, app.AnyAppConfig));

                                          //Regional level
                                          var parents = this.ParentSectionsOnPath;
                                          foreach (var item in parents)
                                          {
                                              derivation.Add(new configLevel(item, item.AnyAppConfig));
                                              derivation.Add(new configLevel(item, item.GetAppConfig(appName)));
                                          }

                                          //This Level
                                          derivation.Add(new configLevel(this, this.AnyAppConfig));
                                          derivation.Add(new configLevel(this, this.GetAppConfig(appName)));
                                          #endregion

                                          foreach (var clevel in derivation.Where(cl => cl.Node != null))
                                          {
                                              if (!pragmasDisabled)
                                              {
                                                  ((ConfigSectionNode)clevel.Node).ProcessAllExistingIncludes(clevel.From.ToString(), includePragma);
                                              }

                                              try
                                              {
                                                  result.OverrideBy(clevel.Node);
                                              }
                                              catch (Exception error)
                                              {
                                                  throw new MetabaseException(StringConsts.METABASE_EFFECTIVE_APP_CONFIG_OVERRIDE_ERROR.Args(clevel.From.ToString(), error.ToMessageWithType()), error);
                                              }
                                          }

                                          //OS Include
                                          var include = result[CONFIG_OS_APP_CONFIG_INCLUDE_SECTION];
                                          if (include.Exists)
                                          {
                                              var osInclude = Metabank.GetOSConfNode(this.OS)[CONFIG_APP_CONFIG_SECTION] as ConfigSectionNode;
                                              if (osInclude.Exists)
                                              {
                                                  include.Configuration.Include(include, osInclude);
                                              }
                                          }

                                          result.ResetModified();
                                          return(result);
                                      }