public void ServiceOperation_Verify_ToString()
 {
     var request = new SDataServiceOperationRequest(_service)
                   {
                       ResourceKind = "employees",
                       OperationName = "getStats"
                   };
     var url = request.ToString();
     Expect(url, Is.EqualTo("http://localhost:59213/sdata/aw/dynamic/-/employees/$service/getStats"));
 }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
        // Needs help!
        public void promoteLead()
        {
            try
            {
                float previous = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                SDataTemplateResourceRequest contactTemplate = new SDataTemplateResourceRequest(dynamic);
                contactTemplate.ResourceKind = "contacts";

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

                Sage.SData.Client.Atom.AtomEntry leadEntry = null;
                do
                {
                    leadEntry = fetchLead();
                } while (leadEntry == null);

                SDataPayload leadPayload = leadEntry.GetSDataPayload();
                bool check = false;
                var feed = new Sage.SData.Client.Atom.AtomFeed();

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

                if (i == 50)
                    return;

                do
                {
                    try
                    {
                        SDataResourceCollectionRequest search = new SDataResourceCollectionRequest(dynamic)
                        {
                            ResourceKind = "accounts",
                            QueryValues = { { "where", "AccountName eq '" + leadPayload.Values["Company"] + "'" } }
                        };

                        feed = search.Read();
                    }
                    catch { check = true; }
                } while (check);

                bool test = false;
                foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                {
                    if (entry != null)
                    {
                        accountPayload = entry.GetSDataPayload();
                        test = true;
                        break;
                    }
                    else
                        test = false;
                }

                if (!test)
                {
                    var request = new SDataServiceOperationRequest(dynamic)
                    {
                        ResourceKind = "leads",
                        Entry = new Sage.SData.Client.Atom.AtomEntry(),
                        OperationName = "ConvertLeadToContact"
                    };


                    //if (leadPayload.Values["Company"] != null)
                    //{
                    //    accountPayload = makeAccountWithName((string)leadPayload.Values["Company"]);
                    //}

                    var entity = new SDataPayload()
                    {
                        Key = leadPayload.Key
                    };
                    request.Entry.SetSDataPayload(
                       new SDataPayload
                       {
                           ResourceName = "LeadConvertLeadToContact",
                           Namespace = "http://schemas.sage.com/dynamic/2007",
                           Values = {
                       {"request", new SDataPayload
                           {
                           Values = {
                               {"entity", leadPayload},
                               {"LeadId", entity},
                               {"contact", tempEntry},
                               {"account", leadPayload.Values["Company"]},
                               {"rule", ""}
                                    }
                           }
                        }
                                 }
                       });
                    request.Create();
                    float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                    float timed = (after - previous) / 1000;
                    Log(DateTime.Now + " - Converted " + leadPayload.Values["FirstName"] + " " + leadPayload.Values["LastName"] + " to a contact - " + timed + " seconds", fileName);
                }
                else
                {
                    SDataServiceOperationRequest request = new SDataServiceOperationRequest(dynamic)
                    {
                        ResourceKind = "leads",
                        //Entry = leadEntry,
                        Entry = new Sage.SData.Client.Atom.AtomEntry(),
                        OperationName = "ConvertLeadToAccount"
                    };
                    var entity = new SDataPayload()
                    {
                        Key = leadPayload.Key
                    };

                    request.Entry.SetSDataPayload(
                       new SDataPayload
                       {
                           ResourceName = "LeadConvertLeadToAccount",
                           Namespace = "http://schemas.sage.com/dynamic/2007",
                           Values = {
                       {"request", new SDataPayload
                           {
                           Values = {
                               {"entity", leadPayload},
                               {"LeadId", entity},
                               {"account", accountPayload.Key}
                                    }
                           }
                        }
                                 }
                       });
                    request.Create();
                    float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                    float timed = (after - previous) / 1000;
                    Log(DateTime.Now + " - Converted " + leadPayload.Values["FirstName"] + " " + leadPayload.Values["LastName"] 
                        + " to a contact with Account " + leadPayload.Values["Company"] + " - " + timed + " seconds", fileName);
                }
                leadsPromotedCount++;
                SetLeadsPromoted(leadsPromotedCount.ToString());
            }
            catch (Exception e) { 
                Log(e.ToString(), fileName); 
            }
        }
Exemplo n.º 5
0
        // Functional
        public void completeActivity()
        {
            try
            {
                // Initiates a value to keep track of amount of activities created.
                int i = 0;
                float previous = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;

                var request = new SDataServiceOperationRequest(service)
                {
                    ResourceKind = "activities",
                    OperationName = "Complete",
                    Entry = new Sage.SData.Client.Atom.AtomEntry()
                };

                // From the Whitepaper pdf to get the user payload
                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"];

                SDataResourceCollectionRequest activities = new SDataResourceCollectionRequest(service)
                {
                    ResourceKind = "activities",
                    QueryValues = { { "where", "Leader eq '" + userPayload.Values["userId"] + "'" }, { "orderBy", "StartDate" } }
                };

                var feed = activities.Read();

                // From the Whitepaper pdf to get the user payload
                //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"];
                // var user = userPayload.Values["userName"];
                // string userID = user.ToString().ToLower();


                foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                {
                    var payload = entry.GetSDataPayload();
                    var time = payload.Values["StartDate"];
                    DateTime stime = Convert.ToDateTime(time);
                    bool allow = true;

                    // Can the user complete personal activities?
                    if (UserID == "admin" && ((string)payload.Values["Type"] == "atPersonal" || (string)payload.Values["Type"] == "个人"))
                        allow = false;


                    // Checks if the amount of activities created is equal to the amount desired.
                    // Current problem resultant from changing the service to /system/
                    if (allow && payload != null)//(string)payload.Values["Description"] != "")
                    {
                        if (DateTime.Compare(stime, DateTime.Now) < 0)
                        {
                            if (i >= 1)
                                previous = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;

                            if (activityCompleteAmount == i)
                                break;

                            try
                            {
                                var entity = new SDataPayload()
                                {
                                    Key = payload.Key
                                };
                                request.Entry.SetSDataPayload(
                                   new SDataPayload
                                    {
                                        ResourceName = "ActivityComplete",
                                        Namespace = "http://schemas.sage.com/slx/system/2010",
                                        Values = {
                       {"Request", new SDataPayload
                           {
                           Values = {
                               {"Entity", entity},
                               {"UserId", userPayload.Values["userId"]},
                               {"Result", "Complete"},
                               {"CompleteDate", DateTime.Now.ToUniversalTime()}
                                    }
                           }
                        }
                                 }
                                    });
                                var response = request.Create();
                                var responsePayload = response.GetSDataPayload();
                                float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                                float timed = (after - previous) / 1000;
                                Log(DateTime.Now + " - Completed activity: " + payload.Values["Description"] + " - " + timed + "seconds", fileName);
                                i++;
                                activitiesCompleteCount++;
                                SetCompletedActivities(activitiesCompleteCount.ToString());
                            }
                            catch (Exception e)
                            {
                                Log(e.ToString(),fileName);
                            }
                        }
                    }

                }
            }
            catch (ArgumentNullException e)
            {
                Log(e.ToString(), fileName);
            }
        }
Exemplo n.º 6
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); 
            }
        }
Exemplo n.º 7
0
        // Needs help!
        public void promoteSpecificLead()
        {
            SDataTemplateResourceRequest contactTemplate = new SDataTemplateResourceRequest(dynamic);
            contactTemplate.ResourceKind = "contacts";

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

            Sage.SData.Client.Atom.AtomEntry leadEntry = null;
            do
            {
                leadEntry = fetchLead();
            } while (leadEntry == null);

            SDataPayload leadPayload = leadEntry.GetSDataPayload();

            SDataResourceCollectionRequest search = new SDataResourceCollectionRequest(dynamic)
            {
                ResourceKind = "accounts",
                QueryValues = { { "where", "AccountName eq '" + leadPayload.Values["Company"] + "'" } }
            };

            var feed = search.Read();
            bool test = false;
            foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
            {
                if (entry != null)
                {
                    test = true;
                    break;
                }
                else
                    test = false;
            }

            if (test)
            {
                SDataServiceOperationRequest request = new SDataServiceOperationRequest(service)
                {
                    ResourceKind = "leads",
                    Entry = leadEntry,
                    OperationName = "ConvertLeadToContact"
                };
                request.Create();
                Debug.WriteLine("Converted " + leadPayload.Values["FirstName"] + " " + leadPayload.Values["LastName"] + " to a contact");
                /*
                payload.Values["AccountName"] = leadPayload.Values["Company"];
                payload.Values["CreateDate"] = DateTime.Now;
                payload.Values["CreateUser"] = UserID;
                payload.Values["CuisinePreference"] = "Asian, Grill, or Mexican";
                payload.Values["Email"] = leadPayload.Values["Email"];
                payload.Values[""] = "";*/
            }
            else
            {
                SDataServiceOperationRequest request = new SDataServiceOperationRequest(service)
                {
                    ResourceKind = "leads",
                    Entry = leadEntry,
                    OperationName = "ConvertLeadToAccount"
                };
                request.Create();
                Debug.WriteLine("Converted " + leadPayload.Values["FirstName"] + " " + leadPayload.Values["LastName"] + " to a contact with Account " + leadPayload.Values["Company"]);
            }


        }