public void ExportNonExistingQueryTest() { AvrAccessExportResult result = AccessExporter.ExportX86(1, "en", GetTempFilePath()); Assert.IsNotNull(result); Assert.IsFalse(result.IsOk); }
public void ExportFailsX64Test() { AvrAccessExportResult result = AccessExporter.ExportX64(HumanQueryId, "en", GetTempFilePath()); Assert.IsNotNull(result); Console.WriteLine(result.ExceptionString); Assert.IsFalse(result.IsOk); }
public void ExportSuccessRuX86Test() { AvrAccessExportResult result = AccessExporter.ExportX86(HumanQueryId, "ru", GetTempFilePath()); Assert.IsNotNull(result); Console.WriteLine(result.ExceptionString); Assert.IsTrue(result.IsOk); }
public FileResult ExportQueryRoutines(long queryId, int exportType) { if (exportType != 0 && exportType != 1 && exportType != 2) { throw new ArgumentException(EidssMessages.Get("ExportTypeError"), "exportType"); } // export to Access. It's impossible without creating temp file if (exportType == 2) { const int effortCount = 10; int effortNum = 1; WindowsLogHelper.WriteToEventLogWindows("Try to export data to MS Access", EventLogEntryType.Information); //var path = Path.Combine(Path.GetTempPath(), DateTime.Now.Ticks.ToString()); string path = Path.Combine(Server.MapPath("~/App_Data/ExportQueryFiles"), DateTime.Now.Ticks.ToString()); string filename = Path.ChangeExtension(path, "mdb"); WindowsLogHelper.WriteToEventLogWindows(String.Format("Full path = {0}", filename), EventLogEntryType.Information); AccessExporter.ExportAnyCPU(queryId, ModelUserContext.CurrentLanguage, filename); //Thread.Sleep(6000); var fileBytes = new byte[0]; while (effortNum <= effortCount) { try { effortNum++; fileBytes = System.IO.File.ReadAllBytes(filename); break; } catch (Exception) { Thread.Sleep(1000); } } if (fileBytes.Length == 0) { throw new ArgumentException(EidssMessages.Get("Cantreadfile")); } //пробуем удалить файл effortNum = 1; while (effortNum <= effortCount) { try { effortNum++; System.IO.File.Delete(filename); break; } // ReSharper disable EmptyGeneralCatchClause catch (Exception) // ReSharper restore EmptyGeneralCatchClause { } } return(File(fileBytes, MediaTypeNames.Application.Octet, Path.GetFileName(filename))); } // Export to Excel ExportType type = exportType == 0 ? ExportType.Xls : ExportType.Xlsx; CachedQueryResult queryResult = ServiceClientHelper.ExecQuery(queryId, false, string.Empty, true); if (!string.IsNullOrEmpty(queryResult.ErrorMessage)) { //todo:[mike] return queryResult.ErrorMessage to user } List <byte[]> fileBytesList = NpoiExcelWrapper.QueryLineListToExcel(queryResult.QueryTable, type); if (fileBytesList.Count == 0) { throw new AvrDataException(string.Format("Could not export query '{0}' to Excel", queryId)); } // todo: [ELeonov] Should return multifile result if fileBytesList contains more than one element (see task 9516) return(File(fileBytesList[0], MediaTypeNames.Application.Octet, "QueryLineList." + type)); }