public static void TextNullTextWriter(TextWriter output) { output.Flush(); output.Dispose(); output.WriteLine(decimal.MinValue); output.WriteLine(Math.PI); output.WriteLine(); output.Flush(); output.Dispose(); }
/// <summary> /// 释放占用的资源。 /// </summary> /// <param name="disposing"></param> protected override void Dispose(bool disposing) { if (!_disposed && disposing) { if (_writer != null) { _writer.Dispose(); _writer = null; } } base.Dispose(disposing); }
public void WriteCsSources(EntityApp app, DbFirstConfig config) { _app = app; _config = config; HasErrors = false; var fileStream = File.Create(_config.OutputPath); _output = new StreamWriter(fileStream); WriteSource(); _output.Flush(); _output.Dispose(); }//method
static int Dispose(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); System.IO.TextWriter obj = (System.IO.TextWriter)ToLua.CheckObject <System.IO.TextWriter>(L, 1); obj.Dispose(); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// Close this file and release internal resources. /// </summary> public void Dispose() { if (!isDisposed) { if (writer != null) { writer.Flush(); writer.Dispose(); writer = null; } isDisposed = true; } }
System.IO.TextWriter CreateWriter() { System.IO.TextWriter writer = null; if (_writer == null || _lastDate.Date != System.DateTime.Today) { _lastDate = System.DateTime.Now; if (_writer != null) { try { _writer.Flush(); } catch { } try { _writer.Dispose(); } catch { } _writer = null; } string name = string.Format("{0}\\{1}-{2}.log", System.DateTime.Now.ToString("yyyy-MM-dd"), Name, System.DateTime.Now.ToString("HHmmss")); _file = System.IO.Path.Combine(_path, name); AppHelper.CreateDirectory(System.IO.Path.GetDirectoryName(_file)); writer = new System.IO.StreamWriter(CreateFile(_file, true, true), System.Text.Encoding.UTF8, 1024); _writer = writer; } else { writer = _writer; } return(writer); }
/// <summary> /// Generates a Package XML File containing all informations needed to recreate the Package /// </summary> /// <param name="flname">The Filename for the File</param> public void GeneratePackageXML(string flname) { System.IO.TextWriter fs = System.IO.File.CreateText(flname); try { fs.WriteLine("<?xml version=\"1.0\" encoding=\"" + fs.Encoding.HeaderName + "\" ?>"); fs.Write(GeneratePackageXML(false)); } finally { fs.Close(); fs.Dispose(); fs = null; } }
public static Task CopyToAsync(this TextReader reader, TextWriter writer, bool leaveReaderOpen, bool leaveWriterOpen) { return reader.PipeAsync( async () => { var buffer = new char[Constants.CharBufferSize]; int charsRead; while ((charsRead = await reader.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false)) > 0) { await writer.WriteAsync(buffer, 0, charsRead).ConfigureAwait(false); } }, leaveOpen: leaveReaderOpen, extraDisposeAction: leaveWriterOpen ? default(Action) : () => writer.Dispose() ); }
public static void Add(string msg, params object[] args) { if (!IsOn || s_IOErrorOccurred) return; try { if (args == null) { s_writer.WriteLine(msg); } else { s_writer.WriteLine(msg, args); } s_writer.Flush(); } catch (IOException) { s_IOErrorOccurred = true; try { s_writer.Close(); s_writer.Dispose(); s_writer = null; } catch { // supress exceptions that occur during cleanup. } return; } catch (System.ObjectDisposedException) { s_IOErrorOccurred = true; try { s_writer.Close(); s_writer.Dispose(); s_writer = null; } catch { // supress exceptions that occur during cleanup. } return; } }
/// <summary> /// Saves Metainformations about a PackedFile as xml output /// </summary> /// <param name="flname">The Filename</param> /// <param name="pfd">The description of the File</param> protected void SaveMetaInfo(string flname, PackedFileDescriptor pfd) { System.IO.TextWriter fs = System.IO.File.CreateText(flname); try { fs.WriteLine("<?xml version=\"1.0\" encoding=\"" + fs.Encoding.HeaderName + "\" ?>"); fs.WriteLine("<package type=\"" + ((uint)Header.IndexType).ToString() + "\">"); fs.Write(pfd.GenerateXmlMetaInfo()); fs.WriteLine("</package>"); } finally { fs.Close(); fs.Dispose(); fs = null; } }
public void GenerateInsertStatement(string tableName, string whereClause,string outputFileName) { try { Initialize(); _outPutFile = new StreamWriter(outputFileName); string columnList = GetColumnList(tableName).ToString(); DataTable dTable = FormAndRunQuery(tableName, columnList, whereClause); FormInserts(dTable, tableName, columnList); _outPutFile.Close(); _outPutFile = null; } catch (Exception e) { if(_outPutFile != null) _outPutFile.Dispose(); throw e; } }
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(); }
public void GenerateOutput() { Console.WriteLine("* Generating code into '" + m_outputFilename + "'"); var directory = Path.GetDirectoryName(m_outputFilename); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } using (var stream = new FileStream(m_outputFilename, FileMode.Create, FileAccess.Write)) { m_outputFile = new StreamWriter(stream); EmitPrelude(); EmitPublic(); EmitPrivate(); m_outputFile.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; } } }
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(); }
public static void Dispose(TextWriter w) { if (!__DEBUG__) return; w.Flush(); w.Close(); w.Dispose(); }
static string RestoreConsoleOut(TextWriter defaultWriter, TextWriter capture) { if (defaultWriter == null) { throw new ArgumentNullException("defaultWriter"); } if (capture == null) { throw new ArgumentNullException("capture"); } Console.SetOut(defaultWriter); try { capture.Flush(); return capture.ToString(); } finally { capture.Dispose(); } }
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(); }
private XmlDocument Serialize(object obj) { StringWriter writer = null; try { writer = new StringWriter(CultureInfo.InvariantCulture); XmlSerializer serializer = new XmlSerializer(obj.GetType()); serializer.Serialize(writer, obj); XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(writer.ToString()); return xDoc; } catch (Exception) { throw; } finally { if (writer != null) { writer.Close(); writer.Dispose(); } } }
/// <summary> /// Removes a writer from the log. /// </summary> public static void RemoveWriter(TextWriter writer, Boolean close) { if (close) writer.Dispose(); InstallerLog._writers.Remove(writer); }
static void ParseCommandLineArgs(string[] args) { file_path = Directory.GetCurrentDirectory() + "\\" + args[0]; //Set the print value if (args.Contains("-verbose") == true) { print_level = 2; } else if (args.Contains("-print") == true) { print_level = 1; } else if (args.Contains("-silent") == true) { print_level = 0; } else { print_level = 1;// Default value of print } if(args.Contains("-step") == true) { step_mode = true; } if (args.Contains("-log") == true) { string logsFolder = Directory.GetCurrentDirectory() + "\\logs"; StringBuilder sb = new StringBuilder(9); sb.Append(logsFolder); sb.Append("\\"); sb.Append(Path.GetFileNameWithoutExtension(file_path)); sb.Append("_"); sb.Append(DateTime.Now.Year.ToString()); sb.Append("_"); sb.Append(DateTime.Now.Month.ToString().PadLeft(2, '0')); sb.Append("_"); sb.Append(DateTime.Now.Day.ToString().PadLeft(2, '0')); sb.Append("_"); sb.Append(DateTime.Now.Hour.ToString().PadLeft(2, '0')); sb.Append("_"); sb.Append(DateTime.Now.Minute.ToString().PadLeft(2, '0')); sb.Append("_"); sb.Append(DateTime.Now.Second.ToString().PadLeft(2, '0')); sb.Append(".txt"); try { if (Directory.Exists(logsFolder) == false) { try { Directory.CreateDirectory(logsFolder); } catch (Exception e) { if (print_level > 0) { Console.WriteLine("Logs directory could not be created: " + e.Message); } return; } } logger = new StreamWriter(sb.ToString()); } catch (Exception) { logger.Close(); logger.Dispose(); if (print_level > 0) { Console.WriteLine("Log at {0} could not created", sb.ToString()); if (use_prompts == true) { Console.WriteLine("Exit? Y/N"); char key = Console.ReadKey().KeyChar; if (key == 'y' || key == 'Y') { return; } } } } } }