public void EventDatatableEncoding() { TableFormat tf = new TableFormat(1, 1); tf.addField(FieldFormat.FLOAT_FIELD, "value"); tf.addField(FieldFormat.INTEGER_FIELD, "quality"); DataTable nested = new DataTable(tf, 12345.67f, 123); ClassicEncodingSettings ces = new ClassicEncodingSettings(false); DataTable table = new DataTable(AbstractContext.EF_UPDATED, "test", nested, null); string encodedTable = table.encode(ces); // .encode(this.createClassicEncodingSettings(true)); //string expected = "<F=<<variable><S><A=>><<value><T><A=<F=>>><<user><S><F=N><A=<NULL>>>" // + "<M=1><X=1>><R=<test>" // + "<<F=<<value><F><A=0>>" // + "<<quality><I><A=0>><M=1><X=1>>" // + "<R=<12345.67><123>>><<NULL>>>"; string expected = "\\u001c\\u0046\\u001e\\u001c\\u001c\\u0076\\u0061\\u0072\\u0069\\u0061\\u0062\\u006c\\u0065\\u001d\\u001c\\u0053\\u001d\\u001c\\u0041\\u001e\\u001d\\u001d\\u001c\\u001c\\u0076\\u0061\\u006c\\u0075\\u0065\\u001d\\u001c\\u0054\\u001d\\u001c\\u0041\\u001e\\u001c\\u0046\\u001e\\u001d\\u001d\\u001d\\u001c\\u001c\\u0075\\u0073\\u0065\\u0072\\u001d\\u001c\\u0053\\u001d\\u001c\\u0046\\u001e\\u004e\\u001d\\u001c\\u0041\\u001e\\u001a\\u001d\\u001d\\u001c\\u004d\\u001e\\u0031\\u001d\\u001c\\u0058\\u001e\\u0031\\u001d\\u001d\\u001c\\u0052\\u001e\\u001c\\u0074\\u0065\\u0073\\u0074\\u001d\\u001c\\u001c\\u0046\\u001e\\u001c\\u001c\\u0076\\u0061\\u006c\\u0075\\u0065\\u001d\\u001c\\u0046\\u001d\\u001c\\u0041\\u001e\\u0030\\u001d\\u001d\\u001c\\u001c\\u0071\\u0075\\u0061\\u006c\\u0069\\u0074\\u0079\\u001d\\u001c\\u0049\\u001d\\u001c\\u0041\\u001e\\u0030\\u001d\\u001d\\u001c\\u004d\\u001e\\u0031\\u001d\\u001c\\u0058\\u001e\\u0031\\u001d\\u001d\\u001c\\u0052\\u001e\\u001c\\u0031\\u0032\\u0033\\u0034\\u0035\\u002e\\u0036\\u0037\\u001d\\u001c\\u0031\\u0032\\u0033\\u001d\\u001d\\u001d\\u001c\\u001a\\u001d\\u001d"; StringBuilder sb = new StringBuilder(); foreach (char c in encodedTable) { sb.Append("\\u"); sb.Append(string.Format("{0:x4}", (int)c)); } Assert.AreEqual(expected, sb.ToString()); }
public void TestFirstEncoding() { TableFormat tf = new TableFormat(1, 1); tf.addField(FieldFormat.FLOAT_FIELD, "value"); tf.addField(FieldFormat.INTEGER_FIELD, "quality"); DataTable nested = new DataTable(tf, 12345.67f, 123); ClassicEncodingSettings ces = new ClassicEncodingSettings(true); ces.setFormatCache(new FormatCache()); ces.setKnownFormatCollector(new KnownFormatCollector()); DataTable table = new DataTable(AbstractContext.EF_UPDATED, "test", nested, null); String encodedTable = table.encode(ces); String actual = "<F=<<variable><S><A=>><<value><T><A=<F=>>><<user><S><F=N><A=<NULL>>>" + "<M=1><X=1>><D=0><R=<test>" + "<<F=<<value><F><A=0>>" + "<<quality><I><A=0>><M=1><X=1>><D=1>" + "<R=<12345.67><123>>><<NULL>>>"; Assert.AreEqual(encodedTable, actual); }
public void testClientFormatCache() { TableFormat f1 = new TableFormat(format1, new ClassicEncodingSettings(true)); TableFormat f2 = new TableFormat(format2, new ClassicEncodingSettings(true)); FormatCache fc = new FormatCache(); fc.put(123, f1); TableFormat res = fc.get(123); Assert.AreSame(f1, res); int?id = fc.getId(f1); Assert.AreEqual(123, id); fc.put(456, f1); fc.put(456, f2); res = fc.get(456); Assert.AreSame(f2, res); }
/// <summary> /// how to create a custom table /// </summary> /// <remarks></remarks> public void CreateCustomTable() { // Set a reference to the drawing document. // This assumes a drawing document is active. DrawingDocument oDrawDoc = (DrawingDocument)_InvApplication.ActiveDocument; // Set a reference to the active sheet. Sheet oSheet = default(Sheet); oSheet = oDrawDoc.ActiveSheet; // Set the column titles string[] oTitles = new string[] { "Part Number", "Quantity", "Material" }; // Set the contents of the custom table (contents are set row-wise) string[] oContents = new string[] { "1", "1", "Brass", "2", "2", "Aluminium", "3", "1", "Steel" }; // Set the column widths (defaults to the column title width if not specified) double[] oColumnWidths = new double[] { 2.5, 2.5, 4 }; // Create the custom table CustomTable oCustomTable = default(CustomTable); oCustomTable = oSheet.CustomTables.Add("My Table", _InvApplication.TransientGeometry.CreatePoint2d(15, 15), 3, 3, oTitles, oContents, oColumnWidths); // Change the 3rd column to be left justified. oCustomTable.Columns[3].ValueHorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft; // Create a table format object TableFormat oFormat = oSheet.CustomTables.CreateTableFormat(); // Set inside line color to red. oFormat.InsideLineColor = _InvApplication.TransientObjects.CreateColor(255, 0, 0); // Set outside line weight. oFormat.OutsideLineWeight = 0.1; // Modify the table formats oCustomTable.OverrideFormat = oFormat; }
public static void UpdateTableFormat() { string name = "updateTableFormat.docx"; string nodePath = "Section/0/Body/0"; int? index = 0; string folder = "input"; string storage = null; string password = null; TableFormat tableFormat = new TableFormat { Bidi = false, Borders = new Borders { TopBorder = new Border { BorderType = Border.BorderTypeEnum.Dot, Color = new Color(255, 25, 1), LineWidth = 3 } } }; string destFilePath = "output/UpdateTableFormat_output.docx"; tablesApi.UpdateTableFormat(name, nodePath, index, tableFormat, destFilePath, folder, storage, password); }
public async Task ExecuteAsync(FileInfo inputPath, TableFormat inputFormat, string outputFilePath) { var inputData = File.ReadAllText(inputPath.FullName); var result = await ExecuteAsync(convertor.Convert(inputData, inputFormat), System.IO.Path.GetFileName(inputPath.FullName)); File.WriteAllText(outputFilePath, result); }
private void init(string nameString, TableFormat formatString, string descriptionString) { this.setName(nameString); this.setFormat(formatString); this.setDescription(descriptionString); }
private static TableFormat ModificationTimeRecordFormat() { var format = new TableFormat(1, 100); format.addField("<" + VF_MODTIME_VARIABLE + "><S><D=Variable Name>"); format.addField("<" + VF_MODTIME_MODTIME + "><D><D=Modification Time>"); return(format); }
public string Convert(string input, TableFormat format) { if (!convertors.ContainsKey(format)) { throw new UnsupportedFormatException(format); } return(convertors[format]().Parse(input)); }
public void setFormat(TableFormat formatString) { if (this.format != null) { this.format.makeImmutable(null); } this.format = formatString; }
private void init(String nameString, TableFormat formatString, Boolean readableBoolean, Boolean writableBoolean, String descriptionString) { name = nameString; format = formatString; readable = readableBoolean; writable = writableBoolean; description = descriptionString ?? nameString; }
static UpdateManager() { VFT_TEST_VARIABLE = new TableFormat(1, 1); VFT_TEST_VARIABLE.addField("<" + VF_TEST_VARIABLE_VALUE + ">" + "<E>" + "<D=Value>" + "<A=1>"); VFT_TEST_VARIABLE.addField("<" + VF_TEST_VARIABLE_TIMESTAMP + ">" + "<D>" + "<D=Timestamp>" + "<A=2000-02-01 12:00:00.000>"); VFT_TEST_VARIABLE.addField("<" + VF_TEST_VARIABLE_QUALITY + ">" + "<I>" + "<D=Quality>" + "<A=0>"); }
public TableData(string data) { var strs = data.Split('|'); fileName = strs[0].Trim(); md5value = strs[1].Trim(); format = (TableFormat)(int.Parse(strs[2])); withServer = strs[3].Trim() == "1" ? true : false; }
private void init(String nameString, TableFormat inputTableFormat, TableFormat outputTableFormat, String descriptionString, String groupString) { name = nameString; inputFormat = inputTableFormat; outputFormat = outputTableFormat; description = descriptionString; group = groupString; }
protected override TableFormat decodeFormat(String source, CallerController <CallerData> caller) { if (source == null) { return(null); } var idSourceBuilder = new StringBuilder(); int i; for (i = 0; i < source.Length; i++) { var c = source[i]; if (Char.IsDigit(c)) { idSourceBuilder.Append(c); } else { break; } } source = source.Substring(i); var idSource = idSourceBuilder.ToString(); var formatIdNullable = idSource.Length > 0 ? int.Parse(idSource) : (int?)null; var format = source.Length > 0 ? new TableFormat(source, new ClassicEncodingSettings(false)) : null; if (formatIdNullable == null) { return(format); } var formatId = (int)formatIdNullable; if (format == null) { TableFormat cached = controller.getFormatCache().get(formatId); if (cached == null) { throw new ArgumentException("Unknown format ID: " + formatId); } return(cached); } controller.getFormatCache().put(formatId, format); return(format); }
public override DataTable decodeRemoteDataTable(TableFormat format, String encodedReply) { if (controller.isAvoidSendingFormats()) { if (format != null) { return(new DataTable(format, encodedReply)); } } return(new DataTable(encodedReply, controller.createClassicEncodingSettings(false), false)); }
protected TableFormat createTestTableFormat() { TableFormat format = new TableFormat(1, 1); FieldFormat ff = FieldFormat.create("name", FieldFormat.STRING_FIELD, "name", "default name"); ff.addValidator(NAME_SYNTAX_VALIDATOR); format.addField(ff); format.addField(FieldFormat.create("dt", FieldFormat.DATATABLE_FIELD, "dt", new DataTable())); format.addField(FieldFormat.create("float", FieldFormat.FLOAT_FIELD, "float", 1.5f)); format.setReorderable(true); return(format); }
public override object valueFromString(String value, ClassicEncodingSettings settings, Boolean validate) { try { DataTable defaultValue = (DataTable)getDefaultValue(); bool? tempEncodeFieldNames = null; TableFormat oldFormat = null; if (settings != null) { oldFormat = settings.getFormat(); if (defaultValue != null) { settings.setFormat(defaultValue.getFormat()); } tempEncodeFieldNames = settings.isEncodeFieldNames(); } else { settings = new ClassicEncodingSettings(false); tempEncodeFieldNames = false; } try { DataTable res = value != null ? new DataTable(value, settings, validate) : null; // TODO: add data replication and validation // if (defaultValue != null && defaultValue.getFieldCount() > 0 && !res.getFormat().extend(defaultValue.getFormat())) // { // DataTable newRes = (DataTable) defaultValue.Clone(); // DataTableReplication.copy(res, newRes, true, true, true); // } // if (res != null && validate) // { // res.validate(null, null, null); // } return(res); } finally { settings.setFormat(oldFormat); settings.setEncodeFieldNames((bool)tempEncodeFieldNames); } } catch (Exception ex) { throw new ArgumentException("Error constructing value of field '" + ToString() + "': " + ex.Message, ex); } }
public override DataTable getRemoteVariable(TableFormat format, String name) { var encodedReply = sendGetVariable(name).getEncodedDataTableFromReply(); try { return(decodeRemoteDataTable(format, encodedReply)); } catch (Exception ex) { throw new ContextException("Error parsing encoded data table: " + encodedReply, ex); } }
public static void Save(this DataTable table, Stream stream, TableFormat format) { switch (format) { case TableFormat.SerializedXml: { XmlSerializer serializer = new XmlSerializer(typeof(DataTable)); serializer.Serialize(stream, table); } break; case TableFormat.SerializedBin: { BinaryFormatter serializer = new BinaryFormatter(); serializer.Serialize(stream, table); } break; case TableFormat.Csv: { var writer = new CsvWriter(new StreamWriter(stream)); writer.Delimiter = ";"; writer.Write(table); } break; case TableFormat.Tsv: { var writer = new CsvWriter(new StreamWriter(stream)); writer.Delimiter = "\t"; writer.Write(table); } break; case TableFormat.CSharp: { var matrix = table.ToMatrix(); var str = matrix.ToString(CSharpMatrixFormatProvider.InvariantCulture); TextWriter writer = new StreamWriter(stream); writer.WriteLine(str); } break; case TableFormat.OctaveMatFile: case TableFormat.OpenDocument: case TableFormat.OlderExcel: case TableFormat.LibSVM: case TableFormat.Idx: throw new NotSupportedException(); } }
public override DataTable callRemoteFunction(String name, TableFormat outputFormat, DataTable parameters) { try { var ans = controller.sendCommandAndCheckReplyCode(ClientCommandUtils.callFunctionOperation(this.getPath(), name, parameters.encode(controller.createClassicEncodingSettings(true)))); return(decodeRemoteDataTable(outputFormat, ans.getEncodedDataTableFromReply())); } catch (Exception ex) { Log.CONTEXT_FUNCTIONS.debug("Error calling function '" + name + "' of context '" + this.getPath() + "'", ex); throw new ContextException(ex.Message, ex); } }
public static void Save(this double[][] matrix, Stream stream, TableFormat format) { switch (format) { case TableFormat.SerializedXml: { XmlSerializer serializer = new XmlSerializer(typeof(double[][])); serializer.Serialize(stream, matrix); } break; case TableFormat.SerializedBin: { BinaryFormatter serializer = new BinaryFormatter(); serializer.Serialize(stream, matrix); } break; case TableFormat.Csv: { var writer = new CsvWriter(new StreamWriter(stream)); writer.Delimiter = System.Convert.ToChar(";"); writer.Write(matrix); } break; case TableFormat.Tsv: { var writer = new CsvWriter(new StreamWriter(stream)); writer.Delimiter = System.Convert.ToChar("\t"); writer.Write(matrix); } break; case TableFormat.CSharp: { var str = matrix.ToString(CSharpMatrixFormatProvider.InvariantCulture); TextWriter writer = new StreamWriter(stream); writer.WriteLine(str); } break; case TableFormat.OctaveMatFile: case TableFormat.OpenDocument: case TableFormat.OlderExcel: case TableFormat.LibSVM: case TableFormat.Idx: throw new NotSupportedException(); } }
static PerformanceTestingAgent() { VFT_PERFORMANCE_TESTING = new TableFormat(1, 1); VFT_PERFORMANCE_TESTING.addField( "<" + VF_PERFORMANCE_TESTING_VARIABLE_COUNT + ">" + "<I>" + "<D=" + "Variable Count>" + "<A=" + DEFAULT_VARIABLE_COUNT + ">"); VFT_PERFORMANCE_TESTING.addField( "<" + VF_PERFORMANCE_TESTING_PERIOD + ">" + "<L>" + "<D=" + "Update Period" + ">" + "<E=" + LongFieldFormat.EDITOR_PERIOD + ">" + "<O=" + LongFieldFormat.encodePeriodEditorOptions(0 /*TimeHelper.MILLISECOND*/, 2 /*TimeHelper.MINUTE*/) + ">" + "<A=" + DEFAULT_PERIOD + ">"); }
public void testEqualsHashCode() { TableFormat tf1 = createTestTableFormat(); TableFormat tf2 = createTestTableFormat(); var fields1 = tf1.getFields(); var fields2 = tf2.getFields(); Assert.AreEqual(fields1[0].GetHashCode(), fields2[0].GetHashCode()); Assert.AreEqual(fields1[1].GetHashCode(), fields2[1].GetHashCode()); Assert.AreEqual(fields1[2].GetHashCode(), fields2[2].GetHashCode()); Assert.AreEqual(fields1.GetHashCode(), fields2.GetHashCode()); Assert.AreEqual(tf1, tf2); Assert.AreEqual(tf1.GetHashCode(), tf2.GetHashCode()); }
private static void ApplyTableFormat( this Range range, TableFormat tableFormat) { if (tableFormat == null) { return; } var implementedProperties = new[] { nameof(TableFormat.CellsFormat), }; tableFormat.ThrowOnNotImplementedProperty(implementedProperties); range.ApplyCellFormat(tableFormat.CellsFormat); }
public void TestCachedEncoding() { TableFormat tf = new TableFormat(1, 1); tf.addField(FieldFormat.FLOAT_FIELD, "value"); tf.addField(FieldFormat.INTEGER_FIELD, "quality"); DataTable nested = new DataTable(tf, 12345.67f, 123); ClassicEncodingSettings ces = new ClassicEncodingSettings(true); ces.setFormatCache(new FormatCache()); ces.setKnownFormatCollector(new KnownFormatCollector()); DataTable table = new DataTable(AbstractContext.EF_UPDATED, "test", nested, null); table.encode(ces); String encodedTable = table.encode(ces); String actual = "<D=0><R=<test><<D=0><R=<12345.67><123>>><<NULL>>>"; Assert.AreEqual(encodedTable, actual); }
public void testServerFormatCache() { TableFormat f1 = new TableFormat(format1, new ClassicEncodingSettings(true)); TableFormat f2 = new TableFormat(format2, new ClassicEncodingSettings(true)); FormatCache fc = new FormatCache(); int id = fc.add(f1); Assert.AreEqual(0, id); id = fc.add(f2); Assert.AreEqual(1, id); TableFormat res = fc.get(0); Assert.AreSame(f1, res); res = fc.get(1); Assert.AreSame(f2, res); TableFormat newf1 = new TableFormat(format1, new ClassicEncodingSettings(true)); res = fc.getCachedVersion(newf1); Assert.AreSame(f1, res); TableFormat newf2 = new TableFormat(format2, new ClassicEncodingSettings(true)); res = fc.getCachedVersion(newf2); Assert.AreSame(f2, res); }
public void Write(TableFormat tableFormat = TableFormat.Default) { switch (tableFormat) { case SimpleSharp.TableFormat.Default: Console.WriteLine(ToString()); break; case SimpleSharp.TableFormat.MarkDown: Console.WriteLine(ToMarkDownString()); break; case SimpleSharp.TableFormat.Alternative: Console.WriteLine(ToStringAlternative()); break; case SimpleSharp.TableFormat.Minimal: Console.WriteLine(ToMinimalString()); break; default: throw new ArgumentOutOfRangeException(nameof(tableFormat), tableFormat, null); } }
public void testEquals() { FieldFormat ff1 = FieldFormat.create("<value><I><A=0>"); ff1.addValidator(new LimitsValidator(5, 10)); TableFormat tf1 = ff1.wrap(); tf1.addRecordValidator(new KeyFieldsValidator()); tf1.addTableValidator(new TableKeyFieldsValidator()); FieldFormat ff2 = FieldFormat.create("<value><I><A=0>"); ff2.addValidator(new LimitsValidator(5, 10)); TableFormat tf2 = ff2.wrap(); tf2.addRecordValidator(new KeyFieldsValidator()); tf2.addTableValidator(new TableKeyFieldsValidator()); Assert.AreEqual(tf1, tf2); Assert.AreEqual(tf1.GetHashCode(), tf2.GetHashCode()); }
public void TestNestedTableEncoding() { string strdata = "test % %% %%% test"; TableFormat tf = new TableFormat(); FieldFormat ff = FieldFormat.create("strfield", FieldFormat.STRING_FIELD); ff.setDefault(strdata); tf.addField(ff); DataTable table = new DataTable(tf, strdata + "value"); DataTable wrapped = table; for (int i = 0; i < 2; i++) { TableFormat wtf = new TableFormat(); FieldFormat wff = FieldFormat.create("dtfield" + i, FieldFormat.DATATABLE_FIELD); wff.setDefault(wrapped); wtf.addField(wff); wrapped = new DataTable(wtf, wrapped); } string encoded = wrapped.encode(false); DataTable restored = new DataTable(encoded, new ClassicEncodingSettings(false), true); Assert.AreEqual(wrapped, restored); }
public static DataTable Load(Stream stream, TableFormat format) { switch (format) { case TableFormat.SerializedXml: { XmlSerializer serializer = new XmlSerializer(typeof(DataTable)); return (DataTable)serializer.Deserialize(stream); } case TableFormat.SerializedBin: { BinaryFormatter serializer = new BinaryFormatter(); return (DataTable)serializer.Deserialize(stream); } case TableFormat.OctaveMatFile: { MatReader reader = new MatReader(stream); return reader.Fields.First().Value.GetValue<double[,]>().ToTable(); } case TableFormat.OpenDocument: { ExcelReader reader = new ExcelReader(stream, true); string ws = reader.GetWorksheetList().First(); return reader.GetWorksheet(ws); } case TableFormat.OlderExcel: { ExcelReader reader = new ExcelReader(stream, false); string ws = reader.GetWorksheetList().First(); return reader.GetWorksheet(ws); } case TableFormat.Csv: { CsvReader reader = new CsvReader(stream, true); return reader.ToTable(); } case TableFormat.Tsv: { CsvReader reader = new CsvReader(stream, true, '\t'); return reader.ToTable(); } case TableFormat.LibSVM: { SparseReader reader = new SparseReader(stream); return reader.ToTable(); } case TableFormat.Idx: { IdxReader reader = new IdxReader(stream); return reader.ReadToEndAsVectors().ToTable(); } case TableFormat.CSharp: throw new NotSupportedException(); } }