public List<Token> process(TextReader pTextReader) { D.isNull(pTextReader); _tokens = new List<Token>(); _textReader = pTextReader; _endOfFile = false; readNextChar(); _currentLine = 1; _currentPosition = 0; _currentTokenStartPosition = 0; Token t; do { t = readNextToken(); t.LineNr = _currentLine; t.LinePosition = _currentTokenStartPosition; _currentTokenStartPosition = _currentPosition; _tokens.Add(t); #if WRITE_DEBUG Console.WriteLine(t.LineNr + ": " + t.getTokenType().ToString() + " " + t.getTokenString()); #endif } while(t.getTokenType() != Token.TokenType.EOF); _textReader.Close(); _textReader.Dispose(); return _tokens; }
public UpgradesComparison(TextReader reader) { InitializeComponent(); MainPage.Instance.UpgradeListOpen = true; Graph.Mode = ComparisonGraph.DisplayMode.Overall; Graph.Character = MainPage.Instance.Character; try { XmlSerializer serializer = new XmlSerializer(typeof(SerializationData)); SerializationData data = (SerializationData)serializer.Deserialize(reader); SetCustomSubpoints(data.CustomSubpoints); itemCalculations = new Dictionary<string, ComparisonCalculationUpgrades[]>(); for (int i = 0; i < data.Keys.Count; i++) { itemCalculations[data.Keys[i]] = data.ItemCalculations[i]; } SlotCombo.SelectedIndex = 0; } catch (Exception /*e*/) { Close(); MessageBox.Show("The chosen file is not a Rawr Upgrade List.", "Unable to Load Upgrade List", MessageBoxButton.OK); } finally { reader.Dispose(); } }
public List<Token> process(TextReader textReader) { Debug.Assert(textReader != null); m_tokens = new List<Token>(); m_textReader = textReader; m_endOfFile = false; readNextChar(); m_currentLine = 1; m_currentPosition = 0; m_currentTokenStartPosition = 0; Token t; do { t = readNextToken(); t.LineNr = m_currentLine; t.LinePosition = m_currentTokenStartPosition; m_currentTokenStartPosition = m_currentPosition; m_tokens.Add(t); //Console.WriteLine(t.LineNr + ": " + t.getTokenType().ToString() + " " + t.getTokenString()); } while(t.getTokenType() != Token.TokenType.EOF); m_textReader.Close(); m_textReader.Dispose(); return m_tokens; }
public static TextReader Normalize(TextReader tr, ISerializationContext ctx) { string s = tr.ReadToEnd(); TextReader reader = Normalize(s, ctx); tr.Dispose(); return reader; }
public static void TestNullTextReader(TextReader input) { StreamReader sr = input as StreamReader; if (sr != null) Assert.True(sr.EndOfStream, "EndOfStream property didn't return true"); input.ReadLine(); input.Dispose(); input.ReadLine(); if (sr != null) Assert.True(sr.EndOfStream, "EndOfStream property didn't return true"); input.Read(); input.Peek(); input.Read(new char[2], 0, 2); input.ReadToEnd(); input.Dispose(); }
private void displayData(TextReader reader) { source.Text = ""; string line = reader.ReadLine(); while (line != null) { source.Text += line + '\n'; line = reader.ReadLine(); } reader.Dispose(); }
public void Done() { try { input.Dispose(); } catch (Exception e) when(e.IsIOException()) { Console.Error.WriteLine("Caught: " + e + "; ignoring."); } }
internal XmlClientConfigBuilder(TextReader reader) { try { _document.Load(reader); reader.Dispose(); } catch (Exception) { throw new InvalidOperationException("Could not parse configuration file, giving up."); } }
public SettingsFileManager(string filename) { InitializeDefaultSettings(); settings = new Dictionary<Settings, string>(); try { reader = new StreamReader(filename); } catch (FileNotFoundException) { File.Create(filename); reader = new StreamReader(filename); } bool endReached = false; List<string> lines = new List<string>(); while (!endReached) { string line = reader.ReadLine(); if (line == null) { endReached = true; } else { lines.Add(line); } } reader.Close(); reader.Dispose(); foreach (string line in lines) { // Ignore comments if(line.StartsWith("//")) continue; // Split string into key and value string[] linePieces = line.Split('='); if (1< linePieces.Length && linePieces.Length <3) { // Turn the first argument into an enum constant Settings s = (Settings)Enum.Parse(typeof(Settings), linePieces[0].ToUpper(), true); settings.Add(s, linePieces[1]); } } }
internal ODataJsonInputContext(ODataFormat format, TextReader reader, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, bool readingResponse, bool synchronous, IEdmModel model, IODataUrlResolver urlResolver) : base(format, messageReaderSettings, version, readingResponse, synchronous, model, urlResolver) { ExceptionUtils.CheckArgumentNotNull<ODataFormat>(format, "format"); ExceptionUtils.CheckArgumentNotNull<ODataMessageReaderSettings>(messageReaderSettings, "messageReaderSettings"); try { this.textReader = reader; this.jsonReader = new BufferingJsonReader(this.textReader, base.UseServerFormatBehavior, messageReaderSettings.MessageQuotas.MaxNestingDepth); } catch (Exception exception) { if (ExceptionUtils.IsCatchableExceptionType(exception) && (reader != null)) { reader.Dispose(); } throw; } }
private void settings() { int settChoice = 0; Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("1"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(". % Miesięczny Zysk"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("\n2"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(". !RESET!"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("\n3"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(". Wróc do MENU"); Console.Write("\n-> "); s = Console.ReadLine(); while (settChoice != 1 && settChoice != 2 && settChoice != 3) { try { settChoice = int.Parse(s); break; } catch (Exception e) { Console.Write("-> "); s = Console.ReadLine(); } finally { } } Console.Clear(); switch (settChoice) { case 1: Console.Write("Twój aktualny planowy % miesięczny zysk to : "); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(expectedMonthlyIncome); Console.ForegroundColor = ConsoleColor.Gray; double uexpectedMonthlyIncome = 0.0D; int probowal = 0; UEXPECTEDMONTHLYINCOME: if (probowal == 0) { Console.Write("\n\nJaki chciałbyś mieć miesięczny zysk w % [ 0.00 - 0% , 1.00 - 100% ] ( Format - 0.00 ) : "); probowal++; } else { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format, ta liczba może być ułamkiem z ',' lub '.', z przedziału od 0 do 1 ( np. 0.50 [ czyli 50% ] ) : "); Console.ForegroundColor = ConsoleColor.Gray; } s = Console.ReadLine(); try { uexpectedMonthlyIncome = stringToDouble(s); } catch (Exception e) { while (true == true) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format, ta liczba może być ułamkiem z ',' lub '.', z przedziału od 0 do 1 ( np. 0.50 [ czyli 50% ] ) : "); Console.ForegroundColor = ConsoleColor.Gray; s = Console.ReadLine(); try { uexpectedMonthlyIncome = stringToDouble(s); break; } catch (Exception ee) { } finally { } } } finally { } if (uexpectedMonthlyIncome <= 0 || uexpectedMonthlyIncome > 1) { goto UEXPECTEDMONTHLYINCOME; } // Zaktualizuj bankroll , endDate , bankrollTo, startingAvarageIncome // Wczytaj pierwszą linię string pierwszaLinijka = ""; string reszta = ""; try { textReader = new StreamReader(fileName); } catch (Exception e) { } finally { pierwszaLinijka = textReader.ReadLine(); reszta = textReader.ReadToEnd(); textReader.Dispose(); textReader.Close(); } expectedMonthlyIncome = uexpectedMonthlyIncome; // Wpisz try { textWriter = new StreamWriter(fileName); } catch (Exception e) { } finally { s = nickname.ToString() + "_" + pickCount.ToString() + "_" + bankroll.ToString() + "_" + bankrollStart.ToString() + "_" + bankrollTo.ToString() + "_" + startDate.ToShortDateString() + "_" + endDate.ToShortDateString() + "_" + startingAvarageIncome.ToString() + "_" + expectedMonthlyIncome.ToString() + "_" + avarageOdd + "_" + betTypes.ToUpper(); textWriter.WriteLine(s); textWriter.Write(reszta); textWriter.Flush(); textWriter.Dispose(); textWriter.Close(); } // ATTENTION Console.ForegroundColor = ConsoleColor.Red; Console.Write("\n!! Ta zmiana będzie miała wpływ dopiero po zakończeniu danego cyklu !!"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\n\nNaciśniej ENTER aby wyjść..."); if (Console.ReadLine() != "EXIT") { } // EXIT break; case 2: // USUWANIE ALL OSTATNIA RZECZ WOOOO :D Console.Write("Ta operacja spowoduję że stracisz wszystko swoje dotychczasowe dane, mecze i statystyki."); Console.ForegroundColor = ConsoleColor.Red; Console.Write("\nCZY ABY NAPEWNO CHCESZ TO ZROBIĆ!? ('T' jeżeli tak) : "); Console.ForegroundColor = ConsoleColor.Gray; s = Console.ReadLine(); if (s.ToUpper() == "T") { try { textWriter = new StreamWriter(fileName); } catch (Exception e) { } finally { textWriter.Write(""); textWriter.Flush(); textWriter.Dispose(); textWriter.Close(); Environment.Exit(0); } } break; case 3: break; } Console.Clear(); }
internal ODataJsonLightInputContext( ODataFormat format, TextReader reader, ODataMediaType contentType, ODataMessageReaderSettings messageReaderSettings, bool readingResponse, bool synchronous, IEdmModel model, IODataUrlResolver urlResolver) : base(format, messageReaderSettings, readingResponse, synchronous, model, urlResolver) { Debug.Assert(reader != null, "reader != null"); Debug.Assert(contentType != null, "contentType != null"); try { ExceptionUtils.CheckArgumentNotNull(format, "format"); ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings"); } catch (ArgumentNullException) { // Dispose the message stream if we failed to create the input context. reader.Dispose(); throw; } try { this.textReader = reader; if (contentType.HasStreamingSetToTrue()) { this.jsonReader = new BufferingJsonReader( this.textReader, JsonLightConstants.ODataErrorPropertyName, messageReaderSettings.MessageQuotas.MaxNestingDepth, ODataFormat.Json, contentType.HasIeee754CompatibleSetToTrue()); } else { // If we have a non-streaming Json Light content type we need to use the re-ordering Json reader this.jsonReader = new ReorderingJsonReader(this.textReader, messageReaderSettings.MessageQuotas.MaxNestingDepth, contentType.HasIeee754CompatibleSetToTrue()); } } catch (Exception e) { // Dispose the message stream if we failed to create the input context. if (ExceptionUtils.IsCatchableExceptionType(e) && reader != null) { reader.Dispose(); } throw; } // dont know how to get MetadataDocumentUri uri here, messageReaderSettings do not have one // Uri metadataDocumentUri = messageReaderSettings..MetadataDocumentUri == null ? null : messageReaderSettings.MetadataDocumentUri.BaseUri; // the uri here is used here to create the FullMetadataLevel can pass null in this.metadataLevel = JsonLight.JsonLightMetadataLevel.Create(contentType, null, model, readingResponse); }
public override void Parse(TextReader @in) { int lineNumber = 0; try { string line = null; while ((line = @in.ReadLine()) != null) { lineNumber++; if (line.Length == 0 || line[0] == '#') { continue; // ignore empty lines and comments } CharsRef[] inputs; CharsRef[] outputs; // TODO: we could process this more efficiently. string[] sides = Split(line, "=>"); if (sides.Length > 1) // explicit mapping { if (sides.Length != 2) { throw new System.ArgumentException("more than one explicit mapping specified on the same line"); } string[] inputStrings = Split(sides[0], ","); inputs = new CharsRef[inputStrings.Length]; for (int i = 0; i < inputs.Length; i++) { inputs[i] = Analyze(Unescape(inputStrings[i]).Trim(), new CharsRef()); } string[] outputStrings = Split(sides[1], ","); outputs = new CharsRef[outputStrings.Length]; for (int i = 0; i < outputs.Length; i++) { outputs[i] = Analyze(Unescape(outputStrings[i]).Trim(), new CharsRef()); } } else { string[] inputStrings = Split(line, ","); inputs = new CharsRef[inputStrings.Length]; for (int i = 0; i < inputs.Length; i++) { inputs[i] = Analyze(Unescape(inputStrings[i]).Trim(), new CharsRef()); } if (expand) { outputs = inputs; } else { outputs = new CharsRef[1]; outputs[0] = inputs[0]; } } // currently we include the term itself in the map, // and use includeOrig = false always. // this is how the existing filter does it, but its actually a bug, // especially if combined with ignoreCase = true for (int i = 0; i < inputs.Length; i++) { for (int j = 0; j < outputs.Length; j++) { Add(inputs[i], outputs[j], false); } } } } catch (System.ArgumentException e) { throw new Exception("Invalid synonym rule at line " + lineNumber, e); //ex.initCause(e); //throw ex; } finally { @in.Dispose(); } }
public void Close() { _reader.Dispose(); }
public override object Deserialize(TextReader tr) { if (tr != null) { // Normalize the text before parsing it tr = TextUtil.Normalize(tr, SerializationContext); // Create a lexer for our text stream iCalLexer lexer = new iCalLexer(tr); iCalParser parser = new iCalParser(lexer); // Get our serialization context ISerializationContext ctx = SerializationContext; // Parse the component! ICalendarProperty p = parser.property(ctx, null); // Close our text stream tr.Dispose(); // Return the parsed property return p; } return null; }
private void addPick() { bool havePending = checkIfHavePendingBets(); if (havePending) { Console.WriteLine("Masz zakłady w grze, najpierw je zaktualizuj!"); Console.Write("\nKlinij ENTER aby wrócić do Menu..."); if (Console.ReadLine() != "EXIT!") { } } else { int id = pickCount + 1; string zdarzenie = ""; // DO POBRANIA!! string typZdarzenia = ""; // DO POBRANIA!! int howManyDaysLeft; double ileDoZarobkuDziennie; string choice = ""; // DO POBRANIA double plusMinus = 0.0D; double probability = 0.0D; // DO POBRANIA double odd = 0.0D; // DO POBRANIA!! double value = 0.0D; double stake; double doZarobkuTeraz; double obstawioneWStepie = 0.0D; DateTime today = new DateTime( DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day ); double remainingToWin; int daysLeft; double multiplier = 1.0D; Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("Nazwa zdarzenia "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("( Format : dowolny ciąg znaków ) : "); zdarzenie = Console.ReadLine(); while (zdarzenie == "") { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format. Musisz podać niepusty ciąg znaków : "); Console.ForegroundColor = ConsoleColor.Gray; zdarzenie = Console.ReadLine(); } // //// // Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("Typ "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("( Format : dowolny ciąg znaków ) : "); choice = Console.ReadLine(); while (zdarzenie == "") { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format. Musisz podać niepusty ciąg znaków : "); Console.ForegroundColor = ConsoleColor.Gray; choice = Console.ReadLine(); } // //// // int probowal = 0; ODD: if (probowal == 0) { Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("Kurs "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("( Format : ułamek ze znakiem '.' lub ',' z przedziału od 1.00 do +Infinity ( np. 1.65 ) : "); probowal++; } else { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format, ta liczba może być ułamkiem z ',' lub '.', z przedziału od 1.00 do +Infinity ( np. 1.65 ) : "); Console.ForegroundColor = ConsoleColor.Gray; } s = Console.ReadLine(); try { odd = stringToDouble(s); } catch (Exception e) { while (true == true) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format, ta liczba może być ułamkiem z ',' lub '.', z przedziału od 1.00 do +Infinity ( np. 1.65 ) : "); Console.ForegroundColor = ConsoleColor.Gray; s = Console.ReadLine(); try { odd = stringToDouble(s); break; } catch (Exception ee) { } finally { } } } finally { } if (odd < 1) { goto ODD; } // //// // probowal = 0; PROBABILITY: if (probowal == 0) { Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("Prawdopodobieństwo "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("( Format : procent, jako ułamek ze znakiem '.' lub ',' z przedziału od 0 do 1 ( np. 0.50 ) : "); probowal++; } else { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format, ta liczba może być ułamkiem z ',' lub '.', z przedziału od 0 do 1 ( np. 0.50 ) : "); Console.ForegroundColor = ConsoleColor.Gray; } s = Console.ReadLine(); try { probability = stringToDouble(s); } catch (Exception e) { while (true == true) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format, ta liczba może być ułamkiem z ',' lub '.', z przedziału od 0 do 1 ( np. 0.50 ) : "); Console.ForegroundColor = ConsoleColor.Gray; s = Console.ReadLine(); try { probability = stringToDouble(s); break; } catch (Exception ee) { } finally { } } } finally { } if (probability <= 0 || probability > 1) { goto PROBABILITY; } /////////////////////////// Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("Rodzaj "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("( Format : pojedyńczy znak, 'P' jako PreGame, 'L' jako Live ) : "); typZdarzenia = Console.ReadLine(); while (typZdarzenia.ToUpper() != "P" && typZdarzenia.ToUpper() != "L") { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format, wpisz jeden znak [ P lub L ] : "); Console.ForegroundColor = ConsoleColor.Gray; typZdarzenia = Console.ReadLine(); } Console.ForegroundColor = ConsoleColor.Magenta; Console.Write("\nJesteś pewien że chcesz dodać ten zakład? Wpisz 'T' jeżeli tak, inny znak aby wyjść"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\n-> "); s = Console.ReadLine(); bool moznaWykonac = true; if (s.ToUpper() == "T") { // // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! SPRAWDŹ CZY RODZAJ ZAKŁADÓW ZGADZA SIĘ Z TWOIMI PREFERENCJAMI // try { textReader = new StreamReader(fileName); } catch (Exception e) { } finally { s = textReader.ReadLine(); textArray = s.Split(znakiOdstepu); string preferencja = textArray[10].ToUpper(); if (typZdarzenia != preferencja.ToUpper()) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.Write("\nNie możesz grać zakładów tego rodzaju!"); Console.ForegroundColor = ConsoleColor.Gray; moznaWykonac = false; } textReader.Dispose(); textReader.Close(); } // int losingStreak = 0; if (pickCount == 0) { bankrollTo = bankroll * (1 + expectedMonthlyIncome); endDate = (today).AddMonths(1); if (endDate.Year == today.Year) { howManyDaysLeft = endDate.DayOfYear - DateTime.Now.DayOfYear; ileDoZarobkuDziennie = (bankrollTo - bankroll) / howManyDaysLeft; startingAvarageIncome = ileDoZarobkuDziennie; } else { howManyDaysLeft = (daysInYear(DateTime.Now.Year) - DateTime.Now.DayOfYear) + endDate.DayOfYear; ileDoZarobkuDziennie = (bankrollTo - bankroll) / howManyDaysLeft; startingAvarageIncome = ileDoZarobkuDziennie; } if (probability == 0.0D) { probability = 1 / odd; } value = odd * probability; stake = (ileDoZarobkuDziennie * value) / (odd - 1); doZarobkuTeraz = ileDoZarobkuDziennie; if (stake < (bankroll / 35)) { stake = bankroll / 35; } } else { // //// Wczytanie last 10 picków // try { textReader = new StreamReader(fileName); } catch (Exception e) { Console.Write(e); } finally { ileLinijek = 0; string ileLinijekString = textReader.ReadLine(); while (ileLinijekString != null) { ileLinijek++; ileLinijekString = textReader.ReadLine(); } textReader.Dispose(); textReader.Close(); } int j; string[] lastString; double[] lastStakes; string[] lastStatus; if (ileLinijek > 10) { lastString = new string[10]; lastStakes = new double[10]; lastStatus = new string[10]; j = 10; } else { lastString = new string[ileLinijek - 1]; lastStakes = new double[ileLinijek - 1]; lastStatus = new string[ileLinijek - 1]; j = ileLinijek - 1; } int i = 1; // Wczytywanie do Last String if (ileLinijek > 10) { try { textReader = new StreamReader(fileName); } catch (Exception e) { Console.Write(e); } finally { int indexX = 0; // TU JEST JAKI PROBLEM while (i <= ileLinijek) { if (ileLinijek == 11) { if (i != 1) { s = textReader.ReadLine(); lastString[i - 2] = s; } else { s = textReader.ReadLine(); } } else { if (i >= ileLinijek - 9) { indexX = i - (ileLinijek - 9); s = textReader.ReadLine(); lastString[indexX] = s; } else { s = textReader.ReadLine(); } } i++; } textReader.Dispose(); textReader.Close(); } } else if (ileLinijek <= 10 && ileLinijek > 1) { try { textReader = new StreamReader(fileName); } catch (Exception e) { Console.Write(e); } finally { while (i <= ileLinijek) { if (i != 1) { s = textReader.ReadLine(); lastString[i - 2] = s; } else { s = textReader.ReadLine(); } i++; } textReader.Dispose(); textReader.Close(); } } else { } // // TUTAJTJWJTTJAWTJAWWTUAUWTAATJWATJTJATJAJAT ///THTHATHTWHTWHTHAWTH ///?THTHTAHATHTAHAT // Wpisywanie danych do lastStakes i lastStatus :> i = 0; while (i <= (lastString.Length - 1)) { sArray = lastString[i].Split(znakiOdstepu); lastStakes[i] = double.Parse(sArray[8]); lastStatus[i] = sArray[9]; i++; } while (j > 0 && lastStatus[j-1] == "L") { if (lastStatus[j-1] == "W") { break; } obstawioneWStepie += lastStakes[j-1]; losingStreak++; j--; } if (endDate.Year == today.Year) { ileDoZarobkuDziennie = (bankrollTo - bankroll - obstawioneWStepie) / ((int)endDate.DayOfYear - (int)today.DayOfYear); } else { ileDoZarobkuDziennie = (bankrollTo - bankroll - obstawioneWStepie) / (daysInYear(today.Year) - today.DayOfYear + endDate.DayOfYear); } // //// Counting Multiplier if (endDate.Year == today.Year) { howManyDaysLeft = endDate.DayOfYear - DateTime.Today.DayOfYear; daysLeft = endDate.DayOfYear - DateTime.Today.DayOfYear; } else { howManyDaysLeft = (daysInYear(DateTime.Now.Year) - DateTime.Now.DayOfYear) + endDate.DayOfYear; daysLeft = (daysInYear(DateTime.Now.Year) - DateTime.Now.DayOfYear) + endDate.DayOfYear; } if ((daysLeft * startingAvarageIncome) > (bankrollTo - bankroll)) { int upPasses = (int)Math.Floor(((daysLeft * startingAvarageIncome) - (bankrollTo - bankroll)) / startingAvarageIncome); while (multiplier > 0.7) { multiplier -= 0.06; } } // if (probability == 0.0D) { probability = 1 / odd; } value = odd * probability; if (ileDoZarobkuDziennie > (2 * startingAvarageIncome)) { ileDoZarobkuDziennie = 2 * startingAvarageIncome; } stake = ((((ileDoZarobkuDziennie * 1.0D) + obstawioneWStepie) * ( value - ( ( value - 1 ) / 2) ) / (odd - 1)) * multiplier); doZarobkuTeraz = ileDoZarobkuDziennie + obstawioneWStepie; if (stake < (bankroll / 35)) { stake = bankroll / 35; } if ((bankroll * avarageOdd) < ( bankrollTo / (expectedMonthlyIncome + 1) ) ) { stake = bankroll; } if (stake > bankroll) { stake = bankroll; } } //////// UPDATE MAIN INFOS // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! SPRAWDZ CZY NIE ZA MALE VALUE Console.ForegroundColor = ConsoleColor.DarkRed; if (losingStreak == 0) { if (value < 1.00D) { moznaWykonac = false; Console.Write("\nValue jest za mały bym mógł zawrzeć ten zakład!"); } } else if (losingStreak == 1) { if (value < 1.025D) { moznaWykonac = false; Console.Write("\nValue jest za mały bym mógł zawrzeć ten zakład!"); } } else if (losingStreak == 2) { if (value < 1.05D) { moznaWykonac = false; Console.Write("\nValue jest za mały bym mógł zawrzeć ten zakład!"); } } else if (losingStreak == 3) { if (value < 1.08D) { moznaWykonac = false; Console.Write("\nValue jest za mały bym mógł zawrzeć ten zakład!"); } } else if (losingStreak >= 4) { if (value < 1.125D) { moznaWykonac = false; Console.Write("\nValue jest za mały bym mógł zawrzeć ten zakład!"); } } Console.ForegroundColor = ConsoleColor.Gray; pickCount++; if (moznaWykonac) { s = id.ToString() + '_' + today.ToShortDateString() + '_' + zdarzenie + '_' + typZdarzenia + '_' + choice + '_' + odd.ToString() + '_' + probability.ToString() + '_' + value.ToString() + '_' + stake.ToString() + '_' + "P" + '_' + plusMinus.ToString(); Console.Write("\nZakład został zawarty pomyślnie!"); Console.ForegroundColor = ConsoleColor.Red; Console.Write("\n\nSTAWKA"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(" : "); Console.ForegroundColor = ConsoleColor.Green; Console.Write(String.Format("{0:0.00}", stake)); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\n\nNacisnij ENTER aby wrócić do Menu..."); } else { Console.Write("\n\nNacisnij ENTER aby wrócić do Menu..."); } } else { moznaWykonac = false; Console.Write("\n\nNacisnij ENTER aby wrócić do Menu..."); } if (moznaWykonac) { string mainInfo = ""; allText = ""; try { textReader = new StreamReader(fileName); } catch (Exception e) { Console.WriteLine(e); } finally { allText = textReader.ReadToEnd(); textReader.Dispose(); textReader.Close(); } try { textWriter = new StreamWriter(fileName); } catch (Exception e) { Console.WriteLine(e); } finally { // CHANGE MAIN INFO textWriter.Write(allText); if (moznaWykonac) { textWriter.WriteLine(s); } textWriter.Flush(); textWriter.Dispose(); textWriter.Close(); } } if (Console.ReadLine() != "EXIT") { } choiceMenu = 0; } Console.Clear(); }
protected override void CloseText(TextReader reader) { reader.Dispose(); }
public string GetTextFromFileInSameDirectory(string fileName) { if (APIServer.PageClassXDirectory.ContainsKey(this.GetType()) == false) { Console.WriteLine("PageClassXDirectory no contain " + this.GetType()); } string path = APIServer.PageClassXDirectory[this.GetType()] + "\\" + fileName; if (File.Exists(path) == false) { Console.WriteLine(path + " does not exist"); return "N/A"; } textReader = new StreamReader(path); string text = textReader.ReadToEnd(); textReader.Close(); textReader.Dispose(); // Console.WriteLine("text length: " + text.Length + " from " + path); return text; }
private void statistics() { // WCZYTANIE ALL ZAKŁADÓW IF NO PENDING , JEŻELI PENDING ZAKŁADY -1 try { textReader = new StreamReader(fileName); } catch (Exception e) { } finally { ileLinijek = 0; s = textReader.ReadLine(); while (s != null) { ileLinijek++; s = textReader.ReadLine(); } textReader.Dispose(); textReader.Close(); } string[] allBets = new string[ileLinijek]; try { textReader = new StreamReader(fileName); } catch (Exception e) { } finally { int i = 0; s = textReader.ReadLine(); while (s != null) { allBets[i] = s; i++; s = textReader.ReadLine(); } textReader.Dispose(); textReader.Close(); } int ileMamyZakladow = 0; if (checkIfHavePendingBets()) { ileMamyZakladow = ileLinijek - 2; } else { ileMamyZakladow = ileLinijek - 1; } string[] dates = new string[ileMamyZakladow]; string[] rodzaj = new string[ileMamyZakladow]; string[] odd = new string[ileMamyZakladow]; string[] value = new string[ileMamyZakladow]; string[] stakes = new string[ileMamyZakladow]; string[] status = new string[ileMamyZakladow]; string[] pM = new string[ileMamyZakladow]; string[] daneZDanejLinijki = new string[11]; for (int i = 0; i <= ileMamyZakladow; i++) { if (i != 0) //s = id.ToString() + '_' + today.ToShortDateString() + '_' + zdarzenie + '_' + typZdarzenia + '_' + choice + '_' + odd.ToString() + '_' + probability.ToString() + '_' + value.ToString() + '_' + stake.ToString() + '_' + "P" + '_' + plusMinus.ToString(); { daneZDanejLinijki = allBets[i].Split(znakiOdstepu); dates[i-1] = daneZDanejLinijki[1]; rodzaj[i-1] = daneZDanejLinijki[3]; odd[i-1] = daneZDanejLinijki[5]; value[i-1] = daneZDanejLinijki[7]; stakes[i-1] = daneZDanejLinijki[8]; status[i-1] = daneZDanejLinijki[9]; pM[i-1] = daneZDanejLinijki[10]; } } // Policz wszystko z danych double avarageOdd = 0.0D; int preGameBets = 0; int liveBets = 0; int valueMoreThan120 = 0; double plusMinus = 0.0D; int trafione = 0; int nietrafione = 0; double avarageStake = 0.0D; for (int i = 1; i <= ileMamyZakladow; i++) { avarageOdd += stringToDouble(odd[i-1]); if (rodzaj[i-1] == "P") { preGameBets++; } else if (rodzaj[i-1] == "L") { liveBets++; } if (stringToDouble(value[i-1]) > 1.20D) { valueMoreThan120++; } plusMinus = bankroll - bankrollStart; if (status[i-1] == "W") { trafione++; } else if (status[i-1] == "L") { nietrafione++; } avarageStake += stringToDouble(stakes[i - 1]); } avarageStake /= ileMamyZakladow; avarageOdd /= ileMamyZakladow; Console.ForegroundColor = ConsoleColor.Gray; Console.Write("Zakończonych zakładów: "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(ileMamyZakladow); Console.ForegroundColor = ConsoleColor.Green; Console.Write("\n\nTrafionych: "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(trafione); Console.ForegroundColor = ConsoleColor.Red; Console.Write("\n\nNietrafionych: "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(nietrafione); Console.ForegroundColor = ConsoleColor.Magenta; Console.Write("\n\nŚredni Kurs: "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(String.Format("{0:0.00}", avarageOdd)); Console.ForegroundColor = ConsoleColor.Magenta; Console.Write("\n\nŚrednia Stawka: "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(String.Format("{0:0.00}", avarageStake)); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("\n\nZakładów Pre Game: "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(preGameBets); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("\n\nZakładów Live: "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(liveBets); Console.ForegroundColor = ConsoleColor.White; Console.Write("\n\nZakładów z Value większym niż 1.20: "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(valueMoreThan120); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("\n\nZarobione: "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(String.Format("{0:0.00}", plusMinus)); // Zakończenie if (Console.ReadLine() != "EXIT") { } Console.Clear(); }
private void transactions() { int transChoice = 0; Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("1"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(". Wpłata"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("\n2"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(". Wypłata"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("\n3"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(". Wróc do MENU"); Console.Write("\n-> "); s = Console.ReadLine(); while (transChoice != 1 && transChoice != 2 && transChoice != 3) { try { transChoice = int.Parse(s); break; } catch (Exception e) { Console.Write("-> "); s = Console.ReadLine(); } finally { } } Console.Clear(); switch (transChoice) { case 1: if (!checkIfHavePendingBets()) { // Podaj ile chcesz wpłacić double doWplaty = 0.0D; int probowal = 0; Console.Write("Twoje środki : "); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(String.Format("{0:0.00}", bankroll)); Console.Write("\n\n"); Console.ForegroundColor = ConsoleColor.Gray; DEPOSIT: if (probowal == 0) { Console.Write("Ile chcesz wpłacić pieniędzy ( Format - 00.00 ) : "); probowal++; } else { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format, wpłacona kwota może być dodatnim ułamkiem z ',' lub '.' ( np. 250.00 ) : "); Console.ForegroundColor = ConsoleColor.Gray; } s = Console.ReadLine(); try { doWplaty = stringToDouble(s); } catch (Exception e) { while (true == true) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format, wpłacona kwota może być dodatnim ułamkiem z ',' lub '.' ( np. 250.00 ) : "); Console.ForegroundColor = ConsoleColor.Gray; s = Console.ReadLine(); try { doWplaty = stringToDouble(s); break; } catch (Exception ee) { } finally { } } } finally { } if (doWplaty < 0) { goto DEPOSIT; } // Zaktualizuj bankroll , endDate , bankrollTo, startingAvarageIncome // Wczytaj pierwszą linię string pierwszaLinijka = ""; string reszta = ""; try { textReader = new StreamReader(fileName); } catch (Exception e) { } finally { pierwszaLinijka = textReader.ReadLine(); reszta = textReader.ReadToEnd(); textReader.Dispose(); textReader.Close(); } // Wczytać resztę komendą readToEnd // Zmienić br ,ed ,brT, sai bankroll += doWplaty; bankrollTo = bankroll * (1 + expectedMonthlyIncome); endDate = DateTime.Today.AddMonths(1); int howManyDaLeft; if (endDate.Year == DateTime.Now.Year) { howManyDaLeft = endDate.DayOfYear - DateTime.Now.DayOfYear; startingAvarageIncome = (bankrollTo - bankroll) / howManyDaLeft; } else { howManyDaLeft = (daysInYear(DateTime.Now.Year) - DateTime.Now.DayOfYear) + endDate.DayOfYear; startingAvarageIncome = (bankrollTo - bankroll) / howManyDaLeft; } // Zmienić pierwszą linię // Zapisać all try { textWriter = new StreamWriter(fileName); } catch (Exception e) { } finally { s = nickname.ToString() + "_" + pickCount.ToString() + "_" + bankroll.ToString() + "_" + bankrollStart.ToString() + "_" + bankrollTo.ToString() + "_" + startDate.ToShortDateString() + "_" + endDate.ToShortDateString() + "_" + startingAvarageIncome.ToString() + "_" + expectedMonthlyIncome.ToString() + "_" + avarageOdd + "_" + betTypes.ToUpper(); textWriter.WriteLine(s); textWriter.Write(reszta); textWriter.Flush(); textWriter.Dispose(); textWriter.Close(); } // Potwierdź Console.ForegroundColor = ConsoleColor.Green; Console.Write("\nOPERACJA ZAKOŃCZYŁA SIĘ POWODZENIEM"); // Wyjdź Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\n\nNaciśnij ENTER aby wyjść..."); if (Console.ReadLine() != "EXIT") { } // Wyjdź } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Nie możesz wykonać operacji ponieważ masz zakład w grze"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\nNaciśnij ENTER aby wyjść..."); if (Console.ReadLine() != "EXIT") { } } break; case 2: if (!checkIfHavePendingBets()) { // Podaj ile chcesz wypłacić double doWyplaty = 0.0D; int probowal2 = 0; Console.Write("Twoje środki : "); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(String.Format("{0:0.00}", bankroll)); Console.Write("\n\n"); Console.ForegroundColor = ConsoleColor.Gray; WITHDRAW: if (probowal2 == 0) { Console.Write("Ile chcesz wypłacić pieniędzy ( Format - 00.00 ) : "); probowal2++; } else { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format, wypłacona kwota może być dodatnim ułamkiem z ',' lub '.' ( np. 250.00 ) : "); Console.ForegroundColor = ConsoleColor.Gray; } s = Console.ReadLine(); try { doWyplaty = stringToDouble(s); } catch (Exception e) { while (true == true) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format, wypłacona kwota może być dodatnim ułamkiem z ',' lub '.' ( np. 250.00 ) : "); Console.ForegroundColor = ConsoleColor.Gray; s = Console.ReadLine(); try { doWyplaty = stringToDouble(s); break; } catch (Exception ee) { } finally { } } } finally { } if (doWyplaty > bankroll || doWyplaty < 0) { goto WITHDRAW; } // Zaktualizuj bankroll , endDate , bankrollTo, startingAvarageIncome string pierwszaLinijka2 = ""; string reszta2 = ""; try { textReader = new StreamReader(fileName); } catch (Exception e) { } finally { pierwszaLinijka2 = textReader.ReadLine(); reszta2 = textReader.ReadToEnd(); textReader.Dispose(); textReader.Close(); } bankroll -= doWyplaty; bankrollTo = bankroll * (1 + expectedMonthlyIncome); endDate = DateTime.Today.AddMonths(1); int howManyDaLeft2; if (endDate.Year == DateTime.Now.Year) { howManyDaLeft2 = endDate.DayOfYear - DateTime.Now.DayOfYear; startingAvarageIncome = (bankrollTo - bankroll) / howManyDaLeft2; } else { howManyDaLeft2 = (daysInYear(DateTime.Now.Year) - DateTime.Now.DayOfYear) + endDate.DayOfYear; startingAvarageIncome = (bankrollTo - bankroll) / howManyDaLeft2; } try { textWriter = new StreamWriter(fileName); } catch (Exception e) { } finally { s = nickname.ToString() + "_" + pickCount.ToString() + "_" + bankroll.ToString() + "_" + bankrollStart.ToString() + "_" + bankrollTo.ToString() + "_" + startDate.ToShortDateString() + "_" + endDate.ToShortDateString() + "_" + startingAvarageIncome.ToString() + "_" + expectedMonthlyIncome.ToString() + "_" + avarageOdd + "_" + betTypes.ToUpper(); textWriter.WriteLine(s); textWriter.Write(reszta2); textWriter.Flush(); textWriter.Dispose(); textWriter.Close(); } // Potwierdź Console.ForegroundColor = ConsoleColor.Green; Console.Write("\nOPERACJA ZAKOŃCZYŁA SIĘ POWODZENIEM"); // Wyjdź Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\n\nNaciśnij ENTER aby wyjść..."); if (Console.ReadLine() != "EXIT") { } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Nie możesz wykonać operacji ponieważ masz zakład w grze"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\nNaciśnij ENTER aby wyjść..."); if (Console.ReadLine() != "EXIT") { } } break; case 3: break; } Console.Clear(); }
private void updatePick() { try { textReader = new StreamReader(fileName); } catch (Exception e) { } finally { ileLinijek = 0; s = textReader.ReadLine(); while (s != null) { ileLinijek++; s = textReader.ReadLine(); } } textReader.Dispose(); textReader.Close(); int updateChoice = 0; Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("1"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(". Aktualizuj zakład w grze"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("\n2"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(". Usuń dodany zakład"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("\n3"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(". Wróc do MENU"); Console.Write("\n-> "); s = Console.ReadLine(); while (updateChoice != 1 && updateChoice != 2 && updateChoice != 3) { try { updateChoice = int.Parse(s); break; } catch (Exception e) { Console.Write("-> "); s = Console.ReadLine(); } finally { } } Console.Clear(); switch (updateChoice) { case 1: int i = 1; string meczDoZmiany = ""; string infoDoZmiany = ""; try { textReader = new StreamReader(fileName); } catch (Exception e) { } finally { i = 1; textArray = null; textArray = new string[ileLinijek]; while (i <= ileLinijek) { textArray[i-1] = textReader.ReadLine(); i++; } meczDoZmiany = textArray[i - 2]; infoDoZmiany = textArray[0]; textReader.Dispose(); textReader.Close(); } // Update tego co trzeba string[] meczDoZmianyDane = new string[11]; string[] infoDoZmianyDane = new string[11]; meczDoZmianyDane = meczDoZmiany.Split(znakiOdstepu); infoDoZmianyDane = infoDoZmiany.Split(znakiOdstepu); if (meczDoZmianyDane[9] == "P") { // Pokaż informację o aktualnym zdarzeniu :D Console.WriteLine("Masz aktualnie w grze : "); Console.ForegroundColor = ConsoleColor.Magenta; Console.Write(meczDoZmianyDane[1] + " "); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(meczDoZmianyDane[2] + " "); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(meczDoZmianyDane[4]); Console.ForegroundColor = ConsoleColor.Gray; // Zapytaj jak zaaktualizowac zdarzenie Console.Write("\n\nPodaj jaki był wynik zdarzenia. Znak 'W' jeżeli trafiony, 'L' jeżeli przegrany, inny aby wyjść"); Console.Write("\n-> "); string doZmiany = Console.ReadLine(); if (doZmiany.ToUpper() == "W" || doZmiany.ToUpper() == "L") { meczDoZmianyDane[9] = doZmiany.ToUpper(); // pickCount = int.Parse(infoDoZmianyDane[1]); bankroll = stringToDouble(infoDoZmianyDane[2]); bankrollStart = stringToDouble(infoDoZmianyDane[3]); bankrollTo = stringToDouble(infoDoZmianyDane[4]); iDate = stringToDate(infoDoZmianyDane[5]); startDate = new DateTime(iDate[0], iDate[1], iDate[2]); iDate = stringToDate(infoDoZmianyDane[6]); endDate = new DateTime(iDate[0], iDate[1], iDate[2]); startingAvarageIncome = stringToDouble(infoDoZmianyDane[7]); expectedMonthlyIncome = stringToDouble(infoDoZmianyDane[8]); avarageOdd = stringToDouble(infoDoZmianyDane[9]); betTypes = infoDoZmianyDane[10]; // double zysk = 0.0D; double playedOdd = 0.0D; if (meczDoZmianyDane[9] == "W") { // Zmień plus minus playedOdd = stringToDouble(meczDoZmianyDane[5]) - 1.0D; zysk = stringToDouble(meczDoZmianyDane[8]) * playedOdd; // Zmień bankroll bankroll += zysk; // pickCount++; } else if (meczDoZmianyDane[9] == "L") { // Zmień plus minus playedOdd = stringToDouble(meczDoZmianyDane[5]) - 1.0D; zysk = -1.0D * stringToDouble(meczDoZmianyDane[8]); // Zmień bankroll bankroll += zysk; // pickCount++; } int howManyDaLeft = 0; if (bankroll > bankrollTo) { endDate = DateTime.Now.AddMonths(1); bankrollTo = bankroll * (1 + expectedMonthlyIncome); if (endDate.Year == DateTime.Now.Year) { howManyDaLeft = endDate.DayOfYear - DateTime.Now.DayOfYear; startingAvarageIncome = (bankrollTo - bankroll) / howManyDaLeft; } else { howManyDaLeft = (daysInYear(DateTime.Now.Year) - DateTime.Now.DayOfYear) + endDate.DayOfYear; startingAvarageIncome = (bankrollTo - bankroll) / howManyDaLeft; } } else { /*if (DateTime.Now.CompareTo(endDate) > 0 && meczDoZmianyDane[9] == "W") { Console.WriteLine("BBB"); endDate = DateTime.Now.AddMonths(1); bankrollTo = bankroll * (1 + expectedMonthlyIncome); if (endDate.Year == DateTime.Now.Year) { howManyDaLeft = endDate.DayOfYear - DateTime.Now.DayOfYear; startingAvarageIncome = (bankrollTo - bankroll) / howManyDaLeft; } else { howManyDaLeft = (daysInYear(DateTime.Now.Year) - DateTime.Now.DayOfYear) + endDate.DayOfYear; startingAvarageIncome = (bankrollTo - bankroll) / howManyDaLeft; } }*/ } // Wnieś poprawki do INFO i MECZE ale też zakutalizuj główne try { textWriter = new StreamWriter(fileName); } catch (Exception e) { Console.WriteLine(e); } finally { s = nickname.ToString() + "_" + pickCount.ToString() + "_" + bankroll.ToString() + "_" + bankrollStart.ToString() + "_" + bankrollTo.ToString() + "_" + startDate.ToShortDateString() + "_" + endDate.ToShortDateString() + "_" + startingAvarageIncome.ToString() + "_" + expectedMonthlyIncome.ToString() + "_" + avarageOdd + "_" + betTypes; textWriter.WriteLine(s); i = 1; while (i <= textArray.Length - 2) { textWriter.WriteLine(textArray[i].ToString()); i++; } s = meczDoZmianyDane[0] + "_" + meczDoZmianyDane[1] + "_" + meczDoZmianyDane[2] + "_" + meczDoZmianyDane[3] + "_" + meczDoZmianyDane[4] + "_" + meczDoZmianyDane[5] + "_" + meczDoZmianyDane[6] + "_" + meczDoZmianyDane[7] + "_" + meczDoZmianyDane[8] + "_" + meczDoZmianyDane[9] + "_" + zysk.ToString(); textWriter.WriteLine(s); textWriter.Flush(); textWriter.Dispose(); textWriter.Close(); } } else { } } else { Console.Write("Nie masz żadnego meczu do zaaktualizowania"); Console.Write("\n\nKliknij ENTER aby wrócić do Menu..."); if (Console.ReadLine() != "EXIT") { } } break; case 2: int i2 = 1; string meczDoZmiany2 = ""; try { textReader = new StreamReader(fileName); } catch (Exception e) { } finally { i2 = 1; textArray = null; textArray = new string[ileLinijek]; while (i2 <= ileLinijek) { textArray[i2-1] = textReader.ReadLine(); i2++; } meczDoZmiany2 = textArray[i2 - 2]; textReader.Dispose(); textReader.Close(); } // Update tego co trzeba string[] meczDoZmianyDane2 = new string[11]; meczDoZmianyDane2 = meczDoZmiany2.Split(znakiOdstepu); if (meczDoZmianyDane2[9] == "P") { // Pokaż informację o aktualnym zdarzeniu :D Console.WriteLine("Masz aktualnie w grze : "); Console.ForegroundColor = ConsoleColor.Magenta; Console.Write(meczDoZmianyDane2[1] + " "); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(meczDoZmianyDane2[2] + " "); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(meczDoZmianyDane2[4]); Console.ForegroundColor = ConsoleColor.Gray; // Pytanie czy chcesz na pewno usunąć zakład!? Console.Write("\n\nCzy na pewno chcesz usunąć to zdarzenie? Wpisz T jeżeli tak, inny znak żeby wyjść"); Console.Write("\n-> "); s = Console.ReadLine(); // Jeżeli tak przepisujemy całą tablice bez ostatniogo indeksu if (s.ToUpper() == "T") { try { textWriter = new StreamWriter(fileName); } catch (Exception e) { } finally { i = 1; while (i <= ileLinijek - 1) { textWriter.WriteLine(textArray[i - 1]); i++; } textWriter.Flush(); textWriter.Dispose(); textWriter.Close(); } } else { } } else { Console.Write("Nie masz żadnego meczu do zaaktualizowania"); Console.Write("\n\nKliknij ENTER aby wrócić do Menu..."); if (Console.ReadLine() != "EXIT") { } } break; case 3: break; } Console.Clear(); }
private void history() { int ileZakladow = 0; int ileLinijek = 0; int ilePokazac = 0; try { textReader = new StreamReader(fileName); } catch (Exception e) { } finally { s = textReader.ReadLine(); while (s != null) { ileLinijek++; ileZakladow++; s = textReader.ReadLine(); } ileZakladow--; textReader.Dispose(); textReader.Close(); } string[] wszystkieLinijki = new string[ileZakladow+1]; try { textReader = new StreamReader(fileName); } catch (Exception e) { } finally { int i = 0; s = textReader.ReadLine(); while (s != null) { wszystkieLinijki[i] = s; i++; s = textReader.ReadLine(); } textReader.Dispose(); textReader.Close(); } Console.Write("Masz w historii "); Console.ForegroundColor = ConsoleColor.Cyan; if (checkIfHavePendingBets()) { ileZakladow--; } Console.Write(ileZakladow); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(" zakładów"); Console.Write("\n\nWpisz ile ostatnich zakładów chcesz zobaczyć, 0 aby wyjść ( liczba musi być mniejsza od ilości zakładów ): "); Console.Write("\n-> "); s = Console.ReadLine(); try { ilePokazac = int.Parse(s); } catch (Exception e) { ilePokazac = 0; } finally { } if (ilePokazac <= 0 || ilePokazac > ileZakladow) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("\nPodano złą liczbę zakładów!"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\n\nKliknij ENTER aby wrócić do Menu..."); if (Console.ReadLine() != "EXIT") { } } else { if (ilePokazac < 33) { Console.BufferHeight = 40; } else if (ilePokazac >= 33 && ilePokazac < int.MaxValue - 8) { Console.BufferHeight = ilePokazac + 7; } else { Console.BufferHeight = int.MaxValue - 1; } if (Console.BufferHeight > 10000) { Console.BufferHeight = 10000; } int i = 0; string[] actualGameInfo = new string[11]; int ostatniiIndeks = ileLinijek - ilePokazac; if (checkIfHavePendingBets()) { ostatniiIndeks--; ileLinijek--; } while (ileLinijek > ostatniiIndeks) { if (ileLinijek == 1) { } else { actualGameInfo = wszystkieLinijki[ileLinijek - 1].Split(znakiOdstepu); int zdarzenieNameLenght = 50; int choiceLenght = 10; actualGameInfo[2] = wyrownajString(actualGameInfo[2], zdarzenieNameLenght); actualGameInfo[4] = wyrownajString(actualGameInfo[4], choiceLenght); if (actualGameInfo[9] == "W") { Console.ForegroundColor = ConsoleColor.Green; } else if (actualGameInfo[9] == "L") { Console.ForegroundColor = ConsoleColor.Red; } Console.Write("\n{0} ", actualGameInfo[1]); Console.Write(" "); Console.Write(actualGameInfo[2] + " "); Console.Write(actualGameInfo[4] + " "); Console.Write(" @ "); Console.Write(String.Format("{0:0.00}", stringToDouble(actualGameInfo[5]))); Console.Write(" "); Console.Write(" za "); Console.Write(String.Format("{0:0.00}", stringToDouble(actualGameInfo[8]))); } ileLinijek--; } Console.ForegroundColor = ConsoleColor.Gray; // ZAKOŃCZENIE Console.Write("\n\nKliknij ENTER aby wrócić do Menu..."); if (Console.ReadLine() != "EXIT") { } } Console.Clear(); }
private static IEnumerable<string> CreateLineIterator(TextReader self, TextReaderRocksOptions options) { try { string line; while ((line = self.ReadLine ()) != null) yield return line; } finally { if ((options & TextReaderRocksOptions.CloseReader) != 0) { self.Close (); self.Dispose (); } } }
public Stake() { try { textReader = new StreamReader(fileName); } catch (Exception e) { Console.Write(e); } finally { string ileLinijekString = textReader.ReadLine(); if (ileLinijekString != null) { ileLinijek++; } textReader.Dispose(); textReader.Close(); } if (ileLinijek == 0) { try { textWriter = new StreamWriter(fileName); } catch (Exception e) { Console.WriteLine(e); } finally { Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine("To twój pierwszy raz z programem BetProvider, podaj kilka danych\n"); Console.ForegroundColor = ConsoleColor.Gray; nickname = ""; bankroll = 0.0D; expectedMonthlyIncome = -0.1D; avarageOdd = 1.65D; Console.Write("Podaj swoje imię ( Format - znaki ) : "); s = Console.ReadLine(); nickname = s; while (nickname == "") { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nie podałeś swojego imienia, wprowadź ciąg znaków ( np. Wojtek ) : "); Console.ForegroundColor = ConsoleColor.Gray; nickname = Console.ReadLine(); } int probowal = 0; BANKROLL : if (probowal == 0) { Console.Write("Podaj swój Bankroll ( Format - 00.00 ) : "); probowal++; } else { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format, bankroll może być dodatnim ułamkiem z ',' lub '.' ( np. 250.00 ) : "); Console.ForegroundColor = ConsoleColor.Gray; } s = Console.ReadLine(); try { bankroll = stringToDouble(s); } catch (Exception e) { while( true == true ) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format, bankroll może być dodatnim ułamkiem z ',' lub '.' ( np. 250.00 ) : "); Console.ForegroundColor = ConsoleColor.Gray; s = Console.ReadLine(); try { bankroll = stringToDouble(s); break; } catch (Exception ee) { } finally { } } } finally { } if (bankroll < 0) { goto BANKROLL; } probowal = 0; EXPECTEDMONTHLYINCOME : if (probowal == 0) { Console.Write("Jaki chciałbyś mieć miesięczny zysk w % [ 0.00 - 0% , 1.00 - 100% ] ( Format - 0.00 ) : "); probowal++; } else { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format, ta liczba może być ułamkiem z ',' lub '.', z przedziału od 0 do 1 ( np. 0.50 [ czyli 50% ] ) : "); Console.ForegroundColor = ConsoleColor.Gray; } s = Console.ReadLine(); try { expectedMonthlyIncome = stringToDouble(s); } catch (Exception e) { while (true == true) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format, ta liczba może być ułamkiem z ',' lub '.', z przedziału od 0 do 1 ( np. 0.50 [ czyli 50% ] ) : "); Console.ForegroundColor = ConsoleColor.Gray; s = Console.ReadLine(); try { expectedMonthlyIncome = stringToDouble(s); break; } catch (Exception ee) { } finally { } } } finally { } if (expectedMonthlyIncome <= 0 || expectedMonthlyIncome > 1) { goto EXPECTEDMONTHLYINCOME; } probowal = 0; AVARAGEODD : if (probowal == 0) { Console.Write("Podaj jaki był twój dotychczasowy średni kurs [ Od 1.00 do +Infinity ] ( Format - 00.00 ) : "); probowal++; } else { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format, ta liczba może być ułamkiem z ',' lub '.', z przedziału od 1.00 do +Infinity ( np. 1.65 ) : "); Console.ForegroundColor = ConsoleColor.Gray; } s = Console.ReadLine(); try { avarageOdd = stringToDouble(s); } catch (Exception e) { while (true == true) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format, ta liczba może być ułamkiem z ',' lub '.', z przedziału od 1.00 do +Infinity ( np. 1.65 ) : "); Console.ForegroundColor = ConsoleColor.Gray; s = Console.ReadLine(); try { avarageOdd = stringToDouble(s); break; } catch (Exception ee) { } finally { } } } finally { } if (avarageOdd < 1) { goto AVARAGEODD; } Console.Write("Podaj jakie zakłady chcesz grać. Wpisz 'P' dla PreGame, 'L' dla Live, lub 'O' dla obydwu : "); s = Console.ReadLine(); betTypes = s; while (betTypes.ToUpper() != "O" && betTypes.ToUpper() != "P" && betTypes.ToUpper() != "L") { Console.ForegroundColor = ConsoleColor.Red; Console.Write("Nieprawidłowy format, wpisz tylko jedną literę: O, P lub L : "); Console.ForegroundColor = ConsoleColor.Gray; s = Console.ReadLine(); betTypes = s; } pickCount = 0; bankrollStart = bankroll; bankrollTo = bankroll * (expectedMonthlyIncome + 1.0D); startDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day); endDate = (DateTime.Now).AddMonths(1); int howManyDLeft = 0; if (endDate.Year == DateTime.Now.Year) { howManyDLeft = endDate.DayOfYear - DateTime.Now.DayOfYear; startingAvarageIncome = (bankrollTo - bankroll) / howManyDLeft; } else { howManyDLeft = (daysInYear(DateTime.Now.Year) - DateTime.Now.DayOfYear) + endDate.DayOfYear; startingAvarageIncome = (bankrollTo - bankroll) / howManyDLeft; } s = nickname.ToString() + "_" + pickCount.ToString() + "_" + bankroll.ToString() + "_" + bankrollStart.ToString() + "_" + bankrollTo.ToString() + "_" + startDate.ToShortDateString() + "_" + endDate.ToShortDateString() + "_" + startingAvarageIncome.ToString() + "_" + expectedMonthlyIncome.ToString() + "_" + avarageOdd + "_" + betTypes.ToUpper(); textWriter.WriteLine(s); textWriter.Flush(); textWriter.Dispose(); textWriter.Close(); } } Console.Clear(); choiceMenu = 0; while (choiceMenu != 9) { Console.BufferHeight = 40; // Wczytanie danych :> try { textReader = new StreamReader(fileName); } catch (Exception e) { Console.Write(e); } finally { s = textReader.ReadLine(); sArray = s.Split(znakiOdstepu); nickname = (string)sArray[0]; pickCount = int.Parse(sArray[1]); bankroll = stringToDouble(sArray[2]); bankrollStart = stringToDouble(sArray[3]); bankrollTo = stringToDouble(sArray[4]); iDate = stringToDate(sArray[5]); startDate = new DateTime(iDate[0], iDate[1], iDate[2]); iDate = stringToDate(sArray[6]); endDate = new DateTime(iDate[0], iDate[1], iDate[2]); startingAvarageIncome = stringToDouble(sArray[7]); expectedMonthlyIncome = stringToDouble(sArray[8]); avarageOdd = stringToDouble(sArray[9]); betTypes = sArray[10]; textReader.Dispose(); textReader.Close(); } string noweCosTam = ""; if (DateTime.Today.CompareTo(endDate) > 0) { endDate = DateTime.Today.AddMonths(1); bankrollTo = bankroll * (1 + expectedMonthlyIncome); int howManyDaysLeft = 0; if (endDate.Year == DateTime.Today.Year) { howManyDaysLeft = endDate.DayOfYear - DateTime.Now.DayOfYear; startingAvarageIncome = (bankrollTo - bankroll) / howManyDaysLeft; } else { howManyDaysLeft = (daysInYear(DateTime.Now.Year) - DateTime.Now.DayOfYear) + endDate.DayOfYear; startingAvarageIncome = (bankrollTo - bankroll) / howManyDaysLeft; } noweCosTam = nickname.ToString() + "_" + pickCount.ToString() + "_" + bankroll.ToString() + "_" + bankrollStart.ToString() + "_" + bankrollTo.ToString() + "_" + startDate.ToShortDateString() + "_" + endDate.ToShortDateString() + "_" + startingAvarageIncome.ToString() + "_" + expectedMonthlyIncome.ToString() + "_" + avarageOdd + "_" + betTypes.ToUpper(); try { textReader = new StreamReader(fileName); } catch (Exception e) { Console.Write(e); } finally { ileLinijek = 0; string ileLinijekString = textReader.ReadLine(); while (ileLinijekString != null) { ileLinijek++; ileLinijekString = textReader.ReadLine(); } textReader.Dispose(); textReader.Close(); } string all = ""; try { textReader = new StreamReader(fileName); } catch (Exception e) { Console.Write(e); } finally { string xx = textReader.ReadLine(); textArray = new string[ileLinijek - 1]; int j = 2; while (j <= ileLinijek) { textArray[j - 2] = textReader.ReadLine(); j++; } textReader.Dispose(); textReader.Close(); } try { textWriter = new StreamWriter(fileName); } catch (Exception e) { Console.Write(e); } finally { textWriter.WriteLine(noweCosTam); for (int i = 0; i < textArray.Length; i++) { textWriter.WriteLine(textArray[i]); } textWriter.Flush(); textWriter.Dispose(); textWriter.Close(); } } // Pokazanie podstawowych danych //s = nickname.ToString() + "_" + pickCount.ToString() + "_" + bankroll.ToString() + "_" + bankrollStart.ToString() + "_" + bankrollTo.ToString() + "_" + startDate.ToShortDateString() + "_" + endDate.ToShortDateString() + "_" + startingAvarageIncome.ToString() + "_" + expectedMonthlyIncome.ToString() + "_" + avarageOdd + "_" + betTypes.ToUpper(); // WCZYTYWANIE I ZAPISANIE Console.Write("Witaj "); Console.ForegroundColor = ConsoleColor.Magenta; Console.Write(nickname); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("!"); string[] actualGameInfo = new string[11]; if (checkIfHavePendingBets()) { try { textReader = new StreamReader(fileName); } catch (Exception e) { Console.Write(e); } finally { ileLinijek = 0; string ileLinijekString = textReader.ReadLine(); while (ileLinijekString != null) { ileLinijek++; ileLinijekString = textReader.ReadLine(); } textReader.Dispose(); textReader.Close(); } try { textReader = new StreamReader(fileName); } catch (Exception e) { Console.Write(e); } finally { int i = 1; while (i <= ileLinijek) { s = textReader.ReadLine(); i++; } textReader.Dispose(); textReader.Close(); } actualGameInfo = s.Split(znakiOdstepu); Console.Write("\n\nAktualnie w grze masz:\n"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("{0} ", actualGameInfo[1]); Console.ForegroundColor = ConsoleColor.White; Console.Write(actualGameInfo[2] + " "); Console.ForegroundColor = ConsoleColor.Red; Console.Write(actualGameInfo[4] + " "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("@ "); Console.ForegroundColor = ConsoleColor.Magenta; Console.Write(String.Format("{0:0.00}", stringToDouble(actualGameInfo[5]))); Console.Write(" "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("za "); Console.ForegroundColor = ConsoleColor.Green; Console.Write(String.Format("{0:0.00}", stringToDouble(actualGameInfo[8]))); Console.ForegroundColor = ConsoleColor.Gray; } else { Console.Write("\n\nAktualnie nie masz zagranego zakładu"); } string[] infoDoPokazanieWMenu = new string[11]; try { textReader = new StreamReader(fileName); } catch (Exception e) { } finally { s = textReader.ReadLine(); infoDoPokazanieWMenu = s.Split(znakiOdstepu); textReader.Dispose(); textReader.Close(); } Console.Write("\n\nStan Konta : "); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(String.Format("{0:0.00}", stringToDouble(infoDoPokazanieWMenu[2]))); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\nPlanowany stan konta do "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(infoDoPokazanieWMenu[6]); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(" : "); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(String.Format("{0:0.00}", stringToDouble(infoDoPokazanieWMenu[4]))); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\nGrasz już "); Console.ForegroundColor = ConsoleColor.Cyan; int daysPlayes = countDays(startDate); Console.Write(daysPlayes); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(" dni. W tym czasie postawiłeś "); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(infoDoPokazanieWMenu[1]); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(" zakładów."); // Pokazanie opcji Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("\n\n1."); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(" Aktualizacja ostatniego zakładu"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("\n2."); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(" Dodawanie zakładów"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("\n3."); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(" Historia"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("\n4."); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(" Statystyki"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("\n5."); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(" Transakcje"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("\n6."); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(" Ustawienia"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("\n9."); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(" EXIT"); Console.ForegroundColor = ConsoleColor.Red; Console.Write("\n\n*********************************************************"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\nProgram stworzony przez "); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("Marcin "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\""); Console.ForegroundColor = ConsoleColor.Magenta; Console.Write("qRTe"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\""); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(" Horoszko"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\nCopyright : Marcin Horoszko || "); Console.ForegroundColor = ConsoleColor.White; Console.Write("Wszelkie prawa zastrzeżone"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\nKontakt : "); Console.ForegroundColor = ConsoleColor.White; Console.Write("*****@*****.**"); Console.ForegroundColor = ConsoleColor.Red; Console.Write("\n*********************************************************"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\n\n-> "); s = Console.ReadLine(); while (true == true) { try { choiceMenu = int.Parse(s); break; } catch (Exception e) { Console.Write("-> "); s = Console.ReadLine(); } finally { } } switch (choiceMenu) { case 1: Console.Clear(); updatePick(); break; case 2: Console.Clear(); addPick(); break; case 3: Console.Clear(); history(); break; case 4: Console.Clear(); statistics(); break; case 5: Console.Clear(); transactions(); break; case 6: Console.Clear(); settings(); break; case 9: Console.Clear(); break; } } }
/// <summary> /// Loads the mixed code document from the specified TextReader. /// </summary> /// <param name="reader">The TextReader used to feed the HTML data into the document.</param> public void Load(TextReader reader) { _codefragments.Clear(); _textfragments.Clear(); // all pseudo constructors get down to this one StreamReader sr = reader as StreamReader; if (sr != null) { _streamencoding = sr.CurrentEncoding; } _text = reader.ReadToEnd(); reader.Dispose(); Parse(); }
private static IEnumerable<string> CreateTokensIterator(TextReader self, TextReaderRocksOptions options, Func<char?, char, bool>[] categories) { try { var cats = categories.Select ( c => Lambda.F ((StringBuilder buf, char ch) => c (buf.Length == 0 ? ((char?) null) : (char?) buf [buf.Length-1], ch))); foreach (var t in Chars (self).Tokens ( new StringBuilder (), (buf, c) => buf.Append (c), buf => { var r = buf.ToString (); buf.Length = 0; return Tuple.Create (r, buf); }, cats.ToArray ())) yield return t; } finally { if ((options & TextReaderRocksOptions.CloseReader) != 0) { self.Close (); self.Dispose (); } } }
/** * Reads until end-of-stream and returns all read chars, finally closes the stream. * * @param input the input stream * @throws IOException if an I/O error occurs while reading the stream */ private static String ToString(TextReader input) { try { int len = 256; char[] buffer = new char[len]; char[] output = new char[len]; len = 0; int n; while ((n = input.Read(buffer, 0, buffer.Length)) != 0) { if (len + n > output.Length) { // grow capacity char[] tmp = new char[Math.Max(output.Length << 1, len + n)]; Array.Copy(output, 0, tmp, 0, len); Array.Copy(buffer, 0, tmp, len, n); buffer = output; // use larger buffer for future larger bulk reads output = tmp; } else { Array.Copy(buffer, 0, output, len, n); } len += n; } return new String(output, 0, len); } finally { if (input != null) input.Dispose(); } }
/// <summary> /// Reads until end-of-stream and returns all read chars, finally closes the stream. /// </summary> /// <param name="input"> the input stream </param> /// <exception cref="IOException"> if an I/O error occurs while reading the stream </exception> private static string ToString(TextReader input) { var reader = input as FastStringReader; if (reader != null) // fast path { return reader.String; } try { int len = 256; char[] buffer = new char[len]; char[] output = new char[len]; len = 0; int n; while ((n = input.Read(buffer)) >= 0) { if (len + n > output.Length) // grow capacity { char[] tmp = new char[Math.Max(output.Length << 1, len + n)]; Array.Copy(output, 0, tmp, 0, len); Array.Copy(buffer, 0, tmp, len, n); buffer = output; // use larger buffer for future larger bulk reads output = tmp; } else { Array.Copy(buffer, 0, output, len, n); } len += n; } return new string(output, 0, len); } finally { input.Dispose(); } }
public static DataTable Parse(TextReader stream, CsvHeadersAction Headers, char delimiter) { DataTable table = new DataTable(); CsvStream csv = new CsvStream(stream); string[] row = csv.GetNextRow(delimiter); if (row == null) return null; if (Headers == CsvHeadersAction.SkipHeaderLine) { row = csv.GetNextRow(delimiter); } if (Headers == CsvHeadersAction.UseAsColumnNames) { //foreach (string header in row) for (int i = 0;i<row.Length;i++) { if (row[i] != null && row[i].Length > 0 && !table.Columns.Contains(row[i])) table.Columns.Add(row[i], typeof(string)); else table.Columns.Add(GetNextColumnHeader(table), typeof(string)); } row = csv.GetNextRow(delimiter); } while (row != null) { while (row.Length > table.Columns.Count) table.Columns.Add(GetNextColumnHeader(table), typeof(string)); table.Rows.Add(row); row = csv.GetNextRow(delimiter); } stream.Close(); stream.Dispose(); return table; }
private bool checkIfLastGameLost() { bool havePending = false; try { textReader = new StreamReader(fileName); } catch (Exception e) { } finally { ileLinijek = 0; s = textReader.ReadLine(); while (s != null) { ileLinijek++; s = textReader.ReadLine(); } } textReader.Dispose(); textReader.Close(); try { textReader = new StreamReader(fileName); } catch (Exception e) { } finally { int i = 1; if (ileLinijek <= 1) { } else { s = textReader.ReadLine(); while (s != null) { if (i == ileLinijek) { sArray = s.Split(znakiOdstepu); string statusSign = sArray[9]; if (statusSign == "L") { havePending = true; } } i++; s = textReader.ReadLine(); } } } textReader.Dispose(); textReader.Close(); return havePending; }