/// <summary> /// Constructor for Uri class. /// </summary> /// <param name="uri">The protocol and filepath of the uri.</param> public TStoreUri(string uri) { _rawUri = uri; if (_rawUri.StartsWith("records:") || _rawUri.StartsWith("recs:")) { int colon = _rawUri.IndexOf(':'); _filePath = _rawUri.Substring(colon+1); _storageType = TStorageType.RecordFile; } else if (_rawUri.StartsWith("store:") || _rawUri.StartsWith("tstore:")) { int colon = _rawUri.IndexOf(':'); _filePath = _rawUri.Substring(colon+1); _storageType = TStorageType.TStore; } else if (_rawUri.StartsWith("dir:") || _rawUri.StartsWith("directory:")) { int colon = _rawUri.IndexOf(':'); _filePath = _rawUri.Substring(colon+1); _storageType = TStorageType.Directory; } else { _filePath = _rawUri; // it may be that the user just forgot to put the proper leading protocol // try to figure out if this is the case so they don't have to. // if this is a directory then the input is either a Directory or TStore. if (Directory.Exists(_rawUri)) { if (File.Exists(Path.Combine(_rawUri, "keys-data"))) { // this is a cheat _storageType = TStorageType.TStore; } else _storageType = TStorageType.Directory; } // directory doesn't exist else if (File.Exists(_rawUri)) { EmptyInternalSource source = new EmptyInternalSource(); //FileStream fs = new FileStream(RawUri, FileMode.Open); //FileStream fs = new FileStream(RawUri, FileMode.Open, FileAccess.Read, FileShare.Read); Stream fs = ZStreamIn.Open(_rawUri); // so we can read gz files bool flatFile = false; try { // try reading the properties of a recordsFile. source.ReadProperties(fs); } catch { flatFile = true; } fs.Close(); if (flatFile) _storageType = TStorageType.FlatFile; else _storageType = TStorageType.RecordFile; } } }
/// <summary> /// Constructor for the TStoreUri. /// </summary> /// <param name="type">The TStorageType of the uri.</param> /// <param name="filePath">The file path of the uri.</param> public TStoreUri(TStorageType type, string filePath) { _storageType = type; _filePath = filePath; _rawUri = null; }