public TransactionTable UpdateItems(WebProperties webProps, DataTable items, IntegrationLog log) { var transactionTable = new TransactionTable(); try { SfService sfService = GetSfService(webProps); if (!sfService.IsSyncEnabled()) { throw new Exception("All synchronizations are currently disabled."); } List <string> ids; Dictionary <string, string> idMap = BuildIdMap(items, out ids); int index = 0; foreach (var result in sfService.UpsertItems((string)webProps.Properties["Object"], items)) { foreach (var pair in result) { SaveResult upsertResult = pair.Value; string sfId = upsertResult.id; string spid; try { spid = idMap[sfId]; } catch { spid = items.Rows[index]["SPID"].ToString(); } if (upsertResult.success) { transactionTable.AddRow(spid, sfId, pair.Key == UpsertKind.INSERT ? TransactionType.INSERT : TransactionType.UPDATE); } else { transactionTable.AddRow(spid, sfId, TransactionType.FAILED); if (upsertResult.errors.Any()) { Error[] errors = upsertResult.errors; for (int i = 0; i < errors.Count(); i++) { var error = errors[i]; string fields = string.Empty; if (error.fields != null) { try { fields = "Fields: " + string.Join(",", error.fields) + "."; } catch { } } log.LogMessage( string.Format( "Could not insert / update record with Salesforce ID: {0}, SharePoint ID: {1}. Status code: {2}. Message: {3} {4}", sfId, spid, error.statusCode, error.message, fields), IntegrationLogType.Warning); } } } } index++; } } catch (Exception e) { log.LogMessage(e.Message, IntegrationLogType.Error); } return(transactionTable); }
// Public Methods (9) public TransactionTable DeleteItems(WebProperties webProps, DataTable items, IntegrationLog log) { var transactionTable = new TransactionTable(); try { if (!bool.Parse((string)webProps.Properties["AllowDeleteInt"])) { throw new Exception("Salesforce delete is not allowed."); } SfService sfService = GetSfService(webProps); if (!sfService.IsSyncEnabled()) { throw new Exception("All synchronizations are currently disabled."); } List <string> ids; Dictionary <string, string> idMap = BuildIdMap(items, out ids); int index = 0; foreach (DeleteResult deleteResult in sfService.DeleteObjectItemsById(ids.ToArray())) { string sfId = deleteResult.id; string spid; try { spid = idMap[sfId]; } catch { spid = items.Rows[index]["SPID"].ToString(); } if (deleteResult.success) { transactionTable.AddRow(spid, sfId, TransactionType.DELETE); } else { transactionTable.AddRow(spid, sfId, TransactionType.FAILED); if (deleteResult.errors.Any()) { Error[] errors = deleteResult.errors; for (int i = 0; i < errors.Count(); i++) { log.LogMessage( string.Format( "Could not delete record with Salesforce ID: {0}, SharePoint ID: {1}. Status code: {2}. Message: {3}. Fields: {4}", sfId, spid, errors[i].statusCode, errors[i].message, string.Join(",", errors[i].fields)), IntegrationLogType.Warning); } } } index++; } } catch (Exception e) { log.LogMessage(e.Message, IntegrationLogType.Error); } return(transactionTable); }