void _recordContext_DataLoaded(object sender, System.EventArgs e) { try { IIncident i = _recordContext.GetWorkspaceRecord(RightNow.AddIns.Common.WorkspaceRecordType.Incident) as IIncident; this.EnableControl(i); } catch (Exception ex) { string logMessage = "Error in loading Repair Order. Cancel Async Thread. Error: " + ex.Message; string logNote = ""; _log.ErrorLog(incidentId: _logIncidentId, logMessage: logMessage, logNote: logNote); } }
//Retrieve configuration verb via RNow SOAP and Parse it as JSON public static bool getConfigVerb(IGlobalContext _gContext) { //Init the RightNow Service rnSrv = new RightNowService(_gContext); client = rnSrv._rnowClient; string logMessage, logNote; //Query configuration from Cloud Service String query = "select Configuration.Value from Configuration where lookupname='CUSTOM_CFG_Accel_Ext_Integrations'"; String[] rowData = null; try { rowData = rnSrv.queryData(query); } catch (Exception ex) { if (logWrap != null) { logMessage = "Integration Configuration verb is not set properly. "; logNote = "Error in query config 'CUSTOM_CFG_Accel_Ext_Integrations' from Cloud Service. Error query: " + query + "; Error Message: " + ex.Message; logWrap.ErrorLog(); } MessageBox.Show("Integration Configuration verb is not set properly. Please contact your system administrator. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } // Check whether configuration is set if (rowData.Length == 0) { String message = "Integration Configuration verb does not exist. Please contact your system administrator"; MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); if (logWrap != null) { logMessage = "Integration Configuration verb does not exist."; logNote = "CUSTOM_CFG_Accel_Ext_Integrations is missing in Configuration Settings."; logWrap.ErrorLog(logMessage: logMessage, logNote: logNote); } return(false); } // Get configuration value string jsonString = rowData[0]; jsonString = jsonString.Replace("\"\"", "\""); // get the AdminProfileID // make sure it is located before "hosts" (if this is also missing, well, the config // verb is in bad shape. // can't use "{"AdminProfileID" because { can be followed by newline in config verb if (jsonString.Contains("AdminProfileID") && jsonString.Contains("hosts") && jsonString.IndexOf("AdminProfileID") < jsonString.IndexOf("hosts")) { // get the AdminProfileID value AdminProfileID = Convert.ToInt32(jsonString.Split(',')[0].Split(':')[1]); } else { String message = "Integration Configuration verb does not contain AdminProfileID as first member of JSON.\n Please contact your system administrator"; MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); if (logWrap != null) { logMessage = "Integration Configuration verb does not contain AdminProfileID as first member of JSON"; logNote = "The string is: " + jsonString; logWrap.ErrorLog(logMessage: logMessage, logNote: logNote); } AdminProfileID = 0; return(false); } loginUserIsAdmin = _gContext.ProfileId == ConfigurationSetting.AdminProfileID; // Parse endpoint configuration int i = jsonString.IndexOf("["); int j = jsonString.LastIndexOf("]"); if (i < 0 || i > j) { String message = "Siebel Integration Configuration verb is not set properly. Please contact your system administrator"; MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); if (logWrap != null) { logMessage = "Accelerator Integration Configuration verb [] array is not set properly."; logNote = "Configuration cannot be parsed, the string is: " + jsonString; logWrap.ErrorLog(logMessage: logMessage, logNote: logNote); } return(false); } string jsonTrim = jsonString.Substring(i, j - i + 1); /* Using Serializer to parse Configuration JSON String * The parsing is based on the classes definition in the following region */ var serializer = new JavaScriptSerializer(); List <ConfigurationVerb> configVerbArray = null; try { configVerbArray = serializer.Deserialize <List <ConfigurationVerb> >(jsonTrim); } catch (System.ArgumentException ex) { String message = "Accelerator Integration Configuration verb JSON is invalid. Please contact your system administrator"; MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); logMessage = "Accelerator Integration Configuration verb JSON is invalid."; logNote = "Configuration cannot be parsed, the string is: " + jsonString; logWrap.ErrorLog(logMessage: logMessage, logNote: logNote); return(false); } bool found = false; // Get the server url of current site string _interfaceUrl = _gContext.InterfaceURL; string[] splittedInterfaceUrl = _interfaceUrl.Split('/'); string _configServerUrl = splittedInterfaceUrl[2]; // Get values in configuration settings foreach (ConfigurationVerb configVerb in configVerbArray) { if (configVerb.rnt_host.Contains(_configServerUrl)) { string extBaseUrl = configVerb.integration.ext_base_url; //Get Siebel server type and initiate Siebel Provider string serverType = configVerb.integration.server_type; SiebelProvider = serverTypeToProvider(serverType); username = configVerb.integration.username; password = configVerb.integration.password; siebelServiceUserId = configVerb.integration.siebel_service_user_id; siebelDefaultSrOwnerId = configVerb.integration.siebel_default_sr_owner_id; SiebelServiceTimeout = configVerb.integration.SiebelServiceTimeout; log_level = configVerb.integration.log_level; assignLogLevelEnum(); rnt_host = configVerb.rnt_host; //Prepare the Service Request Type Mapping if (configVerb.integration.request_type_mapping != null) { requestTypeMapping = setRequestTypeMapping(configVerb.integration.request_type_mapping); } incidentsByContactReportID = configVerb.integration.incidentsByContactReportID; contactSearchReportID = configVerb.integration.contactSearchReportID; uspsUsername = configVerb.postalValidation.username; ext_address_validate_url = configVerb.postalValidation.ext_address_validate_url; Dictionary <String, Service> extServices = configVerb.integration.ext_services; foreach (KeyValuePair <String, Service> extService in extServices) { switch (extService.Key) { case "service_request_detail": if (extService.Value.create != null) { CreateSR_WSDL = extBaseUrl + extService.Value.create.relative_path; } if (extService.Value.update != null) { UpdateSR_WSDL = extBaseUrl + extService.Value.update.relative_path; } if (extService.Value.read != null) { LookupSR_WSDL = extBaseUrl + extService.Value.read.relative_path; } break; case "service_request_list": if (extService.Value.read != null) { LookupSRbyContactPartyID_WSDL = extBaseUrl + extService.Value.read.relative_path; } break; case "repair_order_detail": if (extService.Value.create != null) { CreateRepair_WSDL = extBaseUrl + extService.Value.create.relative_path; } if (extService.Value.update != null) { UpdateRepair_WSDL = extBaseUrl + extService.Value.update.relative_path; } if (extService.Value.read != null) { LookupRepair_WSDL = extBaseUrl + extService.Value.read.relative_path; } break; case "repair_order_list": if (extService.Value.read != null) { RepairOrderList_WSDL = extBaseUrl + extService.Value.read.relative_path; } break; case "service_request_note": if (extService.Value.create != null) { CreateInteraction_WSDL = extBaseUrl + extService.Value.create.relative_path; } break; case "contact_list": if (extService.Value.read != null) { LookupContactList_WSDL = extBaseUrl + extService.Value.read.relative_path; } break; case "item_list": if (extService.Value.read != null) { ItemList_WSDL = extBaseUrl + extService.Value.read.relative_path; } break; case "entitlement_list": if (extService.Value.read != null) { EntitlementList_WSDL = extBaseUrl + extService.Value.read.relative_path; } break; case "repair_logistics_list": if (extService.Value.read != null) { RepairLogisticsList_WSDL = extBaseUrl + extService.Value.read.relative_path; } break; case "repair_list": if (extService.Value.read != null) { RepairOrderList_WSDL = extBaseUrl + extService.Value.read.relative_path; } break; } } found = true; break; } } // If current site is not set in configuration. if (!found) { String message = "The current host, " + _configServerUrl + ", is not present in Integration Configuration verb.\n Please contact your system administrator"; MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); if (logWrap != null) { logMessage = "Current Host is not present in Integration Configuration verb. "; logNote = "Current site is not set in configuration CUSTOM_CFG_Accel_Ext_Integrations. The configuration verb is: " + jsonString; logWrap.ErrorLog(logMessage: logMessage, logNote: logNote); } return(false); } configVerbPerfect = true; return(true); }
/// <summary> /// Retrieve configuration verb via RNow SOAP and Parse it as JSON /// </summary> /// <param name="_gContext">The add-in global context</param> /// <returns></returns> public static bool getConfigVerb(IGlobalContext _gContext) { string logMessage, logNote; //Query configuration from Cloud Service String query = "select Configuration.Value from Configuration where lookupname='CUSTOM_CFG_Accel_Ext_Integrations'"; String[] rowData = null; try { rowData = rnSrv.queryData(query); } catch (Exception ex) { if (logWrap != null) { logMessage = "Integration Configuration verb is not set properly. "; logNote = "Error in query config 'CUSTOM_CFG_Accel_Ext_Integrations' from Cloud Service. Error query: " + query + "; Error Message: " + ex.Message; logWrap.ErrorLog(logMessage: logMessage, logNote: logNote); } MessageBox.Show("Integration Configuration verb is not set properly. Please contact your system administrator. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } // Check whether configuration is set if (rowData.Length == 0) { String message = "Integration Configuration verb does not exist. Please contact your system administrator"; MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); if (logWrap != null) { logMessage = "Integration Configuration verb does not exist."; logNote = "CUSTOM_CFG_Accel_Ext_Integrations is missing in Configuration Settings."; logWrap.ErrorLog(logMessage: logMessage, logNote: logNote); } return(false); } // Get configuration value string jsonString = rowData[0]; jsonString = jsonString.Replace("\"\"", "\""); jsonString = jsonString.TrimStart('"'); jsonString = jsonString.TrimEnd('"'); JavaScriptSerializer ser = new JavaScriptSerializer(); ConfigVerb configVerb = null; try { configVerb = ser.Deserialize <ConfigVerb>(jsonString); } catch (System.ArgumentException ex) { String message = "Accelerator Integration Configuration verb JSON is invalid. Please contact your system administrator."; MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); logMessage = "Accelerator Integration Configuration verb JSON is invalid."; logNote = "Configuration cannot be parsed, the string is: " + jsonString; logWrap.ErrorLog(logMessage: logMessage, logNote: logNote); System.Diagnostics.Debug.WriteLine(ex.Message); return(false); } if (configVerb.AdminProfileID == 0) { String message = "Integration Configuration verb does not contain AdminProfileID as first member of JSON.\n Please contact your system administrator"; MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); if (logWrap != null) { logMessage = "Integration Configuration verb does not contain AdminProfileID as first member of JSON"; logNote = "The string is: " + jsonString; logWrap.ErrorLog(logMessage: logMessage, logNote: logNote); } return(false); } loginUserIsAdmin = _gContext.ProfileId == configVerb.AdminProfileID; bool found = false; // Get the server url of current site string _interfaceUrl = _gContext.InterfaceURL; string[] splittedInterfaceUrl = _interfaceUrl.Split('/'); string _configServerUrl = splittedInterfaceUrl[2]; // Get values in configuration settings foreach (Host host in configVerb.hosts) { if (host.rnt_host.Contains(_configServerUrl)) { string extBaseUrl = host.integration.ext_base_url; log_level = host.integration.log_level; max_srm_rows_fetch = host.integration.max_srm_rows_fetch; assignLogLevelEnum(); rnt_host = host.rnt_host; convReplyPOSTEndpoint = host.integration.ext_base_url + host.integration.ext_services.conversation_reply.create.relative_path; convReplyGETEndpoint = host.integration.ext_base_url + host.integration.ext_services.conversation_reply.list.relative_path; convPUTEndpoint = host.integration.ext_base_url + host.integration.ext_services.conversation.update.relative_path; convChannelConstraints = host.integration.channel_constraints; found = true; break; } } // If current site is not set in configuration. if (!found) { String message = "The current host, " + _configServerUrl + ", is not present in Integration Configuration verb.\n Please contact your system administrator"; MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); if (logWrap != null) { logMessage = "Current Host is not present in Integration Configuration verb. "; logNote = "Current site is not set in configuration CUSTOM_CFG_Accel_Ext_Integrations. The configuration verb is: " + jsonString; logWrap.ErrorLog(logMessage: logMessage, logNote: logNote); } return(false); } configVerbPerfect = true; return(true); }