/// <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); }
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) { } }
protected override void BuildUrl(SDataUri uri) { base.BuildUrl(uri); uri.AppendPath("$system"); uri.AppendPath("registry"); uri.AppendPath("endpoints"); }
/// <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; }
public void Assign_Ampersand_In_Query_Test() { var uri = new SDataUri("http://localhost:2001/sdata/aw/dynamic/-/accounts") {Query = "a=%26&b=%26"}; Assert.That(uri.Query, Is.EqualTo("a=%26&b=%26")); Assert.That(uri["a"], Is.EqualTo("&")); Assert.That(uri["b"], Is.EqualTo("&")); }
private RequestOperation CreateBatchOperation() { var uri = new SDataUri(Uri); if (uri.PathSegments.Length != 4) { throw new InvalidOperationException("Batch requests can only be made on collection end points"); } var feed = new AtomFeed(); var batchOp = new RequestOperation(HttpMethod.Post, feed); foreach (var op in _operations) { AtomEntry entry; if (op.Resource == null) { if (op.Method != HttpMethod.Post) { throw new InvalidOperationException("A predicate must be specified for GET, PUT and DELETE batch requests"); } var entryUri = new SDataUri(uri) { CollectionPredicate = op.Predicate }; entry = new AtomEntry { Id = new AtomId(entryUri.Uri) }; } else { entry = op.Resource as AtomEntry; if (entry == null) { throw new InvalidOperationException("Only atom entry resources can be submitted in batch requests"); } } entry.SetSDataHttpMethod(op.Method); if (!string.IsNullOrEmpty(op.ETag)) { entry.SetSDataHttpIfMatch(op.ETag); } feed.AddEntry(entry); foreach (var file in op.Files) { batchOp.Files.Add(file); } } return(batchOp); }
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()); }
protected SDataBaseRequest(ISDataService service) { Guard.ArgumentNotNull(service, "service"); _service = service; _uri = new SDataUri(); Protocol = service.Protocol; ServerName = service.ServerName; Port = service.Port; VirtualDirectory = !string.IsNullOrEmpty(service.VirtualDirectory) ? service.VirtualDirectory : "sdata"; }
protected override void BuildUrl(SDataUri uri) { base.BuildUrl(uri); if (!string.IsNullOrEmpty(ResourceKind)) { uri.AppendPath(ResourceKind); } uri.AppendPath(ServiceTerm); }
/// <summary> /// Execute the request and return a response object. /// </summary> public SDataResponse GetResponse() { var uri = Uri; RequestOperation operation; if (_operations.Count == 1) { operation = _operations[0]; } else { operation = CreateBatchOperation(); uri = new SDataUri(uri).AppendPath("$batch").ToString(); } string location = null; var attempts = TimeoutRetryAttempts; while (true) { var request = CreateRequest(uri, operation); WebResponse response; try { response = request.GetResponse(); } catch (WebException ex) { if (ex.Status == WebExceptionStatus.Timeout && attempts > 0) { attempts--; continue; } throw new SDataException(ex); } var httpResponse = response as HttpWebResponse; var statusCode = httpResponse != null ? httpResponse.StatusCode : 0; if (statusCode != HttpStatusCode.Found) { return(new SDataResponse(response, location)); } uri = location = response.Headers[HttpResponseHeader.Location]; } }
/// <summary> /// Initialises a new instance of the <see cref="SDataService"/> class, initialized with a target url, user name and password. /// </summary> /// <param name="url"></param> /// <param name="userName">user name used for credentials</param> /// <param name="password">password for user</param> public SDataService(string url, string userName, string password) { _uri = url != null ? new SDataUri(url) : new SDataUri { Server = "sdata", Product = "-", Contract = "-", CompanyDataset = "-" }; UserName = userName; Password = password; Timeout = 120000; UserAgent = "Sage"; }
public IAsyncResult BeginGetResponse(AsyncCallback callback, object state) { var uri = Uri; RequestOperation operation; if (_operations.Count == 1) { operation = _operations[0]; } else { operation = CreateBatchOperation(); uri = new SDataUri(uri).AppendPath("$batch").ToString(); } var request = CreateRequest(uri, operation); return(new AsyncResultWrapper <WebResponse>(request.BeginGetResponse, request.EndGetResponse, callback, state)); }
public void Non_Standard_Parameters_Should_Have_Underscore_Prefix_Test() { var uri = new SDataUri("http://test.com/sdata/-/-/-/resource?_includeContent=true"); Assert.IsTrue(uri.IncludeContent ?? false); }
/// <summary> /// Asynchronous PUT to the server /// </summary> /// <param name="request">The request that identifies the resource within the syndication data source.</param> /// <param name="resource">The resource that should be created asynchronously.</param> public virtual AsyncRequest CreateAsync(SDataBaseRequest request, ISyndicationResource resource) { Guard.ArgumentNotNull(request, "request"); Guard.ArgumentNotNull(resource, "resource"); try { var requestUrl = new SDataUri(request.ToString()) {TrackingId = Guid.NewGuid().ToString()}.ToString(); var operation = new RequestOperation(HttpMethod.Post, resource); var response = ExecuteRequest(requestUrl, operation, MediaType.Xml); var tracking = (Tracking) response.Content; return new AsyncRequest(this, response.Location, tracking); } catch (Exception ex) { throw new SDataClientException(ex.Message, ex); } }
/// <summary> /// Initialises a new instance of the <see cref="SDataUri"/> class with /// the specified <see cref="Uri"/>. /// </summary> /// <param name="uri">The <see cref="Uri"/> to assign.</param> public SDataUri(SDataUri uri) : base(uri) { }
protected override void BuildUrl(SDataUri uri) { base.BuildUrl(uri); if (!string.IsNullOrEmpty(ResourceSelector)) { uri.CollectionPredicate = ResourceSelector.StartsWith("(") && ResourceSelector.EndsWith(")") ? ResourceSelector.Substring(1, ResourceSelector.Length - 2) : ResourceSelector; } else if (Entry != null) { var payload = Entry.GetSDataPayload(); if (payload != null) { uri.CollectionPredicate = string.Format("'{0}'", payload.Key); } } }
protected virtual void BuildUrl(SDataUri uri) { }
/// <summary> /// Initialises a new instance of the <see cref="SDataUri"/> class with /// the specified <see cref="Uri"/>. /// </summary> /// <param name="uri">The <see cref="Uri"/> to assign.</param> public SDataUri(SDataUri uri) : base(uri) { }
/// <summary> /// function to format url string for the request /// </summary> /// <returns>formatted string</returns> public override string ToString() { var uri = new SDataUri(Uri.Uri.AbsoluteUri); BuildUrl(uri); return uri.Uri.AbsoluteUri.Replace("%20", " "); }
protected override void BuildUrl(SDataUri uri) { base.BuildUrl(uri); foreach (var value in ResourceProperties) { uri.AppendPath(value); } }
protected override void BuildUrl(SDataUri uri) { base.BuildUrl(uri); uri.AppendPath(TemplateTerm); }
// 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..."); } }
/// <summary> /// Execute the request and return a response object. /// </summary> public SDataResponse GetResponse() { var uri = Uri; RequestOperation operation; if (_operations.Count == 1) { operation = _operations[0]; } else { operation = CreateBatchOperation(); uri = new SDataUri(uri).AppendPath("$batch").ToString(); } string location = null; while (true) { var request = CreateRequest(uri, operation); WebResponse response; try { response = request.GetResponse(); } catch (WebException ex) { throw new SDataException(ex); } var httpResponse = response as HttpWebResponse; var statusCode = httpResponse != null ? httpResponse.StatusCode : 0; if (statusCode != HttpStatusCode.Found) return new SDataResponse(response, location); uri = location = response.Headers[HttpResponseHeader.Location]; } }
protected override void BuildUrl(SDataUri uri) { base.BuildUrl(uri); uri.AppendPath(SchemaTerm); }
protected override void BuildUrl(SDataUri uri) { base.BuildUrl(uri); uri.AppendPath(ServiceTerm); if (!string.IsNullOrEmpty(OperationName)) { uri.AppendPath(OperationName); } }
private RequestOperation CreateBatchOperation() { var uri = new SDataUri(Uri); if (uri.PathSegments.Length != 4) { throw new InvalidOperationException("Batch requests can only be made on collection end points"); } var feed = new AtomFeed(); var batchOp = new RequestOperation(HttpMethod.Post, feed); foreach (var op in _operations) { AtomEntry entry; if (op.Resource == null) { if (op.Method != HttpMethod.Post) { throw new InvalidOperationException("A predicate must be specified for GET, PUT and DELETE batch requests"); } var entryUri = new SDataUri(uri) {CollectionPredicate = op.Predicate}; entry = new AtomEntry {Id = new AtomId(entryUri.Uri)}; } else { entry = op.Resource as AtomEntry; if (entry == null) { throw new InvalidOperationException("Only atom entry resources can be submitted in batch requests"); } } entry.SetSDataHttpMethod(op.Method); if (!string.IsNullOrEmpty(op.ETag)) { entry.SetSDataHttpIfMatch(op.ETag); } feed.AddEntry(entry); foreach (var file in op.Files) { batchOp.Files.Add(file); } } return batchOp; }
protected override void BuildUrl(SDataUri uri) { base.BuildUrl(uri); if (!string.IsNullOrEmpty(ResourceSelector)) { uri.CollectionPredicate = ResourceSelector.StartsWith("(") && ResourceSelector.EndsWith(")") ? ResourceSelector.Substring(1, ResourceSelector.Length - 2) : ResourceSelector; } }