コード例 #1
0
 /// <summary>Simulates a crash of OS or machine by overwriting
 /// unsynced files.
 /// </summary>
 public virtual void  Crash()
 {
     lock (this)
     {
         crashed   = true;
         openFiles = new System.Collections.Hashtable();
         System.Collections.IEnumerator it = unSyncedFiles.GetEnumerator();
         unSyncedFiles = new System.Collections.Hashtable();
         int count = 0;
         while (it.MoveNext())
         {
             System.String name = (System.String)((System.Collections.DictionaryEntry)it.Current).Value;
             RAMFile       file = (RAMFile)fileMap_ForNUnit[name];
             if (count % 3 == 0)
             {
                 DeleteFile(name, true);
             }
             else if (count % 3 == 1)
             {
                 // Zero out file entirely
                 int numBuffers = file.NumBuffers();
                 for (int i = 0; i < numBuffers; i++)
                 {
                     byte[] buffer = file.GetBuffer(i);
                     for (int j = 0; j < buffer.Length; j++)
                     {
                         buffer[j] = (byte)0;
                     }
                 }
             }
             else if (count % 3 == 2)
             {
                 // Truncate the file:
                 file.SetLength(file.GetLength() / 2);
             }
             count++;
         }
     }
 }