コード例 #1
0
        public IEnumerable <TenantQuotaRow> FindTenantQuotaRows(TenantQuotaRowQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            IQueryable <DbQuotaRow> q = CoreDbContext.QuotaRows;


            if (query.Tenant != Tenant.DEFAULT_TENANT)
            {
                q = q.Where(r => r.Tenant == query.Tenant);
            }
            if (!string.IsNullOrEmpty(query.Path))
            {
                q = q.Where(r => r.Path == query.Path);
            }

            if (query.LastModified != default)
            {
                q = q.Where(r => r.LastModified >= query.LastModified);
            }


            return(q.Select(FromDbQuotaRowToTenantQuotaRow).ToList());
        }
コード例 #2
0
        public IEnumerable <TenantQuotaRow> FindTenantQuotaRows(TenantQuotaRowQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            var q = new SqlQuery(tenants_quotarow).Select("tenant", "path", "counter", "tag");

            if (query.Tenant != Tenant.DEFAULT_TENANT)
            {
                q.Where("tenant", query.Tenant);
            }
            if (!string.IsNullOrEmpty(query.Path))
            {
                q.Where("path", query.Path);
            }
            if (query.LastModified != default(DateTime))
            {
                q.Where(Exp.Ge("last_modified", query.LastModified));
            }

            return(ExecList(q)
                   .ConvertAll(r => new TenantQuotaRow
            {
                Tenant = Convert.ToInt32(r[0]),
                Path = (string)r[1],
                Counter = Convert.ToInt64(r[2]),
                Tag = (string)r[3],
            }));
        }
コード例 #3
0
 public List <TenantQuotaRow> FindTenantQuotaRows(TenantQuotaRowQuery query)
 {
     return(quotaService.FindTenantQuotaRows(query).ToList());
 }
コード例 #4
0
        public IEnumerable <TenantQuotaRow> FindTenantQuotaRows(TenantQuotaRowQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            if (Interlocked.CompareExchange(ref syncQuotaRows, 1, 0) == 0)
            {
                try
                {
                    var rows = cache.Get(KEY_QUOTA_ROWS) as Dictionary <string, List <TenantQuotaRow> >;
                    if (rows == null || interval.Expired)
                    {
                        var date = rows != null ? interval.StartTime : DateTime.MinValue;
                        interval.Start(CacheExpiration);

                        var changes = service.FindTenantQuotaRows(new TenantQuotaRowQuery(Tenant.DEFAULT_TENANT).WithLastModified(date))
                                      .GroupBy(r => r.Tenant.ToString())
                                      .ToDictionary(g => g.Key, g => g.ToList());

                        // merge changes from db to cache
                        if (rows == null)
                        {
                            rows = changes;
                        }
                        else
                        {
                            foreach (var p in changes)
                            {
                                if (rows.ContainsKey(p.Key))
                                {
                                    var cachedRows = rows[p.Key];
                                    foreach (var r in p.Value)
                                    {
                                        cachedRows.RemoveAll(c => c.Path == r.Path);
                                        cachedRows.Add(r);
                                    }
                                }
                                else
                                {
                                    rows[p.Key] = p.Value;
                                }
                            }
                        }

                        cache.Insert(KEY_QUOTA_ROWS, rows, DateTime.UtcNow.Add(CacheExpiration));
                    }
                }
                finally
                {
                    syncQuotaRows = 0;
                }
            }
            var quotaRows = cache.Get(KEY_QUOTA_ROWS) as IDictionary <string, List <TenantQuotaRow> >;

            if (quotaRows == null)
            {
                return(new TenantQuotaRow[0]);
            }

            lock (quotaRows)
            {
                var list = quotaRows.ContainsKey(query.Tenant.ToString()) ?
                           quotaRows[query.Tenant.ToString()] :
                           new List <TenantQuotaRow>();

                if (query != null && !string.IsNullOrEmpty(query.Path))
                {
                    return(list.Where(r => query.Path == r.Path));
                }
                return(list.ToList());
            }
        }