Skip to content

Instantly share code, notes, and snippets.

@seankearon
Created September 15, 2013 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seankearon/6572130 to your computer and use it in GitHub Desktop.
Save seankearon/6572130 to your computer and use it in GitHub Desktop.
void Main()
{
var file = @"C:\Users\Me\Desktop\Certificates.txt";
var a = JObject.Parse(File.ReadAllText(file));
var cert = a["Certificates"][0];
// Get the UIDs for the existing boards and circuits.
var boards = cert["Boards"].Select (x => (Guid)x["UniqueId"]).ToArray();
var circuits = cert["Boards"].SelectMany (x => x["Circuits"]).Select (x => (Guid)x["UniqueId"]).ToArray();
var changes = new List<string>();
foreach (var board in cert["Boards"])
{
var designation = (string)board["Designation"];
var supplyBoard = (Guid)board["SupplyBoard"];
var supplyCircuit = (Guid)board["SupplyCircuit"];
if (supplyBoard != Guid.Empty && !boards.Contains(supplyBoard))
{
board["SupplyBoard"] = Guid.Empty;
board["SupplyIsOriginOfInstallation"] = true;
changes.Add("Set supply to origin for " + designation);
}
if (supplyCircuit != Guid.Empty && !circuits.Contains(supplyCircuit))
{
board["SupplyCircuit"] = Guid.Empty;
board["SupplyIsOriginOfInstallation"] = true;
changes.Add("Set supply to origin for " + designation);
}
}
File.WriteAllText(file, a.ToString());
changes.Dump("Changes");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment