Changeset 920
- Timestamp:
- 4/29/2009 9:20:50 AM (4 years ago)
- Location:
- branches/eraser6
- Files:
-
- 6 edited
-
Eraser/LogForm.cs (modified) (5 diffs)
-
Eraser/ProgressForm.cs (modified) (1 diff)
-
Eraser/SchedulerPanel.cs (modified) (1 diff)
-
Manager/DirectExecutor.cs (modified) (10 diffs)
-
Manager/Logger.cs (modified) (4 diffs)
-
Manager/Task.cs (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/Eraser/LogForm.cs
r909 r920 46 46 //Add all the existing log messages 47 47 this.log.BeginUpdate(); 48 Dictionary<DateTime, List<LogEntry>>log = task.Log.Entries;48 LogSessionCollection log = task.Log.Entries; 49 49 foreach (DateTime sessionTime in log.Keys) 50 50 { 51 51 this.log.Groups.Add(new ListViewGroup(S._("Session: {0:F}", sessionTime))); 52 52 foreach (LogEntry entry in log[sessionTime]) 53 task_Logged( entry);53 task_Logged(this, new LogEventArgs(entry)); 54 54 } 55 55 56 56 //Register our event handler to get live log messages 57 task.Log. OnLogged += new Logger.LogEventFunction(task_Logged);57 task.Log.Logged += new EventHandler<LogEventArgs>(task_Logged); 58 58 this.log.EndUpdate(); 59 59 } … … 61 61 private void LogForm_FormClosed(object sender, FormClosedEventArgs e) 62 62 { 63 task.Log. OnLogged -= new Logger.LogEventFunction(task_Logged);63 task.Log.Logged -= new EventHandler<LogEventArgs>(task_Logged); 64 64 } 65 65 66 private void task_Logged( LogEntrye)66 private void task_Logged(object sender, LogEventArgs e) 67 67 { 68 68 if (InvokeRequired) … … 71 71 try 72 72 { 73 Invoke(new Logger.LogEventFunction(task_Logged), new object[] { e });73 Invoke(new EventHandler<LogEventArgs>(task_Logged), new object[] { e }); 74 74 } 75 75 catch (ObjectDisposedException) … … 82 82 } 83 83 84 ListViewItem item = log.Items.Add(e. Timestamp.ToString("F", CultureInfo.CurrentCulture));85 item.SubItems.Add(e.L evel.ToString());86 item.SubItems.Add(e. Message);84 ListViewItem item = log.Items.Add(e.LogEntry.Timestamp.ToString("F", CultureInfo.CurrentCulture)); 85 item.SubItems.Add(e.LogEntry.Level.ToString()); 86 item.SubItems.Add(e.LogEntry.Message); 87 87 if (log.Groups.Count != 0) 88 88 item.Group = log.Groups[log.Groups.Count - 1]; 89 89 90 switch (e.L evel)90 switch (e.LogEntry.Level) 91 91 { 92 92 case LogLevel.Fatal: … … 109 109 { 110 110 StringBuilder text = new StringBuilder(); 111 Dictionary<DateTime, List<LogEntry>>logEntries = task.Log.Entries;111 LogSessionCollection logEntries = task.Log.Entries; 112 112 foreach (DateTime sessionTime in logEntries.Keys) 113 113 { -
branches/eraser6/Eraser/ProgressForm.cs
r917 r920 102 102 //Inform the user on the status of the task. 103 103 LogLevel highestLevel = LogLevel.Information; 104 L ist<LogEntry>entries = e.Task.Log.LastSessionEntries;104 LogEntryCollection entries = e.Task.Log.LastSessionEntries; 105 105 foreach (LogEntry log in entries) 106 106 if (log.Level > highestLevel) -
branches/eraser6/Eraser/SchedulerPanel.cs
r917 r920 230 230 //Get the exit status of the task. 231 231 LogLevel highestLevel = LogLevel.Information; 232 L ist<LogEntry>logs = e.Task.Log.LastSessionEntries;232 LogEntryCollection logs = e.Task.Log.LastSessionEntries; 233 233 foreach (LogEntry log in logs) 234 234 if (log.Level > highestLevel) -
branches/eraser6/Manager/DirectExecutor.cs
r917 r920 154 154 //Start a new log session to separate this session's events 155 155 //from previous ones. 156 task.Log. NewSession();156 task.Log.Entries.NewSession(); 157 157 158 158 //Run the task … … 176 176 catch (Exception e) 177 177 { 178 task.Log. Add(new LogEntry(e.Message, LogLevel.Error));178 task.Log.LastSessionEntries.Add(new LogEntry(e.Message, LogLevel.Error)); 179 179 } 180 180 } 181 181 catch (FatalException e) 182 182 { 183 task.Log. Add(new LogEntry(e.Message, LogLevel.Fatal));183 task.Log.LastSessionEntries.Add(new LogEntry(e.Message, LogLevel.Fatal)); 184 184 } 185 185 catch (Exception e) 186 186 { 187 task.Log. Add(new LogEntry(e.Message, LogLevel.Error));187 task.Log.LastSessionEntries.Add(new LogEntry(e.Message, LogLevel.Error)); 188 188 } 189 189 finally … … 387 387 Environment.OSVersion.Version >= new Version(6, 0)) 388 388 { 389 throw new UnauthorizedAccessException(S._("The program does not have the required" +390 " permissions to erase the unused space on disk. Run the program as an administrator" +391 "a nd retry the operation."));389 throw new UnauthorizedAccessException(S._("The program does not have the " + 390 "required permissions to erase the unused space on disk. Run the program " + 391 "as an administrator and retry the operation.")); 392 392 } 393 393 else 394 throw new UnauthorizedAccessException(S._("The program does not have the required permissions" +395 " to erase the unused space on disk"));394 throw new UnauthorizedAccessException(S._("The program does not have the " + 395 "required permissions to erase the unused space on disk")); 396 396 } 397 397 398 398 //If the user is under disk quotas, log a warning message 399 399 if (VolumeInfo.FromMountpoint(target.Drive).HasQuota) 400 task.Log. Add(new LogEntry(S._("The drive which is having its unused space erased" +401 " has disk quotas active. This will prevent the complete erasure of unused" +402 " space and will pose a security concern"), LogLevel.Warning));400 task.Log.LastSessionEntries.Add(new LogEntry(S._("The drive which is having its " + 401 "unused space erased has disk quotas active. This will prevent the complete " + 402 "erasure of unused space and will pose a security concern"), LogLevel.Warning)); 403 403 404 404 //Get the erasure method if the user specified he wants the default. … … 565 565 if ((info.Attributes & FileAttributes.ReparsePoint) != 0) 566 566 { 567 task.Log. Add(new LogEntry(S._("Files in {0} did not have their cluster" +568 " tips erased because it is a hard link or a symbolic link.",569 info.FullName), LogLevel.Information));567 task.Log.LastSessionEntries.Add(new LogEntry(S._("Files in {0} did " + 568 "not have their cluster tips erased because it is a hard link or " + 569 "a symbolic link.", info.FullName), LogLevel.Information)); 570 570 return; 571 571 } … … 573 573 foreach (FileInfo file in info.GetFiles()) 574 574 if (Util.File.IsProtectedSystemFile(file.FullName)) 575 task.Log. Add(new LogEntry(S._("{0} did not have its cluster tips" +576 " erased, because it is a system file", file.FullName),577 LogLevel.Information));575 task.Log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have " + 576 "its cluster tips erased, because it is a system file", 577 file.FullName), LogLevel.Information)); 578 578 else if ((file.Attributes & FileAttributes.ReparsePoint) != 0) 579 task.Log. Add(new LogEntry(S._("{0} did not have its cluster tips" +580 " erased because it is a hard link or a symbolic link.",581 file.FullName), LogLevel.Information));579 task.Log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have " + 580 "its cluster tips erased because it is a hard link or a " + 581 "symbolic link.", file.FullName), LogLevel.Information)); 582 582 else if ((file.Attributes & FileAttributes.Compressed) != 0 || 583 583 (file.Attributes & FileAttributes.Encrypted) != 0 || 584 584 (file.Attributes & FileAttributes.SparseFile) != 0) 585 585 { 586 task.Log. Add(new LogEntry(S._("{0} did not have its cluster tips" +587 " erased because it is compressed, encrypted or a sparse file.",588 file.FullName), LogLevel.Information));586 task.Log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have " + 587 "its cluster tips erased because it is compressed, encrypted " + 588 "or a sparse file.", file.FullName), LogLevel.Information)); 589 589 } 590 590 else … … 599 599 catch (IOException e) 600 600 { 601 task.Log. Add(new LogEntry(S._("{0} did not have its cluster tips erased" +602 " because of the following error: {1}", info.FullName, e.Message),603 LogLevel.Error));601 task.Log.LastSessionEntries.Add(new LogEntry(S._("{0} did not " + 602 "have its cluster tips erased because of the following " + 603 "error: {1}", info.FullName, e.Message), LogLevel.Error)); 604 604 } 605 605 } … … 610 610 catch (UnauthorizedAccessException e) 611 611 { 612 task.Log. Add(new LogEntry(S._("{0} did not have its cluster tips erased" +613 " because of the following error: {1}", info.FullName, e.Message),614 LogLevel.Error));612 task.Log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have its " + 613 "cluster tips erased because of the following error: {1}", 614 info.FullName, e.Message), LogLevel.Error)); 615 615 } 616 616 catch (IOException e) 617 617 { 618 task.Log. Add(new LogEntry(S._("{0} did not have its cluster tips erased" +619 " because of the following error: {1}", info.FullName, e.Message),620 LogLevel.Error));618 task.Log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have its " + 619 "cluster tips erased because of the following error: {1}", 620 info.FullName, e.Message), LogLevel.Error)); 621 621 } 622 622 }; … … 639 639 catch (Exception e) 640 640 { 641 task.Log.Add(new LogEntry(S._("{0} did not have its cluster tips erased. " + 642 "The error returned was: {1}", files[i], e.Message), LogLevel.Error)); 641 task.Log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have its " + 642 "cluster tips erased. The error returned was: {1}", files[i], 643 e.Message), LogLevel.Error)); 643 644 } 644 645 finally … … 755 756 { 756 757 //Log the error 757 task.Log. Add(new LogEntry(S._("The file {0} could not be erased " +758 " because the file was either compressed, encrypted or a sparse file.",759 info.FullName), LogLevel.Error));758 task.Log.LastSessionEntries.Add(new LogEntry(S._("The file {0} could " + 759 "not be erased because the file was either compressed, encrypted or " + 760 "a sparse file.", info.FullName), LogLevel.Error)); 760 761 } 761 762 … … 809 810 catch (UnauthorizedAccessException) 810 811 { 811 task.Log.Add(new LogEntry(S._("The file {0} could not be erased because the " + 812 "file's permissions prevent access to the file.", info.FullName), 812 task.Log.LastSessionEntries.Add(new LogEntry(S._("The file {0} could not " + 813 "be erased because the file's permissions prevent access to the file.", 814 info.FullName), LogLevel.Error)); 815 } 816 catch (FileLoadException) 817 { 818 task.Log.LastSessionEntries.Add(new LogEntry(S._("The file {0} could not be " + 819 "erased because the file is currently in use.", info.FullName), 813 820 LogLevel.Error)); 814 }815 catch (FileLoadException)816 {817 task.Log.Add(new LogEntry(S._("The file {0} could not be erased because the " +818 "file is currently in use.", info.FullName), LogLevel.Error));819 821 } 820 822 finally -
branches/eraser6/Manager/Logger.cs
r919 r920 72 72 protected Logger(SerializationInfo info, StreamingContext context) 73 73 { 74 entries = (Dictionary<DateTime, List<LogEntry>>) 75 info.GetValue("Entries", typeof(Dictionary<DateTime, List<LogEntry>>)); 76 foreach (DateTime key in entries.Keys) 74 Entries = (LogSessionCollection)info.GetValue("Entries", typeof(LogSessionCollection)); 75 foreach (DateTime key in Entries.Keys) 77 76 lastSession = key; 78 77 } … … 81 80 public virtual void GetObjectData(SerializationInfo info, StreamingContext context) 82 81 { 83 info.AddValue("Entries", entries);82 info.AddValue("Entries", Entries); 84 83 } 85 84 #endregion … … 90 89 public Logger() 91 90 { 92 entries = new Dictionary<DateTime, List<LogEntry>>(); 93 } 94 95 /// <summary> 96 /// The prototype of a registrant of the Log event. 97 /// </summary> 98 /// <param name="e"></param> 99 public delegate void LogEventFunction(LogEntry entry); 91 Entries = new LogSessionCollection(this); 92 } 100 93 101 94 /// <summary> 102 95 /// All the registered event handlers for the log event of this task. 103 96 /// </summary> 104 public event LogEventFunction OnLogged; 97 public EventHandler<LogEventArgs> Logged { get; set; } 98 99 internal void OnLogged(object sender, LogEventArgs e) 100 { 101 if (Logged != null) 102 Logged(sender, e); 103 } 105 104 106 105 /// <summary> … … 108 107 /// started. 109 108 /// </summary> 110 public event EventHandler OnNewSession; 109 public EventHandler<EventArgs> NewSession { get; set; } 110 111 internal void OnNewSession(object sender, LogEventArgs e) 112 { 113 if (Logged != null) 114 Logged(sender, e); 115 } 111 116 112 117 /// <summary> 113 118 /// Retrieves the log for this task. 114 119 /// </summary> 115 public Dictionary<DateTime, List<LogEntry>> Entries 120 public LogSessionCollection Entries { get; private set; } 121 122 /// <summary> 123 /// Retrieves the log entries from the previous session. 124 /// </summary> 125 public LogEntryCollection LastSessionEntries 116 126 { 117 127 get 118 128 { 119 return entries; 120 } 121 } 122 123 /// <summary> 124 /// Retrieves the log entries from the previous session. 125 /// </summary> 126 public List<LogEntry> LastSessionEntries 129 lock (Entries) 130 return Entries[lastSession]; 131 } 132 } 133 134 /// <summary> 135 /// Clears the log entries from the log. 136 /// </summary> 137 public void Clear() 138 { 139 lock (Entries) 140 { 141 Entries.Clear(); 142 lastSession = DateTime.MinValue; 143 } 144 } 145 146 /// <summary> 147 /// The last session 148 /// </summary> 149 private DateTime lastSession; 150 } 151 152 public class LogEventArgs : EventArgs 153 { 154 /// <summary> 155 /// Constructor. 156 /// </summary> 157 /// <param name="entry">The log entry that was just logged.</param> 158 public LogEventArgs(LogEntry entry) 159 { 160 LogEntry = entry; 161 } 162 163 /// <summary> 164 /// The log entry that was just logged. 165 /// </summary> 166 public LogEntry LogEntry { get; private set; } 167 } 168 169 public class LogSessionCollection : IDictionary<DateTime, LogEntryCollection> 170 { 171 /// <summary> 172 /// Constructor. 173 /// </summary> 174 /// <param name="logger">The logger object managing the logging.</param> 175 public LogSessionCollection(Logger logger) 176 { 177 owner = logger; 178 } 179 180 public void NewSession() 181 { 182 Add(DateTime.Now, new LogEntryCollection(owner)); 183 } 184 185 #region IDictionary<DateTime,LogSessionEntryCollection> Members 186 public void Add(DateTime key, LogEntryCollection value) 187 { 188 dictionary.Add(key, value); 189 } 190 191 public bool ContainsKey(DateTime key) 192 { 193 return dictionary.ContainsKey(key); 194 } 195 196 public ICollection<DateTime> Keys 197 { 198 get { return dictionary.Keys; } 199 } 200 201 public bool Remove(DateTime key) 202 { 203 return dictionary.Remove(key); 204 } 205 206 public bool TryGetValue(DateTime key, out LogEntryCollection value) 207 { 208 return dictionary.TryGetValue(key, out value); 209 } 210 211 public ICollection<LogEntryCollection> Values 212 { 213 get { return dictionary.Values; } 214 } 215 216 public LogEntryCollection this[DateTime key] 127 217 { 128 218 get 129 219 { 130 lock (entries) 131 return entries[lastSession]; 132 } 133 } 134 135 /// <summary> 136 /// Adds a new session to the log. 137 /// </summary> 138 internal void NewSession() 139 { 140 lock (entries) 141 { 142 lastSession = DateTime.Now; 143 entries.Add(lastSession, new List<LogEntry>()); 144 } 145 146 if (OnNewSession != null) 147 OnNewSession(this, new EventArgs()); 148 } 149 150 /// <summary> 151 /// Logs the message and its associated information into the current session. 152 /// </summary> 153 /// <param name="entry">The log entry structure representing the log 154 /// message.</param> 155 internal void Add(LogEntry entry) 156 { 157 lock (entries) 158 { 159 if (entries.Count == 0) 160 NewSession(); 161 entries[lastSession].Add(entry); 162 } 163 164 if (OnLogged != null) 165 OnLogged(entry); 166 } 167 168 /// <summary> 169 /// Clears the log entries from the log. 170 /// </summary> 220 return dictionary[key]; 221 } 222 set 223 { 224 dictionary[key] = value; 225 } 226 } 227 #endregion 228 229 #region ICollection<KeyValuePair<DateTime,LogSessionEntryCollection>> Members 230 public void Add(KeyValuePair<DateTime, LogEntryCollection> item) 231 { 232 Add(item.Key, item.Value); 233 } 234 171 235 public void Clear() 172 236 { 173 lock (entries) 174 { 175 entries.Clear(); 176 lastSession = DateTime.MinValue; 177 } 178 } 179 180 /// <summary> 181 /// The log entries. 182 /// </summary> 183 private Dictionary<DateTime, List<LogEntry>> entries; 184 185 /// <summary> 186 /// The last session 187 /// </summary> 188 private DateTime lastSession; 237 dictionary.Clear(); 238 } 239 240 public bool Contains(KeyValuePair<DateTime, LogEntryCollection> item) 241 { 242 return dictionary.ContainsKey(item.Key) && dictionary[item.Key] == item.Value; 243 } 244 245 public void CopyTo(KeyValuePair<DateTime, LogEntryCollection>[] array, int arrayIndex) 246 { 247 throw new NotImplementedException(); 248 } 249 250 public int Count 251 { 252 get { return dictionary.Count; } 253 } 254 255 public bool IsReadOnly 256 { 257 get { return false; } 258 } 259 260 public bool Remove(KeyValuePair<DateTime, LogEntryCollection> item) 261 { 262 return dictionary.Remove(item.Key); 263 } 264 #endregion 265 266 #region IEnumerable<KeyValuePair<DateTime,LogSessionEntryCollection>> Members 267 public IEnumerator<KeyValuePair<DateTime, LogEntryCollection>> GetEnumerator() 268 { 269 return dictionary.GetEnumerator(); 270 } 271 #endregion 272 273 #region IEnumerable Members 274 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 275 { 276 return GetEnumerator(); 277 } 278 #endregion 279 280 /// <summary> 281 /// The log manager. 282 /// </summary> 283 private Logger owner; 284 285 /// <summary> 286 /// The store for this object. 287 /// </summary> 288 private Dictionary<DateTime, LogEntryCollection> dictionary = 289 new Dictionary<DateTime, LogEntryCollection>(); 290 } 291 292 public class LogEntryCollection : IList<LogEntry> 293 { 294 /// <summary> 295 /// Constructor. 296 /// </summary> 297 /// <param name="logger">The <see cref="Logger"/> object handling logging.</param> 298 internal LogEntryCollection(Logger logger) 299 { 300 owner = logger; 301 } 302 303 #region IList<LogEntry> Members 304 public int IndexOf(LogEntry item) 305 { 306 return list.IndexOf(item); 307 } 308 309 public void Insert(int index, LogEntry item) 310 { 311 list.Insert(index, item); 312 owner.OnLogged(owner, new LogEventArgs(item)); 313 } 314 315 public void RemoveAt(int index) 316 { 317 throw new InvalidOperationException(); 318 } 319 320 public LogEntry this[int index] 321 { 322 get 323 { 324 return list[index]; 325 } 326 set 327 { 328 throw new InvalidOperationException(); 329 } 330 } 331 #endregion 332 333 #region ICollection<LogEntry> Members 334 public void Add(LogEntry item) 335 { 336 Insert(Count, item); 337 } 338 339 public void Clear() 340 { 341 throw new InvalidOperationException(); 342 } 343 344 public bool Contains(LogEntry item) 345 { 346 return list.Contains(item); 347 } 348 349 public void CopyTo(LogEntry[] array, int arrayIndex) 350 { 351 list.CopyTo(array, arrayIndex); 352 } 353 354 public int Count 355 { 356 get { return list.Count; } 357 } 358 359 public bool IsReadOnly 360 { 361 get { return false; } 362 } 363 364 public bool Remove(LogEntry item) 365 { 366 return list.Remove(item); 367 } 368 #endregion 369 370 #region IEnumerable<LogEntry> Members 371 public IEnumerator<LogEntry> GetEnumerator() 372 { 373 return list.GetEnumerator(); 374 } 375 #endregion 376 377 #region IEnumerable Members 378 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 379 { 380 return GetEnumerator(); 381 } 382 #endregion 383 384 /// <summary> 385 /// The Logger object managing logging. 386 /// </summary> 387 private Logger owner; 388 389 /// <summary> 390 /// The store for this object. 391 /// </summary> 392 private List<LogEntry> list = new List<LogEntry>(); 189 393 } 190 394 -
branches/eraser6/Manager/Task.cs
r917 r920 429 429 //The system cannot read the file, assume no ADSes for lack of 430 430 //more information. 431 Task.Log. Add(new LogEntry(e.Message, LogLevel.Error));431 Task.Log.LastSessionEntries.Add(new LogEntry(e.Message, LogLevel.Error)); 432 432 } 433 433 } … … 671 671 { 672 672 //Ignore, but log. 673 Task.Log. Add(new LogEntry(S._("Could not erase {0} because {1}",673 Task.Log.LastSessionEntries.Add(new LogEntry(S._("Could not erase {0} because {1}", 674 674 dir.FullName, e.Message), LogLevel.Error)); 675 675 } … … 782 782 catch (UnauthorizedAccessException e) 783 783 { 784 Task.Log. Add(new LogEntry(e.Message, LogLevel.Error));784 Task.Log.LastSessionEntries.Add(new LogEntry(e.Message, LogLevel.Error)); 785 785 } 786 786 }
Note: See TracChangeset
for help on using the changeset viewer.
