public void AtomFeedReader_MultiPageEnumerator() { var page1 = new AtomFeed(); var page2 = new AtomFeed(); using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(Resources.TestFeed))) { page1.Load(stream); stream.Seek(0, SeekOrigin.Begin); page2.Load(stream); } page1.SetOpenSearchStartIndex(1); page1.SetOpenSearchItemsPerPage(1); ((IList <AtomEntry>)page1.Entries).RemoveAt(1); page2.SetOpenSearchStartIndex(2); page2.SetOpenSearchItemsPerPage(1); ((IList <AtomEntry>)page2.Entries).RemoveAt(0); var pages = new Stack <AtomFeed>(new[] { page2, page1 }); var request = new SDataResourceCollectionRequest(_service); _mock.Setup(s => s.ReadFeed(request)).Returns(pages.Pop).AtMost(2); var reader = request.ExecuteReader(); reader.ToList(); }
private SDataResourceCollectionRequest CreateCollectionRequest() { var request = new SDataResourceCollectionRequest(_sdataService); request.ResourceKind = _requestTypeInfo.ResourceKind; return(request); }
public void AtomFeedReader_Verify_CanRead() { var request = new SDataResourceCollectionRequest(_service); _mock.Setup(s => s.ReadFeed(request)).Returns(TestData.Feed); var reader = request.ExecuteReader(); Expect(reader, Is.Not.Null); }
public void ResourceCollection_Verify_ToStringWithQuery() { var request = new SDataResourceCollectionRequest(_service) { ResourceKind = "employees", QueryValues = { { "where", "gender eq m" } } }; var url = request.ToString(); Expect(url, Is.EqualTo("http://localhost:59213/sdata/aw/dynamic/-/employees?where=gender eq m")); }
public void ResourceCollection_Verify_ToStringWithPaging() { var request = new SDataResourceCollectionRequest(_service) { ResourceKind = "employees", StartIndex = 1, Count = 100 }; var url = request.ToString(); Expect(url, Is.EqualTo("http://localhost:59213/sdata/aw/dynamic/-/employees?startIndex=1&count=100")); }
public void ResourceCollection_Verify_CanRead() { var request = new SDataResourceCollectionRequest(_service) { ResourceKind = "employees" }; _mock.Setup(s => s.ReadFeed(request)).Returns(TestData.Feed); var feed = request.Read(); Expect(feed, Is.Not.Null); }
private void UpdateCollection() { try { _sdataResourceCollectionRequest = new SDataResourceCollectionRequest(Service) { ResourceKind = tbCollectionResourceKind.Text, StartIndex = (int)numStartIndex.Value, Count = (int)numCount.Value }; _feed = _sdataResourceCollectionRequest.Read(); _reader = null; var lookup = _feed.Links.ToLookup(link => link.Relation); btnFirst.Enabled = lookup["first"].Any(); btnPrevious.Enabled = lookup["previous"].Any(); btnNext.Enabled = lookup["next"].Any(); btnLast.Enabled = lookup["last"].Any(); var table = new DataTable(); table.Columns.Add("Author"); table.Columns.Add("Id"); table.Columns.Add("Title"); // iterate through the list of entries in the feed foreach (var atomentry in _feed.Entries) { var dr = table.NewRow(); dr[0] = atomentry.Authors.Select(author => author.Name).FirstOrDefault(); dr[1] = atomentry.Id.Uri.AbsoluteUri; dr[2] = atomentry.Title.Content; table.Rows.Add(dr); } // show it in the grid atomEntryGrid.DataSource = table; atomEntryGrid.Refresh(); atomEntryGrid.AutoResizeColumns(); if (atomEntryGrid.SelectedRows.Count != 0) { atomEntryGrid_CellContentClick(null, null); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void AtomFeedReader_EnumeratorMatchesIndexer() { var request = new SDataResourceCollectionRequest(_service); _mock.Setup(s => s.ReadFeed(request)).Returns(TestData.Feed); var reader = request.ExecuteReader(); var i = 0; foreach (var entry in reader) { Expect(entry, Is.EqualTo(reader[i])); i++; } }
public void AtomFeedReader_CurrentMatchesEnumerator() { var request = new SDataResourceCollectionRequest(_service); _mock.Setup(s => s.ReadFeed(request)).Returns(TestData.Feed); var reader = request.ExecuteReader(); var enumerator = reader.GetEnumerator(); do { enumerator.MoveNext(); Expect(reader.Current, Is.EqualTo(enumerator.Current)); } while (reader.MoveNext()); Expect(!enumerator.MoveNext()); }
public void AtomFeedReader_IndexerMatchesCurrent() { var request = new SDataResourceCollectionRequest(_service); _mock.Setup(s => s.ReadFeed(request)).Returns(TestData.Feed); var reader = request.ExecuteReader(); for (var i = 0; i < reader.Count; i++) { Expect(i, Is.EqualTo(reader.CurrentIndex)); Expect(reader[i], Is.EqualTo(reader.Current)); reader.MoveNext(); } Expect(!reader.MoveNext()); }
private void btnReaderRead_Click(object sender, EventArgs e) { try { _sdataResourceCollectionRequest = new SDataResourceCollectionRequest(Service) { ResourceKind = tbCollectionResourceKind.Text, StartIndex = (int)numStartIndex.Value, Count = (int)numCount.Value }; _feed = null; _reader = _sdataResourceCollectionRequest.ExecuteReader(); tbReaderCount.Text = _reader.Count.ToString(); UpdateReaderGrid(); } catch (SDataClientException ex) { MessageBox.Show(ex.Message); } }
private static void Main() { var service = new SDataService(); // set user name to authenticate with service.UserName = "******"; // set password to authenticate with service.Password = ""; service.Protocol = "HTTP"; service.ServerName = "sdata.acme.com"; service.ApplicationName = "sageApp"; service.VirtualDirectory = "sdata"; AtomFeed feed; AtomEntry entry; SDataPayload payload; #region CREATE an Entry // read the template for accounts var tru1 = new SDataTemplateResourceRequest(service); tru1.ContractName = "test"; tru1.ResourceKind = "accounts"; // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts/$template // read the entry from the server entry = service.ReadEntry(tru1); // TODO: Make changes to the entry payload payload = entry.GetSDataPayload(); var sru1 = new SDataSingleResourceRequest(service); sru1.ContractName = "test"; sru1.ResourceKind = "accounts"; var newEntry = service.CreateEntry(sru1, entry); #endregion #region CREATE a BATCH Operaton (Synchronous) // create the BatchURL var sbu = new SDataBatchRequest(service); sbu.ContractName = "test"; sbu.ResourceKind = "products"; // the configuration above generates http://sdata.acme.com/sageApp/test/-/products/$batch using (var batch = new SDataBatchRequest(service)) { // read the template for accounts var templateResourceRequest = new SDataTemplateResourceRequest(service); templateResourceRequest.ContractName = "test"; templateResourceRequest.ResourceKind = "accounts"; // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts/$template // read the entry from the server var templateEntry = service.ReadEntry(templateResourceRequest); var insertRequest = new SDataSingleResourceRequest(service); insertRequest.ContractName = "test"; insertRequest.ResourceKind = "accounts"; // do some stuff with the entry service.CreateEntry(insertRequest, templateEntry); // build, submit and get var result = batch.Commit(); } #endregion #region CREATE a BATCH Operation (Asynchronous) // create the BatchURL sbu = new SDataBatchRequest(service); sbu.ContractName = "test"; sbu.ResourceKind = "products"; // the configuration above generates http://sdata.acme.com/sageApp/test/-/products/$batch using (var batch = new SDataBatchRequest(service)) { // read the template for accounts var templateResourceRequest = new SDataTemplateResourceRequest(service); templateResourceRequest.ContractName = "test"; templateResourceRequest.ResourceKind = "accounts"; // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts/$template // read the entry from the server var templateEntry = service.ReadEntry(templateResourceRequest); var insertRequest = new SDataSingleResourceRequest(service); insertRequest.ContractName = "test"; insertRequest.ResourceKind = "accounts"; // do some stuff with the entry var request = batch.CreateAsync(); ISyndicationResource result; // wait around until the response is ready do { var progress = request.Progress; } while ((result = request.Refresh()) == null); feed = result as AtomFeed; } #endregion #region READ a Resource Collection Feed // Read a Resource Collection Feed var rcu = new SDataResourceCollectionRequest(service); rcu.ContractName = "test"; rcu.DataSet = "prod"; rcu.ResourceKind = "accounts"; // pageing rcu.StartIndex = 21; rcu.Count = 10; // query rcu.QueryValues.Add("where", "accountid='123456789abc'"); rcu.QueryValues.Add("orderby", "'account'"); // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/prod/accounts?startIndex=21&count=10 // Read the feed from the server feed = service.ReadFeed(rcu); #endregion #region READ a Single Resource Entry // Read a Single Resource Entry var sru = new SDataSingleResourceRequest(service); sru.ContractName = "test"; sru.ResourceKind = "accounts"; sru.ResourceSelector = "'A001'"; // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts('A001') // read the entry from the server entry = service.ReadEntry(sru); #endregion #region READ a Resource Property var rpu = new SDataResourcePropertyRequest(service); rpu.ContractName = "test"; rpu.ResourceKind = "accounts"; rpu.ResourceSelector = "'A001'"; rpu.ResourceProperties.Add("postalAddress"); rpu.ResourceProperties.Add("country"); // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/accounts('A001')/postalAddress/country // read the entry from the server entry = service.ReadEntry(rpu); // now reconfigure and read property as a feed rpu.ResourceProperties.Add("salesOrders('0023')"); rpu.ResourceProperties.Add("orderLines"); // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts('A001')/salesOrders('0023')/orderLines // read the feed from the server service.ReadFeed(rpu); #endregion #region READ a Template Resource var tru = new SDataTemplateResourceRequest(service); tru.ContractName = "test"; tru.ResourceKind = "accounts"; // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts/$template // read the entry from the server entry = service.ReadEntry(tru); #endregion #region READ a Resource Schema var rsu = new SDataResourceSchemaRequest(service); rsu.ContractName = "test"; // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/$schema // read the feed from the server var schema = service.ReadSchema(rsu); // now reconfigurate and set resource kind and version rsu.ResourceKind = "accounts"; rsu.Version = "5"; // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts/$schema?version=5 // read the entry from the server schema = service.ReadSchema(rsu); #endregion #region READ System Resources or Services var su = new SDataSystemRequest(service); // the above configuration generates http://sdata.acme.com/sdata/$system // read the feed from the server service.ReadFeed(su); #endregion #region READ Intermediate URLS #region READ Enumeration of Applications var iau = new IntermediateApplicationsRequest(service); // the above configuration generates http://sdata.acme.com/sdata // read the feed from the server service.ReadFeed(iau); #endregion #region READ Enumeration of DataSets var idu = new IntermediateDataSetsRequest(service); // the above configuration generates http://sdata.acme.com/sdata/sageApp // read the feed from the server feed = service.ReadFeed(idu); #endregion #region READ Enumeration of Contracts var icu = new IntermediateContractsRequest(service); // the above configuration generates http://sdata.acme.com/sdata/sageApp // read the feed from the server feed = service.ReadFeed(icu); #endregion #region READ Enumeration of Resource Collections var ircu = new IntermediateResourceCollectionsRequest(service); ircu.ContractName = "test"; // the above configuration generates http://sdata.acme.com/sdata/sageApp/test // read the feed from the server feed = service.ReadFeed(ircu); #endregion #region READ Enumeration of Services var isu = new IntermediateServicesRequest(service); isu.ContractName = "test"; // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/$service // read the feed from the server service.ReadFeed(isu); // reconfigure and set the resource kind isu.ResourceKind = "accounts"; // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/accounts/$service // read the feed from the server service.ReadFeed(isu); #endregion #endregion #region Update an Entry // Read a Single Resource Entry var sru2 = new SDataSingleResourceRequest(service); sru2.ContractName = "test"; sru2.ResourceKind = "accounts"; sru2.ResourceSelector = "'A001'"; // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/accounts('A001') // TODO: Make changes to the entry payload payload = newEntry.GetSDataPayload(); // update the server service.UpdateEntry(sru2, newEntry); #endregion #region DELETE an Entry service.DeleteEntry(sru2, newEntry); #endregion }
public List <T> GetData <T>(string filterType, string filterText) { // Set up our return data object -- a list of typed objects. List <T> returnData = new List <T>(); // Grab a listing of all the properties of this type of object PropertyInfo[] properties = typeof(T).GetProperties(); //Create a SData serivce object connection. Use the proper url and login info. string sDataUrl = GetFullSDataUrl(); ISDataService svc = new SDataService(GetFullSDataUrl(), _userId, _password); // Now create the request, passing in the ISDataService we created above var req = new SDataResourceCollectionRequest(svc); // Tell it which kind of resource we want to access. // Note, this needs to match the values on the SData tab // of the entity in Application Architect // e.g., req.ResourceKind = "AR_Customer"; Type objectType = typeof(T); req.ResourceKind = objectType.Name; // This part is optional (without it we'd be getting ALL objects of type T). // This is our where clause, or condition of which contacts we want. // In this example we want all customers whose last name starts with // the value 'American'. We need to use the exact property name as defined // in the entity (case-sensitive). //req.QueryValues.Add("where", @"CustomerName like 'American%'"); req.QueryValues.Add(filterType, filterText); req.Count = 500; // puke - we may need to check OpenSearch numbers to see if we got it all. // Now read the data (or run the query) AtomFeed feed = null; try { feed = req.Read(); } catch (Exception ex) { // no data... return our empty list object return(returnData); } // We now have the results in our AtomFeed variable, which is // basically a list of AtomEntry objects. To get to our data, // we need to read the payload from each AtomEntry and then we // can access the values for each field from it's Values // dictionary. In this example, we'll just write a few fields // from each contact to the console. foreach (AtomEntry entry in feed.Entries) { // Get the payload for this entity SDataPayload payload = entry.GetSDataPayload(); // Create an instance of type T to add to our return list T myObj = Activator.CreateInstance <T>(); // loop through the properties of T to find matching data from our query string name; foreach (PropertyInfo property in properties) { name = property.Name; if (!payload.Values.ContainsKey(name)) { // the returned data doesn't contain this property at all, // so skip it. continue; } if (payload.Values[name] == null) { property.SetValue(myObj, null); } else { // we found a match, so set the value of this property in this object instance property.SetValue(myObj, Convert.ChangeType(payload.Values[name], property.GetMethod.ReturnType)); } } // add the T object instance to our return list returnData.Add(myObj); } // return the entire list back to the caller. return(returnData); }
public void ResourceCollection_Verify_CanConstruct() { var request = new SDataResourceCollectionRequest(_service); Expect(request, Is.Not.Null); }