public string DeleteTableContent() { DataSync ds = new DataSync(); int overrideDelete = Int32.Parse(Request["override"] as string); string msg = null; if (ds.formStatusUploaded() || overrideDelete == 1) { string paramTableName = Request["tableName"] as string; Debug.WriteLine("* * * DataSync DeleteTableContent tableName; " + paramTableName); // IFormsSql formsSql = new FormsSql(); // *** this needs to be uncommented for Production int deletedRecordCount = formsSql.DeleteTableContent(paramTableName); //int deletedRecordCount = 23; msg = deletedRecordCount.ToString() + " records deleted from table " + paramTableName; } else { msg = "Cannot delete records because non-uploaded form results present."; } return(msg); }
/// <summary> /// Processes the long running action. /// </summary> /// <param name="id">The id.</param> public string ProcessDataSync(string id) { int rspCnt = 0; int resultTableCnt = formsSql.GetNumberOfResultsTables(); lock (syncRoot) { ProcessStatus[id] = 1; } try { // Delete all result table first for (int DeleteOrderId = resultTableCnt - 1; DeleteOrderId >= 0; DeleteOrderId--) { rspCnt = formsSql.DeleteTableContent(formsSql.GetResultsTableName(DeleteOrderId)); // ProcessStatus[id] = 2, 3, 4 lock (syncRoot) { ProcessStatus[id] += 1; } } for (int fileId = 0; fileId < resultTableCnt; fileId++) { // 2. Execute the URL to run the method on the remote server: // Export/GetResponsesCsv?fileId=1 // Construct HTTP request to get the file HttpWebRequest httpRequest = (HttpWebRequest) WebRequest.Create(sisOnlineURL + "Export/GetResponseCsv?fileId=" + fileId.ToString()); httpRequest.Method = WebRequestMethods.Http.Get; DataTable csvData = new DataTable(); // Get back the HTTP response for web server using (HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse()) { Stream httpResponseStream = httpResponse.GetResponseStream(); // ProcessStatus[id] = 5, 7, 9 lock (syncRoot) { ProcessStatus[id] += 1; } using (var reader = new CsvReader(httpResponseStream)) { // the CSV file has a header record, so we read that first reader.ReadHeaderRecord(); csvData.Fill(reader); Debug.WriteLine("Table contains {0} rows.", csvData.Rows.Count); } rspCnt = csvData.Rows.Count; csvData = RemoveNullString(csvData); } // 3. Read the FileStreamResult // - Read through the records /* using (SqlBulkCopy bulkCopy = new SqlBulkCopy(formsSql.GetConnectionString(), SqlBulkCopyOptions.KeepNulls | SqlBulkCopyOptions.KeepIdentity)) * { * bulkCopy.DestinationTableName = formsSql.GetResultsTableName(fileId); * bulkCopy.ColumnMappings.Clear(); * foreach (var column in csvData.Columns) * bulkCopy.ColumnMappings.Add(column.ToString(), column.ToString()); * bulkCopy.WriteToServer(csvData); * } */ csvData.TableName = formsSql.GetResultsTableName(fileId); DbConnection connection = UasAdo.GetUasAdoConnection(); FillDatabaseTable(csvData, connection); // ProcessStatus[id] = 6, 8, 10 lock (syncRoot) { ProcessStatus[id] += 1; } } } catch (Exception ex) { Debug.WriteLine("* * * DataSync exception: " + ex.Message); } return(id); }