public static bool CallStorageService(string path, byte[] fileData, string fileName) { var fileEntity = new fileEntity { path = path.Replace("/", "|").Replace(@"\", "|"), fileData = fileData, fileName = fileName }; var storage = new StorageServiceClient("StorageServiceImplPort"); return(storage.AddFileObj(fileEntity)); }
public void UploadFile(string path, string name, byte[] data) { if (data == null) { return; } var storage = new StorageServiceClient(); var f = new fileEntity { path = path, fileData = data, fileName = name }; try { storage.AddFileObj(f); } catch (Exception ex) { throw ex; } }
public CmaFile GetFileById(long id, string para) { string path = ""; string fileName = ""; string fileType = ""; if (para == "VAV") //for home page download { path = "|VAV|Home"; using (var db = new CMAEntities()) { fileType = db.HOMEFILEs.Where(f => f.ID == id).Select(f => f.FILETYPE).ToList().FirstOrDefault(); fileName = id + "." + fileType; } } else if (para == "IPP") //for macro-ecnomic 100 charts and user uploaded file { using (var db = new IPPEntities()) { var subPath = (from f in db.FILEINFOs join t in db.TOPICs on f.TOPICID equals t.ID join m in db.MODULEINFOs on t.MODULEID equals m.ID where f.ID == id select new { m.NAMEEN, t.ID, f.FILETYPE }).ToList().FirstOrDefault(); path = "|IPP|" + subPath.NAMEEN + "|" + subPath.ID; fileName = id + "." + subPath.FILETYPE; fileType = subPath.FILETYPE; } } else if (para.Contains("WMP"))//cmafiledb { using (var db = new Genius_HistEntities()) { if (para == "WMP_PROSP") { var accRoute = db.BANK_FIN_PRD_PROSP.Where(f => f.INNER_CODE == id).ToList().Select(f => f.ACCE_ROUTE).FirstOrDefault().Replace("\\", "|"); path = "|WMP|RROSP|" + accRoute.Substring(0, accRoute.LastIndexOf("|")); fileName = id.ToString() + accRoute.Substring(accRoute.LastIndexOf(".")); fileType = accRoute.Substring(accRoute.LastIndexOf(".") + 1); } else if (para == "WMP_REP") { var accRoute = db.FIN_PRD_RPT.Where(f => f.RPT_ID == id).ToList().Select(f => f.ACCE_ROUTE).FirstOrDefault().Replace("\\", "|"); path = "|WMP|PRD_RPT|" + accRoute.Substring(0, accRoute.LastIndexOf("|")); fileName = id.ToString() + accRoute.Substring(accRoute.LastIndexOf(".")); fileType = accRoute.Substring(accRoute.LastIndexOf(".") + 1); } else if (para == "WMP_DISC") { var accRoute = db.DISC_ACCE_CFP.Where(f => f.SEQ == id).ToList().Select(f => f.ACCE_ROUTE).FirstOrDefault().Replace("\\", "|"); var accOrder = db.DISC_ACCE_CFP.Where(f => f.SEQ == id).ToList().Select(f => f.ACCE_ORDER).FirstOrDefault().ToString(); var disc_id = db.DISC_ACCE_CFP.Where(f => f.SEQ == id).ToList().Select(f => f.DISC_ID).FirstOrDefault().ToString(); path = "|WMP|DISC_CFP|" + accRoute.Substring(0, accRoute.LastIndexOf("|")); fileName = disc_id + "_" + accOrder + accRoute.Substring(accRoute.LastIndexOf(".")); fileType = accRoute.Substring(accRoute.LastIndexOf(".") + 1); } } } else if (para == "ZCX") { using (var db = new ZCXEntities()) { var accRoute = db.RATE_REP.Where(f => f.RATE_ID == id).ToList().Select(f => f.RATE_FILE_PATH).FirstOrDefault().Replace("/", "|"); path = "|ZCX|RATE" + accRoute.Substring(0, accRoute.LastIndexOf("|")); fileName = accRoute.Substring(accRoute.LastIndexOf("|") + 1); fileType = accRoute.Substring(accRoute.LastIndexOf(".") + 1); } } else if (para == "RR") { using (var db = new ResearchReportEntities()) { path = "|RR|" + db.ALLFILESINFOes.Where(f => f.FILEID == id).ToList().Select(f => f.BIZCODE + "|" + f.INSTITUTIONINFOCODE + "|" + f.FILETYPECODE).FirstOrDefault(); fileName = db.ALLFILESINFOes.Where(f => f.FILEID == id).ToList().Select(f => f.FILEID.ToString() + "." + f.EXTENSION).FirstOrDefault(); } } else if (para.ToUpper() == "LOGO") { using (var db = new ResearchReportEntities()) { var institution = db.INSTITUTIONINFOes.FirstOrDefault(i => i.ID_C == (decimal)id); if (institution != null) { path = "|RR|Logo"; fileName = string.Format("{0}.{1}", institution.CODE, institution.EXTENSION); } } } var storage = new StorageServiceClient(); var obj = new fileEntity(); try { obj = storage.RetriveFileObj(path, fileName); } catch (Exception ex) { throw ex; } if (obj.fileData == null || obj.fileData.Length == 0) { return(null); } return(new CmaFile { Id = id, Content = obj.fileData, FileType = fileType }); }
/*Sync file from storage service of .28 to storage service of production*/ private string SyncFile(System.Data.DataTable sourceData, TableMapping tableMapping, ref int successFileNo, ref int failFileNo) { var imeClient = new Luna.DataSync.Core.IME_SS.StorageServiceClient(); var prodClient = new Luna.DataSync.Core.PROD_SS.StorageServiceClient(); var tableName = tableMapping.Source; var msg = new StringBuilder(); msg.AppendFormat("File sync detail for table:{0} : \n<ol>", tableMapping.Destination); foreach (System.Data.DataRow dtRow in sourceData.Rows) { string path = ""; string fileName = ""; string fileId = ""; var keyColumns = tableMapping.GetKeyColumnNames().ToList(); fileId = keyColumns.Count == 1 ? dtRow[keyColumns.FirstOrDefault()].ToString() : keyColumns.Aggregate((i, j) => dtRow[i] + "_" + dtRow[j]); //ignore if there is no physical path //when tablename = INSTITUTIONINFO, phisicalpath = |Logo var realPath = tableMapping.Source == "INSTITUTIONINFO" ? "|Logo" : dtRow[tableMapping.PathColumn].ToString(); if (string.IsNullOrEmpty(realPath)) { continue; } realPath = realPath.Replace(@"\", "/"); var ext = ""; if (tableName.Equals("FILEDETAIL") || tableName.Equals("INSTITUTIONINFO")) { ext = "." + dtRow[tableMapping.ExtColumn]; path = tableMapping.PathRoot + (realPath.IndexOf("|") != 0 ? String.Format("|{0}", realPath) : realPath); } else { ext = Path.GetExtension(realPath); path = tableMapping.PathRoot + realPath.Substring(0, realPath.LastIndexOf("/")).Replace("/", "|"); } fileName = fileId + ext; fileEntity obj = null; obj = imeClient.RetriveFileObj(path, fileName); if (obj.fileData == null) { //var strException = string.Format("Can not retrive file(ID:{0},path{1},name:{2}) \n from {3} from source table: {4} \n ", fileId, path, fileName, imeClient.Endpoint.Address, tableMapping.Source); //throw new Exception(strException); msg.AppendFormat("<li>{0}:{1}{2} <span style=\"color:red;\">failed</span>.<br/>(Cannot retrive file from {3})</li>", fileId, path, fileName, imeClient.Endpoint.Address); failFileNo++; continue; } bool success; //try //{ // Luna.DataSync.Core.PROD_SS.fileEntity newObj = new Luna.DataSync.Core.PROD_SS.fileEntity { fileData = obj.fileData, fileName = fileName, path = path }; // success = prodClient.AddFileObj(newObj); //} //catch (Exception ex) //{ // throw new Exception(string.Format("Get exception when call storage service (write file)\n " + // "fileId: {0} in destination table: {1} \n {2} \n", fileId, tableMapping.Source, ex)); //} var newObj = new Luna.DataSync.Core.PROD_SS.fileEntity { fileData = obj.fileData, fileName = fileName, path = path }; success = prodClient.AddFileObj(newObj); if (!success) { //throw new Exception(string.Format("Can not save file(ID:{0},path{1},name:{2}) \n to {3} in destination table: {4}", fileId, path, fileName, imeClient.Endpoint.Address, tableMapping.Source)); msg.AppendFormat("<li>{0}:{1}{2} <span style=\"color:red;\">failed</span>.<br/>(Cannot save file to {3})</li>", fileId, path, fileName, prodClient.Endpoint.Address); failFileNo++; continue; } msg.AppendFormat("<li>{0}:{1}{2} sync <span style=\"color:green;\">succeed</span>.</li>", fileId, path, fileName); successFileNo++; //try //{ // if (!success) // { // if (tableName.Equals("FILEDETAIL")) // dtRow["ISVALID"] = 0; // else // dtRow["ISSYNCED"] = 0; // syncInfo += string.Format("{0}|{1}, fail \n", path, fileName); // } // sourceData.AcceptChanges(); //} //catch (Exception ex) //{ // throw new Exception(string.Format("Get exception when update file sync status\n " + // "fileId: {0} \n destination table: {1} \n {2} \n", fileId, tableMapping.Destination, ex)); //} } msg.Append("</ol>"); return(msg.ToString()); }