public void Service_Verity_CanInitialize() { var service = new SDataService("http://localhost:59213/sdata/aw/dynamic/-/employees", "lee", "abc123"); Expect(service.UserName, Is.Not.Null); Expect(service.UserName, Is.EqualTo("lee")); Expect(service.Password, Is.Not.Null); Expect(service.Password, Is.EqualTo("abc123")); Expect(service.Protocol, Is.Not.Null); Expect(service.Protocol, Is.EqualTo("http")); Expect(service.ServerName, Is.Not.Null); Expect(service.ServerName, Is.EqualTo("localhost")); Expect(service.Port, Is.Not.Null); Expect(service.Port, Is.EqualTo(59213)); Expect(service.VirtualDirectory, Is.Not.Null); Expect(service.VirtualDirectory, Is.EqualTo("sdata")); Expect(service.ApplicationName, Is.Not.Null); Expect(service.ApplicationName, Is.EqualTo("aw")); Expect(service.ContractName, Is.Not.Null); Expect(service.ContractName, Is.EqualTo("dynamic")); Expect(service.DataSet, Is.Not.Null); Expect(service.DataSet, Is.EqualTo("-")); }
public void BatchProcess_RequestRemovedOnDispose() { var service = new SDataService("http://localhost:59213/sdata/aw/dynamic/-/"); using (var request = new SDataBatchRequest(service)) { Assert.That(BatchProcess.Instance.Requests, Contains.Item(request)); } Assert.That(BatchProcess.Instance.Requests, Is.Empty); }
public SDataQueryProvider(string sdataContractUrl, string userName, string password, SDataEntityRepository repository) { _sdataContractUrl = sdataContractUrl; _userName = userName; _password = password; _requestTypeInfo = new RequestTypeInfo(typeof(TEntity)); _repository = repository; _sdataService = new SDataService(_sdataContractUrl, _userName, _password); IncludeNames = new List <string>(); }
public MainForm() { InitializeComponent(); var service = new SDataService(); foreach (TabPage tab in tabControl1.TabPages) { ((BaseControl)tab.Controls[0]).Service = service; } tabControl1_SelectedIndexChanged(null, null); }
public bool InsertRecord <T>(T dataItem) { bool returnData = false; // Create a SData serivce object connection. Use the proper url and login info. ISDataService svc = new SDataService(GetFullSDataUrl(), _userId, _password); // Create the SData Payload of data to be sent SDataPayload myPayload = new SDataPayload(); myPayload.Namespace = string.Empty; myPayload.ResourceName = typeof(T).Name; myPayload.Uri = new Uri(svc.Url); // Add to an ATOM feed entry b/c that's what SData uses AtomEntry myEntry = new AtomEntry(); myEntry.SetSDataPayload(myPayload); // loop through the properties to find matching data from our query foreach (PropertyInfo property in dataItem.GetType().GetProperties()) { // If the property value is null, don't add it if (property.GetValue(dataItem) == null) { continue; } myPayload.Values.Add(property.Name, property.GetValue(dataItem)); } // prepare the create request SDataSingleResourceRequest sendRequest = new SDataSingleResourceRequest(svc, myEntry); sendRequest.ResourceKind = typeof(T).Name; sendRequest.ResourceSelector = ""; try { AtomEntry response = sendRequest.Create(); returnData = true; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); returnData = false; } return(returnData); }
private AtomEntry CreateServiceRequest(SDataService service) { var request = new SDataServiceOperationRequest(service); request.ContractName = "test"; request.ResourceKind = "products"; request.OperationName = "computePrice"; // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/products/$service/computePrice // now reconfigure and generate for globally for the entire contract request.ResourceKind = string.Empty; // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/$service/computePrice // read the feed from the server return(request.Create()); }
public bool UpdateTechnicianRecord(JT_Technician dataItem) { bool returnData = false; // Create a SData serivce object connection. Use the proper url and login info. ISDataService svc = new SDataService(GetFullSDataUrl(), _userId, _password); // Create the SData Payload of data to be sent SDataPayload myPayload = new SDataPayload(); myPayload.Namespace = string.Empty; myPayload.ResourceName = typeof(JT_Technician).Name; myPayload.Uri = new Uri(svc.Url); // Add to an ATOM feed entry b/c that's what SData uses AtomEntry myEntry = new AtomEntry(); myEntry.SetSDataPayload(myPayload); // update only specific properties myPayload.Values.Add("CurrentStartTime", dataItem.CurrentStartTime); myPayload.Values.Add("CurrentStartDate", dataItem.CurrentStartDate.ToString("yyyy-MM-dd")); myPayload.Values.Add("CurrentSalesOrderNo", dataItem.CurrentSalesOrderNo); myPayload.Values.Add("CurrentWTNumber", dataItem.CurrentWTNumber); myPayload.Values.Add("CurrentWTStep", dataItem.CurrentWTStep); myPayload.Values.Add("CurrentStatus", dataItem.CurrentStatus); // prepare the create request SDataSingleResourceRequest sendRequest = new SDataSingleResourceRequest(svc, myEntry); sendRequest.ResourceKind = typeof(JT_Technician).Name; sendRequest.ResourceSelector = dataItem.TechnicianDeptNo + ";" + dataItem.TechnicianNo; try { AtomEntry response = sendRequest.Update(); returnData = true; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); returnData = false; } return(returnData); }
public void BatchProcess_AddItemWithUnsuitableRequest() { var service = new SDataService("http://localhost:59213/sdata/aw/dynamic/-/"); using (var request = new SDataBatchRequest(service) { ResourceKind = "employees" }) { var item = new SDataBatchRequestItem { Url = "http://localhost:59213/sdata/aw/dynamic/-/contacts" }; var added = BatchProcess.Instance.AddToBatch(item); Assert.That(added, Is.False); Assert.That(request.Items, Is.Empty); } }
private AtomEntry CreateServiceOperationAsync(SDataService service) { var request = new SDataServiceOperationRequest(service); request.ApplicationName = "sageApp"; request.ContractName = "test"; request.OperationName = "computePrice"; // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/$service/computePrice // read the entry from the server var asyncRequest = request.CreateAsync(); ISyndicationResource result; // wait around until the response is ready do { var progress = asyncRequest.Progress; // report progress to the user } while ((result = asyncRequest.Refresh()) == null); return(result as AtomEntry); }
public void Service_Verify_CanConstructWithUrl() { var service = new SDataService("http://localhost:59213/sdata/aw/dynamic/-/employees", "lee", "abc123"); Expect(service, Is.Not.Null); }
public void Service_Verify_CanConstruct() { var service = new SDataService(); Expect(service, Is.Not.Null); }
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); }