コード例 #1
0
        static void Main(string[] args)
        {
            Boolean mounted = false;

            Logger.UsuallyDebugging = false;
            Logger.setLogger(null);
            try
            {
                Logger.getLogger().log(AssemblyHelper.About(System.Reflection.Assembly.GetExecutingAssembly()));
                if (args.Length < 3)
                {
                    Logger.getLogger().log("Usage: ChunkFS <mountpoint> <chunksize> <sourcefile>...");
                    return;
                }
                CFSDriveConfig cfg      = new CFSDriveConfig("CmdLineDrive", args[0], args[1], args, 2);
                ChunkFSDriver  theDrive = new ChunkFSDriver(cfg);
                if (theDrive.Init())
                {
                    Logger.getLogger().log("drive will be mounted now, to unmount hit <CTRL>C");
                    mounted = true;
                    theDrive.exec();
                }
                else
                {
                    Logger.getLogger().log("Init() failed, drive not mounted");
                }
            }
            catch (Exception ex)
            {
                mounted = false;
                Logger.getLogger().log("failed, exception:" + ex.Message + ex.StackTrace);
            }
            finally
            {
                if (mounted)
                {
                    Logger.getLogger().log("drive unmounted");
                }
            }
        }
コード例 #2
0
 static void Main(string[] args)
 {
     Boolean mounted = false;
     Logger.UsuallyDebugging = false;
     Logger.setLogger(null);
     try
     {
         Logger.getLogger().log(AssemblyHelper.About(System.Reflection.Assembly.GetExecutingAssembly()));
         if (args.Length < 3)
         {
             Logger.getLogger().log("Usage: ChunkFS <mountpoint> <chunksize> <sourcefile>...");
             return;
         }
         CFSDriveConfig cfg = new CFSDriveConfig("CmdLineDrive", args[0], args[1], args, 2);
         ChunkFSDriver theDrive = new ChunkFSDriver(cfg);
         if (theDrive.Init())
         {
             Logger.getLogger().log("drive will be mounted now, to unmount hit <CTRL>C");
             mounted = true;
             theDrive.exec();
         }
         else
         {
             Logger.getLogger().log("Init() failed, drive not mounted");
         }
     }
     catch (Exception ex)
     {
         mounted = false;
         Logger.getLogger().log("failed, exception:" + ex.Message + ex.StackTrace);
     }
     finally
     {
         if (mounted)
             Logger.getLogger().log("drive unmounted");
     }
 }
コード例 #3
0
 public static void MyClassInitialize(TestContext testContext)
 {
     CFSDriveConfig config = new CFSDriveConfig("test", args[0], args[1], args, 2);
     target = new ChunkFSDriver(config);
     //bool ok = target.Init(args[1], args[2]);
     bool ok = target.Init();
 }
コード例 #4
0
        public void ReadFileTest2()
        {
            bool remember = Logger.UsuallyDebugging;
            Logger.UsuallyDebugging = true;
            Logger.setLogger(null);
            int kperchunk = 640;
            string infn = TestDataHelper.locateTestText();
            string mount = "k:\\";
            string csize = "640K";
            string[] files = { mount, csize, infn };
            CFSDriveConfig cfg = new CFSDriveConfig(null, mount, csize, files, 2);
            ChunkFSDriver cfs = new ChunkFSDriver(cfg);
            cfs.Init();
            Assert.IsTrue(cfs.Count() > 0);

            uint readBytes = 64 * 1024;
            uint readBytesExpected = readBytes;
            byte[] buffer = new byte[readBytes];

            string filename = infn.Substring(infn.LastIndexOf("\\") + 1);
            FileInfo fi = new FileInfo(infn);
            long actualsize = fi.Length;
            string outDir = fi.DirectoryName + "\\out\\";
            int bytesperchunk = kperchunk * 1024;
            int chunksExpected = (int)((actualsize + (long)bytesperchunk - 1L) / (long)bytesperchunk);

            long offset = 0;
            DokanFileInfo info = new DokanFileInfo(0);
            FileInformation finf = new FileInformation();
            int ok;

            for (int i = 0; i < chunksExpected; i++)
            {
                // get file info and note the size
                string uniq = fi.LastWriteTime.ToString("yyyyMMddHHmm", CultureInfo.InvariantCulture);
                string currfn = filename + "." + uniq + "." + (i + 1) + "." + chunksExpected;
                ok = cfs.GetFileInformation(currfn, finf, info);
                long currcs = finf.Length;

                // open the file, create an output file
                ok = cfs.CreateFile(currfn, FileAccess.Read, FileShare.Read, FileMode.Open, FileOptions.None, info);
                FileStream ofs = new FileStream(outDir + currfn, FileMode.Create, FileAccess.Write);

                // read all the bytes and write to output
                offset = 0;
                do
                {
                    ok = cfs.ReadFile(currfn, buffer, ref readBytes, offset, info);
                    ofs.Write(buffer, 0, (int)readBytes);
                    offset += readBytes;
                } while (offset + 1 < currcs);

                // close the input and output
                ok = cfs.Cleanup(currfn, info);
                ok = cfs.CloseFile(currfn, info);
                string ofn = ofs.Name;
                ofs.Close();
                new FileInfo(ofn).LastWriteTime = finf.LastWriteTime;
            }
            // now you can compare the files TODO

            //int expected = 0;
            //int actual;
            //actual = cfs.ReadFile(filename, buffer, ref readBytes, offset, info);
            //Assert.AreEqual(readBytesExpected, readBytes);
            //Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
            Logger.UsuallyDebugging = remember;
            Logger.setLogger(null);
        }
コード例 #5
0
 public void InitTest()
 {
     CFSDriveConfig config = new CFSDriveConfig("test", args[0], args[1], args, 2);
     //bool ok = target.Init(args[1], args[2]);
     ChunkFSDriver target = new ChunkFSDriver(config);
     bool ok = target.Init();
     Assert.IsTrue(ok);
 }
コード例 #6
0
 private void pbMount_Click(object sender, EventArgs e)
 {
     try
     {
         int ix = this.dgConfigs.CurrentCell.RowIndex;
         CFSDriveConfig dc = this.myDrives[ix];
         if (!dc.isValid())
         {
             MessageBox.Show(this, "Drive config is not valid", "Error", MessageBoxButtons.OK);
             return;
         }
         ChunkFSDriver theDrive = new ChunkFSDriver(dc);
         if (theDrive.Init())
         {
             //MessageBox.Show("drive will be mounted now, to unmount hit <CTRL>C");
             Thread t = new Thread(new ThreadStart(theDrive.exec2));
             t.Start();
             dc.Mounted = true;
             dc.RunningDriver = theDrive;
             myDrives.ResetBindings();
             manageGuiState(dc);
         }
         else
         {
             MessageBox.Show("Init() failed, drive not mounted");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, ex.Message + ex.StackTrace, "Mount Failed", MessageBoxButtons.OK);
     }
     finally
     {
         //manageGuiState();
     }
 }