コード例 #1
0
        public void LoadTickets()
        {
            Sage.SData.Client.Core.SDataSingleResourceRequest request = new
                Sage.SData.Client.Core.SDataSingleResourceRequest(_service);

            request.ResourceKind = "tickets";
            //**Be sure to change this query!

            request.QueryValues.Add("include", "Account");
            request.ResourceSelector = "'tDEMOA000002'";
            // Read the feed from the server
            SDataPayload ticket, account;

            //I did this as a seperate so that I could tell when the read comes back
            Sage.SData.Client.Atom.AtomEntry entry = request.Read();
            //and clear the please wait message.
            //first get the payload out for the entry
            ticket = entry.GetSDataPayload();
            account = (SDataPayload)ticket.Values["Account"];
            account.Values["UserField1"] = "Sam";

            //put everything back..
            ticket.Values["Account"] = account;

            entry.SetSDataPayload(ticket);
            request.Entry = entry;
            request.Update();

            if (request.Entry.GetSDataHttpStatus() !=
                System.Net.HttpStatusCode.OK)
            {
                MessageBox.Show("Uh oh. Something went wrong.");
            }
        }
        public void SingleResource_Verify_CanUpdate()
        {
            var request = new SDataSingleResourceRequest(_service)
                          {
                              ResourceKind = "employees",
                              ResourceSelector = "1"
                          };
            _mock.Setup(s => s.ReadEntry(request)).Returns(TestData.Entry);

            var entry = request.Read();
            var payload = entry.GetSDataPayload();
            payload.Values["Title"] = "test update";
            request.Entry = entry;
            _mock.Setup(s => s.UpdateEntry(request, request.Entry)).Returns(TestData.Entry);

            entry = request.Update();
            Expect(entry, Is.Not.Null);
        }
        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
ファイル: Bot.cs プロジェクト: rjledger/Demo-Bot
        // Functional, updated to include transitions between stages...
        public void updateOpportunity()
        {
            try
            {
                float previous = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                Sage.SData.Client.Atom.AtomEntry entry = null;
                SDataPayload payload = null;
                int counter = 0;
                int counter2 = 0;
                bool checker = false;
                do
                {
                    checker = false;
                        do
                        {
                            entry = fetchOpportunity();
                            counter++;
                        } while (entry == null || counter == 50);
                        
                        if (counter == 50)
                        {
                            Log("Unable to locate a valid opportunity at " + DateTime.Now, fileName);
                            return;
                        }
                    payload = entry.GetSDataPayload();
                    counter2++;
                    if (counter2 == 50)
                    {
                        Log("Unable to locate a valid opportunity (second do-while) at " + DateTime.Now, fileName);
                        return;
                    }
                    string temp = payload.Values["SalesPotential"].ToString();
                    
                    if (temp == "0.0000")
                        checker = true;
                } while (((string)payload.Values["Closed"]) == "true" || checker == true);

                int x = rand.Next(0, 100);
                if (x < (Convert.ToInt32(payload.Values["CloseProbability"]) + 20) && payload.Values["AddToForecast"].ToString() == "false")
                {
                    payload.Values["AddToForecast"] = true;
                    float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                    float timed = (after - previous) / 1000;
                    Log(DateTime.Now + " - Added " + payload.Values["Description"] + " to forecast - " + timed + " seconds of searching", fileName);
                    Debug.WriteLine("Added " + payload.Values["Description"] + " to forecast");
                }

                if ((string)payload.Values["CloseProbability"] == 100.ToString())
                {
                    string reason = localize(language, "Reason", null, null, null, true);
                    payload.Values["Closed"] = true;
                    payload.Values["CloseProbability"] = 100;
                    payload.Values["ActualClose"] = DateTime.Now;
                    payload.Values["Win"] = true;
                    payload.Values["Reason"] = reason;
                    switch (language)
                    {
                        case "English":
                        payload.Values["Status"] = "Closed - Won";
                        break;
                        case "Chinese":
                        payload.Values["Status"] = "关闭 - 韩元";
                        break;
                    }
                    payload.Values["SalesAmount"] = payload.Values["SalesPotential"];
                    payload.Values["ActualAmount"] = payload.Values["SalesAmount"];

                    entry.SetSDataPayload(payload);

                    SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
                    {
                        ResourceKind = "opportunities",
                        Entry = entry
                    };

                    request.Update();
                    float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                    float timed = (after - previous) / 1000;
                    Log(DateTime.Now + " - Updated Opp with win: " + payload.Values["Description"]  + " - " + timed + " seconds", fileName);
                    Debug.WriteLine("Updated Opp with win: " + payload.Values["Description"]);
                    oppsUpdatedCount++;
                    SetOppsUpdated(oppsUpdatedCount.ToString());
                    return;
                }
                else
                {
                    double choice = 5 * rand.NextDouble();
                    if (choice < 1.6)
                    {
                        if (choice < .3)
                        {
                            // Close the opportunity (either winning or losing it based on the 'close prob'
                            int luckyOne = Convert.ToInt32(payload.Values["CloseProbability"]) + 10;
                            int testMyLuck = rand.Next(0, 100);
                            if (testMyLuck <= luckyOne)
                            {
                                // Winner winner! Close the opportunity with a win.
                                // Is this a service request? Close-win?
                                string reason = localize(language, "Reason", null, null, null, true);
                                payload.Values["Closed"] = true;
                                payload.Values["CloseProbability"] = 100;
                                payload.Values["ActualClose"] = DateTime.Now;
                                payload.Values["Win"] = true;
                                payload.Values["Reason"] = reason;
                                switch (language)
                                {
                                    case "English":
                                        payload.Values["Status"] = "Closed - Won";
                                        break;
                                    case "Chinese":
                                        payload.Values["Status"] = "关闭 - 韩元";
                                        break;
                                }
                                payload.Values["SalesAmount"] = payload.Values["SalesPotential"];
                                payload.Values["ActualAmount"] = payload.Values["SalesAmount"];

                                entry.SetSDataPayload(payload);

                                SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
                                {
                                    ResourceKind = "opportunities",
                                    Entry = entry
                                };

                                request.Update();
                                float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                                float timed = (after - previous) / 1000;
                                Log(DateTime.Now + " - Updated Opp with win: " + payload.Values["Description"] +  " - " + timed + " seconds", fileName);
                                Debug.WriteLine("Updated Opp with win: " + payload.Values["Description"]);
                                oppsUpdatedCount++;
                                SetOppsUpdated(oppsUpdatedCount.ToString());
                                return;
                            }
                            else
                            {
                                // Ruh roh! You lost, close the opportunity with a 'lost' value
                                string reason = localize(language, "Reason", null, null, null, false);
                                payload.Values["Closed"] = true;
                                payload.Values["CloseProbability"] = 0;
                                payload.Values["ActualClose"] = DateTime.Now;
                                payload.Values["Win"] = false;
                                payload.Values["Reason"] = reason;
                                switch (language)
                                {
                                    case "English":
                                        payload.Values["Status"] = "Closed - Lost";
                                        break;
                                    case "Chinese":
                                        payload.Values["Status"] = "关闭 - 失落";
                                        break;
                                }

                                entry.SetSDataPayload(payload);

                                SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
                                {
                                    ResourceKind = "opportunities",
                                    Entry = entry
                                };

                                request.Update();
                                float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                                float timed = (after - previous) / 1000;
                                Log(DateTime.Now + " - Updated Opp with loss: " + payload.Values["Description"]  + " - " + timed + " seconds", fileName);
                                Debug.WriteLine("Updated Opp with loss: " + payload.Values["Description"]);
                                oppsUpdatedCount++;
                                SetOppsUpdated(oppsUpdatedCount.ToString());
                                return;
                            }
                        }
                        else
                        {
                            int unlucky = rand.Next(0, 100);
                            if (unlucky < 3)
                            {
                                string reason = localize(language, "Reason", null, null, null, false);
                                payload.Values["Closed"] = true;
                                payload.Values["CloseProbability"] = 0;
                                payload.Values["ActualClose"] = DateTime.Now;
                                payload.Values["Win"] = false;
                                payload.Values["Reason"] = reason;
                                payload.Values["Status"] = "Closed - Lost";

                                entry.SetSDataPayload(payload);

                                SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
                                {
                                    ResourceKind = "opportunities",
                                    Entry = entry
                                };

                                request.Update();
                                float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                                float timed = (after - previous) / 1000;
                                Log(DateTime.Now + " - Updated Opp with loss: " + payload.Values["Description"]  + " - " + timed + " seconds", fileName);
                                Debug.WriteLine("Updated Opp with loss: " + payload.Values["Description"]);
                                oppsUpdatedCount++;
                                SetOppsUpdated(oppsUpdatedCount.ToString());
                                return;
                            }
                            // Add a note to the opportunity
                            makeNoteFor(payload);
                            Log(DateTime.Now + " - Note made for: " + payload.Values["Description"], fileName);
                            Debug.WriteLine("Note made for: " + payload.Values["Description"]);
                            return;
                        }
                    }
                    else
                    {
                        if (choice >= 2.9)
                        {
                            // Updates the sales process
                            localize(language, "Progress Stage", payload, null, null, true);

                            entry.SetSDataPayload(payload);

                            SDataSingleResourceRequest requested = new SDataSingleResourceRequest(dynamic)
                            {
                                ResourceKind = "opportunities",
                                Entry = entry
                            };
                            requested.Update();
                            float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                            float timed = (after - previous) / 1000;
                            Log(DateTime.Now + " - Opportunity: " + payload.Values["Description"] + " moved to the next stage - " + timed + " seconds", fileName);
                            Debug.WriteLine("Opportunity: " + payload.Values["Description"] + " moved to the next stage");
                            oppsUpdatedCount++;
                            SetOppsUpdated(oppsUpdatedCount.ToString());
                        }
                        else
                        {
                            int unlucky = rand.Next(0, 100);
                            if (unlucky < 3)
                            {
                                string reason = localize(language, "Reason", null, null, null, false);
                                payload.Values["Closed"] = true;
                                payload.Values["CloseProbability"] = 0;
                                payload.Values["ActualClose"] = DateTime.Now;
                                payload.Values["Win"] = false;
                                payload.Values["Reason"] = reason;
                                switch (language)
                                {
                                    case "English":
                                        payload.Values["Status"] = "Closed - Lost";
                                        break;
                                    case "Chinese":
                                        payload.Values["Status"] = "关闭 - 失落";
                                        break;
                                }

                                entry.SetSDataPayload(payload);

                                SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
                                {
                                    ResourceKind = "opportunities",
                                    Entry = entry
                                };

                                request.Update();
                                float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                                float timed = (after - previous) / 1000;
                                Log(DateTime.Now + " - Updated Opp with loss: " + payload.Values["Description"]  + " - " + timed + " seconds", fileName);
                                Debug.WriteLine("Updated Opp with loss: " + payload.Values["Description"]);
                                oppsUpdatedCount++;
                                SetOppsUpdated(oppsUpdatedCount.ToString());
                                return;
                            }
                            // Add an activity to the opportunity
                            makeActivityFor(payload);
                            Log(DateTime.Now + " - Activity made for: " + payload.Values["Description"], fileName);
                            Debug.WriteLine("Activity made for: " + payload.Values["Description"]);
                        }
                    }
                }
            }
            catch (Exception e) { 
                Log(e.ToString(), fileName); 
            }
        }
コード例 #5
0
ファイル: Bot.cs プロジェクト: rjledger/Demo-Bot
        // Functional, updated to include transitions between stages...
        public void updateSpecificOpportunity()
        {
            Sage.SData.Client.Atom.AtomEntry entry = null;
            SDataPayload payload = null;
            int counter = 0;
            int counter2 = 0;
            do
            {
                do
                {
                    do
                    {
                        entry = fetchOpportunity();
                    } while (entry == null);
                    counter++;
                    if (counter == 50)
                    {
                        Debug.WriteLine("Unable to locate a valid opportunity.");
                        return;
                    }
                } while (entry == null);
                payload = entry.GetSDataPayload();
                counter2++;
                if (counter2 == 50)
                {
                    Debug.WriteLine("Unable to locate a valid opportunity (second do-while)");
                    return;
                }
            } while (((string)payload.Values["Closed"]) == "true");

            if ((string)payload.Values["CloseProbability"] == 100.ToString())
            {
                string reason = randomReason(true);
                payload.Values["Closed"] = true;
                payload.Values["CloseProbability"] = 100;
                payload.Values["ActualClose"] = DateTime.Now;
                payload.Values["Win"] = true;
                payload.Values["Reason"] = reason;
                payload.Values["Status"] = "Closed - Won";

                entry.SetSDataPayload(payload);

                SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
                {
                    ResourceKind = "opportunities",
                    Entry = entry
                };

                request.Update();

                Debug.WriteLine("Updated: " + payload.Values["Description"]);
                return;
            }
            else
            {

                double choice = 4 * rand.NextDouble();
                if (choice < 1.6)
                {
                    if (choice < .3)
                    {
                        // Close the opportunity (either winning or losing it based on the 'close prob'
                        string percent = payload.Values["CloseProbability"].ToString();
                        int testMyLuck = rand.Next(0, 100);
                        if (testMyLuck <= Convert.ToInt32(percent))
                        {
                            // Winner winner! Close the opportunity with a win.
                            // Is this a service request? Close-win?
                            string reason = randomReason(true);
                            payload.Values["Closed"] = true;
                            payload.Values["CloseProbability"] = 100;
                            payload.Values["ActualClose"] = DateTime.Now;
                            payload.Values["Win"] = true;
                            payload.Values["Reason"] = reason;
                            payload.Values["Status"] = "Closed - Won";

                            entry.SetSDataPayload(payload);

                            SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
                            {
                                ResourceKind = "opportunities",
                                Entry = entry
                            };

                            request.Update();

                            Debug.WriteLine("Updated: " + payload.Values["Description"]);
                            return;
                        }
                        else
                        {
                            // Ruh roh! You lost, close the opportunity with a 'lost' value
                            string reason = randomReason(false);
                            payload.Values["Closed"] = true;
                            payload.Values["CloseProbability"] = 0;
                            payload.Values["ActualClose"] = DateTime.Now;
                            payload.Values["Win"] = false;
                            payload.Values["Reason"] = reason;
                            payload.Values["Status"] = "Closed - Lost";

                            entry.SetSDataPayload(payload);

                            SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
                            {
                                ResourceKind = "opportunities",
                                Entry = entry
                            };

                            request.Update();

                            Debug.WriteLine("Updated: " + payload.Values["Description"]);
                            return;
                        }
                    }
                    else
                    {
                        // Add a note to the opportunity
                        makeNoteFor(payload);
                        Debug.WriteLine("Note made for: " + payload.Values["Description"]);
                        return;
                    }
                }
                else
                {
                    if (choice >= 2.9)
                    {
                        // Updates the sales process
                        progressStage(payload);

                        entry.SetSDataPayload(payload);

                        SDataSingleResourceRequest requested = new SDataSingleResourceRequest(dynamic)
                        {
                            ResourceKind = "opportunities",
                            Entry = entry
                        };
                        requested.Update();
                        Debug.WriteLine("Opportunity: " + payload.Values["Description"] + " moved to the next stage");
                    }
                    else
                    {
                        // Add an activity to the opportunity
                        makeActivityFor(payload);
                        Debug.WriteLine("Activity made for: " + payload.Values["Description"]);
                    }
                }
            }
        }
コード例 #6
0
        private void btnUpdateContact_Click(object sender, EventArgs e)
        {
            try
            {
                var b = new SDataSingleResourceRequest(mydataService);
                b.ResourceKind = "contacts";
                b.ResourceSelector = "'" + slxContact.Id + "'";
                AtomEntry entry = b.Read();
                SDataPayload payload = entry.GetSDataPayload();
                payload.Values["FirstName"] = txtContactFirstName.Text;
                payload.Values["LastName"] = txtContactLastName.Text;
                payload.Values["Title"] = txtContactTitle.Text;

                string wkPhone = txtContactWorkPhone.Text;
                if (!String.IsNullOrEmpty(wkPhone))
                {
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < wkPhone.Length; i++)
                    {
                        if (char.IsLetterOrDigit(wkPhone[i]))
                            sb.Append(wkPhone[i]);
                    }

                    wkPhone = sb.ToString();
                    payload.Values["WorkPhone"] = wkPhone;
                }

                string mPhone = txtContactMobilePhone.Text;
                if (!String.IsNullOrEmpty(mPhone))
                {
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < mPhone.Length; i++)
                    {
                        if (char.IsLetterOrDigit(mPhone[i]))
                            sb.Append(mPhone[i]);
                    }

                    mPhone = sb.ToString();
                    payload.Values["Mobile"] = mPhone;
                }

                b.Entry = entry;
                AtomEntry updatedEnty = b.Update();

                MessageBox.Show("Updates Completed");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }