Example #1
0
        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);
        }
Example #2
0
        internal GraphicsContext(GraphicsAdapter graphicsAdapter, IGraphicsSurface graphicsSurface)
        {
            _graphicsAdapter = graphicsAdapter;
            _graphicsSurface = graphicsSurface;

            _acquireNextImageSemaphore = new ResettableLazy <ulong>(CreateAcquireNextImageSemaphore);
            _commandBuffers            = new ResettableLazy <IntPtr[]>(CreateCommandBuffers);
            _commandPool              = new ResettableLazy <ulong>(CreateCommandPool);
            _device                   = new ResettableLazy <IntPtr>(CreateDevice);
            _deviceQueue              = new ResettableLazy <IntPtr>(CreateDeviceQueue);
            _fences                   = new ResettableLazy <ulong[]>(CreateFences);
            _frameBuffers             = new ResettableLazy <ulong[]>(CreateFrameBuffers);
            _graphicsQueueFamilyIndex = new ResettableLazy <uint>(FindGraphicsQueueFamilyIndex);
            _queueSubmitSemaphore     = new ResettableLazy <ulong>(CreateQueueSubmitSemaphore);
            _renderPass               = new ResettableLazy <ulong>(CreateRenderPass);
            _surface                  = new ResettableLazy <ulong>(CreateSurface);
            _swapChain                = new ResettableLazy <ulong>(CreateSwapChain);
            _swapChainImageViews      = new ResettableLazy <ulong[]>(CreateSwapChainImageViews);

            _ = _state.Transition(to: Initialized);

            // Do event hookups after we are in the initialized state, since an event could
            // technically fire while the constructor is still running.

            _graphicsSurface.SizeChanged += HandleGraphicsSurfaceSizeChanged;
        }
Example #3
0
 internal SCSlideLayout(SCSlideMaster slideMaster, SlideLayoutPart sldLayoutPart)
 {
     _slideMaster    = slideMaster;
     SlideLayoutPart = sldLayoutPart;
     _shapes         = new ResettableLazy <ShapeCollection>(() =>
                                                            ShapeCollection.CreateForSlideLayout(sldLayoutPart.SlideLayout.CommonSlideData.ShapeTree, this));
 }
Example #4
0
        public GameViewModel()
        {
            gameCopy = new GameCopy();

            gameStats = new ResettableLazy <IEnumerable <GameItemGroupViewModel> >(() =>
                                                                                   GameItemGrouping.GroupItems(GameCopy.Items));
        }
Example #5
0
 internal SCParagraph(A.Paragraph aParagraph, SCTextBox textBox)
 {
     this.AParagraph    = aParagraph;
     this.Level         = GetInnerLevel(aParagraph);
     this.bullet        = new Lazy <Bullet>(this.GetBullet);
     this.ParentTextBox = textBox;
     this.portions      = new ResettableLazy <PortionCollection>(() => new PortionCollection(this.AParagraph, this));
 }
Example #6
0
            public void ReturnTheFactoryResultWhenCalledOnce()
            {
                var rl     = ResettableLazy.Create(() => TestResult);
                var result = rl.Value;

                result.Wait();
                Assert.Equal(TestResult, result.Result);
            }
Example #7
0
            public void ReturnFalseWhenCalledBeforeValue()
            {
                var rl     = new ResettableLazy <int>(() => TestResult);
                var result = rl.IsValueCreated;

                result.Wait();
                Assert.Equal(false, result.Result);
            }
Example #8
0
 internal SCTableCell(SCTableRow parentTableRow, A.TableCell aTableCell, int rowIndex, int columnIndex)
 {
     this.ParentTableRow = parentTableRow;
     this.ATableCell     = aTableCell;
     this.RowIndex       = rowIndex;
     this.ColumnIndex    = columnIndex;
     this.textBox        = new ResettableLazy <SCTextBox>(this.GetTextBox);
 }
Example #9
0
        public WindowProvider()
        {
            _classAtom    = new ResettableLazy <ushort>(CreateClassAtom);
            _nativeHandle = new ResettableLazy <GCHandle>(CreateNativeHandle);

            _windows = new ThreadLocal <Dictionary <IntPtr, Window> >(trackAllValues: true);
            _        = _state.Transition(to: Initialized);
        }
Example #10
0
 internal Category(
     ResettableLazy <List <X.Cell> > indexToXCell,
     int index,
     NumericValue cachedName)
 {
     _indexToXCell = indexToXCell;
     _index        = index;
     _cachedName   = cachedName;
 }
Example #11
0
 internal Category(
     ResettableLazy <List <X.Cell> > indexToXCell,
     int index,
     NumericValue cachedName,
     Category mainCategory) : this(indexToXCell, index, cachedName)
 {
     // TODO: what about creating a new separate class like MultiCategory:Category
     MainCategory = mainCategory;
 }
Example #12
0
 internal SCFont(A.Text aText, Portion portion)
 {
     this.aText       = aText;
     this.size        = new ResettableLazy <int>(this.GetSize);
     this.latinFont   = new ResettableLazy <A.LatinFont>(this.GetALatinFont);
     this.colorFormat = new Lazy <ColorFormat>(() => new ColorFormat(this));
     this.Portion     = portion;
     this.aFontScheme = ((Shape)portion.ParentParagraph.ParentTextBox.ParentTextBoxContainer).ThemePart.Theme.ThemeElements.FontScheme;
 }
 public HashStorage(ISimpleDataProvider dataProvider,
                    IDbConnectionProvider dbConnection, ILogger logger)
 {
     _dataProvider = dataProvider;
     _dbConnection = dbConnection;
     _logger       = logger;
     _hashStorage  = new ResettableLazy <HashSet <byte[]> >(InitHashSet);
     _tableName    = OrmUtils.GetTableName <TData>();
 }
Example #14
0
        /// <summary>Initializes a new instance of the <see cref="Application" /> class.</summary>
        /// <param name="compositionAssemblies">The <see cref="Assembly" /> instances to search for type exports.</param>
        /// <exception cref="ArgumentNullException"><paramref name="compositionAssemblies" /> is <c>null</c>.</exception>
        public Application(params Assembly[] compositionAssemblies)
        {
            ThrowIfNull(compositionAssemblies, nameof(compositionAssemblies));

            _compositionAssemblies = compositionAssemblies;
            _parentThread          = Thread.CurrentThread;
            _compositionHost       = new ResettableLazy <CompositionHost>(CreateCompositionHost);

            _ = _state.Transition(to: Stopped);
        }
Example #15
0
            public void ReturnTrueWhenCalledAfterValue()
            {
                var rl = new ResettableLazy <int>(() => TestResult);

                rl.Value.Wait();
                var result = rl.IsValueCreated;

                result.Wait();
                Assert.Equal(true, result.Result);
            }
Example #16
0
        public void IsEmptyByDefault()
        {
            var refLazy = new ResettableLazy <string>(() => "");

            Assert.IsFalse(refLazy.HasValue);

            var valLazy = new ResettableLazyValue <int>(() => 0);

            Assert.IsFalse(valLazy.HasValue);
        }
Example #17
0
        public void TakesValueFromCreator()
        {
            var refLazy = new ResettableLazy <string>(() => "Hello World");

            Assert.AreEqual("Hello World", refLazy.Value);

            var valLazy = new ResettableLazyValue <int>(() => 42);

            Assert.AreEqual(42, valLazy.Value);
        }
Example #18
0
            public void ReturnTheFactoryResultWhenCalledAfterReset()
            {
                var rl = ResettableLazy.Create(() => Task.FromResult(TestResult));

                rl.Value.Wait();
                rl.Reset();
                var result = rl.Value;

                result.Wait();
                Assert.Equal(TestResult, result.Result);
            }
Example #19
0
 internal SlideTable(
     OpenXmlCompositeElement pShapeTreeChild,
     ILocation innerTransform,
     ShapeContext spContext,
     SCSlide slide) : base(slide, pShapeTreeChild)
 {
     this.innerTransform = innerTransform;
     Context             = spContext;
     rowCollection       =
         new ResettableLazy <RowCollection>(() => RowCollection.Create(this, (P.GraphicFrame)PShapeTreeChild));
     pGraphicFrame = pShapeTreeChild as P.GraphicFrame;
 }
Example #20
0
 public ExtendedEventDataSaver(IDbConnectionProvider connectionProvider,
                               IQueryTextStoringService queryTextStoringService, IDateRepository dateRepository,
                               ILogger <ExtendedEventDataSaver> logger)
 {
     _connectionProvider      = connectionProvider;
     _queryTextStoringService = queryTextStoringService;
     _dateRepository          = dateRepository;
     _logger             = logger;
     _lockModeRepository = new SimpleLookupRepository <LockingMode>(connectionProvider);
     _lastQueryDate      = new ResettableLazy <DateTime>(connectionProvider.GetLastQueryDate <LongInfoRecord>);
     _lastDeadLockDate   = new ResettableLazy <DateTime>(connectionProvider.GetLastQueryDate <DeadLockInfoRecord>);
 }
Example #21
0
        public void CanBeInitialized()
        {
            var refLazy = new ResettableLazy <string>(() => "", "Hello World");

            Assert.IsTrue(refLazy.HasValue);
            Assert.AreEqual("Hello World", refLazy.Value);

            var valLazy = new ResettableLazyValue <int>(() => 0, 42);

            Assert.IsTrue(valLazy.HasValue);
            Assert.AreEqual(valLazy.Value, 42);
        }
Example #22
0
        public void IsNotEmptyAfterAccess()
        {
            var refLazy = new ResettableLazy <string>(() => "");

            _ = refLazy.Value;
            Assert.IsTrue(refLazy.HasValue);

            var valLazy = new ResettableLazyValue <int>(() => 0);

            _ = valLazy.Value;
            Assert.IsTrue(valLazy.HasValue);
        }
Example #23
0
            public void CauseOnlySingleCallOfTheFactoryWhenCalledTwice()
            {
                var count = 0;
                var rl    = new ResettableLazy <int>(() =>
                {
                    count++;
                    return(TestResult);
                });

                rl.Value.Wait();
                rl.Value.Wait();
                Assert.Equal(1, count);
            }
Example #24
0
 public MappedDB()
 {
     foreach (var moduleType in Enum.GetValues(typeof(ModuleType)).Cast <ModuleType>())
     {
         modules.Add(moduleType, new Dictionary <UID, Row>());
     }
     fairiesByIndex = new ResettableLazy <IReadOnlyDictionary <int, FairyRow> >(
         () => Fairies.ToDictionary(f => f.CardId.EntityId, f => f));
     itemsByIndex = new ResettableLazy <IReadOnlyDictionary <int, ItemRow> >(
         () => Items.ToDictionary(i => i.CardId.EntityId, i => i));
     spellsByIndex = new ResettableLazy <IReadOnlyDictionary <int, SpellRow> >(
         () => Spells.ToDictionary(s => s.CardId.EntityId, s => s));
 }
Example #25
0
        private DispatchProvider()
        {
            _dispatchers = new ConcurrentDictionary <Thread, IDispatcher>();

            _dispatcherExitRequestedAtom = new ResettableLazy <UIntPtr>(CreateDispatcherExitRequestedAtom);
            _display          = new ResettableLazy <UIntPtr>(CreateDisplay);
            _systemIntPtrAtom = new ResettableLazy <UIntPtr>(CreateSystemIntPtrAtom);
            _windowProviderCreateWindowAtom = new ResettableLazy <UIntPtr>(CreateWindowProviderCreateWindowAtom);
            _windowWindowProviderAtom       = new ResettableLazy <UIntPtr>(CreateWindowWindowProviderAtom);
            _wmProtocolsAtom    = new ResettableLazy <UIntPtr>(CreateWmProtocolsAtom);
            _wmDeleteWindowAtom = new ResettableLazy <UIntPtr>(CreateWmDeleteWindowAtom);

            _ = _state.Transition(to: Initialized);
        }
Example #26
0
        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);
        }
Example #27
0
            public void CauseOnlySingleCallOfTheFactoryWhenCalledByMultipleThreads()
            {
                var count = 0;
                var rl    = new ResettableLazy <int>(() =>
                {
                    return(Task.Run(() =>
                    {
                        count++;
                        return TestResult;
                    }));
                });

                Enumerable.Repeat(string.Empty, 20).AsParallel().ToList().ForEach(_ => rl.Value.Wait());
                Assert.Equal(1, count);
            }
Example #28
0
        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();
        }
Example #29
0
        public void DoesNotCallCreatorEarly()
        {
            bool didCallRef = false;
            var  refLazy    = new ResettableLazy <string>(() => { didCallRef = true; return(""); });

            Assert.IsFalse(didCallRef);
            _ = refLazy.Value;
            Assert.IsTrue(didCallRef);

            bool didCallVal = false;
            var  valLazy    = new ResettableLazyValue <int>(() => { didCallVal = true; return(0); });

            Assert.IsFalse(didCallVal);
            _ = valLazy.Value;
            Assert.IsTrue(didCallVal);
        }
Example #30
0
 protected void Initialize(
     Func <Application> application,
     Func <List <Action> > actions,
     Func <List <ClaimSet> > claimSets,
     Func <List <ResourceClaim> > resourceClaims,
     Func <List <AuthorizationStrategy> > authorizationStrategies,
     Func <List <ClaimSetResourceClaimAction> > claimSetResourceClaimActions,
     Func <List <ResourceClaimAction> > resourceClaimActions)
 {
     Application                  = new ResettableLazy <Application>(application);
     Actions                      = new ResettableLazy <List <Action> >(actions);
     ClaimSets                    = new ResettableLazy <List <ClaimSet> >(claimSets);
     ResourceClaims               = new ResettableLazy <List <ResourceClaim> >(resourceClaims);
     AuthorizationStrategies      = new ResettableLazy <List <AuthorizationStrategy> >(authorizationStrategies);
     ClaimSetResourceClaimActions = new ResettableLazy <List <ClaimSetResourceClaimAction> >(claimSetResourceClaimActions);
     ResourceClaimActions         = new ResettableLazy <List <ResourceClaimAction> >(resourceClaimActions);
 }
 public void SetUp()
 {
     _resettableLazy = new ResettableLazy<Lazy<int>, int>(() => new Lazy<int>(() => 0));
 }