本文整理汇总了C#中System.IO.StringReader.Close方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.StringReader.Close方法的具体用法?C# System.IO.StringReader.Close怎么用?C# System.IO.StringReader.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StringReader
的用法示例。
在下文中一共展示了System.IO.StringReader.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: parse
public List<CCFE_ConfigurationProperty> parse()
{
List<CCFE_ConfigurationProperty> propertyList = new List<CCFE_ConfigurationProperty>();
//read in file data as string
string fileText = System.IO.File.ReadAllText(FileLocation);
//create StringReader to parse string
System.IO.StringReader stringReader = new System.IO.StringReader(fileText);
string line;
string propertyPattern = "^([A-Z])([A-z])+=\\S+";
string[] propertyValues;
while ((line = stringReader.ReadLine()) != null)
{
//check if line is a property using regex
if (System.Text.RegularExpressions.Regex.IsMatch(line, propertyPattern))
{
//break string into 'name' and 'value' parts
propertyValues = line.Split('=');
propertyList.Add(new CCFE_ConfigurationProperty(propertyValues[0], propertyValues[1]));
}
}
stringReader.Close();
return propertyList;
}
示例2: LoadFromXmlFile
static List<Employee> LoadFromXmlFile (string xmlFilename)
{
var xmlString = System.IO.File.ReadAllText(xmlFilename);
XmlSerializer serializer = new XmlSerializer (typeof(List<Employee>));
System.IO.TextReader reader = new System.IO.StringReader(xmlString);
object o = serializer.Deserialize(reader);
reader.Close();
return (List<Employee>)o;
}
示例3: UpdateFromString
public static void UpdateFromString(string xml)
{
XmlSerializer serializer = new XmlSerializer(typeof(List<Employee>));
System.IO.TextReader reader = new System.IO.StringReader(xml);
object o = serializer.Deserialize(reader);
reader.Close();
var employees = (List<Employee>)o;
SaveToSQLite(employees);
}
示例4: DirectoryXML
private XDocument DirectoryXML(string LocalPath)
{
XDocument directoryXML;
System.IO.StringReader tr = new System.IO.StringReader(GetDirXML(LocalPath));
directoryXML = XDocument.Load(tr);
tr.Close();
return directoryXML;
}
示例5: frmSaveBarcodes_Load
private void frmSaveBarcodes_Load(object sender, EventArgs e)
{
using (System.IO.StringReader rd = new System.IO.StringReader(""))
{
richTextBox1.Text = rd.ReadLine();
rd.Close();
}
}
示例6: ReadValuesFromXml
public void ReadValuesFromXml(string xml)
{
XmlSerializer xs = new XmlSerializer(typeof(Collection<UserQuestionOption>));
System.IO.StringReader sr = new System.IO.StringReader(xml);
try
{
this.Values = (Collection<UserQuestionOption>)xs.Deserialize(sr);
}
finally
{
this.Values = new Collection<UserQuestionOption>();
sr.Close();
}
}
示例7: FromXml
/// <summary>
/// Deserialize an object from an xml string
/// </summary>
/// <param name="xml">The xml representation of the object</param>
/// <returns>EntityObject</returns>
/// <remarks>After deserializing the object returned will have to be cast to the proper type</remarks>
public EntityObject FromXml(string xml)
{
EntityObject entity = null;
System.IO.StringReader reader = null;
try
{
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(this.GetType());
reader = new System.IO.StringReader(xml);
entity = (EntityObject)serializer.Deserialize(reader);
}
finally
{
if(reader!=null) reader.Close();
}
return entity;
}
示例8: btnProcessFile_Click
private void btnProcessFile_Click(object sender, RoutedEventArgs e)
{
if (lbFileName.Text == "")
MessageBox.Show("Select the file you want to process.");
else if (!System.IO.File.Exists(lbFileName.Text))
MessageBox.Show("The specificed file does not exist anymore.");
else {
int minimumCharacterCount = 0;
try {
minimumCharacterCount = int.Parse(txMinimumCharacterCount.Text);
if (minimumCharacterCount == 0)
MessageBox.Show("You must enter a positive value for minimum character count.");
} catch {
MessageBox.Show("Be sure to only enter digits in the minimum character count.");
}
if (minimumCharacterCount > 0 && MessageBox.Show("This process will overwrite the specified file. Continue?", "Confirm Overwrite", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) {
var fileContents = System.IO.File.ReadAllText(lbFileName.Text);
var reader = new System.IO.StringReader(fileContents);
string line;
var newFileContents = new System.Text.StringBuilder();
line = reader.ReadLine();
while (line != null) {
if (line.Length >= minimumCharacterCount)
newFileContents.AppendLine(line);
line = reader.ReadLine();
}
reader.Close();
System.IO.File.WriteAllText(lbFileName.Text, newFileContents.ToString());
MessageBox.Show("Process Completed");
}
}
}
示例9: Token
//public static string[] SplitWords(string content)
//{
// List<string> strList = new List<string>();
// Analyzer analyzer = new PanGuAnalyzer();//指定使用盘古 PanGuAnalyzer 分词算法
// TokenStream tokenStream = analyzer.TokenStream("", new StringReader(content));
// Lucene.Net.Analysis.Token token = null;
// while ((token = tokenStream.Next()) != null)
// { //Next继续分词 直至返回null
// strList.Add(token.TermText()); //得到分词后结果
// }
// return strList.ToArray();
//}
#region 分词测试
/// <summary>
/// 分词测试
/// </summary>
/// <param name="keyword"></param>
/// <returns></returns>
public string Token(string keyword)
{
string ret = "";
System.IO.StringReader reader = new System.IO.StringReader(keyword);
Analyzer analyzer = new PanGuAnalyzer();//指定使用盘古 PanGuAnalyzer 分词算法
TokenStream ts = analyzer.TokenStream(keyword, reader);
bool hasNext = ts.IncrementToken();
Lucene.Net.Analysis.Tokenattributes.ITermAttribute ita;
while (hasNext)
{
ita = ts.GetAttribute<Lucene.Net.Analysis.Tokenattributes.ITermAttribute>();
ret += ita.Term + "|";
hasNext = ts.IncrementToken();
}
ts.CloneAttributes();
reader.Close();
analyzer.Close();
return ret;
}
示例10: button1_Click
private void button1_Click(object sender, EventArgs e)
{
//TextBox1�ɓ��͂���Ă��镶�����s���ǂݍ���
//������(TextBox1�ɓ��͂��ꂽ������)����StringReader�C���X�^���X��쐬
System.IO.StringReader rs = new System.IO.StringReader(txt_in.Text);
string tmp = string.Empty;
string read = string.Empty;
//�X�g���[���̖��[�܂ŌJ��Ԃ�
while (rs.Peek() > -1){
//��s�ǂݍ���ŕ\������
read = rs.ReadLine();
if (read.Length > 0){
if ((string.IsNullOrEmpty(this.del_dbms_output(read)) == false)){
tmp += del_dbms_output(read) + "\r\n";
}
}
}
rs.Close();
txt_out.Text = tmp;
}
示例11: GetSRIDs
/// <summary>
/// Enumerates all SRID's in the SRID.csv file.
/// </summary>
/// <returns>Enumerator</returns>
public static IEnumerable<WKTstring> GetSRIDs()
{
TextAsset filecontent = Resources.Load(filename) as TextAsset;
using (System.IO.StringReader sr = new System.IO.StringReader(filecontent.text))
{
string line = sr.ReadLine();
while (line != null)
{
int split = line.IndexOf(';');
if (split > -1)
{
WKTstring wkt = new WKTstring();
wkt.WKID = int.Parse(line.Substring(0, split));
wkt.WKT = line.Substring(split + 1);
yield return wkt;
}
line = sr.ReadLine();
}
sr.Close();
}
}
示例12: Schema_MetaDataCollections
/// <summary>
/// Builds a MetaDataCollections schema datatable
/// </summary>
/// <returns>DataTable</returns>
private static DataTable Schema_MetaDataCollections()
{
DataTable tbl = new DataTable("MetaDataCollections");
tbl.Locale = CultureInfo.InvariantCulture;
tbl.Columns.Add("CollectionName", typeof(string));
tbl.Columns.Add("NumberOfRestrictions", typeof(int));
tbl.Columns.Add("NumberOfIdentifierParts", typeof(int));
tbl.BeginLoadData();
System.IO.StringReader reader = new System.IO.StringReader(SR.MetaDataCollections);
tbl.ReadXml(reader);
reader.Close();
tbl.AcceptChanges();
tbl.EndLoadData();
return tbl;
}
示例13: Read
//────────────────────────────────────────
/// <summary>
/// TODO:「,」「"」に対応したい。
///
///
/// 縦と横が逆のテーブル。
///
/// CSVを読取り、テーブルにして返します。
///
///
/// SRS仕様の実装状況
/// ここでは、先頭行を[0]行目と数えるものとします。
/// (1)CSVの[0]行目は列名です。
/// (2)CSVの[1]行目は型名です。
/// (3)CSVの[2]行目はコメントです。
///
/// (4)データ・テーブル部で、0列目に「EOF」と入っていれば終了。大文字・小文字は区別せず。
/// それ以降に、コメントのようなデータが入力されていることがあるが、フィールドの型に一致しないことがあるので無視。
/// TODO EOF以降の行も、コメントとして残したい。
///
/// (5)列名にENDがある場合、その手前までの列が有効データです。
/// END以降の列は無視します。
/// TODO END以降の行も、コメントとして残したい。
///
/// (6)int型として指定されているフィールドのデータ・テーブル部に空欄があった場合、DBNull(データベース用のヌル)とします。
/// </summary>
/// <param name="csvText"></param>
/// <returns>列名情報も含むテーブル。列の型は文字列型とします。</returns>
public Table_Humaninput Read(
string string_Csv,
Request_ReadsTable forTable_Request,
Format_Table_Humaninput forTable_Format,
Log_Reports log_Reports
)
{
Log_Method log_Method = new Log_MethodImpl();
log_Method.BeginMethod(Info_Table.Name_Library, this, "Read",log_Reports);
//
//
//
//
CsvLineParserImpl csvParser = new CsvLineParserImpl();
Table_Humaninput xenonTable = new Table_HumaninputImpl(
forTable_Request.Name_PutToTable, forTable_Request.Expression_Filepath, forTable_Request.Expression_Filepath.Cur_Configuration );
xenonTable.Tableunit = forTable_Request.Tableunit;
xenonTable.Typedata = forTable_Request.Typedata;
xenonTable.IsDatebackupActivated = forTable_Request.IsDatebackupActivated;
xenonTable.Format_Table_Humaninput = forTable_Format;
//
// 一旦、テーブルを全て読み込みます。
//
List<List<string>> lines = new List<List<string>>();
{
// CSVテキストを読み込み、型とデータのバッファーを作成します。
System.IO.StringReader reader = new System.IO.StringReader(string_Csv);
while (-1 < reader.Peek())
{
string sLine = reader.ReadLine();
List<string> tokens = new List<string>();
string[] sFields;
sFields = csvParser.UnescapeLineToFieldList(sLine, this.charSeparator).ToArray();
int nColumnIndex = 0;
foreach (string sToken in sFields)
{
if (nColumnIndex == 0 && ToCsv_Table_Humaninput_RowColRegularImpl.S_END == sToken.Trim().ToUpper())
{
// 1列目にENDがある場合、その手前までの列が有効データです。
// END以降の行は無視します。
goto row_end;
}
tokens.Add(sToken);
nColumnIndex++;
}
lines.Add(tokens);
}
row_end:
// ストリームを閉じます。
reader.Close();
}
//
// 型定義部
//
// (※NO,ID,EXPL,NAME など、フィールドの定義を持つテーブル)
//
RecordFielddefinition recordFielddefinition = new RecordFielddefinitionImpl();
//
// データ・テーブル部
//
//.........这里部分代码省略.........
示例14: updateLogs
/// <summary>
/// Sync the map log with the master log when changes happen outside of the program by comparing the new map log to the copy of what this program last wrote to the map log.</summary>
private void updateLogs()
{
/// The most current copy of the Map Log's contents
string textLogFileCurrent = "";
/// A line of text from the current Map Log
string tempLogFileLine;
/// A line from the last write of the Map Log
string tempStoredLine;
// if there is no stored log file string to compare to, we can't check for updates
if (textMapLogFile == null || textMapLogFile.Length < 1) {
return;
}
// check the log file has a write time stamp latter than when this program last wrote to the file
if (lastLogged.CompareTo(getLastWriteTimeUTC(btnMapLog.Label)) < 0) {
// read the entire log file into memory
try {
using (System.IO.StreamReader fileLog = new System.IO.StreamReader (OpenFile (btnMapLog.Label, false))) {
textLogFileCurrent = fileLog.ReadToEnd();
fileLog.Close();
}
} catch (System.ArgumentNullException) {
// OpenFile should have already given an error message since OpenFile() returns null on error
return;
}
// compare the lines of the file and mirror the differences to the master log and the internal storage
try {
using (System.IO.StringReader strStoredLog = new System.IO.StringReader(textMapLogFile)) {
using (System.IO.StringReader strLogFileCurrent = new System.IO.StringReader(textLogFileCurrent)) {
// A tracker for smoothing the file comparison when the read lines are not the same
bool bothMisplaced;
// get the first line of each record
tempLogFileLine = strLogFileCurrent.ReadLine();
tempStoredLine = strStoredLog.ReadLine();
// compare the lines of each record
while ( null != tempLogFileLine || null != tempStoredLine ) {
bothMisplaced = true;
// if the lines read are different
if ( null != tempLogFileLine && !tempLogFileLine.Equals(tempStoredLine) ) {
// Options: line added or line removed
// Test for Line added (line in the Log File and not in Stored memory)
if ( null != tempLogFileLine && !textMapLogFile.Contains(tempLogFileLine) ) {
// Add the line to the stored Log File
textMapLogFile += "\n" + tempLogFileLine;
// Add the line Master Log, if it isn't already there
MapPoint newItem = new MapPoint(tempLogFileLine);
// Ignore entries without a label. The game inserts the point without a label and then asks the user for the label.
if (newItem.label != "") {
// add the MapPoint to the list and update the Master Log, if successfully added.
if (lstMasterLog.Add(newItem) != -1) {
rewriteMasterLog();
}
// refilter and sort the list
sortNeeded = true;
}
// get the next line in the current Log File
tempLogFileLine = strLogFileCurrent.ReadLine();
bothMisplaced = false;
}
// Test for Line removed (line in Stored memory and not in the Log File)
if ( null != tempStoredLine && !textLogFileCurrent.Contains(tempStoredLine) ) {
// remove the entry from the stored record, so it is a more accurate representation of the Map Log's current contents
textMapLogFile.Remove(textMapLogFile.IndexOf(tempStoredLine),tempStoredLine.Length);
// remove the entry from the master log (in memory and in the file)
lstMasterLog.Remove(tempStoredLine);
rewriteMasterLog();
// get the next line in the stored Log File
tempStoredLine = strStoredLog.ReadLine();
bothMisplaced = false;
}
// if each read line is in the opposing record (neither of the two above 'if's executed)
if (bothMisplaced) {
// read the next line of each record since both current lines are accounted for (just misplaced)
tempLogFileLine = strLogFileCurrent.ReadLine();
tempStoredLine = strStoredLog.ReadLine();
}
} else {
// get the next line of each record
tempLogFileLine = strLogFileCurrent.ReadLine();
tempStoredLine = strStoredLog.ReadLine();
}
}
// release resources when we're done with them
strStoredLog.Close();
strLogFileCurrent.Close();
lastLogged = getLastWriteTimeUTC(btnMapLog.Label);
}
}
} catch (System.OutOfMemoryException) {
// Program ran out of memory to read from a string???
return;
}
}
}
示例15: AddressImport_Click
protected void AddressImport_Click( System.Object sender, System.EventArgs args )
{
if ( !this.IsValid )
return;
bool update_duplicates = false;
System.Web.UI.HtmlControls.HtmlInputCheckBox duplicates = (System.Web.UI.HtmlControls.HtmlInputCheckBox)this.SharpUI.FindControl("duplicates");
if ( duplicates!=null && duplicates.Checked )
update_duplicates = true;
bool error = false;
int count = 0;
int linenumber = 0;
System.Data.DataTable data = GetData();
System.Data.DataView view = data.DefaultView;
if ( update_duplicates )
view.AllowEdit = true;
if ( data!=null && this._data.Value.Length>0 ) {
System.IO.StringReader reader = new System.IO.StringReader(this._data.Value);
System.String line = null;
while ( !error && (line=reader.ReadLine())!=null ) {
linenumber++;
line=line.Trim();
if ( line.Length==0 )
continue;
int index = line.IndexOf(this._delimiter.Value);
if ( index==-1 || index==(line.Length-1) ) {
error = true;
break;
}
System.String name = line.Substring(0, index);
System.String addr = line.Substring(index+1);
if ( name.Length>0 && addr.Length>0 ) {
name = System.Web.HttpUtility.HtmlDecode(name);
addr = System.Web.HttpUtility.HtmlDecode(addr);
if ( !anmar.SharpMimeTools.ABNF.address_regex.IsMatch(addr) ) {
error = true;
break;
}
view.RowFilter = System.String.Concat(data.Columns[1].ColumnName, "='", addr, "'");
if ( view.Count==1 ) {
if ( update_duplicates ) {
view[0][0] = name;
count++;
} else {
if ( log.IsErrorEnabled )
log.Error(System.String.Concat("Error importing record [", addr, "] in addressbook [", this._book_name, "] for user [", this.User.Identity.Name, "] (duplicated item)"));
error = true;
}
} else {
try {
data.Rows.Add(new object[]{name, addr, this._book_name, this.User.Identity.Name});
count++;
} catch ( System.Exception e ) {
if ( log.IsErrorEnabled )
log.Error(System.String.Concat("Error importing record [", addr, "] in addressbook [", this._book_name, "] for user [", this.User.Identity.Name, "]"), e);
error = true;
}
}
}
}
if ( !error ) {
System.Collections.Specialized.ListDictionary addressbook = anmar.SharpWebMail.UI.AddressBook.GetAddressbook(this._book_name, Application["sharpwebmail/send/addressbook"]);
error = !anmar.SharpWebMail.UI.AddressBook.UpdateDataSource(data, addressbook, Session["client"] as anmar.SharpWebMail.IEmailClient );
}
reader.Close();
reader = null;
} else {
error = true;
}
if ( error )
this.SetMessage("addressbookImportError", linenumber);
else
this.SetMessage("addressbookImportSuccess", count);
data = null;
}