Example #1
0
 protected virtual int DatabaseFileSize()
 {
     var localContainer = Fixture().FileSession();
     localContainer.SyncFiles();
     var length = new File(localContainer.FileName()).Length();
     return (int) length;
 }
		/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
		protected RandomAccessFileAdapter(string path, bool lockFile, long initialLength, 
			bool readOnly)
		{
			bool ok = false;
			try
			{
				_path = new Sharpen.IO.File(path).GetCanonicalPath();
				_delegate = RandomAccessFileFactory.NewRandomAccessFile(_path, readOnly, lockFile
					);
				if (initialLength > 0)
				{
					_delegate.Seek(initialLength - 1);
					_delegate.Write(new byte[] { 0 });
				}
				ok = true;
			}
			catch (IOException e)
			{
				throw new Db4oIOException(e);
			}
			finally
			{
				if (!ok)
				{
					Close();
				}
			}
		}
Example #3
0
			/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
			public FileBin(BinConfiguration config)
			{
				bool ok = false;
				try
				{
					_path = new Sharpen.IO.File(config.Uri()).GetCanonicalPath();
					_file = RandomAccessFileFactory.NewRandomAccessFile(_path, config.ReadOnly(), config
						.LockFile());
					if (config.InitialLength() > 0)
					{
						Write(config.InitialLength() - 1, new byte[] { 0 }, 1);
					}
					ok = true;
				}
				catch (IOException e)
				{
					throw new Db4oIOException(e);
				}
				finally
				{
					if (!ok)
					{
						Close();
					}
				}
			}
Example #4
0
        private string CheckExt(Sharpen.IO.File file)
        {
            string name = file.GetName();
            int    pos  = name.LastIndexOf(".");

            if (pos > 0)
            {
                i_ext = Sharpen.Runtime.Substring(name, pos);
                return(Sharpen.Runtime.Substring(name, 0, pos));
            }
            i_ext = string.Empty;
            return(name);
        }
 private void Prepare()
 {
     var file = new File(TempFile());
     if (file.Exists())
     {
         file.Delete();
     }
     var testDB = OpenDB();
     var item = new Item("richard"
         , 100);
     testDB.Store(item);
     testDB.Close();
 }
Example #6
0
        private string CheckExt(File file)
        {
            var name = file.GetName();
            var pos  = name.LastIndexOf(".");

            if (pos > 0)
            {
                i_ext = Runtime.Substring(name, pos);
                return(Runtime.Substring(name, 0, pos));
            }
            i_ext = string.Empty;
            return(name);
        }
Example #7
0
 /// <exception cref="System.IO.IOException"></exception>
 public virtual void WriteTo(File file)
 {
     if (GetStatus() == Status.Unused)
     {
         throw new IOException(Messages.Get(43));
     }
     if (i_stream.IsClient)
     {
         i_file   = file;
         i_status = Status.Queued;
         ((IBlobTransport)i_stream).WriteBlobTo(i_trans, this);
     }
     else
     {
         WriteLocal(file);
     }
 }
Example #8
0
		public Db4oDrsFixture(string name, IReflector reflector)
		{
			_name = name;
			File folder = new File(Path);
			if (!folder.Exists())
			{
				Sharpen.Runtime.Out.WriteLine("Path " + Path + " does not exist. Using current working folder."
					);
				Sharpen.Runtime.Out.WriteLine("Check the " + RamDriveProperty + " environment variable on your system."
					);
				folder = new File(".");
			}
			testFile = new File(folder.GetPath() + "/drs_cs_" + _name + ".db4o");
			if (reflector != null)
			{
				Config().ReflectWith(reflector);
			}
		}
Example #9
0
 /// <exception cref="System.IO.IOException"></exception>
 public virtual void ReadFrom(File file)
 {
     if (!file.Exists())
     {
         throw new IOException(Messages.Get(41, file.GetAbsolutePath
                                                ()));
     }
     i_length = (int)file.Length();
     CheckExt(file);
     if (i_stream.IsClient)
     {
         i_file = file;
         ((IBlobTransport)i_stream).ReadBlobFrom(i_trans, this);
     }
     else
     {
         ReadLocal(file);
     }
 }
Example #10
0
 /// <exception cref="System.IO.IOException"></exception>
 public virtual void ReadFrom(File file)
 {
     if (!file.Exists())
     {
         throw new IOException(Messages.Get(41, file.GetAbsolutePath
             ()));
     }
     i_length = (int) file.Length();
     CheckExt(file);
     if (i_stream.IsClient)
     {
         i_file = file;
         ((IBlobTransport) i_stream).ReadBlobFrom(i_trans, this);
     }
     else
     {
         ReadLocal(file);
     }
 }
Example #11
0
 public virtual void ProcessAtServer()
 {
     try
     {
         BlobImpl blobImpl = this.ServerGetBlobImpl();
         if (blobImpl != null)
         {
             blobImpl.SetTrans(Transaction());
             Sharpen.IO.File file = blobImpl.ServerFile(null, true);
             Socket4Adapter  sock = ServerMessageDispatcher().Socket();
             Msg.Ok.Write(sock);
             FileOutputStream fout = new FileOutputStream(file);
             Copy(sock, fout, blobImpl.GetLength(), false);
             Msg.Ok.Write(sock);
         }
     }
     catch (Exception)
     {
     }
 }
Example #12
0
		public virtual void Run(string logFilePath, string statisticsFilePath)
		{
			_logFilePath = logFilePath;
			_statisticsFilePath = statisticsFilePath;
			try
			{
				OpenFiles();
				_logFileName = new Sharpen.IO.File(_logFilePath).GetName();
				Sharpen.Runtime.Out.Write("  Creating statistics for " + _logFileName + "  ...   "
					);
				long start = Runtime.CurrentTimeMillis();
				CreateStatistics();
				long elapsed = Runtime.CurrentTimeMillis() - start;
				string elapsedString = FormatTime(elapsed);
				Sharpen.Runtime.Out.WriteLine("Finished! Time taken: " + elapsedString);
			}
			catch (FileNotFoundException e)
			{
				Sharpen.Runtime.PrintStackTrace(e);
			}
			CloseFiles();
		}
Example #13
0
		public virtual void Run(string logDirectoryPath)
		{
			Sharpen.IO.File directory = new Sharpen.IO.File(logDirectoryPath);
			if (directory.IsDirectory())
			{
				Sharpen.Runtime.Out.WriteLine("[BATCH] Creating statistics for logs in " + logDirectoryPath
					);
				IFilenameFilter logFilter = new LogFilter();
				Sharpen.IO.File[] logFiles = directory.ListFiles(logFilter);
				int i;
				for (i = 0; i < logFiles.Length; i++)
				{
					new LogStatistics().Run(logFiles[i].GetPath());
				}
				Sharpen.Runtime.Out.WriteLine("[BATCH] Statistics for " + i + " log files have been created!"
					);
			}
			else
			{
				Sharpen.Runtime.Out.WriteLine("[BATCH] Given path is no directory!");
				Sharpen.Runtime.Out.WriteLine("[BATCH] Path: " + logDirectoryPath);
			}
		}
Example #14
0
 public virtual void ProcessAtServer()
 {
     try
     {
         BlobImpl blobImpl = this.ServerGetBlobImpl();
         if (blobImpl != null)
         {
             blobImpl.SetTrans(Transaction());
             Sharpen.IO.File file   = blobImpl.ServerFile(null, false);
             int             length = (int)file.Length();
             Socket4Adapter  sock   = ServerMessageDispatcher().Socket();
             Msg.Length.GetWriterForInt(Transaction(), length).Write(sock);
             FileInputStream fin = new FileInputStream(file);
             Copy(fin, sock, false);
             sock.Flush();
             Msg.Ok.Write(sock);
         }
     }
     catch (Exception)
     {
         Write(Msg.Error);
     }
 }
Example #15
0
 public virtual void Run(string logDirectoryPath)
 {
     Sharpen.IO.File directory = new Sharpen.IO.File(logDirectoryPath);
     if (directory.IsDirectory())
     {
         Sharpen.Runtime.Out.WriteLine("[BATCH] Creating statistics for logs in " + logDirectoryPath
                                       );
         IFilenameFilter   logFilter = new LogFilter();
         Sharpen.IO.File[] logFiles  = directory.ListFiles(logFilter);
         int i;
         for (i = 0; i < logFiles.Length; i++)
         {
             new LogStatistics().Run(logFiles[i].GetPath());
         }
         Sharpen.Runtime.Out.WriteLine("[BATCH] Statistics for " + i + " log files have been created!"
                                       );
     }
     else
     {
         Sharpen.Runtime.Out.WriteLine("[BATCH] Given path is no directory!");
         Sharpen.Runtime.Out.WriteLine("[BATCH] Path: " + logDirectoryPath);
     }
 }
Example #16
0
        /// <exception cref="System.IO.IOException"></exception>
        public virtual void ReadLocal(File file)
        {
            var copied = false;

            if (fileName == null)
            {
                var newFile = new File(ServerPath(), file.GetName());
                if (!newFile.Exists())
                {
                    Copy(file, newFile);
                    copied   = true;
                    fileName = newFile.GetName();
                }
            }
            if (!copied)
            {
                Copy(file, ServerFile(CheckExt(file), true));
            }
            lock (i_stream.Lock())
            {
                i_stream.StoreInternal(i_trans, this, false);
            }
            i_status = Status.Completed;
        }
Example #17
0
 public Db4oNetworking(IClientServerFactory csFactory, string label)
 {
     _csFactory = csFactory != null ? csFactory : DefaultClientServerFactory();
     _file = new File(FilePath());
     _label = label;
 }
Example #18
0
 /// <exception cref="System.IO.IOException"></exception>
 private static void Copy(File from, File to)
 {
     System.IO.File.Copy(from, to);
 }
Example #19
0
 public override bool Exists(string path)
 {
     var existingFile = new File(path);
     return existingFile.Exists() && existingFile.Length() > 0;
 }
Example #20
0
        public override bool Exists(string path)
        {
            var existingFile = new File(path);

            return(existingFile.Exists() && existingFile.Length() > 0);
        }
 public Db4oLibraryEnvironmentProvider(File classPath)
 {
     _classPath = classPath;
 }
Example #22
0
 /// <summary>returns true if the specified file system path already exists.</summary>
 /// <remarks>returns true if the specified file system path already exists.</remarks>
 public virtual bool Exists(string uri)
 {
     Sharpen.IO.File file = new Sharpen.IO.File(uri);
     return(file.Exists() && file.Length() > 0);
 }
		public override bool Exists(string path)
		{
			Sharpen.IO.File existingFile = new Sharpen.IO.File(path);
			return existingFile.Exists() && existingFile.Length() > 0;
		}
Example #24
0
 /// <exception cref="System.IO.IOException"></exception>
 private static void Copy(Sharpen.IO.File from, Sharpen.IO.File to)
 {
     System.IO.File.Copy(from, to);
 }
Example #25
0
 /// <exception cref="System.IO.IOException"></exception>
 public virtual void WriteTo(File file)
 {
     if (GetStatus() == Status.Unused)
     {
         throw new IOException(Messages.Get(43));
     }
     if (i_stream.IsClient)
     {
         i_file = file;
         i_status = Status.Queued;
         ((IBlobTransport) i_stream).WriteBlobTo(i_trans, this);
     }
     else
     {
         WriteLocal(file);
     }
 }
 public override bool Exists(string path)
 {
     Sharpen.IO.File existingFile = new Sharpen.IO.File(path);
     return(existingFile.Exists() && existingFile.Length() > 0);
 }
Example #27
0
 private string CheckExt(File file)
 {
     var name = file.GetName();
     var pos = name.LastIndexOf(".");
     if (pos > 0)
     {
         i_ext = Runtime.Substring(name, pos);
         return Runtime.Substring(name, 0, pos);
     }
     i_ext = string.Empty;
     return name;
 }
Example #28
0
		/// <summary>returns true if the specified file system path already exists.</summary>
		/// <remarks>returns true if the specified file system path already exists.</remarks>
		public virtual bool Exists(string uri)
		{
			Sharpen.IO.File file = new Sharpen.IO.File(uri);
			return file.Exists() && file.Length() > 0;
		}
Example #29
0
 /// <exception cref="System.IO.IOException"></exception>
 private static void Copy(File from, File to)
 {
     System.IO.File.Copy(from, to);
 }
Example #30
0
 public virtual bool Accept(Sharpen.IO.File dir, string name)
 {
     return(name.ToLower().EndsWith(".log"));
 }
Example #31
0
        /// <summary>returns true if the specified file system path already exists.</summary>
        /// <remarks>returns true if the specified file system path already exists.</remarks>
        public virtual bool Exists(string uri)
        {
            var file = new File(uri);

            return(file.Exists() && file.Length() > 0);
        }
Example #32
0
 /// <exception cref="System.IO.IOException"></exception>
 public virtual void WriteLocal(File file)
 {
     Copy(ServerFile(null, false), file);
     i_status = Status.Completed;
 }
Example #33
0
 /// <summary>returns true if the specified file system path already exists.</summary>
 /// <remarks>returns true if the specified file system path already exists.</remarks>
 public virtual bool Exists(string uri)
 {
     var file = new File(uri);
     return file.Exists() && file.Length() > 0;
 }
Example #34
0
 /// <exception cref="System.IO.IOException"></exception>
 public virtual void WriteLocal(File file)
 {
     Copy(ServerFile(null, false), file);
     i_status = Status.Completed;
 }
 public AbstractFileBasedDb4oFixture()
 {
     var fileName = FileName();
     _databaseFile = new File(CrossPlatformServices.DatabasePath(fileName));
 }
Example #36
0
 /// <exception cref="System.IO.IOException"></exception>
 public virtual void ReadLocal(File file)
 {
     var copied = false;
     if (fileName == null)
     {
         var newFile = new File(ServerPath(), file.GetName());
         if (!newFile.Exists())
         {
             Copy(file, newFile);
             copied = true;
             fileName = newFile.GetName();
         }
     }
     if (!copied)
     {
         Copy(file, ServerFile(CheckExt(file), true));
     }
     lock (i_stream.Lock())
     {
         i_stream.StoreInternal(i_trans, this, false);
     }
     i_status = Status.Completed;
 }