private void ExportComplete(IAsyncResult result) { try { ExportResults results = _exportCaller.EndInvoke(result); OnExportCompleted(new ExportCompletedEventArgs(results, null)); } catch (Exception e) { OnExportCompleted(new ExportCompletedEventArgs(null, e)); } }
public ExportCompletedEventArgs(ExportResults results, Exception error) : base(error, false, null) { this.ExportResults = results; }
public ExportResults Export() { ReportInformation(String.Format("Starting export to file \"{0}\".", this.OutputPath)); ReportInformation(String.Format("Connecting to CRM server at {0}", this._factory.ServerUrl)); _crmService = _factory.GetCrmService(); _metadataService = _factory.GetMetadataService(); ExportResults ret = new ExportResults(); List <String> entitiesNotFound; if (VerifyExportShouldWork(out entitiesNotFound)) { try { List <EntityResult> entityResults = new List <EntityResult>(); List <BusinessEntity> allRecords = new List <BusinessEntity>(); int count = 0; int total = EntitiesForExport.Count(); foreach (String entityName in EntitiesForExport) { count++; int percentage = (int)Math.Round(100.0 * count / total); ReportInformation(String.Format("Exporting {0}...", entityName)); OnProgressChanged(new ProgressChangedEventArgs(percentage, null)); List <BusinessEntity> entityRecords = RetrieveAllRecords(entityName); foreach (DynamicEntity entity in entityRecords) { ReportDetail(String.Format( "Exported {0} with id {1}.", entity.Name, entity.Properties.OfType <KeyProperty>().First().Value.Value)); } entityResults.Add(new EntityResult(entityName, entityRecords.Count)); allRecords.AddRange(entityRecords); } XmlSerializer serializer = new XmlSerializer(typeof(List <BusinessEntity>)); XmlTextWriter writer = new XmlTextWriter(OutputPath, Encoding.ASCII); serializer.Serialize(writer, allRecords); writer.Close(); ret.EntityResults = entityResults; ret.Success = true; } catch (SoapException ex) { ret.Success = false; ret.ErrorMessage = String.Format(ex.Detail.InnerText); ReportError(ex.ToString()); } catch (Exception ex) { ret.Success = false; ret.ErrorMessage = ex.Message; ReportError(ex.ToString()); } } else { ret.Success = false; ret.ErrorMessage = String.Format("Verification of Export Failed because entity(ies) {0} do not exist in the environment", String.Join(",", entitiesNotFound.ToArray())); } return(ret); }