Beispiel #1
0
        public override void CreateDatastore(IDatastoreBuilder builder)
        {
            string path       = Path;
            var    isInMemory = IsInMemory;

            if (!isInMemory)
            {
                CreateEmptyFile(path);
            }

            try
            {
                base.CreateDatastore(builder);
            }
            catch
            {
                if (!isInMemory)
                {
                    try
                    {
                        { File.Delete(path); }
                    }
                    catch
                    {
                        // don't stomp on original exception
                    }
                }
                throw;
            }
        }
Beispiel #2
0
        protected void Initialize(bool makeNew, IDatastoreBuilder builder, IUpdater updater)
        {
            var isInMemory = IsInMemory;
            var exists     = Exists;

            if (isInMemory)
            {
                // HACK we need to open a connection when we start using a in memory db
                // and keep it open because our database will die if we close the connection
                OpenConnection();
                if (builder != null)
                {
                    CreateDatastore(builder);
                }
            }
            else if (makeNew)
            {
                if (builder != null)
                {
                    CreateDatastore(builder);
                }
            }
            else if (!makeNew && !exists)
            {
                throw new FileNotFoundException();
            }

            try
            {
                LogMessage("File Opened", "normal");
            }
            catch (FMSC.ORM.ReadOnlyException)
            { /*ignore, in case we want to allow access to a read-only DB*/ }
            catch (FMSC.ORM.SQLException)
            { }

            if (isInMemory == false &&
                makeNew == false)
            {
                // only run updater if db is not in memory and not new
                if (updater != null)
                {
                    updater.Update(this);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates a CruiseDatastore instance for a database @ path.
        /// </summary>
        /// <exception cref="ArgumentNullException">path can not be null or an empty string</exception>
        /// <exception cref="IOException">File extension is not valid</exception>
        /// <exception cref="UnauthorizedAccessException">File open in another application or thread</exception>
        public CruiseDatastore(string path, bool makeNew, IDatastoreBuilder builder, IUpdater updater) : base(path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (path != IN_MEMORY_DB_PATH)
            {
                // I wanted to refactor IsExtentionValid to just take in the extention
                // instead of the full path but V2 uses ExtrapolateCruiseFileType
                // to determin if extention is valid and that method wants the full file name
                if (IsExtentionValid(path) is false)
                {
                    var extension = System.IO.Path.GetExtension(path);
                    throw new IOException($"File extension {extension} is not recognized");
                }
            }


            Path = path;

            Initialize(makeNew, builder, updater);
            Logger.Log($"Created DAL instance. Path = {Path}", LogCategory.Datastore, LogLevel.Info);
        }