private static byte[] GetDatabaseBinaryAttribute(string id, DbBinaryConfig dbBinaryConfig) { IDMLIdentifiers identifiers = null; IDatabaseAccessProvider dbAccessProvider; if (string.IsNullOrEmpty(dbBinaryConfig.DBConnection)) { dbAccessProvider = DatabaseAccess.ForCurrentDatabase; identifiers = DatabaseAccess.ForCurrentDatabase.DatabaseServices.DMLService.Identifiers; } else { dbAccessProvider = DatabaseAccess.ForDBConnection(dbBinaryConfig.DBConnection); identifiers = DatabaseAccess.ForDBConnection(dbBinaryConfig.DBConnection).DatabaseServices.DMLService.Identifiers; } string selectSQL = "SELECT " + identifiers.EscapeIdentifier(dbBinaryConfig.Attribute.ToUpper()) + " FROM " + dbBinaryConfig.EntityGetter(null, BuiltInFunction.GetCurrentLocale()) + " WHERE " + identifiers.EscapeIdentifier(dbBinaryConfig.Id.ToUpper()) + " = "; if (dbBinaryConfig.IsAlphaId) { selectSQL += "'" + BuiltInFunction.EncodeSql(id) + "'"; } else { selectSQL += BuiltInFunction.EncodeSql(id); } return(GetBinaryFromDb(selectSQL, dbBinaryConfig.Attribute, dbAccessProvider)); }
protected override string EntityToTablename(string entity, int tenantId) { string entityLC = entity.ToLowerInvariant(); switch (entityLC) { case "recentitem": return(ENRecentItemEntity.LocalViewName(AppInfo.GetAppInfo().Tenant.Id, BuiltInFunction.GetCurrentLocale())); case "messagetype": return(ENMessageTypeEntity.LocalViewName(AppInfo.GetAppInfo().Tenant.Id, BuiltInFunction.GetCurrentLocale())); case "menuitem": return(ENMenuItemEntity.LocalViewName(AppInfo.GetAppInfo().Tenant.Id, BuiltInFunction.GetCurrentLocale())); case "contact": return(ENContactEntity.LocalViewName(AppInfo.GetAppInfo().Tenant.Id, BuiltInFunction.GetCurrentLocale())); case "application": return(ENApplicationEntity.LocalViewName(AppInfo.GetAppInfo().Tenant.Id, BuiltInFunction.GetCurrentLocale())); case "user": return(ENUserEntity.LocalViewName(AppInfo.GetAppInfo().Tenant.Id, BuiltInFunction.GetCurrentLocale())); } throw new DataBaseException("'" + entity + "' found in 'Expand Inline' parameter is an unknown Entity"); }
protected override string EntityToTablename(string entity, int tenantId) { string entityLC = entity.ToLowerInvariant(); switch (entityLC) { case "addresstype": return(ENAddressTypeEntity.LocalViewName(AppInfo.GetAppInfo().Tenant.Id, BuiltInFunction.GetCurrentLocale())); case "address": return(ENAddressEntity.LocalViewName(AppInfo.GetAppInfo().Tenant.Id, BuiltInFunction.GetCurrentLocale())); case "user": return(ENUserEntity.LocalViewName(AppInfo.GetAppInfo().Tenant.Id, BuiltInFunction.GetCurrentLocale())); case "country": return(ENCountryEntity.LocalViewName(AppInfo.GetAppInfo().Tenant.Id, BuiltInFunction.GetCurrentLocale())); } throw new DataBaseException("'" + entity + "' found in 'Expand Inline' parameter is an unknown Entity"); }
private static byte[] GetDatabaseBinaryAttribute(string id, DbBinaryConfig dbBinaryConfig) { IDMLIdentifiers identifiers = null; IDatabaseAccessProvider dbAccessProvider; if (string.IsNullOrEmpty(dbBinaryConfig.DBConnection)) { dbAccessProvider = DatabaseAccess.ForCurrentDatabase; identifiers = dbAccessProvider.DatabaseServices.DMLService.Identifiers; } else { dbAccessProvider = DatabaseAccess.ForDBConnection(dbBinaryConfig.DBConnection); identifiers = dbAccessProvider.DatabaseServices.DMLService.Identifiers; } using (Transaction trans = dbAccessProvider.GetReadOnlyTransaction()) { try { using (Command cmd = trans.CreateCommand( "SELECT " + identifiers.EscapeIdentifier(dbBinaryConfig.Attribute.ToUpper()) + " FROM " + dbBinaryConfig.EntityGetter(null, BuiltInFunction.GetCurrentLocale()) + " WHERE " + identifiers.EscapeIdentifier(dbBinaryConfig.Id.ToUpper()) + " = @ID")) { cmd.CreateParameter("@ID", (DbType)dbBinaryConfig.IdDbType, id); using (IDataReader reader = cmd.ExecuteReader()) { if ((reader.IsClosed) || (!reader.Read())) { return(null); } return(ReadBytes(reader, dbBinaryConfig.Attribute)); } } } catch (Exception) { return(null); } } }
/// <summary> /// Action: GetMenuItem /// </summary> public static void GetMenuItem(HeContext heContext, int inParamId, out RCMenuItemRecord outParamRecord) { outParamRecord = new RCMenuItemRecord(null); try { outParamRecord = ENMenuItemEntity.GetRecordById(inParamId); } catch { using (Transaction trans = DatabaseAccess.ForCurrentDatabase.GetRequestTransaction()) { string sql = "SELECT " + " [ID]" + ", [ORDER]" + ", [CAPTION]" + " FROM " + ENMenuItemEntity.LocalViewName(heContext.AppInfo.Tenant.Id, BuiltInFunction.GetCurrentLocale()) + " " + "WHERE [ID] = @inParamId"; Command sqlCmd = trans.CreateCommand(sql); sqlCmd.CreateParameter("@inParamId", DbType.Int32, inParamId); using (IDataReader reader = sqlCmd.ExecuteReader("Entity Action GetMenuItem", true, false, false)) { if (reader.Read()) { outParamRecord.ReadDB(reader); } else { throw new DataBaseException(ENMenuItemEntity.LocalViewName(heContext.AppInfo.Tenant.Id, BuiltInFunction.GetCurrentLocale()) + " with key " + inParamId + " was not found"); } } } } }
private void Page_Load(object sender, System.EventArgs e) { HttpContext current = HttpContext.Current; HttpRequest request = current.Request; HttpResponse response = current.Response; int cacheTime = 0; if ((!string.Equals(HttpContext.Current.Request.HttpMethod, "GET", StringComparison.CurrentCultureIgnoreCase)) && (!string.Equals(HttpContext.Current.Request.HttpMethod, "HEAD", StringComparison.CurrentCultureIgnoreCase))) { response.Clear(); response.Status = "405 Method Not Allowed"; response.StatusCode = 405; response.AppendHeader("Allow", "GET, HEAD"); response.StatusDescription = "Method Not Allowed"; response.Write("Method Not Allowed"); response.End(); return; } string parameters = request.PathInfo; if (parameters.Substring(1).IndexOf("/") == parameters.Substring(1).LastIndexOf("/")) { parameters = "/" + RuntimePlatformUtils.Images.DecryptImageDetails(parameters.Substring(1, parameters.LastIndexOf("/") - 1).Replace("-", "+").Replace("_", "/")) + parameters.Substring(parameters.LastIndexOf("/")); } else { parameters = ""; } Match m = ParametersRegex.Match(parameters); if (!m.Success) { response.Clear(); response.Status = "400 Bad Request"; response.StatusCode = 400; response.StatusDescription = "Bad Request"; response.Write("Bad Request"); response.End(); return; } _entity = m.Groups["Entity"].Value.ToLower(); _attribute = m.Groups["Attribute"].Value.ToLower(); _id = m.Groups["Id"].Value; _filename = m.Groups["Filename"].Value.ToLower(); object objt = htDbImgConfig[_entity + "/" + _attribute]; if (objt == null) { NotFound(response); return; } DbImgConfig dbimgconfig; dbimgconfig = (DbImgConfig)objt; byte[] buffer = new byte[0]; string md5Hash = ""; string reqcachecontrol = ""; string reqpragma = ""; if (Request.Headers["Cache-Control"] != null) { reqcachecontrol = Request.Headers["Cache-Control"].ToString().Trim(); } if (Request.Headers["Pragma"] != null) { reqpragma = Request.Headers["Pragma"].ToString().Trim(); } bool refreshItem = ((reqcachecontrol == "no-cache") || (reqpragma == "no-cache") || (reqcachecontrol == "max-age=0")); object tmpHash = RuntimeCache.Instance.Get(new CacheKey("DbImage/" + _entity + "/" + _attribute + "/" + _id + "/" + _filename)); if ((!refreshItem) && (tmpHash != null)) { DbImgCacheFile cacheinfo = (DbImgCacheFile)tmpHash; md5Hash = cacheinfo.md5Hash; buffer = cacheinfo.buffer; } else { OutSystems.HubEdition.Extensibility.Data.DMLService.IDMLIdentifiers identifiers = null; IDatabaseAccessProvider dbAccessProvider; if (string.IsNullOrEmpty(dbimgconfig.DBConnection)) { dbAccessProvider = DatabaseAccess.ForCurrentDatabase; identifiers = DatabaseAccess.ForCurrentDatabase.DatabaseServices.DMLService.Identifiers; } else { dbAccessProvider = DatabaseAccess.ForDBConnection(dbimgconfig.DBConnection); identifiers = DatabaseAccess.ForDBConnection(dbimgconfig.DBConnection).DatabaseServices.DMLService.Identifiers; } using (Transaction trans = dbAccessProvider.GetReadOnlyTransaction()) { try { using (Command cmd = trans.CreateCommand( "SELECT " + identifiers.EscapeIdentifier(dbimgconfig.Attribute.ToUpper()) + " FROM " + dbimgconfig.EntityGetter(null, BuiltInFunction.GetCurrentLocale()) + " WHERE " + identifiers.EscapeIdentifier(dbimgconfig.Id.ToUpper()) + " = @ID")) { cmd.CreateParameter("@ID", (DbType)dbimgconfig.IdDbType, _id); using (IDataReader reader = cmd.ExecuteReader()) { if ((reader.IsClosed) || (!reader.Read())) { NotFound(response); return; } long size = reader.GetBytes(0, 0, null, 0, 0); buffer = new byte[size]; reader.GetBytes(0, 0, buffer, 0, buffer.Length); } } } catch (Exception) { NotFound(response); return; } } md5Hash = HashHelper.Hash(buffer); if (dbimgconfig.CacheTime != 0) { DateTime absoluteexpire = DateTime.UtcNow; switch (dbimgconfig.CacheTime) { case 1: absoluteexpire = absoluteexpire.AddHours(1); break; case 2: absoluteexpire = absoluteexpire.AddDays(1); break; case 3: absoluteexpire = absoluteexpire.AddDays(7); break; } RuntimeCache.Instance.Add(new CacheKey("DbImage/" + _entity + "/" + _attribute + "/" + _id + "/" + _filename), new DbImgCacheFile(md5Hash, buffer), null, absoluteexpire, CacheUtils.NoSliding, OutSystems.RuntimeCommon.Caching.CacheItemPriority.Removable); } } bool isValidImage; cacheTime = dbimgconfig.CacheTime; response.Clear(); response.ContentType = RuntimePlatformUtils.GetMIMEType(buffer, out isValidImage); if (!isValidImage && RuntimePlatformSettings.Security.EnforceValidTypesOnBinaryEndpoints.GetValue()) { InternalError(response); return; } response.Status = "200 OK"; response.StatusCode = 200; response.StatusDescription = "OK"; response.AppendHeader("Content-MD5", md5Hash); response.AppendHeader("Last-Modified", "Sat, 01 Jan 2000 00:00:00 GMT"); response.AppendHeader("Cache-Control", _cachecontrolstr[cacheTime]); response.AppendHeader("ETag", "\"" + md5Hash + "\""); response.AppendHeader("Accept-Ranges", "none"); switch (cacheTime) { case 0: { response.Expires = -1; break; } case 1: { response.Expires = 60; // 1 hour break; } case 2: { response.Expires = 1440; // 1 day - 60*24 break; } case 3: { response.Expires = 10080; // 1 week - 60*24*7 break; } } if (string.Equals(HttpContext.Current.Request.HttpMethod, "GET", StringComparison.CurrentCultureIgnoreCase)) { response.BinaryWrite(buffer); } response.End(); }