public void CreateTable(IList <ColumnDetails> columns, SecurityPermissions permissions) { this.Table = new Table(this.Configuration.ArribaTable, this.Configuration.ItemCountLimit); // Try to load the table if it already exists if (BinarySerializable.EnumerateUnder(Path.Combine("Tables", this.Configuration.ArribaTable)).Count() > 0) { Trace.WriteLine(string.Format("Loading Arriba Table '{0}'...", this.Configuration.ArribaTable)); this.Table.Load(this.Configuration.ArribaTable); } // Columns are added dynamically by Append // Set the table security SecureDatabase sdb = new SecureDatabase(); sdb.SetSecurity(this.Configuration.ArribaTable, permissions); sdb.SaveSecurity(this.Configuration.ArribaTable); // Debug Only: Verify consistency just after load if (this.DiagnosticsEnabled) { Trace.WriteLine("Verifying Arriba Table consistency [on load]..."); ExecutionDetails d = new ExecutionDetails(); this.Table.VerifyConsistency(this.DiagnosticsLevel, d); if (!d.Succeeded) { Debugger.Break(); Trace.TraceError(String.Format("Consistency Errors Detected: {0}", String.Join("\r\n", d.Errors))); } } }
/// <summary> /// Return the set of CSVs containing items with changed dates within the provided range. /// CSVs are titled with the changed date [UTC] of the first item contained, so we want /// the last CSV with a DateTime before start up to the last CSV with a DateTime before end. /// </summary> /// <remarks> /// Ex: Suppose we want 2016-02-01 to 2016-02-03 from: /// 20160125 [Exclude: Next CSV name is still before start, so all items will be before start.] /// 20160130 * [Include: The last name before Start. 2016-02-01 is in here] /// 20160202 * [Include: Name is still before end. 2016-02-03 is in here] /// 20160204 [Exclude: Name is after end, so all items will be after end] /// </remarks> /// <param name="start">StartDate from which to include</param> /// <param name="end">EndDate before which to include</param> /// <returns>List of CsvPaths which contain all items between start and end</returns> private List <string> FindCsvsBetween(DateTime start, DateTime end) { List <string> result = new List <string>(); string csvFolderPath = Path.Combine(BinarySerializable.CachePath, String.Format(CsvWriterItemConsumer.CsvPathForTable, this.TableName)); foreach (string csvFilePath in BinarySerializable.EnumerateUnder(csvFolderPath)) { if (Path.GetExtension(csvFilePath).Equals(".csv", StringComparison.OrdinalIgnoreCase)) { DateTime csvFirstItemChangedDate = DateTime.ParseExact(Path.GetFileNameWithoutExtension(csvFilePath), CsvWriterItemConsumer.CsvFileNameDateTimeFormatString, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); // If items from here are after the end, stop if (csvFirstItemChangedDate > end) { break; } // If this name is before the start, all previous CSVs are not needed if (csvFirstItemChangedDate < start) { result.Clear(); } // Add this to the list result.Add(csvFilePath); } } return(result); }
public void CreateTable(IList <ColumnDetails> columns, SecurityPermissions permissions) { this.Table = new Table(this.Configuration.ArribaTable, this.Configuration.ItemCountLimit); // Try to load the table if it already exists if (BinarySerializable.EnumerateUnder(Path.Combine("Tables", this.Configuration.ArribaTable)).Count() > 0) { Trace.WriteLine(string.Format("Loading Arriba Table '{0}'...", this.Configuration.ArribaTable)); this.Table.Load(this.Configuration.ArribaTable); } // Verify all columns match requested types [will throw if column exists but as different type] foreach (ColumnDetails cd in columns) { this.Table.AddColumn(cd); } // Set the table security new SecureDatabase().SetSecurity(this.Configuration.ArribaTable, permissions); // Debug Only: Verify consistency just after load if (this.DiagnosticsEnabled) { Trace.WriteLine("Verifying Arriba Table consistency [on load]..."); ExecutionDetails d = new ExecutionDetails(); this.Table.VerifyConsistency(this.DiagnosticsLevel, d); if (!d.Succeeded) { Debugger.Break(); Trace.TraceError(String.Format("Consistency Errors Detected: {0}", String.Join("\r\n", d.Errors))); } } }
public virtual void Load(string tableName, IEnumerable <string> partitions) { _locker.EnterWriteLock(); try { _partitions.Clear(); this.Name = tableName; string tablePath = TableCachePath(tableName); if (partitions != null) { foreach (string partitionFile in partitions) { Partition p = new Partition(); p.Read(Path.Combine(tablePath, partitionFile + ".bin")); _partitions.Add(p); } } else { // Load each bin file in the Table folder (*NOT* bin.new; this means a write was in progress) foreach (string partitionFile in BinarySerializable.EnumerateUnder(tablePath)) { if (partitionFile.EndsWith(".bin", StringComparison.OrdinalIgnoreCase)) { Partition p = new Partition(); p.Read(partitionFile); _partitions.Add(p); } } } // If there are no partitions to load, re-add the default 'all' one if (_partitions.Count == 0) { _partitions.Add(new Partition(PartitionMask.All)); } // Reset the number of partition bits _partitionBits = _partitions[0].Mask.BitCount; // Reset ColumnAliasCorrector mappings _columnAliasCorrector.SetMappings(this); } finally { _locker.ExitWriteLock(); } }
/// <summary> /// Returns whether a given table exists on disk. This requires the folder /// for the table to exist and to contain at least one .bin file. /// </summary> /// <param name="tableName">Name of table to check</param> /// <returns>True if table exists, False otherwise</returns> public static bool Exists(string tableName) { string tablePath = TableCachePath(tableName); foreach (string partitionFile in BinarySerializable.EnumerateUnder(tablePath)) { if (partitionFile.EndsWith(".bin", StringComparison.OrdinalIgnoreCase)) { return(true); } } return(false); }
public void BinarySerializable_EnumerateAndDelete() { IEnumerable <string> items; // Delete any pre-existing items foreach (string serializedItem in BinarySerializable.EnumerateUnder(".")) { BinarySerializable.Delete(serializedItem); } // Add one item SampleSerializable sample = new SampleSerializable(12345); sample.Write("Sample"); // Verify folder size finds one item only Assert.AreEqual(4, BinarySerializable.Size(".")); // Verify it is found items = BinarySerializable.EnumerateUnder("."); Assert.AreEqual(1, items.Count()); // Add another item sample.Write("Sample2"); // Verify both are found items = BinarySerializable.EnumerateUnder("."); Assert.AreEqual(2, items.Count()); // Verify folder size finds both items Assert.AreEqual(8, BinarySerializable.Size(".")); // Delete first item; verify count drops BinarySerializable.Delete("Sample"); items = BinarySerializable.EnumerateUnder("."); Assert.AreEqual(1, items.Count()); }