private static void Main(string[] args) { string inputFileName = args[0]; string outputFileName = Path.Combine(Path.GetDirectoryName(inputFileName) ?? throw new InvalidOperationException(), Path.GetFileNameWithoutExtension(inputFileName) + "_[daty].kcd"); string paramFileName = args[1]; KcdReader kcdReader = new KcdReader(inputFileName); kcdReader.LoadKcd(); List <KcdFeature> kcdFeatures = kcdReader.GetKcdFeatures(); using (StreamWriter sw = new StreamWriter(new FileStream(outputFileName, FileMode.Create), Encoding.GetEncoding(1250))) { foreach (string header in kcdReader.GetHeader()) { sw.Write(header + '\r'); } foreach (KcdFeature kcdFeature in kcdFeatures) { sw.Write(kcdFeature.AtrKodObiektu + '\r'); if (kcdFeature.AtrC != null) { sw.Write(kcdFeature.AtrC + '\r'); } if (kcdFeature.AtrG != null) { sw.Write(kcdFeature.AtrG + '\r'); } if (kcdFeature.AtrM != null) { sw.Write(kcdFeature.AtrM + '\r'); } if (kcdFeature.AtrS != null) { sw.Write(kcdFeature.AtrS + '\r'); } if (kcdFeature.AtrK != null) { sw.Write(kcdFeature.AtrK + '\r'); } if (kcdFeature.AtrI != null) { sw.Write(kcdFeature.AtrI + '\r'); } if (kcdFeature.AtrO != null) { sw.Write(kcdFeature.AtrO + '\r'); } foreach (string atrP in kcdFeature.AtrP) { sw.Write(atrP + '\r'); } if (kcdFeature.Atr1 != null) { sw.Write(kcdFeature.Atr1 + '\r'); } if (kcdFeature.Atr2 != null) { sw.Write(kcdFeature.Atr2 + '\r'); } if (kcdFeature.Atr3 != null) { sw.Write(kcdFeature.Atr3 + '\r'); } if (kcdFeature.Atr4 != null) { sw.Write(kcdFeature.Atr4 + '\r'); } if (kcdFeature.Atr6 != null) { sw.Write(kcdFeature.Atr6 + '\r'); } if (kcdFeature.Atr7 != null) { sw.Write(kcdFeature.Atr7 + '\r'); } if (kcdFeature.Atr8 != null) { sw.Write(kcdFeature.Atr8 + '\r'); } if (kcdFeature.Atr11 != null) { sw.Write(kcdFeature.Atr11 + '\r'); } if (kcdFeature.Atr15 != null) { sw.Write(kcdFeature.Atr15 + '\r'); } if (kcdFeature.Atr16 != null) { sw.Write(kcdFeature.Atr16 + '\r'); } if (kcdFeature.Atr17 != null) { sw.Write(kcdFeature.Atr17 + '\r'); } if (kcdFeature.Atr18 != null) { sw.Write(kcdFeature.Atr18 + '\r'); } if (kcdFeature.Atr19 != null) { sw.Write(kcdFeature.Atr19 + '\r'); } if (kcdFeature.Atr40 != null) { sw.Write(kcdFeature.Atr40 + '\r'); } if (kcdFeature.Atr41 != null) { sw.Write(kcdFeature.Atr41 + '\r'); } if (kcdFeature.Atr73 != null) { sw.Write(kcdFeature.Atr73 + '\r'); } if (kcdFeature.Atr76 != null) { sw.Write(kcdFeature.Atr76 + '\r'); } if (kcdFeature.Atr77 != null) { sw.Write(kcdFeature.Atr77 + '\r'); } if (kcdFeature.Atr78 != null) { sw.Write(kcdFeature.Atr78 + '\r'); } if (kcdFeature.Atr79 != null) { sw.Write(kcdFeature.Atr79 + '\r'); } if (kcdFeature.Atr81 != null) { sw.Write(kcdFeature.Atr81 + '\r'); } if (kcdFeature.Atr84 != null) { sw.Write(kcdFeature.Atr84 + '\r'); } if (kcdFeature.Atr86 != null) { sw.Write(kcdFeature.Atr86 + '\r'); } if (kcdFeature.Atr87 != null) { sw.Write(kcdFeature.Atr87 + '\r'); } if (kcdFeature.Atr88 != null) { sw.Write(kcdFeature.Atr88 + '\r'); } if (kcdFeature.Atr89 != null) { sw.Write(kcdFeature.Atr89 + '\r'); } if (kcdFeature.Atr91 != null) { sw.Write(kcdFeature.Atr91 + '\r'); } if (kcdFeature.Atr92 != null) { sw.Write(kcdFeature.Atr92 + '\r'); } if (kcdFeature.Atr93 != null) { sw.Write(kcdFeature.Atr93 + '\r'); } if (kcdFeature.Atr94 != null) { sw.Write(kcdFeature.Atr94 + '\r'); } if (kcdFeature.Atr103 != null) { sw.Write(kcdFeature.Atr103 + '\r'); } if (kcdFeature.Atr109 != null) { sw.Write(kcdFeature.Atr109 + '\r'); } if (kcdFeature.Atr110 != null) { sw.Write(kcdFeature.Atr110 + '\r'); } if (kcdFeature.Atr113 != null) { sw.Write(kcdFeature.Atr113 + '\r'); } if (kcdFeature.Atr255 != null) { sw.Write(kcdFeature.Atr255 + '\r'); } if (kcdFeature.Atr333 != null) { sw.Write(kcdFeature.Atr333 + '\r'); } if (kcdFeature.Atr990 != null) { sw.Write(kcdFeature.Atr990 + '\r'); } if (kcdFeature.Atr991 != null) { sw.Write(kcdFeature.Atr991 + '\r'); } if (kcdFeature.Atr995 != null) { sw.Write(kcdFeature.Atr995 + '\r'); } //foreach (string atrW in kcdFeature.AtrW) //{ // sw.Write(atrW + '\r'); //} } sw.Write(":FK" + '\r'); } Console.WriteLine(@"Koniec"); Console.ReadKey(); }
private static void Main(string[] args) { string inFileName = args[0]; // USUNIĘCIE DUBLI PUNKTOW NA WEJSCIU string outFileName = Path.Combine(Path.GetDirectoryName(inFileName) ?? throw new InvalidOperationException(), Path.GetFileNameWithoutExtension(inFileName) + ".tmp"); using (StreamReader sr = new StreamReader(inFileName, Encoding.GetEncoding(1250))) using (StreamWriter sw = new StreamWriter(outFileName, false, Encoding.GetEncoding(1250))) { string linePop = ""; while (sr.Peek() >= 0) { string line = sr.ReadLine(); if (line != linePop) { linePop = line; sw.WriteLine(line); } } } inFileName = outFileName; KcdReader kcdReader = new KcdReader(inFileName); kcdReader.LoadKcd(); int featureCount = 0; using (StreamWriter sw = new StreamWriter( new FileStream( Path.Combine(Path.GetDirectoryName(inFileName) ?? throw new InvalidOperationException(), Path.GetFileNameWithoutExtension(inFileName) + "_[err].kcd"), FileMode.Create), Encoding.GetEncoding(1250))) { foreach (KcdFeature kcdFeature in kcdReader.GetKcdFeatures()) { if (kcdFeature.AtrDuplicatesCount == 0) { featureCount++; sw.Write(kcdFeature.AtrKodObiektu + '\r'); if (kcdFeature.AtrC != null) { sw.Write(kcdFeature.AtrC + '\r'); } if (kcdFeature.AtrM != null) { sw.Write(kcdFeature.AtrM + '\r'); } if (kcdFeature.AtrS != null) { sw.Write(kcdFeature.AtrS + '\r'); } if (kcdFeature.AtrK != null) { sw.Write(kcdFeature.AtrK + '\r'); } if (kcdFeature.Atr333 != null) { sw.Write(kcdFeature.Atr333 + '\r'); } if (kcdFeature.AtrI != null) { sw.Write(kcdFeature.AtrI + '\r'); } foreach (string atrP in kcdFeature.AtrP) { sw.Write(atrP + '\r'); } if (kcdFeature.AtrO != null) { sw.Write(kcdFeature.AtrO + '\r'); } if (kcdFeature.Atr6 != null) { sw.Write(kcdFeature.Atr6 + '\r'); } if (kcdFeature.Atr15 != null) { sw.Write(kcdFeature.Atr15 + '\r'); } if (kcdFeature.Atr16 != null) { sw.Write(kcdFeature.Atr16 + '\r'); } if (kcdFeature.Atr17 != null) { sw.Write(kcdFeature.Atr17 + '\r'); } if (kcdFeature.Atr18 != null) { sw.Write(kcdFeature.Atr18 + '\r'); } if (kcdFeature.Atr73 != null) { sw.Write(kcdFeature.Atr73 + '\r'); } if (kcdFeature.Atr76 != null) { sw.Write(kcdFeature.Atr76 + '\r'); } if (kcdFeature.Atr77 != null) { sw.Write(kcdFeature.Atr77 + '\r'); } if (kcdFeature.Atr78 != null) { sw.Write(kcdFeature.Atr78 + '\r'); } if (kcdFeature.Atr79 != null) { sw.Write(kcdFeature.Atr79 + '\r'); } if (kcdFeature.Atr94 != null) { sw.Write(kcdFeature.Atr94 + '\r'); } if (kcdFeature.AtrW != null) { sw.Write(kcdFeature.AtrW + '\r'); } } } if (featureCount > 0) { sw.Write(":FK" + '\r'); } } featureCount = 0; using (StreamWriter sw = new StreamWriter( new FileStream( Path.Combine(Path.GetDirectoryName(inFileName) ?? throw new InvalidOperationException(), Path.GetFileNameWithoutExtension(inFileName) + "_[poprawne].kcd"), FileMode.Create), Encoding.GetEncoding(1250))) { foreach (KcdFeature kcdFeature in kcdReader.GetKcdFeatures()) { if (kcdFeature.AtrDuplicatesCount == 1) { featureCount++; sw.Write(kcdFeature.AtrKodObiektu + '\r'); if (kcdFeature.AtrC != null) { sw.Write(kcdFeature.AtrC + '\r'); } if (kcdFeature.AtrM != null) { sw.Write(kcdFeature.AtrM + '\r'); } if (kcdFeature.AtrS != null) { sw.Write(kcdFeature.AtrS + '\r'); } if (kcdFeature.AtrK != null) { sw.Write(kcdFeature.AtrK + '\r'); } if (kcdFeature.Atr333 != null) { sw.Write(kcdFeature.Atr333 + '\r'); } if (kcdFeature.AtrI != null) { sw.Write(kcdFeature.AtrI + '\r'); } foreach (string atrP in kcdFeature.AtrP) { sw.Write(atrP + '\r'); } if (kcdFeature.AtrO != null) { sw.Write(kcdFeature.AtrO + '\r'); } if (kcdFeature.Atr6 != null) { sw.Write(kcdFeature.Atr6 + '\r'); } if (kcdFeature.Atr15 != null) { sw.Write(kcdFeature.Atr15 + '\r'); } if (kcdFeature.Atr16 != null) { sw.Write(kcdFeature.Atr16 + '\r'); } if (kcdFeature.Atr17 != null) { sw.Write(kcdFeature.Atr17 + '\r'); } if (kcdFeature.Atr18 != null) { sw.Write(kcdFeature.Atr18 + '\r'); } if (kcdFeature.Atr73 != null) { sw.Write(kcdFeature.Atr73 + '\r'); } if (kcdFeature.Atr76 != null) { sw.Write(kcdFeature.Atr76 + '\r'); } if (kcdFeature.Atr77 != null) { sw.Write(kcdFeature.Atr77 + '\r'); } if (kcdFeature.Atr78 != null) { sw.Write(kcdFeature.Atr78 + '\r'); } if (kcdFeature.Atr79 != null) { sw.Write(kcdFeature.Atr79 + '\r'); } if (kcdFeature.Atr94 != null) { sw.Write(kcdFeature.Atr94 + '\r'); } if (kcdFeature.AtrW != null) { sw.Write(kcdFeature.AtrW + '\r'); } } } if (featureCount > 0) { sw.Write(":FK" + '\r'); } } featureCount = 0; using (StreamWriter sw = new StreamWriter( new FileStream( Path.Combine(Path.GetDirectoryName(inFileName) ?? throw new InvalidOperationException(), Path.GetFileNameWithoutExtension(inFileName) + "_[duble].kcd"), FileMode.Create), Encoding.GetEncoding(1250))) { foreach (KcdFeature kcdFeature in kcdReader.GetKcdFeatures()) { if (kcdFeature.AtrDuplicatesCount > 1) { featureCount++; sw.Write(kcdFeature.AtrKodObiektu + '\r'); if (kcdFeature.AtrC != null) { sw.Write(kcdFeature.AtrC + '\r'); } if (kcdFeature.AtrM != null) { sw.Write(kcdFeature.AtrM + '\r'); } if (kcdFeature.AtrS != null) { sw.Write(kcdFeature.AtrS + '\r'); } if (kcdFeature.AtrK != null) { sw.Write(kcdFeature.AtrK + '\r'); } if (kcdFeature.Atr333 != null) { sw.Write(kcdFeature.Atr333 + '\r'); } if (kcdFeature.AtrI != null) { sw.Write(kcdFeature.AtrI + '\r'); } foreach (string atrP in kcdFeature.AtrP) { sw.Write(atrP + '\r'); } if (kcdFeature.AtrO != null) { sw.Write(kcdFeature.AtrO + '\r'); } if (kcdFeature.Atr6 != null) { sw.Write(kcdFeature.Atr6 + '\r'); } if (kcdFeature.Atr15 != null) { sw.Write(kcdFeature.Atr15 + '\r'); } if (kcdFeature.Atr16 != null) { sw.Write(kcdFeature.Atr16 + '\r'); } if (kcdFeature.Atr17 != null) { sw.Write(kcdFeature.Atr17 + '\r'); } if (kcdFeature.Atr18 != null) { sw.Write(kcdFeature.Atr18 + '\r'); } if (kcdFeature.Atr73 != null) { sw.Write(kcdFeature.Atr73 + '\r'); } if (kcdFeature.Atr76 != null) { sw.Write(kcdFeature.Atr76 + '\r'); } if (kcdFeature.Atr77 != null) { sw.Write(kcdFeature.Atr77 + '\r'); } if (kcdFeature.Atr78 != null) { sw.Write(kcdFeature.Atr78 + '\r'); } if (kcdFeature.Atr79 != null) { sw.Write(kcdFeature.Atr79 + '\r'); } if (kcdFeature.Atr94 != null) { sw.Write(kcdFeature.Atr94 + '\r'); } if (kcdFeature.AtrW != null) { sw.Write(kcdFeature.AtrW + '\r'); } } } if (featureCount > 0) { sw.Write(":FK" + '\r'); } } Console.WriteLine(@"Koniec"); Console.ReadKey(); }
static void Main(string[] args) { string fileName = args[0]; string outputFile = Path.Combine(Path.GetDirectoryName(fileName) ?? throw new InvalidOperationException(), Path.GetFileNameWithoutExtension(fileName) + "_[pikiety].kcd"); string logFile = Path.Combine(Path.GetDirectoryName(fileName) ?? throw new InvalidOperationException(), Path.GetFileNameWithoutExtension(fileName) + "_[pikiety].log"); KcdReader kcdReader = new KcdReader(fileName); kcdReader.LoadKcd(); List <KcdFeature> kcdFeatures = kcdReader.GetKcdFeatures(); foreach (KcdFeature kcdFeature in kcdFeatures.Where(kcdFeature => string.IsNullOrEmpty(kcdFeature.AtrK))) { kcdFeature.AtrK = "brak"; } Dictionary <string, int> operatyCount = kcdFeatures.Select(kcd => kcd.AtrK).Distinct().ToDictionary(o => o, o => 0); using (StreamWriter sw = new StreamWriter(new FileStream(outputFile, FileMode.Create), Encoding.GetEncoding(1250))) { foreach (KcdFeature kcdFeature in kcdFeatures.Where(kcdFeature => !kcdFeature.AtrKodObiektu.StartsWith(":ET") && !kcdFeature.AtrKodObiektu.StartsWith(":ES") && !kcdFeature.AtrKodObiektu.StartsWith(":EP"))) { kcdFeature.AtrP = kcdFeature.AtrP.Distinct().ToList(); foreach (string atrP in kcdFeature.AtrP) { operatyCount[kcdFeature.AtrK] = operatyCount[kcdFeature.AtrK] + 1; sw.Write(":EP1902" + '\r'); if (!string.IsNullOrEmpty(kcdFeature.AtrK) && kcdFeature.AtrK != "brak") { sw.Write(kcdFeature.AtrK + '\r'); // KERG, OPERAT, IDMAT } sw.Write(atrP + '\r'); if (!string.IsNullOrEmpty(kcdFeature.Atr15)) { sw.Write(kcdFeature.Atr15 + '\r'); // Źródło danych o położeniu SUT (15) } if (!string.IsNullOrEmpty(kcdFeature.Atr16)) { sw.Write(kcdFeature.Atr16 + '\r'); // Źródło danych o położeniu (16) } if (!string.IsNullOrEmpty(kcdFeature.Atr73)) { sw.Write(kcdFeature.Atr73 + '\r'); // Data pomiaru (73) } sw.Write("a103," + operatyCount[kcdFeature.AtrK] + '\r'); sw.Write(atrP.Replace("p", "w") + '\r'); // w - etykieta } } sw.Write(":FK" + '\r'); } using (StreamWriter sw = new StreamWriter(new FileStream(logFile, FileMode.Create), Encoding.GetEncoding(1250))) { foreach (KeyValuePair <string, int> operat in operatyCount) { Console.WriteLine(operat.Key + ": " + operat.Value); sw.WriteLine(operat.Key + ": " + operat.Value); } } Console.Write(@"Koniec"); Console.ReadKey(); }