Example #1
0
 public HUtils(IInstanceProvider instanceProvider)
 {
     configService      = instanceProvider.GetInstance <IConfigService>();
     fullscreenAdsModel = instanceProvider.GetInstance <IFullscreenAdsModel>();
     lifetimeStatistics = instanceProvider.GetInstance <ILifetimeStatistics>();
     showCustomAdSignal = instanceProvider.GetInstance <ShowCustomAdSignal>();
 }
Example #2
0
        internal object GetInstance(InstanceContext instanceContext)
        {
            if (provider == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxNoDefaultConstructor));
            }

            return(provider.GetInstance(instanceContext));
        }
Example #3
0
        public virtual async Task <IEventSourcedEntity> GetAsync(Type aggregateType, string streamName, int minRevision = 0, int maxRevision = int.MaxValue)
        {
            if (streamName.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(streamName));
            }

            var streamEntries = await persistenceEngine
                                .LoadStreamEntriesByStreamAsync(streamName)
                                .ToListAsync();

            if (streamEntries.Count == 0)
            {
                return(null);
            }

            var instance = (IEventSourcedEntity)instanceProvider.GetInstance(aggregateType);

            var events = new List <IEvent>();

            for (var i = 0; i < streamEntries.Count; i++)
            {
                var rawStreamEntry = streamEntries[i];

                events.Add((IEvent)persistenceEngine.Serializer.Deserialize(rawStreamEntry.Payload));
            }

            instance.LoadEvents(events);

            return(instance);
        }
Example #4
0
 private void Initialize()
 {
     if (!_initialized)
     {
         _js = _jsRuntimeProvider.GetInstance();
         _js.Initialize();
         _js.LoadLibrary(Utility.ResourceAsString(CompilerLibraryResourceName, this.GetType()));
         _initialized = true;
     }
 }
Example #5
0
        private object GetInstanceAndInit(IInstanceProvider instanceProvider)
        {
            object value = null;
            bool   isNew;

            instanceProvider.GetInstance(out value, out isNew);
            if (isNew)
            {
                InjectInto(value);
            }
            return(value);
        }
        public object GetInstance()
        {
            var instance = instanceProvider.GetInstance();
            var factory  = instance as IFactory ?? throw new Exception();

            if (factory.TryCreate(out var result) == false)
            {
                throw new Exception("Failed to create object.");
            }

            return(result);
        }
        public void RunOperation_ReceiveLogA()
        {
            IList <LogRecord> logRecords = null;

            try
            {
                using (var context = _logDbContextProvider.GetInstance())
                {
                    context.LogRecords.RemoveRange(context.LogRecords);
                    context.SaveChanges();

                    foreach (EventLog eventLog in _eventLogs)
                    {
                        if (eventLog != null)
                        {
                            _logic.ReceiveLogA(eventLog).GetAwaiter().GetResult();

                            logRecords = context.LogRecords.Where(lr => lr.Logger == eventLog.Logger).ToList();

                            if (eventLog.IsValid())
                            {
                                Assert.AreEqual(logRecords.Count, 1);
                            }
                            else
                            {
                                Assert.AreEqual(logRecords.Count, 0);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Example #8
0
        private object GetInstanceAndInit(IInstanceProvider instanceProvider)
        {
            object value = null;
            bool   isNew;

            instanceProvider.GetInstance(out value, out isNew);
            if (isNew)
            {
                InjectInto(value);
                if (instanceProvider.PostInjectionCallback != null)
                {
                    instanceProvider.PostInjectionCallback(value);
                }
            }
            return(value);
        }
Example #9
0
        public T GetObject()
        {
            if (instances.TryTake(out var item))
            {
                return(item);
            }

            if (instanceProvider == null)
            {
                return(item);
            }

            var instance = instanceProvider.GetInstance() as T;

            item = instance ?? throw new Exception();

            return(item);
        }
Example #10
0
        private void RunForSize(IInstanceProvider instanceProvider, ISolver exactSolver, ISolver solver, int variableCount)
        {
            var instances    = Enumerable.Range(0, BATCH_SIZE).Select(x => instanceProvider.GetInstance(variableCount)).ToArray();
            var exactResults = instances.AsParallel().AsOrdered().Select(exactSolver.Solve).ToArray();
            var results      = instances.Select(solver.Solve).ToArray();

            var zipped           = exactResults.Zip(results, (er, r) => new { er, r }).ToArray();
            var hasSolution      = zipped.Where(x => x.er.Configuration != 0).ToArray();
            var hasBothSolutions = hasSolution.Where(x => x.r.Configuration != 0).ToArray();

            var relativeDivergences       = hasBothSolutions.Select(i => (i.er.Weight - i.r.Weight) / (double)i.er.Weight).ToArray();
            var averageRelativeDivergence = relativeDivergences.Average(x => x);
            var maxRelativeDivergence     = relativeDivergences.Max(x => x);
            var notExactSolutions         = zipped.Count(x => x.er.Weight != x.r.Weight);
            var solutionNotFound          = hasSolution.Length - hasBothSolutions.Length;

            Console.WriteLine($"Variable Count:              {variableCount}");
            Console.WriteLine($"Average Relative Divergence: {averageRelativeDivergence}");
            Console.WriteLine($"Max Relative Divergence:     {maxRelativeDivergence}");
            Console.WriteLine($"Not Exact Solutions:         {notExactSolutions}");
            Console.WriteLine($"Solution Not Found:          {solutionNotFound}");
        }
Example #11
0
        protected virtual void Execute(ContentTransformState state, params object[] args)
        {
            // If input is empty or the wrong type, do nothing
            if (state.Content == null || state.MimeType != InputMimeType)
            {
                return;
            }

            string result = null;

            using (var compiler = _jsCompilerProvider.GetInstance()) {
                result = compiler.Compile(state.Content, args);
            }

            if (result != null)
            {
                state.ReplaceContent(new ContentResult()
                {
                    Content  = result,
                    MimeType = OutputMimeType,
                });
            }
        }
Example #12
0
        public static IRepository <TEntity, TKey> GetRepositoryFor <TEntity, TKey>(this IInstanceProvider instanceProvider) where TEntity : class, IEntity <TKey> where TKey : IEquatable <TKey>
        {
            var repositoryType = typeof(IRepository <,>).MakeGenericType(typeof(TEntity), typeof(TKey));

            return((IRepository <TEntity, TKey>)instanceProvider.GetInstance(repositoryType));
        }
 private T ResolveExecutable <T>()
 {
     return((T)instanceProvider.GetInstance(typeof(T)));
 }
Example #14
0
 public HEconomy(IInstanceProvider instanceProvider)
 {
     economyModel = instanceProvider.GetInstance <IEconomyModel>();
     onCustomizationActivatedSignal = instanceProvider.GetInstance <OnCustomizationActivatedSignal>();
     onCustomizationActivatedSignal.AddListener(ActivateCustomizationItem);
 }
Example #15
0
        Object IInstanceProvider.GetInstance(InstanceContext instanceContext, Message message)
        {
            IInstanceProvider selfAsIInstanceProvider = this;

            return(selfAsIInstanceProvider.GetInstance(instanceContext));
        }
Example #16
0
 public object GetInstance(InstanceContext instanceContext)
 {
     return(m_ServiceDurableInstanceProvider.GetInstance(instanceContext));
 }
Example #17
0
 public object GetInstance()
 {
     return(instance ??= instanceProvider.GetInstance());
 }
Example #18
0
        public HGameplay(IInstanceProvider instanceProvider)
        {
            audioPlayer               = instanceProvider.GetInstance <IAudioPlayerModel>();
            customSaveModel           = instanceProvider.GetInstance <ICustomSaveModel>();
            scoreModel                = instanceProvider.GetInstance <IScoreModel>();
            gameEndModel              = instanceProvider.GetInstance <IGameEndModel>();
            sessionStatistics         = instanceProvider.GetInstance <ISessionStatistics>();
            interstitialsDisplayModel = instanceProvider.GetInstance <InterstitialsDisplayModel>();
            gameStartSignal           = instanceProvider.GetInstance <GameStartSignal>();
            updateBestScoreSignal     = instanceProvider.GetInstance <UpdateBestScoreSignal>();
            newLevelSignal            = instanceProvider.GetInstance <NewLevelSignal>();
            endLevelSignal            = instanceProvider.GetInstance <EndLevelSignal>();
            currentLevelChangeSignal  = instanceProvider.GetInstance <CurrentLevelChangeSignal>();

            gameContinueSignal = instanceProvider.GetInstance <GameContinueSignal>();
            gameContinueSignal.AddListener(ContinueGame);

            gamePauseSignal = instanceProvider.GetInstance <GamePauseSignal>();
            gamePauseSignal.AddListener(PauseGame);

            gameResumeSignal = instanceProvider.GetInstance <GameResumeSignal>();
            gameResumeSignal.AddListener(ResumeGame);
        }
        public static IValidation GetValidationFor(this IInstanceProvider instanceProvider, Type entityType)
        {
            var validationType = typeof(IValidation <>).MakeGenericType(entityType);

            return((IValidation)instanceProvider.GetInstance(validationType));
        }