예제 #1
0
        public void ClearCache <T>(int tenantId) where T : class, ISettings
        {
            var settings = LoadSettings <T>(tenantId);
            var key      = settings.ID.ToString() + tenantId + Guid.Empty;

            DbSettingsManagerCache.Remove(key);
        }
예제 #2
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);
            }
        }
예제 #3
0
 public DbSettingsManager(
     IServiceProvider serviceProvider,
     DbSettingsManagerCache dbSettingsManagerCache,
     DbOptionsManager optionsDbManager,
     IOptionsMonitor <ILog> option,
     AuthContext authContext, TenantManager tenantManager) : this(null)
 {
     ServiceProvider        = serviceProvider;
     DbSettingsManagerCache = dbSettingsManagerCache;
     AuthContext            = authContext;
     TenantManager          = tenantManager;
     Cache     = dbSettingsManagerCache.Cache;
     DbManager = optionsDbManager.Value;
     log       = option.CurrentValue;
 }
예제 #4
0
 public ConfigureDbSettingsManager(
     IServiceProvider serviceProvider,
     DbSettingsManagerCache dbSettingsManagerCache,
     IOptionsMonitor <ILog> iLog,
     AuthContext authContext,
     IOptionsSnapshot <TenantManager> tenantManager,
     DbContextManager <WebstudioDbContext> dbContextManager
     )
 {
     ServiceProvider        = serviceProvider;
     DbSettingsManagerCache = dbSettingsManagerCache;
     ILog             = iLog;
     AuthContext      = authContext;
     TenantManager    = tenantManager;
     DbContextManager = dbContextManager;
 }
예제 #5
0
 public DbSettingsManager(
     IServiceProvider serviceProvider,
     DbSettingsManagerCache dbSettingsManagerCache,
     IOptionsMonitor <ILog> option,
     AuthContext authContext,
     TenantManager tenantManager,
     DbContextManager <WebstudioDbContext> dbContextManager)
 {
     ServiceProvider        = serviceProvider;
     DbSettingsManagerCache = dbSettingsManagerCache;
     AuthContext            = authContext;
     TenantManager          = tenantManager;
     Cache = dbSettingsManagerCache.Cache;
     Log   = option.CurrentValue;
     WebstudioDbContext = dbContextManager.Value;
 }
예제 #6
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 db  = DbManager;
                var def = (T)settings.GetDefault(ServiceProvider);

                var defaultData = Serialize(def);

                ISqlInstruction i;
                if (data.SequenceEqual(defaultData))
                {
                    // remove default settings
                    i = new SqlDelete("webstudio_settings")
                        .Where("id", settings.ID.ToString())
                        .Where("tenantid", tenantId)
                        .Where("userid", userId.ToString());
                }
                else
                {
                    i = new SqlInsert("webstudio_settings", true)
                        .InColumnValue("id", settings.ID.ToString())
                        .InColumnValue("userid", userId.ToString())
                        .InColumnValue("tenantid", tenantId)
                        .InColumnValue("data", data);
                }

                DbSettingsManagerCache.Remove(key);

                db.ExecuteNonQuery(i);

                Cache.Insert(key, settings, expirationTimeout);
                return(true);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(false);
            }
        }