public void RFCAnalysis() { SOFTTEK.SAP.Integration.SAPConnection sapConnector = new SAP.Integration.SAPConnection(); Assert.IsNotNull(sapConnector); //string connectionString = sapConnector.SAPConnectionString(); var testDestination = sapConnector.LoadDestination(); testDestination.Ping(); var testDestinationRepository = testDestination.Repository; string[] rfcs = { "ZRFC_PM_TOMAR_MEDIDA", "ZFM_RFC_OBJETO_TECNICO", "ZFM_RFC_ORDENES_MANTENIMIENTO", "ZFM_RFC_NOTIFICACION_ORDEN", "ZFM_RFC_CREACION_AVISOS", "ZFM_RFC_UPDATE_NOTIFICACION", }; Dictionary <string, object> rfcsMetadata = new Dictionary <string, object>(); rfcs.ToList().ForEach(s => { var testRFC = testDestinationRepository.CreateFunction(s); var rfcMetadata = testRFC.Metadata; rfcsMetadata[s] = rfcMetadata; }); }
public Dictionary <string, object> CreateAdvice(Dictionary <string, object> parameters) { try { SOFTTEK.SAP.Integration.SAPConnection sapConnector = new SAP.Integration.SAPConnection(); var sapDestination = sapConnector.LoadDestination(); Dictionary <string, object> rfcInputParameters = new Dictionary <string, object>(); rfcInputParameters["IM_NOTIFHEADER"] = SAPData.CreateRFCStructure( parameters, sapDestination, "ZPMS_AVISOS_MANTENIMIENTO" ); rfcInputParameters["IM_NOTIF_TYPE"] = "M1"; Dictionary <string, object> rfcParameters = RetrieveResponseData <object>(kRFCNameCreateAdvice, rfcInputParameters); // Validate RFC's response if (rfcParameters[kRFCResponseIndicatorFieldName] != null && !kDefaultResponseIndicator.Equals(((dynamic)rfcParameters[kRFCResponseIndicatorFieldName]).Value)) { throw new InvalidOperationException( string.Format("The SAP RFC {0} has completed the request with code {1}. {2}", kRFCNameMeasurementDocument, ((dynamic)rfcParameters[kRFCResponseIndicatorFieldName]).Value, ((dynamic)rfcParameters[kRFCResponseDetailFieldName]).Value) ); } Logger.Log(new Foundation.Entity.LogEntry { Type = LOG_TYPE.LOG_TYPE_MESSAGE, Description = string.Format("The SAP RFC {0} has completed the request with code {1}. {2}", kRFCNameMasterData, ((dynamic)rfcParameters[kRFCResponseIndicatorFieldName]).Value, ((dynamic)rfcParameters[kRFCResponseDetailFieldName]).Value), App = Context.SecurityContext.AppID, Device = Context.SecurityContext.DeviceID, Module = "SAPDataProvider.CreateAdvice", User = Context.SecurityContext.ClientID }); return(rfcParameters); } catch (Exception ex) { Logger.Log(new Foundation.Entity.LogEntry { Type = LOG_TYPE.LOG_TYPE_ERROR, Description = ex.Message, App = Context.SecurityContext.AppID, Device = Context.SecurityContext.DeviceID, Module = "SAPDataProvider.CreateAdvice", User = Context.SecurityContext.ClientID }); throw ex; } }
public void TestSAPConnection() { SOFTTEK.SAP.Integration.SAPConnection sapConnector = new SAP.Integration.SAPConnection(); Assert.IsNotNull(sapConnector); //string connectionString = sapConnector.SAPConnectionString(); var testDestination = sapConnector.LoadDestination(); testDestination.Ping(); var testDestinationRepository = testDestination.Repository; var testRFC = testDestinationRepository.CreateFunction("ZRFC_PM_TOMAR_MEDIDA"); var rfcMetadata = testRFC.Metadata; Dictionary <string, object> input = new Dictionary <string, object>(); Dictionary <string, object> output = new Dictionary <string, object>(); testRFC.SetValue("I_PUNTO", "9003"); testRFC.SetValue("I_MEDIDA", "1000"); testRFC.Invoke(testDestination); for (int i = 0; i < rfcMetadata.ParameterCount; i++) { if (rfcMetadata[i].Direction.Equals(global::SAP.Middleware.Connector.RfcDirection.IMPORT)) { Type inputType = SAP.Integration.SAPData.GetDataType(rfcMetadata[i].DataType); input[rfcMetadata[i].Name] = testRFC.GetValue(rfcMetadata[i].Name);//inputType.IsValueType ? Activator.CreateInstance(inputType) : null; } else if (rfcMetadata[i].Direction.Equals(global::SAP.Middleware.Connector.RfcDirection.EXPORT)) { Type outputType = SAP.Integration.SAPData.GetDataType(rfcMetadata[i].DataType); output[rfcMetadata[i].Name] = testRFC.GetValue(rfcMetadata[i].Name); //outputType.IsValueType ? Activator.CreateInstance(outputType) : null; } } Assert.IsNotNull(output); }
/// <summary> /// Delegate method responsible of building up the RFC request and map the response into a list /// of elements by using the provided mopping function. /// </summary> /// <typeparam name="K">Expected Type of elements according to the provided mapper parameter</typeparam> /// <param name="rfcName">Name of the RFC</param> /// <param name="parameters">Dictionary with the required parameters to invoke the RFC</param> /// <param name="mapper">Function delegate responsible of mapping table structures into list of elements of type T.</param> /// <returns>Dictionary that stores</returns> private Dictionary <string, object> RetrieveResponseData <K>(string rfcName, Dictionary <string, object> parameters = null, Func <string, Func <Dictionary <string, object>, K> > mapper = null) { SOFTTEK.SAP.Integration.SAPConnection sapConnector = new SAP.Integration.SAPConnection(); var sapDestination = sapConnector.LoadDestination(); var sapDestinationRepository = sapDestination.Repository; var sapRFC = sapDestinationRepository.CreateFunction(rfcName); /// Add Input Parameters if (null != parameters && parameters.Keys != null) { parameters.Keys.ToList().ForEach(k => sapRFC.SetValue(k, parameters[k])); } /// Invoke RFC for data retrieval sapRFC.Invoke(sapDestination); var rfcMetadata = sapRFC.Metadata; Dictionary <string, object> rfcParameters = new Dictionary <string, object>(); // Retrieve data from response for (int i = 0; i < rfcMetadata.ParameterCount; i++) { if (global::SAP.Middleware.Connector.RfcDirection.IMPORT.Equals(rfcMetadata[i].Direction)) { rfcParameters[rfcMetadata[i].Name] = new { Direction = kParameterInputDirection, Type = SAP.Integration.SAPData.GetDataType(rfcMetadata[i].DataType), Value = sapRFC.GetValue(rfcMetadata[i].Name) }; } else if (global::SAP.Middleware.Connector.RfcDirection.EXPORT.Equals(rfcMetadata[i].Direction)) { rfcParameters[rfcMetadata[i].Name] = new { Direction = kParameterOutputDirection, Type = SAP.Integration.SAPData.GetDataType(rfcMetadata[i].DataType), Value = sapRFC.GetValue(rfcMetadata[i].Name) }; } else if (global::SAP.Middleware.Connector.RfcDirection.TABLES.Equals(rfcMetadata[i].Direction)) { IRfcTable rfcTable = (IRfcTable)sapRFC.GetValue(rfcMetadata[i].Name); if (rfcTable != default(IRfcTable)) { if (mapper != null && mapper(rfcMetadata[i].Name) != null) { rfcParameters[rfcMetadata[i].Name] = new { Direction = kParameterOutputDirection, Type = typeof(List <K>), Value = SAP.Integration.SAPData.RFCTableToGenericList(rfcTable, mapper(rfcMetadata[i].Name)) }; } else { rfcParameters[rfcMetadata[i].Name] = new { Direction = kParameterOutputDirection, Type = typeof(Dictionary <string, object>), Value = rfcTable.ToListOfDictionaries() }; } } } } return(rfcParameters); }
public void InsertSapAdvice() { SCMS.Entity.PM.Advice returnList = new SCMS.Entity.PM.Advice(); var sapUser = "******"; SOFTTEK.SCMS.Entity.PM.Advice modelInsert = new Entity.PM.Advice(); List <SCMS.Entity.PM.TechnicalObject> sapTechnicalObjects = new List <SCMS.Entity.PM.TechnicalObject>(); SOFTTEK.SAP.Integration.SAPConnection sapConnector = new SAP.Integration.SAPConnection(); var connectDestination = sapConnector.LoadDestination(); var destinationRepository = connectDestination.Repository; var initializerRFC = destinationRepository.CreateFunction(new System.Configuration.AppSettingsReader().GetValue("SAP_RFC_CREATE_ADVICE", typeof(string)).ToString()); var rfcMetadata = initializerRFC.Metadata; bool stateConnection = Ping(connectDestination); Dictionary <string, object> input = new Dictionary <string, object>(); Dictionary <string, object> output = new Dictionary <string, object>(); Dictionary <object, object> tables = new Dictionary <object, object>(); Dictionary <object, object> estructuras = new Dictionary <object, object>(); //if(stateConnection) //initializerRFC.Invoke(connectDestination); //if (initializerRFC.GetString("EV_INDICADOR") == "0") //{ for (int i = 0; i < rfcMetadata.ParameterCount; i++) { if (rfcMetadata[i].Direction.Equals(global::SAP.Middleware.Connector.RfcDirection.IMPORT)) { Type inputType = SAP.Integration.SAPData.GetDataType(rfcMetadata[i].DataType); input[rfcMetadata[i].Name] = initializerRFC.GetValue(rfcMetadata[i].Name);//inputType.IsValueType ? Activator.CreateInstance(inputType) : null; } else if (rfcMetadata[i].Direction.Equals(global::SAP.Middleware.Connector.RfcDirection.EXPORT)) { Type outputType = SAP.Integration.SAPData.GetDataType(rfcMetadata[i].DataType); output[rfcMetadata[i].Name] = initializerRFC.GetValue(rfcMetadata[i].Name); //outputType.IsValueType ? Activator.CreateInstance(outputType) : null; } else if (rfcMetadata[i].Direction.Equals(global::SAP.Middleware.Connector.RfcDirection.TABLES)) { Type tablesType = SAP.Integration.SAPData.GetDataType(rfcMetadata[i].DataType); tables[rfcMetadata[i].Name] = initializerRFC.GetValue(rfcMetadata[i].Name); //outputType.IsValueType ? Activator.CreateInstance(outputType) : null; } else if (rfcMetadata[i].Direction.Equals(global::SAP.Middleware.Connector.RfcDataType.STRUCTURE)) { Type estructurasType = SAP.Integration.SAPData.GetDataType(rfcMetadata[i].DataType); estructuras[rfcMetadata[i].Name] = initializerRFC.GetValue(rfcMetadata[i].Name); } } //} //else //{ // throw new Exception(String.Format("No ha sido posible cosultar las ordenes de trabajo. Causa: {0}", initializerRFC.GetString("EV_TEXT"))); //} TimeSpan ts = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); TIME time = new TIME(Convert.ToUInt32(DateTime.Now.Hour), Convert.ToUInt32(DateTime.Now.Minute), Convert.ToUInt32(DateTime.Now.Second)); Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("EQUIPMENT", ""); dic.Add("FUNCT_LOC", ""); dic.Add("PRIORITY", "Alta"); dic.Add("NOTIF_DATE", DateTime.Now); dic.Add("SHORT_TEXT", ""); dic.Add("BREAKDOWN", ""); dic.Add("STRMLFNDATE", DateTime.Now); dic.Add("STRMLFNTIME", time.ToString()); dic.Add("ENDMLFNDATE", DateTime.Now); dic.Add("ENDMLFNTIME", time.ToString()); IRfcStructure dictonaryMetadataTable; try { dictonaryMetadataTable = SOFTTEK.SAP.Integration.SAPData.CreateRFCStructure(dic, connectDestination, "ZPMS_AVISOS_MANTENIMIENTO"); } catch (Exception ex) { throw new Exception(string.Format("Ha ocurrido un error, causa : {0}", ex)); } }