public static ICrossModuleTransferUtility GetCrossModuleTransferUtility(string srcConfigPath, int srcTenant, string srcModule, string destConfigPath, int destTenant, string destModule) { var srcConfigSection = GetSection(srcConfigPath); var descConfigSection = GetSection(destConfigPath); var srcModuleConfig = srcConfigSection.Modules.GetModuleElement(srcModule); var destModuleConfig = descConfigSection.Modules.GetModuleElement(destModule); var srcHandlerConfig = srcConfigSection.Handlers.GetHandler(srcModuleConfig.Type); var destHandlerConfig = descConfigSection.Handlers.GetHandler(destModuleConfig.Type); if (!string.Equals(srcModuleConfig.Type, destModuleConfig.Type, StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException("Can't instance transfer utility for modules with different storage types"); } if (string.Equals(srcModuleConfig.Type, "disc", StringComparison.OrdinalIgnoreCase)) { return(new DiscCrossModuleTransferUtility(TennantPath.CreatePath(srcTenant.ToString()), srcModuleConfig, srcHandlerConfig.GetProperties(), TennantPath.CreatePath(destTenant.ToString()), destModuleConfig, destHandlerConfig.GetProperties())); } if (string.Equals(srcModuleConfig.Type, "s3", StringComparison.OrdinalIgnoreCase)) { return(new S3CrossModuleTransferUtility(TennantPath.CreatePath(srcTenant.ToString()), srcModuleConfig, srcHandlerConfig.GetProperties(), TennantPath.CreatePath(destTenant.ToString()), destModuleConfig, destHandlerConfig.GetProperties())); } return(null); }
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 = TennantPath.CreatePath(tenant); var store = DataStoreCache.Get(tenant, module); if (store == null) { var section = StorageFactoryConfig.Section; if (section == null) { throw new InvalidOperationException("config section not found"); } var settings = SettingsManager.LoadForTenant <StorageSettings>(tenantId); store = GetStoreAndCache(tenant, module, StorageSettingsHelper.DataStoreConsumer(settings), controller); } return(store); }
internal static void ClearCache() { var tenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId.ToString(); var path = TennantPath.CreatePath(tenantId); foreach (var module in GetModuleList("", true)) { Cache.Publish(DataStoreCacheItem.Create(path, module), CacheNotifyAction.Remove); } }
public IDataStore GetStorageFromConsumer(string configpath, string tenant, string module, DataStoreConsumer consumer) { if (tenant == null) { tenant = DefaultTenantName; } //Make tennant path tenant = TennantPath.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 TennantQuotaController(tenantId, TenantManager))); }
public static IDataStore GetStorage(string configpath, string tenant, string module, IQuotaController controller) { if (tenant == null) { tenant = DefaultTenantName; } //Make tennant path tenant = TennantPath.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"); } store = GetStoreAndCache(tenant, module, section, controller); } return(store); }
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); } 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 (!TennantPath.TryGetTenant(_tenant, out currentTenantId)) { currentTenantId = 0; } var auth = EmailValidationKeyProvider.GetEmailKey(currentTenantId, path.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); }