예제 #1
0
 public override void CloseIO()
 {
     try
     {
         if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
         {
             NeoDatis.Tool.DLogger.Debug("Closing file with size " + fileWriter.Length());
         }
         // Problem found by mayworm : necessary for MacOSX
         if (fileWriter.IsLocked())
         {
             fileWriter.UnlockFile();
         }
         fileWriter.Close();
     }
     catch (System.IO.IOException e)
     {
         NeoDatis.Tool.DLogger.Error(NeoDatis.Tool.Wrappers.OdbString.ExceptionToString(e,
                                                                                        true));
     }
     fileWriter = null;
     if (IsForTransaction() && AutomaticDeleteIsEnabled())
     {
         bool b = NeoDatis.Tool.IOUtil.DeleteFile(wholeFileName);
         if (!b)
         {
             throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.CanNotDeleteFile
                                                        .AddParameter(wholeFileName));
         }
     }
 }
예제 #2
0
 public virtual void TestOdbFileIo()
 {
     NeoDatis.Tool.Wrappers.IO.OdbFileIO fileIO = new NeoDatis.Tool.Wrappers.IO.OdbFileIO
                                                      (NeoDatis.Odb.Test.ODBTest.Directory + "testLock1", true, null);
     fileIO.Seek(1024);
     fileIO.Write((byte)10);
     fileIO.LockFile();
     AssertEquals(true, fileIO.IsLocked());
     fileIO.Close();
 }
예제 #3
0
		/// <summary>Simple lock</summary>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		public virtual void TestOdbFileIo()
		{
			NeoDatis.Tool.Wrappers.IO.OdbFileIO fileIO = new NeoDatis.Tool.Wrappers.IO.OdbFileIO
				(NeoDatis.Odb.Test.ODBTest.Directory + "testLock1", true, null);
			fileIO.Seek(1024);
			fileIO.Write((byte)10);
			fileIO.LockFile();
			AssertEquals(true, fileIO.IsLocked());
			fileIO.Close();
		}
예제 #4
0
        private void Init(string fileName, bool canWrite)
        {
            string dataDirectory = NeoDatis.Tool.Wrappers.OdbSystem.GetProperty("data.directory"
                                                                                );

            if (dataDirectory != null)
            {
                wholeFileName = dataDirectory + "/" + fileName;
            }
            else
            {
                wholeFileName = fileName;
            }
            try
            {
                if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
                {
                    NeoDatis.Tool.DLogger.Info("Opening datatbase file : " + new NeoDatis.Tool.Wrappers.IO.OdbFile
                                                   (wholeFileName).GetFullPath());
                }
                fileWriter = BuildFileWriter(canWrite);
                SetIoDeviceLength(fileWriter.Length());
            }
            catch (System.Exception e)
            {
                //fixme
                new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.InternalError
                                                     , e);
            }
            if (canWrite)
            {
                try
                {
                    fileWriter.LockFile();
                }
                catch (System.Exception)
                {
                    // The file region is already locked
                    throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.OdbFileIsLockedByCurrentVirtualMachine
                                                               .AddParameter(wholeFileName).AddParameter(NeoDatis.Tool.Wrappers.OdbThread.GetCurrentThreadName
                                                                                                             ()).AddParameter(NeoDatis.Odb.OdbConfiguration.IsMultiThread().ToString()));
                }
                if (!fileWriter.IsLocked())
                {
                    throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.OdbFileIsLockedByExternalProgram
                                                               .AddParameter(wholeFileName).AddParameter(NeoDatis.Tool.Wrappers.OdbThread.GetCurrentThreadName
                                                                                                             ()).AddParameter(NeoDatis.Odb.OdbConfiguration.IsMultiThread().ToString()));
                }
            }
        }
		private void Init(string fileName, bool canWrite)
		{
			string dataDirectory = NeoDatis.Tool.Wrappers.OdbSystem.GetProperty("data.directory"
				);
			if (dataDirectory != null)
			{
				wholeFileName = dataDirectory + "/" + fileName;
			}
			else
			{
				wholeFileName = fileName;
			}
			try
			{
				if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
				{
					NeoDatis.Tool.DLogger.Info("Opening datatbase file : " + new NeoDatis.Tool.Wrappers.IO.OdbFile
						(wholeFileName).GetFullPath());
				}
				fileWriter = BuildFileWriter(canWrite);
				SetIoDeviceLength(fileWriter.Length());
			}
			catch (System.Exception e)
			{
				//fixme
				new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.InternalError
					, e);
			}
			if (canWrite)
			{
				try
				{
					fileWriter.LockFile();
				}
				catch (System.Exception)
				{
					// The file region is already locked
					throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.OdbFileIsLockedByCurrentVirtualMachine
						.AddParameter(wholeFileName).AddParameter(NeoDatis.Tool.Wrappers.OdbThread.GetCurrentThreadName
						()).AddParameter(NeoDatis.Odb.OdbConfiguration.IsMultiThread().ToString()));
				}
				if (!fileWriter.IsLocked())
				{
					throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.OdbFileIsLockedByExternalProgram
						.AddParameter(wholeFileName).AddParameter(NeoDatis.Tool.Wrappers.OdbThread.GetCurrentThreadName
						()).AddParameter(NeoDatis.Odb.OdbConfiguration.IsMultiThread().ToString()));
				}
			}
		}
		public override void CloseIO()
		{
			try
			{
				if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
				{
					NeoDatis.Tool.DLogger.Debug("Closing file with size " + fileWriter.Length());
				}
				// Problem found by mayworm : necessary for MacOSX
				if (fileWriter.IsLocked())
				{
					fileWriter.UnlockFile();
				}
				fileWriter.Close();
			}
			catch (System.IO.IOException e)
			{
				NeoDatis.Tool.DLogger.Error(NeoDatis.Tool.Wrappers.OdbString.ExceptionToString(e, 
					true));
			}
			fileWriter = null;
			if (IsForTransaction() && AutomaticDeleteIsEnabled())
			{
				bool b = NeoDatis.Tool.IOUtil.DeleteFile(wholeFileName);
				if (!b)
				{
					throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.CanNotDeleteFile
						.AddParameter(wholeFileName));
				}
			}
		}