本文整理汇总了C#中XmlTextWriter.WriteBinHex方法的典型用法代码示例。如果您正苦于以下问题:C# XmlTextWriter.WriteBinHex方法的具体用法?C# XmlTextWriter.WriteBinHex怎么用?C# XmlTextWriter.WriteBinHex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlTextWriter
的用法示例。
在下文中一共展示了XmlTextWriter.WriteBinHex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportStrategy
public static bool ExportStrategy(string fileName, IList strategyList)
{
FileStream fileStream = null;
bool bRet = false;
try
{
fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
fileStream.SetLength(0L);
XmlTextWriter writer = new XmlTextWriter(fileStream, Encoding.Default);
byte[] strategyBytes;
//声明
writer.WriteStartDocument();
writer.WriteWhitespace("\n");
writer.WriteStartElement("StrategyList");
foreach (Strategy strategy in strategyList)
{
writer.WriteWhitespace("\n\t");
writer.WriteStartElement("Strategy");
writer.WriteWhitespace("\n\t\t");
writer.WriteElementString("Name", strategy.SecurityObject.Name);
writer.WriteWhitespace("\n\t\t");
writer.WriteElementString("Comment", strategy.SecurityObject.Comment);
writer.WriteWhitespace("\n\t\t");
writer.WriteElementString("Event", ((int)strategy.Event).ToString());
writer.WriteWhitespace("\n\t\t");
writer.WriteStartElement("Automation");
strategyBytes = AdminServer.TheInstance.AutomationManager.Save(strategy.Automation);
writer.WriteBinHex(strategyBytes, 0, strategyBytes.Length);
writer.WriteEndElement();
writer.WriteWhitespace("\n\t\t");
writer.WriteElementString("Enable", strategy.Enabled ? "1" : "0");
writer.WriteWhitespace("\n\t");
writer.WriteEndElement();
}
writer.WriteWhitespace("\n");
writer.WriteEndElement();
writer.Flush();
bRet = true;
}
catch (Exception)
{
bRet = false;
}
finally
{
if (fileStream != null) fileStream.Close();
}
return bRet;
}
示例2: ExportScheduledTask
public static bool ExportScheduledTask(string fileName, IList taskList)
{
FileStream fileStream = null;
bool bRet = false;
try
{
fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
fileStream.SetLength(0L);
XmlTextWriter writer = new XmlTextWriter(fileStream, Encoding.Default);
IFormatter formatter = new BinaryFormatter();
MemoryStream taskDataStream;
//声明
writer.WriteStartDocument();
writer.WriteWhitespace("\n");
writer.WriteStartElement("TaskList");
foreach (ScheduledTaskUnit taskUnit in taskList)
{
taskDataStream = new MemoryStream();
formatter.Serialize(taskDataStream, taskUnit.Task);
writer.WriteWhitespace("\n\t");
writer.WriteStartElement("Task");
writer.WriteWhitespace("\n\t\t");
writer.WriteElementString("Name", taskUnit.Task.SecurityObject.Name);
writer.WriteWhitespace("\n\t\t");
writer.WriteElementString("Comment", taskUnit.Task.SecurityObject.Comment);
writer.WriteWhitespace("\n\t\t");
writer.WriteStartElement("Data");
writer.WriteBinHex(taskDataStream.ToArray(), 0, (int)taskDataStream.Length);
writer.WriteEndElement();
writer.WriteWhitespace("\n\t");
writer.WriteEndElement();
}
writer.WriteWhitespace("\n");
writer.WriteEndElement();
writer.Flush();
}
catch (Exception)
{
bRet = false;
}
finally
{
if (fileStream != null) fileStream.Close();
}
return bRet;
}