public void Test_ServerSubGridTreeLeaf_ComputeLatestPassInformation() { var leaf = CreateADefaultEmptyLeaf(); Assert.True(leaf.Directory.GlobalLatestCells != null && leaf.Directory.GlobalLatestCells.PassDataExistenceMap != null, "Pass data existence map is not instantiated"); Assert.False(leaf.CellHasValue(0, 0), "Cell already has a value"); // Add three passes them compute the latest pass information and ensure it matches with the cell passes CellPass pass = CreateTestCellPass(); leaf.AddPass(0, 0, pass); pass.Time = pass.Time.AddMinutes(1); leaf.AddPass(0, 0, pass); pass.Time = pass.Time.AddMinutes(1); leaf.AddPass(0, 0, pass); leaf.ComputeLatestPassInformation(true, StorageProxy.Instance(StorageMutability.Mutable)); Assert.True(leaf.CellHasValue(0, 0), "Cell does not have value"); CellPass latestPass = leaf.Directory.GlobalLatestCells[0, 0]; Assert.True(latestPass.Equals(pass), "Latest cell pass does not match pass"); }
public string Delete(int id) { client.url = CombineUrl(id); StorageProxy.keyBucketTable[ShardFunction(id)].Remove(id); var response = client.Delete(id); StorageProxy.WriteKeyBucketTable(); return(response); }
private void InitializeClients() { Cdn = new CdnProxy(_internalData); Dns = new DnsProxy(_internalData); IaaS = new IaaSProxy(_internalData); Live = new LiveProxy(_internalData); Security = new SecurityProxy(_internalData); Storage = new StorageProxy(_internalData); Vod = new VodProxy(_internalData); }
public string Put(int id, [FromBody] string value) { client.url = CombineUrl(id); if (!StorageProxy.keyBucketTable[ShardFunction(id)].Contains(id)) { StorageProxy.keyBucketTable[ShardFunction(id)].Add(id); } StorageProxy.WriteKeyBucketTable(); return(client.Put(id, value)); }
public void Test_ServerSubGridTreeLeaf_Clear() { var leaf = CreateADefaultEmptyLeaf(); CellPass pass = CreateTestCellPass(); leaf.AddPass(0, 0, pass); leaf.ComputeLatestPassInformation(true, StorageProxy.Instance(StorageMutability.Mutable)); leaf.Clear(); Assert.False(leaf.CellHasValue(0, 0), "Cell has a value"); // Assert.IsTrue(leaf.Directory.SegmentDirectory.First().Segment.PassesData.PassData[0,0].PassCount == 0, "cell pass count is not 0"); Assert.Null(leaf.Directory.SegmentDirectory.First().Segment); }
public void Test_SubGridSegmentIterator_InitialiseIterator() { ServerSubGridTree tree = new ServerSubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, ServerSubGridTreeLeaf>(), StorageMutability.Mutable); IServerLeafSubGrid leaf = new ServerSubGridTreeLeaf(tree, null, SubGridTreeConsts.SubGridTreeLevels, StorageMutability.Mutable); SubGridSegmentIterator iterator = new SubGridSegmentIterator(leaf, leaf.Directory, StorageProxy.Instance(StorageMutability.Mutable)) { IterationDirection = IterationDirection.Forwards }; iterator.InitialiseIterator(); Assert.Equal(-1, iterator.IterationState.Idx); iterator.IterationDirection = IterationDirection.Backwards; iterator.InitialiseIterator(); Assert.Equal(iterator.IterationState.Idx, leaf.Directory.SegmentDirectory.Count); }
public void Test_ServerSubGridTreeLeaf_CellHasValue() { // Add a cell pass and check the CellHasValue flags the cell as having a value var leaf = CreateADefaultEmptyLeaf(); Assert.True(leaf.Directory.GlobalLatestCells != null && leaf.Directory.GlobalLatestCells.PassDataExistenceMap != null, "Pass data existence map is not instantiated"); Assert.False(leaf.CellHasValue(0, 0), "Cell already has a value"); CellPass pass = CreateTestCellPass(); leaf.AddPass(0, 0, pass); leaf.ComputeLatestPassInformation(true, StorageProxy.Instance(StorageMutability.Mutable)); Assert.True(leaf.CellHasValue(0, 0), "Cell does not have value"); }
public void Test_SegmentIterator_MoveToFirstSegment() { var subGrid = MakeSubgridWith10240CellPassesAtOneSecondIntervals(); var Iterator = new SubGridSegmentIterator(subGrid, StorageProxy.Instance(StorageMutability.Mutable)) { IterationDirection = IterationDirection.Forwards, ReturnDirtyOnly = true, RetrieveAllPasses = true }; Assert.True(Iterator.MoveToFirstSubGridSegment(), "Was not able to move to first segment (forwards) when requesting only dirty segments"); Iterator = new SubGridSegmentIterator(subGrid, StorageProxy.Instance(StorageMutability.Mutable)) { IterationDirection = IterationDirection.Backwards, ReturnDirtyOnly = true, RetrieveAllPasses = true }; Assert.True(Iterator.MoveToFirstSubGridSegment(), "Was not able to move to first segment (backwards) when requesting only dirty segments"); Iterator = new SubGridSegmentIterator(subGrid, StorageProxy.Instance(StorageMutability.Mutable)) { IterationDirection = IterationDirection.Forwards, ReturnDirtyOnly = false, RetrieveAllPasses = true }; Assert.True(Iterator.MoveToFirstSubGridSegment(), "Was not able to move to first segment (forwards) when requesting all segments"); Iterator = new SubGridSegmentIterator(subGrid, StorageProxy.Instance(StorageMutability.Mutable)) { IterationDirection = IterationDirection.Backwards, ReturnDirtyOnly = false, RetrieveAllPasses = true }; Assert.True(Iterator.MoveToFirstSubGridSegment(), "Was not able to move to first segment (backwards) when requesting all segments"); }
public void Test_SubgridSegment_Cleaver() { // Create a sub grid to hold the segment IServerLeafSubGrid subGrid = MakeSubgridWith10240CellPassesAtOneSecondIntervals(); // Exercise the cleaver! // Instruct the segment container to cleave the segment // Set the segment to not dirty - it should be ignored subGrid.Cells.PassesData[0].Dirty = false; var cleaver = new SubGridSegmentCleaver(); cleaver.PerformSegmentCleaving(StorageProxy.Instance(StorageMutability.Mutable), subGrid, 10000); Assert.True(1 == subGrid.Cells.PassesData.Count, $"After cleaving with no dirty segments there are {subGrid.Cells.PassesData.Count} segments instead of the expected one segments"); // Set the segment to not dirty - it should be ignored subGrid.Cells.PassesData[0].Dirty = true; cleaver = new SubGridSegmentCleaver(); cleaver.PerformSegmentCleaving(StorageProxy.Instance(StorageMutability.Mutable), subGrid, 10000); //Check there are now two segments in total Assert.True(2 == subGrid.Cells.PassesData.Count, $"After cleaving there are {subGrid.Cells.PassesData.Count} segments instead of the expected two segments"); //Check the total number of passes across the two segments is 10240, and the maximum pass count is 5 ISubGridCellPassesDataSegment segment1 = subGrid.Cells.PassesData[0]; ISubGridCellPassesDataSegment segment2 = subGrid.Cells.PassesData[1]; segment1.PassesData.CalculateTotalPasses(out int totalPassCount1, out _, out int maximumPassCount1); segment2.PassesData.CalculateTotalPasses(out int totalPassCount2, out _, out int maximumPassCount2); Assert.True(10240 == (totalPassCount1 + totalPassCount2), $"Totals ({totalPassCount1} and {totalPassCount2} don't add up to 10240 after cleaving"); Assert.True(5 == maximumPassCount1, $"Maximum pass count 1 {maximumPassCount1}, is not 5"); Assert.True(5 == maximumPassCount2, $"Maximum pass count 2 {maximumPassCount2}, is not 5"); // Check the segment pass count in the segment is correct Assert.True(totalPassCount1 == segment1.PassesData.SegmentPassCount, $"Total passes for segment 1 {totalPassCount1} is not equal to segmentPassCount in that segment {segment1.PassesData.SegmentPassCount}"); Assert.True(totalPassCount2 == segment2.PassesData.SegmentPassCount, $"Total passes for segment 2 {totalPassCount2} is not equal to segmentPassCount in that segment {segment2.PassesData.SegmentPassCount}"); }
public void Test_SubGridSegmentIterator_SetIteratorElevationRange() { ServerSubGridTree tree = new ServerSubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, ServerSubGridTreeLeaf>(), StorageMutability.Mutable); IServerLeafSubGrid leaf = new ServerSubGridTreeLeaf(tree, null, SubGridTreeConsts.SubGridTreeLevels, StorageMutability.Mutable); SubGridSegmentIterator iterator = new SubGridSegmentIterator(leaf, leaf.Directory, StorageProxy.Instance(StorageMutability.Mutable)); const double lowerElevation = 9.0; const double upperElevation = 19.0; iterator.SetIteratorElevationRange(lowerElevation, upperElevation); Assert.True(iterator.IterationState.MinIterationElevation == lowerElevation && iterator.IterationState.MaxIterationElevation == upperElevation, "Elevation lower and upper bounds not set correctly"); }
public void Test_SubGridSegmentIterator_SetTimeRange() { ServerSubGridTree tree = new ServerSubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, ServerSubGridTreeLeaf>(), StorageMutability.Mutable); IServerLeafSubGrid leaf = new ServerSubGridTreeLeaf(tree, null, SubGridTreeConsts.SubGridTreeLevels, StorageMutability.Mutable); SubGridSegmentIterator iterator = new SubGridSegmentIterator(leaf, leaf.Directory, StorageProxy.Instance(StorageMutability.Mutable)); DateTime start = DateTime.SpecifyKind(new DateTime(2000, 1, 1, 1, 1, 1), DateTimeKind.Utc); DateTime end = DateTime.SpecifyKind(new DateTime(2000, 1, 2, 1, 1, 1), DateTimeKind.Utc); iterator.SetTimeRange(start, end); Assert.True(iterator.IterationState.StartSegmentTime == start && iterator.IterationState.EndSegmentTime == end, "Start and end time not set correctly"); }
public void Test_SubGridSegmentIterator_SubGridSegmentIterator() { ServerSubGridTree tree = new ServerSubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, ServerSubGridTreeLeaf>(), StorageMutability.Mutable); IServerLeafSubGrid leaf = new ServerSubGridTreeLeaf(tree, null, SubGridTreeConsts.SubGridTreeLevels, StorageMutability.Mutable); SubGridSegmentIterator iterator = new SubGridSegmentIterator(leaf, leaf.Directory, StorageProxy.Instance(StorageMutability.Mutable)); Assert.True(iterator.Directory == leaf.Directory && iterator.SubGrid == leaf, "SubGrid segment iterator not correctly initialised"); }
public void Test_TerrainSwather_PerformSwathing() { var siteModel = new SiteModel(StorageMutability.Immutable); var machine = new VSS.TRex.Machines.Machine(); var grid = new ServerSubGridTree(siteModel.ID, StorageMutability.Mutable); var SiteModelGridAggregator = new ServerSubGridTree(siteModel.ID, StorageMutability.Mutable); var MachineTargetValueChangesAggregator = new ProductionEventLists(siteModel, MachineConsts.kNullInternalSiteModelMachineIndex); var processor = new TAGProcessor(siteModel, machine, SiteModelGridAggregator, MachineTargetValueChangesAggregator); var fence = new Fence(); fence.SetRectangleFence(0, 0, 10, 2); TerrainSwather swather = new TerrainSwather(processor, MachineTargetValueChangesAggregator, siteModel, grid, fence); CreateSwathContext(0, 0, 0, 10, 0, 0, 0, 2, 0, 10, 2, 0, out SimpleTriangle HeightInterpolator1, out SimpleTriangle HeightInterpolator2, out SimpleTriangle TimeInterpolator1, out SimpleTriangle TimeInterpolator2); // Compute swath with full cell pass on the front (blade) measurement location bool swathResult = swather.PerformSwathing(HeightInterpolator1, HeightInterpolator2, TimeInterpolator1, TimeInterpolator2, false, PassType.Front, MachineSide.None); // Did the swathing operation succeed? Assert.True(swathResult, "Perform swathing failed"); // Did it produce the expected set of swathed cells? Assert.Equal(1, grid.Root.CountChildren()); // Computation of the latest pass information which aids locating cells with non-null values try { IStorageProxy storageProxy = StorageProxy.Instance(StorageMutability.Mutable); grid.Root.ScanSubGrids(grid.FullCellExtent(), x => { ((IServerLeafSubGrid)x).ComputeLatestPassInformation(true, storageProxy); return(true); }); } catch (Exception E) { Assert.False(true, $"Exception {E} occured computing latest cell information"); } grid.CalculateIndexOfCellContainingPosition(grid.CellSize / 2, grid.CellSize / 2, out int _, out int _); int nonNullCellCount = 0; try { grid.Root.ScanSubGrids(grid.FullCellExtent(), x => { nonNullCellCount += ((IServerLeafSubGrid)x).CountNonNullCells(); return(true); }); } catch (Exception e) { Assert.False(true, $"Exception {e} occured counting non-null cells"); } Assert.Equal(174, nonNullCellCount); // Todo: Iterate over the cells and confirm their content is as expected }
public HomeController(ILogger <HomeController> logger, StorageProxy storageProxy) { Logger = logger; StorageProxy = storageProxy; }
public SurveyAPIController(SurveyContext context) { _context = context; this._storageProxy = new StorageProxy(context); }
public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); IAppSetting appSetting = new AppSetting(); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); IStorageProxy storageProxy = new StorageProxy(appSetting.StorageConnectionString); await storageProxy.WriteTable(appSetting.LogTableName, requestBody); if (string.IsNullOrEmpty(requestBody)) { return(new StatusCodeResult(404)); } List <MonitorDataModel> monitorDatas = new List <MonitorDataModel>(); try { var singleMonitorDatas = requestBody.ConvertToObj <List <SingleMonitorDataContract> >(); foreach (var singleMonitorData in singleMonitorDatas) { foreach (var data in singleMonitorData.Data.IData) { var device = singleMonitorData.Data.DName.Split(','); MonitorDataModel model = new MonitorDataModel { Id = Guid.NewGuid().ToString(), GatewayId = singleMonitorData.GSN, DeviceId = singleMonitorData.Data.DId, DeviceName = device[0], DeviceType = device.Length == 2 ? device[1] : string.Empty, MonitorId = data.IId, MonitorName = data.IName, MonitorType = data.IType, Unit = data.IUnit, Value = data.IValue, IsScan = false, Timestamp = DateTime.Now }; monitorDatas.Add(model); } } } catch (Exception) { var multpleMonitorDatas = requestBody.ConvertToObj <List <MultipleMonitorDataContract> >(); foreach (var multpleMonitorData in multpleMonitorDatas) { foreach (var monitorData in multpleMonitorData.Data) { var device = monitorData.DName.Split(','); foreach (var data in monitorData.IData) { MonitorDataModel model = new MonitorDataModel { Id = Guid.NewGuid().ToString(), GatewayId = multpleMonitorData.GSN, DeviceId = monitorData.DId, DeviceName = device[0], DeviceType = device.Length == 2 ? device[1] : string.Empty, MonitorId = data.IId, MonitorName = data.IName, MonitorType = data.IType, Unit = data.IUnit, Value = data.IValue, IsScan = false, Timestamp = DateTime.Now }; monitorDatas.Add(model); } } } } MongoHelper mongoHelper = new MongoHelper(appSetting.MongoDBConnectionString, appSetting.MongoDBName); foreach (var data in monitorDatas) { mongoHelper.InsertOne <MonitorDataModel>(appSetting.MongoCollectionName, data); } //TODO:insert monitor data to database //using (SqlHelper helper = new SqlHelper(connectionString)) //{ // string sql = "insert into ...."; // helper.ExecuteNonQuery(sql, CommandType.Text); //} return(new OkObjectResult($"Hello, IoTManager")); }