public bool TestConnection(WebProperties webProps, IntegrationLog log, out string message) { message = string.Empty; try { O365Service o365Service = GetO365Service(webProps); if (!o365Service.EnsureEPMLiveAppInstalled()) { log.LogMessage( "Please make sure that you have installed the EPM Live app in your Office 365 environment.", IntegrationLogType.Error); return(false); } return(true); } catch (Exception e) { message = e.Message; log.LogMessage(message, IntegrationLogType.Error); return(false); } }
public TransactionTable UpdateItems(WebProperties WebProps, DataTable Items, IntegrationLog Log) { TransactionTable trans = new TransactionTable(); if (BuildWSDL(WebProps, Log)) { MethodInfo Method = null; foreach (MethodInfo t in methodInfo) { if (t.Name == WebProps.Properties["WSDLFunction"].ToString()) { Method = t; param = t.GetParameters(); break; } } if (Method != null) { foreach (DataRow drItem in Items.Rows) { try { Hashtable hshProps = GetItemHash(WebProps, drItem); object[] param1 = new object[param.Length]; int i = 0; foreach (var p in param) { param1[i++] = Convert.ChangeType(hshProps[p.Name], p.ParameterType); } Object obj = Activator.CreateInstance(service); Object response = Method.Invoke(obj, param1); try { if (WebProps.Properties["LogInfo"].ToString() == "True") { Log.LogMessage("WSDL Response: " + response.ToString(), IntegrationLogType.Information); } } catch { } } catch (Exception ex) { Log.LogMessage("Error sending item (" + drItem["SPID"].ToString() + "): " + ex.Message, IntegrationLogType.Error); } } } else { Log.LogMessage("Could not find method", IntegrationLogType.Error); } } return(trans); }
// 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("Office 365 delete is not allowed."); } O365Service o365Service = GetO365Service(webProps); List <string> ids; Dictionary <string, string> idMap = BuildIdMap(items, out ids); int index = 0; foreach ( O365Result result in o365Service.DeleteListItemsById(ids.ToArray(), (string)webProps.Properties["List"])) { string o365Id = result.ItemId.ToString(); string spid; try { spid = idMap[o365Id]; } catch { spid = items.Rows[index]["SPID"].ToString(); } if (result.Success) { transactionTable.AddRow(spid, o365Id, TransactionType.DELETE); } else { transactionTable.AddRow(spid, o365Id, TransactionType.FAILED); log.LogMessage(string.Format( "Could not delete record with Office 365 ID: {0}, SharePoint ID: {1}. Message: {2}", o365Id, spid, result.Error), IntegrationLogType.Warning); } index++; } } catch (Exception e) { log.LogMessage(e.Message, IntegrationLogType.Error); } return(transactionTable); }
public TransactionTable UpdateItems(WebProperties webProps, DataTable items, IntegrationLog log) { var transactionTable = new TransactionTable(); try { O365Service o365Service = GetO365Service(webProps); List <string> ids; Dictionary <string, string> idMap = BuildIdMap(items, out ids); int index = 0; foreach ( O365Result result in o365Service.UpsertItems((string)webProps.Properties["List"], webProps.IntegrationId, items)) { string o365Id = result.ItemId.ToString(); string spId; try { spId = idMap[o365Id]; } catch { spId = items.Rows[index]["SPID"].ToString(); } if (result.Success) { transactionTable.AddRow(spId, o365Id, result.TransactionType); } else { transactionTable.AddRow(spId, o365Id, TransactionType.FAILED); log.LogMessage(string.Format( "Could not insert / update record with Office 365 ID: {0}, SharePoint ID: {1}. Message: {2}", o365Id, spId, result.Error), IntegrationLogType.Warning); } index++; } } catch (Exception e) { log.LogMessage(e.Message, IntegrationLogType.Error); } return(transactionTable); }
public Dictionary <string, string> GetDropDownValues(WebProperties webProps, IntegrationLog log, string property, string parentPropertyValue) { var dictionary = new Dictionary <string, string>(); try { SfService sfService = GetSfService(webProps); if (property.Equals("Object")) { dictionary = sfService.GetIntegratableObjects(); } else if (property.Equals("UserMapType")) { return new Dictionary <string, string> { { "Email", "Email" } } } ; throw new Exception("Invalid property: " + property); } catch (Exception e) { log.LogMessage(e.Message, IntegrationLogType.Error); } return(dictionary); }
private bool BuildWSDL(WebProperties WebProps, IntegrationLog Log) { try { Uri uri = new Uri(WebProps.Properties["WSDL"].ToString()); //byte[] byteArray = Encoding.ASCII.GetBytes(WebProps.Properties["WSDL"].ToString()); //MemoryStream stream = new MemoryStream(byteArray); WebRequest webRequest = WebRequest.Create(uri); System.IO.Stream stream = webRequest.GetResponse().GetResponseStream(); ServiceDescription sd = ServiceDescription.Read(stream); string sdName = sd.Services[0].Name; // Initialize a service description servImport ServiceDescriptionImporter servImport = new ServiceDescriptionImporter(); servImport.AddServiceDescription(sd, String.Empty, String.Empty); servImport.ProtocolName = "Soap"; servImport.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties; CodeNamespace nameSpace = new CodeNamespace(); CodeCompileUnit codeCompileUnit = new CodeCompileUnit(); codeCompileUnit.Namespaces.Add(nameSpace); ServiceDescriptionImportWarnings warnings = servImport.Import(nameSpace, codeCompileUnit); if (warnings == 0) { using (var stringWriter = new StringWriter(CultureInfo.CurrentCulture)) { var prov = new CSharpCodeProvider(); prov.GenerateCodeFromNamespace(nameSpace, stringWriter, new CodeGeneratorOptions()); var assemblyReferences = new string[2] { "System.Web.Services.dll", "System.Xml.dll" }; var param = new CompilerParameters(assemblyReferences) { GenerateExecutable = false, GenerateInMemory = true, TreatWarningsAsErrors = false, WarningLevel = 4, }; var results = new CompilerResults(new TempFileCollection()); results = prov.CompileAssemblyFromDom(param, codeCompileUnit); var assembly = results.CompiledAssembly; service = assembly.GetType(sdName); methodInfo = service.GetMethods(); } } return(true); } catch (Exception ex) { Log.LogMessage(ex.Message, IntegrationLogType.Error); } return(false); }
public TransactionTable UpdateItems(WebProperties WebProps, DataTable Items, IntegrationLog Log) { CheckArgumentForNull(WebProps, nameof(WebProps)); CheckArgumentForNull(Items, nameof(Items)); CheckArgumentForNull(Log, nameof(Log)); const string queryTemplate = "SELECT * FROM {0} WHERE {1}=@id"; var tableName = WebProps.Properties[PropKeyTable]; var idColumn = WebProps.Properties[PropKeyIdColumn]; var trans = new TransactionTable(); using (var connection = GetConnection(WebProps.Properties)) { connection.Open(); foreach (DataRow drItem in Items.Rows) { var currentId = drItem[ColNameId].ToString(); var spId = drItem[ColNameSpid].ToString(); try { if (currentId == string.Empty) { trans.AddRow(spId, InsertRow(WebProps, drItem, Log, connection), TransactionType.INSERT); } else { var dataSet = new DataSet(); using (var command = new SqlCommand(string.Format(queryTemplate, tableName, idColumn), connection)) { command.Parameters.AddWithValue("@id", currentId); using (var dataAdapter = new SqlDataAdapter(command)) { dataAdapter.Fill(dataSet); } } if (dataSet.Tables.Count > 0 && dataSet.Tables[0].Rows.Count > 0) { trans.AddRow(spId, UpdateRow(WebProps, drItem, Log, connection), TransactionType.UPDATE); } else { trans.AddRow(spId, InsertRow(WebProps, drItem, Log, connection), TransactionType.INSERT); } } } catch (Exception ex) { Trace.TraceError(ex.ToString()); Log.LogMessage(ex.Message, IntegrationLogType.Error); trans.AddRow(spId, currentId, TransactionType.FAILED); } } } return(trans); }
public List <ColumnProperty> GetColumns(WebProperties webProps, IntegrationLog log, string listName) { var columnProperties = new List <ColumnProperty>(); try { O365Service o365Service = GetO365Service(webProps); var ignoredFields = new[] { "AppAuthor", "AppEditor", "Attachments", "DocIcon", "ItemChildCount", "FolderChildCount", "_UIVersionString" }; columnProperties.AddRange( from field in o365Service.GetListFields(webProps.Properties["List"].ToString()) let internalName = field.InternalName where !ignoredFields.Contains(internalName) && !internalName.StartsWith("LinkTitle") && !internalName.EndsWith("NoMenu") orderby field.Title select new ColumnProperty { ColumnName = internalName, DiplayName = field.Title, type = TranslateFieldType(field.FieldTypeKind), DefaultListColumn = GetMatchingListColumn(internalName) }); } catch (Exception e) { log.LogMessage(e.Message, IntegrationLogType.Error); } return(columnProperties); }
public DataTable PullData(WebProperties webProps, IntegrationLog log, DataTable items, DateTime lastSynch) { try { SfService sfService = GetSfService(webProps); sfService.GetObjectItems((string)webProps.Properties["Object"], items, lastSynch); } catch (Exception e) { log.LogMessage("Scheduled Pull. " + e.Message, e.Message.StartsWith("No records found") ? IntegrationLogType.Warning : IntegrationLogType.Error); } return(items); }
public DataTable GetItem(WebProperties webProps, IntegrationLog log, string itemId, DataTable items) { try { SfService sfService = GetSfService(webProps); sfService.GetObjectItemsById((string)webProps.Properties["Object"], itemId, items); } catch (Exception e) { log.LogMessage(e.Message, e.Message.StartsWith("No records found") ? IntegrationLogType.Warning : IntegrationLogType.Error); } return(items); }
public List <ColumnProperty> GetColumns(WebProperties webProps, IntegrationLog log, string listName) { var columnProperties = new List <ColumnProperty>(); try { SfService sfService = GetSfService(webProps); var ignoredFields = new[] { "IsDeleted", "CreatedDate", "LastModifiedDate", "LastModifiedById", "SystemModstamp", "LastActivityDate", sfService.AppNamespace + "__Additional_Assigned_To__c", sfService.AppNamespace + "__FK__c" }; columnProperties.AddRange( from field in sfService.GetObjectFields(webProps.Properties["Object"].ToString()) where !ignoredFields.Contains(field.name) orderby field.name select new ColumnProperty { ColumnName = field.name, DiplayName = field.label, type = TranslateFieldType(field.type), DefaultListColumn = GetMatchingListColumn(field.label, field.name, sfService.AppNamespace) }); } catch (Exception e) { log.LogMessage(e.Message, IntegrationLogType.Error); } return(columnProperties); }
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); }