private string ReloadConfig(EventHandlerEnvironment env) { NamedValues namedValues = env.Vault.NamedValueStorageOperations.GetNamedValues(MFNamedValueType.MFConfigurationValue, "SAPDocumentConnector"); if (namedValues.Contains("config")) { config = ( Configuration )Newtonsoft.Json.JsonConvert.DeserializeObject(( string )namedValues["config"], typeof(Configuration)); } return(Newtonsoft.Json.JsonConvert.SerializeObject(config, Newtonsoft.Json.Formatting.Indented)); }
private void LinkSAPDocument(StateEnvironment env) { SAPDataSource source = new SAPDataSource(); // Only documents are interesting if (env.ObjVer.Type != ( int )MFBuiltInObjectType.MFBuiltInObjectTypeDocument) { return; } // Only SAP Document classes are interesting string objectAliases = env.Vault.ClassOperations.GetObjectClassAdmin(env.ObjVerEx.Class).SemanticAliases.Value; if (!objectAliases.Contains("SAPALINK::Document")) { SysUtils.ReportToEventLog("Missing alias: SAPALINK::Document\n", System.Diagnostics.EventLogEntryType.Information); return; } // Map class to SAP document type. If not found, no link. Regex documentTypeRegex = new Regex($"{DocumentTypeProperty.Alias}=(?<documentType>[^;]+)"); Match documentTypeMatch = documentTypeRegex.Match(objectAliases); string documentType = null; if (documentTypeMatch.Success) { documentType = documentTypeMatch.Groups["documentType"].Value; } else if (env.ObjVerEx.Properties.GetProperty(DocumentTypeProperty) != null) { documentType = env.ObjVerEx.Properties.GetProperty(DocumentTypeProperty).GetValueAsUnlocalizedText(); } if (documentType == "" || documentType == null) { throw new Exception("No SAP Document type property nor SAPDocumentType alias found."); } // SAP BusinessobjectType Regex objectTypeRegex = new Regex($"{SAPBusinessObjectIDProperty.Alias}=(?<objectType>[^;]+)"); Match objectTypeMatch = objectTypeRegex.Match(objectAliases); string SAPObjectType = null; if (objectTypeMatch.Success) { SAPObjectType = objectTypeMatch.Groups["objectType"].Value; } else if (env.ObjVerEx.Properties.GetProperty(SAPBusinessObjectIDProperty) != null) { SAPObjectType = env.ObjVerEx.Properties.GetProperty(SAPBusinessObjectIDProperty).GetValueAsUnlocalizedText(); } if (SAPObjectType == "" || SAPObjectType == null) { throw new Exception("No SAP Business object type property nor SAPBusinessObjectType alias found."); } // Open SAP connection NamedValues values = env.Vault.NamedValueStorageOperations.GetNamedValues(MFNamedValueType.MFAdminConfiguration, "SAPDocumentConnector"); if (!values.Contains("Password")) { throw new Exception("The encrypted password could not be found in the NamedValuestorage."); } source.OpenConnection(config.ConnectionString + "password="******"Password"].ToString()), Guid.Empty); // Get previous version's employee IDs. //PropertyValue previousSAPObjectLink = ( env.ObjVerEx.PreviousVersion != null ) ? // env.ObjVerEx.PreviousVersion.Properties.GetProperty( SAPObjectLinkProperty ) : null; //IEnumerable<string> previousSAPObjects = ( previousSAPObjectLink != null ) ? // getSAPObjectIDs( env, previousSAPObjectLink ) : new List<string>(); // Get current version's employee IDs. PropertyValue currentSAPObjectLink = env.ObjVerEx.Properties.GetProperty(SAPObjectLinkProperty); if (currentSAPObjectLink == null) { throw new Exception("No SAP SAPObject property defined."); } IEnumerable <string> currentSAPObjects = getSAPObjectIDs(env, currentSAPObjectLink); //// Get deleted employee IDs. //IEnumerable<string> deletedIDs = previousSAPObjects.Except( currentSAPObjects ); //// Get new employee IDs. //IEnumerable<string> newIDs = currentSAPObjects.Except( previousSAPObjects ); // Remove old links //removeLinks( env, deletedIDs ); // TODO Doesn't work yet. // Create new links createLinks(env, documentType, SAPObjectType, currentSAPObjects, source); // Close connection try { source.CloseConnection(); } catch (Exception ex) { SysUtils.ReportToEventLog("Closing connection to SAP failed.\n" + ex.Message, System.Diagnostics.EventLogEntryType.Warning); } }