本文整理汇总了C#中System.IO.StreamReader类的典型用法代码示例。如果您正苦于以下问题:C# StreamReader类的具体用法?C# StreamReader怎么用?C# StreamReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StreamReader类属于System.IO命名空间,在下文中一共展示了StreamReader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ResetIp
private void ResetIp()
{
try
{
textBoxIP.Text = "";
var req = (HttpWebRequest)WebRequest.Create("http://canyouseeme.org");
var resp = (HttpWebResponse)req.GetResponse();
string x = new StreamReader(resp.GetResponseStream()).ReadToEnd();
// input type="hidden" name="IP" value="41.28.175.2"/>
string[] sepd = x.Split(new char[] { '<' });
foreach (string s in sepd)
if (s.Contains("input type=\"hidden\" name=\"IP\""))
{
string[] spdbyspace = s.Split(new char[] { ' ' });
foreach (string sen in spdbyspace)
if (sen.Contains("value"))
{
string[] spd_by_qoute = sen.Split(new char[] { '"' });
this.CurrentExIp = spd_by_qoute[1];
textBoxIP.Text = this.CurrentExIp;
this.ExIpDetetected = true;
return;
}
}
}
catch (Exception z)
{
textBoxIP.Text = "No internet";
}
}
开发者ID:4neso,项目名称:Rykon2,代码行数:31,代码来源:FormIps.cs
示例2: Main
static void Main(string[] args)
{
var m_Config = new ServerConfig
{
Port = 911,
Ip = "Any",
MaxConnectionNumber = 1000,
Mode = SocketMode.Tcp,
Name = "CustomProtocolServer"
};
var m_Server = new CustomProtocolServer();
m_Server.Setup(m_Config, logFactory: new ConsoleLogFactory());
m_Server.Start();
EndPoint serverAddress = new IPEndPoint(IPAddress.Parse("127.0.0.1"), m_Config.Port);
using (Socket socket = new Socket(serverAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
{
socket.Connect(serverAddress);
var socketStream = new NetworkStream(socket);
var reader = new StreamReader(socketStream, Encoding.ASCII, false);
string charSource = Guid.NewGuid().ToString().Replace("-", string.Empty)
+ Guid.NewGuid().ToString().Replace("-", string.Empty)
+ Guid.NewGuid().ToString().Replace("-", string.Empty);
Random rd = new Random();
var watch = Stopwatch.StartNew();
for (int i = 0; i < 10; i++)
{
int startPos = rd.Next(0, charSource.Length - 2);
int endPos = rd.Next(startPos + 1, charSource.Length - 1);
var currentMessage = charSource.Substring(startPos, endPos - startPos + 1);
byte[] requestNameData = Encoding.ASCII.GetBytes("ECHO");
socketStream.Write(requestNameData, 0, requestNameData.Length);
var data = Encoding.ASCII.GetBytes(currentMessage);
socketStream.Write(new byte[] { (byte)(data.Length / 256), (byte)(data.Length % 256) }, 0, 2);
socketStream.Write(data, 0, data.Length);
socketStream.Flush();
// Console.WriteLine("Sent: " + currentMessage);
var line = reader.ReadLine();
//Console.WriteLine("Received: " + line);
//Assert.AreEqual(currentMessage, line);
}
watch.Stop();
Console.WriteLine(watch.ElapsedMilliseconds);
}
Console.ReadLine();
}
开发者ID:zesus19,项目名称:c5.v1,代码行数:60,代码来源:Program.cs
示例3: GetDealClosingCostTypesFromDeepBlue
public static List<DeepBlue.Models.Entity.DealClosingCostType> GetDealClosingCostTypesFromDeepBlue(CookieCollection cookies)
{
// Admin/DealClosingCostTypeList?pageIndex=1&pageSize=5000&sortName=Name&sortOrder=asc
List<DeepBlue.Models.Entity.DealClosingCostType> dealClosingCostTypes = new List<DeepBlue.Models.Entity.DealClosingCostType>();
// Send the request
string url = HttpWebRequestUtil.GetUrl("Admin/DealClosingCostTypeList?pageIndex=1&pageSize=5000&sortName=Name&sortOrder=asc");
HttpWebResponse response = HttpWebRequestUtil.SendRequest(url, null, false, cookies, false, HttpWebRequestUtil.JsonContentType);
if (response.StatusCode == System.Net.HttpStatusCode.OK) {
using (Stream receiveStream = response.GetResponseStream()) {
// Pipes the stream to a higher level stream reader with the required encoding format.
using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8)) {
string resp = readStream.ReadToEnd();
if (!string.IsNullOrEmpty(resp)) {
JavaScriptSerializer js = new JavaScriptSerializer();
FlexigridData flexiGrid = (FlexigridData)js.Deserialize(resp, typeof(FlexigridData));
foreach (Helpers.FlexigridRow row in flexiGrid.rows) {
DeepBlue.Models.Entity.DealClosingCostType dealClosingType = new DeepBlue.Models.Entity.DealClosingCostType();
dealClosingType.DealClosingCostTypeID = Convert.ToInt32(row.cell[0]);
dealClosingType.Name = Convert.ToString(row.cell[1]);
dealClosingCostTypes.Add(dealClosingType);
}
}
else {
}
response.Close();
readStream.Close();
}
}
}
return dealClosingCostTypes;
}
开发者ID:jsingh,项目名称:DeepBlue,代码行数:31,代码来源:DealImport.cs
示例4: Start
public void Start(string[] args)
{
registry = new Registry();
if (!registry.Register(this))
{
Console.WriteLine("Error registering service.");
return;
}
Console.WriteLine("Registered service.");
try
{
TcpClient tcpclient = new TcpClient();
if (args.Count() != 2)
throw new Exception("Argument must contain a publishing ip and port. call with: 127.0.0.1 12345");
tcpclient.Connect(args[0], Int32.Parse(args[1]));
StreamReader sr = new StreamReader(tcpclient.GetStream());
string data;
while ((data = sr.ReadLine()) != null)
{
Console.WriteLine("Raw data: " + data);
if (RawAisData != null)
RawAisData(data);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message + e.StackTrace);
Console.WriteLine("Press enter");
Console.ReadLine();
}
}
开发者ID:Gohla,项目名称:protophase,代码行数:31,代码来源:RawAisPublisher.cs
示例5: sendMessage
private void sendMessage()
{
MailAddress adresa = new MailAddress("[email protected]");
MailMessage zpráva;
if (logFile)
{
string log;
using (StreamReader reader = new StreamReader(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Info", "Log", "logStatusBaru.log")))
{
log = reader.ReadToEnd();
}
if (log.Length > 50000)
log.Remove(50000);
zpráva = new MailMessage("[email protected]", "[email protected]", předmětTextBox.Text, textZprávyTextBox.Text + log);
}
else
{
zpráva = new MailMessage("[email protected]", "[email protected]", předmětTextBox.Text, textZprávyTextBox.Text);
}
SmtpClient klient = new SmtpClient();
klient.Host = "smtp.gmail.com";
klient.Port = 465;
klient.EnableSsl = true;
//klient.Send(zpráva);
}
开发者ID:Cendrb,项目名称:UTU,代码行数:25,代码来源:OdeslatNázor.xaml.cs
示例6: AllFieldsEmptyTest
public void AllFieldsEmptyTest()
{
using( var stream = new MemoryStream() )
using( var reader = new StreamReader( stream ) )
using( var writer = new StreamWriter( stream ) )
using( var parser = new CsvParser( reader ) )
{
writer.WriteLine( ";;;;" );
writer.WriteLine( ";;;;" );
writer.Flush();
stream.Position = 0;
parser.Configuration.Delimiter = ";;";
parser.Configuration.HasHeaderRecord = false;
var row = parser.Read();
Assert.IsNotNull( row );
Assert.AreEqual( 3, row.Length );
Assert.AreEqual( "", row[0] );
Assert.AreEqual( "", row[1] );
Assert.AreEqual( "", row[2] );
row = parser.Read();
Assert.IsNotNull( row );
Assert.AreEqual( 3, row.Length );
Assert.AreEqual( "", row[0] );
Assert.AreEqual( "", row[1] );
Assert.AreEqual( "", row[2] );
row = parser.Read();
Assert.IsNull( row );
}
}
开发者ID:KPK-Teamwork-Team-Bajic,项目名称:KPK-Teamwork,代码行数:33,代码来源:CsvParserDelimiterTests.cs
示例7: Main
public static void Main()
{
var url = new Uri(ApiUrl + "?auth-id=" + AuthenticationID + "&auth-token=" + AuthenticationToken);
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
using (var stream = request.GetRequestStream())
using (var writer = new StreamWriter(stream))
writer.Write(RequestPayload);
using (var response = request.GetResponse())
using (var stream = response.GetResponseStream())
using (var reader = new StreamReader(stream))
{
var rawResponse = reader.ReadToEnd();
Console.WriteLine(rawResponse);
// Suppose you wanted to use Json.Net to pretty-print the response (delete the next two lines if not):
// Json.Net: http://http://json.codeplex.com/
dynamic parsedJson = JsonConvert.DeserializeObject(rawResponse);
Console.WriteLine(JsonConvert.SerializeObject(parsedJson, Formatting.Indented));
// Or suppose you wanted to deserialize the json response to a defined structure (defined below):
var candidates = JsonConvert.DeserializeObject<CandidateAddress[]>(rawResponse);
foreach (var address in candidates)
Console.WriteLine(address.DeliveryLine1);
}
Console.ReadLine();
}
开发者ID:42shadow42,项目名称:LiveAddressSamples,代码行数:30,代码来源:street-address-batch.cs
示例8: Delete
/// <summary>
/// 删除文件
/// </summary>
/// <param name="fileName"></param>
public void Delete(string fileName)
{
try
{
string uri = ftpURI + fileName;
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.DeleteFile;
string result = String.Empty;
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
long size = response.ContentLength;
Stream datastream = response.GetResponseStream();
StreamReader sr = new StreamReader(datastream);
result = sr.ReadToEnd();
sr.Close();
datastream.Close();
response.Close();
}
catch (Exception ex)
{
Insert_Standard_ErrorLog.Insert("FtpWeb", "Delete Error --> " + ex.Message + " 文件名:" + fileName);
}
}
开发者ID:dingxinbei,项目名称:OLdBck,代码行数:31,代码来源:FtpWeb.cs
示例9: ReadStudentsInfoFromFile
private static void ReadStudentsInfoFromFile(string filePath, SortedDictionary<string, SortedSet<Student>> courses)
{
using (StreamReader reader = new StreamReader(filePath))
{
string line = reader.ReadLine();
while (line != string.Empty && line != null)
{
string[] data = line.Split('|');
string firstName = data[0].Trim();
string lastName = data[1].Trim();
string courseName = data[2].Trim();
if (courses.ContainsKey(courseName))
{
courses[courseName].Add(new Student(firstName, lastName));
}
else
{
courses[courseName] = new SortedSet<Student>();
courses[courseName].Add(new Student(firstName, lastName));
}
line = reader.ReadLine();
}
}
}
开发者ID:dchakov,项目名称:Data-Structures-and-Algorithms_HW,代码行数:26,代码来源:StartUp.cs
示例10: ReadToken
private object ReadToken(StreamReader sr)
{
EatWhitespace(sr);
char c = sr.ReadChar();
switch (c)
{
case '{':
return ReadDict(sr);
case '/':
{
if (sr.PeekChar() == '/')
{
sr.ReadLine();
return null;
}
else
{
return ReadString(sr, c);
}
}
default:
return ReadString(sr, c);
}
}
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:26,代码来源:KeyValues.cs
示例11: EatWhitespace
private void EatWhitespace(StreamReader sr)
{
while (char.IsWhiteSpace(sr.PeekChar()))
{
sr.ReadChar();
}
}
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:7,代码来源:KeyValues.cs
示例12: Decrypt
public static string Decrypt(string sourceData)
{
// set key and initialization vector values
byte[] key = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
byte[] iv = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
try
{
// convert data to byte array
byte[] encryptedDataBytes =
Convert.FromBase64String(sourceData);
// get source memory stream and fill it
MemoryStream tempStream =
new MemoryStream(encryptedDataBytes, 0,
encryptedDataBytes.Length);
// get decryptor and decryption stream
DESCryptoServiceProvider decryptor =
new DESCryptoServiceProvider();
CryptoStream decryptionStream =
new CryptoStream(tempStream,
decryptor.CreateDecryptor(key, iv),
CryptoStreamMode.Read);
// decrypt data
StreamReader allDataReader =
new StreamReader(decryptionStream);
return allDataReader.ReadToEnd();
}
catch
{
throw new StringEncryptorException(
"Unable to decrypt data.");
}
}
开发者ID:moacap,项目名称:BalloonShop-2-MVC,代码行数:35,代码来源:StringEncryptor.cs
示例13: Download
public string Download(Uri uri)
{
using(var reader = new StreamReader(uri.LocalPath))
{
return reader.ReadToEnd();
}
}
开发者ID:paveltimofeev,项目名称:Caliberweb-Core,代码行数:7,代码来源:FileWebClient.cs
示例14: Up
public override void Up()
{
AddTables();
using (var sm = new StreamReader(GetType().Assembly.GetManifestResourceStream("DVS.Database.Databases.DVS_DB.Version2.SystemData.sql")))
{
var systemDataScript = sm.ReadToEnd();
if (!String.IsNullOrEmpty(systemDataScript))
AddSql(systemDataScript);
}
Sql(@"create trigger dbo.tr_PopGeolocation
on dbo.AppraiserServiceAreas
for insert, update
as
BEGIN
update a
set [GeoLocation] = geography::STGeomFromText('POINT(' + CAST([a].[Longitude] AS VARCHAR(20)) + ' ' + CAST([a].[Latitude] AS VARCHAR(20)) + ')', 4326)
from dbo.AppraiserServiceAreas a
join inserted i on i.id = a.id
END");
if (DbConfigManager.IsAddTestData)
{
using (var sm = new StreamReader(GetType().Assembly.GetManifestResourceStream("DVS.Database.Databases.DVS_DB.Version2.TestData.sql")))
{
var testDataScript = sm.ReadToEnd();
if (!String.IsNullOrEmpty(testDataScript))
AddSql(testDataScript);
}
}
}
开发者ID:evkap,项目名称:DVS,代码行数:32,代码来源:Version2.cs
示例15: SaveTileBackgroundImage
private static void SaveTileBackgroundImage(TileViewModel model)
{
string xamlCode;
using (var tileStream = Application.GetResourceStream(new Uri("/WP7LiveTileDemo;component/Controls/CustomTile.xaml", UriKind.Relative)).Stream)
{
using (var reader = new StreamReader(tileStream))
{
xamlCode = reader.ReadToEnd();
}
}
var control = (Control)XamlReader.Load(xamlCode);
control.DataContext = model;
var bitmap = new WriteableBitmap(173, 173);
bitmap.Render(control, new TranslateTransform());
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var stream = store.CreateFile(TileBackgroundPath))
{
bitmap.Invalidate();
bitmap.SaveJpeg(stream, 173, 173, 0, 100);
stream.Close();
}
}
}
开发者ID:danclarke,项目名称:WP7LiveTileDemo,代码行数:29,代码来源:TileUtil.cs
示例16: GeoIP
public GeoIP()
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://freegeoip.net/xml/");
request.Proxy = null;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseString = reader.ReadToEnd();
reader.Close();
dataStream.Close();
response.Close();
XmlDocument doc = new XmlDocument();
doc.LoadXml(responseString);
WANIP = doc.SelectSingleNode("Response//Ip").InnerXml.ToString();
Country = (!string.IsNullOrEmpty(doc.SelectSingleNode("Response//CountryName").InnerXml.ToString())) ? doc.SelectSingleNode("Response//CountryName").InnerXml.ToString() : "Unknown";
CountryCode = (!string.IsNullOrEmpty(doc.SelectSingleNode("Response//CountryCode").InnerXml.ToString())) ? doc.SelectSingleNode("Response//CountryCode").InnerXml.ToString() : "-";
Region = (!string.IsNullOrEmpty(doc.SelectSingleNode("Response//RegionName").InnerXml.ToString())) ? doc.SelectSingleNode("Response//RegionName").InnerXml.ToString() : "Unknown";
City = (!string.IsNullOrEmpty(doc.SelectSingleNode("Response//City").InnerXml.ToString())) ? doc.SelectSingleNode("Response//City").InnerXml.ToString() : "Unknown";
}
catch
{
WANIP = "-";
Country = "Unknown";
CountryCode = "-";
Region = "Unknown";
City = "Unknown";
}
}
开发者ID:kr-app-a72,项目名称:Computer-Info,代码行数:32,代码来源:GeoIP.cs
示例17: Post
public static string Post(this HttpListenerRequest request, string str)
{
using (StreamReader stream = new StreamReader(request.InputStream))
{
return stream.ReadToEnd();
}
}
开发者ID:REDECODE,项目名称:ArchimedeSDK,代码行数:7,代码来源:WebServer.cs
示例18: Shader
public Shader(GraphicsDevice dev, string name)
{
this.dev = dev;
string code;
using (var file = new StreamReader(FileSystem.Open("cg{0}{1}.fx".F(Path.DirectorySeparatorChar, name))))
code = file.ReadToEnd();
effect = Tao.Cg.Cg.cgCreateEffect(dev.Context, code, null);
if (effect == IntPtr.Zero)
{
var err = Tao.Cg.Cg.cgGetErrorString(Tao.Cg.Cg.cgGetError());
var results = Tao.Cg.Cg.cgGetLastListing(dev.Context);
throw new InvalidOperationException(
"Cg compile failed ({0}):\n{1}".F(err, results));
}
technique = Tao.Cg.Cg.cgGetFirstTechnique(effect);
if (technique == IntPtr.Zero)
throw new InvalidOperationException("No techniques");
while (Tao.Cg.Cg.cgValidateTechnique(technique) == 0)
{
technique = Tao.Cg.Cg.cgGetNextTechnique(technique);
if (technique == IntPtr.Zero)
throw new InvalidOperationException("No valid techniques");
}
}
开发者ID:Generalcamo,项目名称:OpenRA,代码行数:26,代码来源:Shader.cs
示例19: DlgTips_Load
private void DlgTips_Load(object sender, EventArgs e)
{
try
{
string strxml = "";
using (StreamReader streamReader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Johnny.Kaixin.WinUI.Resources.Versions.config")))
{
strxml = streamReader.ReadToEnd();
}
XmlDocument objXmlDoc = new XmlDocument();
objXmlDoc.LoadXml(strxml);
if (objXmlDoc == null)
return;
DataView dv = GetData(objXmlDoc, "ZrAssistant/Versions");
for (int ix = 0; ix < dv.Table.Rows.Count; ix++)
{
_versionList.Add(dv.Table.Rows[ix][0].ToString(), dv.Table.Rows[ix][1].ToString());
cmbVersion.Items.Add(dv.Table.Rows[ix][0].ToString());
}
chkNeverDisplay.Checked = Properties.Settings.Default.NeverDisplay;
cmbVersion.SelectedIndex = 0;
SetTextValue();
btnOk.Select();
}
catch (Exception ex)
{
Program.ShowMessageBox("DlgTips", ex);
}
}
开发者ID:jojozhuang,项目名称:Projects,代码行数:34,代码来源:DlgTips.cs
示例20: ReadFromFSLocation
private string ReadFromFSLocation(string path)
{
using (StreamReader sr = new StreamReader(path))
{
return sr.ReadToEnd().Trim();
}
}
开发者ID:mikekberg,项目名称:GIOPL.NET,代码行数:7,代码来源:EdisonDevicePinService.cs
注:本文中的System.IO.StreamReader类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论