public static IDataProviderService Create(int testPoints) { var provider = new TestSinusDataProviderService(); provider.TestPoints = (uint)testPoints; return(provider); }
private static void RunServiceAndProvider(out int maxPointsRes, out int dataUpdatedNotificationsRes, List <IDataItem> generatedPointList, out DataService service, out double minXRes, out double maxXRes, out double minYRes, out double maxYRes, out int dataItemsGeneratedRes, int linesMumber, int maxPoints) { var pointsNumber = linesMumber + 1; var dataUpdatedNotificationsSink = new object(); var dataUpdatedNotifications = 0; var sink = new object(); var minX = double.MaxValue; var maxX = double.MinValue; var minY = double.MaxValue; var maxY = double.MinValue; int dataItemsGenerated = 0; using (var provider = new TestSinusDataProviderService()) { provider.TestPoints = (uint)pointsNumber; provider.OnReceiveData += (value, dateTime) => { lock (sink) { var item = new DataItem(dateTime.Ticks / TimeSpan.TicksPerMillisecond, value); minX = minX > item.X ? item.X : minX; maxX = maxX < item.X ? item.X : maxX; minY = minY > item.Y ? item.Y : minY; maxY = maxY < item.Y ? item.Y : maxY; dataItemsGenerated++; } }; provider.OnGraphDataArrayReceived += (sender, e) => { lock (sink) { foreach (var item in e.DataItems) { minX = minX > item.X ? item.X : minX; maxX = maxX < item.X ? item.X : maxX; minY = minY > item.Y ? item.Y : minY; maxY = maxY < item.Y ? item.Y : maxY; } dataItemsGenerated += e.DataItems.Count; if (e.DataItems.Count - maxPoints - 1 < 0) { generatedPointList?.AddRange(e.DataItems); } else { generatedPointList?.AddRange( e.DataItems.ToList() .GetRange(e.DataItems.Count - maxPoints - 1, maxPoints)); } } }; service = new DataService((uint)maxPoints); service.DataUpdated += (sender, e) => { lock (dataUpdatedNotificationsSink) { dataUpdatedNotifications += e.Items.Count; } }; service.RegisterDataProvider(provider); provider.Run(); } maxPointsRes = maxPoints; dataUpdatedNotificationsRes = dataUpdatedNotifications; minXRes = minX; maxXRes = maxX; minYRes = minY; maxYRes = maxY; dataItemsGeneratedRes = dataItemsGenerated; }