Пример #1
0
        public void EnsureRuntimeDatabaseValidity()
        {
            // This workaround allows service to start inside container without crashing on db connection for the first time.
            // Problem (docker) - Even that api service depends on db service, postgres default behaviour is that it reset itself after first start.
            // This results in small time period when db service is unavailable and api startup process crashes.
            Thread.Sleep(5 * 1000);

            var dbContextOptions = new DbContextOptionsBuilder <DssDataContext>()
                                   .UseNpgsql(_configuration.GetValue <string>("DssConnectionString"))
                                   .Options;

            var dbContext = new DssDataContext(dbContextOptions);

            // checks if db is created and does migration if needed
            dbContext.Database.EnsureCreated();

            // just a simple check => not reliable
            var demoDataValid = dbContext.RegisteredClientActions.Any();

            if (demoDataValid == false)
            {
                var initializer = new DemoDataInitializer(dbContext);
                initializer.CreateDemoData();
            }
        }
        protected void SaveOnClick(object sender, EventArgs e)
        {
            string[] keys = JsonConvert.DeserializeObject<string[]>(hfKeys.Value);
            decimal[] values = JsonConvert.DeserializeObject<decimal[]>(hfData.Value);
            var dictionary = new Dictionary<string, decimal>(keys.Length);
            for (int i = 0; i < keys.Length; i++)
            {
                dictionary.Add(keys[i], values[i]);
            }

            using (var context = new DssDataContext())
            {
                bool hasChanges = false;
                var depended = GetDependedScale(context);
                foreach (var critFuzzy in depended)
                {
                    decimal newValue = dictionary[critFuzzy.name];
                    if (critFuzzy.rank.Value != newValue)
                    {
                        critFuzzy.rank = newValue;
                        hasChanges = true;
                    }
                }
                if (hasChanges)
                    context.SubmitChanges();
            }
            Response.Redirect("Criteria.aspx", true);
        }
Пример #3
0
        private DssDataContext GetInMemoryDataContext()
        {
            var options = GetInMemoryDataContextOptions();

            var dataContext = new DssDataContext(options);

            return(dataContext);
        }
Пример #4
0
 public IndividualPlansApiService(DssDataContext dataContext, IHttpContextAccessor httpContextAccessor) :
     base(dataContext, httpContextAccessor)
 {
 }
 private List<crit_scale> GetDependedScale(DssDataContext context)
 {
     return (from crit in context.crit_scales
             where crit.criteria_id == CriteriaId
             orderby crit.ord
             select crit).ToList();
 }
        private void MyDataBind()
        {
            if (CriteriaId < 0)
            {
                Visible = false;
                return;
            }
            using (var context = new DssDataContext())
            {
                var criteria = context.criterias.First(x => x.id == CriteriaId);
                FunctionName = criteria.name;
                var dependedCrit = context.criterias.First(x => x.parent_crit_id == CriteriaId);
                CriteriaName = dependedCrit.name;

                bool isNumber = criteria.is_number != 0;
                ViewState.Add("isNumber", isNumber);

                var depended = GetDependedScale(context);
                Categories = string.Join(",", depended.Select(x => "'" + x.name + "'"));
                Data = string.Join(",", depended.Select(x => x.rank.Value.ToString(CultureInfo.InvariantCulture)));
            }
            hfKeys.Value = "[" + Categories + "]";
        }
 public AgreedActionsApiService(DssDataContext dataContext, IHttpContextAccessor httpContextAccessor) :
     base(dataContext, httpContextAccessor)
 {
 }
 public RegisteredActionsController(DssDataContext dbContext, IRegisteredActionsApiService registeredActionsApiService)
 {
     _registeredActionsApiService = registeredActionsApiService;
     _dataContext = dbContext;
 }
 public EmployeeApiService(DssDataContext dataContext, IHttpContextAccessor httpContextAccessor) :
     base(dataContext, httpContextAccessor)
 {
 }
Пример #10
0
 private bool IsScaleVisible()
 {
     if (TreeView1.SelectedNode == null)
         return false;
     var critId = int.Parse(TreeView1.SelectedNode.Value);
     using (var context = new DssDataContext())
     {
         bool hasChild = context.criterias.Any(x => x.parent_crit_id == critId);
         bool isScaleVisible = !hasChild;
         if (isScaleVisible)
             ScaleEditHL.NavigateUrl = string.Format("Fuzzy.aspx?id={0}&isScale=1", critId);
         return isScaleVisible;
     }
 }
        private void ScaleInit()
        {
            using (var context = new DssDataContext())
            {
                var criteria = context.criterias.First(x => x.id == CriteriaId);
                FunctionName = criteria.name;

                var depended = GetDependedScale(context);
                Categories = string.Join(",", depended.Select(x => "'" + x.name + "'"));
                Data = string.Join(",", depended.Select(x => x.rank.Value.ToString(CultureInfo.InvariantCulture)));
                MaxValue = (int) Math.Ceiling(depended.Max(x => x.rank.Value));
            }
            hfKeys.Value = "[" + Categories + "]";
        }
Пример #12
0
 public ClientApiService(DssDataContext dataContext, IHttpContextAccessor httpContextAccessor) :
     base(dataContext, httpContextAccessor)
 {
 }
Пример #13
0
 protected ApiTestBase()
 {
     DataContext = GetInMemoryDataContext();
 }
Пример #14
0
 public DemoDataInitializer(DssDataContext dataContext)
 {
     _dataContext  = dataContext;
     _imageFetcher = new ImageFetcher();
 }
Пример #15
0
 public ApiServiceBase(DssDataContext dataContext, IHttpContextAccessor httpContextAccessor)
 {
     DataContext          = dataContext;
     _httpContextAccessor = httpContextAccessor;
 }
 public JwtAuthenticationApiService(DssDataContext dataContext, IHttpContextAccessor httpContextAccessor, Microsoft.Extensions.Configuration.IConfiguration config)
     : base(dataContext, httpContextAccessor)
 {
     _config = config;
 }
Пример #17
0
 public DemoDataInitializer(DssDataContext dataContext, IImageFetcherService imageFetcher)
 {
     _dataContext  = dataContext;
     _imageFetcher = imageFetcher;
 }