How to fix 'cannot read from closed TextReader' error

  • Thread starter Thread starter BataBo Jokviu
  • Start date Start date
B

BataBo Jokviu

Guest
So after several iterations of this code I get 'cannot read from closed TextReader'

Here is my code:

class Program
{
static Regex idcheck = new Regex(@"id"":""(.+?)"",");
static Regex Migrationcheck = new Regex(@"legacy"":(.+?)}");

private static String _outputFileUnmigrated = "Unmigrated.txt";
private static String _outputFileMigrated = "Migrated.txt";

static void Main(string[] args)
{
Console.Write("Threads : ");
int threads = int.Parse(Console.ReadLine());


var lines = File.ReadLines("List.txt");
var UnmigratedNumber = 0;
var MigratedNumber = 0;
Console.Title = "Cookie Legacy checker | by BataBo | Checked: " + (UnmigratedNumber + MigratedNumber) + " | Good:" + UnmigratedNumber;


Parallel.ForEach(lines, new ParallelOptions { MaxDegreeOfParallelism = threads }, name =>
{
// using (StreamWriter UnmigratedWriter = File.AppendText(_outputFileUnmigrated))
// {
// using (StreamWriter MigratedWriter = File.AppendText(_outputFileMigrated))
// {
foreach (var line in lines)
{
args = new[]
{
"https://api.mojang.com/users/profiles/minecraft/" + line
};

using (var client1 = new WebClient())
{

var content = string.Empty;
var porxies2 = File.ReadLines("Proxies.txt");
foreach (var porxy in porxies2)
{
WebProxy wp = new WebProxy(porxy.ToString());
client1.Proxy = wp;
try
{
content = ScrubContent(client1.DownloadString(args[0]));
break;
}
catch (Exception ex)
{
Console.WriteLine("{0}", ex.Message);
}
}

var idchecked = idcheck.Matches(content).Cast<Match>().Single().Groups[1];

args = new[]
{
"https://sessionserver.mojang.com/session/minecraft/profile/" + idchecked

};
using (var client2 = new WebClient())
{
var content1 = string.Empty;
var porxies = File.ReadLines("Proxies.txt");
foreach (var porxy in porxies)
{
WebProxy wp = new WebProxy(porxy.ToString());
client2.Proxy = wp;
try
{
content1 = ScrubContent(client2.DownloadString(args[0]));
break;
}
catch (Exception ex)
{
Console.WriteLine("{0}", ex.Message);
}
}

try
{
var migrationchecked = Migrationcheck.Matches(content1).Cast<Match>().Single().Groups[1];
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("UNMIGRATED " + line);
// UnmigratedWriter.WriteLine(line);
UnmigratedNumber++;
Console.Title = "Cookie Legacy checker | by BataBo | Checked: " + (UnmigratedNumber + MigratedNumber) + " | Good:" + UnmigratedNumber;

}
catch (InvalidOperationException ex)
{

Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("MIGRATED " + line);
// MigratedWriter.WriteLine(line);
MigratedNumber++;
Console.Title = "Cookie Legacy checker | by BataBo | Checked: " + (UnmigratedNumber + MigratedNumber) + " | Good:" + UnmigratedNumber;
}

}
}
}




//}
// }
});
Console.WriteLine("");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("====================Results====================");
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Checked: {0} names", UnmigratedNumber + MigratedNumber);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Unmigrated: {0} accounts", UnmigratedNumber);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Migrated: {0} accounts", MigratedNumber);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("====================Results====================");
Console.ReadLine();
}

static string ScrubContent(string content)
{
return new string(content.Where(c => c != '\n').ToArray());
}
}

Continue reading...
 
Back
Top