コード例 #1
0
        /// <summary>
        ///     Private constructor; its highly recommended to use the static methods and functions of the
        ///     Facade rather than to access the functionality of the handler yourself.
        ///     If you do want to access the FileStorageHandler yourself, use the static method
        ///     CreateFileStorageHandlerInstance that will return the instance for you. Please be aware of
        ///     the handling and de-allocation of the file streams yourself!
        /// </summary>
        private FileStorageHandler(string fileStorageName, VersionBehaviour versionBehaviour)
        {
            FileStorageName = fileStorageName;
            IndexFilename = FilenameFactory.GetFileStorageIndexFilename(fileStorageName);
            DataFilename = FilenameFactory.GetFileStorageDataFilename(fileStorageName);

            if (!File.Exists(IndexFilename))
            {
                throw new FileNotFoundException(string.Format("IndexFilename {0} was not found", IndexFilename));
            }
            if (!File.Exists(DataFilename))
            {
                throw new FileNotFoundException(string.Format("DataFilename {0} was not found", DataFilename));
            }

            LoadDataFileHeader();

            switch (versionBehaviour)
            {
                case VersionBehaviour.ValidateVersion:

                    if (_dataFileHeaderStruct.VersionMajor < VersionMajor)
                    {
                        throw new NotSupportedException(string.Format("Version {2} conflict (file has major version number {0}, the code expects major version {1}). Please upgrade the container using the command tool; filestoragecmd upgrade old new", _dataFileHeaderStruct.VersionMajor, VersionMajor, GetVersion()));
                    }
                    if (_dataFileHeaderStruct.VersionMajor == VersionMajor)
                    {
                        //
                        // check minor number
                        //
                        if (_dataFileHeaderStruct.VersionMinor < VersionMinor)
                        {
                            throw new NotSupportedException(string.Format("Version {2} conflict (file has minor version number {0}, the code expects minor version {1}). Please upgrade the container using the command tool; filestoragecmd upgrade old new", _dataFileHeaderStruct.VersionMinor, VersionMinor, GetVersion()));
                        }
                        if (_dataFileHeaderStruct.VersionMinor == VersionMinor)
                        {
                            //
                            // ok, its supported
                            //
                        }
                        else
                        {
                            //
                            // we cannot be sure if we are compatible, throw an exception
                            //
                            throw new NotSupportedException(string.Format("The storage was built using a more recent version ({0}) and is therefore not supported. Please upgrade your NFileStorage dll's (http://nfilestorage.codeplex.com", GetVersion()));
                        }
                    }
                    else
                    {
                        //
                        // we cannot be sure if we are compatible, throw an exception
                        //
                        throw new NotSupportedException(string.Format("The storage was built using a more recent version ({0}) and is therefore not supported. Please upgrade your NFileStorage dll's (http://nfilestorage.codeplex.com", GetVersion()));
                    }
                    break;
                case VersionBehaviour.BypassVersionCheck:
                    //
                    // no version checking needs to occur nothing to do here
                    // (this is used for example when upgrading a filestorage
                    // to a more recent version)
                    //
                    break;
                default:
                    throw new NotSupportedException(string.Format("Unsupported versionbehaviour {0}", versionBehaviour));
            }
        }
コード例 #2
0
 /// <summary>
 ///     Returns an instance of the FileStorageHandler; use the static methods and functions of the
 ///     Facade to access the 'core' functionality of the handler. Only use the instance if
 ///     you want to control the opening and closing of index and data file streams yourself (for
 ///     performance improvements).
 ///     Its is recommended to use the static methods and functions to prevent leaving file streams
 ///     open.
 /// </summary>
 public static FileStorageHandler Open(string fileStorageName, VersionBehaviour versionBehaviour)
 {
     return new FileStorageHandler(fileStorageName, versionBehaviour);
 }