private void TestShowTables() { try { _logger.Message("Testing ShowTables"); manager.CreateDatabase(dbName); manager.UseDatabase(dbName); String dbPath = GetFilePath.Database(dbName); for (int i = 0; i < 2; i++) { Directory.CreateDirectory(dbPath + "\\subfolder" + i); } List <String> subdirList = manager.ShowTables(); Assert.AreEqual(2, subdirList.Count); Assert.AreEqual("subfolder0", subdirList[0]); Assert.AreEqual("subfolder1", subdirList[1]); } catch (Exception e) { _logger.Error(e.Message); } finally { manager.DropDatabase(dbName); } }
public static Project CreateEmpty(ILocalizationContext context, FileInfo path, INodeFactory conversationNodeFactory, INodeFactory domainNodeFactory, ISerializer <TData> serializer, ISerializer <TConversationData> conversationSerializer, ConversationSerializerDeserializerFactory conversationSerializerDeserializer, ISerializer <TDomainData> domainSerializer, PluginsConfig pluginsConfig, Func <IAudioProviderCustomization> audioCustomization, UpToDateFile.BackEnd backEnd) { using (MemoryStream m = new MemoryStream()) { //Create the new conversation file stream, fill with essential content and close FileInfo conversationFile = ConversationFile.GetAvailableConversationPath(path.Directory, Enumerable.Empty <ISaveableFileProvider>()); using (FileStream conversationStream = Util.LoadFileStream(conversationFile, FileMode.CreateNew, FileAccess.Write)) { conversationSerializer.Write(SerializationUtils.MakeConversationData(Enumerable.Empty <ConversationNode>(), new ConversationEditorData()), conversationStream); } //Create the new project GetFilePath getFilePath = null; //Should never need this as all the FileId lists are empty Write(getFilePath, Enumerable.Empty <Id <FileInProject> >(), Enumerable.Empty <Id <FileInProject> >(), Enumerable.Empty <Id <FileInProject> >(), Enumerable.Empty <Id <FileInProject> >(), Enumerable.Empty <TData.LocalizerSetData>(), m, serializer); using (FileStream projectfile = Util.LoadFileStream(path, FileMode.Create, FileAccess.Write)) { m.Position = 0; m.CopyTo(projectfile); m.Position = 0; } TData data = new TData(Enumerable.Empty <TData.FileIdAndPath>(), Enumerable.Empty <TData.FileIdAndPath>(), Enumerable.Empty <TData.FileIdAndPath>(), Enumerable.Empty <TData.FileIdAndPath>(), Enumerable.Empty <TData.LocalizerSetData>()); Project result = new Project(context, data, conversationNodeFactory, domainNodeFactory, m, path, serializer, conversationSerializer, conversationSerializerDeserializer, domainSerializer, pluginsConfig, audioCustomization, backEnd); return(result); } }
private void TestInsertRecord() { try { _logger.Message("Testing InsertRecord"); //path to files related to table String recordPath = GetFilePath.TableRecords(dbName, tableName); //making the table List <Column> cols = new List <Column>(); cols.Add(new Column(Column.DataType.Int, "Int", 100)); cols.Add(new Column(Column.DataType.Double, "Double", 1)); cols.Add(new Column(Column.DataType.Char, "String", 20)); manager.CreateTable(dbName, tableName, cols); //making records to be inserted List <String> l1 = new List <string>(); l1.Add("5"); l1.Add("5.1"); l1.Add("random1"); Record r1 = new Record(l1); manager.InsertRecord(r1); Stream fs = new FileStream(recordPath, FileMode.OpenOrCreate); byte[] r1Bytes = manager.storageManager.Read(fs, manager.storageManager.HeaderSize); Record actualR1 = manager.table.StringToRecord(new string(Converter.BytesToChar(r1Bytes))); AssertRecords(r1, actualR1); fs.Close(); //inserting a field having null value List <String> l2 = new List <string>(); l2.Add("2048000"); l2.Add("5.2"); l2.Add("random2"); Record r2 = new Record(l2); manager.InsertRecord(r2); fs = new FileStream(recordPath, FileMode.OpenOrCreate); r1Bytes = manager.storageManager.Read(fs, manager.storageManager.HeaderSize); actualR1 = manager.table.StringToRecord(new string(Converter.BytesToChar(r1Bytes))); AssertRecords(r1, actualR1); byte[] r2Bytes = manager.storageManager.Read(fs, manager.storageManager.HeaderSize + r1Bytes.Length); Record actualR2 = manager.table.StringToRecord(new string(Converter.BytesToChar(r2Bytes))); AssertRecords(r2, actualR2); fs.Close(); } catch (Exception e) { _logger.Error(e.Message); } finally { manager.DropTable(dbName, tableName); } }
public void TestDeleteFileFromRepository() { var obj = YamlDeserializer.DDTObjects(GetFilePath.GetPath(DDTFilePath)); foreach (var item in obj.Items) { UploadFileToRepo(item.FileName, item.Branch, item.Content, item.CommitMessage, Method.DELETE, StatusCode.NoContent.ToString()); } }
public void TestAddFile() { var obj = YamlDeserializer.DDTObjects(GetFilePath.GetPath(DDTFilePath)); foreach (var item in obj.Items) { UploadFileToRepo(item.FileName, item.Branch, item.Content, item.CommitMessage, Method.POST, StatusCode.Created.ToString()); } }
public void TestDeleteBranch() { var obj = YamlDeserializer.KDTObjects(GetFilePath.GetPath(KDTFilePathDelete)); foreach (var item in obj.Action) { KeywordDrivenTesting.PerformAction(item.name, Client, item.value, StatusCode.NoContent, _newBranch); } }
/** * Takes dictionary containing the address => to be deleted record */ public void DeleteRecords(Dictionary <int, Record> uselessRecords) { String recordsPath = GetFilePath.TableRecords(table.DbName, table.Name); Stream fs = new FileStream(recordsPath, FileMode.OpenOrCreate); List <int> addresses = new List <int>(uselessRecords.Keys); storageManager.Deallocate(recordsPath, addresses); fs.Close(); }
private void TestAddIndex() { try { _logger.Message("Testing AddIndex"); //making the table String indexPath = GetFilePath.TableColumnIndex(dbName, tableName, "Int"); List <Column> cols = new List <Column>(); cols.Add(new Column(Column.DataType.Int, "Int", 100)); cols.Add(new Column(Column.DataType.Double, "Double", 1)); cols.Add(new Column(Column.DataType.Char, "String", 20)); manager.CreateTable(dbName, tableName, cols); //making records to be inserted List <String> l1 = new List <string>(); l1.Add("5"); l1.Add("5.1"); l1.Add("random1"); Record r1 = new Record(l1); List <String> l2 = new List <string>(); l2.Add("2048000"); l2.Add("5.2"); l2.Add("random2"); Record r2 = new Record(l2); List <String> l3 = new List <string>(); l3.Add("-409600"); l3.Add("5.3"); l3.Add("random3"); Record r3 = new Record(l3); manager.InsertRecord(r1); manager.InsertRecord(r2); manager.InsertRecord(r3); manager.AddIndex(new Column(Column.DataType.Int, "Int", 100)); Assert.IsTrue(File.Exists(indexPath)); BtreeDictionary <Index <int>, int> btree = (BtreeDictionary <Index <int>, int>)Converter.FileToObject(indexPath); Assert.AreEqual(3, btree.Count); Assert.IsTrue(btree.ContainsKey(new Index <int>(2048000, 54))); Assert.IsTrue(btree.ContainsValue(96)); } catch (Exception e) { _logger.Error(e.Message); } finally { manager.DropTable(dbName, tableName); } }
/** * Drop index from a particular column */ public void DropIndex(Column index) { //making the index file String indexFile = GetFilePath.TableColumnIndex(table.DbName, table.Name, index.Name); storageManager.DropFile(indexFile); //removing entry from list in table and update back to file also table.IndexColumns.Remove(index); UpdateTableToFile(); }
/** * Takes dictionary containing the address => to be deleted record * And deletes that particular column value from the index path */ public void DeleteRecordsFromIndices(Dictionary <int, Record> uselessRecords) { foreach (Column indexColumn in table.IndexColumns) { int position = table.GetColumnIndex(indexColumn); String indexFile = GetFilePath.TableColumnIndex(table.DbName, table.Name, table.Columns[position].Name); if (table.Columns[position].Type == Column.DataType.Int) { BtreeDictionary <Index <int>, int> intbptree = (BtreeDictionary <Index <int>, int>)Converter.FileToObject(indexFile); foreach (KeyValuePair <int, Record> pair in uselessRecords) { int address = pair.Key; String value = pair.Value.Fields[position]; if (value != null) { intbptree.Remove(new Index <int>(int.Parse(value), address)); } } Converter.ObjectToFile(intbptree, indexFile); } else if (table.Columns[position].Type == Column.DataType.Double) { BtreeDictionary <Index <double>, int> doublebptree = (BtreeDictionary <Index <double>, int>)Converter.FileToObject(indexFile); foreach (KeyValuePair <int, Record> pair in uselessRecords) { int address = pair.Key; String value = pair.Value.Fields[position]; if (value != null) { doublebptree.Remove(new Index <double>(double.Parse(value), address)); } } Converter.ObjectToFile(doublebptree, indexFile); } else if (table.Columns[position].Type == Column.DataType.Char) { BtreeDictionary <Index <String>, int> stringbptree = (BtreeDictionary <Index <String>, int>)Converter.FileToObject(indexFile); foreach (KeyValuePair <int, Record> pair in uselessRecords) { int address = pair.Key; String value = pair.Value.Fields[position]; if (value != null) { stringbptree.Remove(new Index <String>(value, address)); } } Converter.ObjectToFile(stringbptree, indexFile); } } }
public void DropTable(String dbName, String tableName) { String path = GetFilePath.Table(dbName, tableName); if (!Directory.Exists(path)) { throw new Exception("Table does not exist"); } else { storageManager.DropFolder(path); } }
public AudioProvider(FileInfo projectPath, GetFilePath getFilePath, Func <string, bool> fileLocationOk, IProject project, IAudioProviderCustomization customization) { m_projectPath = projectPath.Directory; m_project = project; m_customization = customization; Func <IEnumerable <Tuple <Id <FileInProject>, DocumentPath> >, IEnumerable <IAudioFile> > load = files => files.Select(file => new AudioFile(file.Item1, file.Item2, this)); Func <DirectoryInfo, AudioFile> makeEmpty = path => { throw new NotSupportedException("Can't create new audio files within the editor"); }; Func <Id <FileInProject>, MissingAudioFile> makeMissing = file => new MissingAudioFile(file, getFilePath(file), this); m_audioFiles = new ProjectElementList <IAudioFile>(getFilePath, fileLocationOk, load, makeEmpty, makeMissing); UpdateQueued = new SuppressibleAction(() => { ReallyUpdateUsage(); }); //For now just update everything }
/** * Inserts a record into the table * Those fields should be null which have not been set * @returns Address where it is inserted */ public int InsertRecord(Record record) { //Inserting entry into record file String recordsPath = GetFilePath.TableRecords(table.DbName, table.Name); Stream fs = new FileStream(recordsPath, FileMode.OpenOrCreate); int address = storageManager.Allocate(recordsPath, fs); char[] recordStream = table.RecordToCharArray(record); storageManager.Write(fs, address, Converter.CharToBytes(recordStream)); fs.Close(); return(address); }
/** * @returns Dictionary<key, Record> * key => address * Record => record corresponding to the address * which satisfies the given condition * * if condition is null means select all records * Does Linear Search of all the records */ public Dictionary <int, Record> GetAddressRecordDict(Condition condition) { int index = -1; //means unitialized if (condition != null) { index = table.GetColumnIndex(condition.Attribute); if (index == -1) //no column matched { return(new Dictionary <int, Record>()); } } //initializing the variables Dictionary <int, Record> finalDict = new Dictionary <int, Record>(); Stream fs = new FileStream(GetFilePath.TableRecords(table.DbName, table.Name), FileMode.OpenOrCreate); int recordSize = storageManager.GetRecordSize(fs); int endOfFile = storageManager.GetEndOfFile(fs); //getting the whole bitmap here so that we know there is no record there Stream bitmapFs = new FileStream(GetFilePath.TableRecordsBitmap(table.DbName, table.Name), FileMode.OpenOrCreate); List <int> bitmapList = Converter.BytesToIntList(storageManager.GetCompleteFile(bitmapFs)); HashSet <int> bitmapSet = new HashSet <int>(bitmapList); bitmapFs.Close(); //traversing the whole file int NumRecords = Constants.MaxSelectRecords; //BUG use this if read more than a chunk for (int offset = storageManager.HeaderSize; offset < endOfFile; offset += recordSize) { if (!bitmapSet.Contains(offset)) { char[] recordStr = new char[recordSize]; Converter.BytesToChar(storageManager.Read(fs, offset)).CopyTo(recordStr, 0); Record record = table.StringToRecord(new string(recordStr)); if (condition == null) { finalDict.Add(offset, record); } else if (IsRecordValid(record, condition, index)) { finalDict.Add(offset, record); } } } fs.Close(); return(finalDict); }
public ProjectElementList(GetFilePath getFilePath, Func <string, bool> fileLocationOk, Func <IEnumerable <Tuple <Id <FileInProject>, DocumentPath> >, IEnumerable <TElement> > loader, Func <DirectoryInfo, TElement> makeEmpty) { m_getFilePath = getFilePath; m_data = new CallbackDictionary <Id <FileInProject>, TElement>(); m_data.Removing += (key, element) => { element.Removed(); }; m_data.Clearing += () => { m_data.Values.ForAll(element => { element.Removed(); }); }; m_loader = loader; m_makeEmpty = makeEmpty; m_fileLocationOk = fileLocationOk; m_suppressibleGotChanged = new SuppressibleAction(() => { GotChanged.Execute(); }); Added += a => m_suppressibleGotChanged.TryExecute(); Removed += a => m_suppressibleGotChanged.TryExecute(); }
public void UseDatabase(String dbName) { String path = GetFilePath.Database(dbName); String conf = GetFilePath.DatabaseConf(dbName); if (!Directory.Exists(path)) { throw new Exception("Database does not exist"); } else { db = new Database(dbName); } }
/** * Not initializing db object as that will * be done after he has used "use database" query */ public void CreateDatabase(String dbName) { String path = GetFilePath.Database(dbName); String conf = GetFilePath.DatabaseConf(dbName); if (Directory.Exists(path)) { throw new Exception("Database already exists"); } else { storageManager.CreateFolder(path); } }
public List <String> ShowTables() { String path = GetFilePath.Database(db.Name); DirectoryInfo dirInfo = new DirectoryInfo(path); DirectoryInfo[] subdirInfo = dirInfo.GetDirectories(); List <String> subdirNames = new List <string>(); foreach (DirectoryInfo subdir in subdirInfo) { subdirNames.Add(subdir.Name); } return(subdirNames); }
/** * Gets the dictionary containing the address => updated record */ public void UpdateRecord(Dictionary <int, Record> updatedRecords) { String recordsPath = GetFilePath.TableRecords(table.DbName, table.Name); Stream fs = new FileStream(recordsPath, FileMode.OpenOrCreate); foreach (int address in updatedRecords.Keys) { char[] recordStream = table.RecordToCharArray(updatedRecords[address]); storageManager.Write(fs, address, Converter.CharToBytes(recordStream)); } fs.Close(); //remove old key //add new key }
/** * This constructor would be used to init the conf * of table * Will be needed when using select, insert, etc. */ public TableManager(String dbName, String tableName) { String path = GetFilePath.Table(dbName, tableName); String conf = GetFilePath.TableConf(dbName, tableName); if (!Directory.Exists(path)) { throw new Exception("Table does not exist"); } else { storageManager = new StorageManager(); table = (Table)Converter.FileToObject(conf); } }
/// <param name="context">Context used when localizing to reference current localization</param> /// <param name="usedGuids"></param> /// <param name="shouldClean"></param> /// <param name="shouldExpand"></param> /// <param name="pathOk">Path is an acceptable filename for a new localization file</param> /// <param name="fileLocationOk">Path is an acceptable location from which to import an existing localization file</param> public LocalizationEngine(GetFilePath getFilePath, IEnumerable <Project.TData.LocalizerSetData> sets, ILocalizationContext context, Func <HashSet <Id <LocalizedText> > > usedGuids, Func <string, bool> shouldClean, Func <FileInfo, bool> pathOk, Func <string, bool> fileLocationOk, UpToDateFile.BackEnd backEnd, DirectoryInfo origin) { m_context = context; m_usedGuids = usedGuids; ShouldClean = shouldClean; Func <IEnumerable <Tuple <Id <FileInProject>, DocumentPath> >, IEnumerable <ILocalizationFile> > load = files => { //return files.Select(file => LocalizationFile.Load(file, MakeSerializer(file.Name), backend)); var filesAndSerializer = files.Select(f => new { Id = f.Item1, Path = f.Item2, Serializer = MakeSerializer(f.Item2.AbsolutePath, f.Item1) }).ToList(); return(ParallelEnumerable.Select(filesAndSerializer.AsParallel(), fs => LocalizationFile.Load(fs.Path, fs.Id, fs.Serializer, backEnd))); }; Func <DirectoryInfo, LocalizationFile> makeEmpty = path => LocalizationFile.MakeNew(path, MakeSerializer, pathOk, backEnd, origin); m_localizers = new ProjectElementList <ILocalizationFile>(getFilePath, fileLocationOk.Bottleneck(), load, makeEmpty); m_localizationSets = sets.ToHashSet(); }
private void TestCreateDropDatabase() { try { //database does not exist _logger.Message("Testing CreateDropDatabase"); manager.CreateDatabase(dbName); Assert.IsTrue(Directory.Exists(GetFilePath.Database(dbName))); //not checking conf file as that is not getting made right now manager.DropDatabase(dbName); Assert.IsTrue(!Directory.Exists(GetFilePath.Database(dbName))); } catch (Exception e) { _logger.Error(e.Message); } }
private void TestCreateDropTable() { try { _logger.Message("Testing CreateDropTable"); manager.CreateTable(dbName, tableName, new List <Column>()); Assert.IsTrue(Directory.Exists(GetFilePath.Table(dbName, tableName))); Assert.IsTrue(File.Exists(GetFilePath.TableConf(dbName, tableName))); Assert.IsTrue(File.Exists(GetFilePath.TableRecords(dbName, tableName))); manager.DropTable(dbName, tableName); Assert.IsTrue(!Directory.Exists(GetFilePath.Table(dbName, tableName))); } catch (Exception e) { _logger.Error(e.Message); } }
/** * Creates all the folders/files related to a new table * IMPORTANT - Presently assumed indexColumns would be empty * Index can be added on later using AddIndex */ public void CreateTable(string dbName, string tableName, List <Column> columns) { String path = GetFilePath.Table(dbName, tableName); String conf = GetFilePath.TableConf(dbName, tableName); String records = GetFilePath.TableRecords(dbName, tableName); if (Directory.Exists(path)) { throw new Exception("Table already exists"); } else { table = new Table(dbName, tableName, columns, new List <Column>()); storageManager.CreateFolder(path); //table folder Converter.ObjectToFile(table, conf); //schema file of table byte[] record = Converter.CharToBytes(new char[table.GetSizeOfRecordArray()]); storageManager.CreateFile(records, record.Length, true); //records file of table } }
/** * Inserts a record into the indices of the table * record -> to be inserted * address -> entry in the records file */ public void InsertRecordToIndices(Record record, int address) { foreach (Column indexColumn in table.IndexColumns) { int position = table.GetColumnIndex(indexColumn); String indexFile = GetFilePath.TableColumnIndex(table.DbName, table.Name, table.Columns[position].Name); String value = record.Fields[position]; if (table.Columns[position].Type == Column.DataType.Int) { if (value != null) { BtreeDictionary <Index <int>, int> intbptree = (BtreeDictionary <Index <int>, int>)Converter.FileToObject(indexFile); intbptree.Add(new Index <int>(int.Parse(value), address), address); Converter.ObjectToFile(intbptree, indexFile); } } else if (table.Columns[position].Type == Column.DataType.Double) { if (value != null) { BtreeDictionary <Index <double>, int> doublebptree = (BtreeDictionary <Index <double>, int>)Converter.FileToObject(indexFile); doublebptree.Add(new Index <double>(double.Parse(value), address), address); Converter.ObjectToFile(doublebptree, indexFile); } } else if (table.Columns[position].Type == Column.DataType.Char) { if (value != null) { BtreeDictionary <Index <String>, int> stringbptree = (BtreeDictionary <Index <String>, int>)Converter.FileToObject(indexFile); stringbptree.Add(new Index <String>(value, address), address); Converter.ObjectToFile(stringbptree, indexFile); } } } }
return(Parse <TData>(File.ReadAllBytes(GetFilePath(templateFileName)), File.ReadAllBytes(GetFilePath(targetFileName))));
static Func <IEnumerable <Tuple <Id <FileInProject>, DocumentPath> >, IEnumerable <TElement> > MyLoader(GetFilePath getFilePath, Func <IEnumerable <Tuple <Id <FileInProject>, DocumentPath> >, IEnumerable <TElement> > loader, Func <Id <FileInProject>, TElement> makeMissing) { return(files => { List <TElement> result = new List <TElement>(); foreach (var file in files) { if (file.Item2.Exists) { try { var doc = loader(file.Only()).Single(); result.Add(doc); } catch (MyFileLoadException e) { Console.Out.WriteLine(e.Message); Console.Out.WriteLine(e.StackTrace); Console.Out.WriteLine(e.InnerException.Message); Console.Out.WriteLine(e.InnerException.StackTrace); MessageBox.Show("File: " + file.Item2.AbsolutePath + " could not be accessed"); var doc = makeMissing(file.Item1); result.Add(doc); } } else { var doc = makeMissing(file.Item1); result.Add(doc); } } return result; }); }
/** * Adding index to particular column * if some records were already there */ public void AddIndex(Column index) { //making the index file String indexFile = GetFilePath.TableColumnIndex(table.DbName, table.Name, index.Name); Dictionary <int, Record> allRecords = GetAddressRecordDict(null); int position = table.GetColumnIndex(index); BtreeDictionary <Index <int>, int> intbptree; BtreeDictionary <Index <String>, int> stringbptree; BtreeDictionary <Index <double>, int> doublebptree; if (index.Type == Column.DataType.Int) { intbptree = new BtreeDictionary <Index <int>, int>(); //making a b+tree foreach (KeyValuePair <int, Record> keyValuePair in allRecords) { String s = keyValuePair.Value.Fields[position]; if (s != null) { Index <int> idx = new Index <int>(int.Parse(s), keyValuePair.Key); intbptree.Add(idx, keyValuePair.Key); } //BUG not inserting empty or null values as of now /*else * { * Index<int> idx = new Index<int>(Constants.NullAsInt, keyValuePair.Key); * intbptree.Add(idx, keyValuePair.Key); * }*/ } //writing b+tree to the file Converter.ObjectToFile(intbptree, indexFile); } else if (index.Type == Column.DataType.Double) { doublebptree = new BtreeDictionary <Index <double>, int>(); //making a b+tree foreach (KeyValuePair <int, Record> keyValuePair in allRecords) { String s = keyValuePair.Value.Fields[position]; if (s != null) { Index <double> idx = new Index <double>(double.Parse(s), keyValuePair.Key); doublebptree.Add(idx, keyValuePair.Key); } } //writing b+tree to the file Converter.ObjectToFile(doublebptree, indexFile); } else if (index.Type == Column.DataType.Char) { stringbptree = new BtreeDictionary <Index <String>, int>(); //making a b+tree foreach (KeyValuePair <int, Record> keyValuePair in allRecords) { String s = keyValuePair.Value.Fields[position]; if (s != null) { Index <String> idx = new Index <String>(s, keyValuePair.Key); stringbptree.Add(idx, keyValuePair.Key); } } //writing b+tree to the file Converter.ObjectToFile(stringbptree, indexFile); } //adding entry to list in table and update back to file also table.IndexColumns.Add(index); UpdateTableToFile(); }
public ProjectElementList(GetFilePath getFilePath, Func <string, bool> fileLocationOk, Func <IEnumerable <Tuple <Id <FileInProject>, DocumentPath> >, IEnumerable <TElement> > loader, Func <DirectoryInfo, TElement> makeEmpty, Func <Id <FileInProject>, TElement> makeMissing) : this(getFilePath, fileLocationOk, MyLoader(getFilePath, loader, makeMissing), makeEmpty) { }
/** * @returns Dictionary<key, Record> * key => address * Record => record corresponding to the address * which satisfies the given condition * * Does searching in the btree * Call this function only if that column is an index * @param name="condition" NotNullable */ public Dictionary <int, Record> GetAddressRecordDictOnIndex(Condition condition) { //initializing the variables Dictionary <int, Record> finalDict = new Dictionary <int, Record>(); List <int> addresses = new List <int>(); int index = -1; //means unitialized if (condition != null) { index = table.GetColumnIndex(condition.Attribute); } if (index == -1 || condition == null) //not feasible columns { return(finalDict); } String indexFile = GetFilePath.TableColumnIndex(table.DbName, table.Name, condition.Attribute.Name); String recordsFile = GetFilePath.TableRecords(table.DbName, table.Name); //getting the b+ tree into the main memory BtreeDictionary <Index <int>, int> intbptree; BtreeDictionary <Index <double>, int> doublebptree; BtreeDictionary <Index <String>, int> stringbptree; //traversing the whole btree if (condition.Attribute.Type == Column.DataType.Int) { //getting tree into main memory intbptree = (BtreeDictionary <Index <int>, int>)Converter.FileToObject(indexFile); //initialized possible feasible range of the records IEnumerable range; if (condition.Sign == Condition.ConditionType.Equal) { range = intbptree.BetweenKeys(new Index <int>(int.Parse(condition.Value), int.MinValue), new Index <int>(int.Parse(condition.Value), int.MaxValue)); } else if (condition.Sign == Condition.ConditionType.Less || condition.Sign == Condition.ConditionType.LessEqual) { range = intbptree.BetweenKeys(new Index <int>(int.MinValue, int.MinValue), new Index <int>(int.Parse(condition.Value), int.MaxValue)); } else { range = intbptree.BetweenKeys(new Index <int>(int.Parse(condition.Value), int.MinValue), new Index <int>(int.MaxValue, int.MaxValue)); } //initialized the selected addresses list foreach (KeyValuePair <Index <int>, int> pair in range) { if (IsColumnValueValid(pair.Key.Key.ToString(), condition, index)) { addresses.Add(pair.Value); } } } else if (condition.Attribute.Type == Column.DataType.Double) { //getting tree into main memory doublebptree = (BtreeDictionary <Index <double>, int>)Converter.FileToObject(indexFile); //initialized possible feasible range of the records IEnumerable range; if (condition.Sign == Condition.ConditionType.Equal) { range = doublebptree.BetweenKeys(new Index <double>(double.Parse(condition.Value), int.MinValue), new Index <double>(double.Parse(condition.Value), int.MaxValue)); } else if (condition.Sign == Condition.ConditionType.Less || condition.Sign == Condition.ConditionType.LessEqual) { range = doublebptree.BetweenKeys(new Index <double>(double.MinValue, int.MinValue), new Index <double>(double.Parse(condition.Value), int.MaxValue)); } else { range = doublebptree.BetweenKeys(new Index <double>(double.Parse(condition.Value), int.MinValue), new Index <double>(double.MaxValue, int.MaxValue)); } //initialized the selected addresses list foreach (KeyValuePair <Index <double>, int> pair in range) { if (IsColumnValueValid(pair.Key.Key.ToString(), condition, index)) { addresses.Add(pair.Value); } } } else if (condition.Attribute.Type == Column.DataType.Char) { //getting tree into main memory stringbptree = (BtreeDictionary <Index <String>, int>)Converter.FileToObject(indexFile); //initialized possible feasible range of the records IEnumerable range; if (condition.Sign == Condition.ConditionType.Equal) { range = stringbptree.BetweenKeys(new Index <String>(condition.Value, int.MinValue), new Index <String>(condition.Value, int.MaxValue)); } else { throw new Exception("This type of condition for strings is not supported"); } //BUG not implementing less than greater than for strings //initialized the selected addresses list foreach (KeyValuePair <Index <String>, int> pair in range) { if (IsColumnValueValid(pair.Key.Key, condition, index)) { addresses.Add(pair.Value); } } } //getting all records corresponding to the addresses list Stream fs = new FileStream(recordsFile, FileMode.OpenOrCreate); foreach (int address in addresses) { byte[] recordsBytes = storageManager.Read(fs, address); Record record = table.StringToRecord(new string(Converter.BytesToChar(recordsBytes))); finalDict.Add(address, record); } fs.Close(); return(finalDict); }