/// <summary> /// Loads data from csv file into List of PodatakViewModels to show in grid. /// </summary> /// <param name="filePath">Csv file path (directory + "podaci.csv")</param> /// <returns>List</returns> private async Task <List <PodatakViewModel> > LoadCsvDataFrom(string filePath) { List <PodatakViewModel> pom = new List <PodatakViewModel>(); if (System.IO.File.Exists(filePath)) { using (System.IO.StreamReader objReader = new System.IO.StreamReader(filePath, System.Text.Encoding.UTF8)) { var contents = await objReader.ReadToEndAsync(); using (System.IO.StringReader strReader = new System.IO.StringReader(contents)) { do { var textLine = await strReader.ReadLineAsync(); if (textLine != string.Empty) { pom.Add(new PodatakViewModel( textLine.Split(';') )); } } while (strReader.Peek() != -1); } } } return(pom); }
public async Task<IHttpActionResult> PostTurnoutSwipe(TurnoutSwipeDto dto) { using (var reader = new StringReader(dto.Data)) { string line; while ((line = await reader.ReadLineAsync()) != null) { var match = Regex.Match(line, @"^([+-])\x02\w{2}(\w{8})\w{2}\x03\x03$"); if (!match.Success) continue; var sign = match.Groups[1].ToString(); var hexRfid = match.Groups[2].ToString(); var rfid = Convert.ToInt64(hexRfid, 16); var scout = await Db.Scouts.FirstOrDefaultAsync(s => s.Rfid == rfid); if (scout == null) continue; var point = new TurnoutPoint { Amount = sign == "+" ? 1 : -1, HouseId = scout.HouseId, Time = DateTime.Now }; Db.TurnoutPoints.Add(point); await Db.SaveChangesAsync(); ScoreUpdated(); } return Ok(); } }
public async Task LoadAsync(Stream input, CancellationToken cancellationToken) { if (input == null) throw new ArgumentNullException(nameof(input)); var headerSizeBuffer = BitConverter.GetBytes(default(int)); await input.ReadAsync(headerSizeBuffer, 0, headerSizeBuffer.Length, cancellationToken); var headerSize = BitConverter.ToInt32(headerSizeBuffer, 0); var headerBuffer = new byte[headerSize]; await input.ReadAsync(headerBuffer, 0, headerBuffer.Length, cancellationToken); // Clear the files this.Files.Clear(); using (var sr = new StringReader(Encoding.Unicode.GetString(headerBuffer, 0, headerBuffer.Length))) { var separator = new[] { '|' }; string line; while ((line = await sr.ReadLineAsync()) != null) { var values = line.Split(separator); this.Add(values[0], int.Parse(values[1])); } } }
protected override async Task<IList<EconomicEvent>> ParseEconomicEventsAsync(string rawData) { var reader = new StringReader(rawData); var results = new List<EconomicEvent>(); string header = await reader.ReadLineAsync().ConfigureAwait(false); VerifyHeader(header); string line = string.Empty; while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null) { if (string.IsNullOrEmpty(line)) break; string[] colums = line.Split(','); // be careful about not available data, n/a tentative etc etc try { results.Add(new EconomicEvent { DateTime = ParseDateTime(colums[0].Trim('"')), Name = colums[1].Trim('"'), Country = colums[2].Trim('"'), Currency = CurrencyRegistry.ForCountry(colums[2].Trim('"')), Volatility = colums[3].Trim('"'), Actual = colums[4].Trim('"'), Previous = colums[5].Trim('"'), Consensus = colums[6].Trim('"') }); } catch (Exception e) { Console.WriteLine(e.Message); } } return results; }
static FsharpWorker() { requestQueue = new BufferBlock<FsharpRequest>(); worker = Task.Run(async ()=>{ while(true){ var request = await requestQueue.ReceiveAsync(); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "fsharpi"; startInfo.Arguments = "--nologo"; startInfo.RedirectStandardInput = true; startInfo.RedirectStandardOutput = true; startInfo.UseShellExecute = false; var process = Process.Start(startInfo); var reader = process.StandardOutput; var writer = process.StandardInput; using(var sr = new StringReader(request.Body)){ string line; while((line=await sr.ReadLineAsync())!=null){ writer.WriteLine(line); } } writer.WriteLine(";;"); writer.WriteLine("#quit;;"); string output; string response=""; while((output = await reader.ReadLineAsync())!=null){ response+=output; response+="\r\n"; } if (!process.WaitForExit(200)){ Console.WriteLine("fsharpi process failed to quit in time"); } request.SetResult(response); } }); }
public static async Task<List<GitCommit>> Parse(string output) { GitCommit commit = null; List<GitCommit> commits = new List<GitCommit>(); bool processingMessage = false; using (StringReader strReader = new StringReader(output)) { do { string line = await strReader.ReadLineAsync(); if (line.StartsWith("commit ")) { if (commit != null) commits.Add(commit); commit = new GitCommit(); commit.Sha = line.Split(' ')[1]; } if (startsWithHeader(line)) { var header = line.Split(':')[0]; var val = string.Join(":", line.Split(':').Skip(1)).Trim(); // headers commit.Headers.Add(header, val); } if (string.IsNullOrEmpty(line)) { // commit message divider processingMessage = !processingMessage; } if (line.Length > 0 && line[0] == '\t') { // commit message. commit.Message += line; } if (line.Length > 1 && Char.IsLetter(line[0]) && line[1] == '\t') { var status = line.Split('\t')[0]; var file = line.Split('\t')[1]; commit.Files.Add(new GitFileStatus() { Status = status, File = file }); } } while (strReader.Peek() != -1); } if (commit != null) commits.Add(commit); return commits; }
public async Task WriteMessage(Message message) { if (message == null) throw new ArgumentNullException("message"); var headers = message.Headers; if (headers != null) { foreach (var header in headers) { var headerName = header.Key; var headerValue = header.Value; await _writer.WriteAsync(string.Format("{0}: ", headerName)); using (var headerValueReader = new StringReader(headerValue)) { var multilineContinuation = false; string line; while ((line = await headerValueReader.ReadLineAsync()) != null) { if (multilineContinuation) { // Prefix continuation with whitespace so that subsequent // lines are not confused with different headers. line = " " + line; } await _writer.WriteLineAsync(line); multilineContinuation = true; } } } } // Blank line separates headers from content await _writer.WriteLineAsync(); var content = message.Content; if (!string.IsNullOrWhiteSpace(content)) { // No special formatting required for content. Content is defined as // everything following the blank line. await _writer.WriteAsync(content); } }
private async Task<DateTime> CheckRemoteFilePublicationDateAsync(string file) { DateTime dt = DateTime.MinValue; using (StringReader sr = new StringReader(file)) { string line = string.Empty; while ((line = await sr.ReadLineAsync().ConfigureAwait(false)) != null) { if (line.StartsWith("# -")) { int indexOfDateFirstCharacter = line.IndexOf(":") + 2; int indexOfDateLastCharacter = line.IndexOf(" ", indexOfDateFirstCharacter); int lengthOfDate = (indexOfDateLastCharacter - indexOfDateFirstCharacter) + 1; string dateAsString = line.Substring(indexOfDateFirstCharacter, lengthOfDate); if (DateTime.TryParse(dateAsString, out dt) == false) { dt = new DateTime(2000, 1, 1); } } } } return dt; }
private async Task<List<string>> ConvertRemoteHosts(string remote) { List<string> formatted = new List<string>(); using (StringReader sr = new StringReader(remote)) { string line = string.Empty; while ((line = await sr.ReadLineAsync().ConfigureAwait(false)) != null) { if (line.StartsWith("0.0.0.0")) { string domain = GetDomainName(line); string s = FormatDomainName(domain); formatted.Add(s); } } } return formatted; }
protected override void Report(TextWriter writer) { using (var reader = new StringReader(_output.ToString())) { string line; while ((line = reader.ReadLineAsync().Result) != null) writer.WriteLineAsync(line).Wait(); } }
private static async Task<List<KeyValuePair<string, string>>> GetResponseKeyValuePairList(string responseString) { var list = new List<KeyValuePair<string, string>>(); if (!string.IsNullOrEmpty(responseString)) { using (var stringReader = new StringReader(responseString)) { string line = string.Empty; while (!string.IsNullOrEmpty(line = await stringReader.ReadLineAsync()) && !line.Equals(MPDKeyWords.Response.OK)) { var pair = line.Split(MPDKeyWords.Response.KEYVALUESEPERATION.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); var key = (pair.Length > 0) ? pair[0] : string.Empty; if (pair.Length > 1) pair[1] = pair[1].TrimStart(MPDKeyWords.Response.SPACE.ToCharArray()); var value = string.Empty; for(var i = 1; i < pair.Length; i++) { value += pair[i]; if(i != pair.Length - 1) value += MPDKeyWords.Response.KEYVALUESEPERATION; } list.Add(new KeyValuePair<string, string>(key, value)); } } } return list; }