Exemple #1
0
 // Initialize CWSS
 public static void initCWSS(IGlobalContext _gContext)
 {
     rnSrv  = new RightNowService(_gContext);
     client = rnSrv._rnowClient;
 }
Exemple #2
0
        //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>
        /// Method which is invoked by the AddIn framework when the control is created.
        /// </summary>
        /// <param name="inDesignMode">Flag which indicates if the control is being drawn on the Workspace Designer. (Use this flag to determine if code should perform any logic on the workspace record)</param>
        /// <param name="RecordContext">The current workspace record context.</param>
        /// <returns>The control which implements the IWorkspaceComponent2 interface.</returns>
        public IWorkspaceComponent2 CreateControl(bool inDesignMode, IRecordContext RecordContext)
        {
            if (!ConfigurationSetting.configVerbPerfect)
            {
                if (!ConfigurationSetting.loginUserIsAdmin)
                {
                    MessageBox.Show("Activity Add-In is not initialized properly. \nPlease contact your system administrator.\n You are now logged out.");
                    _gContext.Logout();
                }
                else // don't want to logout admin
                {
                    MessageBox.Show("Activity Add-In is not loaded because of invalid configuration verb.");
                    return new ActivityAddIn(inDesignMode, RecordContext);
                }
            }

            _rContext = RecordContext;
            if (!inDesignMode && _rContext != null)
            {
                ConfigurationSetting instance = ConfigurationSetting.Instance(_gContext);

                _usr = ConfigurationSetting.username;
                _pwd = ConfigurationSetting.password;
                //_client = ConfigurationSetting.client;
                _rnSrv = ConfigurationSetting.rnSrv;
                _log = ConfigurationSetting.logWrap;
                _siebelServiceUserId = ConfigurationSetting.siebelServiceUserId;
                _siebelDefaultSrOwnerId = ConfigurationSetting.siebelDefaultSrOwnerId;

                Activity.ServiceProvider = ConfigurationSetting.SiebelProvider;
                Activity.LookupURL = ConfigurationSetting.CreateSR_WSDL;
                Activity.ServiceUsername = String.IsNullOrEmpty(_usr) ? "ebusiness" : _usr;
                Activity.ServicePassword = String.IsNullOrEmpty(_pwd) ? "password" : _pwd;
                Activity.ServiceClientTimeout = ConfigurationSetting.SiebelServiceTimeout;
                Activity.InitSiebelProvider();
            }
            _wsAddIn = new ActivityAddIn(inDesignMode, _rContext);

            _wsAddIn._rnSrv = _rnSrv;
            _wsAddIn._log = _log;
            _wsAddIn._siebelServiceUserId = _siebelServiceUserId;


            if (_log != null)
            {
                string logMessage = "Activity AddIn is setup.";
                _log.DebugLog(logMessage: logMessage);
            }

            return _wsAddIn;
        }
        /// <summary>
        /// Method which is invoked by the AddIn framework when the control is created.
        /// </summary>
        /// <param name="inDesignMode">Flag which indicates if the control is being drawn on the Workspace Designer. (Use this flag to determine if code should perform any logic on the workspace record)</param>
        /// <param name="RecordContext">The current workspace record context.</param>
        /// <returns>The control which implements the IWorkspaceComponent2 interface.</returns>
        public IWorkspaceComponent2 CreateControl(bool inDesignMode, IRecordContext RecordContext)
        {
            if (!ConfigurationSetting.configVerbPerfect)
            {
                if (!ConfigurationSetting.loginUserIsAdmin)
                {
                    MessageBox.Show("Contact Search Add-In is not initialized properly. \nPlease contact your system administrator.\n You are now logged out.");
                    _globalContext.Logout();
                }
                else // don't want to logout admin
                {
                    MessageBox.Show("Contact Search Add-In is not loaded because of invalid configuration verb.");
                    return new ContactWorkspaceAddIn(inDesignMode, RecordContext, _globalContext);
                }
            }
            _rContext = RecordContext;
            if (!inDesignMode && RecordContext != null)
            {
                //Get configuration
                ConfigurationSetting instance = ConfigurationSetting.Instance(_globalContext);
                _usr = ConfigurationSetting.username;
                _pwd = ConfigurationSetting.password;
                _client = ConfigurationSetting.client;
                _rnSrv = ConfigurationSetting.rnSrv;
                _log = ConfigurationSetting.logWrap;

                Accelerator.Siebel.SharedServices.ContactModel.ServiceProvider = ConfigurationSetting.SiebelProvider;
                Accelerator.Siebel.SharedServices.ContactModel.ListLookupURL = ConfigurationSetting.LookupContactList_WSDL;
                Accelerator.Siebel.SharedServices.ContactModel.ServiceUsername = String.IsNullOrEmpty(_usr) ? "ebusiness" : _usr;
                Accelerator.Siebel.SharedServices.ContactModel.ServicePassword = String.IsNullOrEmpty(_pwd) ? "password" : _pwd;
                Accelerator.Siebel.SharedServices.ContactModel.ServiceClientTimeout = ConfigurationSetting.SiebelServiceTimeout;
                Accelerator.Siebel.SharedServices.ContactModel.InitSiebelProvider();

                Contact_Search_Report_ID = ConfigurationSetting.contactSearchReportID;
            }
            _wsAddIn = new ContactWorkspaceAddIn(inDesignMode, RecordContext, _globalContext);
            _wsAddIn._contactSearchReportId = Contact_Search_Report_ID;
            _wsAddIn._rnSrv = _rnSrv;
            _wsAddIn._log = _log;
            return _wsAddIn;
        }
 // Initialize CWSS
 public static void initCWSS(IGlobalContext _gContext)
 {
     rnSrv = new RightNowService(_gContext);
     client = rnSrv._rnowClient;
 }
        //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;
        }