private void TransportReportViewer_Load(object sender, EventArgs e) { this.DragEnter += Form1_DragEnter; this.DragDrop += Form1_DragDrop; if (reportFileName == "") { return; } report = tpm.ReadTransportReport(reportFileName); labelTransportationProfileName.Text = report.TransportProfileName; labelTransportCompleted.Text = (report.TransportCompleted) ? "Yes" : "No"; labelTransportStartedAt.Text = report.TransportStartedAt; labelTransportFinishedAt.Text = report.TransportFinishedAt; labelTransportedIn.Text = report.TransportedIn; labelTotalExportedRecords.Text = report.TotalExportedRecords.ToString(); labelTotalImportedRecords.Text = report.TotalImportedRecords.ToString(); labelTotalImportFailures.Text = report.TotalImportFailures.ToString(); SortableBindingList <NtoNTransportReportLine> sortedReportLines = new SortableBindingList <NtoNTransportReportLine>(report.ReportLines); dataGridView1.DataSource = sortedReportLines; if (report.TotalImportFailures > 0 && File.Exists(reportFailuresFileName)) { buttonFailuresReport.Visible = true; } else { buttonFailuresReport.Visible = false; } }
private void Form1_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] filePaths = (string[])(e.Data.GetData(DataFormats.FileDrop)); foreach (string fileLoc in filePaths) { // Code to read the contents of the text file if (File.Exists(fileLoc)) { this.reportFileName = fileLoc; this.reportFailuresFileName = reportFileName.Replace("TransportReport", "ImportFailuresReport"); try { report = tpm.ReadTransportReport(reportFileName); } catch (Exception ex) { MessageBox.Show("Invalid Report File: \n" + ex.Message); } labelTransportationProfileName.Text = report.TransportProfileName; labelTransportCompleted.Text = (report.TransportCompleted) ? "Yes" : "No"; labelTransportStartedAt.Text = report.TransportStartedAt; labelTransportFinishedAt.Text = report.TransportFinishedAt; labelTransportedIn.Text = report.TransportedIn; labelTotalExportedRecords.Text = report.TotalExportedRecords.ToString(); labelTotalImportedRecords.Text = report.TotalImportedRecords.ToString(); labelTotalImportFailures.Text = report.TotalImportFailures.ToString(); SortableBindingList <NtoNTransportReportLine> sortedReportLines = new SortableBindingList <NtoNTransportReportLine>(report.ReportLines); dataGridView1.DataSource = sortedReportLines; //Retrieve Failures Report FileName if (report.TotalImportFailures > 0 && File.Exists(reportFailuresFileName)) { buttonFailuresReport.Visible = true; } else { buttonFailuresReport.Visible = false; } } } } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string[] filePath = openFileDialog1.FileNames; foreach (string fileLoc in filePath) { // Code to read the contents of the text file if (File.Exists(fileLoc)) { this.reportFileName = fileLoc; this.reportFailuresFileName = reportFileName.Replace("TransportReport", "ImportFailuresReport"); try { report = tpm.ReadTransportReport(reportFileName); } catch (Exception ex) { MessageBox.Show("Invalid Report File: \n" + ex.Message); } labelTransportationProfileName.Text = report.TransportProfileName; labelTransportCompleted.Text = (report.TransportCompleted) ? "Yes" : "No"; labelTransportStartedAt.Text = report.TransportStartedAt; labelTransportFinishedAt.Text = report.TransportFinishedAt; labelTransportedIn.Text = report.TransportedIn; labelTotalExportedRecords.Text = report.TotalExportedRecords.ToString(); labelTotalImportedRecords.Text = report.TotalImportedRecords.ToString(); labelTotalImportFailures.Text = report.TotalImportFailures.ToString(); SortableBindingList <NtoNTransportReportLine> sortedReportLines = new SortableBindingList <NtoNTransportReportLine>(report.ReportLines); dataGridView1.DataSource = sortedReportLines; //Retrieve Failures Report FileName if (report.TotalImportFailures > 0 && File.Exists(reportFailuresFileName)) { buttonFailuresReport.Visible = true; } else { buttonFailuresReport.Visible = false; } } } } }
/// <summary> /// Exports the specified profile. /// </summary> /// <param name="profile">The profile.</param> /// <param name="transportReportFileName">Name of the transport report file.</param> private void Export(NtoNAssociationsTransportProfile profile, string transportReportFileName) { NtoNTransportReport report = null; try { report = new NtoNTransportReport(transportReportFileName); //Get Transport Report if (File.Exists(transportReportFileName)) { report = ReadTransportReport(transportReportFileName); } //Clean Data folder string dataExportFolder = Folder + "\\" + profile.ProfileName + "\\Data"; if (Directory.Exists(dataExportFolder)) { Directory.Delete(dataExportFolder, true); } Directory.CreateDirectory(dataExportFolder); MSCRMConnection connection = profile.getSourceConneciton(); NtoNRelationshipsStructure es = ReadEnvStructure(profile.SourceConnectionName); _serviceProxy = cm.connect(connection); IOrganizationService service = (IOrganizationService)_serviceProxy; List<NtoNTransportReportLine> TransportReport = new List<NtoNTransportReportLine>(); profile.TotalExportedRecords = 0; //Mesure export time DateTime exportStartDT = DateTime.Now; LogManager.WriteLog("Start exporting data from " + connection.ConnectionName); int recordCount = 0; if (es != null) { foreach (SelectedNtoNRelationship ee in profile.SelectedNtoNRelationships) { LogManager.WriteLog("Exporting data for relationship " + ee.RelationshipSchemaName); DateTime entityExportStartDT = DateTime.Now; string fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"; fetchXml += "<entity name='" + ee.IntersectEntityName + "'>"; //Get Entity structure NtoNRelationship strE = new NtoNRelationship(); foreach (NtoNRelationship envE in es.NtoNRelationships) { if (envE.IntersectEntityName == ee.IntersectEntityName) { strE = envE; fetchXml += "<attribute name='" + strE.Entity1IntersectAttribute + "' />"; fetchXml += "<attribute name='" + strE.Entity2IntersectAttribute + "' />"; if (ee.IntersectEntityName == "listmember" || ee.IntersectEntityName == "campaignitem") fetchXml += "<attribute name='entitytype' />"; else if (ee.IntersectEntityName == "campaignactivityitem") fetchXml += "<attribute name='itemobjecttypecode' />"; break; } } //Add Query filter int objectTypeCode = 0; if (ee.Entity2LogicalName == "account") objectTypeCode = 1; else if (ee.Entity2LogicalName == "campaign") objectTypeCode = 4400; else if (ee.Entity2LogicalName == "contact") objectTypeCode = 2; else if (ee.Entity2LogicalName == "lead") objectTypeCode = 4; else if (ee.Entity2LogicalName == "list") objectTypeCode = 4300; else if (ee.Entity2LogicalName == "product") objectTypeCode = 1024; else if (ee.Entity2LogicalName == "salesliterature") objectTypeCode = 1038; if (ee.IntersectEntityName == "campaignitem") fetchXml += "<filter type='and'><condition attribute='entitytype' operator='eq' value='" + objectTypeCode + "' /></filter>"; else if (ee.IntersectEntityName == "campaignactivityitem") fetchXml += "<filter type='and'><condition attribute='itemobjecttypecode' operator='eq' value='" + objectTypeCode + "' /></filter>"; fetchXml += "</entity></fetch>"; int recordCountPerEntity = ExportEntity(profile, fetchXml, ee.RelationshipSchemaName); recordCount += recordCountPerEntity; DateTime entityExportEndDT = DateTime.Now; TimeSpan ts = entityExportEndDT - entityExportStartDT; NtoNTransportReportLine transportReportLine = new NtoNTransportReportLine(); transportReportLine.RelationshipSchemaName = ee.RelationshipSchemaName; transportReportLine.ExportedRecords = recordCountPerEntity; report.TotalExportedRecords += recordCountPerEntity; transportReportLine.ExportedIn = ts.ToString().Substring(0, 10); transportReportLine.ExportStartedAt = entityExportStartDT.ToString(); transportReportLine.ExportFinishedAt = entityExportEndDT.ToString(); report.ReportLines.Add(transportReportLine); WriteTransportReport(report, transportReportFileName); } } TimeSpan exportTimeSpan = DateTime.Now - exportStartDT; LogManager.WriteLog("Export finished for " + profile.SourceConnectionName + ". Exported " + recordCount + " records in " + exportTimeSpan.ToString().Substring(0, 10)); } catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex) { LogManager.WriteLog("Error:" + ex.Detail.Message + "\n" + ex.Detail.TraceText); } catch (Exception ex) { if (ex.InnerException != null) { LogManager.WriteLog("Error:" + ex.Message + "\n" + ex.InnerException.Message); } else { LogManager.WriteLog("Error:" + ex.Message); } } }
/// <summary> /// Imports the specified profile. /// </summary> /// <param name="profile">The profile.</param> /// <param name="transportReportFileName">Name of the transport report file.</param> private void Import(NtoNAssociationsTransportProfile profile, string transportReportFileName) { int totalTreatedRecords = 0; int totalImportFailures = 0; int totalImportSuccess = 0; int ReconnectionRetryCount = 5; try { NtoNTransportReport report = new NtoNTransportReport(transportReportFileName); //Get Transport Report if (File.Exists(transportReportFileName)) { report = ReadTransportReport(transportReportFileName); } MSCRMConnection connection = profile.getTargetConneciton(); ; _serviceProxy = cm.connect(connection); IOrganizationService service = (IOrganizationService)_serviceProxy; LogManager.WriteLog("Start importing data in " + connection.ConnectionName); //Mesure import time DateTime importStartDT = DateTime.Now; //es = ReadEnvStructure(profile.SourceConnectionName); foreach (SelectedNtoNRelationship ee in profile.SelectedNtoNRelationships) { //Check if there are any records to import if (ee.ExportedRecords == 0) { continue; } //Mesure import time DateTime entityImportStartDT = DateTime.Now; string entityFolderPath = Folder + "\\" + profile.ProfileName + "\\Data\\" + ee.RelationshipSchemaName; string[] filePaths = Directory.GetFiles(entityFolderPath, "*.xml"); LogManager.WriteLog("Importing " + ee.RelationshipSchemaName + " records."); int treatedRecordsForEntity = 0; int importedRecordsForEntity = 0; int importFailuresForEntity = 0; foreach (string filePath in filePaths) { List<Type> knownTypes = new List<Type>(); knownTypes.Add(typeof(Entity)); XmlDictionaryReaderQuotas XRQ = new XmlDictionaryReaderQuotas(); XRQ.MaxStringContentLength = int.MaxValue; using(FileStream fs = new FileStream(filePath, FileMode.Open)) using (XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(fs, XRQ)) { DataContractSerializer ser = new DataContractSerializer(typeof(EntityCollection), knownTypes); EntityCollection fromDisk = (EntityCollection)ser.ReadObject(reader, true); foreach (Entity en in fromDisk.Entities) { EntityReference relatedEntity1 = new EntityReference(); EntityReference relatedEntity2 = new EntityReference(); try { Guid relatedEntity1Id = getRelatedEntityGuid(en[ee.Entity1IntersectAttribute]); Guid relatedEntity2Id = getRelatedEntityGuid(en[ee.Entity2IntersectAttribute]); relatedEntity1 = new EntityReference { LogicalName = ee.Entity1LogicalName, Id = relatedEntity1Id }; relatedEntity2 = new EntityReference { LogicalName = ee.Entity2LogicalName, Id = relatedEntity2Id }; if (!AlreadyAssociated(_serviceProxy, ee, relatedEntity1Id, relatedEntity2Id)) { if (ee.IntersectEntityName == "listmember") { Guid entity_id = Guid.Empty; Guid list_id = Guid.Empty; if (ee.Entity1LogicalName == "list") { entity_id = relatedEntity2Id; list_id = relatedEntity1Id; } else { entity_id = relatedEntity1Id; list_id = relatedEntity2Id; } AddMemberListRequest request = new AddMemberListRequest(); request.EntityId = entity_id; request.ListId = list_id; AddMemberListResponse response = (AddMemberListResponse)service.Execute(request); } else if (ee.IntersectEntityName == "campaignitem") { Guid entity_id = Guid.Empty; Guid list_id = Guid.Empty; string EntityName = ""; if (ee.Entity1LogicalName == "campaign") { entity_id = relatedEntity2Id; list_id = relatedEntity1Id; EntityName = (string)en["entitytype"]; relatedEntity2.LogicalName = EntityName; } else { entity_id = relatedEntity1Id; list_id = relatedEntity2Id; EntityName = (string)en["entitytype"]; relatedEntity1.LogicalName = EntityName; } AddItemCampaignRequest req = new AddItemCampaignRequest(); req.CampaignId = relatedEntity1Id; req.EntityName = EntityName; req.EntityId = entity_id; AddItemCampaignResponse resp = (AddItemCampaignResponse)service.Execute(req); } else if (ee.IntersectEntityName == "campaignactivityitem") { Guid entity_id = Guid.Empty; Guid list_id = Guid.Empty; string EntityName = ""; if (ee.Entity1LogicalName == "campaignactivity") { entity_id = relatedEntity2Id; list_id = relatedEntity1Id; EntityName = (string)en["itemobjecttypecode"]; relatedEntity2.LogicalName = EntityName; } else { entity_id = relatedEntity1Id; list_id = relatedEntity2Id; EntityName = (string)en["itemobjecttypecode"]; relatedEntity1.LogicalName = EntityName; } AddItemCampaignActivityRequest req = new AddItemCampaignActivityRequest(); req.CampaignActivityId = relatedEntity1Id; req.EntityName = EntityName; req.ItemId = entity_id; AddItemCampaignActivityResponse resp = (AddItemCampaignActivityResponse)service.Execute(req); } else { EntityReferenceCollection relatedEntities = new EntityReferenceCollection(); relatedEntities.Add(relatedEntity2); Relationship relationship = new Relationship(ee.RelationshipSchemaName); relationship.PrimaryEntityRole = EntityRole.Referencing; service.Associate(relatedEntity1.LogicalName, relatedEntity1.Id, relationship, relatedEntities); } } importedRecordsForEntity++; totalImportSuccess++; } catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex) { totalImportFailures++; importFailuresForEntity++; NtoNRelationshipsImportFailure failure = new NtoNRelationshipsImportFailure { CreatedOn = DateTime.Now.ToString(), NtoNRelationshipName = ee.RelationshipSchemaName, Reason = ex.Detail.Message, UrlEntity1 = profile.getSourceConneciton().ServerAddress + "main.aspx?pagetype=entityrecord&etn=" + relatedEntity1.LogicalName + "&id=" + relatedEntity1.Id.ToString(), UrlEntity2 = profile.getSourceConneciton().ServerAddress + "main.aspx?pagetype=entityrecord&etn=" + relatedEntity2.LogicalName + "&id=" + relatedEntity2.Id.ToString() }; report.TotalImportFailures += 1; //Insert the Failure line in the Failures Report WriteNewImportFailureLine(failure, importFailuresReportFileName); } catch (Exception ex) { //Check if the authentification session is expired if (ex.InnerException != null && ex.InnerException.Message.StartsWith("ID3242")) { LogManager.WriteLog("Error:The CRM authentication session expired. Reconnection attempt n° " + ReconnectionRetryCount); ReconnectionRetryCount--; //On 5 failed reconnections exit if (ReconnectionRetryCount == 0) throw; _serviceProxy = cm.connect(connection); service = (IOrganizationService)_serviceProxy; LogManager.WriteLog("Error:The CRM authentication session expired."); totalImportFailures++; importFailuresForEntity++; NtoNRelationshipsImportFailure failure = new NtoNRelationshipsImportFailure { CreatedOn = DateTime.Now.ToString(), NtoNRelationshipName = ee.RelationshipSchemaName, Reason = ex.InnerException.Message, UrlEntity1 = profile.getSourceConneciton().ServerAddress + "main.aspx?pagetype=entityrecord&etn=" + relatedEntity1.LogicalName + "&id=" + relatedEntity1.Id.ToString(), UrlEntity2 = profile.getSourceConneciton().ServerAddress + "main.aspx?pagetype=entityrecord&etn=" + relatedEntity2.LogicalName + "&id=" + relatedEntity2.Id.ToString() }; report.TotalImportFailures += 1; //Insert the Failure line in the Failures Report WriteNewImportFailureLine(failure, importFailuresReportFileName); } else { throw; } } totalTreatedRecords++; treatedRecordsForEntity++; updateTransportReport(report, ee, importedRecordsForEntity, importFailuresForEntity, entityImportStartDT); } } } LogManager.WriteLog("Treated " + treatedRecordsForEntity + " " + ee.RelationshipSchemaName + " records with " + importedRecordsForEntity + " successfully imported records and " + importFailuresForEntity + " failures."); } TimeSpan importTimeSpan = DateTime.Now - importStartDT; LogManager.WriteLog("Import finished for " + connection.ConnectionName + ". Treated " + totalTreatedRecords + " records in " + importTimeSpan.ToString().Substring(0, 10) + ". Successfuly imported " + totalImportSuccess + " records and " + totalImportFailures + " failures."); WriteTransportReport(report, transportReportFileName); } catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex) { LogManager.WriteLog("Error:" + ex.Detail.Message + "\n" + ex.Detail.TraceText); } catch (Exception ex) { if (ex.InnerException != null) LogManager.WriteLog("Error:" + ex.Message + "\n" + ex.InnerException.Message); else { LogManager.WriteLog("Error:" + ex.Message); } } }
/// <summary> /// Updates the transport report. /// </summary> /// <param name="report">The report.</param> /// <param name="ee">The Selected N to N Relationship.</param> /// <param name="importedRecordsForEntity">The imported records for entity.</param> /// <param name="importFailuresForEntity">The import failures for entity.</param> /// <param name="entityImportStartDT">The entity import start dt.</param> public void updateTransportReport(NtoNTransportReport report, SelectedNtoNRelationship ee, int importedRecordsForEntity, int importFailuresForEntity, DateTime entityImportStartDT) { bool addNewLine = true; foreach (NtoNTransportReportLine reportLine in report.ReportLines) { if (reportLine.RelationshipSchemaName == ee.RelationshipSchemaName) { reportLine.ImportedRecords = importedRecordsForEntity; report.TotalImportedRecords += importedRecordsForEntity; DateTime entityImportEndDT = DateTime.Now; TimeSpan ts = entityImportEndDT - entityImportStartDT; reportLine.ImportStartedAt = entityImportStartDT.ToString(); reportLine.ImportFinishedAt = entityImportEndDT.ToString(); reportLine.ImportedIn = ts.ToString().Substring(0, 10); reportLine.ImportFailures = importFailuresForEntity; addNewLine = false; break; } } if (addNewLine) { NtoNTransportReportLine currentLine = new NtoNTransportReportLine(); currentLine.RelationshipSchemaName = ee.RelationshipSchemaName; currentLine.ImportedRecords = importedRecordsForEntity; report.TotalImportedRecords += importedRecordsForEntity; DateTime entityImportEndDT = DateTime.Now; TimeSpan ts = entityImportEndDT - entityImportStartDT; currentLine.ImportStartedAt = entityImportStartDT.ToString(); currentLine.ImportFinishedAt = entityImportEndDT.ToString(); currentLine.ImportedIn = ts.ToString().Substring(0, 10); currentLine.ImportFailures = importFailuresForEntity; report.ReportLines.Add(currentLine); } WriteTransportReport(report, ReportFileName); }
/// <summary> /// Writes the transport report. /// </summary> /// <param name="tr">The N to N Transport Report.</param> /// <param name="transportReportFileName">Name of the transport report file.</param> public void WriteTransportReport(NtoNTransportReport tr, string transportReportFileName) { FileStream writer = new FileStream(transportReportFileName, FileMode.Create); DataContractSerializer ser = new DataContractSerializer(typeof(NtoNTransportReport)); ser.WriteObject(writer, tr); writer.Close(); }
/// <summary> /// Runs the profile. /// </summary> /// <param name="profile">The profile.</param> /// <returns>The Execution Report File Name</returns> public string RunProfile(NtoNAssociationsTransportProfile profile) { LogManager.WriteLog("Running N*N Transportation Profile: " + profile.ProfileName); //Check if there are selected Relationships to transport if (profile.SelectedNtoNRelationships == null || profile.SelectedNtoNRelationships.Count == 0) { LogManager.WriteLog("No Relationships selected for transport. Select the Relationships and then run the profile"); return ""; } DateTime now = DateTime.Now; ReportFileName = Folder + "\\" + profile.ProfileName + "\\ExecutionReports\\TransportReport" + now.Year + "-" + now.Month + "-" + now.Day + "-" + now.Hour + "-" + now.Minute + "-" + now.Second + ".xml"; importFailuresReportFileName = Folder + "\\" + profile.ProfileName + "\\ExecutionReports\\ImportFailuresReport" + now.Year + "-" + now.Month + "-" + now.Day + "-" + now.Hour + "-" + now.Minute + "-" + now.Second + ".xml"; //Initialize Execution Reports folder string executionReportsFolder = Folder + "\\" + profile.ProfileName + "\\ExecutionReports"; if (!Directory.Exists(executionReportsFolder)) { Directory.CreateDirectory(executionReportsFolder); } //Create Transport Report NtoNTransportReport tr = new NtoNTransportReport(profile.ProfileName); WriteTransportReport(tr, ReportFileName); //Check for the Operation to execute if (profile.Operation == 0) { //Export data Export(profile, ReportFileName); } else if (profile.Operation == 1) { //Import Data Import(profile, ReportFileName); } else if (profile.Operation == 2) { //Transport data => Export + Import Export(profile, ReportFileName); Import(profile, ReportFileName); } NtoNTransportReport report = ReadTransportReport(ReportFileName); report.TransportFinishedAt = DateTime.Now.ToString(); report.TransportCompleted = true; TimeSpan TransportTimeSpan = DateTime.Now - Convert.ToDateTime(report.TransportStartedAt); report.TransportedIn = TransportTimeSpan.ToString().Substring(0, 10); WriteTransportReport(report, ReportFileName); return ReportFileName; }
private void TransportReportViewer_Load(object sender, EventArgs e) { this.DragEnter += Form1_DragEnter; this.DragDrop += Form1_DragDrop; if (reportFileName == "") return; report = tpm.ReadTransportReport(reportFileName); labelTransportationProfileName.Text = report.TransportProfileName; labelTransportCompleted.Text = (report.TransportCompleted) ? "Yes" : "No"; labelTransportStartedAt.Text = report.TransportStartedAt; labelTransportFinishedAt.Text = report.TransportFinishedAt; labelTransportedIn.Text = report.TransportedIn; labelTotalExportedRecords.Text = report.TotalExportedRecords.ToString(); labelTotalImportedRecords.Text = report.TotalImportedRecords.ToString(); labelTotalImportFailures.Text = report.TotalImportFailures.ToString(); SortableBindingList<NtoNTransportReportLine> sortedReportLines = new SortableBindingList<NtoNTransportReportLine>(report.ReportLines); dataGridView1.DataSource = sortedReportLines; if (report.TotalImportFailures > 0 && File.Exists(reportFailuresFileName)) { buttonFailuresReport.Visible = true; } else { buttonFailuresReport.Visible = false; } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string[] filePath = openFileDialog1.FileNames; foreach (string fileLoc in filePath) { // Code to read the contents of the text file if (File.Exists(fileLoc)) { this.reportFileName = fileLoc; this.reportFailuresFileName = reportFileName.Replace("TransportReport", "ImportFailuresReport"); try { report = tpm.ReadTransportReport(reportFileName); } catch (Exception ex) { MessageBox.Show("Invalid Report File: \n" + ex.Message); } labelTransportationProfileName.Text = report.TransportProfileName; labelTransportCompleted.Text = (report.TransportCompleted) ? "Yes" : "No"; labelTransportStartedAt.Text = report.TransportStartedAt; labelTransportFinishedAt.Text = report.TransportFinishedAt; labelTransportedIn.Text = report.TransportedIn; labelTotalExportedRecords.Text = report.TotalExportedRecords.ToString(); labelTotalImportedRecords.Text = report.TotalImportedRecords.ToString(); labelTotalImportFailures.Text = report.TotalImportFailures.ToString(); SortableBindingList<NtoNTransportReportLine> sortedReportLines = new SortableBindingList<NtoNTransportReportLine>(report.ReportLines); dataGridView1.DataSource = sortedReportLines; //Retrieve Failures Report FileName if (report.TotalImportFailures > 0 && File.Exists(reportFailuresFileName)) { buttonFailuresReport.Visible = true; } else { buttonFailuresReport.Visible = false; } } } } }
private void Form1_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] filePaths = (string[])(e.Data.GetData(DataFormats.FileDrop)); foreach (string fileLoc in filePaths) { // Code to read the contents of the text file if (File.Exists(fileLoc)) { this.reportFileName = fileLoc; this.reportFailuresFileName = reportFileName.Replace("TransportReport", "ImportFailuresReport"); try { report = tpm.ReadTransportReport(reportFileName); } catch (Exception ex) { MessageBox.Show("Invalid Report File: \n" + ex.Message); } labelTransportationProfileName.Text = report.TransportProfileName; labelTransportCompleted.Text = (report.TransportCompleted) ? "Yes" : "No"; labelTransportStartedAt.Text = report.TransportStartedAt; labelTransportFinishedAt.Text = report.TransportFinishedAt; labelTransportedIn.Text = report.TransportedIn; labelTotalExportedRecords.Text = report.TotalExportedRecords.ToString(); labelTotalImportedRecords.Text = report.TotalImportedRecords.ToString(); labelTotalImportFailures.Text = report.TotalImportFailures.ToString(); SortableBindingList<NtoNTransportReportLine> sortedReportLines = new SortableBindingList<NtoNTransportReportLine>(report.ReportLines); dataGridView1.DataSource = sortedReportLines; //Retrieve Failures Report FileName if (report.TotalImportFailures > 0 && File.Exists(reportFailuresFileName)) { buttonFailuresReport.Visible = true; } else { buttonFailuresReport.Visible = false; } } } } }
private void runProfileToolStripMenuItem_Click(object sender, EventArgs e) { if (!SaveProfile()) return; LogManager.WriteLog("Running Transportation Profile: " + currentProfile.ProfileName); //Check if there are selected entities to transport if (currentProfile.SelectedNtoNRelationships == null || currentProfile.SelectedNtoNRelationships.Count == 0) { MessageBox.Show("No entities selected for transport. Select the entities and then run the profile"); LogManager.WriteLog("No entities selected for transport. Select the entities and then run the profile"); return; } DateTime now = DateTime.Now; man.ReportFileName = man.Folder + "\\" + currentProfile.ProfileName + "\\ExecutionReports\\TransportReport" + now.Year + "-" + now.Month + "-" + now.Day + "-" + now.Hour + "-" + now.Minute + "-" + now.Second + ".xml"; man.importFailuresReportFileName = man.Folder + "\\" + currentProfile.ProfileName + "\\ExecutionReports\\ImportFailuresReport" + now.Year + "-" + now.Month + "-" + now.Day + "-" + now.Hour + "-" + now.Minute + "-" + now.Second + ".xml"; //Initialize Execution Reports folder string executionReportsFolder = man.Folder + "\\" + currentProfile.ProfileName + "\\ExecutionReports"; if (!Directory.Exists(executionReportsFolder)) { Directory.CreateDirectory(executionReportsFolder); } //Create Transport Report NtoNTransportReport tr = new NtoNTransportReport(currentProfile.ProfileName); man.WriteTransportReport(tr, man.ReportFileName); transportReportToolStripMenuItem.Visible = false; labelImportSuccess.Text = ""; labelImportFailures.Text = ""; label2.Visible = false; label3.Visible = false; label4.Visible = false; if (currentProfile.Operation == 0 || currentProfile.Operation == 2) { if (!transportRunning) { buttonStopTransport.Visible = true; runProfileToolStripMenuItem.Enabled = false; pgbState.Visible = true; SetFields(false); toolStripStatusLabel.Text = "Initializing Data Export"; if (bwExport.IsBusy != true) bwExport.RunWorkerAsync(); } else { MessageBox.Show("Transport already running!"); } } else if (currentProfile.Operation == 1) { if (!transportRunning) { buttonStopTransport.Visible = true; runProfileToolStripMenuItem.Enabled = false; pgbState.Visible = true; SetFields(false); toolStripStatusLabel.Text = "Initializing Data Import"; label2.Visible = true; label3.Visible = true; label4.Visible = true; if (bwImport.IsBusy != true) bwImport.RunWorkerAsync(); } else { MessageBox.Show("Transport already running!"); } } }