public Projectile(Vector3 location, Spell spell, Single direction, Single angle, ArenaPlayer owner) { Spell = spell; Location = location; Direction = direction; Velocity = spell.Velocity; Angle = angle; Size = new Vector3(spell.Width * 0.5f, spell.Width, spell.Tall); Single zRadians = MathHelper.DegreesToRadians(Angle); Single cosZRadians = (Single)Math.Cos(zRadians); Location.X += -(((Single)Math.Sin(Direction) + (Size.X * 0.5f)) * cosZRadians); Location.Y += (Single)Math.Sin(Direction) * cosZRadians; if (zRadians < 0) { Location.Z += Math.Abs(zRadians * 4f) + 4f; } Owner = owner; Team = owner.ActiveTeam; GravityStepDelta = 0; GravityStepCount = 0; DistanceTicks = new TickCounter(30, 50); Duration = new Interval(Spell.DurationTimer, false); BoundingBox = new OrientedBoundingBox(Location, Size, direction); OriginalOrigin = BoundingBox.Origin; OriginalAngle = Angle; }
public void TestTickCounter() { var start = new TickCounter(); Assert.IsTrue(TickCounter.MaxDelta.DeltaToNowMilliseconds > 0); var maxd = TickCounter.MaxDelta; System.Threading.Thread.Sleep(200); Assert.IsTrue(maxd.DeltaToNowMilliseconds > 0); Assert.IsTrue(maxd.DeltaToNowMilliseconds > int.MaxValue / 2); Assert.IsTrue(start.DeltaToNowMilliseconds > 0); Assert.IsTrue(Math.Round((TickCounter.Now - start).ToSeconds / 3f) == Math.Round((float)start.DeltaToNowSeconds / 3f)); var start_copy = new TickCounter(start.Ticks); System.Threading.Thread.Sleep(BufUtils.RandomInt(300) + 200); var startdelta = start.DeltaToNowMilliseconds; var now1 = new TickCounter(); Assert.IsTrue(start.ToString().Length > 0); Assert.IsTrue((now1 - start).ToMilliseconds > 0); Assert.IsTrue(((now1 - start).ToMilliseconds) / 100 == startdelta / 100); }
public RowItem Pivot(TickCounter tickCounter, RowItem rowItem) { foreach (var pivotColumn in PivotColumns) { var parent = pivotColumn.Parent.CollectionAncestor(); IList <PivotKey> pivotKeys; if (null == parent) { pivotKeys = new PivotKey[] { null }; } else { pivotKeys = rowItem.PivotKeys.Where(key => key.Last.Key.Equals(parent.PropertyPath)).ToArray(); } foreach (var pivotKey in pivotKeys) { var parentValue = pivotColumn.Parent.GetPropertyValue(rowItem, pivotKey); if (null != parentValue) { var keys = pivotColumn.CollectionInfo.GetKeys(parentValue).Cast <object>().ToArray(); if (keys.Length > 0) { var newPivotKeys = rowItem.PivotKeys.Except(new[] { pivotKey }).ToList(); var pivotKeyLocal = pivotKey ?? PivotKey.EMPTY; var propertyPath = pivotColumn.PropertyPath; newPivotKeys.AddRange(keys.Select(key => pivotKeyLocal.AppendValue(propertyPath, key))); rowItem = rowItem.SetPivotKeys(new HashSet <PivotKey>(newPivotKeys)); } } } } return(rowItem); }
public IEnumerable <RowItem> Expand(TickCounter tickCounter, RowItem rowItem, int sublistColumnIndex) { if (sublistColumnIndex >= SublistColumns.Count) { return(new[] { rowItem }); } var sublistColumn = SublistColumns[sublistColumnIndex]; object parentValue = sublistColumn.Parent.GetPropertyValue(rowItem, null); if (null == parentValue) { return(new[] { rowItem }); } var items = sublistColumn.CollectionInfo.GetItems(parentValue).Cast <object>().ToArray(); if (items.Length == 0) { return(new[] { rowItem }); } IList <object> keys = null; if (sublistColumn.CollectionInfo.IsDictionary) { keys = sublistColumn.CollectionInfo.GetKeys(parentValue).Cast <object>().ToArray(); } var expandedItems = new List <RowItem>(); for (int index = 0; index < items.Length; index++) { object key = keys == null ? index : keys[index]; var child = rowItem.SetRowKey(rowItem.RowKey.AppendValue(sublistColumn.PropertyPath, key)); expandedItems.AddRange(Expand(tickCounter, child, sublistColumnIndex + 1)); } return(expandedItems); }
// Start is called before the first frame update void Start() { // Get reference to sprite renderer. _SpriteR = gameObject.GetComponent <SpriteRenderer>(); // Set animation counter rate. _TickerCounter = new TickCounter(_AnimateOnTicksForEugene); }
void DeliveryStatusReceived(DeliveryStatusMessage dsmsg) { GarlicCreationInfo info; lock ( OutstandingMessageIds ) { info = OutstandingMessageIds[dsmsg.MessageId]; if (info == null) { /* * DebugUtils.LogDebug( string.Format( "TagsTransferWindow: DeliveryStatusReceived: Non matching status message MsgId: {0}.", * dsmsg.MessageId ) ); */ return; } OutstandingMessageIds.Remove(dsmsg.MessageId); } lock ( Window ) { Window.Remove(info.TrackingId); } DebugUtils.LogDebug(string.Format("TagsTransferWindow: DeliveryStatusReceived: Received ACK MsgId: {0} TrackingId: {1}. {2}", dsmsg.MessageId, info.TrackingId, info.Created.DeltaToNow)); if (WaitingForEGAck != null && info.KeyType == GarlicCreationInfo.KeyUsed.ElGamal && dsmsg.MessageId == LatestEGMessage.AckMessageId) { WaitingForEGAck = null; // Aes messages sent after this can be decrypted, hopefully. // Send them one more time. /* * lock ( OutstandingMessageIds ) * { * var remove = OutstandingMessageIds.Where( gci => gci.Value.KeyType == GarlicCreationInfo.KeyUsed.Aes && * !gci.Value.AckMessageId.HasValue && gci.Value.EGAckMessageId == dsmsg.MessageId ); * foreach ( var one in remove.ToArray() ) * { * OutstandingMessageIds.Remove( one.Key ); * } * } * * lock ( Window ) * { * var remove = Window.Where( gci => gci.Value.KeyType == GarlicCreationInfo.KeyUsed.Aes && * !gci.Value.AckMessageId.HasValue && gci.Value.EGAckMessageId == dsmsg.MessageId ); * foreach ( var one in remove.ToArray() ) * { * Window.Remove( one.Key ); * } * } */ } MessageAckEvent(info); }
private void UpdateSSUReportedAddr(IPAddress ipaddr) { if (LastIPReport?.DeltaToNow.ToMinutes < 30) { return; } if (LastIPReport == null) { LastIPReport = new TickCounter(); } LastIPReport.SetNow(); MyRouterContext.SSUReportedAddr(ipaddr); }
public PivotedRows ExpandAndPivot(TickCounter tickCounter, IEnumerable <RowItem> rowItems) { var expandedItems = rowItems.SelectMany(rowItem => Expand(tickCounter, rowItem, 0)).ToArray(); var pivotedItems = expandedItems.Select(item => Pivot(tickCounter, item)); var filteredItems = Filter(pivotedItems); var rows = ImmutableList.ValueOf(filteredItems); var result = new PivotedRows(rows, new PropertyDescriptorCollection(GetItemProperties(rows).ToArray())); if (ViewInfo.HasTotals) { result = GroupAndTotal(tickCounter, result); } return(result); }
// Returns a tracking id supplied with events internal GarlicCreationInfo Send(bool explack, params GarlicCloveDelivery[] cloves) { GarlicCreationInfo egmsg = null; try { egmsg = Session.Encrypt(explack, I2NPHeader.GenerateMessageId(), cloves); var npmsg = new GarlicMessage(egmsg.Garlic).GetHeader16(I2NPHeader.GenerateMessageId()); if (explack || WaitingForEGAck != null || egmsg.KeyType == GarlicCreationInfo.KeyUsed.ElGamal) { if (egmsg.KeyType == GarlicCreationInfo.KeyUsed.ElGamal) { LatestEGMessage = egmsg; WaitingForEGAck = TickCounter.Now; } egmsg.LastSend = TickCounter.Now; lock ( Window ) { Window[egmsg.TrackingId] = egmsg; } } if (egmsg.AckMessageId.HasValue) { lock ( OutstandingMessageIds ) { OutstandingMessageIds[egmsg.AckMessageId.Value] = egmsg; } } DebugUtils.LogDebug(string.Format("TagsTransferWindow: Send: ({0}) TrackingId: {1}, Ack MessageId: {2}.", egmsg.KeyType, egmsg.TrackingId, egmsg.AckMessageId)); TunnelSelector(Session.LatestRemoteLeaseSet, npmsg, egmsg); } catch (Exception ex) { Session.Reset(); DebugUtils.Log("TagsTransferWindow Send", ex); } return(egmsg); }
// Start is called before the first frame update void Start() { int currentIndex; // Get reference to sprite renderer. _SpriteR = gameObject.GetComponent <SpriteRenderer>(); // Reference to the sprite collider. _GuardianCollider = gameObject.GetComponent <Collider2D>(); // Set animation counter rate. _TickerCounter = new TickCounter(_AnimateOnTicksForKong); // Calculate indexes of guardian sprites in sprite sheet. currentIndex = ResourceManager.FindSpriteIndex(ResourceManager.GuardiansSprites, _SpriteR.sprite); _SpriteAnimator = new IndexAnimator(4, currentIndex, IndexDirection.Backward, true); }
// Start is called before the first frame update void Start() { int currentIndex; // Get reference to sprite renderer. _SpriteR = gameObject.GetComponent <SpriteRenderer>(); // Get original comet color. _OriginalCometColor = _SpriteR.color; // Reference to the sprite collider. _CometCollider = gameObject.GetComponent <Collider2D>(); // Set animation counter rate. _TickerCounter = new TickCounter(_AnimateOnTicksForComet); // Calculate indexes of guardian sprites in sprite sheet. currentIndex = ResourceManager.FindSpriteIndex(ResourceManager.GuardiansSprites, _SpriteR.sprite); _SpriteAnimator = new IndexAnimator(8, currentIndex, IndexDirection.Forward, false); }
// Start is called before the first frame update void Start() { int indexLenght; int currentIndex; IndexDirection indexMovingTo; // Get reference to sprite renderer. _SpriteR = gameObject.GetComponent <SpriteRenderer>(); // Reference to the sprite collider. _GuardianCollider = gameObject.GetComponent <Collider2D>(); // Set animation counter rate. _TickerCounter = new TickCounter(_AnimateOnTicksForGuardian); // Calculate indexes of guardian sprites in sprite sheet. indexLenght = (_IsBidirectional == true) ? 8 : 4; currentIndex = ResourceManager.FindSpriteIndex(ResourceManager.GuardiansSprites, _SpriteR.sprite); indexMovingTo = (_IsMovingRight == true) ? IndexDirection.Forward : IndexDirection.Backward; _SpriteAnimator = new IndexAnimator(indexLenght, currentIndex, indexMovingTo, _IsBidirectional); }
public PivotedRows ExpandAndPivot(TickCounter tickCounter, IEnumerable<RowItem> rowItems) { var expandedItems = rowItems.SelectMany(rowItem => Expand(tickCounter, rowItem, 0)).ToArray(); var pivotedItems = expandedItems.Select(item => Pivot(tickCounter, item)); var filteredItems = Filter(pivotedItems); var rows = ImmutableList.ValueOf(filteredItems); var result = new PivotedRows(rows, new PropertyDescriptorCollection(GetItemProperties(rows).ToArray())); if (ViewInfo.HasTotals) { result = GroupAndTotal(tickCounter, result); } return result; }
public RowItem Pivot(TickCounter tickCounter, RowItem rowItem) { foreach (var pivotColumn in PivotColumns) { var parent = pivotColumn.Parent.CollectionAncestor(); IList<PivotKey> pivotKeys; if (null == parent) { pivotKeys = new PivotKey[] { null }; } else { pivotKeys = rowItem.PivotKeys.Where(key => key.Last.Key.Equals(parent.PropertyPath)).ToArray(); } foreach (var pivotKey in pivotKeys) { var parentValue = pivotColumn.Parent.GetPropertyValue(rowItem, pivotKey); if (null != parentValue) { var keys = pivotColumn.CollectionInfo.GetKeys(parentValue).Cast<object>().ToArray(); if (keys.Length > 0) { var newPivotKeys = rowItem.PivotKeys.Except(new[] {pivotKey}).ToList(); var pivotKeyLocal = pivotKey ?? PivotKey.EMPTY; var propertyPath = pivotColumn.PropertyPath; newPivotKeys.AddRange(keys.Select(key => pivotKeyLocal.AppendValue(propertyPath, key))); rowItem = rowItem.SetPivotKeys(new HashSet<PivotKey>(newPivotKeys)); } } } } return rowItem; }
public PivotedRows GroupAndTotal(TickCounter tickCounter, PivotedRows pivotedRows) { IDictionary <IList <Tuple <PropertyPath, PivotKey, object> >, List <GroupedRow> > allReportRows = new Dictionary <IList <Tuple <PropertyPath, PivotKey, object> >, List <GroupedRow> >(); var groupColumns = ViewInfo.DisplayColumns .Where(col => TotalOperation.GroupBy == col.ColumnSpec.TotalOperation) .Select(col => col.ColumnDescriptor) .ToArray(); var pivotOnColumns = ViewInfo.DisplayColumns .Where(col => TotalOperation.PivotKey == col.ColumnSpec.TotalOperation) .Select(col => col.ColumnDescriptor) .ToArray(); var allInnerPivotKeys = new HashSet <PivotKey>(); var allPivotKeys = new Dictionary <PivotKey, PivotKey>(); foreach (var rowItem in pivotedRows.RowItems) { allInnerPivotKeys.UnionWith(rowItem.PivotKeys); IList <Tuple <PropertyPath, PivotKey, object> > groupKey = new List <Tuple <PropertyPath, PivotKey, object> >(); foreach (var column in groupColumns) { var pivotColumn = GetPivotColumn(column); if (null == pivotColumn) { groupKey.Add(new Tuple <PropertyPath, PivotKey, object>(column.PropertyPath, null, column.GetPropertyValue(rowItem, null))); } else { foreach (var pivotKey in GetPivotKeys(pivotColumn.PropertyPath, new [] { rowItem })) { if (!pivotKey.Contains(pivotColumn.PropertyPath)) { continue; } groupKey.Add(new Tuple <PropertyPath, PivotKey, object>(column.PropertyPath, pivotKey, column.GetPropertyValue(rowItem, pivotKey))); } } } groupKey = ImmutableList.ValueOf(groupKey); var pivotOnKeyValues = new List <KeyValuePair <PropertyPath, object> >(); foreach (var column in pivotOnColumns) { var pivotColumn = GetPivotColumn(column); if (null == pivotColumn) { pivotOnKeyValues.Add(new KeyValuePair <PropertyPath, object>(column.PropertyPath, column.GetPropertyValue(rowItem, null))); } else { Trace.TraceWarning("Unable to pivot on column {0} because it is already pivoted.", pivotColumn.PropertyPath); // Not L10N } } var pivotOnKey = PivotKey.GetPivotKey(allPivotKeys, pivotOnKeyValues); List <GroupedRow> rowGroups; if (!allReportRows.TryGetValue(groupKey, out rowGroups)) { rowGroups = new List <GroupedRow>(); allReportRows.Add(groupKey, rowGroups); } var rowGroup = rowGroups.FirstOrDefault(rg => !rg.ContainsKey(pivotOnKey)); if (null == rowGroup) { rowGroup = new GroupedRow(); rowGroups.Add(rowGroup); } rowGroup.AddInnerRow(pivotOnKey, rowItem); } var outerPivotKeys = allPivotKeys.Keys.Where(key => key.Length == pivotOnColumns.Length).ToArray(); var pivotKeyComparer = PivotKey.GetComparer(ViewInfo.DataSchema); Array.Sort(outerPivotKeys, pivotKeyComparer); var innerPivotKeys = allInnerPivotKeys.ToArray(); Array.Sort(innerPivotKeys, pivotKeyComparer); var reportItemProperties = new List <PropertyDescriptor>(); var propertyNames = new HashSet <string>(); foreach (var displayColumn in ViewInfo.DisplayColumns) { if (displayColumn.ColumnSpec.Hidden) { continue; } var totalOperation = displayColumn.ColumnSpec.TotalOperation; if (TotalOperation.GroupBy == totalOperation) { var pivotColumn = GetPivotColumn(displayColumn.ColumnDescriptor); if (null == pivotColumn) { string propertyName = MakeUniqueName(propertyNames, displayColumn.PropertyPath); reportItemProperties.Add(new GroupedPropertyDescriptor(propertyName, displayColumn, null)); } else { foreach (var innerPivotKey in innerPivotKeys) { string propertyName = MakeUniqueName(propertyNames, displayColumn.PropertyPath); reportItemProperties.Add(new GroupedPropertyDescriptor(propertyName, displayColumn, innerPivotKey)); } } } } foreach (var outerPivotKey in outerPivotKeys) { foreach (var displayColumn in ViewInfo.DisplayColumns) { if (displayColumn.ColumnSpec.Hidden) { continue; } if (TotalOperation.PivotValue == displayColumn.ColumnSpec.TotalOperation || TotalOperation.PivotKey == displayColumn.ColumnSpec.TotalOperation) { var pivotColumn = GetPivotColumn(displayColumn.ColumnDescriptor); if (null == pivotColumn) { string propertyName = MakeUniqueName(propertyNames, displayColumn.PropertyPath); reportItemProperties.Add(new GroupedPropertyDescriptor(propertyName, outerPivotKey, displayColumn, null)); } else { foreach (var innerPivotKey in allInnerPivotKeys) { string propertyName = MakeUniqueName(propertyNames, displayColumn.PropertyPath); reportItemProperties.Add(new GroupedPropertyDescriptor(propertyName, outerPivotKey, displayColumn, innerPivotKey)); } } } } } return(new PivotedRows(allReportRows.SelectMany(entry => entry.Value.Select( reportRow => new RowItem(reportRow))), new PropertyDescriptorCollection(reportItemProperties.ToArray()))); }
// This test does not work //[Test] public void TestSSU() { //Logging.LogToFile( "TestSSU.log" ); RouterContext testcontext = new RouterContext(new I2PCertificate(I2PSigningKey.SigningKeyTypes.DSA_SHA1)); testcontext.DefaultTCPPort = 2048 + BufUtils.RandomInt(5000); testcontext.DefaultUDPPort = 2048 + BufUtils.RandomInt(5000); var host = new SSUHost(testcontext, new FixedMTU()); host.AllowConnectToSelf = true; host.ConnectionCreated += host_ConnectionCreated; // Remote var dnsa = Dns.GetHostEntry(Dns.GetHostName()).AddressList.Where(a => a.AddressFamily == AddressFamily.InterNetwork).FirstOrDefault(); var addr = new I2PRouterAddress(dnsa, testcontext.UDPPort, 6, "SSU"); addr.Options["key"] = FreenetBase64.Encode(testcontext.IntroKey); RouterContext remotetestcontext = new RouterContext(new I2PCertificate(I2PSigningKey.SigningKeyTypes.DSA_SHA1)); remotetestcontext.DefaultTCPPort = testcontext.DefaultTCPPort + 5; remotetestcontext.DefaultUDPPort = testcontext.DefaultUDPPort + 5; var remotehost = new SSUHost(remotetestcontext, new FixedMTU()); remotehost.AllowConnectToSelf = true; var client = remotehost.AddSession(addr, testcontext.MyRouterIdentity); client.Connect(); var data = new BufLen(BufUtils.RandomBytes(30000)); var messagecount = 900; // If the out queue is larger than 1000 msgs we start discarding them for (int i = 0; i < messagecount; ++i) { client.Send(new DataMessage(data)); } System.Threading.Thread.Sleep(10000); for (int i = 0; i < messagecount; ++i) { if (i % 10 == 0) { System.Threading.Thread.Sleep(100); } client.Send(new DataMessage(data)); } var start = new TickCounter(); while (DataReceived.Count < 2 * messagecount) { if (start.DeltaToNow.ToMinutes >= 1) { Assert.Fail("Failed to receive sent data due to a timeout"); break; } System.Threading.Thread.Sleep(500); } for (int i = 0; i < 100; ++i) { Assert.IsTrue(((DataMessage)DataReceived.Random().Message).DataMessagePayload == new BufLen(data)); } System.Threading.Thread.Sleep(500); client.Terminate(); System.Threading.Thread.Sleep(500); host.Terminate(); System.Threading.Thread.Sleep(500); }
public void TicksToMilliseconds(long ticks, double expected) { Assert.Equal(expected, TickCounter.TicksToMilliseconds(ticks), 6); }
public PivotedRows GroupAndTotal(TickCounter tickCounter, PivotedRows pivotedRows) { IDictionary<IList<Tuple<PropertyPath, PivotKey, object>>, List<GroupedRow>> allReportRows = new Dictionary<IList<Tuple<PropertyPath, PivotKey, object>>, List<GroupedRow>>(); var groupColumns = ViewInfo.DisplayColumns .Where(col => TotalOperation.GroupBy == col.ColumnSpec.TotalOperation) .Select(col => col.ColumnDescriptor) .ToArray(); var pivotOnColumns = ViewInfo.DisplayColumns .Where(col => TotalOperation.PivotKey == col.ColumnSpec.TotalOperation) .Select(col => col.ColumnDescriptor) .ToArray(); var allInnerPivotKeys = new HashSet<PivotKey>(); var allPivotKeys = new Dictionary<PivotKey, PivotKey>(); foreach (var rowItem in pivotedRows.RowItems) { allInnerPivotKeys.UnionWith(rowItem.PivotKeys); IList<Tuple<PropertyPath, PivotKey, object>> groupKey = new List<Tuple<PropertyPath, PivotKey, object>>(); foreach (var column in groupColumns) { var pivotColumn = GetPivotColumn(column); if (null == pivotColumn) { groupKey.Add(new Tuple<PropertyPath, PivotKey, object>(column.PropertyPath, null, column.GetPropertyValue(rowItem, null))); } else { foreach (var pivotKey in GetPivotKeys(pivotColumn.PropertyPath, new []{rowItem})) { if (!pivotKey.Contains(pivotColumn.PropertyPath)) { continue; } groupKey.Add(new Tuple<PropertyPath, PivotKey, object>(column.PropertyPath, pivotKey, column.GetPropertyValue(rowItem, pivotKey))); } } } groupKey = ImmutableList.ValueOf(groupKey); var pivotOnKeyValues = new List<KeyValuePair<PropertyPath, object>>(); foreach (var column in pivotOnColumns) { var pivotColumn = GetPivotColumn(column); if (null == pivotColumn) { pivotOnKeyValues.Add(new KeyValuePair<PropertyPath, object>(column.PropertyPath, column.GetPropertyValue(rowItem, null))); } else { Trace.TraceWarning("Unable to pivot on column {0} because it is already pivoted.", pivotColumn.PropertyPath); // Not L10N } } var pivotOnKey = PivotKey.GetPivotKey(allPivotKeys, pivotOnKeyValues); List<GroupedRow> rowGroups; if (!allReportRows.TryGetValue(groupKey, out rowGroups)) { rowGroups = new List<GroupedRow>(); allReportRows.Add(groupKey, rowGroups); } var rowGroup = rowGroups.FirstOrDefault(rg => !rg.ContainsKey(pivotOnKey)); if (null == rowGroup) { rowGroup = new GroupedRow(); rowGroups.Add(rowGroup); } rowGroup.AddInnerRow(pivotOnKey, rowItem); } var outerPivotKeys = allPivotKeys.Keys.Where(key=>key.Length == pivotOnColumns.Length).ToArray(); var pivotKeyComparer = PivotKey.GetComparer(ViewInfo.DataSchema); Array.Sort(outerPivotKeys, pivotKeyComparer); var innerPivotKeys = allInnerPivotKeys.ToArray(); Array.Sort(innerPivotKeys, pivotKeyComparer); var reportItemProperties = new List<PropertyDescriptor>(); var propertyNames = new HashSet<string>(); foreach (var displayColumn in ViewInfo.DisplayColumns) { if (displayColumn.ColumnSpec.Hidden) { continue; } var totalOperation = displayColumn.ColumnSpec.TotalOperation; if (TotalOperation.GroupBy == totalOperation) { var pivotColumn = GetPivotColumn(displayColumn.ColumnDescriptor); if (null == pivotColumn) { string propertyName = MakeUniqueName(propertyNames, displayColumn.PropertyPath); reportItemProperties.Add(new GroupedPropertyDescriptor(propertyName, displayColumn, null)); } else { foreach (var innerPivotKey in innerPivotKeys) { string propertyName = MakeUniqueName(propertyNames, displayColumn.PropertyPath); reportItemProperties.Add(new GroupedPropertyDescriptor(propertyName, displayColumn, innerPivotKey)); } } } } foreach (var outerPivotKey in outerPivotKeys) { foreach (var displayColumn in ViewInfo.DisplayColumns) { if (displayColumn.ColumnSpec.Hidden) { continue; } if (TotalOperation.PivotValue == displayColumn.ColumnSpec.TotalOperation || TotalOperation.PivotKey == displayColumn.ColumnSpec.TotalOperation) { var pivotColumn = GetPivotColumn(displayColumn.ColumnDescriptor); if (null == pivotColumn) { string propertyName = MakeUniqueName(propertyNames, displayColumn.PropertyPath); reportItemProperties.Add(new GroupedPropertyDescriptor(propertyName, outerPivotKey, displayColumn, null)); } else { foreach (var innerPivotKey in allInnerPivotKeys) { string propertyName = MakeUniqueName(propertyNames, displayColumn.PropertyPath); reportItemProperties.Add(new GroupedPropertyDescriptor(propertyName, outerPivotKey, displayColumn, innerPivotKey)); } } } } } return new PivotedRows(allReportRows.SelectMany(entry=>entry.Value.Select( reportRow=>new RowItem(reportRow))), new PropertyDescriptorCollection(reportItemProperties.ToArray())); }
public IEnumerable<RowItem> Expand(TickCounter tickCounter, RowItem rowItem, int sublistColumnIndex) { if (sublistColumnIndex >= SublistColumns.Count) { return new[] {rowItem}; } var sublistColumn = SublistColumns[sublistColumnIndex]; object parentValue = sublistColumn.Parent.GetPropertyValue(rowItem, null); if (null == parentValue) { return new[] {rowItem}; } var items = sublistColumn.CollectionInfo.GetItems(parentValue).Cast<object>().ToArray(); if (items.Length == 0) { return new[] {rowItem}; } IList<object> keys = null; if (sublistColumn.CollectionInfo.IsDictionary) { keys = sublistColumn.CollectionInfo.GetKeys(parentValue).Cast<object>().ToArray(); } var expandedItems = new List<RowItem>(); for (int index = 0; index < items.Length; index++) { object key = keys == null ? index : keys[index]; var child = rowItem.SetRowKey(rowItem.RowKey.AppendValue(sublistColumn.PropertyPath, key)); expandedItems.AddRange(Expand(tickCounter, child, sublistColumnIndex + 1)); } return expandedItems; }
private void Initialize() { TickCounter = new TickCounter(); _frameContext = new FrameContext(this); _startTime = DateTime.UtcNow; }
protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"ThaAdxRideTheTrend"; Name = "ThaAdxRideTheTrend"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = true; ExitOnSessionCloseSeconds = 30; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.Standard; Slippage = 0; StartBehavior = StartBehavior.WaitUntilFlat; TimeInForce = TimeInForce.Gtc; TraceOrders = false; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 20; // Disable this property for performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = true; TradingAccountId = 0; ExitPeriod = 3; AdxPeriod = 14; MinAdx = 25; ExitSlopeThreshold = -15; UseBoundaryHours = true; StartHour = 7; StartMinute = 30; EndHour = 12; EndMinute = 30; LossExitTicks = 8; EnterPeriod = 3; EnterSlopeThreshold = 20; RecordHistoricalTrades = false; EnterBarsLength = 2; ExitBarsLength = 2; EnterViaLimit = true; EnterViaStop = true; ExitStopBuffer = 2; ExitLimitBuffer = 2; Quantity = 2; MinTickRange = 8; FireSns = false; MinTrendLength = 1; TargetDollars = 0; TrailingStopMinDollars = 0; TrailingStopDivisorDollars = 0; TrailingStopCushionDollars = 0; OverrideRealTimeOnly = false; } else if (State == State.Configure) { //SetOrderQuantity = SetOrderQuantity.DefaultQuantity; trailingStopEnabled = TrailingStopMinDollars > 0; if (trailingStopEnabled) { AddDataSeries(BarsPeriodType.Tick, 300); } tickCounter = TickCounter(true, false); AddChartIndicator(tickCounter); rangeIndicator = MyRange(14, MinTickRange); //AddChartIndicator(rangeIndicator); adxIndicator = EnhancedADX(AdxPeriod, MinAdx); AddChartIndicator(adxIndicator); if (EnterPeriod > 1) { enterAdxSlopeIndicator = AdxSlope(AdxPeriod, EnterPeriod, EnterSlopeThreshold); AddChartIndicator(enterAdxSlopeIndicator); } if (ExitPeriod > 1) { exitAdxSlopeIndicator = AdxSlope(AdxPeriod, ExitPeriod, ExitSlopeThreshold); //AddChartIndicator(exitAdxSlopeIndicator); } disableManager.AddRange(DayOfWeek.Monday, 6, 25, 6, 50); disableManager.AddRange(DayOfWeek.Tuesday, 6, 25, 6, 50); disableManager.AddRange(DayOfWeek.Wednesday, 6, 25, 6, 50); disableManager.AddRange(DayOfWeek.Thursday, 6, 25, 6, 50); disableManager.AddRange(DayOfWeek.Friday, 6, 25, 6, 50); // disableManager.AddRange(DayOfWeek.Sunday, 15, 45, 24, 0); // disableManager.AddRange(DayOfWeek.Monday, 15, 45, 24, 0); // disableManager.AddRange(DayOfWeek.Tuesday, 15, 45, 24, 0); // disableManager.AddRange(DayOfWeek.Wednesday, 15, 45, 24, 0); // disableManager.AddRange(DayOfWeek.Thursday, 15, 45, 24, 0); // disableManager.AddRange(DayOfWeek.Friday, 15, 45, 24, 0); } else if (State == State.DataLoaded) { } }
private void NextFrame() { TickCounter.Tick(); _frameContext.NextFrame(); }