internal static CloudBlockBlob CreateBlob(string containerName, string tableName, string ext) { IsdkStorageProviderInterface service = Helper.ServiceObject; CloudBlobDirectory ContainerDirectory = convertedData.GetDirectoryReference(containerName); switch (ext) { case ".xml": // Get dbf data and save to blob XDocument dataInDbfFormat = service.GetDataAsDaisy(containerName, tableName, null); CloudBlockBlob dbfBlob = ContainerDirectory.GetBlockBlobReference(tableName + ext); using (MemoryStream xmlStream = new MemoryStream()) { using (XmlWriter xmlWriter = XmlWriter.Create(xmlStream)) { dataInDbfFormat.Save(xmlWriter); xmlWriter.Close(); xmlStream.Position = 0; dbfBlob.UploadFromStream(xmlStream); } } return(dbfBlob); case ".csv": // Get csv data and save to blob string dataInCsvFormat = service.GetdDataAsCsv(containerName, tableName, null); CloudBlockBlob csvBlob = ContainerDirectory.GetBlockBlobReference(tableName + ext); using (MemoryStream csvStream = new MemoryStream()) { using (StreamWriter sw = new StreamWriter(csvStream)) { sw.Write(dataInCsvFormat); sw.Flush(); csvStream.Position = 0; csvBlob.UploadFromStream(csvStream); sw.Close(); } } return(csvBlob); case ".ANSI.csv": // Get csv data and save to blob for Excel string dataInANSICsvFormat = service.GetdDataAsCsv(containerName, tableName, null); //Encoding winLatinCodePage = Encoding.GetEncoding(1252); Encoding winLatinCodePage = Encoding.GetEncoding(Convert.ToInt32(OgdiConfiguration.GetValue("ANSICodePage"))); CloudBlockBlob ANSIcsvBlob = ContainerDirectory.GetBlockBlobReference(tableName + ext); MemoryStream ANSIcsvStream = new MemoryStream(Encoding.Convert(Encoding.Unicode, winLatinCodePage, Encoding.Unicode.GetBytes(dataInANSICsvFormat))); ANSIcsvStream.Position = 0; ANSIcsvBlob.UploadFromStream(ANSIcsvStream); return(ANSIcsvBlob); } return(null); }
public void ProcessMessage(string msg) { var messageParts = msg.Split(new char[] { ',' }); var containerName = messageParts[0]; var tableName = messageParts[1]; // Get service interface to access azure storage string serviceUri = RoleEnvironment.GetConfigurationSettingValue("serviceUri"); string pathDTD = RoleEnvironment.GetConfigurationSettingValue("pathDTD"); IsdkStorageProviderInterface service = IsdkStorageProviderInterface.GetServiceObject(serviceUri, pathDTD); // Get dbf data and save to blob XDocument dataInDbfFormat = service.GetDataAsDaisy(containerName, tableName, null); CloudBlockBlob dbfBlob = container.GetBlockBlobReference(tableName + ".xml"); using (MemoryStream xmlStream = new MemoryStream()) { using (XmlWriter xmlWriter = XmlWriter.Create(xmlStream)) { dataInDbfFormat.Save(xmlWriter); xmlWriter.Close(); xmlStream.Position = 0; dbfBlob.UploadFromStream(xmlStream); } } // Get csv data and save to blob string dataInCsvFormat = service.GetdDataAsCsv(containerName, tableName, null); CloudBlockBlob csvBlob = container.GetBlockBlobReference(tableName + ".csv"); using (MemoryStream csvStream = new MemoryStream()) { using (StreamWriter sw = new StreamWriter(csvStream)) { sw.Write(dataInCsvFormat); sw.Flush(); csvStream.Position = 0; csvBlob.UploadFromStream(csvStream); sw.Close(); } } }
internal static CloudBlockBlob CreateBlob(string containerName, string tableName, string ext) { IsdkStorageProviderInterface service = Helper.ServiceObject; switch (ext) { case ".xml": // Get dbf data and save to blob XDocument dataInDbfFormat = service.GetDataAsDaisy(containerName, tableName, null); CloudBlockBlob dbfBlob = convertedData.GetBlockBlobReference(tableName + ".xml"); using (MemoryStream xmlStream = new MemoryStream()) { using (XmlWriter xmlWriter = XmlWriter.Create(xmlStream)) { dataInDbfFormat.Save(xmlWriter); xmlWriter.Close(); xmlStream.Position = 0; dbfBlob.UploadFromStream(xmlStream); } } return(dbfBlob); case ".csv": // Get csv data and save to blob string dataInCsvFormat = service.GetdDataAsCsv(containerName, tableName, null); CloudBlockBlob csvBlob = convertedData.GetBlockBlobReference(tableName + ".csv"); using (MemoryStream csvStream = new MemoryStream()) { using (StreamWriter sw = new StreamWriter(csvStream)) { sw.Write(dataInCsvFormat); sw.Flush(); csvStream.Position = 0; csvBlob.UploadFromStream(csvStream); sw.Close(); } } return(csvBlob); } return(null); }