Ejemplo n.º 1
0
        /// <summary>
        /// Is the gate applicable for the current context
        /// </summary>
        /// <param name="gate">gate to check</param>
        /// <returns>true if applicable, false otherwise</returns>
        private bool IsGateApplicableInternal(IGate gate)
        {
            bool grantAccess = gate.IsGateEnabled;

            // If the gate is disabled but has been asked to be enabled through settings.
            if (m_settings?.GatesToggleEnabled?.Contains(gate.Name) ?? false)
            {
                grantAccess = true;
                ULSLogging.LogTraceTag(0x2382104e /* tag_967bo */, Categories.GateSelection, Levels.Verbose, "Enabling gate '{0}' through BRS that was disabled using gate toggle setting",
                                       gate.Name);
            }

            grantAccess = grantAccess && DoesHostEnvironmentHaveAccess(gate);
            grantAccess = grantAccess && DoesServiceHaveAccess(gate);
            grantAccess = grantAccess && DoesIPAddressHaveAccess(gate);
            grantAccess = grantAccess && DoesMarketHaveAccess(gate);
            grantAccess = grantAccess && DoesEnvironmentHaveAccess(gate);
            grantAccess = grantAccess && DoesBrowserHaveAccess(gate);
            grantAccess = grantAccess && DoesClientHaveAccess(gate);
            grantAccess = grantAccess && DoesUserHaveAccess(gate);
            grantAccess = grantAccess && IsCurrentDateEnabled(gate);
            grantAccess = grantAccess && DoQueryParametersHaveAccess(gate);
            grantAccess = grantAccess && DoesCloudContextHaveAccess(gate);

            if (gate.ExperimentInfo != null)
            {
                grantAccess = grantAccess && ExperimentContext.IsExperimentalGateApplicable(gate);
            }

            return(grantAccess);
        }
 public Result <ExperimentModel> GetExperiment(long id)
 {
     using (var experimentContext = new ExperimentContext())
     {
         var Experiment = experimentContext.Experiments.FirstOrDefault(c => c.Id == id);
         if (Experiment != null)
         {
             return(Result.Ok(Experiment));
         }
     }
     return(Result.Failure <ExperimentModel>(null));
 }
        private Dictionary <string, Color> GetGroupColors()
        {
            Dictionary <string, string> sampleGrouping = ExperimentContext.GetGrouping();
            List <string> groups = new List <string>(sampleGrouping.Values.Distinct());
            Dictionary <string, Color> groupColors = new Dictionary <string, Color>();

            for (int i = 0; i < groups.Count; i++)
            {
                string group = groups[i] ?? "";
                groupColors[group] = colorArray[i % colorArray.Length];
            }
            return(groupColors);
        }
        public ExperimentController(ExperimentContext context)
        {
            this.context = context;

            if (context.AccelData.Count() == 0)
            {
                // Create a new TodoItem if collection is empty,
                // which means you can't delete all TodoItems.
                context.AccelData.Add(new AccelData {
                    Time = DateTime.Now, Acceleration = 0.04M
                });
                context.SaveChanges();
            }
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            //services.AddDbContext<ExperimentContext>(opt =>
            //    opt.UseInMemoryDatabase("TodoList"));
            string connectionString = Configuration.GetConnectionString("ZhengylDatabase");

            services.AddDbContext <ExperimentContext>(options =>
                                                      options.UseSqlServer(connectionString));

            using (var context = new ExperimentContext())
            {
                var blogs = context.AccelData.ToListAsync();
            }
        }
        private void CompoundSelectionChanged(ICompoundGroup obj)
        {
            if (obj != null)
            {
                IDictionary <string, ICompound> sampleWiseDataDictionary = obj.SampleWiseDataDictionary;
                Dictionary <string, string>     sampleGrouping           = ExperimentContext.GetGrouping();
                GroupColors = GetGroupColors();
                PlotItems   = new List <PlotItem>();
                foreach (string sampleName in sampleWiseDataDictionary.Keys)
                {
                    PlotItems.Add(new PlotItem(sampleName, sampleGrouping[sampleName], sampleWiseDataDictionary[sampleName]));
                }

                UpdatePlotControl();
            }
        }
        public void UpadateExperimentHandler()
        {
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            var task = Task.Run(async() =>
            {
                using var consumerBuilder = new ConsumerBuilder <Null, ExperimentModel>(consumerConfig)
                                            .SetValueDeserializer(new JsonDeserializer <ExperimentModel>().AsSyncOverAsync())
                                            .Build();
                {
                    consumerBuilder.Subscribe("UpadateExperimentCommand");
                    try
                    {
                        while (true)
                        {
                            try
                            {
                                var consumeResult = consumerBuilder.Consume(cancellationTokenSource.Token);
                                if (consumeResult != null && consumeResult.Message.Value != null)
                                {
                                    var Experiment = GetExperiment(consumeResult.Message.Value.Id);
                                    if (Experiment.IsSuccess)
                                    {
                                        using (var experimentContext = new ExperimentContext())
                                        {
                                            var existExperiment       = Experiment.Value;
                                            existExperiment.Name      = consumeResult.Message.Value.Name;
                                            existExperiment.TimeStamp = consumeResult.Message.Value.TimeStamp;
                                            experimentContext.Experiments.Update(existExperiment);
                                            experimentContext.SaveChanges();

                                            await _experimentEventsService.ExperimentUpadatedEvent(existExperiment);
                                        }
                                    }
                                }
                            }
                            catch (ConsumeException consumeException)
                            {
                            }
                        }
                    }
                    catch (OperationCanceledException)
                    {
                        consumerBuilder.Close();
                    }
                }
            });
        }
        public Result CreateExperimentHandler()
        {
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            var task = Task.Run(() =>
            {
                using var consumerBuilder = new ConsumerBuilder <Null, ExperimentModel>(consumerConfig)
                                            .SetValueDeserializer(new JsonDeserializer <ExperimentModel>().AsSyncOverAsync())
                                            .Build();
                consumerBuilder.Subscribe("CreateExperimentCommand");
                try
                {
                    while (true)
                    {
                        try
                        {
                            var consumeResult = consumerBuilder.Consume(cancellationTokenSource.Token);
                            if (consumeResult != null && consumeResult.Message != null)
                            {
                                using var experimentContext = new ExperimentContext();
                                try
                                {
                                    var experiment = consumeResult.Message.Value;
                                    experimentContext.Experiments.Add(experiment);
                                    experimentContext.SaveChanges();
                                    _experimentEventsService.ExperimentCreatedEvent(experiment);
                                }
                                catch (Exception exception)
                                {
                                }
                            }
                        }
                        catch (ConsumeException consumeException)
                        {
                        }
                    }
                }
                catch (OperationCanceledException)
                {
                    consumerBuilder.Close();
                }
            });

            return(Result.Ok());
        }
        private void CompoundSelectionChanged(ICompoundGroup compoundGroupObject)
        {
            if (compoundGroupObject == null)
            {
                return;
            }

            IDictionary <string, ICompound> sampleWiseDataDictionary = compoundGroupObject.SampleWiseDataDictionary;
            Dictionary <string, string>     sampleGrouping           = ExperimentContext.GetGrouping();

            GroupColors = GetGroupColors();
            PlotItems   = new List <PlotItem>();
            foreach (string sampleName in sampleWiseDataDictionary.Keys)
            {
                PlotItems.Add(new PlotItem(sampleName, sampleGrouping[sampleName], sampleWiseDataDictionary[sampleName]));
            }

            DisplayMode = "List";
            UpdatePlotControl();
        }
Ejemplo n.º 10
0
 public ExperimentRepository(ExperimentContext context)
 {
     this._context = context ?? throw new ArgumentNullException(nameof(context));
 }