public void UsesCreatorAfterReset() { bool didCallRef = false; var refLazy = new ResettableLazy <string>(() => { if (didCallRef) { return("Second"); } didCallRef = true; return("First"); }); _ = refLazy.Value; refLazy.Reset(); Assert.AreEqual("Second", refLazy.Value); bool didCallVal = false; var valLazy = new ResettableLazyValue <int>(() => { if (didCallVal) { return(1337); } didCallVal = true; return(42); }); _ = valLazy.Value; valLazy.Reset(); Assert.AreEqual(1337, valLazy.Value); }
public void AddTable(Table table) { if (table.rows.Count <= 0) { return; } int moduleNumber = table.rows.First().Key.Module; ModuleType module = EnumUtils.intToEnum <ModuleType>(moduleNumber); if (module == ModuleType.Unknown) { throw new InvalidDataException("Unknown database module"); } // Merge by overwriting previous defined rows modules[module] = modules[module].Concat(table.rows) .GroupBy(pair => pair.Key) .ToDictionary( group => group.Key, group => group.Last().Value ); switch (module) { case ModuleType.Fairy: fairiesByIndex.Reset(); break; case ModuleType.Item: itemsByIndex.Reset(); break; case ModuleType.Spell: spellsByIndex.Reset(); break; } }
private void Flush() { _queryTextStoringService.Flush(); _pendingLocksInfo.BulkInsert(_connectionProvider); _logger.LogInformation("{0} long locks inserted.", _pendingLocksInfo.Count); _pendingLocksInfo.Clear(); _pendingDeadLocksInfo.BulkInsert(_connectionProvider); _logger.LogInformation("{0} deadloks inserted.", _pendingDeadLocksInfo.Count); _pendingDeadLocksInfo.Clear(); _lastQueryDate.Reset(); _lastDeadLockDate.Reset(); }
public void CanBeReset() { var refLazy = new ResettableLazy <string>(() => ""); _ = refLazy.Value; refLazy.Reset(); Assert.IsFalse(refLazy.HasValue); var valLazy = new ResettableLazyValue <int>(() => 0); _ = valLazy.Value; valLazy.Reset(); Assert.IsFalse(valLazy.HasValue); }
public void Value() { var func = Substitute.For <Func <bool> >(); func.Invoke().Returns(true); var rl = new ResettableLazy <bool>(func); rl.Value.Should().BeTrue(); func.Received(1).Invoke(); rl.Value.Should().BeTrue(); func.Received(1).Invoke(); rl.Reset(); rl.Value.Should().BeTrue(); func.Received(2).Invoke(); }
private void HandleGraphicsSurfaceSizeChanged(object?sender, PropertyChangedEventArgs <Vector2> e) { WaitForIdle(); if (_frameBuffers.IsCreated) { var frameBuffers = _frameBuffers.Value; foreach (var frameBuffer in frameBuffers) { if (frameBuffer != VK_NULL_HANDLE) { vkDestroyFramebuffer(_device.Value, frameBuffer, pAllocator: null); } } _frameBuffers.Reset(); } if (_swapChainImageViews.IsCreated) { var swapChainImageViews = _swapChainImageViews.Value; foreach (var swapChainImageView in swapChainImageViews) { if (swapChainImageView != VK_NULL_HANDLE) { vkDestroyImageView(_device.Value, swapChainImageView, pAllocator: null); } } _swapChainImageViews.Reset(); } if (_swapChain.IsCreated) { vkDestroySwapchainKHR(_device.Value, _swapChain.Value, pAllocator: null); _swapChain.Reset(); } }
private void HandleGraphicsSurfaceSizeChanged(object?sender, PropertyChangedEventArgs <Vector2> e) { WaitForIdle(); if (_renderTargets.IsCreated) { var renderTargets = _renderTargets.Value; foreach (var renderTarget in renderTargets) { if (renderTarget != null) { _ = renderTarget->Release(); } } _renderTargets.Reset(); } if (_swapChain.IsCreated) { ThrowExternalExceptionIfFailed(nameof(IDXGISwapChain.ResizeBuffers), SwapChain->ResizeBuffers((uint)_graphicsSurface.BufferCount, (uint)_graphicsSurface.Width, (uint)_graphicsSurface.Height, DXGI_FORMAT_R8G8B8A8_UNORM, SwapChainFlags: 0)); } }
public void MergeCells(ITableCell inputCell1, ITableCell inputCell2) // TODO: Optimize method { SCTableCell cell1 = (SCTableCell)inputCell1; SCTableCell cell2 = (SCTableCell)inputCell2; if (CannotBeMerged(cell1, cell2)) { return; } int minRowIndex = cell1.RowIndex < cell2.RowIndex ? cell1.RowIndex : cell2.RowIndex; int maxRowIndex = cell1.RowIndex > cell2.RowIndex ? cell1.RowIndex : cell2.RowIndex; int minColIndex = cell1.ColumnIndex < cell2.ColumnIndex ? cell1.ColumnIndex : cell2.ColumnIndex; int maxColIndex = cell1.ColumnIndex > cell2.ColumnIndex ? cell1.ColumnIndex : cell2.ColumnIndex; // Horizontal merging List <A.TableRow> aTableRowList = this.ATable.Elements <A.TableRow>().ToList(); if (minColIndex != maxColIndex) { int horizontalMergingCount = maxColIndex - minColIndex + 1; for (int rowIdx = minRowIndex; rowIdx <= maxRowIndex; rowIdx++) { A.TableCell[] rowATblCells = aTableRowList[rowIdx].Elements <A.TableCell>().ToArray(); A.TableCell firstMergingCell = rowATblCells[minColIndex]; firstMergingCell.GridSpan = new Int32Value(horizontalMergingCount); Span <A.TableCell> nextMergingCells = new Span <A.TableCell>(rowATblCells, minColIndex + 1, horizontalMergingCount - 1); foreach (A.TableCell aTblCell in nextMergingCells) { aTblCell.HorizontalMerge = new BooleanValue(true); MergeParagraphs(minRowIndex, minColIndex, aTblCell); } } } // Vertical merging if (minRowIndex != maxRowIndex) { // Set row span value for the first cell in the merged cells int verticalMergingCount = maxRowIndex - minRowIndex + 1; IEnumerable <A.TableCell> rowSpanCells = aTableRowList[minRowIndex].Elements <A.TableCell>() .Skip(minColIndex) .Take(maxColIndex + 1); foreach (A.TableCell aTblCell in rowSpanCells) { aTblCell.RowSpan = new Int32Value(verticalMergingCount); } // Set vertical merging flag foreach (A.TableRow aTblRow in aTableRowList.Skip(minRowIndex + 1).Take(maxRowIndex)) { foreach (A.TableCell aTblCell in aTblRow.Elements <A.TableCell>().Take(maxColIndex + 1)) { aTblCell.VerticalMerge = new BooleanValue(true); MergeParagraphs(minRowIndex, minColIndex, aTblCell); } } } // Delete a:gridCol and a:tc elements if all columns are merged for (int colIdx = 0; colIdx < Columns.Count;) { int?gridSpan = ((SCTableCell)Rows[0].Cells[colIdx]).ATableCell.GridSpan?.Value; if (gridSpan > 1 && Rows.All(row => ((SCTableCell)row.Cells[colIdx]).ATableCell.GridSpan?.Value == gridSpan)) { int deleteColumnCount = gridSpan.Value - 1; // Delete a:gridCol elements foreach (Column column in Columns.Skip(colIdx + 1).Take(deleteColumnCount)) { column.AGridColumn.Remove(); Columns[colIdx].Width += column.Width; // append width of deleting column to merged column } // Delete a:tc elements foreach (A.TableRow aTblRow in aTableRowList) { IEnumerable <A.TableCell> removeCells = aTblRow.Elements <A.TableCell>().Skip(colIdx).Take(deleteColumnCount); foreach (A.TableCell aTblCell in removeCells) { aTblCell.Remove(); } } colIdx += gridSpan.Value; continue; } colIdx++; } // Delete a:tr for (int rowIdx = 0; rowIdx < Rows.Count;) { int?rowSpan = ((SCTableCell)Rows[rowIdx].Cells[0]).ATableCell.RowSpan?.Value; if (rowSpan > 1 && Rows[rowIdx].Cells.All(c => ((SCTableCell)c).ATableCell.RowSpan?.Value == rowSpan)) { int deleteRowsCount = rowSpan.Value - 1; // Delete a:gridCol elements foreach (SCTableRow row in Rows.Skip(rowIdx + 1).Take(deleteRowsCount)) { row.ATableRow.Remove(); Rows[rowIdx].Height += row.Height; } rowIdx += rowSpan.Value; continue; } rowIdx++; } rowCollection.Reset(); }