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 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);
            }
        }
        public void SingleResource_Verify_CanProcess_SDataBatchRequest()
        {
            var request1 = new SDataSingleResourceRequest(_service)
                           {
                               ResourceKind = "employees",
                               ResourceSelector = "1"
                           };
            var request2 = new SDataSingleResourceRequest(_service)
                           {
                               ResourceKind = "employees",
                               ResourceSelector = "2"
                           };
            var request3 = new SDataSingleResourceRequest(_service)
                           {
                               ResourceKind = "employees",
                               ResourceSelector = "3"
                           };
            _mock.Setup(s => s.ReadEntry(request1)).Returns(TestData.Entry);
            _mock.Setup(s => s.ReadEntry(request2)).Returns(TestData.Entry);
            _mock.Setup(s => s.ReadEntry(request3)).Returns(TestData.Entry);

            request2.Entry = request2.Read();
            request3.Entry = request3.Read();

            _mock.Setup(s => s.UpdateEntry(request2, request2.Entry)).Returns(TestData.Entry);
            _mock.Setup(s => s.DeleteEntry(request3, request3.Entry)).Returns(true);

            var payload2 = request2.Entry.GetSDataPayload();
            payload2.Values["MaritalStatus"] = "Married";

            AtomFeed batchfeed;

            using (var batch = new SDataBatchRequest(_service))
            {
                batch.ResourceKind = "employees";
                request1.Read();
                request2.Update();
                request3.Delete();

                _mock.Setup(s => s.CreateFeed(batch, It.IsAny<AtomFeed>())).Returns(TestData.Feed);
                batchfeed = batch.Commit();
            }

            Expect(batchfeed, Is.Not.Null);
        }
Пример #4
0
        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
        }
Пример #5
0
        // Functional
        public void makeOpportunity()
        {
            try
            {
                float previous = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                SDataTemplateResourceRequest opportunityTemplate = new SDataTemplateResourceRequest(dynamic);
                opportunityTemplate.ResourceKind = "opportunities";

                Sage.SData.Client.Atom.AtomEntry tempEntry = opportunityTemplate.Read();
                SDataPayload payload = tempEntry.GetSDataPayload();

                SDataPayload accountPayload = null;
                int i = 0;
                do
                {
                    accountPayload = fetchAccount();
                    i++;
                } while (accountPayload == null && i < 50);

                if (i == 50)
                    return;   

                int oppValue = 500 * rand.Next(5, 1000);
                DateTime closeDate = DateTime.Now;
                closeDate = closeDate.AddMonths(3);
                int month = rand.Next(0, 12);
                int day = rand.Next(0, 30);
                closeDate = closeDate.AddMonths(month);
                closeDate = closeDate.AddDays(day);

                string type = "";
                int x = rand.Next(1, 2);
                switch (language)
                {
                    case "English":
                        if (x == 1)
                            type = "Add-On";
                        else
                            type = "New";
                    break;
                    case "Chinese":
                        if (x == 1)
                            type = "附加";
                        else
                            type = "新";
                    break;
                }

                var getUserRequest = new SDataServiceOperationRequest(service)
                {
                    OperationName = "getCurrentUser",
                    Entry = new Sage.SData.Client.Atom.AtomEntry()
                };
                var temp = getUserRequest.Create();
                var userPayload = temp.GetSDataPayload();
                userPayload = (SDataPayload)userPayload.Values["response"];

                //payload.Values["ActualAmount"] = oppValue;
                payload.Values["CreateUser"] = UserID;
                payload.Values["Description"] = accountPayload.Values["AccountName"] + " - Phase " + rand.Next(0, 10);
                payload.Values["Account"] = accountPayload;
                payload.Values["Owner"] = accountPayload.Values["Owner"];
                //payload.Values["SalesAmount"] = oppValue;
                payload.Values["SalesPotential"] = oppValue;
                payload.Values["CloseProbability"] = 1;//5 * rand.Next(0, 20);
                payload.Values["EstimatedClose"] = closeDate;
                payload.Values["Stage"] = "1-Prospect";
                payload.Values["LeadSource"] = fetchLeadSource();
                payload.Values["Type"] = type;
                payload.Values["AccountManager"] = accountPayload.Values["AccountManager"];
                //payload.Values["Weighted"] = oppValue / 100;
                //payload.Values["OverrideSalesPotential"] = false;
                //payload.Values["EstimatedClose"] = randomDateGenerator();

                if (accountPayload.Values["Contacts"] != null)
                {
                    SDataBatchRequest contact = new SDataBatchRequest(dynamic)
                    {
                        ResourceKind = "contacts",
                        QueryValues = { { "where", "Account.Id eq '" + accountPayload.Key + "'" } }
                    };


                    /*
                    var feed = contact.Read();
                    SDataPayload contactPayload = ;
                    if (feed.Entries.Count() != 0)
                    {
                        int i = 1;
                        foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                        {
                            contactPayload.Values["Contact" + i] = entry.GetSDataPayload();
                            i++;
                        } */
                    payload.Values["Contacts"] = contact;
                    //}
                }

                tempEntry.SetSDataPayload(payload);

                SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
                {
                    ResourceKind = "opportunities",
                    Entry = tempEntry
                };
                request.Create();
                float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                float timed = (after - previous) / 1000;
                opportunitiesCount++;
                SetOppsCreated(opportunitiesCount.ToString());
                Log(DateTime.Now + " - Opportunity made for account: " + accountPayload.Values["AccountName"] + " - " + timed + " seconds", fileName);
            }
            catch (Exception e) { 
                Log(e.ToString(), fileName); 
            }
        }
Пример #6
0
        // Functional
        public void opportunity()
        {
            SDataTemplateResourceRequest opportunityTemplate = new SDataTemplateResourceRequest(dynamic);
            opportunityTemplate.ResourceKind = "opportunities";

            Sage.SData.Client.Atom.AtomEntry tempEntry = opportunityTemplate.Read();
            SDataPayload payload = tempEntry.GetSDataPayload();

            SDataPayload accountPayload = null;
            int i = 0;
            do
            {
                accountPayload = fetchAccount();
                i++;
            } while (accountPayload == null & i < 50);

            if (i == 50)
                return;

            int oppValue = 500 * rand.Next(1, 1000);
            DateTime closeDate = DateTime.Now;
            closeDate = closeDate.AddMonths(3);
            int month = rand.Next(0, 12);
            int day = rand.Next(0, 30);
            closeDate = closeDate.AddMonths(month);
            closeDate = closeDate.AddDays(day);

            payload.Values["ActualAmount"] = oppValue;
            payload.Values["CreateDate"] = DateTime.Now;
            payload.Values["CreateUser"] = UserID;
            payload.Values["Description"] = accountPayload.Values["AccountName"] + " - Phase " + rand.Next(0, 10);
            payload.Values["Account"] = accountPayload;
            payload.Values["Owner"] = UserID;
            payload.Values["SalesAmount"] = oppValue;
            payload.Values["SalesPotential"] = oppValue;
            payload.Values["CloseProbability"] = 5 * rand.Next(0, 20);
            payload.Values["EstimatedClose"] = closeDate;

            if (accountPayload.Values["Contacts"] != null)
            {
                SDataBatchRequest contact = new SDataBatchRequest(dynamic)
                {
                    ResourceKind = "contacts",
                    QueryValues = { { "where", "Account.Id eq '" + accountPayload.Key + "'" } }
                };


                /*
                var feed = contact.Read();
                SDataPayload contactPayload = ;
                if (feed.Entries.Count() != 0)
                {
                    int i = 1;
                    foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                    {
                        contactPayload.Values["Contact" + i] = entry.GetSDataPayload();
                        i++;
                    } */
                payload.Values["Contacts"] = contact;
                //}
            }

            tempEntry.SetSDataPayload(payload);

            SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
            {
                ResourceKind = "opportunities",
                Entry = tempEntry
            };
            request.Create();
            opportunitiesCount++;
            SetOppsCreated(opportunitiesCount.ToString());
            Debug.WriteLine("Opportunity made for account: " + accountPayload.Values["AccountName"]);
        }