From cb0780a4b7583580cc9178516d2d5e60ee093a57 Mon Sep 17 00:00:00 2001
From: JLdgu
Date: Thu, 11 Jun 2026 12:27:38 +0100
Subject: [PATCH] Remove Knox reconciliation process
No production Samsung devices remain on DCC network
---
PhoneAssistant.Cli/Knox.cs | 200 ---------------------------------
PhoneAssistant.Cli/Program.cs | 4 +-
PhoneAssistant.Cli/readMe.html | 33 +-----
3 files changed, 4 insertions(+), 233 deletions(-)
delete mode 100644 PhoneAssistant.Cli/Knox.cs
diff --git a/PhoneAssistant.Cli/Knox.cs b/PhoneAssistant.Cli/Knox.cs
deleted file mode 100644
index edc49529..00000000
--- a/PhoneAssistant.Cli/Knox.cs
+++ /dev/null
@@ -1,200 +0,0 @@
-using CsvHelper;
-using CsvHelper.Configuration.Attributes;
-using ExcelDataReader;
-using Serilog;
-using System.CommandLine;
-using System.Data;
-using System.Globalization;
-using System.Text;
-
-namespace PhoneAssistant.Cli;
-
-internal static class Knox
-{
- internal static void Command(RootCommand rootCommand)
- {
- StringBuilder sb = new();
- sb.AppendLine("Create a csv file containing decommissioned/disposed IMEIs that can be bulk imported to Samsung Knox.");
- sb.AppendLine();
- sb.AppendLine("The output file (knox_import.csv) will contain IMEIs that are marked as decommissioned and disposed on myScomis.");
- sb.AppendLine("Input file name expected formats are:");
- sb.AppendLine("CI List*.xlsx for myScomis import - most recent will be used");
- sb.AppendLine("kme_devices.csv");
- sb.AppendLine();
- sb.AppendLine("All files should be placed in the folder specified. Defaults to users Downloads folder");
-
- Command knoxCommand = new("knox", sb.ToString());
- Option workFolderOption = new("--folder", "-f")
- {
- Description = "Path to the folder where the output csv file should be created",
- Validators =
- {
- result =>
- {
- var dir = result.GetValueOrDefault();
- if (dir == null || !dir.Exists)
- {
- result.AddError("The specified folder does not exist.");
- }
- }
- }
- };
- knoxCommand.Add(workFolderOption);
-
- knoxCommand.SetAction(parseResult =>
- {
- try
- {
- var outputFolder = parseResult.GetValue(workFolderOption);
- if (outputFolder is null)
- Log.Fatal("Output folder is required");
- else
- {
- Log.Information("Creating Knox import file");
- Knox.Execute(outputFolder);
- }
- }
- catch (Exception ex)
- {
- Log.Fatal(exception: ex, "Unhandled exception:");
- }
- });
-
- rootCommand.Add(knoxCommand);
- }
-
- public static void Execute(DirectoryInfo workFolder)
- {
- workFolder ??= new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads"));
- if (!workFolder.Exists)
- {
- Log.Error("The folder {0} does not exist.", workFolder.FullName);
- return;
- }
-
- // Find the latest "CI List *.xlsx" file in the workFolder directory
- var ciFiles = workFolder.GetFiles("CI List*.xlsx");
- if (ciFiles.Length == 0)
- {
- Log.Error("No 'CI List *.xlsx' file found in {0}.", workFolder.FullName);
- return;
- }
- FileInfo ciFile = ciFiles.OrderByDescending(f => f.LastWriteTime).First();
-
- FileInfo knoxFile = new(Path.Combine(workFolder.FullName, "kme_devices.csv"));
- if (!knoxFile.Exists)
- {
- Log.Error("No 'kme_devices.csv' file found in {0}.", workFolder.FullName);
- return;
-
- }
-
- using var reader = new StreamReader(knoxFile.FullName);
- using var csvFile = new CsvReader(reader, CultureInfo.InvariantCulture);
-
- List activeSIMs = [.. csvFile.GetRecords()];
- HashSet imeiSet = [.. activeSIMs.Select(sim => sim.IMEI_MEID)];
-
- using FileStream stream = new(ciFile.FullName, FileMode.Open, FileAccess.Read);
- using var excelReader = ExcelReaderFactory.CreateReader(stream);
-
- // Convert the first sheet to DataTable
- var ciSheet = new System.Data.DataTable();
- var fieldCount = excelReader.FieldCount;
-
- for (int i = 0; i < fieldCount; i++)
- {
- ciSheet.Columns.Add($"Col{i}", typeof(object));
- }
-
- while (excelReader.Read())
- {
- var values = new object[fieldCount];
- excelReader.GetValues(values);
- ciSheet.Rows.Add(values);
- }
-
- if (ciSheet.Rows.Count == 0 || ciSheet.Columns.Count <= 3)
- {
- Log.Error("Expected 'Name' in cell D1, found empty sheet.");
- return;
- }
-
- string? cellValue = ciSheet.Rows[0][3]?.ToString()?.Trim();
- if (cellValue != "Name")
- {
- Log.Error("Expected 'Name' in cell D1, found '{0}'.", cellValue);
- return;
- }
-
- int rows = ciSheet.Rows.Count - 1;
- Log.Information("Processing {0} rows from the Excel file.", rows);
- Progress progress = new();
-
- List matchedIMEIs = [];
- for (int i = 1; i < ciSheet.Rows.Count; i++)
- {
- if (i % 10 == 0 || i == rows)
- {
- progress.Draw(i, rows);
- }
-
- var row = ciSheet.Rows[i];
- if (row == null) continue;
- string? imei = row[3]?.ToString()?.Trim();
- string? status = row[7]?.ToString()?.Trim();
-
- if (string.IsNullOrEmpty(imei)) continue;
- if (string.IsNullOrEmpty(status)) continue;
-
- if (!status.Equals("Decommissioned", StringComparison.OrdinalIgnoreCase) &&
- !status.Equals("Disposed", StringComparison.OrdinalIgnoreCase)) continue;
- if (!imeiSet.Contains(imei)) continue;
-
- matchedIMEIs.Add(new SIM(imei));
-
- }
- using var writer = new StreamWriter(Path.Combine(workFolder.FullName,"knox_bulk_delete.csv"));
- using var csvOut = new CsvWriter(writer, CultureInfo.InvariantCulture);
- csvOut.WriteRecords(matchedIMEIs);
-
- Log.Information("Matched {0} IMEIs.", matchedIMEIs.Count);
- }
-}
-
-
-public class ActiveKnoxSIM
-{
- [Name("IMEI/MEID")]
- public required string IMEI_MEID { get; set; }
- public string? IMEI2 { get; set; }
- [Name("Serial number")]
- public string? SerialNumber { get; set; }
- [Name("Wi-Fi: Device MAC Address")]
- public string? WifiDeviceMacAddress { get; set; }
- [Name("Order Date")]
- public string? OrderDate { get; set; }
- [Name("Order Number")]
- public string? OrderNumber { get; set; }
- public string? Model { get; set; }
- [Name("User ID")]
- public string? UserID { get; set; }
- public string? Tags { get; set; }
- public string? Submitted { get; set; }
- [Name("Enrollment profile")]
- public string? EnrollmentProfile { get; set; }
- public string? Status { get; set; }
- [Name("Reseller ID")]
- public string? ResellerID { get; set; }
- [Name("Reseller name")]
- public string? ResellerName { get; set; }
- [Name("Last Modified Time")]
- public string? LastModifiedTime { get; set; }
- [Name("Last Seen")]
- public string? LastSeen { get; set; }
-}
-
-public class SIM(string imei)
-{
- public string IMEI { get; init; } = imei;
-}
\ No newline at end of file
diff --git a/PhoneAssistant.Cli/Program.cs b/PhoneAssistant.Cli/Program.cs
index b7c571a2..5735a658 100644
--- a/PhoneAssistant.Cli/Program.cs
+++ b/PhoneAssistant.Cli/Program.cs
@@ -25,9 +25,7 @@ private static Task Main(string[] args)
Base.Command(rootCommand);
Disposal.Command(rootCommand);
-
- Knox.Command(rootCommand);
-
+
return rootCommand.Parse(args).InvokeAsync();
}
finally
diff --git a/PhoneAssistant.Cli/readMe.html b/PhoneAssistant.Cli/readMe.html
index 58bfa3d3..22354138 100644
--- a/PhoneAssistant.Cli/readMe.html
+++ b/PhoneAssistant.Cli/readMe.html
@@ -19,12 +19,12 @@ CLI Overview
Command Structure
- CLI command structure consists of the cli application ("pac"), the commands ("base", "knox"), and possibly command arguments and options.
+ CLI command structure consists of the cli application ("pac"), the commands ("base", "disposal"), and possibly command arguments and options.
.\pac base
- .\pac knox --folder c:\temp
+ .\pac disposal --folder c:\temp
base Command
@@ -39,34 +39,7 @@ Options
**Required.** Full path to the EE base report file to import (must be an `.xlsx` file).
-
- knox Command
- Compares a list of myScomis CIs with one from Samsung Knox and creates a list of decommissioned or disposed devices, suitable for bulk import into Samsung Knox.
- Usage
-
- Options
-
- --folder or -f
-
-
- Path to the folder where the input files can be found and the output CSV file should be created.
- If not specified, defaults to the user's Downloads folder.
-
- Input Files
-
- The working folder should contain:
- - An export from myScomis containing CIs, the most recently modified `CI List*.xlsx` file in the working folder is used.
- - An export from Samsung Knox containing the complete list of enrolled devices `kme_devices.csv`
-
- Output File
-
- The working folder should contain:
- - A CSV file suitable for bulk device delete in Samsung Knox `knox_bulk_delete.csv`
-
+