public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn) { string fileName = absoluteUri.Segments[absoluteUri.Segments.Length - 1]; string key = String.Format("{0}#{1}", m_mapAssembly, fileName); if (Includes.ContainsKey(key)) { return(new MemoryStream(Includes[key])); } else { object content = null; using (SqlConnection connection = new SqlConnection(BtsConnectionHelper.MgmtDBConnectionString)) { string sqlText = String.Format(@"SELECT top 1 res.[cabContent] FROM [BizTalkMgmtDb].[dbo].[adpl_sat] as ass join [BizTalkMgmtDb].[dbo].[adpl_sat] as res on ass.luid = '{0}' and ass.[applicationId] = res.[applicationId] where res.luid like concat(ass.[applicationId] ,'%:{1}')", m_mapAssembly, fileName); using (SqlCommand command = new SqlCommand(sqlText, connection)) { connection.Open(); content = command.ExecuteScalar(); } } if (content != null) { SqlBinary cabContent = new SqlBinary((byte[])content); MemoryStream stream = new MemoryStream(cabContent.Value); byte[] CabBytes = null; using (CabFile file = new CabFile(stream)) { // file.EntryExtract += CabEntryExtract; file.ExtractEntries(); CabBytes = file.Entries[0].Data; Includes.TryAdd(key, CabBytes); } //default utf-8, so the files must be in utf-8 return(new MemoryStream(CabBytes)); } } throw new ArgumentException(String.Format("Resource file {0} could not be found!", fileName)); }
public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn) { string fileName = absoluteUri.Segments[absoluteUri.Segments.Length - 1]; string key = String.Format("{0}#{1}#{2}", m_portDirection, m_portName, fileName); if (Includes.ContainsKey(key)) { return(new MemoryStream(Includes[key])); } else { object content = null; using (SqlConnection connection = new SqlConnection(BtsConnectionHelper.MgmtDBConnectionString)) { using (SqlCommand command = new SqlCommand(String.Format("SELECT cabContent FROM [adpl_sat] join [bts_{0}port] on [applicationId] = [nApplicationID] and [nvcName] = '{1}' where luid = concat(applicationId,':','{2}')", m_portDirection, m_portName, fileName), connection)) { connection.Open(); content = command.ExecuteScalar(); } } if (content != null) { SqlBinary cabContent = new SqlBinary((byte[])content); MemoryStream stream = new MemoryStream(cabContent.Value); byte[] CabBytes = null; using (CabFile file = new CabFile(stream)) { // file.EntryExtract += CabEntryExtract; file.ExtractEntries(); CabBytes = file.Entries[0].Data; Includes.Add(key, CabBytes); } //default utf-8, so the files must be in utf-8 return(new MemoryStream(CabBytes)); } } throw new ArgumentException(String.Format("Resource file {0} could not be found in the same application as the {1} port {2}", fileName, m_portDirection, m_portName)); }