/// <summary> /// Adds a url to the batch for processing /// </summary> /// <param name="item">url for batch item</param> /// <returns>True if an appropriate pending batch operation was found</returns> public bool AddToBatch(SDataBatchRequestItem item) { Guard.ArgumentNotNull(item, "item"); var uri = new SDataUri(item.Url) { CollectionPredicate = null, Query = null }; if (uri.PathSegments.Length > 4) { uri.TrimRange(4, uri.PathSegments.Length - 4); } uri.AppendPath("$batch"); var baseUri = uri.ToString(); var request = _requests.LastOrDefault(x => string.Equals(x.ToString(), baseUri, StringComparison.InvariantCultureIgnoreCase)); if (request != null) { request.Items.Add(item); return true; } return false; }
private void FormatURL() { try { var server = tbServer.Text; var pos = server.IndexOf(':'); var uri = new SDataUri(); int port; if (pos >= 0 && int.TryParse(server.Substring(pos + 1), out port)) { server = server.Substring(0, pos); uri.Port = port; } uri.Scheme = cbProtocol.Text; uri.Host = server; uri.Server = tbVirtualDirectory.Text; uri.Product = tbApplication.Text; uri.Contract = tbContract.Text; uri.CompanyDataset = tbDataSet.Text; tbURL.Text = uri.ToString(); } catch (UriFormatException) { } }
/// <summary> /// Adds a url to the batch for processing /// </summary> /// <param name="item">url for batch item</param> public void AddToBatch(SDataBatchRequestItem item) { Guard.ArgumentNotNull(item, "item"); var uri = new SDataUri(item.Url) { CollectionPredicate = null, Query = null }; if (uri.PathSegments.Length > 3) { uri.PathSegments = uri.PathSegments.Take(3).ToArray(); } var baseUri = uri.ToString(); var request = _requests.LastOrDefault(x => x.ToString() == baseUri); if (request == null) { throw new InvalidOperationException("Unable to find an appropriate batch request in progress"); } request.Requests.Add(item); }
public void Appending_Segments_To_Specific_Service_Urls_Test() { var uri = new SDataUri("http://test.com/sdata/-/-/-/resource/$service/name"); uri.AppendPath("test"); Assert.AreEqual("resource", uri.CollectionType); Assert.AreEqual("name", uri.ServiceMethod); Assert.AreEqual("-/-/-/resource/$service/name/test", uri.DirectPath); Assert.AreEqual("http://test.com/sdata/-/-/-/resource/$service/name/test", uri.ToString()); }
// 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..."); } }