public override void Refresh()
 {
     try
     {
         _sdataTemplateResourceRequest = new SDataTemplateResourceRequest(Service) {ResourceKind = tbTemplateResourceKind.Text};
         tbTemplateURL.Text = _sdataTemplateResourceRequest.ToString();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#2
0
文件: Bot.cs 项目: rjledger/Demo-Bot
        // Functional
        public void noteFor(SDataPayload opportunityPayload)
        {
            try
            {
                // Initializing the variables used to populate the payload. Each variable gets a value using a random value generator as defined below the creation functions.
                string type = "atNote";
                string category = "Note";
                string description = randomDescriptionGenerator(category);
                SDataPayload key = (SDataPayload)opportunityPayload.Values["Account"];
                SDataSingleResourceRequest getAccount = new SDataSingleResourceRequest(dynamic)
                {
                    ResourceKind = "accounts",
                    ResourceSelector = "'" + key.Key + "'"
                };
                var rawr = getAccount.Read();
                SDataPayload accountPayload = rawr.GetSDataPayload();
                string notes = randomNoteGenerator(category, accountPayload, description);

                int accId = rand.Next(2000);

                SDataTemplateResourceRequest noteHistoryTemplate = new SDataTemplateResourceRequest(dynamic);
                noteHistoryTemplate.ResourceKind = "history";
                Sage.SData.Client.Atom.AtomEntry tempEntry = noteHistoryTemplate.Read();

                SDataPayload payload = tempEntry.GetSDataPayload();
                payload.Values["OpportunityName"] = opportunityPayload.Values["Description"];
                payload.Values["OpportunityId"] = opportunityPayload.Key;
                payload.Values["Type"] = type;
                payload.Values["Category"] = category;
                payload.Values["Description"] = description;
                payload.Values["Notes"] = notes;
                payload.Values["LongNotes"] = notes;
                payload.Values["AccountName"] = accountPayload.Values["AccountName"];
                payload.Values["AccountId"] = accountPayload.Key;
                payload.Values["StartDate"] = DateTimeOffset.Now.ToUniversalTime();
                payload.Values["CompletedDate"] = DateTime.Now.ToUniversalTime();
                if (accountPayload.Values["Contacts"] != null)
                {
                    SDataResourceCollectionRequest contact = new SDataResourceCollectionRequest(dynamic)
                    {
                        ResourceKind = "contacts",
                        QueryValues = { { "where", "Account.Id eq '" + accountPayload.Key + "'" } }
                    };
                    var feed = contact.Read();
                    SDataPayload contactPayload = null;
                    if (feed.Entries.Count() != 0)
                    {
                        foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                        {
                            contactPayload = entry.GetSDataPayload();
                            break;
                        }
                        payload.Values["ContactName"] = contactPayload.Values["Name"];
                        payload.Values["ContactId"] = contactPayload.Key;
                    }
                }

                SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
                {
                    ResourceKind = "history",
                    Entry = tempEntry
                };

                request.Create();
                notesCount++;
                SetNotesCreated(notesCount.ToString());
                Log("Created Note: " + payload.Values["Description"] + "... at time " + DateTime.Now, fileName);
            }
            catch (Exception e)
            {
                Log(e.ToString(),fileName);;
            }
        }
示例#3
0
文件: Bot.cs 项目: rjledger/Demo-Bot
        // Not utilized in this build, was a POC that did not get implemented/was found to be unnecessary upon creation of
        // a viable UI for the program.
        #region Spreadsheet Data Creation
        // Functions that create entries into the database.
        public void note(List<string> write)
        {
            try
            {
                // Initializing the variables used to populate the payload. Each variable gets a value using a random value generator as defined below the creation functions.
                string type = "atNote";
                string category = "Note";
                //string description = randomDescriptionGenerator(category);
                SDataPayload accountPayload = null;
                int i = 0;
                do
                {
                    accountPayload = fetchAccount();
                    i++;
                } while (accountPayload == null && i < 50);

                if (i == 50)
                    return;
                //string notes = randomNoteGenerator(category, accountPayload, description);

                int accId = rand.Next(2000);

                SDataTemplateResourceRequest noteHistoryTemplate = new SDataTemplateResourceRequest(dynamic);
                noteHistoryTemplate.ResourceKind = "history";
                Sage.SData.Client.Atom.AtomEntry tempEntry = noteHistoryTemplate.Read();

                SDataPayload payload = tempEntry.GetSDataPayload();
                payload.Values["Type"] = type;
                payload.Values["Category"] = category;
                payload.Values["Description"] = write[3];
                payload.Values["Notes"] = write[2];
                payload.Values["LongNotes"] = write[3];
                payload.Values["AccountName"] = accountPayload.Values["AccountName"];
                payload.Values["AccountId"] = accountPayload.Key;

                // Checks if there is an associated contact with the account.
                if (accountPayload.Values["Contacts"] != null)
                {
                    SDataResourceCollectionRequest contact = new SDataResourceCollectionRequest(dynamic)
                    {
                        ResourceKind = "contacts",
                        QueryValues = { { "where", "Account.Id eq '" + accountPayload.Key + "'" } }
                    };
                    var feed = contact.Read();
                    SDataPayload contactPayload = null;
                    if (feed.Entries.Count() != 0)
                    {
                        foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                        {
                            contactPayload = entry.GetSDataPayload();
                            break;
                        }
                        payload.Values["ContactName"] = contactPayload.Values["Name"];
                        payload.Values["ContactId"] = contactPayload.Key;
                    }
                }

                // Checks if there is an associated opportunity with the account, similar to how the contact was found.
                if (accountPayload.Values["Opportunities"] != null)
                {
                    SDataResourceCollectionRequest opp = new SDataResourceCollectionRequest(dynamic)
                    {
                        ResourceKind = "opportunities",
                        QueryValues = { { "where", "Account.Id eq '" + accountPayload.Key + "'" } }
                    };
                    var feed = opp.Read();
                    SDataPayload oppPayload = null;
                    if (feed.Entries.Count() != 0)
                    {
                        foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                        {
                            oppPayload = entry.GetSDataPayload();
                            break;
                        }
                        payload.Values["OpportunityName"] = oppPayload.Values["Description"];
                        payload.Values["OpportunityId"] = oppPayload.Key;
                    }
                }

                // Checks if there is an associated ticket with the account, similar to how the contact was found.
                if (accountPayload.Values["Tickets"] != null)
                {
                    SDataResourceCollectionRequest tick = new SDataResourceCollectionRequest(dynamic)
                    {
                        ResourceKind = "tickets",
                        QueryValues = { { "where", "Account.Id eq '" + accountPayload.Key + "'" } }
                    };
                    var feed = tick.Read();
                    SDataPayload ticketPayload = null;
                    if (feed.Entries.Count() != 0)
                    {
                        foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                        {
                            ticketPayload = entry.GetSDataPayload();
                            break;
                        }
                        payload.Values["TicketNumber"] = ticketPayload.Values["TicketNumber"];
                        payload.Values["TicketId"] = ticketPayload.Key;
                    }
                }
                payload.Values["StartDate"] = DateTimeOffset.Now.ToUniversalTime();
                payload.Values["CompletedDate"] = DateTime.Now.ToUniversalTime();

                SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
                {
                    ResourceKind = "history",
                    Entry = tempEntry
                };

                request.Create();
                notesCount++;
                SetNotesCreated(notesCount.ToString());
                Log("Created Note: " + payload.Values["Description"] + "... at time " + DateTime.Now, fileName);
            }
            catch (Exception e)
            {
                Log(e.ToString(),fileName);;
            }

        }
示例#4
0
文件: Bot.cs 项目: rjledger/Demo-Bot
        // 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); 
            }
        }
示例#5
0
文件: Bot.cs 项目: rjledger/Demo-Bot
        // Functional
        public void makeTicket()
        {
            try
            {
                float previous = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                SDataTemplateResourceRequest ticketTemplate = new SDataTemplateResourceRequest(dynamic);
                ticketTemplate.ResourceKind = "tickets";

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

                SDataPayload accountPayload = null;
                int j = 0;
                do
                {
                    accountPayload = fetchAccount();
                    j++;
                } while (accountPayload == null && j < 50);
                //accountPayload.Values["UserField1"] = UserID;
                if (j == 50)
                    return;

                // Only need account name for the payload to be complete
                payload.Values["Account"] = accountPayload;
                try
                {
                    if (accountPayload.Values["Contacts"] != null)
                    {
                        SDataResourceCollectionRequest contact = new SDataResourceCollectionRequest(dynamic)
                        {
                            ResourceKind = "contacts",
                            QueryValues = { { "where", "Account.Id eq '" + accountPayload.Key + "'" } }
                        };
                        var feed = contact.Read();
                        SDataPayload contactPayload = null;
                        if (feed.Entries.Count() != 0)
                        {
                            foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                            {
                                contactPayload = entry.GetSDataPayload();
                                break;
                            }
                            payload.Values["Contact"] = contactPayload;
                        }
                    }
                    else
                    {
                        int i = rand.Next(0, 150);
                        SDataResourceCollectionRequest contact = new SDataResourceCollectionRequest(dynamic)
                        {
                            ResourceKind = "contacts",
                            QueryValues = { { "startIndex", i.ToString() } }
                        };
                        var feed = contact.Read();
                        SDataPayload contactPayload = null;
                        if (feed.Entries.Count() != 0)
                        {
                            foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                            {
                                contactPayload = entry.GetSDataPayload();
                                break;
                            }
                            payload.Values["Contact"] = contactPayload;
                        }
                    }
                }
                catch (Exception e)
                {
                    Log(e.ToString(), fileName);
                }

                tempEntry.SetSDataPayload(payload);

                SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
                {
                    ResourceKind = "tickets",
                    Entry = tempEntry
                };
                request.Create();
                float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                float timed = (after - previous) / 1000;
                Log(DateTime.Now + " - Created ticket number: " + accountPayload.Values["AccountName"] +  " - " + timed + " seconds", fileName);
                ticketsCount++;
                SetTicketsCreated(ticketsCount.ToString());
            }
            catch (Exception e) { 
                Log(e.ToString(), fileName); 
            }

        }
示例#6
0
文件: Bot.cs 项目: rjledger/Demo-Bot
        // Functional
        public void lead()
        {
            SDataTemplateResourceRequest leadsTemplate = new SDataTemplateResourceRequest(dynamic);
            leadsTemplate.ResourceKind = "leads";

            bool checker = true;
            string firstName = "";
            string lastName = "";

            Sage.SData.Client.Atom.AtomEntry tempEntry = leadsTemplate.Read();
            SDataPayload payload = tempEntry.GetSDataPayload();
            // Checks to see if there is a lead with that name already created
            do
            {
                firstName = GetFakeFirstName();
                lastName = GetFakeLastName();
                SDataResourceCollectionRequest check = new SDataResourceCollectionRequest(dynamic)
                {
                    ResourceKind = "contacts",
                    QueryValues = { { "where", "LastName eq '" + lastName + "'" } }
                };
                var feed = check.Read();
                foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                {
                    SDataPayload tempPayload = entry.GetSDataPayload();
                    if ((string)tempPayload.Values["FirstName"] == firstName)
                    {
                        checker = true;
                        break;
                    }
                    else
                        checker = false;
                }
            } while (checker);

            string emailProvider = "gmail";
            int temp = rand.Next(0, 4);
            switch (temp)
            {
                case 0:
                    emailProvider = "yahoo";
                    break;
                case 1:
                    emailProvider = "gmail";
                    break;
                case 2:
                    emailProvider = "mail";
                    break;
                case 3:
                    emailProvider = "me";
                    break;
                default:
                    emailProvider = "hotmail";
                    break;

            }
            string phone = rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString();
            payload.Values["CreateUser"] = UserID;
            payload.Values["CreateDate"] = DateTime.Now.ToUniversalTime();
            payload.Values["Company"] = GetFakeCompanyName();
            payload.Values["Email"] = firstName.ToLower() + lastName.ToLower() + "@" + emailProvider + ".com";
            payload.Values["FirstName"] = firstName;
            payload.Values["LastName"] = lastName;
            payload.Values["LastNameUpper"] = lastName.ToUpper();
            payload.Values["Mobile"] = phone;
            payload.Values["LeadNameFirstLast"] = firstName + " " + lastName;
            payload.Values["LeadNameLastFirst"] = lastName + ", " + firstName;

            SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
            {
                ResourceKind = "leads",
                Entry = tempEntry
            };

            /*SDataServiceOperationRequest request = new SDataServiceOperationRequest(service)
            {
                ResourceKind = "leads",
                //OperationName = "Save",
                Entry = tempEntry
            }; */
            request.Create();
            Debug.WriteLine(payload.Values["Company"] + ", " + payload.Values["LeadNameFirstLast"]);
            leadsCount++;
                // In this case the notes created label becomes the leads generated label
            SetLeadsCreated(leadsCount.ToString());
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            // SDataTemplateResourceRequest needs .Core so I have a using.
            SDataTemplateResourceRequest req = new SDataTemplateResourceRequest(_service);
            req.ResourceKind = "contacts";
            //AtomEntry needs Sage.SData.Client.Atom so I added a using
            AtomEntry entry = req.Read();
            var contact = entry.GetSDataPayload();

            //get rid of these guys since we do not want to set them.
            contact.Values.Remove("CreateDate");
            contact.Values.Remove("CreateUser");
            contact.Values.Remove("ModifyDate");
            contact.Values.Remove("ModifyUser");

            contact.Values["Account"] = GetEntityPayload("accounts", "AA2EK0013031");
            contact.Values["Email"] = "*****@*****.**";
            contact.Values["FirstName"] = "Jason";
            contact.Values["LastName"] = "Huber";

            //removing the address, but you would want it, and it would be another payload like account....
               //payload.Values.Remove("Address");

            //updated to go and get a new address template and get it in there..

               SDataPayload address = GetEntityTemplate("addresses");

               address.Values["Description"] = "SalesLogix/Act Office";
               address.Values["Address1"] = "8800 n. Gainey Center Drive";
               address.Values["City"] = "Scottsdale";
               address.Values["State"] = "AZ";

               contact.Values["Address"] = address;
            //payload.Values["Description"] = txtProjectDesc.Text;
            //payload.Values["StartDate"] = Convert.ToDateTime(dtStartDate.Text).ToString("yyyy-MM-dd");
            //payload.Values["EndDate"] = Convert.ToDateTime(dtEndDate.Text).ToString("yyyy-MM-dd");

            //now we can send the entry in.
            //need to go and get the task, then update it, then send it back.
            Sage.SData.Client.Core.SDataSingleResourceRequest rcu = new Sage.SData.Client.Core.SDataSingleResourceRequest(_service);

            rcu.ResourceKind = "contacts";
            rcu.Entry = entry;
            try
            {
                AtomEntry result = rcu.Create();
                //the result here should be 201 instead of 200 because it is a create.
                //http://interop.sage.com/daisy/sdata/CreateOperation/ErrorHandling.html

                if (result.GetSDataHttpStatus() == System.Net.HttpStatusCode.Created)
                {
                    MessageBox.Show("I added the contact!");
                }
                else
                {
                    MessageBox.Show("Insert Failed. /n" + result.GetSDataHttpMessage());
                }
            }
            catch (Exception 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
        }
示例#9
0
文件: Bot.cs 项目: rjledger/Demo-Bot
        // Functional
        public SDataPayload makeAccountWithName(string accountName)
        {
            try
            {
                float previous = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                SDataTemplateResourceRequest accountTemplate = new SDataTemplateResourceRequest(dynamic);
                accountTemplate.ResourceKind = "accounts";
                Sage.SData.Client.Atom.AtomEntry tempEntry = accountTemplate.Read();
                SDataPayload payload = tempEntry.GetSDataPayload();

                payload.Values["AccountName"] = accountName;
                payload.Values["AccountNameUpper"] = accountName.ToUpper();
                payload.Values["CreateDate"] = DateTime.Now;
                payload.Values["CreateUser"] = UserID;
                payload.Values["Type"] = localize(language, "Account Type", null, null, null, true);
                payload.Values["Status"] = localize(language, "Account Status", null, null, null, true);

                tempEntry.SetSDataPayload(payload);

                /*SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
                {
                    ResourceKind = "accounts",
                    Entry = tempEntry
                };
                request.Create(); */
                float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                float timed = (after - previous) / 1000;
                accountsCount++;
                SetAccountsCreated(accountsCount.ToString());
                Log(DateTime.Now + " - Created new account: " + payload.Values["AccountName"] +  " - " + timed + " seconds", fileName);
                return payload;
            }
            catch { return null; }
        }
示例#10
0
文件: Bot.cs 项目: rjledger/Demo-Bot
        // Functional
        public void makeAccount()
        {
            try
            {
                float previous = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                SDataTemplateResourceRequest accountTemplate = new SDataTemplateResourceRequest(dynamic);
                accountTemplate.ResourceKind = "accounts";
                Sage.SData.Client.Atom.AtomEntry tempEntry = accountTemplate.Read();
                SDataPayload payload = tempEntry.GetSDataPayload();
                bool checker = false;
                string accountName = "";

                do
                {
                    accountName = localize(language, "Fake Company Name", null, null, null, true);
                    try
                    {
                        SDataResourceCollectionRequest check = new SDataResourceCollectionRequest(dynamic)
                        {
                            ResourceKind = "accounts",
                            QueryValues = { { "where", "AccountNameUpper eq '" + accountName.ToUpper() + "'" } }
                        };
                        var feed = check.Read();
                        if (feed.Entries.Count() == 0)
                            checker = false;
                        else
                            checker = true;
                    }
                    catch (Exception e) { 
                        Log(e.ToString(),fileName);
                    }
                } while (checker == true);

                payload.Values["AccountName"] = accountName;
                payload.Values["AccountNameUpper"] = accountName.ToUpper();
                payload.Values["CreateDate"] = DateTime.Now;
                payload.Values["CreateUser"] = UserID;
                payload.Values["Type"] = localize(language, "Account Type", null, null, null, true);
                payload.Values["Status"] = localize(language, "Account Status", null, null, null, true);

                tempEntry.SetSDataPayload(payload);

                SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
                {
                    ResourceKind = "accounts",
                    Entry = tempEntry
                };
                request.Create();
                float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                float timed = (after - previous) / 1000;
                accountsCount++;
                SetAccountsCreated(accountsCount.ToString());
                Log(DateTime.Now + " - Created new account: " + payload.Values["AccountName"] + " - " + timed + " seconds", fileName);
            }
            catch (Exception e) { 
                Log(e.ToString(),fileName);
            }
        }
示例#11
0
文件: Bot.cs 项目: rjledger/Demo-Bot
        // Functional
        public void makeActivityFor(SDataPayload opportunityPayload)
        {
            try
            {
                float previous = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                // Initializing the variables used to populate the payload. Each variable gets a value using a random value generator as defined below the creation functions.
                string temp = localize(language, "Type Generator", null, null, null, true);
                string category = localize(language, "Category Generator", null, temp, null, true);
                string description = localize(language, "Description Generator", null, temp, null, true);
                string type = "at" + temp;
                string location = localize(language, "Location Generator", null, temp, null, true);
                DateTime startTime = randomDateGenerator();
                string priority = localize(language, "Priority Generator", null, null, null, true);
                SDataPayload key = (SDataPayload)opportunityPayload.Values["Account"];
                SDataSingleResourceRequest getAccount = new SDataSingleResourceRequest(dynamic)
                {
                    ResourceKind = "accounts",
                    ResourceSelector = "'" + key.Key + "'"
                };
                var rawr = getAccount.Read();
                SDataPayload accountPayload = rawr.GetSDataPayload();
                string notes = randomNoteGenerator(temp, accountPayload, description);
                DateTime alarm = startTime.AddMinutes(-15);
                DateTime duration;

                SDataTemplateResourceRequest activityTemplate = new SDataTemplateResourceRequest(service);
                activityTemplate.ResourceKind = "activities";
                Sage.SData.Client.Atom.AtomEntry tempEntry = activityTemplate.Read();

                SDataPayload payload = tempEntry.GetSDataPayload();

                payload.Values["OpportunityName"] = opportunityPayload.Values["Description"];
                payload.Values["OpportunityId"] = opportunityPayload.Key;
                payload.Values["Type"] = type;
                payload.Values["Category"] = category;
                // Get the program to query the server for the contact name, account name, and retrieve the respective ids for each.
                payload.Values["AccountName"] = accountPayload.Values["AccountName"];
                payload.Values["AccountId"] = accountPayload.Key;
                payload.Values["Description"] = description;
                //payload.Values["Duration"] = "15 minutes";
                payload.Values["StartDate"] = startTime;
                payload.Values["Location"] = location;
                payload.Values["Priority"] = priority;
                payload.Values["LongNotes"] = notes;
                payload.Values["Notes"] = notes;
                payload.Values["AlarmTime"] = alarm;
                

                tempEntry.SetSDataPayload(payload);

                SDataSingleResourceRequest request = new SDataSingleResourceRequest(service)
                {
                    ResourceKind = "activities",
                    Entry = tempEntry
                };

                //Creating the entry...
                request.Create();
                float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                float timed = (after - previous) / 1000;
                activitiesCount++;
                SetActivitiesCreated(activitiesCount.ToString());
                Log(DateTime.Now + " - Created Activity: " + payload.Values["Type"] +  " - " + timed + " seconds", fileName);
            }
            catch (Exception e)
            {
                Log(e.ToString(),fileName);;
            }
        }
示例#12
0
文件: Bot.cs 项目: rjledger/Demo-Bot
        // Functional
        public void makeActivity()
        {
            try
            {
                float previous = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                // Initializing the variables used to populate the payload. Each variable gets a value using a random value
                // generator as defined below the creation functions.
                string temp = localize(language, "Type Generator", null, null, null, true);
                string category = localize(language, "Category Generator", null, temp, null, true);
                string description = localize(language, "Description Generator", null, temp, null, true);
                string type = "at" + temp;
                string location = localize(language, "Location Generator", null, temp, null, true);
                DateTime startTime = randomDateGenerator();
                string priority = localize(language, "Priority Generator", null, null, null, true);
                SDataPayload accountPayload = null;
                int i = 0;
                do
                {
                    accountPayload = fetchAccount();
                    i++;
                } while (accountPayload == null && i < 50);

                if (i == 50)
                    return;

                string notes = randomNoteGenerator(temp, accountPayload, description);
                DateTime alarm = startTime.AddMinutes(-15);

                SDataTemplateResourceRequest activityTemplate = new SDataTemplateResourceRequest(service);
                activityTemplate.ResourceKind = "activities";
                Sage.SData.Client.Atom.AtomEntry tempEntry = activityTemplate.Read();

                SDataPayload payload = tempEntry.GetSDataPayload();

                payload.Values["Type"] = type;
                payload.Values["Category"] = category;
                // Get the program to query the server for the contact name, account name, and retrieve the respective ids for each.
                payload.Values["AccountName"] = accountPayload.Values["AccountName"];
                payload.Values["AccountId"] = accountPayload.Key;
                // Checks to make sure there is a contact associated with the account, and if so calls a request to get the payload
                // associated to that contact; then filling in payload.Values
                if (accountPayload.Values["Contacts"] != null)
                {
                    SDataResourceCollectionRequest contact = new SDataResourceCollectionRequest(dynamic)
                    {
                        ResourceKind = "contacts",
                        QueryValues = { { "where", "Account.Id eq '" + accountPayload.Key + "'" } }
                    };
                    var feed = contact.Read();
                    SDataPayload contactPayload = null;
                    if (feed.Entries.Count() != 0)
                    {
                        foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                        {
                            contactPayload = entry.GetSDataPayload();
                            break;
                        }
                        payload.Values["ContactName"] = contactPayload.Values["Name"];
                        payload.Values["ContactId"] = contactPayload.Key;
                    }
                }

                if (temp != "Personal")
                {
                    // Checks if there is an associated opportunity with the account, similar to how the contact was found.
                    if (accountPayload.Values["Opportunities"] != null)
                    {
                        SDataResourceCollectionRequest opp = new SDataResourceCollectionRequest(dynamic)
                        {
                            ResourceKind = "opportunities",
                            QueryValues = { { "where", "Account.Id eq '" + accountPayload.Key + "'" } }
                        };
                        var feed = opp.Read();
                        SDataPayload oppPayload = null;
                        if (feed.Entries.Count() != 0)
                        {
                            foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                            {
                                oppPayload = entry.GetSDataPayload();
                                break;
                            }
                            payload.Values["OpportunityName"] = oppPayload.Values["Description"];
                            payload.Values["OpportunityId"] = oppPayload.Key;
                        }
                    }

                    // Checks if there is an associated ticket with the account, similar to how the contact was found.
                    if (accountPayload.Values["Tickets"] != null)
                    {
                        SDataResourceCollectionRequest tick = new SDataResourceCollectionRequest(dynamic)
                        {
                            ResourceKind = "tickets",
                            QueryValues = { { "where", "Account.Id eq '" + accountPayload.Key + "'" } }
                        };
                        var feed = tick.Read();
                        SDataPayload ticketPayload = null;
                        if (feed.Entries.Count() != 0)
                        {
                            foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                            {
                                ticketPayload = entry.GetSDataPayload();
                                break;
                            }
                            payload.Values["TicketNumber"] = ticketPayload.Values["TicketNumber"];
                            payload.Values["TicketId"] = ticketPayload.Key;
                        }
                    }
                }
                payload.Values["Description"] = description;
                payload.Values["StartDate"] = startTime;
                payload.Values["Location"] = location;
                payload.Values["Priority"] = priority;
                payload.Values["LongNotes"] = notes;
                payload.Values["Notes"] = notes;
                payload.Values["AlarmTime"] = alarm;

                tempEntry.SetSDataPayload(payload);

                SDataSingleResourceRequest request = new SDataSingleResourceRequest(service)
                {
                    ResourceKind = "activities",
                    Entry = tempEntry
                };

                //Creating the entry...
                request.Create();
                float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                float timed = (after - previous) / 1000;
                activitiesCount++;
                SetActivitiesCreated(activitiesCount.ToString());
                Log(DateTime.Now + " - Created Activity: " + payload.Values["Type"] + " - " + timed + " seconds", fileName);
            }
            catch (Exception e)
            {
                Log(e.ToString(),fileName);;
            }
   
        }
示例#13
0
文件: Bot.cs 项目: rjledger/Demo-Bot
        // 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"]);
            }


        }
示例#14
0
文件: Bot.cs 项目: rjledger/Demo-Bot
        // Functional
        public void ticket()
        {
            SDataTemplateResourceRequest ticketTemplate = new SDataTemplateResourceRequest(dynamic);
            ticketTemplate.ResourceKind = "tickets";

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

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

            if (i == 50)
                return;

            //accountPayload.Values["UserField1"] = UserID;

            // Only need account name for the payload to be complete
            payload.Values["Account"] = accountPayload;
            try
            {
                if (accountPayload.Values["Contacts"] != null)
                {
                    SDataResourceCollectionRequest contact = new SDataResourceCollectionRequest(dynamic)
                    {
                        ResourceKind = "contacts",
                        QueryValues = { { "where", "Account.Id eq '" + accountPayload.Key + "'" } }
                    };
                    var feed = contact.Read();
                    SDataPayload contactPayload = null;
                    if (feed.Entries.Count() != 0)
                    {
                        foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                        {
                            contactPayload = entry.GetSDataPayload();
                            break;
                        }
                        payload.Values["Contact"] = contactPayload;
                    }
                }
            }
            catch (Exception e)
            {
                Log(e.ToString(),fileName);;
            }

            tempEntry.SetSDataPayload(payload);

            SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
            {
                ResourceKind = "tickets",
                Entry = tempEntry
            };
            request.Create();
            //Sage.SData.Client.Atom.AtomEntry ent = request.Read();
            //SDataPayload tempLoad = ent.GetSDataPayload();
            Debug.WriteLine("Created ticket number: " + accountPayload.Values["AccountName"]);
            ticketsCount++;
            // in this case notes created is for tickets for helper and for ticker maker
            SetNotesCreated(ticketsCount.ToString());
            //SDataServiceOperationRequest

        }
示例#15
0
文件: Bot.cs 项目: rjledger/Demo-Bot
        // 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"]);
        }
示例#16
0
文件: Bot.cs 项目: rjledger/Demo-Bot
        // Functional
        public void activity(List<string> write)
        {
            try
            {
                SDataTemplateResourceRequest activityTemplate = new SDataTemplateResourceRequest(service);
                activityTemplate.ResourceKind = "activities";
                Sage.SData.Client.Atom.AtomEntry tempEntry = activityTemplate.Read();

                SDataPayload payload = tempEntry.GetSDataPayload();

                payload.Values["Type"] = write[1];
                
                /*
                payload.Values["Category"] = category;
                // Get the program to query the server for the contact name, account name, and retrieve the respective ids for each.
                payload.Values["AccountName"] = accountPayload.Values["AccountName"];
                payload.Values["AccountId"] = accountPayload.Key;
                // Checks to make sure there is a contact associated with the account, and if so calls a request to get the payload associated to that contact; then filling in payload.Values
                if (accountPayload.Values["Contacts"] != null)
                {
                    SDataResourceCollectionRequest contact = new SDataResourceCollectionRequest(dynamic)
                    {
                        ResourceKind = "contacts",
                        QueryValues = { { "where", "Account.Id eq '" + accountPayload.Key + "'" } }
                    };
                    var feed = contact.Read();
                    SDataPayload contactPayload = null;
                    if (feed.Entries.Count() != 0)
                    {
                        foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                        {
                            contactPayload = entry.GetSDataPayload();
                            break;
                        }
                        payload.Values["ContactName"] = contactPayload.Values["Name"];
                        payload.Values["ContactId"] = contactPayload.Key;
                    }
                }

                if (temp != "Personal")
                {
                    // Checks if there is an associated opportunity with the account, similar to how the contact was found.
                    if (accountPayload.Values["Opportunities"] != null)
                    {
                        SDataResourceCollectionRequest opp = new SDataResourceCollectionRequest(dynamic)
                        {
                            ResourceKind = "opportunities",
                            QueryValues = { { "where", "Account.Id eq '" + accountPayload.Key + "'" } }
                        };
                        var feed = opp.Read();
                        SDataPayload oppPayload = null;
                        if (feed.Entries.Count() != 0)
                        {
                            foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                            {
                                oppPayload = entry.GetSDataPayload();
                                break;
                            }
                            payload.Values["OpportunityName"] = oppPayload.Values["Description"];
                            payload.Values["OpportunityId"] = oppPayload.Key;
                        }
                    }

                    // Checks if there is an associated ticket with the account, similar to how the contact was found.
                    if (accountPayload.Values["Tickets"] != null)
                    {
                        SDataResourceCollectionRequest tick = new SDataResourceCollectionRequest(dynamic)
                        {
                            ResourceKind = "tickets",
                            QueryValues = { { "where", "Account.Id eq '" + accountPayload.Key + "'" } }
                        };
                        var feed = tick.Read();
                        SDataPayload ticketPayload = null;
                        if (feed.Entries.Count() != 0)
                        {
                            foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                            {
                                ticketPayload = entry.GetSDataPayload();
                                break;
                            }
                            payload.Values["TicketNumber"] = ticketPayload.Values["TicketNumber"];
                            payload.Values["TicketId"] = ticketPayload.Key;
                        }
                    }
                }
                payload.Values["Description"] = description;
                //payload.Values["Duration"] = "15 minutes";
                payload.Values["StartDate"] = startTime;
                payload.Values["Location"] = location;
                payload.Values["Priority"] = priority;
                payload.Values["LongNotes"] = notes;
                payload.Values["Notes"] = notes;
                payload.Values["AlarmTime"] = alarm;

                tempEntry.SetSDataPayload(payload);

                SDataSingleResourceRequest request = new SDataSingleResourceRequest(service)
                {
                    ResourceKind = "activities",
                    Entry = tempEntry
                };

                //Creating the entry...
                request.Create();
                activitiesCount++;
                SetActivitiesCreated(activitiesCount.ToString());
                 * */
            }
            catch (Exception e)
            {
                Log(e.ToString(),fileName);;
            }
                
        }
示例#17
0
文件: Bot.cs 项目: rjledger/Demo-Bot
        // Functional
        public void activityFor(SDataPayload opportunityPayload)
        {
            try
            {
                // Initializing the variables used to populate the payload. Each variable gets a value using a random value generator as defined below the creation functions.
                string temp = randomTypeGenerator();
                string category = randomCategoryGenerator(temp);
                string description = randomDescriptionGenerator(temp);
                //if (temp == "ToDo" && (description != "Send proposal" || description != "Send quote"))
                //{ temp = todoDecoder(description); }
                string type = "at" + temp;
                string location = randomLocationGenerator(temp);
                DateTime startTime = randomDateGenerator();
                string priority = randomPriorityGenerator();
                SDataPayload key = (SDataPayload)opportunityPayload.Values["Account"];
                SDataSingleResourceRequest getAccount = new SDataSingleResourceRequest(dynamic)
                {
                    ResourceKind = "accounts",
                    ResourceSelector = "'" + key.Key + "'"
                };
                var rawr = getAccount.Read();
                SDataPayload accountPayload = rawr.GetSDataPayload();
                string notes = randomNoteGenerator(temp, accountPayload, description);
                DateTime alarm = startTime.AddMinutes(-15);
                DateTime duration;

                SDataTemplateResourceRequest activityTemplate = new SDataTemplateResourceRequest(service);
                activityTemplate.ResourceKind = "activities";
                Sage.SData.Client.Atom.AtomEntry tempEntry = activityTemplate.Read();

                SDataPayload payload = tempEntry.GetSDataPayload();

                payload.Values["OpportunityName"] = opportunityPayload.Values["Description"];
                payload.Values["OpportunityId"] = opportunityPayload.Key;
                payload.Values["Type"] = type;
                payload.Values["Category"] = category;
                // Get the program to query the server for the contact name, account name, and retrieve the respective ids for each.
                payload.Values["AccountName"] = accountPayload.Values["AccountName"];
                payload.Values["AccountId"] = accountPayload.Key;
                payload.Values["Description"] = description;
                //payload.Values["Duration"] = "15 minutes";
                payload.Values["StartDate"] = startTime;
                payload.Values["Location"] = location;
                payload.Values["Priority"] = priority;
                payload.Values["LongNotes"] = notes;
                payload.Values["Notes"] = notes;
                payload.Values["AlarmTime"] = alarm;


                tempEntry.SetSDataPayload(payload);

                SDataSingleResourceRequest request = new SDataSingleResourceRequest(service)
                {
                    ResourceKind = "activities",
                    Entry = tempEntry
                };

                //Creating the entry...
                request.Create();
                activitiesCount++;
                //SetActivitiesCreated(activitiesCount.ToString());
            }
            catch (Exception e)
            {
                Log(e.ToString(),fileName);;
            }
        }
示例#18
0
文件: Bot.cs 项目: rjledger/Demo-Bot
        // Functional
        public void makeContact()
        {
            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();
                SDataPayload accountPayload = null;
                int i = 0;
                do
                {
                    accountPayload = fetchAccount();
                    i++;
                } while (accountPayload == null && i < 50);

                if (i == 50)
                    return;

                string firstName = localize(language, "Fake First Name", null, null, null, true);
                string lastName = localize(language, "Fake Last Name", null, null, null, true);

                if (accountPayload.Values["Contacts"] != null)
                {
                    SDataResourceCollectionRequest contact = new SDataResourceCollectionRequest(dynamic)
                        {
                            ResourceKind = "contacts",
                            QueryValues = { { "where", "Account.Id eq '" + accountPayload.Key + "'" } }
                        };
                    var feed = contact.Read();
                    SDataPayload contactPayload = null;
                    if (feed.Entries.Count() != 0)
                    {
                        foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                        {
                            contactPayload = entry.GetSDataPayload();
                            if (contactPayload.Values["FirstName"] == firstName && contactPayload.Values["LastName"] == lastName)
                            {
                                do
                                {
                                    firstName = localize(language, "Fake First Name", null, null, null, true);
                                    lastName = localize(language, "Fake Last Name", null, null, null, true);
                                } while (contactPayload.Values["FirstName"] == firstName && contactPayload.Values["LastName"] == lastName);
                            }

                        }
                    }
                }

                string emailProvider = "gmail";
                int temp = rand.Next(0, 4);
                switch (temp)
                {
                    case 0:
                        emailProvider = "yahoo";
                        break;
                    case 1:
                        emailProvider = "gmail";
                        break;
                    case 2:
                        emailProvider = "mail";
                        break;
                    case 3:
                        emailProvider = "me";
                        break;
                    default:
                        emailProvider = "hotmail";
                        break;
                }

                payload.Values["FirstName"] = firstName;
                payload.Values["LastName"] = lastName;
                payload.Values["LastNameUpper"] = lastName.ToUpper();
                payload.Values["NameLF"] = lastName + ", " + firstName;
                payload.Values["Name"] = firstName + " " + lastName;
                payload.Values["FullName"] = lastName + " , " + firstName;
                payload.Values["NamePFL"] = " " + firstName + " " + lastName;
                payload.Values["IsPrimary"] = false;
                payload.Values["Salutation"] = firstName;
                payload.Values["AccountName"] = accountPayload.Values["AccountName"];
                payload.Values["Account"] = accountPayload;
                payload.Values["CreateDate"] = DateTime.Now;
                payload.Values["ModifyDate"] = DateTime.Now;
                payload.Values["ModifyUser"] = UserID;
                payload.Values["CreateUser"] = UserID;
                payload.Values["Email"] = firstName + lastName + "@" + emailProvider + ".com";
                string phone = rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString() + 
                    rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString() + 
                    rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString();
                payload.Values["WorkPhone"] = phone;
                payload.Values["Mobile"] = phone;
                payload.Values["DoNotEmail"] = false;
                payload.Values["DoNotFax"] = false;
                payload.Values["DoNotMail"] = false;
                payload.Values["DoNotPhone"] = false;
                payload.Values["DoNotSolicit"] = false;
                payload.Values["IsServiceAuthorized"] = false;
                payload.Values["WebAddress"] = accountPayload.Values["WebAddress"];
                payload.Values["Status"] = "Active";
                payload.Values["Address"] = new SDataPayload
                                        {
                                            ResourceName = "addresses",
                                            Values = {
                                            {"Description", "Office"},
                                            {"CreateDate", DateTime.Now},
                                            {"CreateUser", UserID},
                                            {"IsMailing", true},
                                            {"IsPrimary", true},
                                            {"AddressType", "Billing &amp; Shipping"}
                                        }
                                        };

                payload.Values["Description"] = accountPayload.Values["Description"];
                payload.Values["PreferredContact"] = "Unknown";

                tempEntry.SetSDataPayload(payload);

                SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
                {
                    ResourceKind = "contacts",
                    Entry = tempEntry
                };
                request.Create();
                float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                float timed = (after - previous) / 1000;
                contactsCount++;
                SetContactsCreated(contactsCount.ToString());
                Log(DateTime.Now + " - Created contact: " + payload.Values["Name"] +  " - " + timed + " seconds", fileName);
            }
            catch (Exception e) {
                Log(e.ToString(), fileName);
            }

        }
 private SDataPayload GetEntityTemplate(string entitytypename)
 {
     // SDataTemplateResourceRequest needs .Core so I have a using.
     SDataTemplateResourceRequest req = new SDataTemplateResourceRequest(_service);
     req.ResourceKind = entitytypename;
     //AtomEntry needs Sage.SData.Client.Atom so I added a using
     AtomEntry entry = req.Read();
     return  entry.GetSDataPayload();
 }
示例#20
0
文件: Bot.cs 项目: rjledger/Demo-Bot
        // Functional
        public void makeLead()
        {
            try
            {
                float previous = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                SDataTemplateResourceRequest leadsTemplate = new SDataTemplateResourceRequest(dynamic);
                leadsTemplate.ResourceKind = "leads";

                bool checker = true;
                string firstName = "";
                string lastName = "";

                Sage.SData.Client.Atom.AtomEntry tempEntry = leadsTemplate.Read();
                SDataPayload payload = tempEntry.GetSDataPayload();
                // Checks to see if there is a lead with that name already created
                do
                {
                    firstName = localize(language, "Fake First Name", null, null, null, true);
                    lastName = localize(language, "Fake Last Name", null, null, null, true);
                    SDataResourceCollectionRequest check = new SDataResourceCollectionRequest(dynamic)
                    {
                        ResourceKind = "contacts",
                        QueryValues = { { "where", "LastName eq '" + lastName + "'" } }
                    };
                    var feed = check.Read();
                    foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                    {
                        SDataPayload tempPayload = entry.GetSDataPayload();
                        if ((string)tempPayload.Values["FirstName"] == firstName)
                        {
                            checker = true;
                            break;
                        }
                        else
                            checker = false;
                    }
                } while (checker);

                string emailProvider = "gmail";
                int temp = rand.Next(0, 4);
                switch (temp)
                {
                    case 0:
                        emailProvider = "yahoo";
                        break;
                    case 1:
                        emailProvider = "gmail";
                        break;
                    case 2:
                        emailProvider = "mail";
                        break;
                    case 3:
                        emailProvider = "me";
                        break;
                    default:
                        emailProvider = "hotmail";
                        break;

                }
                string phone = rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString()
                    + rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString()
                    + rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString();
                payload.Values["CreateUser"] = UserID;
                payload.Values["CreateDate"] = DateTime.Now.ToUniversalTime();
                payload.Values["Company"] = localize(language, "Fake Company Name", null, null, null, true);
                payload.Values["Email"] = firstName.ToLower() + lastName.ToLower() + "@" + emailProvider + ".com";
                payload.Values["FirstName"] = firstName;
                payload.Values["LastName"] = lastName;
                payload.Values["LastNameUpper"] = lastName.ToUpper();
                payload.Values["Mobile"] = phone;
                payload.Values["LeadNameFirstLast"] = firstName + " " + lastName;
                payload.Values["LeadNameLastFirst"] = lastName + ", " + firstName;

                SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
                {
                    ResourceKind = "leads",
                    Entry = tempEntry
                };

                request.Create();
                float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                float timed = (after - previous) / 1000;
                Log(DateTime.Now + " - Created lead: " + payload.Values["Company"] + ", " + payload.Values["LeadNameFirstLast"] + " - " + timed + " seconds", fileName);
                leadsCount++;
                SetLeadsCreated(leadsCount.ToString());
            }
            catch (Exception e) { 
                Log(e.ToString(), fileName); 
            }
        }
示例#21
0
文件: Bot.cs 项目: rjledger/Demo-Bot
        // 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); 
            }
        }
示例#22
0
文件: Bot.cs 项目: rjledger/Demo-Bot
        // Needs help!
        public void contact()
        {
            SDataTemplateResourceRequest contactTemplate = new SDataTemplateResourceRequest(dynamic);
            contactTemplate.ResourceKind = "contacts";
            Sage.SData.Client.Atom.AtomEntry tempEntry = contactTemplate.Read();
            SDataPayload payload = tempEntry.GetSDataPayload();
            SDataPayload accountPayload = null;
            int i = 0;
            do
            {
                accountPayload = fetchAccount();
                i++;
            } while (accountPayload == null && i < 50);

            if (i == 50)
                return;

            string firstName = GetFakeFirstName();
            string lastName = GetFakeLastName();

            if (accountPayload.Values["Contacts"] != null)
            {
                SDataResourceCollectionRequest contact = new SDataResourceCollectionRequest(dynamic)
                {
                    ResourceKind = "contacts",
                    QueryValues = { { "where", "Account.Id eq '" + accountPayload.Key + "'" } }
                };
                var feed = contact.Read();
                SDataPayload contactPayload = null;
                if (feed.Entries.Count() != 0)
                {
                    foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                    {
                        contactPayload = entry.GetSDataPayload();
                        if (contactPayload.Values["FirstName"] == firstName && contactPayload.Values["LastName"] == lastName)
                        {
                            do
                            {
                                firstName = GetFakeFirstName();
                                lastName = GetFakeLastName();
                            } while (contactPayload.Values["FirstName"] == firstName && contactPayload.Values["LastName"] == lastName);
                        }

                    }
                    payload.Values["FirstName"] = firstName;
                    payload.Values["LastName"] = lastName;
                    payload.Values["LastNameUpper"] = lastName.ToUpper();
                    payload.Values["NameLF"] = lastName + ", " + firstName;
                    payload.Values["Name"] = firstName + " " + lastName;
                    payload.Values["FullName"] = lastName + " , " + firstName;
                    payload.Values["NamePFL"] = " " + firstName + " " + lastName;
                }
            }
            string emailProvider = "gmail";
            int temp = rand.Next(0, 4);
            switch (temp)
            {
                case 0:
                    emailProvider = "yahoo";
                    break;
                case 1:
                    emailProvider = "gmail";
                    break;
                case 2:
                    emailProvider = "mail";
                    break;
                case 3:
                    emailProvider = "me";
                    break;
                default:
                    emailProvider = "hotmail";
                    break;
            }

            payload.Values["AccountName"] = accountPayload.Values["AccountName"];
            payload.Values["Account"] = accountPayload;
            payload.Values["CreateDate"] = DateTime.Now;
            payload.Values["CreateUser"] = UserID;
            payload.Values["Email"] = firstName + lastName + "@" + emailProvider + ".com";
            string phone = rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString() + rand.Next(9).ToString();
            payload.Values["WorkPhone"] = phone;
            payload.Values["Mobile"] = phone;
            payload.Values["DoNotEmail"] = false;
            payload.Values["DoNotFax"] = false;
            payload.Values["DoNotMail"] = false;
            payload.Values["DoNotPhone"] = false;
            payload.Values["DoNotSolicit"] = false;
            payload.Values["IsServiceAuthorized"] = false;
            payload.Values["IsPrimary"] = false;
            payload.Values["Status"] = "Active";
            payload.Values["Owner"] = "Everyone";
            payload.Values["PreferredContact"] = "Unknown";


            tempEntry.SetSDataPayload(payload);

            SDataSingleResourceRequest request = new SDataSingleResourceRequest(dynamic)
            {
                ResourceKind = "contacts",
                Entry = tempEntry
            };
            request.Create();
            Log("Created contact: " + payload.Values["Name"], fileName);

        }