public DataCellCollection Resolve(DataCellCollection SourceRow, Column currentColumn, DataCellCollection outRowCollection, Dictionary <string, string> steps, Dictionary <string, string> context) { string currVal = string.Empty; string peviousCol = string.Empty; string peviousSource = string.Empty; List <DataCell> dataCells = new List <DataCell>(); string destColumn = currentColumn.Name; KeyValuePair <string, string> prevItem = new KeyValuePair <string, string>(); foreach (KeyValuePair <string, string> item in steps) { if (this._dataMappers.ContainsKey(item.Key)) { dataCells.AddRange(this._dataMappers[item.Key].Map(SourceRow, currentColumn.Name, currVal, context, outRowCollection)); } if (item.Key == Constants.SourceColKey) { for (int i = 0; i < SourceRow.Cells.Count; i++) { if (item.Value == SourceRow.Cells[i].Column.Name) { currVal = SourceRow.Cells[i].Value; break; } } } if (this._globalLookUpCollection.ContainsKey(item.Key)) { if (this._mappingRulesCollection.ContainsKey(GetMappingRuleKey(item, prevItem))) { currVal = this.ApplyMappingRule(currVal, item, prevItem, (mappingItem) => this._globalLookUpCollection[item.Key].LookUp(item.Key, item.Value, mappingItem)); } else { currVal = this._globalLookUpCollection[item.Key].LookUp(item.Key, item.Value, currVal); } } //if (currentColumn.Name == item.Value) //{ // outRowCollection.Cells.Add(new DataCell(new Column { Name = item.Key }, "", currVal)); //} prevItem = item; } if (dataCells.Count == 0) { outRowCollection.Cells.Add(new DataCell(new Column { Name = currentColumn.Name }, "", currVal)); } else { outRowCollection.Cells.AddRange(dataCells); } return(outRowCollection); }
public void Map_StateUnderTest_ExpectedBehavior_Longitude() { // Arrange DegreeToDecimalLatLongMapper degreeToDecimalLatLongMapper = this.CreateDegreeToDecimalLatLongMapper(); DataCellCollection sourceRows = new DataCellCollection(); sourceRows.Add(new DataCell(new LumenWorks.Framework.IO.Csv.Column() { Name = Constants.columnkey }, "", "3519S 14804E")); string columnkey = Constants.longitudeKey; string value = "3519S 14804E"; DataCellCollection currentState = new DataCellCollection(); Dictionary <string, string> Context = new Dictionary <string, string>(); // Act List <DataCell> result = degreeToDecimalLatLongMapper.Map( sourceRows, columnkey, value, Context, currentState); // Assert 148.066666666667 Assert.IsTrue(result.Count == 1); Assert.IsTrue(result[0].Value == "148.066666666667"); }
public ObjectId CreateZBDic() { ObjectId TableID = ObjectId.Null; const string DicName = "GCLZBConfig"; using (Transaction trans = db.TransactionManager.StartTransaction()) { try { DBDictionary dd = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead); if (dd.Contains(DicName)) { TableID = dd.GetAt(DicName); } else { DataTable dt = new DataTable(); dt.TableName = DicName; dt.AppendColumn(CellType.Double, "TextHeight"); dt.AppendColumn(CellType.Integer, "HeightOderOfMagnitude"); DataCellCollection Row = new DataCellCollection(); DataCell TH = new DataCell(); DataCell HM = new DataCell(); PromptDoubleOptions doubleopts = new PromptDoubleOptions("\n输入字高:"); doubleopts.AllowNegative = false; doubleopts.AllowZero = false; PromptDoubleResult doubleresult = ed.GetDouble(doubleopts); if (doubleresult.Status == PromptStatus.OK) { TH.SetDouble(doubleresult.Value); PromptIntegerOptions intopts = new PromptIntegerOptions("\n输入高程数量级(高程在10以内为0,100以内为1,以此类推):"); intopts.AllowNegative = false; PromptIntegerResult intresult = ed.GetInteger(intopts); if (intresult.Status == PromptStatus.OK) { HM.SetInteger(intresult.Value); Row.Add(TH); Row.Add(HM); dt.AppendRow(Row, true); dd.UpgradeOpen(); TableID = dd.SetAt(DicName, dt); trans.AddNewlyCreatedDBObject(dt, true); } } } } catch (Autodesk.AutoCAD.Runtime.Exception EX) { ed.WriteMessage("出错了!" + EX.ToString()); } trans.Commit(); } return(TableID); }
public void LookUp_StateUnderTest_ExpectedBehavior() { // Arrange this.mockDataSource.Setup((ctx) => ctx.GetHeaders()).Returns(new string[] { "col1", "col2" }); DataCell cell1 = new DataCell(new Column() { Name = "col1" }, "", "val1"); DataCell cell2 = new DataCell(new Column() { Name = "col2" }, "", "val2"); DataCell cell3 = new DataCell(new Column() { Name = "col1" }, "", "val3"); DataCell cell4 = new DataCell(new Column() { Name = "col2" }, "", "val4"); DataCellCollection row1 = new DataCellCollection { Cells = new List <DataCell> { cell1, cell2 } }; DataCellCollection row2 = new DataCellCollection { Cells = new List <DataCell> { cell3, cell4 } }; List <DataCellCollection> rows = new List <DataCellCollection>() { row1, row2 }; this.mockDataSource.Setup((ctx) => ctx.GetDataRowEntries()).Returns(rows); DataLookUpCollection dataLookUpCollection = this.CreateDataLookUpCollection(); string keyColumn = "col1"; string valueColumn = "col2"; string key = "val1"; // Act string result = dataLookUpCollection.LookUp( keyColumn, valueColumn, key); // Assert Assert.IsTrue(result == "val2"); }
private DataCellCollection BuildRow(string[] items) { DataCellCollection row = new DataCellCollection(); if (items.Length != this.Columns.Count) { this._logger.Log($"Columns & Values are not same {string.Join(",",items) }", EventLevel.Error, new DataMisalignedException("Columns & Values are not same")); // return row; } for (int i = 0; i < this.Columns.Count && i < items.Length; i++) { row.Add(new DataCell(this.Columns[i], "", items[i])); } return(this._dataCleaner.CleanRow(row)); }
public void ChangeZBConfig(ObjectId tableID) { DataCellCollection Row = new DataCellCollection(); DataCell TH = new DataCell(); DataCell HM = new DataCell(); using (Transaction trans = db.TransactionManager.StartTransaction()) { try { DataTable dt = (DataTable)trans.GetObject(tableID, OpenMode.ForWrite); PromptDoubleOptions doubleopts = new PromptDoubleOptions("\n输入字高:"); doubleopts.AllowNone = true; doubleopts.AllowNegative = false; doubleopts.AllowZero = false; doubleopts.UseDefaultValue = true; doubleopts.DefaultValue = (double)dt.GetCellAt(0, 0).Value; PromptDoubleResult doubleresult = ed.GetDouble(doubleopts); if (doubleresult.Status == PromptStatus.OK || doubleresult.Status == PromptStatus.None) { TH.SetDouble(doubleresult.Value); PromptIntegerOptions intopts = new PromptIntegerOptions("\n输入高程数量级(高程在10以内为0,100以内为1,以此类推):"); intopts.AllowNone = true; intopts.AllowNegative = false; intopts.UseDefaultValue = true; intopts.DefaultValue = (int)dt.GetCellAt(0, 1).Value; PromptIntegerResult intresult = ed.GetInteger(intopts); if (intresult.Status == PromptStatus.OK || intresult.Status == PromptStatus.None) { HM.SetInteger(intresult.Value); Row.Add(TH); Row.Add(HM); dt.SetRowAt(0, Row, true); } } } catch (Autodesk.AutoCAD.Runtime.Exception EX) { ed.WriteMessage("出错了!" + EX.ToString()); } trans.Commit(); } }
public void cmdAddDataTableData() { var doc = AcApp.DocumentManager.MdiActiveDocument; var ed = doc.Editor; var db = doc.Database; var result = ed.GetEntity("\nPlease select an entity to store data"); if (result.Status != PromptStatus.OK) { return; } using (var tr = db.TransactionManager.StartTransaction()) { var entity = tr.GetObject(result.ObjectId, OpenMode.ForWrite) as Entity; if (entity.ExtensionDictionary.IsNull) { entity.CreateExtensionDictionary(); } var extDictId = entity.ExtensionDictionary; var extDict = tr.GetObject(extDictId, OpenMode.ForWrite) as DBDictionary; var dataTable = new DataTable(); dataTable.AppendColumn(CellType.Integer, "IntValue"); dataTable.AppendColumn(CellType.CharPtr, "Text"); var rowData = new DataCellCollection(); var intValue = new DataCell(); intValue.SetInteger(123); rowData.Add(intValue); var textValue = new DataCell(); textValue.SetString("this is a text"); rowData.Add(textValue); dataTable.AppendRow(rowData, true); extDict["MyData"] = dataTable; tr.AddNewlyCreatedDBObject(dataTable, true); tr.Commit(); } }
public void AddData() { DataTable dt = new DataTable(); dt.TableName = "ParameterTable"; dt.AppendColumn(CellType.CharPtr, "Name"); dt.AppendColumn(CellType.CharPtr, "Meterial"); dt.AppendColumn(CellType.CharPtr, "Parameter"); DataCellCollection Row = new DataCellCollection(); DataCell Name = new DataCell(); DataCell Meterial = new DataCell(); DataCell Parameter = new DataCell(); Name.SetString("工字钢"); Meterial.SetString("Q235B"); Parameter.SetString("200*200*32*25"); Row.Add(Name); Row.Add(Meterial); Row.Add(Parameter); dt.AppendRow(Row, true); Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; PromptEntityResult ent = ed.GetEntity("\n选择要写数据的对象"); if (ent.Status == PromptStatus.OK) { using (Transaction tr = db.TransactionManager.StartTransaction()) { Entity entity = (Entity)tr.GetObject(ent.ObjectId, OpenMode.ForWrite, true); if (entity.ExtensionDictionary == new ObjectId()) { entity.CreateExtensionDictionary(); } DBDictionary extensionDic = (DBDictionary)tr.GetObject(entity.ExtensionDictionary, OpenMode.ForWrite, false); extensionDic.SetAt("ParameterTable", dt); tr.Commit(); } } }
public ObjectId InitialSave() { ObjectId TableID = ObjectId.Null; using (Transaction trans = db.TransactionManager.StartTransaction()) { try { DBDictionary dd = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead); if (dd.Contains(SaveName)) { TableID = dd.GetAt(SaveName); } else { DataTable dt = new DataTable(); dt.TableName = SaveName; dt.AppendColumn(CellType.Integer, SaveKey); DataCellCollection Row = new DataCellCollection(); DataCell Cell = new DataCell(); Cell.SetInteger(InitialNum); Row.Add(Cell); dt.AppendRow(Row, true); dd.UpgradeOpen(); TableID = dd.SetAt(SaveName, dt); trans.AddNewlyCreatedDBObject(dt, true); } trans.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception EX) { ed.WriteMessage("\n出错了!{0}", EX.ToString()); } finally { trans.Dispose(); } } return(TableID); }
public DataCellCollection CleanRow(DataCellCollection result) { if (this.rowCleanCfg.Count > 0) { foreach (DataCell item in result.Cells) { if (this.rowCleanCfg.ContainsKey(item.Column.Name)) { string colName = item.Column.Name; switch (this.rowCleanCfg[colName].Key) { case "filter-for-symbol": Regex regEx = new Regex(this.rowCleanCfg[colName].Value); MatchCollection matches = regEx.Matches(item.Value); item.Value = string.Join("", matches.Select(m => m.Value).ToArray()); break; case "remove-symbols": string[] symbols = this.rowCleanCfg[colName].Value.Split(' '); for (int i = 0; i < symbols.Length; i++) { item.Value = item.Value.Replace(symbols[i], ""); } break; case "replace-symbol": symbols = this.rowCleanCfg[colName].Value.Split(' '); item.Value = item.Value.Replace(symbols[0], symbols[1]); break; default: break; } } } } return(result); }
private string createFlag(Document doc) { string dbnamestr = null; Database db = doc.Database; DBPoint flag = null; //创建点 using (Transaction tm = db.TransactionManager.StartTransaction()) { flag = new DBPoint(new Point3d(0, 0, 0)); flag.Layer = "-735"; flag.Visible = false; BlockTable bt = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false); btr.AppendEntity(flag); tm.AddNewlyCreatedDBObject(flag, true); tm.Commit(); } ////扩展数据 Guid guid = Guid.NewGuid(); DataTable dt = new DataTable(); dt.TableName = "database flag"; dt.AppendColumn(CellType.Bool, "hasDatabase"); dt.AppendColumn(CellType.CharPtr, "databaseName"); DataCellCollection row = new DataCellCollection(); DataCell hasDatabase = new DataCell(); DataCell databaseName = new DataCell(); hasDatabase.SetBool(true); dbnamestr = guid.ToString(); databaseName.SetString(dbnamestr); row.Add(hasDatabase); row.Add(databaseName); dt.AppendRow(row, true); using (Transaction tm = db.TransactionManager.StartTransaction()) { Entity entity = (Entity)tm.GetObject(flag.ObjectId, OpenMode.ForWrite, false); if (entity.ExtensionDictionary == new ObjectId()) { entity.CreateExtensionDictionary(); } DBDictionary extensionDic = (DBDictionary)tm.GetObject(flag.ExtensionDictionary, OpenMode.ForWrite, false); extensionDic.SetAt("database flag", dt); tm.AddNewlyCreatedDBObject(dt, true); ////锁定,冻结图层 LayerTable lt = (LayerTable)tm.GetObject(db.LayerTableId, OpenMode.ForRead, false); LayerTableRecord ltr = (LayerTableRecord)tm.GetObject(lt["-735"], OpenMode.ForWrite, false); ltr.IsFrozen = true; tm.Commit(); } return(dbnamestr); }
public bool PerformTransformation() { int ingestRowsCount = 0; int egressRowsCount = 0; // Console.Clear(); using (IDataSource dataSource = this._dataSourceFactory.GetDataSource(this._runtimeSettings.DataSourceFileName)) { using (IDataSink dataSink = this._dataSinkFactory.GetDataSink(this._runtimeSettings.DataSinkFileName, this._runtimeSettings.OutConfigFileName)) { string[] rowValues = new string[dataSink.Columns.Length]; Dictionary <string, string> context = new Dictionary <string, string>(); foreach (DataCellCollection row in dataSource.GetDataRowEntries()) { ingestRowsCount += 1; DataCellCollection outRowCollection = new DataCellCollection(); for (int i = 0; i < dataSink.Columns.Length; i++) { Dictionary <string, string> steps = this._toSinkDataChainBuilder.GetSteps(dataSink.Columns[i]); try { outRowCollection = this._dataMapHandler.Resolve(row, new Column() { Name = dataSink.Columns[i] }, outRowCollection, steps, context); } catch (Exception ex) { this._logger.Log($"resolving failed for {dataSink.Columns[i]} \n raw row data {row.Cells.Select(c => $"{c.Column.Name}: {c.Value}").ToArray()}", EventLevel.Error, ex); } } if (outRowCollection.Cells.Count != dataSink.Columns.Length) { this._logger.Log($"resolving failed for raw row data {row.Cells.Select(c => $"{c.Column.Name}: {c.Value}").ToArray()}", EventLevel.Error); continue; } dataSink.AddRecordsToSink(outRowCollection.Cells); egressRowsCount += 1; this.ShowProgress(egressRowsCount); } } } this._logger.LogInformation($"Processing Compeleted"); this._logger.LogInformation($"Ingest = {ingestRowsCount} egress={egressRowsCount}"); this._logger.LogInformation($"Initiating Post Run Analysis "); egressRowsCount = 0; using (StreamReader stream = new StreamReader(this._diskIOHandler.FileReadTextStream(this._runtimeSettings.DataSinkFileName))) { // int headerCount = CsvParseHelper.GetAllFields(stream.ReadLine()).Length; while (stream.EndOfStream == false) { string line = stream.ReadLine(); //int cellcount = CsvParseHelper.GetAllFields(line).Length; //if (cellcount != headerCount) //{ // this._logger.Log($"Error Data Alignment mismatch cellcount {cellcount } != headerCount {headerCount } att position {textLines} , line :{line}", EventLevel.Error); // noError++; //} //textLines += 1; this.ShowProgress(egressRowsCount++); } } this._logger.LogInformation($"\nPost Analysis Completed egress={--egressRowsCount}"); this._logger.LogInformation($"\nYour output is ready : {this._runtimeSettings.DataSinkFileName}"); return(ingestRowsCount == egressRowsCount); }
public ObjectId CreateCeDic() //创建存储于NameObjectsDictionary的DataTable用于保存程序设置 //弯管类型存储在(0,0),半径在(0,1),半径倍率在(0,2),字高在(0,3),是否显示节点坐标(0,4) { const string dicname = "GCLCurveElementsConfig"; ObjectId DicId = ObjectId.Null; using (Transaction trans = db.TransactionManager.StartTransaction()) { try { DBDictionary dd = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead); if (dd.Contains(dicname)) { DicId = dd.GetAt(dicname); } else { DataTable dt = new DataTable(); dt.TableName = dicname; dt.AppendColumn(CellType.Integer, "Type"); dt.AppendColumn(CellType.Double, "Diameter"); dt.AppendColumn(CellType.Double, "DiameterMultiple"); dt.AppendColumn(CellType.Double, "TextH"); DataCellCollection Row = new DataCellCollection(); DataCell Type = new DataCell(); DataCell Diameter = new DataCell(); DataCell DiameterMultiple = new DataCell(); DataCell TextH = new DataCell(); PromptKeywordOptions keyopts = new PromptKeywordOptions("\n输入弯管的类型[冷弯(C)/热煨(H)/弹性敷设(E)]:", "C H E"); PromptResult keyresult = ed.GetKeywords(keyopts); if (keyresult.Status == PromptStatus.OK) { switch (keyresult.StringResult) { case "C": Type.SetInteger((int)TypeOfCurveElements.cold); break; case "H": Type.SetInteger((int)TypeOfCurveElements.hot); break; case "E": Type.SetInteger((int)TypeOfCurveElements.elastic); break; } PromptDoubleOptions doubleopts = new PromptDoubleOptions("\n输入弯管外径(mm):"); doubleopts.AllowNegative = false; doubleopts.AllowZero = false; PromptDoubleResult doubleresult = ed.GetDouble(doubleopts); if (doubleresult.Status == PromptStatus.OK) { Diameter.SetDouble(doubleresult.Value); doubleopts.Message = "\n输入管径倍率:"; doubleresult = ed.GetDouble(doubleopts); if (doubleresult.Status == PromptStatus.OK) { DiameterMultiple.SetDouble(doubleresult.Value); doubleopts.Message = "\n输入字高:"; doubleresult = ed.GetDouble(doubleopts); if (doubleresult.Status == PromptStatus.OK) { TextH.SetDouble(doubleresult.Value); Row.Add(Type); Row.Add(Diameter); Row.Add(DiameterMultiple); Row.Add(TextH); dt.AppendRow(Row, true); dd.UpgradeOpen(); DicId = dd.SetAt(dicname, dt); trans.AddNewlyCreatedDBObject(dt, true); } } } } } trans.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception EX) { ed.WriteMessage("\n出错了!" + EX.ToString()); } } return(DicId); }
public void ChangeConfig(ObjectId tableID) //修改程序设置信息 { DataCellCollection Row = new DataCellCollection(); DataCell Type = new DataCell(); DataCell Diameter = new DataCell(); DataCell DiameterMultiple = new DataCell(); DataCell TextH = new DataCell(); using (Transaction trans = db.TransactionManager.StartTransaction()) { try { DataTable dt = (DataTable)trans.GetObject(tableID, OpenMode.ForWrite); PromptKeywordOptions keyopts = new PromptKeywordOptions("\n输入弯管的类型[冷弯(C)/热煨(H)/弹性敷设(E)]:", "C H E"); keyopts.AllowNone = true; switch ((int)dt.GetCellAt(0, 0).Value) { case 1: keyopts.Keywords.Default = "C"; break; case 2: keyopts.Keywords.Default = "H"; break; case 3: keyopts.Keywords.Default = "E"; break; } PromptResult keyresult = ed.GetKeywords(keyopts); if (keyresult.Status == PromptStatus.OK || keyresult.Status == PromptStatus.None) { switch (keyresult.StringResult) { case "C": Type.SetInteger((int)TypeOfCurveElements.cold); break; case "H": Type.SetInteger((int)TypeOfCurveElements.hot); break; case "E": Type.SetInteger((int)TypeOfCurveElements.elastic); break; } PromptDoubleOptions doubleopts = new PromptDoubleOptions("\n输入弯管外径(mm):"); doubleopts.AllowNone = true; doubleopts.AllowNegative = false; doubleopts.AllowZero = false; doubleopts.UseDefaultValue = true; doubleopts.DefaultValue = (double)dt.GetCellAt(0, 1).Value; PromptDoubleResult doubleresult = ed.GetDouble(doubleopts); if (doubleresult.Status == PromptStatus.OK || doubleresult.Status == PromptStatus.None) { Diameter.SetDouble(doubleresult.Value); doubleopts.Message = "\n输入管径倍率:"; doubleopts.DefaultValue = (double)dt.GetCellAt(0, 2).Value; doubleresult = ed.GetDouble(doubleopts); if (doubleresult.Status == PromptStatus.OK || doubleresult.Status == PromptStatus.None) { DiameterMultiple.SetDouble(doubleresult.Value); doubleopts.Message = "\n输入字高:"; doubleopts.DefaultValue = (double)dt.GetCellAt(0, 3).Value; doubleresult = ed.GetDouble(doubleopts); if (doubleresult.Status == PromptStatus.OK || doubleresult.Status == PromptStatus.None) { TextH.SetDouble(doubleresult.Value); Row.Add(Type); Row.Add(Diameter); Row.Add(DiameterMultiple); Row.Add(TextH); dt.SetRowAt(0, Row, true); } } } } } catch (Autodesk.AutoCAD.Runtime.Exception EX) { ed.WriteMessage("\n出错了!" + EX.ToString()); } trans.Commit(); } }