System.Configuration.MgmtConfigurationRecord.CopyConfigSource C# (CSharp) Méthode

CopyConfigSource() private méthode

private CopyConfigSource ( XmlUtilWriter utilWriter, string updatedXml, string configSourceStreamName, byte buffer ) : void
utilWriter XmlUtilWriter
updatedXml string
configSourceStreamName string
buffer byte
Résultat void
        private void CopyConfigSource(XmlUtilWriter utilWriter, string updatedXml, string configSourceStreamName, byte[] buffer) {
            // only copy the byte order mark if it exists in the current web.config
            byte[] preamble;
            using (Stream stream = new MemoryStream(buffer)) {
                using (XmlUtil xmlUtil = new XmlUtil(stream, configSourceStreamName, true)) {
                    preamble = ConfigStreamInfo.StreamEncoding.GetPreamble();
                }
            }

            CheckPreamble(preamble, utilWriter, buffer);

            using (Stream stream = new MemoryStream(buffer)) {
                using (XmlUtil xmlUtil = new XmlUtil(stream, configSourceStreamName, false)) {
                    XmlTextReader reader = xmlUtil.Reader;

                    // copy up to the first element
                    reader.WhitespaceHandling = WhitespaceHandling.All;
                    reader.Read();

                    // determine the indent to use for the element
                    int indent = DEFAULT_INDENT;
                    int linePosition = 1;
                    bool hasElement = xmlUtil.CopyReaderToNextElement(utilWriter, false);
                    if (hasElement) {
                        // find the indent of the first attribute, if any
                        int lineNumber = reader.LineNumber;
                        linePosition = reader.LinePosition - 1;
                        int attributeIndent = 0;
                        while (reader.MoveToNextAttribute()) {
                            if (reader.LineNumber > lineNumber) {
                                attributeIndent =   reader.LinePosition - linePosition;
                                break;
                            }
                        }

                        // find the indent of the first sub element, if any
                        int elementIndent = 0;
                        reader.Read();
                        while (reader.Depth >= 1) {
                            if (reader.NodeType == XmlNodeType.Element) {
                                elementIndent = (reader.LinePosition - 1) - linePosition;
                                break;
                            }

                            reader.Read();
                        }

                        if (elementIndent > 0) {
                            indent = elementIndent;
                        }
                        else if (attributeIndent > 0) {
                            indent = attributeIndent;
                        }
                    }

                    // Write the config source
                    string formattedXml = XmlUtil.FormatXmlElement(updatedXml, linePosition, indent, true);
                    utilWriter.Write(formattedXml);

                    // Copy remaining contents
                    if (hasElement) {
                        // Skip over the existing element
                        while (reader.Depth > 0) {
                            reader.Read();
                        }

                        if (reader.IsEmptyElement || reader.NodeType == XmlNodeType.EndElement) {
                            reader.Read();
                        }

                        // Copy remainder of file
                        while (xmlUtil.CopyXmlNode(utilWriter)) {
                        }
                    }
                }
            }
        }