Esempio n. 1
0
 public StorageSystem(String appDataPath, String localPath, String virtualDirectory, String trainingRunPath, int dummy)
 {
     _appDataPath = appDataPath;
     _storageMode = StorageMode.Local; _directorySeparator = "\\";
     _localPath = localPath;
     _localTrainingRunPath = trainingRunPath;
     _virtualDirectory = virtualDirectory;
 }
Esempio n. 2
0
 protected AbstractDataFile(string filename) {
     UnpackedFilename = filename;
     Mode = StorageMode.UnpackedFile;
     if (filename == null) {
         SourceFilename = null;
     } else {
         SourceFilename = Path.Combine(filename);
         Load();
     }
 }
Esempio n. 3
0
 public StorageSystem(
     String appDataPath,
     String accessKey,
     String secretKey
 )
 {
     _appDataPath = appDataPath;
     _storageMode = StorageMode.S3; _directorySeparator = "/";
     _accessKey = accessKey; _secretKey = secretKey;
 }
Esempio n. 4
0
        protected AbstractDataFile(string carDir, string filename, Acd loadedAcd) {
            UnpackedFilename = filename;

            var acdFile = Path.Combine(carDir, "data.acd");
            if (loadedAcd != null || File.Exists(acdFile)) {
                Mode = StorageMode.AcdFile;
                SourceFilename = acdFile;
            } else {
                Mode = StorageMode.UnpackedFile;
                SourceFilename = Path.Combine(carDir, "data", filename);
            }

            Load(loadedAcd);
        }
Esempio n. 5
0
 /// <summary>
 /// Opens a Storage in this storage.
 /// </summary>
 /// <param name="name">The guid representing the name of the substorage.</param>
 /// <param name="mode">The Storagemode to open the substorage.</param>
 /// <param name="writable">Whether to open the storage as writable.  If
 /// the parent storage is readonly, the substorage cannot be opened
 /// as writable (StorageInvalidOperationException will be thrown).</param>
 /// <returns>The Storage.</returns>
 public Storage OpenStorage(Guid name, StorageMode mode, bool writable)
 {
     bool openWritable = ResolveWritableOverride(writable);
     return new Storage(
         OpenStorage(NameFromGuid(name), mode, openWritable, new SubStorageOpener(this.storage)),
         openWritable
         );
 }
Esempio n. 6
0
 /// <summary>
 /// Opens a Storage in this storage.
 /// </summary>
 /// <param name="name">The guid representing the name of the substorage.</param>
 /// <param name="mode">The Storagemode to open the substorage.</param>
 /// <returns>The Storage.</returns>
 public Storage OpenStorage(Guid name, StorageMode mode)
 {
     return OpenStorage(name, mode, Writable);
 }
Esempio n. 7
0
        /// <summary>
        /// Opens a Storage using the specified opener.
        /// </summary>
        /// <param name="name">The name of the substorage.</param>
        /// <param name="mode">The Storagemode to open the substorage.</param>
        /// <param name="writable">Whether to open the storage as writable.  If
        /// the parent storage is readonly, the substorage cannot be opened
        /// as writable (InvalidoperationException will be thrown).</param>
        /// <param name="opener">The IStorageOpener to use to open the storage.</param>
        /// <param name="created">Out parameter indicated whether the storage was created (or opened)</param>
        /// <returns>The Storage.</returns>
        internal static IStorage OpenStorage(string name, StorageMode mode, bool writable, IStorageOpener opener)
        {
            IStorage storage = null;
            try
            {
                switch (mode)
                {
                    case (StorageMode.Create):
                        opener.CreateStorage(name, out storage);
                        break;

                    case (StorageMode.Open):
                        if (!opener.OpenStorage(name, writable, out storage))
                        {
                            throw new COMException("StorageName does not exist", STG_E.FILENOTFOUND);
                        }
                        break;

                    case (StorageMode.OpenOrCreate):
                        if (!opener.OpenStorage(name, writable, out storage))
                        {
                            opener.CreateStorage(name, out storage);
                        }
                        break;
                }
            }
            catch (COMException e)
            {
                ThrowStorageException(e);
            }
            return storage;
        }
Esempio n. 8
0
 /// <summary>
 /// Constructor for Storage based on a file path
 /// </summary>
 /// <param name="storage">The IStorage from which to construct this storage.</param>
 /// <param name="writable">Whether the storage is writable.</param>
 public Storage(string path, StorageMode mode, bool writable) :
     this(OpenStorage(path, mode, writable, new CompoundFileOpener()), writable)
 {
 }
Esempio n. 9
0
        /// <summary>
        /// Opens an existing root storage object in the file system.
        /// </summary>
        /// <param name="storageFile">The file that contains the storage object to open.</param>
        /// <param name="mode">Specifies the access mode to use to open the storage object.</param>
        /// <returns>The created Storage object.</returns>
        public static Storage Open(string storageFile, StorageMode mode)
        {
            IStorage storage = NativeMethods.StgOpenStorage(storageFile, IntPtr.Zero, (uint)mode, IntPtr.Zero, 0);

            return new Storage(storage);
        }
Esempio n. 10
0
 public bool Supports(StorageMode mode) {
     return mode == StorageMode.Shutdown;
 }
Esempio n. 11
0
 /// <summary>
 /// Opens a Storage in this storage.
 /// </summary>
 /// <param name="name">The string representing the name of the substorage (31 characters or less).</param>
 /// <param name="mode">The Storagemode to open the substorage.</param>
 /// <param name="writable">Whether to open the storage as writable.  If
 /// the parent storage is readonly, the substorage cannot be opened
 /// as writable (StorageInvalidOperationException will be thrown).</param>
 /// <returns>The Storage.</returns>
 public Storage OpenStorage(string name, StorageMode mode, bool writable)
 {
     bool openWritable = ResolveWritableOverride(writable);
     return new Storage(
         OpenStorage(name, mode, openWritable, new SubStorageOpener(this.storage)),
         openWritable
         );
 }
 public static void SetupLargeStreamStorage()
 {
     LargeStreamStorage = new Dictionary<string, LargeStream>();
     ProviderStorageMode = StorageMode.LargeStream;
 }
 public bool Supports(StorageMode mode) {
     return mode == StorageMode.Tombstone;
 }
Esempio n. 14
0
        /// <summary>
        /// Creates a new file entry in the archive using the provided path and data.
        /// </summary>
        /// <param name="path">The path of the entry in the archive.</param>
        /// <param name="data">The data of the entry.</param>
        /// <param name="storageMode">
        /// If storageMode is not StorageMode.Plain, data will be compressed accordingly.
        /// </param>
        /// <exception cref="ArgumentNullException">path or data are <see cref="null"/>.</exception>
        /// <exception cref="ArgumentException">
        /// The specified path is invalid or the specified storage mode is not supported.
        /// </exception>
        /// <returns>The <see cref="ArcEntry"/> instance of the new entry.</returns>
        /// <remarks>Locks the data object.</remarks>
        public ArcEntry CreateEntry(string path, byte[] data, StorageMode storageMode)
        {
            lock (data)
            lock (_lock) {
                    ThrowIfDisposed();
                    ThrowIfReadOnly();

                    if (path == null)
                        throw new ArgumentNullException("Path cannot be null.", "path");

                    if (!PathUtils.EntryAbsolutePathRegex.IsMatch(path))
                        throw new ArgumentException("The specified path is invalid.", "path");

                    if (data == null)
                        throw new ArgumentNullException("Data cannot be null.", "data");

                    if (!Enum.IsDefined(typeof(StorageMode), storageMode))
                        throw new ArgumentException("The specified storage mode is not supported.", "storageMode");

                    byte[] writeData = data;

                    if (storageMode == StorageMode.Lz4Compressed) {
                        writeData = new byte[Lz4.CompressBound(data.Length)];
                        var cSize = Lz4.CompressDefault(data, writeData, data.Length, writeData.Length);
                        Array.Resize(ref writeData, cSize);
                    }

                    _stream.Seek(_header.FooterPointer, SeekOrigin.Begin);

                    var chunk = new ArcStruct.Chunk() {
                        DataPointer = (uint)_stream.Position,
                        CompressedSize = (uint)writeData.Length,
                        PlainSize = (uint)data.Length
                    };

                    _writer.Write(writeData);

                    writeData = null;

                    var entry = new ArcEntry(
                        this,
                        new ArcStruct.Entry() {
                            StorageMode = (uint)storageMode,
                            DataPointer = chunk.DataPointer,
                            CompressedSize = chunk.CompressedSize,
                            PlainSize = chunk.PlainSize,
                            Adler32 = Checksum(data),
                            FileTime = DateTime.Now.ToFileTime()
                            // The other fields will be set by UpdateMeta()
                        },
                        path,
                        new ArcStruct.Chunk[] { chunk }
                    );

                    _entries.Add(entry);

                    UpdateMeta((uint)_stream.Position);

                    return entry;
                }
        }
 /// <summary>
 /// Indicates what storage modes this mechanism provides.
 /// </summary>
 /// <param name="mode">The storage mode to check.</param>
 /// <returns>
 /// Whether or not it is supported.
 /// </returns>
 public bool Supports(StorageMode mode) {
     return (mode & StorageMode.Permanent) == StorageMode.Permanent;
 }
 /// <summary>
 /// Indicates what storage modes this mechanism provides.
 /// </summary>
 /// <param name="mode">The storage mode to check.</param>
 /// <returns>
 /// Whether or not it is supported.
 /// </returns>
 public bool Supports(StorageMode mode) {
     return (mode & StorageMode.Temporary) == StorageMode.Temporary;
 }
Esempio n. 17
0
 /// <summary>
 /// Opens a stream in this storage.
 /// </summary>
 /// <param name="name">The string representing the name of the stream to open.</param>
 /// <param name="mode">The storagemode to use when opening the stream.</param>
 /// <param name="writable">Whether to open the stream as writable.  If
 /// the parent storage is readonly, the stream cannot be opened
 /// as writable (StorageInvalidOperationException will be thrown).</param>
 /// <returns>The stream.</returns>
 public ComStream OpenStream(Guid guid, StorageMode mode, bool writable)
 {
     return OpenStream(NameFromGuid(guid), mode, writable);
 }
Esempio n. 18
0
        /// <summary>
        /// Creates a new compound file storage object.
        /// </summary>
        /// <param name="storageFile">The compound file being created.</param>
        /// <param name="mode">Specifies the access mode to use when opening the new storage object.</param>
        /// <returns>The created Storage object.</returns>
        public static Storage CreateDocFile(string storageFile, StorageMode mode)
        {
            IStorage storage = NativeMethods.StgCreateDocfile(storageFile, (uint)mode, 0);

            return new Storage(storage);
        }
Esempio n. 19
0
 /// <summary>
 /// Opens a stream in this storage.
 /// </summary>
 /// <param name="name">The string representing the name of the stream to open.</param>
 /// <param name="mode">The storagemode to use when opening the stream.</param>
 /// <returns>The stream.</returns>
 public ComStream OpenStream(string name, StorageMode mode)
 {
     return OpenStream(name, mode, Writable);
 }
Esempio n. 20
0
 /// <summary>
 /// Method to get the Session Properties from a loaded session.
 /// </summary>
 protected virtual void GetAllProperties()
 {
     sessionFileName = implementation.SessionFileName;
     resultsRootDirectory = implementation.ResultsRootDirectory;
     definitionRootDirectory =
         implementation.DefinitionManagement.DefinitionFileRootDirectory;
     //descriptionDirectory = implementation.DescriptionDirectory;
     date = implementation.Date;
     sessionTitle = implementation.SessionTitle;
     sessionId = implementation.SessionId;;
     softwareVersions = implementation.SoftwareVersions;
     testedBy = implementation.TestedBy;
     manufacturer = implementation.Manufacturer;
     modelname = implementation.ModelName;
     autoCreateDirectory = implementation.AutoCreateDirectory;
     continueOnError = implementation.ContinueOnError;
     logLevelFlagsMask = (int)implementation.LogLevelFlags;
     storageMode = Convert(implementation.StorageMode);
     dataDirectory = implementation.DataDirectory;
     validateReferencedFile = implementation.ValidateReferencedFile;
     displayConditionText = implementation.DisplayConditionText;
     detailedValidationResults = implementation.DetailedValidationResults;
 }
Esempio n. 21
0
        /// <summary>
        /// Opens a stream in this storage.
        /// </summary>
        /// <param name="name">The guid representing the name of the stream to open.</param>
        /// <param name="mode">The storagemode to use when opening the stream.</param>
        /// <param name="writable">Whether to open the stream as writable.  If
        /// the parent storage is readonly, the stream cannot be opened
        /// as writable (StorageInvalidOperationException will be thrown).</param>
        /// <returns>The stream.</returns>
        public ComStream OpenStream(string name, StorageMode mode, bool writable)
        {
            bool openWritable = ResolveWritableOverride(writable);
            ComStream stream = null;
            try
            {
                switch (mode)
                {
                    case (StorageMode.Create):
                        CreateStream(name, out stream);
                        break;

                    case (StorageMode.Open):
                        OpenStream(name, openWritable, out stream);
                        break;

                    case (StorageMode.OpenOrCreate):
                        try
                        {
                            OpenStream(name, true, out stream);
                        }
                        catch (COMException e)
                        {
                            if (e.ErrorCode == STG_E.FILENOTFOUND)
                                CreateStream(name, out stream);
                            else
                                throw;
                        }
                        break;
                }

            }
            catch (COMException e)
            {
                ThrowStorageException(e);
            }
            return stream;
        }