Пример #1
0
        public bool SaveSettingsFor <T>(T settings, int tenantId, Guid userId) where T : ISettings
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            try
            {
                var key  = settings.ID.ToString() + tenantId + userId;
                var data = Serialize(settings);

                var def = (T)settings.GetDefault(ServiceProvider);

                var defaultData = Serialize(def);

                var tr = WebstudioDbContext.Database.BeginTransaction();

                if (data.SequenceEqual(defaultData))
                {
                    // remove default settings
                    var s = WebstudioDbContext.WebstudioSettings
                            .Where(r => r.Id == settings.ID)
                            .Where(r => r.TenantId == tenantId)
                            .Where(r => r.UserId == userId)
                            .FirstOrDefault();

                    if (s != null)
                    {
                        WebstudioDbContext.WebstudioSettings.Remove(s);
                    }
                }
                else
                {
                    var s = new DbWebstudioSettings
                    {
                        Id       = settings.ID,
                        UserId   = userId,
                        TenantId = tenantId,
                        Data     = data
                    };

                    WebstudioDbContext.AddOrUpdate(r => r.WebstudioSettings, s);
                }

                WebstudioDbContext.SaveChanges();
                tr.Commit();

                DbSettingsManagerCache.Remove(key);

                Cache.Insert(key, settings, expirationTimeout);
                return(true);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(false);
            }
        }
Пример #2
0
 public DbSettingsManager(
     IServiceProvider serviceProvider,
     DbSettingsManagerCache dbSettingsManagerCache,
     IOptionsMonitor <ILog> option,
     AuthContext authContext,
     TenantManager tenantManager,
     DbContextManager <WebstudioDbContext> dbContextManager) : this(null)
 {
     ServiceProvider        = serviceProvider;
     DbSettingsManagerCache = dbSettingsManagerCache;
     AuthContext            = authContext;
     TenantManager          = tenantManager;
     Cache = dbSettingsManagerCache.Cache;
     log   = option.CurrentValue;
     WebstudioDbContext = dbContextManager.Value;
 }
Пример #3
0
 public BaseIndexer(
     Client client,
     IOptionsMonitor <ILog> log,
     DbContextManager <WebstudioDbContext> dbContextManager,
     TenantManager tenantManager,
     BaseIndexerHelper baseIndexerHelper,
     Settings settings,
     IServiceProvider serviceProvider)
 {
     Client             = client;
     Log                = log.CurrentValue;
     TenantManager      = tenantManager;
     BaseIndexerHelper  = baseIndexerHelper;
     Settings           = settings;
     ServiceProvider    = serviceProvider;
     WebstudioDbContext = dbContextManager.Value;
 }
Пример #4
0
 public StatisticManager(DbContextManager <WebstudioDbContext> dbContextManager)
 {
     WebstudioDbContext = dbContextManager.Value;
 }