public void ReadAsync(string url, object userState) { Guard.ArgumentNotNull(url, "url"); var operation = new RequestOperation(HttpMethod.Get); var request = new SDataRequest(url, operation) { UserName = UserName, Password = Password, Timeout = Timeout, Cookies = Cookies, UserAgent = UserAgent }; request.BeginGetResponse( asyncResult => { try { var response = request.EndGetResponse(asyncResult); if (ReadCompleted != null) { var content = response.Content; if (content is string && response.ContentType == MediaType.Xml) { try { content = ReadSchema(response); } catch (XmlException) { } catch (InvalidOperationException) { } } ReadCompleted(this, new ReadCompletedEventArgs(content, null, false, userState)); } } catch (Exception ex) { if (ReadCompleted != null) { ReadCompleted(this, new ReadCompletedEventArgs(null, ex, false, userState)); } } }, null); }
protected virtual ISDataResponse ExecuteRequest(string url, RequestOperation operation, params MediaType[] accept) { var request = new SDataRequest(url, operation) { Accept = accept, UserName = UserName, Password = Password, Timeout = Timeout, Cookies = Cookies, UserAgent = UserAgent }; return request.GetResponse(); }
// Example site to view the templates for the different entries. // https://trinity.sagesaleslogixcloud.com/sdata/slx/dynamic/-/history/$template #region BotFunctions public virtual void Run() { bool ok = false; SDataUri Uri = new SDataUri(service.Url.ToString()); progressLabel.ForeColor = Color.White; SetText("Running Bot"); SDataRequest request = new SDataRequest(Uri.ToString()) { UserName = UserID, Password = Password }; try { // Simulates the Bot as only functioning during some typical work schedule. This schedule excludes any work off due to holidays and weekends... if (DateTime.Compare(DateTime.Now.ToUniversalTime(), startWork.ToUniversalTime()) >= 0 && DateTime.Compare(DateTime.Now.ToUniversalTime(), endWork.ToUniversalTime()) <= 0) { // Checks to see if the bot was first commanded to run, if so demonstrates that it can connect to the server. if (firstRun) { SetActivitiesCreated("0"); SetNotesCreated("0"); SetCompletedActivities("0"); SetLeadsCreated("0"); SetAccountsCreated("0"); SetContactsCreated("0"); SetOppsCreated("0"); SetOppsUpdated("0"); SetTicketsCreated("0"); SetText("Progress:"); role = "General";//getRole(); SetRole(role); SetText("Connecting to server..."); Log("Logging at: " + DateTime.Now + "\n================================================================\n", fileName); SDataResponse response = request.GetResponse(); ok = (response.StatusCode == HttpStatusCode.OK); if (ok == true) { //PerformStep(); SetText("Connected to server"); } // If it cannot connect it displays an error message to the user and stops the bot from running. else { progressLabel.ForeColor = Color.Crimson; SetText("Unable to connect to server. Please try again."); this.stop(); } firstRun = false; // bool value runningHelper needed to clarify which UI label to change. //runningHelper = false; switch (role) { case "General": runGeneral(); SetText("Done"); break; default: runGeneral(); SetText("General role ran"); break; } } else { //runningHelper = false; switch (role) { case "General": runGeneral(); SetText("Done"); break; default: runGeneral(); SetText("General role ran..."); break; } SetText("Waiting..."); } } else return; } catch (Sage.SData.Client.Framework.SDataException) { progressLabel.ForeColor = Color.Crimson; SetText("Invalid User Name. Please try again..."); } }