// ========== Connect ========== /** Connects to the WMS API, will refresh the connection if already connected. Returns true for success and false for failure. Calls UpdateState() for UI feedback. **/ public override bool Connect() { this.UpdateState(1); Program.Log(this.name, "Connecting to " + this.name + "..."); this.serviceProxy = this.GetServiceProxy(); // Failure: if (this.serviceProxy == null) { this.UpdateState(0); Program.LogError(this.name, "Unable to connect to " + this.name + ":"); Program.LogException(this.lastError); return(false); } // Success: this.UpdateState(2); Program.LogSuccess(this.name, "Connected to " + this.name + " successfully."); return(true); }
// ========== Get Service Proxy ========== /** Connects to Peoplevox returning and return a Service proxy if successful or null if failed populating the lastError string of this class.. **/ public PvxApi.IntegrationServiceV4 GetServiceProxy() { PvxApi.IntegrationServiceV4 serviceProxy = new PvxApi.IntegrationServiceV4(); try { // Connect to PVX API serviceProxy.Url = this.GetConfigValue("url").Replace("{clientID}", this.GetConfigValue("clientID")); var response = serviceProxy.Authenticate( this.config.clientID, this.config.username, Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(this.config.password))); // Set SessionId if (response.ResponseId != 0) { serviceProxy = null; this.lastError = response.Detail; } else { // Split the response and get ClientId and Session string var csvValues = response.Detail.Split(",".ToCharArray()); serviceProxy.UserSessionCredentialsValue = new PvxApi.UserSessionCredentials() { ClientId = csvValues[0], //Client Id SessionId = csvValues[1] //Session }; } } catch (Exception e) { serviceProxy = null; this.lastError = e.ToString(); } return(serviceProxy); }