本文整理汇总了C#中System.IO.StringWriter.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# StringWriter.Dispose方法的具体用法?C# StringWriter.Dispose怎么用?C# StringWriter.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StringWriter
的用法示例。
在下文中一共展示了StringWriter.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssinaXml
/// <summary>
/// Assina e salva o fonte de xml
/// </summary>
/// <param name="xmlSource"></param>
/// <param name="pathXmlDestino"></param>
/// <returns></returns>
public static KeyValuePair<bool, string> AssinaXml(string xmlSource, string pathXmlDestino)
{
try
{
if (string.IsNullOrEmpty(xmlSource))
{
throw new ArgumentNullException("xmlSource", "Parametro não pode ser nulo");
}
if (string.IsNullOrEmpty(pathXmlDestino))
{
throw new ArgumentNullException("pathXmlDestino", "Parametro não pode ser nulo");
}
var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlSource);
using (var xml = new StringWriter(new StringBuilder(xmlDoc.OuterXml)))
{
var rsaKey = RetornaAssinaturaRsa(xml);
AssinaXml(xmlDoc, rsaKey);
xmlDoc.Save(pathXmlDestino);
xml.Dispose();
}
return new KeyValuePair<bool, string>(true, "");
}
catch (Exception ex)
{
return new KeyValuePair<bool, string>(false, ex.Message);
}
}
示例2: AssinaXml
/// <summary>
/// Assina e salva o fonte de xml
/// </summary>
/// <param name="xmlSource"></param>
/// <param name="pathXmlDestino"></param>
/// <returns></returns>
public static void AssinaXml(string xmlSource, string pathXmlDestino)
{
try
{
if (string.IsNullOrEmpty(xmlSource))
{
throw new ArgumentNullException("xmlSource", "Parametro não pode ser nulo");
}
if (string.IsNullOrEmpty(pathXmlDestino))
{
throw new ArgumentNullException("pathXmlDestino", "Parametro não pode ser nulo");
}
var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlSource);
var xml = new StringWriter(new StringBuilder(xmlDoc.OuterXml));
var rsaKey = RetornaAssinaturaRSA(xml);
AssinaXml(xmlDoc, rsaKey);
xmlDoc.Save(pathXmlDestino);
xml.Dispose();
}
catch
{
throw;
}
}
示例3: FromHashtableQueue
public static string FromHashtableQueue(Queue<Hashtable> queue)
{
StringWriter textWriter = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(textWriter);
jsonWriter.WriteStartArray();
JsonSerializer serializer = new JsonSerializer();
UUIDConverter UUID = new UUIDConverter();
serializer.Converters.Add(UUID);
while (queue.Count > 0)
{
try
{
Hashtable hashtable = queue.Dequeue();
serializer.Serialize(jsonWriter, hashtable);
}
catch(Exception e)
{
AjaxLife.Debug("MakeJson.FromHashTable", e.Message);
}
}
jsonWriter.WriteEndArray();
jsonWriter.Flush();
string text = textWriter.ToString();
jsonWriter.Close();
textWriter.Dispose();
return text;
}
示例4: btnExport_Click
protected void btnExport_Click(object sender, EventArgs e)
{
int totalCount = 0;
string kpiName = drpKPI.SelectedValue;
string unityValue = drpUnits.SelectedValue;
DateTime beginTime = Convert.ToDateTime(txtBeginTime.Text);
beginTime = beginTime.AddHours(1);
DateTime endTime = Convert.ToDateTime(txtEndTime.Text);
endTime = endTime.AddHours(25);
OverLimitRecordRepeater.DataSource = overLimitRecordDal.SearchOverLimitRecord(1,
int.MaxValue, kpiName, unityValue, drpShifts.SelectedValue, beginTime, endTime, out totalCount);
OverLimitRecordRepeater.DataBind();
Response.ContentEncoding = Encoding.UTF8;
Response.ContentType = "application/ms-excel";
Response.Charset = "utf-8";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("超限明细报表.xls", System.Text.Encoding.UTF8).ToString());
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
OverLimitRecordRepeater.RenderControl(htw);
Response.Write(sw.ToString());
Response.Flush();
Response.End();
sw.Close();
sw.Dispose();
DataBind();
}
示例5: RunTest
void RunTest(string c_code, string expectedXml)
{
StringReader reader = null;
StringWriter writer = null;
try
{
reader = new StringReader(c_code);
writer = new StringWriter();
var xWriter = new XmlnsHidingWriter(writer)
{
Formatting = Formatting.Indented
};
var xc = new XmlConverter(reader, xWriter);
xc.Convert();
writer.Flush();
Assert.AreEqual(expectedXml, writer.ToString());
}
catch
{
Debug.WriteLine(writer.ToString());
throw;
}
finally
{
if (writer != null)
writer.Dispose();
if (reader != null)
reader.Dispose();
}
}
示例6: btnExport_Click
protected void btnExport_Click(Object sender, EventArgs e)
{
Response.ContentEncoding = Encoding.UTF8;
Response.ContentType = "application/ms-excel";
Response.Charset = "utf-8";
Response.AppendHeader("Content-Disposition",
"attachment;filename=" + HttpUtility.UrlEncode("指标历史数据.xls",
System.Text.Encoding.UTF8).ToString());
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
int RecordCount = 0;
DateTime StartDate = Convert.ToDateTime(txtStartDate.Text);
DateTime EndDate = Convert.ToDateTime(txtEndDate.Text);
String ECID = Request.Params["ECID"];
using (ECHistoryDataAccess DataAccess = new ECHistoryDataAccess()) {
ECDataRepeater.DataSource = DataAccess.GetECHourData(ECID, StartDate, EndDate,
1, 20000, out RecordCount);
ECDataRepeater.DataBind();
ECDataRepeater.RenderControl(htw);
Response.Write(sw.ToString());
Response.Flush();
Response.End();
sw.Close();
sw.Dispose();
}
DataBind();
}
示例7: ToJsonString
public static string ToJsonString(this JToken token)
{
if (token == null)
{
throw new ArgumentNullException("token");
}
// The following code is different from token.ToString(), which special-cases null to return "" instead of
// "null".
StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture);
try
{
using (JsonWriter jsonWriter = JsonSerialization.CreateJsonTextWriter(stringWriter))
{
token.WriteTo(jsonWriter);
jsonWriter.Flush();
stringWriter.Flush();
string result = stringWriter.ToString();
stringWriter = null;
return result;
}
}
finally
{
if (stringWriter != null)
{
stringWriter.Dispose();
}
}
}
示例8: Transform
/// <summary>
/// Transforms the specified XML string
/// </summary>
/// <param name="xmlString"></param>
/// <param name="embeddedResourcePath"></param>
/// <returns></returns>
public static string Transform(string xmlString, string embeddedResourcePath)
{
string xslString = ResourceReader.ReadFromResource(embeddedResourcePath);
string result = string.Empty;
try
{
XmlDocument xsl = new XmlDocument();
xsl.LoadXml(xslString);
StringWriter sw = new StringWriter();
XmlTextReader xtr = new XmlTextReader(new StringReader(xmlString));
XmlTextWriter xtw = new XmlTextWriter(sw);
XslCompiledTransform t = new XslCompiledTransform();
t.Load((IXPathNavigable)xsl, null, null);
t.Transform(xtr, null, xtw, null);
result = sw.ToString();
sw.Flush();
sw.Close();
sw.Dispose();
}
catch(Exception ex)
{
result = string.Format("{0} had the following error with the XML file:\n{1}\n{2}", ex.Source, ex.Message, xmlString);
}
return result;
}
示例9: SaveXElementUsingXmlWriter
private string SaveXElementUsingXmlWriter(XElement elem, NamespaceHandling nsHandling)
{
StringWriter sw = new StringWriter();
using (XmlWriter w = XmlWriter.Create(sw, new XmlWriterSettings() { NamespaceHandling = nsHandling, OmitXmlDeclaration = true }))
{
elem.WriteTo(w);
}
sw.Dispose();
return sw.ToString();
}
示例10: CreateMemWriter
private XmlWriter CreateMemWriter(XmlWriterSettings settings)
{
XmlWriterSettings wSettings = settings.Clone();
wSettings.CloseOutput = false;
wSettings.OmitXmlDeclaration = true;
wSettings.CheckCharacters = false;
XmlWriter w = null;
switch (WriterType)
{
case WriterType.UTF8Writer:
wSettings.Encoding = Encoding.UTF8;
if (_strWriter != null) _strWriter.Dispose();
_strWriter = new StringWriter();
w = WriterHelper.Create(_strWriter, wSettings);
break;
case WriterType.UnicodeWriter:
wSettings.Encoding = Encoding.Unicode;
if (_strWriter != null) _strWriter.Dispose();
_strWriter = new StringWriter();
w = WriterHelper.Create(_strWriter, wSettings);
break;
case WriterType.WrappedWriter:
if (_strWriter != null) _strWriter.Dispose();
_strWriter = new StringWriter();
XmlWriter ww = WriterHelper.Create(_strWriter, wSettings);
w = WriterHelper.Create(ww, wSettings);
break;
case WriterType.CharCheckingWriter:
if (_strWriter != null) _strWriter.Dispose();
_strWriter = new StringWriter();
XmlWriter cw = WriterHelper.Create(_strWriter, wSettings);
XmlWriterSettings cws = settings.Clone();
cws.CheckCharacters = true;
w = WriterHelper.Create(cw, cws);
break;
case WriterType.UTF8WriterIndent:
wSettings.Encoding = Encoding.UTF8;
wSettings.Indent = true;
if (_strWriter != null) _strWriter.Dispose();
_strWriter = new StringWriter();
w = WriterHelper.Create(_strWriter, wSettings);
break;
case WriterType.UnicodeWriterIndent:
wSettings.Encoding = Encoding.Unicode;
wSettings.Indent = true;
if (_strWriter != null) _strWriter.Dispose();
_strWriter = new StringWriter();
w = WriterHelper.Create(_strWriter, wSettings);
break;
default:
throw new Exception("Unknown writer type");
}
return w;
}
示例11: IfNoLoggerIsAttachedWeGetAWarning
public void IfNoLoggerIsAttachedWeGetAWarning()
{
const string Warning = "Ohoh";
const string Message = "No loggers have been created for this message: " + Warning;
var defaultOut = Console.Out;
var console = new StringWriter();
Console.SetOut(console);
Logger.Warning(Warning);
Assert.IsTrue(console.ToString().Contains(Message), console.ToString());
Console.SetOut(defaultOut);
console.Dispose();
}
示例12: Compression
public void Compression(System.Web.UI.HtmlTextWriter writer)
{
StringWriter sr = new StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sr);
base.Render(tw);
tw.Flush();
tw.Dispose();
StringBuilder sb = new StringBuilder(sr.ToString());
string outhtml = Regex.Replace(sb.ToString(), "\\r+\\n+\\s+", string.Empty);
writer.Write(outhtml);
sr.Dispose();
}
示例13: Serializar
public string Serializar()
{
string retorno;
TextWriter salida = new StringWriter();
XmlSerializer serializador = new XmlSerializer(this.GetType());
serializador.Serialize(salida, this);
retorno = salida.ToString();
salida.Dispose();
return retorno;
}
示例14: JsonMessageSerializer_WhenUnderlyingMediumFails_ThrowsMessageException
public void JsonMessageSerializer_WhenUnderlyingMediumFails_ThrowsMessageException() {
// given
IMessageTypeResolver resolver = new UnitTestMessageTypeResolver();
TextWriter textWriter = new StringWriter();
textWriter.Dispose(); // so stringwriter will throw ObjectDisposedException
// when / then
MessageTransferException exception =
Assert.Throws<MessageTransferException>(
() => new JsonMessageSerializer(resolver, textWriter).SerializeMessage(new FakeMessage()));
// then
Assert.That(() => exception.InnerException, Is.InstanceOf<ObjectDisposedException>());
}
示例15: FromObject
public static string FromObject(object obj)
{
StringWriter textWriter = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(textWriter);
JsonSerializer serializer = new JsonSerializer();
LLUUIDConverter UUID = new LLUUIDConverter();
serializer.Converters.Add(UUID);
serializer.Serialize(jsonWriter, obj);
jsonWriter.Flush();
string text = textWriter.ToString();
jsonWriter.Close();
textWriter.Dispose();
return text;
}