/// <summary> /// Modifies the <see cref="AtomEntry"/> to match the data source. /// </summary> /// <param name="resource">The <see cref="AtomEntry"/> to be filled.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> public void Fill(AtomEntry resource) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); //------------------------------------------------------------ // Create namespace resolver //------------------------------------------------------------ XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(this.Navigator.NameTable); //------------------------------------------------------------ // Attempt to fill syndication resource //------------------------------------------------------------ //BEGIN PATCH //Update from tracker #4797, but changed slightly from that patch. //Not all hosts are explicitly tagging the entry as "atom:entry". //XPathNavigator entryNavigator = this.Navigator.SelectSingleNode("atom:entry", manager); XPathNavigator entryNavigator = this.Navigator.SelectSingleNode("//*[local-name()='entry']", manager); //END PATCH if (entryNavigator != null) { Atom10SyndicationResourceAdapter.FillEntry(resource, entryNavigator, manager, this.Settings); } }
public void SingleResource_Verify_CanConstructWithTemplateEntry() { var entry = new AtomEntry(); var request = new SDataSingleResourceRequest(_service, entry); Expect(request, Is.Not.Null); Expect(request.Entry, Is.Not.Null); }
public void SingleResource_Verify_CanCreate() { var request = new SDataSingleResourceRequest(_service) {ResourceKind = "employees"}; var payload = new SDataPayload(); payload.Values["Title"] = "create 1"; payload.Values["NationalIdNumber"] = "44444"; payload.Values["LoginId"] = "create 4"; payload.Values["ContactId"] = "9999"; payload.Values["BirthDate"] = SyndicationDateTimeUtility.ToRfc3339DateTime(new DateTime(1970, 8, 2)); payload.Values["HireDate"] = SyndicationDateTimeUtility.ToRfc3339DateTime(DateTime.Now); payload.Values["ModifiedDate"] = SyndicationDateTimeUtility.ToRfc3339DateTime(DateTime.Now); payload.Values["MaritalStatus"] = "Single"; payload.Values["SalariedFlag"] = XmlConvert.ToString(true); payload.Values["CurrentFlag"] = XmlConvert.ToString(true); payload.Values["Gender"] = "Male"; payload.Values["RowGuid"] = Guid.NewGuid().ToString(); var entry = new AtomEntry { UpdatedOn = DateTime.Now, PublishedOn = DateTime.Now }; entry.SetSDataPayload(payload); request.Entry = entry; _mock.Setup(s => s.CreateEntry(request, request.Entry)).Returns(TestData.Entry); entry = request.Create(); Expect(entry, Is.Not.Null); }
private void cmdSave_Click(object sender, EventArgs e) { try { ISDataService service; service = SDataDataService.mydataService(); var entry = new AtomEntry(); var payload = new SDataPayload { ResourceName = "Lead", Namespace = "http://schemas.sage.com/dynamic/2007", Values = { {"Company", txtCompany.Text.Trim()}, {"FirstName",txtFName.Text.Trim()}, {"LastName",txtLName.Text.Trim()}, {"Email",txtEmail.Text.Trim()}, {"Address", new SDataPayload { ResourceName = "LeadAddress", Values = { {"Address1", txtAddress.Text.Trim()}, {"City", txtCity.Text.Trim()}, {"State", txtState.Text.Trim()}, {"PostalCode",txtPostalCode.Text.Trim()} } } } } }; entry.SetSDataPayload(payload); var request = new SDataSingleResourceRequest(service, entry) { ResourceKind = "leads" }; AtomEntry result = request.Create(); if (result != null) { this.DialogResult = System.Windows.Forms.DialogResult.Yes; } this.Close(); } catch (SDataClientException ex) { MessageBox.Show(ex.Message); } }
private void cmdSave_Click(object sender, EventArgs e) { try { ISDataService service; service = SDataDataService.mydataService(); var entry = new AtomEntry(); var payload = new SDataPayload { ResourceName = "Account", Namespace = "http://schemas.sage.com/dynamic/2007", Values = { {"AccountName", txtAccount.Text}, {"Contacts", new SDataPayloadCollection { new SDataPayload { ResourceName = "Contact", Values = { {"AccountName", txtAccount.Text}, {"LastName", txtLName.Text}, {"FirstName", txtFName.Text}, {"Email",txtEmail.Text} } } } } } }; entry.SetSDataPayload(payload); var request = new SDataSingleResourceRequest(service, entry) { ResourceKind = "accounts" }; AtomEntry result = request.Create(); if(result != null) { this.DialogResult = System.Windows.Forms.DialogResult.Yes; } this.Close(); } catch (SDataClientException ex) { MessageBox.Show(ex.Message); } }
private void cmdSave_Click(object sender, EventArgs e) { try { ISDataService service; service = SDataDataService.mydataService(); string ownerId = UserNameToOwnerId.GetId(service.UserName); string userId = UserNameToId.GetId(service.UserName); var entry = new AtomEntry(); var payload = new SDataPayload { ResourceName = "Opportunity", Namespace = "http://schemas.sage.com/dynamic/2007", Values = { {"Description", txtDescription.Text}, {"Account", (SDataPayload)contactPayload.Values["Account"]}, {"Owner", new SDataPayload{ Key = ownerId, ResourceName="Owner"}}, {"AccountManager", new SDataPayload{ Key = userId, ResourceName="AccountManager"}}, {"Contacts", new SDataPayloadCollection { new SDataPayload { ResourceName = "OpportunityContact", Values = {{"Contact",new SDataPayload{ Key = contactPayload.Key}}, {"IsPrimary","true"}} } } } } }; entry.SetSDataPayload(payload); var request = new SDataSingleResourceRequest(service, entry) { ResourceKind = "Opportunities" }; AtomEntry result = request.Create(); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void cmdSave_Click(object sender, EventArgs e) { try { ISDataService service; service = SDataDataService.mydataService(); string contactId = contactPayload.Key; ; string contactName = contactPayload.Values["FirstName"].ToString().Trim() + " " + contactPayload.Values["LastName"].ToString().Trim(); SDataPayload accountPayload = (SDataPayload)contactPayload.Values["Account"]; string accountId = accountPayload.Key; string accountName = contactPayload.Values["AccountName"].ToString().Trim(); var entry = new AtomEntry(); var payload = new SDataPayload { ResourceName = "Activity", Namespace = "http://schemas.sage.com/dynamic/2007", Values = { {"AccountId", accountId}, //{"AccountName", accountName}, {"ContactId", contactId}, {"Description", txtRegarding.Text} } }; entry.SetSDataPayload(payload); var request = new SDataSingleResourceRequest(service, entry) { ResourceKind = "Activities" }; AtomEntry result = request.Create(); if (result != null) { //MessageBox.Show("Acctivity created"); } this.Close(); } catch (SDataClientException ex) { MessageBox.Show(ex.Message); } }
private void cmdSave_Click(object sender, EventArgs e) { try { ISDataService service; service = SDataDataService.mydataService(); string ownerId = UserNameToOwnerId.GetId(service.UserName); var entry = new AtomEntry(); var payload = new SDataPayload { ResourceName = "Ticket", Namespace = "http://schemas.sage.com/dynamic/2007", Values = { {"Account", (SDataPayload)contactPayload.Values["Account"]}, {"Contact", contactPayload},//, {"AssignedTo", new SDataPayload{ Key = ownerId, ResourceName="Owner"}}, //{"Issue",txtSubject.Text}, {"TicketProblem", new SDataPayload{ ResourceName="TicketProblem", Values = { {"Notes",txtSubject.Text} } } } } }; entry.SetSDataPayload(payload); var request = new SDataSingleResourceRequest(service, entry) { ResourceKind = "Tickets" }; AtomEntry result = request.Create(); this.Close(); } catch (SDataClientException ex) { //MessageBox.Show(ex.Message); //Getting object reference error and have no idea why //Everything is created just fine and is working though still get error this.Close(); } }
public void Typical_Entry() { var xml = @"<entry xmlns=""http://www.w3.org/2005/Atom"" xmlns:sync=""http://schemas.sage.com/sdata/sync/2008/1""> <sync:syncState> <sync:endpoint>http://www.example.com/sdata/myApp1/myContract/-/accounts</sync:endpoint> <sync:tick>5</sync:tick> <sync:stamp>2008-10-30T14:55:43Z</sync:stamp> </sync:syncState> </entry>"; var entry = new AtomEntry(); using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(xml))) { entry.Load(stream); } var syncState = entry.GetSDataSyncState(); Assert.That(syncState.EndPoint, Is.EqualTo("http://www.example.com/sdata/myApp1/myContract/-/accounts")); Assert.That(syncState.Tick, Is.EqualTo(5L)); Assert.That(syncState.Stamp, Is.EqualTo(new DateTime(2008, 10, 30, 14, 55, 43))); }
public static string Create(string oppoId, string contactId) { try { ISDataService service; service = SDataDataService.mydataService(); var entry = new AtomEntry(); var payload = new SDataPayload { ResourceName = "OpportunityContact", Namespace = "http://schemas.sage.com/dynamic/2007", Values = { {"Contact", new SDataPayload{ Key = contactId, ResourceName="Contact"}}, {"Opportunity", new SDataPayload{ Key = oppoId, ResourceName="Opportunity"}} } }; entry.SetSDataPayload(payload); var request = new SDataSingleResourceRequest(service, entry) { ResourceKind = "OpportunityContacts" }; AtomEntry result = request.Create(); if (result != null) { return result.Id.ToString(); } else { return null; } } catch (Exception ex) { return null; } }
/// <summary> /// Modifies the <see cref="AtomEntry"/> to match the supplied <see cref="XPathNavigator"/> data source. /// </summary> /// <param name="entry">The <see cref="AtomEntry"/> to be filled.</param> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomEntry"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillEntry(AtomEntry entry, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(entry, "entry"); Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to fill syndication resource //------------------------------------------------------------ AtomUtility.FillCommonObjectAttributes(entry, source); XPathNavigator idNavigator = source.SelectSingleNode("atom:id", manager); XPathNavigator titleNavigator = source.SelectSingleNode("atom:title", manager); XPathNavigator updatedNavigator = source.SelectSingleNode("atom:updated", manager); if (idNavigator != null) { entry.Id = new AtomId(); entry.Id.Load(idNavigator, settings); } if (titleNavigator != null) { entry.Title = new AtomTextConstruct(); entry.Title.Load(titleNavigator, settings); } if (updatedNavigator != null) { DateTime updatedOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updatedNavigator.Value, out updatedOn)) { entry.UpdatedOn = updatedOn; } } Atom10SyndicationResourceAdapter.FillEntryOptionals(entry, source, manager, settings); Atom10SyndicationResourceAdapter.FillEntryCollections(entry, source, manager, settings); SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings); adapter.Fill(entry, manager); }
/// <summary> /// Modifies the <see cref="AtomEntry"/> collection entities to match the supplied <see cref="XPathNavigator"/> data source. /// </summary> /// <param name="entry">The <see cref="AtomEntry"/> to be filled.</param> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomEntry"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillEntryCollections(AtomEntry entry, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(entry, "entry"); Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ XPathNodeIterator authorIterator = source.Select("atom:author", manager); XPathNodeIterator categoryIterator = source.Select("atom:category", manager); XPathNodeIterator contributorIterator = source.Select("atom:contributor", manager); XPathNodeIterator linkIterator = source.Select("atom:link", manager); if (authorIterator != null && authorIterator.Count > 0) { while (authorIterator.MoveNext()) { AtomPersonConstruct author = new AtomPersonConstruct(); if (author.Load(authorIterator.Current, settings)) { entry.Authors.Add(author); } } } if (categoryIterator != null && categoryIterator.Count > 0) { while (categoryIterator.MoveNext()) { AtomCategory category = new AtomCategory(); if (category.Load(categoryIterator.Current, settings)) { entry.Categories.Add(category); } } } if (contributorIterator != null && contributorIterator.Count > 0) { while (contributorIterator.MoveNext()) { AtomPersonConstruct contributor = new AtomPersonConstruct(); if (contributor.Load(contributorIterator.Current, settings)) { entry.Contributors.Add(contributor); } } } if (linkIterator != null && linkIterator.Count > 0) { while (linkIterator.MoveNext()) { AtomLink link = new AtomLink(); if (link.Load(linkIterator.Current, settings)) { entry.Links.Add(link); } } } }
/// <summary> /// Updates information about a syndication resource in the data source. /// </summary> /// <param name="request">The url from the syndication data source for the resource to be updated.</param> /// <param name="entry"> /// An object that implements the <see cref="ISyndicationResource"/> interface that represents the updated information for the resource. /// </param> public virtual AtomEntry UpdateEntry(SDataBaseRequest request, AtomEntry entry) { Guard.ArgumentNotNull(request, "request"); Guard.ArgumentNotNull(entry, "entry"); try { var url = request.ToString(); var eTag = entry.GetSDataHttpETag(); var batchItem = new SDataBatchRequestItem { Url = url, Method = HttpMethod.Put, Entry = entry, ETag = eTag }; if (BatchProcess.Instance.AddToBatch(batchItem)) { return null; } var operation = new RequestOperation(HttpMethod.Put, entry) {ETag = eTag}; return ExecuteEntryRequest(url, operation); } catch (SDataClientException) { throw; } catch (Exception ex) { throw new SDataClientException(ex.Message, ex); } }
/// <summary> /// Creates a new <see cref="AtomEntry"/> instance using the specified <see cref="Uri"/>, <see cref="ICredentials"/>, <see cref="IWebProxy"/>, and <see cref="SyndicationResourceLoadSettings"/> object. /// </summary> /// <param name="source">A <see cref="Uri"/> that represents the URL of the syndication resource XML data.</param> /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the <see cref="AtomEntry"/> instance. This value can be <b>null</b>.</param> /// <returns>An <see cref="AtomEntry"/> object loaded using the <paramref name="source"/> data.</returns> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="FormatException">The <paramref name="source"/> data does not conform to the expected syndication content format. In this case, the entry remains empty.</exception> public static AtomEntry Create(Uri source, WebRequestOptions options, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ AtomEntry syndicationResource = new AtomEntry(); //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Create new instance using supplied parameters //------------------------------------------------------------ syndicationResource.Load(source, options, settings); return syndicationResource; }
private static AtomEntry LoadEntryContent(Stream stream) { var entry = new AtomEntry(); entry.Load(stream); return entry; }
private bool DeleteEntry(string url, AtomEntry entry) { try { var eTag = entry != null ? entry.GetSDataHttpETag() : null; var batchItem = new SDataBatchRequestItem { Url = url, Method = HttpMethod.Delete, ETag = eTag }; if (BatchProcess.Instance.AddToBatch(batchItem)) { return true; } var operation = new RequestOperation(HttpMethod.Delete) {ETag = eTag}; var response = ExecuteRequest(url, operation, MediaType.AtomEntry, MediaType.Xml); return response.StatusCode == HttpStatusCode.OK; } catch (Exception ex) { throw new SDataClientException(ex.Message, ex); } }
/// <summary> /// Updates information about a syndication resource in the data source. /// </summary> /// <param name="request">The url from the syndication data source for the resource to be updated.</param> /// <param name="entry"> /// An object that implements the <see cref="ISyndicationResource"/> interface that represents the updated information for the resource. /// </param> public virtual AtomEntry UpdateEntry(SDataBaseRequest request, AtomEntry entry) { Guard.ArgumentNotNull(request, "request"); return UpdateEntry(request.ToString(), entry); }
/// <summary> /// Adds a new syndication resource to the data source. /// </summary> /// <param name="request">The request that identifies the resource within the syndication data source.</param> /// <param name="entry">The entry that should be created.</param> public virtual AtomEntry CreateEntry(SDataBaseRequest request, AtomEntry entry) { Guard.ArgumentNotNull(request, "request"); var requestUrl = request.ToString(); return CreateEntry(requestUrl, entry); }
/// <summary> /// initializes the single resource request and loads the atom entry /// </summary> /// <remarks>this should be used with the atom entry returned from the /// SDataTemplateResourceRequest</remarks> /// <param name="service"></param> /// <param name="entry"></param> public SDataSingleResourceRequest(ISDataService service, AtomEntry entry) : base(service) { Entry = entry; }
/// <summary> /// Modifies the <see cref="AtomEntry"/> optional entities to match the supplied <see cref="XPathNavigator"/> data source. /// </summary> /// <param name="entry">The <see cref="AtomEntry"/> to be filled.</param> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomEntry"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillEntryOptionals(AtomEntry entry, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(entry, "entry"); Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ XPathNavigator contentNavigator = source.SelectSingleNode("atom:content", manager); XPathNavigator publishedNavigator = source.SelectSingleNode("atom:published", manager); XPathNavigator rightsNavigator = source.SelectSingleNode("atom:rights", manager); XPathNavigator sourceNavigator = source.SelectSingleNode("atom:source", manager); XPathNavigator summaryNavigator = source.SelectSingleNode("atom:summary", manager); if (contentNavigator != null) { entry.Content = new AtomContent(); entry.Content.Load(contentNavigator, settings); } if (publishedNavigator != null) { DateTime publishedOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(publishedNavigator.Value, out publishedOn)) { entry.PublishedOn = publishedOn; } } if (rightsNavigator != null) { entry.Rights = new AtomTextConstruct(); entry.Rights.Load(rightsNavigator, settings); } if (sourceNavigator != null) { entry.Source = new AtomSource(); entry.Source.Load(sourceNavigator, settings); } if (summaryNavigator != null) { entry.Summary = new AtomTextConstruct(); entry.Summary.Load(summaryNavigator, settings); } }
/// <summary> /// Modifies the <see cref="AtomFeed"/> collection entities to match the supplied <see cref="XPathNavigator"/> data source. /// </summary> /// <param name="feed">The <see cref="AtomFeed"/> to be filled.</param> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomFeed"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="feed"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillFeedCollections(AtomFeed feed, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(feed, "feed"); Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ XPathNodeIterator authorIterator = source.Select("atom:author", manager); XPathNodeIterator categoryIterator = source.Select("atom:category", manager); XPathNodeIterator contributorIterator = source.Select("atom:contributor", manager); XPathNodeIterator linkIterator = source.Select("atom:link", manager); XPathNodeIterator entryIterator = source.Select("atom:entry", manager); if (authorIterator != null && authorIterator.Count > 0) { while (authorIterator.MoveNext()) { AtomPersonConstruct author = new AtomPersonConstruct(); if (author.Load(authorIterator.Current, settings)) { feed.Authors.Add(author); } } } if (categoryIterator != null && categoryIterator.Count > 0) { while (categoryIterator.MoveNext()) { AtomCategory category = new AtomCategory(); if (category.Load(categoryIterator.Current, settings)) { feed.Categories.Add(category); } } } if (contributorIterator != null && contributorIterator.Count > 0) { while (contributorIterator.MoveNext()) { AtomPersonConstruct contributor = new AtomPersonConstruct(); if (contributor.Load(contributorIterator.Current, settings)) { feed.Contributors.Add(contributor); } } } if (entryIterator != null && entryIterator.Count > 0) { int counter = 0; while (entryIterator.MoveNext()) { AtomEntry entry = new AtomEntry(); counter++; Atom10SyndicationResourceAdapter.FillEntry(entry, entryIterator.Current, manager, settings); if (settings.RetrievalLimit != 0 && counter > settings.RetrievalLimit) { break; } ((Collection<AtomEntry>)feed.Entries).Add(entry); } } if (linkIterator != null && linkIterator.Count > 0) { while (linkIterator.MoveNext()) { AtomLink link = new AtomLink(); if (link.Load(linkIterator.Current, settings)) { feed.Links.Add(link); } } } }
/// <summary> /// Reads resource information from the data source based on the URL and the ETag of the specified entry. /// </summary> /// <param name="request"></param> /// <param name="entry"></param> /// <returns></returns> public virtual AtomEntry ReadEntry(SDataBaseRequest request, AtomEntry entry) { Guard.ArgumentNotNull(request, "request"); try { var requestUrl = request.ToString(); var eTag = entry != null ? entry.GetSDataHttpETag() : null; var batchItem = new SDataBatchRequestItem { Url = requestUrl, Method = HttpMethod.Get, ETag = eTag }; if (BatchProcess.Instance.AddToBatch(batchItem)) { return null; } var operation = new RequestOperation(HttpMethod.Get) {ETag = eTag}; var response = ExecuteRequest(requestUrl, operation, MediaType.AtomEntry, MediaType.Xml); entry = (AtomEntry) response.Content; if (!string.IsNullOrEmpty(response.ETag)) { entry.SetSDataHttpETag(response.ETag); } return entry; } catch (Exception ex) { throw new SDataClientException(ex.Message, ex); } }
/// <summary> /// Adds the supplied <see cref="AtomEntry"/> to the current instance's <see cref="Entries"/> collection. /// </summary> /// <param name="entry">The <see cref="AtomEntry"/> to be added.</param> /// <returns><b>true</b> if the <see cref="AtomEntry"/> was added to the <see cref="Entries"/> collection, otherwise <b>false</b>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception> public bool AddEntry(AtomEntry entry) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasAdded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(entry, "entry"); //------------------------------------------------------------ // Add entry to collection //------------------------------------------------------------ ((Collection<AtomEntry>)this.Entries).Add(entry); wasAdded = true; return wasAdded; }
private AtomEntry CreateEntry(string url, AtomEntry entry) { Guard.ArgumentNotNull(entry, "entry"); try { var batchItem = new SDataBatchRequestItem { Url = url, Method = HttpMethod.Post, Entry = entry }; if (BatchProcess.Instance.AddToBatch(batchItem)) { return null; } var operation = new RequestOperation(HttpMethod.Post, entry); var response = ExecuteRequest(url, operation, MediaType.AtomEntry, MediaType.Xml); var result = response.Content as AtomEntry; if (result == null) { var feedResult = response.Content as AtomFeed; if (feedResult != null) { result = feedResult.Entries.FirstOrDefault(); } } if (!string.IsNullOrEmpty(response.ETag) && result != null) { result.SetSDataHttpETag(response.ETag); } return result; } catch (Exception ex) { throw new SDataClientException(ex.Message, ex); } }
/// <summary> /// Removes the supplied <see cref="AtomEntry"/> from the current instance's <see cref="Entries"/> collection. /// </summary> /// <param name="entry">The <see cref="AtomEntry"/> to be removed.</param> /// <returns><b>true</b> if the <see cref="AtomEntry"/> was removed from the <see cref="Entries"/> collection, otherwise <b>false</b>.</returns> /// <remarks> /// If the <see cref="Entries"/> collection of the current instance does not contain the specified <see cref="AtomEntry"/>, will return <b>false</b>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception> public bool RemoveEntry(AtomEntry entry) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasRemoved = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(entry, "entry"); //------------------------------------------------------------ // Remove entry from collection //------------------------------------------------------------ if (((Collection<AtomEntry>)this.Entries).Contains(entry)) { ((Collection<AtomEntry>)this.Entries).Remove(entry); wasRemoved = true; } return wasRemoved; }
private AtomEntry UpdateEntry(string url, AtomEntry entry) { Guard.ArgumentNotNull(entry, "entry"); try { var eTag = entry.GetSDataHttpETag(); var batchItem = new SDataBatchRequestItem { Url = url, Method = HttpMethod.Put, Entry = entry, ETag = eTag }; if (BatchProcess.Instance.AddToBatch(batchItem)) { return null; } var operation = new RequestOperation(HttpMethod.Put, entry) {ETag = eTag}; var response = ExecuteRequest(url, operation, MediaType.AtomEntry, MediaType.Xml); entry = (AtomEntry) response.Content; if (!string.IsNullOrEmpty(response.ETag)) { entry.SetSDataHttpETag(response.ETag); } return entry; } catch (Exception ex) { throw new SDataClientException(ex.Message, ex); } }
private void DisplayEntry(AtomEntry entry) { _sdataSingleResourceRequest.Entry = entry; var exists = entry != null; btnSingleCreate.Enabled = exists; btnSingleUpdate.Enabled = exists; btnSingleDelete.Enabled = exists; if (exists) { var uri = entry.Id.Uri.OriginalString; var start = uri.IndexOf("("); var end = uri.IndexOf(")", start); tbSingleResourceSelector.Text = uri.Substring(start, end + 1 - start); // show it in the grid singlePayloadGrid.SelectedObject = entry.GetSDataPayload(); } else { tbSingleResourceSelector.Text = null; singlePayloadGrid.SelectedObject = null; } }
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; }
/// <summary> /// Removes a resource from the syndication data source. /// </summary> /// <param name="request">The request from the syndication data source for the resource to be removed.</param> /// <param name="entry">the resource that is being deleted</param> /// <returns><b>true</b> if the syndication resource was successfully deleted; otherwise, <b>false</b>.</returns> public virtual bool DeleteEntry(SDataBaseRequest request, AtomEntry entry) { Guard.ArgumentNotNull(request, "request"); try { var url = request.ToString(); var eTag = entry != null ? entry.GetSDataHttpETag() : null; var batchItem = new SDataBatchRequestItem { Url = url, Method = HttpMethod.Delete, ETag = eTag }; if (BatchProcess.Instance.AddToBatch(batchItem)) { return true; } var operation = new RequestOperation(HttpMethod.Delete) {ETag = eTag}; var response = ExecuteRequest(url, operation, MediaType.AtomEntry, MediaType.Xml); return response.StatusCode == HttpStatusCode.OK; } catch (Exception ex) { throw new SDataClientException(ex.Message, ex); } }