How to fix error 'System.InvalidOperationExeption:'Sequence contanis no elements'' in c#

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

BataBo Jokviu

Guest
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)
{
var lines = File.ReadLines("List.txt");
var UnmigratedNumber = 0;
var MigratedNumber = 0;
Console.Title = "Cookie Legacy checker | by BataBo | Checked: " + (UnmigratedNumber + MigratedNumber) + " | Good:" + UnmigratedNumber;

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 = ScrubContent(client1.DownloadString(args[0]));
var idchecked = idcheck.Matches(content).Cast<Match>().Single().Groups[1];
Console.WriteLine("" + idchecked);

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

};
using (var client2 = new WebClient())
{
var content1 = ScrubContent(client2.DownloadString(args[0]));
var migrationchecked = Migrationcheck.Matches(content1).Cast<Match>().Single().Groups[1];

Console.WriteLine("" + migrationchecked);


if (migrationchecked.ToString() == "true"){
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("UNMIGRATED " + line);
UnmigratedWriter.WriteLine(line);
UnmigratedNumber++;
Console.Title = "Cookie Legacy checker | by BataBo | Checked: " + (UnmigratedNumber + MigratedNumber) + " | Good:" + UnmigratedNumber;
}

else{
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());
}
}

I currently have problem with migrationcheck variable.My plan was this:If it finds the substring in the variable content than print that account is unmigrated and when It can't find that substring than print migrated but instead when it cant find the string it returns with an error.

This is how website that Im skidding looks like(When name is migrated):

"{\"id\":\"accid\",\"name\":\"MigratedName\",\"properties\":[{\"name\":\"textures\",\"value\":\"somevalue\"}]}"

This is how website that Im skiddding looks like(When name is unmigrated):

"{\"id\":\"accid\",\"name\":\"MigratedName\",\"properties\":[{\"name\":\"textures\",\"value\":\"somevalue\"}] ,\"Legacy\":\"True\"}"

Continue reading...
 
Back
Top