Esempio n. 1
0
        public SectionGroup GetEffectiveSectionGroup()
        {
            if (_effective != null)
            {
                return(_effective);
            }

            _effective = new SectionGroup(this);
            FileContext core = this;

            while (core != null)
            {
                SectionGroup root = core.RootSectionGroup;
                foreach (SectionGroup item in root.SectionGroups)
                {
                    _effective.SectionGroups.Add(item);
                }

                foreach (SectionDefinition item in root.Sections)
                {
                    _effective.Sections.Add(item);
                }

                core = core.Parent;
            }

            return(_effective);
        }
Esempio n. 2
0
        private void Initialize()
        {
            Parent?.Initialize();
            if (_initialized)
            {
                return;
            }

            _initialized = true;
            LoadSchemas();
            _rootSectionGroup = new SectionGroup(this);
            CloneParentSectionGroups(Parent);
            if (FileName == null)
            {
                // TODO: merge with the other exception later.
                throw new FileNotFoundException(
                          string.Format(
                              "Filename: \\\\?\\{0}\r\nLine number: {1}\r\nError: Unrecognized configuration path 'MACHINE/WEBROOT/APPHOST/{2}'\r\n\r\n",
                              _server.FileName,
                              _lineNumber,
                              Location));
            }

            var file = FileName.ExpandIisExpressEnvironmentVariables();

            if (!File.Exists(file))
            {
                if (AppHost)
                {
                    _initialized = false;
                    throw new FileNotFoundException(
                              string.Format("Filename: \\\\?\\{0}\r\nError: Cannot read configuration file\r\n\r\n", FileName),
                              FileName);
                }

                return;
            }

            try
            {
                LoadDocument(file, Location);
            }
            catch (XmlException ex)
            {
                _initialized = false;
                throw new COMException(
                          string.Format(
                              "Filename: \\\\?\\{0}\r\nLine number: {1}\r\nError: Configuration file is not well-formed XML\r\n\r\n",
                              file,
                              ex.LineNumber));
            }
            catch (COMException ex)
            {
                _initialized = false;
                throw new COMException(string.Format("Filename: \\\\?\\{0}\r\n{1}\r\n", file, ex.Message));
            }
        }
Esempio n. 3
0
        internal static void GetAllDefinitions(this SectionGroup group, IList <SectionDefinition> result)
        {
            foreach (SectionDefinition item in group.Sections)
            {
                result.Add(item);
            }

            foreach (SectionGroup child in group.SectionGroups)
            {
                child.GetAllDefinitions(result);
            }
        }
Esempio n. 4
0
        private static void CloneSectionGroups(SectionGroup source, SectionGroup destination)
        {
            foreach (var child in source.SectionGroups)
            {
                var newChild = destination.SectionGroups.Add(child.Name);
                CloneSectionGroups(child, newChild);
            }

            foreach (var define in source.Sections)
            {
                if (define.OverrideModeDefault == SectionGroup.KEYWORD_OVERRIDEMODE_ALLOW)
                {
                    destination.Sections.Add(define);
                }
            }
        }
Esempio n. 5
0
        private void Initialize()
        {
            Parent?.Initialize();
            if (_initialized)
            {
                return;
            }

            _initialized = true;
            if (Parent != null)
            {
                foreach (var item in Parent.DefinitionCache)
                {
                    DefinitionCache.Add(item);
                }
            }

            LoadSchemas();
            _rootSectionGroup = new SectionGroup(this);
            if (FileName == null)
            {
                // TODO: merge with the other exception later.
                throw new FileNotFoundException(
                          $"Filename: \\\\?\\{_server.FileName}\r\nLine number: {_lineNumber}\r\nError: Unrecognized configuration path 'MACHINE/WEBROOT/APPHOST/{Location}'\r\n\r\n");
            }

            var file = FileName.ExpandIisExpressEnvironmentVariables();

            if (!File.Exists(file))
            {
                if (AppHost)
                {
                    _initialized = false;
                    throw new FileNotFoundException(
                              $"Filename: \\\\?\\{FileName}\r\nError: Cannot read configuration file\r\n\r\n",
                              FileName);
                }

                return;
            }

            try
            {
                LoadDocument(file, Location);
            }
            catch (XmlException ex)
            {
                _initialized = false;
                throw new COMException(
                          $"Filename: \\\\?\\{file}\r\nLine number: {(ex.LineNumber == 0 ? 1 : ex.LineNumber)}\r\nError: Configuration file is not well-formed XML\r\n\r\n", ex);
            }
            catch (COMException ex)
            {
                _initialized = false;
                var exception = new COMException($"Filename: \\\\?\\{file}\r\n{ex.Message}\r\n", ex);
                foreach (object key in ex.Data.Keys)
                {
                    exception.Data.Add(key, ex.Data[key]);
                }

                throw exception;
            }
        }