Ignore:
Timestamp:
4/28/2009 12:13:51 PM (5 years ago)
Author:
lowjoel
Message:

Ran static code analysis on Manager.

-Do not initialise class members to default values (runtime will handle that)
-Deserialisation constructors should be marked protected for unsealed classes
-Classes implementing ICollection should end with Collection (Mainly fixed here is ErasureTargetsCollection?)
-ISerializable.GetObjectData? should be marked virtual
-Use proper camel casing (Prng, Guid, FileName? etc)
-Enumeration values should be Camel casing
-Bitfields should be marked with the [Flags] attribute
-Implement the proper IDisposable pattern - one Dispose() and one Dispose(bool) - the latter doing the clean ups for both Dispose and finalisers
-public variables should instead be properties
-Abstract classes should have protected constructors
-Renamed Schedule.Type to Schedule.ScheduleType? to prevent ambiguity with GetType?()
-There shouldn't be a need to pass reference variables by reference

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/Manager/DirectExecutor.cs

    r899 r905  
    4646        } 
    4747 
    48         public override void Dispose() 
     48        protected override void Dispose(bool disposing) 
    4949        { 
    5050            thread.Abort(); 
    5151            schedulerInterrupt.Set(); 
     52            schedulerInterrupt.Close(); 
     53            base.Dispose(disposing); 
    5254        } 
    5355 
     
    5860        } 
    5961 
    60         public override void AddTask(ref Task task) 
     62        public override void AddTask(Task task) 
    6163        { 
    6264            lock (unusedIdsLock) 
     
    186188                if (currentTask == task) 
    187189                { 
    188                     currentTask.Cancelled = true; 
     190                    currentTask.Canceled = true; 
    189191                    return; 
    190192                } 
     
    213215        } 
    214216 
    215         public override List<Task> GetTasks() 
     217        public override ICollection<Task> GetTasks() 
    216218        { 
    217219            lock (tasksLock) 
     
    246248                    foreach (uint id in tasks.Keys) 
    247249                    { 
    248                         Task currentTask = tasks[id]; 
    249                         currentTask.Executor = this; 
     250                        Task task = tasks[id]; 
     251                        task.Executor = this; 
    250252                        while (id > nextId) 
    251253                            unusedIds.Add(nextId++); 
     
    253255 
    254256                        //Check if the task is recurring. If it is, check if we missed it. 
    255                         if (currentTask.Schedule is RecurringSchedule) 
    256                             ScheduleTask(currentTask); 
     257                        if (task.Schedule is RecurringSchedule) 
     258                            ScheduleTask(task); 
    257259                    } 
    258260 
     
    301303                        //Broadcast the task started event. 
    302304                        task.Queued = false; 
    303                         task.Cancelled = false; 
     305                        task.Canceled = false; 
    304306                        task.OnTaskStarted(new TaskEventArgs(task)); 
    305307                        OnTaskProcessing(task); 
     
    329331                            catch (Exception e) 
    330332                            { 
    331                                 task.Log.Add(new LogEntry(e.Message, LogLevel.ERROR)); 
     333                                task.Log.Add(new LogEntry(e.Message, LogLevel.Error)); 
    332334                            } 
    333335                    } 
    334336                    catch (FatalException e) 
    335337                    { 
    336                         task.Log.Add(new LogEntry(e.Message, LogLevel.FATAL)); 
     338                        task.Log.Add(new LogEntry(e.Message, LogLevel.Fatal)); 
    337339                    } 
    338340                    catch (Exception e) 
    339341                    { 
    340                         task.Log.Add(new LogEntry(e.Message, LogLevel.ERROR)); 
     342                        task.Log.Add(new LogEntry(e.Message, LogLevel.Error)); 
    341343                    } 
    342344                    finally 
     
    540542                    Environment.OSVersion.Version >= new Version(6, 0)) 
    541543                { 
    542                     throw new Exception(S._("The program does not have the required permissions " + 
    543                         "to erase the unused space on disk. Run the program as an administrator " + 
     544                    throw new UnauthorizedAccessException(S._("The program does not have the required " + 
     545                        "permissions to erase the unused space on disk. Run the program as an administrator " + 
    544546                        "and retry the operation.")); 
    545547                } 
    546548                else 
    547                     throw new Exception(S._("The program does not have the required permissions " + 
     549                    throw new UnauthorizedAccessException(S._("The program does not have the required permissions " + 
    548550                        "to erase the unused space on disk")); 
    549551            } 
     
    553555                task.Log.Add(new LogEntry(S._("The drive which is having its unused space erased " + 
    554556                    "has disk quotas active. This will prevent the complete erasure of unused " + 
    555                     "space and will pose a security concern"), LogLevel.WARNING)); 
     557                    "space and will pose a security concern"), LogLevel.Warning)); 
    556558 
    557559            //Get the erasure method if the user specified he wants the default. 
     
    581583 
    582584                        lock (currentTask) 
    583                             if (currentTask.Cancelled) 
     585                            if (currentTask.Canceled) 
    584586                                throw new FatalException(S._("The task was cancelled.")); 
    585587                    } 
     
    599601                if (Eraser.Util.File.IsCompressed(info.FullName)) 
    600602                    Eraser.Util.File.SetCompression(info.FullName, false); 
    601  
    602                 //Determine the total amount of data that needs to be written. 
    603                 long totalSize = method.CalculateEraseDataSize(null, volInfo.TotalFreeSpace); 
    604603 
    605604                //Continue creating files while there is free space. 
     
    638637                        //Then run the erase task 
    639638                        method.Erase(stream, long.MaxValue, 
    640                             PRNGManager.GetInstance(ManagerLibrary.Instance.Settings.ActivePRNG), 
     639                            PrngManager.GetInstance(ManagerLibrary.Instance.Settings.ActivePrng), 
    641640                            delegate(long lastWritten, int currentPass) 
    642641                            { 
     
    654653 
    655654                                lock (currentTask) 
    656                                     if (currentTask.Cancelled) 
     655                                    if (currentTask.Canceled) 
    657656                                        throw new FatalException(S._("The task was cancelled.")); 
    658657                            } 
     
    664663                progress.Event.CurrentItemName = S._("Old resident file system table files"); 
    665664                task.OnProgressChanged(progress.Event); 
    666                 fsManager.EraseOldFilesystemResidentFiles(volInfo, method, null); 
     665                fsManager.EraseOldFileSystemResidentFiles(volInfo, method, null); 
    667666            } 
    668667            finally 
     
    682681                { 
    683682                    lock (currentTask) 
    684                         if (currentTask.Cancelled) 
     683                        if (currentTask.Canceled) 
    685684                            throw new FatalException(S._("The task was cancelled.")); 
    686685 
     
    713712            { 
    714713                //Check if we've been cancelled 
    715                 if (task.Cancelled) 
     714                if (task.Canceled) 
    716715                    throw new FatalException(S._("The task was cancelled.")); 
    717716 
     
    723722                        task.Log.Add(new LogEntry(S._("Files in {0} did not have their cluster " + 
    724723                            "tips erased because it is a hard link or a symbolic link.", 
    725                             info.FullName), LogLevel.INFORMATION)); 
     724                            info.FullName), LogLevel.Information)); 
    726725                        return; 
    727726                    } 
     
    731730                            task.Log.Add(new LogEntry(S._("{0} did not have its cluster tips " + 
    732731                                "erased, because it is a system file", file.FullName), 
    733                                 LogLevel.INFORMATION)); 
     732                                LogLevel.Information)); 
    734733                        else if ((file.Attributes & FileAttributes.ReparsePoint) != 0) 
    735734                            task.Log.Add(new LogEntry(S._("{0} did not have its cluster tips " + 
    736735                                "erased because it is a hard link or a symbolic link.", 
    737                                 file.FullName), LogLevel.INFORMATION)); 
     736                                file.FullName), LogLevel.Information)); 
    738737                        else if ((file.Attributes & FileAttributes.Compressed) != 0 || 
    739738                            (file.Attributes & FileAttributes.Encrypted) != 0 || 
     
    742741                            task.Log.Add(new LogEntry(S._("{0} did not have its cluster tips " + 
    743742                                "erased because it is compressed, encrypted or a sparse file.", 
    744                                 file.FullName), LogLevel.INFORMATION)); 
     743                                file.FullName), LogLevel.Information)); 
    745744                        } 
    746745                        else 
     
    757756                                task.Log.Add(new LogEntry(S._("{0} did not have its cluster tips erased " + 
    758757                                    "because of the following error: {1}", info.FullName, e.Message), 
    759                                     LogLevel.ERROR)); 
     758                                    LogLevel.Error)); 
    760759                            } 
    761760                        } 
     
    768767                    task.Log.Add(new LogEntry(S._("{0} did not have its cluster tips erased " + 
    769768                        "because of the following error: {1}", info.FullName, e.Message), 
    770                         LogLevel.ERROR)); 
     769                        LogLevel.Error)); 
    771770                } 
    772771                catch (IOException e) 
     
    774773                    task.Log.Add(new LogEntry(S._("{0} did not have its cluster tips erased " + 
    775774                        "because of the following error: {1}", info.FullName, e.Message), 
    776                         LogLevel.ERROR)); 
     775                        LogLevel.Error)); 
    777776                } 
    778777            }; 
     
    796795                { 
    797796                    task.Log.Add(new LogEntry(S._("{0} did not have its cluster tips erased. " + 
    798                         "The error returned was: {1}", files[i], e.Message), LogLevel.ERROR)); 
     797                        "The error returned was: {1}", files[i], e.Message), LogLevel.Error)); 
    799798                } 
    800799                finally 
     
    841840 
    842841                    //Erase the file 
    843                     method.Erase(stream, long.MaxValue, PRNGManager.GetInstance( 
    844                         ManagerLibrary.Instance.Settings.ActivePRNG), null); 
     842                    method.Erase(stream, long.MaxValue, PrngManager.GetInstance( 
     843                        ManagerLibrary.Instance.Settings.ActivePrng), null); 
    845844                } 
    846845                finally 
     
    913912                        task.Log.Add(new LogEntry(S._("The file {0} could not be erased " + 
    914913                            "because the file was either compressed, encrypted or a sparse file.", 
    915                             info.FullName), LogLevel.ERROR)); 
     914                            info.FullName), LogLevel.Error)); 
    916915                    } 
    917916 
     
    932931                                 itemTotal = method.CalculateEraseDataSize(null, strm.Length); 
    933932                            method.Erase(strm, long.MaxValue, 
    934                                 PRNGManager.GetInstance(ManagerLibrary.Instance.Settings.ActivePRNG), 
     933                                PrngManager.GetInstance(ManagerLibrary.Instance.Settings.ActivePrng), 
    935934                                delegate(long lastWritten, int currentPass) 
    936935                                { 
     
    947946 
    948947                                    lock (currentTask) 
    949                                         if (currentTask.Cancelled) 
     948                                        if (currentTask.Canceled) 
    950949                                            throw new FatalException(S._("The task was cancelled.")); 
    951950                                } 
     
    967966                    task.Log.Add(new LogEntry(S._("The file {0} could not be erased because the " + 
    968967                        "file's permissions prevent access to the file.", info.FullName), 
    969                         LogLevel.ERROR)); 
     968                        LogLevel.Error)); 
    970969                } 
    971970                catch (FileLoadException) 
    972971                { 
    973972                    task.Log.Add(new LogEntry(S._("The file {0} could not be erased because the " + 
    974                         "file is currently in use.", info.FullName), LogLevel.ERROR)); 
     973                        "file is currently in use.", info.FullName), LogLevel.Error)); 
    975974                } 
    976975                finally 
     
    10661065        /// is required by no unused IDs remain. 
    10671066        /// </summary> 
    1068         private uint nextId = 0; 
     1067        private uint nextId; 
    10691068 
    10701069        /// <summary> 
Note: See TracChangeset for help on using the changeset viewer.