本文整理汇总了C#中System.Configuration.XmlUtilWriter.CreateStreamCheckpoint方法的典型用法代码示例。如果您正苦于以下问题:C# XmlUtilWriter.CreateStreamCheckpoint方法的具体用法?C# XmlUtilWriter.CreateStreamCheckpoint怎么用?C# XmlUtilWriter.CreateStreamCheckpoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Configuration.XmlUtilWriter
的用法示例。
在下文中一共展示了XmlUtilWriter.CreateStreamCheckpoint方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyConfigDefinitionsRecursive
//.........这里部分代码省略.........
else if (!elementLocationPathApplies && !IsLocationConfig) {
if (_removedSectionGroups != null && _removedSectionGroups.Contains(configKey)) {
removedSectionOrGroup = true;
}
else {
recurse = true;
recurseGroup = configKey;
recurseLocationUpdates = null;
recurseSectionUpdates = null;
recurseAddNewSections = false;
}
}
}
}
else {
// it is a section - get the update
if (sectionUpdates != null) {
update = sectionUpdates.GetDefinitionUpdate(configKey);
}
else if (!elementLocationPathApplies && !IsLocationConfig) {
if (_removedSections != null && _removedSections.Contains(configKey)) {
removedSectionOrGroup = true;
}
}
}
}
if (recurse) {
#if DBG
string startElementName = reader.Name;
#endif
// flush, and get length of underlying stream
object checkpoint = utilWriter.CreateStreamCheckpoint();
// Copy this element node and up to the first subelement
xmlUtil.CopyXmlNode(utilWriter);
xmlUtil.CopyReaderToNextElement(utilWriter, true);
// Recurse
bool recurseWroteASection = CopyConfigDefinitionsRecursive(
configDefinitionUpdates, xmlUtil, utilWriter, elementLocationPathApplies, recurseLocationUpdates, recurseSectionUpdates,
recurseAddNewSections, recurseGroup, linePosition, indent);
// Copy the end element
xmlUtil.CopyXmlNode(utilWriter);
if (recurseWroteASection) {
wroteASection = true;
}
else {
// back out the change
utilWriter.RestoreStreamCheckpoint(checkpoint);
}
// Copy up to the next element, or exit this level.
xmlUtil.CopyReaderToNextElement(utilWriter, true);
}
else {
bool skip;
if (update == null) {
// remove the section from the file if we're in the correct location,
// or if the section or group should be removed from all locations
skip = elementLocationPathApplies || removedSectionOrGroup;
}
else {
示例2: CopyConfigDeclarationsRecursive
//.........这里部分代码省略.........
linePosition = xmlUtil.TrueLinePosition;
string directive = reader.Name;
string name = reader.GetAttribute(KEYWORD_SECTIONGROUP_NAME);
string configKey = CombineConfigKey(group, name);
if (directive == KEYWORD_SECTIONGROUP) {
// it's a group - get the updates for children
declarationUpdatesChild = declarationUpdates.GetSectionUpdatesForGroup(name);
if (declarationUpdatesChild != null) {
// get the group update
groupUpdate = declarationUpdatesChild.GetSectionGroupUpdate();
// recurse if there are more sections to copy
if (declarationUpdatesChild.HasUnretrievedSections()) {
recurse = true;
recurseGroup = configKey;
recurseDeclarationUpdates = declarationUpdatesChild;
}
}
}
else {
// it is a section - get the update
Debug.Assert(!IsImplicitSection(configKey), "We should never write out an implicit section");
sectionUpdate = declarationUpdates.GetDeclarationUpdate(configKey);
}
bool writeGroupUpdate = (groupUpdate != null && groupUpdate.UpdatedXml != null);
if (recurse) {
#if DBG
string startElementName = reader.Name;
#endif
// create a checkpoint that we can revert to if no children are written
object checkpoint = utilWriter.CreateStreamCheckpoint();
string closingElement = null;
// Copy this element node and up to the first subelement
if (writeGroupUpdate) {
// replace the element with the updated xml
utilWriter.Write(groupUpdate.UpdatedXml);
// skip over the start element
reader.Read();
}
else {
closingElement= xmlUtil.UpdateStartElement(utilWriter, null, true, linePosition, indent);
}
if (closingElement == null) {
// Only if there is a closing element should
// we move to it
xmlUtil.CopyReaderToNextElement(utilWriter, true);
}
// Recurse
bool recurseWroteASection = CopyConfigDeclarationsRecursive(
recurseDeclarationUpdates, xmlUtil, utilWriter, recurseGroup, linePosition, indent);
if (closingElement != null) {
utilWriter.AppendSpacesToLinePosition(linePosition);
utilWriter.Write(closingElement);
// Since we already got to </configSections> in reader, lets
// indent so we can copy the element in the right place
utilWriter.AppendSpacesToLinePosition(parentLinePosition);
} else {
示例3: CheckPreamble
private void CheckPreamble(byte[] preamble, XmlUtilWriter utilWriter, byte[] buffer) {
bool hasByteOrderMark = false;
using (Stream preambleStream = new MemoryStream(buffer)) {
byte[] streamStart = new byte[preamble.Length];
if (preambleStream.Read(streamStart, 0, streamStart.Length) == streamStart.Length) {
hasByteOrderMark = true;
for (int i = 0; i < streamStart.Length; i++) {
if (streamStart[i] != preamble[i]) {
hasByteOrderMark = false;
break;
}
}
}
}
if (!hasByteOrderMark) {
// Force the writer to emit byte order mark, then reset the stream
// so that it is written over.
object checkpoint = utilWriter.CreateStreamCheckpoint();
utilWriter.Write('x');
utilWriter.RestoreStreamCheckpoint(checkpoint);
}
}
示例4: CopyConfigDefinitionsRecursive
//.........这里部分代码省略.........
{
flag3 = true;
str2 = configKey;
updates2 = sectionUpdatesForGroup;
}
}
else if (!flag4 && !base.IsLocationConfig)
{
if ((this._removedSectionGroups != null) && this._removedSectionGroups.Contains(configKey))
{
flag6 = true;
}
else
{
flag3 = true;
str2 = configKey;
updates = null;
updates2 = null;
flag5 = false;
}
}
}
else if (sectionUpdates != null)
{
update = sectionUpdates.GetDefinitionUpdate(configKey);
}
else if ((!flag4 && !base.IsLocationConfig) && ((this._removedSections != null) && this._removedSections.Contains(configKey)))
{
flag6 = true;
}
}
if (flag3)
{
object o = utilWriter.CreateStreamCheckpoint();
xmlUtil.CopyXmlNode(utilWriter);
xmlUtil.CopyReaderToNextElement(utilWriter, true);
bool flag8 = this.CopyConfigDefinitionsRecursive(configDefinitionUpdates, xmlUtil, utilWriter, flag4, updates, updates2, flag5, str2, trueLinePosition, indent);
xmlUtil.CopyXmlNode(utilWriter);
if (flag8)
{
flag = true;
}
else
{
utilWriter.RestoreStreamCheckpoint(o);
}
xmlUtil.CopyReaderToNextElement(utilWriter, true);
}
else
{
bool flag9;
if (update == null)
{
flag9 = flag4 || flag6;
}
else
{
flag9 = false;
if (update.UpdatedXml != null)
{
ConfigurationSection result = (ConfigurationSection) update.SectionRecord.Result;
if (string.IsNullOrEmpty(result.SectionInformation.ConfigSource) || result.SectionInformation.ConfigSourceModified)
{
flag9 = true;
this.WriteSectionUpdate(utilWriter, update, trueLinePosition, indent, true);
flag = true;
示例5: CopyConfigDeclarationsRecursive
private bool CopyConfigDeclarationsRecursive(SectionUpdates declarationUpdates, XmlUtil xmlUtil, XmlUtilWriter utilWriter, string group, int parentLinePosition, int parentIndent)
{
int trueLinePosition;
int num3;
bool flag = false;
XmlTextReader reader = xmlUtil.Reader;
int oldIndent = this.UpdateIndent(parentIndent, xmlUtil, utilWriter, parentLinePosition);
if (reader.NodeType == XmlNodeType.Element)
{
trueLinePosition = xmlUtil.TrueLinePosition;
num3 = trueLinePosition;
}
else if (reader.NodeType == XmlNodeType.EndElement)
{
trueLinePosition = parentLinePosition + oldIndent;
if (utilWriter.IsLastLineBlank)
{
num3 = xmlUtil.TrueLinePosition;
}
else
{
num3 = parentLinePosition;
}
}
else
{
trueLinePosition = parentLinePosition + oldIndent;
num3 = 0;
}
if (declarationUpdates != null)
{
string[] movedSectionNames = declarationUpdates.GetMovedSectionNames();
if (movedSectionNames != null)
{
if (!utilWriter.IsLastLineBlank)
{
utilWriter.AppendNewLine();
}
foreach (string str in movedSectionNames)
{
DeclarationUpdate declarationUpdate = declarationUpdates.GetDeclarationUpdate(str);
utilWriter.AppendSpacesToLinePosition(trueLinePosition);
utilWriter.Write(declarationUpdate.UpdatedXml);
utilWriter.AppendNewLine();
flag = true;
}
utilWriter.AppendSpacesToLinePosition(num3);
}
}
if (reader.NodeType == XmlNodeType.Element)
{
int depth = reader.Depth;
while (reader.Depth == depth)
{
bool flag2 = false;
DeclarationUpdate update2 = null;
DeclarationUpdate sectionGroupUpdate = null;
SectionUpdates sectionUpdatesForGroup = null;
SectionUpdates updates2 = declarationUpdates;
string str2 = group;
oldIndent = this.UpdateIndent(oldIndent, xmlUtil, utilWriter, parentLinePosition);
trueLinePosition = xmlUtil.TrueLinePosition;
string name = reader.Name;
string attribute = reader.GetAttribute("name");
string configKey = BaseConfigurationRecord.CombineConfigKey(group, attribute);
if (name == "sectionGroup")
{
sectionUpdatesForGroup = declarationUpdates.GetSectionUpdatesForGroup(attribute);
if (sectionUpdatesForGroup != null)
{
sectionGroupUpdate = sectionUpdatesForGroup.GetSectionGroupUpdate();
if (sectionUpdatesForGroup.HasUnretrievedSections())
{
flag2 = true;
str2 = configKey;
updates2 = sectionUpdatesForGroup;
}
}
}
else
{
update2 = declarationUpdates.GetDeclarationUpdate(configKey);
}
bool flag3 = (sectionGroupUpdate != null) && (sectionGroupUpdate.UpdatedXml != null);
if (flag2)
{
object o = utilWriter.CreateStreamCheckpoint();
string s = null;
if (flag3)
{
utilWriter.Write(sectionGroupUpdate.UpdatedXml);
reader.Read();
}
else
{
s = xmlUtil.UpdateStartElement(utilWriter, null, true, trueLinePosition, oldIndent);
}
if (s == null)
{
xmlUtil.CopyReaderToNextElement(utilWriter, true);
//.........这里部分代码省略.........
示例6: CheckPreamble
private void CheckPreamble(byte[] preamble, XmlUtilWriter utilWriter, byte[] buffer)
{
bool flag = false;
using (Stream stream = new MemoryStream(buffer))
{
byte[] buffer2 = new byte[preamble.Length];
if (stream.Read(buffer2, 0, buffer2.Length) == buffer2.Length)
{
flag = true;
for (int i = 0; i < buffer2.Length; i++)
{
if (buffer2[i] != preamble[i])
{
flag = false;
goto Label_004A;
}
}
}
}
Label_004A:
if (!flag)
{
object o = utilWriter.CreateStreamCheckpoint();
utilWriter.Write('x');
utilWriter.RestoreStreamCheckpoint(o);
}
}