示例#1
0
        public static IDataStore GetStorage(string configpath, string tenant, string module, IQuotaController controller)
        {
            var tenantId = -2;

            if (string.IsNullOrEmpty(tenant))
            {
                tenant = DefaultTenantName;
            }
            else
            {
                tenantId = Convert.ToInt32(tenant);
            }

            //Make tenant path
            tenant = TenantPath.CreatePath(tenant);

            var store = DataStoreCache.Get(tenant, module);

            if (store == null)
            {
                var section = GetSection(configpath);
                if (section == null)
                {
                    throw new InvalidOperationException("config section not found");
                }

                var settings = StorageSettings.LoadForTenant(tenantId);

                store = GetStoreAndCache(tenant, module, section, settings.DataStoreConsumer, controller);
            }
            return(store);
        }
示例#2
0
        public IDataStore GetStorage(string configpath, string tenant, string module, IQuotaController controller)
        {
            var tenantId = -2;

            if (string.IsNullOrEmpty(tenant))
            {
                tenant = DefaultTenantName;
            }
            else
            {
                tenantId = Convert.ToInt32(tenant);
            }

            //Make tennant path
            tenant = TenantPath.CreatePath(tenant);

            var section = StorageFactoryConfig.Section;

            if (section == null)
            {
                throw new InvalidOperationException("config section not found");
            }

            var settings = SettingsManager.LoadForTenant <StorageSettings>(tenantId);

            //TODO:GetStoreAndCache
            return(GetDataStore(tenant, module, StorageSettingsHelper.DataStoreConsumer(settings), controller));
        }
示例#3
0
        internal static void ClearCache()
        {
            var tenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId.ToString();
            var path     = TenantPath.CreatePath(tenantId);

            foreach (var module in GetModuleList("", true))
            {
                Cache.Publish(DataStoreCacheItem.Create(path, module), CacheNotifyAction.Remove);
            }
        }
示例#4
0
        public IDataStore GetStorageFromConsumer(string configpath, string tenant, string module, DataStoreConsumer consumer)
        {
            if (tenant == null)
            {
                tenant = DefaultTenantName;
            }

            //Make tennant path
            tenant = TenantPath.CreatePath(tenant);

            var section = StorageFactoryConfig.Section;

            if (section == null)
            {
                throw new InvalidOperationException("config section not found");
            }

            int.TryParse(tenant, out var tenantId);
            return(GetDataStore(tenant, module, consumer, new TenantQuotaController(tenantId, TenantManager)));
        }
示例#5
0
        public static IDataStore GetStorage(string configpath, string tenant, string module, IQuotaController controller)
        {
            var tenantId = -2;

            if (string.IsNullOrEmpty(tenant))
            {
                tenant = DefaultTenantName;
            }
            else
            {
                tenantId = Convert.ToInt32(tenant);
            }

            //Make tenant path
            tenant = TenantPath.CreatePath(tenant);

            var store = DataStoreCache.Get(tenant, module);

            if (store == null)
            {
                var sectionKey = "StorageConfigurationSection" + (configpath ?? "").Replace("\\", "").Replace("/", "");
                var section    = AscCache.Memory.Get <StorageConfigurationSection>(sectionKey);

                if (section == null)
                {
                    section = GetSection(configpath);
                    AscCache.Memory.Insert(sectionKey, section, DateTime.MaxValue);
                }

                if (section == null)
                {
                    throw new InvalidOperationException("config section not found");
                }

                var settings = StorageSettings.LoadForTenant(tenantId);

                store = GetStoreAndCache(tenant, module, section, settings.DataStoreConsumer, controller);
            }
            return(store);
        }
示例#6
0
        public Uri GetPreSignedUri(string domain, string path, TimeSpan expire, IEnumerable <string> headers)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            if (string.IsNullOrEmpty(_tenant) && IsSupportInternalUri)
            {
                return(GetInternalUri(domain, path, expire, headers));
            }

            var headerAttr = string.Empty;

            if (headers != null)
            {
                headerAttr = string.Join("&", headers.Select(HttpUtility.UrlEncode));
            }

            if (expire == TimeSpan.Zero || expire == TimeSpan.MinValue || expire == TimeSpan.MaxValue)
            {
                expire = GetExpire(domain);
            }

            var query = string.Empty;

            if (expire != TimeSpan.Zero && expire != TimeSpan.MinValue && expire != TimeSpan.MaxValue)
            {
                var expireString = expire.TotalMinutes.ToString(CultureInfo.InvariantCulture);

                int currentTenantId;
                var currentTenant = CoreContext.TenantManager.GetCurrentTenant(false);
                if (currentTenant != null)
                {
                    currentTenantId = currentTenant.TenantId;
                }
                else if (!TenantPath.TryGetTenant(_tenant, out currentTenantId))
                {
                    currentTenantId = 0;
                }

                var auth = EmailValidationKeyProvider.GetEmailKey(currentTenantId, path.Replace('/', Path.DirectorySeparatorChar).Replace('\\', Path.DirectorySeparatorChar) + "." + headerAttr + "." + expireString);
                query = string.Format("{0}{1}={2}&{3}={4}",
                                      path.Contains("?") ? "&" : "?",
                                      Constants.QUERY_EXPIRE,
                                      expireString,
                                      Constants.QUERY_AUTH,
                                      auth);
            }

            if (!string.IsNullOrEmpty(headerAttr))
            {
                query += string.Format("{0}{1}={2}",
                                       query.Contains("?") ? "&" : "?",
                                       Constants.QUERY_HEADER,
                                       HttpUtility.UrlEncode(headerAttr));
            }

            var tenant = _tenant.Trim('/');
            var vpath  = PathUtils.ResolveVirtualPath(_modulename, domain);

            vpath = PathUtils.ResolveVirtualPath(vpath, false);
            vpath = string.Format(vpath, tenant);
            var virtualPath = new Uri(vpath + "/", UriKind.RelativeOrAbsolute);

            var uri = virtualPath.IsAbsoluteUri ?
                      new MonoUri(virtualPath, virtualPath.LocalPath.TrimEnd('/') + EnsureLeadingSlash(path.Replace('\\', '/')) + query) :
                      new MonoUri(virtualPath.ToString().TrimEnd('/') + EnsureLeadingSlash(path.Replace('\\', '/')) + query, UriKind.Relative);

            return(uri);
        }