public bool VerifyAddInvalidHedgeRowResident() { try { var acDoc = Application.DocumentManager.MdiActiveDocument; var acCurDb = acDoc.Database; using (var acTrans = acDoc.TransactionManager.StartTransaction()) { var acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; if (acBlkTbl == null) { throw new Exception("Null BlockTable"); } var acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; if (acBlkTblRec == null) { throw new Exception("Null BlockTable"); } var acPoly = new Polyline(); acPoly.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0); acPoly.AddVertexAt(1, new Point2d(0, 1), 0, 0, 0); acPoly.AddVertexAt(2, new Point2d(1, 1), 0, 0, 0); var polyId = acBlkTblRec.AppendEntity(acPoly); acTrans.AddNewlyCreatedDBObject(acPoly, true); var hedge = new HedgeRow { Phase = Phase.Proposed, Species = "EnglishElm", TreeType = TreeType.Deciduous, WaterDemand = WaterDemand.High, ActualHeight = Tree.DeciduousHigh["EnglishElm"], ID = "invalid-hedge", BaseObject = polyId }; var ds = DataService.Current; ds.InvalidateStoreTypes(); var treeRingManager = ds.GetStore <StructureDocumentStore>(acDoc.Name).GetManager <TreeRingManager>(); var count = treeRingManager.ActiveObjects.Count; treeRingManager.AddTree(hedge); treeRingManager.UpdateAll(); acTrans.Commit(); bool hedgeAdded = treeRingManager.ActiveObjects.Count == count + 1; bool ringsNotPresent = treeRingManager.RingsCollection.Count == 0; return(hedgeAdded && ringsNotPresent); } } catch (Exception) { return(false); } }
public bool VerifyDrawRingPolylineLengthResident(double length) { try { var acDoc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; var acCurDb = acDoc.Database; using (var acTrans = acDoc.TransactionManager.StartTransaction()) { var acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; if (acBlkTbl == null) { throw new Exception("Null BlockTable"); } var acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; if (acBlkTblRec == null) { throw new Exception("Null BlockTable"); } var acPoly = new Polyline(); acPoly.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0); acPoly.AddVertexAt(1, new Point2d(0, length), 0, 0, 0); acPoly.AddVertexAt(2, new Point2d(length, length), 0, 0, 0); var polyId = acBlkTblRec.AppendEntity(acPoly); acTrans.AddNewlyCreatedDBObject(acPoly, true); var hedge = new HedgeRow { Phase = Phase.Proposed, Species = "EnglishElm", TreeType = TreeType.Deciduous, WaterDemand = WaterDemand.High, ActualHeight = Tree.DeciduousHigh["EnglishElm"], ID = "test-hedge", BaseObject = polyId }; var _ = hedge.DrawShape(0.9, Shrinkage.High) as Polyline; return(false); } } catch (ArgumentException argEx) { return(argEx.Message == "No offset curve created."); } catch (Exception) { return(false); } }
public bool VerifyGenerateValidationNotRemovedResident() { var acDoc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; var acCurDb = acDoc.Database; using (var acTrans = acDoc.TransactionManager.StartTransaction()) { var acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; if (acBlkTbl == null) { return(false); } var acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; if (acBlkTblRec == null) { return(false); } var acPoly = new Polyline(); acPoly.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0); acPoly.AddVertexAt(1, new Point2d(0, 50), 0, 0, 0); acPoly.AddVertexAt(2, new Point2d(50, 100), 0, 0, 0); acPoly.AddVertexAt(3, new Point2d(100, 100), 0, 0, 0); var polyId = acBlkTblRec.AppendEntity(acPoly); acTrans.AddNewlyCreatedDBObject(acPoly, true); var hedge = new HedgeRow { Phase = Phase.Existing, Species = "WHITeWillow", TreeType = TreeType.Deciduous, WaterDemand = WaterDemand.High, ActualHeight = Tree.DeciduousHigh["WHITeWillow"], ID = "test-hedge", BaseObject = polyId }; hedge.Generate(); return(acPoly.NumberOfVertices == 4); } }
public double VerifyDrawRingElevationResident(double elevation) { var acDoc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; var acCurDb = acDoc.Database; using (var acTrans = acDoc.TransactionManager.StartTransaction()) { var acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; if (acBlkTbl == null) { return(-1); } var acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; if (acBlkTblRec == null) { return(-1); } var acPoly = new Polyline(); acPoly.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0); acPoly.AddVertexAt(1, new Point2d(0, 50), 0, 0, 0); acPoly.AddVertexAt(2, new Point2d(50, 50), 0, 0, 0); acPoly.Elevation = elevation; var polyId = acBlkTblRec.AppendEntity(acPoly); acTrans.AddNewlyCreatedDBObject(acPoly, true); var hedge = new HedgeRow { Phase = Phase.Proposed, Species = "EnglishElm", TreeType = TreeType.Deciduous, WaterDemand = WaterDemand.High, ActualHeight = Tree.DeciduousHigh["EnglishElm"], ID = "test-hedge", BaseObject = polyId }; var shape = hedge.DrawShape(0.9, Shrinkage.High) as Polyline; return(shape == null ? -1 : shape.Elevation); } }
public static List <string> HedgeStrategyAgainstDelta(string alias, string deltaAlias, MySqlConnection conn, DataTable priceTable) { DataTable HedgeTable = GetHedge4Strategy(alias: alias, conn: conn, priceTable: priceTable); List <string> HedgeNotes = new List <string>(); DataRow[] HedgeRows = HedgeTable.Select("Hedge<>0"); if (HedgeRows.Count() == 0) { HedgeNotes.Add(alias + ": No hedge necessary"); return(HedgeNotes); } DataTable Trades2Enter = new DataTable(); Trades2Enter.Columns.Add("ticker", typeof(string)); Trades2Enter.Columns.Add("option_type", typeof(string)); Trades2Enter.Columns.Add("strike_price", typeof(decimal)); Trades2Enter.Columns.Add("trade_price", typeof(decimal)); Trades2Enter.Columns.Add("trade_quantity", typeof(decimal)); Trades2Enter.Columns.Add("instrument", typeof(string)); Trades2Enter.Columns.Add("real_tradeQ", typeof(bool)); Trades2Enter.Columns.Add("alias", typeof(string)); foreach (DataRow HedgeRow in HedgeRows) { DataRow TradesRow = Trades2Enter.NewRow(); TradesRow["ticker"] = HedgeRow.Field <string>("Ticker"); TradesRow["trade_price"] = HedgeRow.Field <decimal>("HedgePrice"); TradesRow["trade_quantity"] = HedgeRow.Field <decimal>("Hedge"); TradesRow["instrument"] = "F"; TradesRow["real_tradeQ"] = true; TradesRow["alias"] = alias; Trades2Enter.Rows.Add(TradesRow); } bool loadResult = TA.Strategy.LoadTrades2Strategy(tradesTable: Trades2Enter, alias: alias, conn: conn); if (!loadResult) { HedgeNotes.Add(alias + ": Hedge trades cannot be loaded to the strategy"); return(HedgeNotes); } Trades2Enter.Columns["alias"].Expression = "'" + deltaAlias + "'"; foreach (DataRow Row in Trades2Enter.AsEnumerable()) { Row["trade_quantity"] = -1 * Row.Field <decimal>("trade_quantity"); } loadResult = TA.Strategy.LoadTrades2Strategy(tradesTable: Trades2Enter, alias: alias, conn: conn); if (!loadResult) { HedgeNotes.Add(alias + ": Hedge trades cannot be loaded to the delta"); return(HedgeNotes); } return(HedgeNotes); }