//This thing will throw all sorts of exceptions, make sure to catch them... //It also returns null if basically anything goes wrong? Probably... public static GenericRule newFromIO(string[] lines) { GenericRule schRule = null; if (Int32.Parse(lines[1]) == 0) //5 lines for TimeRule { byte type = Byte.Parse(lines[0]); string[] blockTheseApps = lines[1].Split(new string[] { ",", " " }, StringSplitOptions.RemoveEmptyEntries); string[] stringBool = lines[2].Split(new string[] { ",", " " }, StringSplitOptions.RemoveEmptyEntries); bool[] blockTheseComparts = new bool[stringBool.Length]; for (byte i = 0; i < blockTheseComparts.Length; i++) { blockTheseComparts[i] = Convert.ToBoolean(stringBool[i]); } switch (type) { case 0: default: DateTime startTime = DateTime.Parse(lines[3]); DateTime endTime = DateTime.Parse(lines[4]); schRule = new TimeRule(startTime, endTime, blockTheseComparts, blockTheseApps); break; } } return(schRule); }
private void btnOldOpenBox_Click(object sender, EventArgs e) { GenericRule schRule; try { //Precondtion: 5 elements in each entry string[] fileIn = System.IO.File.ReadAllLines(comDirectory + "\\ResponseRuleDescs.txt"); for (int shift = 0; shift + 5 <= fileIn.Length; shift += 5) { byte type = (byte)Int32.Parse(fileIn[shift + 0]); string[] blockTheseApps = fileIn[shift + 1].Split(new string[] { ",", " " }, StringSplitOptions.RemoveEmptyEntries); string[] stringBool = fileIn[shift + 2].Split(new string[] { ",", " " }, StringSplitOptions.RemoveEmptyEntries); bool[] blockTheseComparts = new bool[stringBool.Length]; for (byte i = 0; i < blockTheseComparts.Length; i++) { blockTheseComparts[i] = Convert.ToBoolean(stringBool[i]); } switch (type) { case 0: default: DateTime startTime = DateTime.Parse(fileIn[shift + 3]); DateTime endTime = DateTime.Parse(fileIn[shift + 4]); schRule = new TimeRule(startTime, endTime, blockTheseComparts, blockTheseApps); break; } if (!rules.Contains(schRule)) { rules.Add(schRule); } updateGridView(); Debug.WriteLine("Rules updated?."); } } catch (Exception ex) { System.IO.File.AppendAllText(comDirectory + "\\EXCEPT.txt", ex.ToString() + "\n"); } }