Last active
June 13, 2020 16:55
-
-
Save Theoistic/0063c8d6da46c3b05341945fa4deb4d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
namespace Test44 | |
{ | |
public class License | |
{ | |
public string ID { get; set; } | |
public string Device { get; set; } | |
public string Country { get; set; } | |
public string Start { get; set; } | |
public string End { get; set; } | |
public int DaysLeft { get; set; } | |
public override string ToString() | |
{ | |
return $"{ID} - Device: {Device}, Country: {Country}, Warranty Start: {Start}, Warranty End: {End}, Days Left: {DaysLeft}"; | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string filename = args.Length == 1 ? args[0] : "hits.txt"; | |
string[] lines = File.ReadAllLines(filename); | |
List<License> Licenses = new List<License>(); | |
foreach(var line in lines) | |
{ | |
string[] data = line.Split(':', ',', '-'); | |
Licenses.Add(new License | |
{ | |
ID = data[0].Trim(), | |
Device = data[2].Trim(), | |
Country = data[4].Trim(), | |
Start = data[6].Trim(), | |
End = data[8].Trim(), | |
DaysLeft = int.Parse(data.Last()) | |
}); | |
} | |
if(!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Over30"))) | |
Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "Over30")); | |
if (!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Under30"))) | |
Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "Under30")); | |
var files = Licenses.Where(x => x.DaysLeft <= 30).GroupBy(x => x.Device).Select(x => x); | |
foreach(var f in files) | |
{ | |
File.WriteAllLines(Path.Combine(Directory.GetCurrentDirectory(), "Under30", $"{f.Key}.txt"), f.Select(x => x.ToString()).ToArray()); | |
} | |
files = Licenses.Where(x => x.DaysLeft > 30).GroupBy(x => x.Device).Select(x => x); | |
foreach (var f in files) | |
{ | |
File.WriteAllLines(Path.Combine(Directory.GetCurrentDirectory(), "Over30", $"{f.Key}.txt"), f.Select(x => x.ToString()).ToArray()); | |
} | |
//File.WriteAllLines(Path.Combine(Directory.GetCurrentDirectory(), "Under30", "text1.txt"), Licenses.Where(x => x.DaysLeft <= 30).Select(x => x.ToString()).ToArray()); | |
//File.WriteAllLines(Path.Combine(Directory.GetCurrentDirectory(), "Over30", "text1.txt"), Licenses.Where(x => x.DaysLeft > 30).Select(x => x.ToString()).ToArray()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment