/// <summary> /// Construct the wrapper. /// Also validates the memory calculation. /// </summary> /// <param name="fileName">Path to the data set file.</param> /// <param name="properties">Comma separated list of properties to include in the results</param> /// <param name="validate">Set to true to validate the memory calculation.</param> public TrieWrapper(string fileName, string properties, bool validate) { _provider = new Trie.Provider(fileName, properties, validate); _fileName = fileName; }
/// <summary> /// Construct the wrapper. /// </summary> /// <param name="fileName">The full path to the file containing device data.</param> /// <param name="properties">Comma seperated list of properties to include in the results.</param> public TrieWrapper(string fileName, string properties) { _provider = new Trie.Provider(fileName, properties); _fileName = fileName; }
/// <summary> /// Construct the wrapper. /// </summary> /// <param name="fileName">The full path to the file containing device data.</param> /// <param name="properties">Comma seperated list of properties to include in the results.</param> public TrieWrapper(string fileName, string properties) { lock (_lock) { // Check the file exists before trying to load it. var info = new FileInfo(fileName); if (info.Exists == false) { throw new ArgumentException(String.Format( "File '{0}' can not be found.", info.FullName), "fileName"); } // If a file has already been loaded then check it's the // same name as the one being used for this instance. Only // one file can be loaded at a time. if (_fileName != null && _fileName.Equals(fileName) == false) { throw new ArgumentException(String.Format( "Trie has already been initialised with file name '{0}'. " + "Multiple providers with different file sources can not be created.", _fileName), "fileName"); } // Only initialise the memory if the file has not already // been loaded into memory. if (_fileName == null) { _provider = new Trie.Provider(info.FullName, properties); // Initialise the list of property names and indexes. var propertyIndex = 0; foreach (var property in _provider.getAvailableProperties()) { PropertyIndexes.Add(property, propertyIndex); propertyIndex++; } // Initialise the list of http header names. foreach (var httpHeader in _provider.getHttpHeaders()) { HttpHeaders.Add(httpHeader); } HttpHeaders.Sort(); _fileName = fileName; } // Increase the number of wrapper instances that have // been created. Used when the wrapper is disposed to // determine if the memory used should be released. _instanceCount++; } }