コード例 #1
0
    public static string GetId(string userName)
    {
        try
            {
                ISDataService mydataService = SDataDataService.mydataService();

                SDataResourceCollectionRequest mydataCollection = new SDataResourceCollectionRequest(mydataService);
                mydataCollection.ResourceKind = "Users";
                mydataCollection.QueryValues.Add("where", "UserName eq '" + userName + "'");
                AtomFeed usersFeed = mydataCollection.Read();
                string userId = string.Empty;

                if (usersFeed.Entries.Count() > 0)
                {
                    foreach (AtomEntry entry in usersFeed.Entries)
                    {
                        string tempURI = entry.Id.Uri.AbsoluteUri;
                        userId = tempURI.Substring(tempURI.IndexOf("'") + 1, tempURI.LastIndexOf("'") - tempURI.IndexOf("'") - 1);
                        break;
                    }
                }

                return userId;
            }
            catch (Exception ex)
            {
                return null;
            }
    }
コード例 #2
0
        public void AtomFeedReader_Verify_CanRead()
        {
            var request = new SDataResourceCollectionRequest(_service);
            _mock.Setup(s => s.ReadFeed(request)).Returns(TestData.Feed);

            var reader = request.ExecuteReader();
            Expect(reader, Is.Not.Null);
        }
        public void ResourceCollection_Verify_CanRead()
        {
            var request = new SDataResourceCollectionRequest(_service) {ResourceKind = "employees"};
            _mock.Setup(s => s.ReadFeed(request)).Returns(TestData.Feed);

            var feed = request.Read();
            Expect(feed, Is.Not.Null);
        }
コード例 #4
0
        private void LoadOpportunities()
        {
            try
            {
                ISDataService service;
                service = SDataDataService.mydataService();

                SDataResourceCollectionRequest oppoContactsCollection = new SDataResourceCollectionRequest(service);

                oppoContactsCollection.ResourceKind = "opportunitycontacts";
                oppoContactsCollection.QueryValues.Add("where", "Contact.Id eq '" + id + "'");

                AtomFeed oppoContactsFeed = oppoContactsCollection.Read();

                if (oppoContactsFeed.Entries.Count() > 0)
                {

                    DataTable table = new DataTable();

                    table.Columns.Add("Id");
                    table.Columns.Add("Description");

                    foreach (AtomEntry entry in oppoContactsFeed.Entries)
                    {
                        SDataPayload oppoContact = entry.GetSDataPayload();

                        SDataPayload tempOppo = (SDataPayload)oppoContact.Values["Opportunity"];

                        SDataSingleResourceRequest oppo = new SDataSingleResourceRequest(service);

                        oppo.ResourceKind = "Opportunities";

                        oppo.ResourceSelector = "('" + tempOppo.Key + "')";

                        AtomEntry oppoEnty = oppo.Read();

                        SDataPayload opportunitiy = (SDataPayload)oppoEnty.GetSDataPayload();

                        DataRow dr = table.NewRow();

                        dr[0] = opportunitiy.Key.ToString();
                        dr[1] = opportunitiy.Values["Description"].ToString();

                        table.Rows.Add(dr);
                    }

                    grdOpportunities.DataSource = table;
                    grdOpportunities.Columns[2].Visible = false;
                    grdOpportunities.Refresh();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 public void ResourceCollection_Verify_ToStringWithQuery()
 {
     var request = new SDataResourceCollectionRequest(_service)
                   {
                       ResourceKind = "employees",
                       QueryValues = {{"where", "gender eq m"}}
                   };
     var url = request.ToString();
     Expect(url, Is.EqualTo("http://localhost:59213/sdata/aw/dynamic/-/employees?where=gender eq m"));
 }
コード例 #6
0
ファイル: SDataConnection.cs プロジェクト: gokuger/SDataTest
        public SDataConnection(String url, String user, String password)
        {
            this.url = url;
            this.user = user;
            this.password = password;

            ISDataService service = new SDataService(url, user, password);
            var request = new SDataResourceCollectionRequest(service);
            this.request = request;
        }
コード例 #7
0
    public static string GetId(string userName)
    {
        try
            {
                ISDataService mydataService = SDataDataService.mydataService();
                string ownerId = string.Empty;

                SDataResourceCollectionRequest mydataCollection = new SDataResourceCollectionRequest(mydataService);
                mydataCollection.ResourceKind = "Users";
                mydataCollection.QueryValues.Add("where", "UserName eq '" + userName + "'");
                AtomFeed usersFeed = mydataCollection.Read();
                string userId = string.Empty;

                if (usersFeed.Entries.Count() > 0)
                {
                    foreach (AtomEntry entry in usersFeed.Entries)
                    {
                        SDataPayload payLoad = entry.GetSDataPayload();
                        string tempURI = entry.Id.Uri.AbsoluteUri;
                        userId = tempURI.Substring(tempURI.IndexOf("'") + 1, tempURI.LastIndexOf("'") - tempURI.IndexOf("'") - 1);
                        break;
                    }
                }

                mydataCollection = null;
                mydataCollection = new SDataResourceCollectionRequest(mydataService);
                mydataCollection.ResourceKind = "Owners";
                AtomFeed ownersFeed = mydataCollection.Read();

                if (ownersFeed.Entries.Count() > 0)
                {
                    foreach (AtomEntry entry in ownersFeed.Entries)
                    {
                        SDataPayload payLoad = entry.GetSDataPayload();
                        SDataPayload userPayload = (SDataPayload)payLoad.Values["User"];

                        if (userPayload != null)
                        {
                            if (userPayload.Key == userId)
                            {
                                ownerId = payLoad.Key;
                                break;
                            }
                        }

                    }
                }

                return ownerId;
            }
            catch (Exception ex)
            {
                return null;
            }
    }
 public void ResourceCollection_Verify_ToStringWithPaging()
 {
     var request = new SDataResourceCollectionRequest(_service)
                   {
                       ResourceKind = "employees",
                       StartIndex = 1,
                       Count = 100
                   };
     var url = request.ToString();
     Expect(url, Is.EqualTo("http://localhost:59213/sdata/aw/dynamic/-/employees?startIndex=1&count=100"));
 }
コード例 #9
0
        public void AtomFeedReader_EnumeratorMatchesIndexer()
        {
            var request = new SDataResourceCollectionRequest(_service);
            _mock.Setup(s => s.ReadFeed(request)).Returns(TestData.Feed);

            var reader = request.ExecuteReader();
            var i = 0;

            foreach (var entry in reader)
            {
                Expect(entry, Is.EqualTo(reader[i]));
                i++;
            }
        }
コード例 #10
0
        public void AtomFeedReader_IndexerMatchesCurrent()
        {
            var request = new SDataResourceCollectionRequest(_service);
            _mock.Setup(s => s.ReadFeed(request)).Returns(TestData.Feed);

            var reader = request.ExecuteReader();

            for (var i = 0; i < reader.Count; i++)
            {
                Expect(i, Is.EqualTo(reader.CurrentIndex));
                Expect(reader[i], Is.EqualTo(reader.Current));
                reader.MoveNext();
            }

            Expect(!reader.MoveNext());
        }
コード例 #11
0
        public void AtomFeedReader_CurrentMatchesEnumerator()
        {
            var request = new SDataResourceCollectionRequest(_service);
            _mock.Setup(s => s.ReadFeed(request)).Returns(TestData.Feed);

            var reader = request.ExecuteReader();
            var enumerator = reader.GetEnumerator();

            do
            {
                enumerator.MoveNext();
                Expect(reader.Current, Is.EqualTo(enumerator.Current));
            } while (reader.MoveNext());

            Expect(!enumerator.MoveNext());
        }
コード例 #12
0
        private void cmdTest_Click(object sender, EventArgs e)
        {
            try
            {
                string userName = txtUserName.Text;
                string password = txtPassword.Text;
                string url = txtSdata.Text;

                string temp = txtSdata.Text.Substring(txtSdata.Text.Length - 1, 1);

                if (temp == "/")
                {
                    url += "sdata/slx/dynamic/-/";
                }
                else
                {
                    url += "/sdata/slx/dynamic/-/";
                }

                ISDataService service;
                service = new SDataService(url, userName, password);

                SDataResourceCollectionRequest sdataCollection = new SDataResourceCollectionRequest(service);

                sdataCollection.ResourceKind = "Accounts";

                AtomFeed accountFeed = sdataCollection.Read();

                if (accountFeed.Entries.Count() > 0)
                {
                    MessageBox.Show("Test Successful");
                }
            }
            catch (SDataClientException ex)
            {
                MessageBox.Show(ex.InnerException.Message);
            }
        }
コード例 #13
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); 
            }

        }
 public void ResourceCollection_Verify_CanConstruct()
 {
     var request = new SDataResourceCollectionRequest(_service);
     Expect(request, Is.Not.Null);
 }
コード例 #15
0
        private void UpdateCollection()
        {
            try
            {
                _sdataResourceCollectionRequest = new SDataResourceCollectionRequest(Service)
                                                  {
                                                      ResourceKind = tbCollectionResourceKind.Text,
                                                      StartIndex = (int) numStartIndex.Value,
                                                      Count = (int) numCount.Value
                                                  };
                _feed = _sdataResourceCollectionRequest.Read();
                _reader = null;

                var lookup = _feed.Links.ToLookup(link => link.Relation);
                btnFirst.Enabled = lookup["first"].Any();
                btnPrevious.Enabled = lookup["previous"].Any();
                btnNext.Enabled = lookup["next"].Any();
                btnLast.Enabled = lookup["last"].Any();

                var table = new DataTable();
                table.Columns.Add("Author");
                table.Columns.Add("Id");
                table.Columns.Add("Title");

                // iterate through the list of entries in the feed
                foreach (var atomentry in _feed.Entries)
                {
                    var dr = table.NewRow();
                    dr[0] = atomentry.Authors.Select(author => author.Name).FirstOrDefault();
                    dr[1] = atomentry.Id.Uri.AbsoluteUri;
                    dr[2] = atomentry.Title.Content;

                    table.Rows.Add(dr);
                }

                // show it in the grid
                atomEntryGrid.DataSource = table;
                atomEntryGrid.Refresh();
                atomEntryGrid.AutoResizeColumns();

                if (atomEntryGrid.SelectedRows.Count != 0)
                {
                    atomEntryGrid_CellContentClick(null, null);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #16
0
        private void btnReaderRead_Click(object sender, EventArgs e)
        {
            try
            {
                _sdataResourceCollectionRequest = new SDataResourceCollectionRequest(Service)
                                                  {
                                                      ResourceKind = tbCollectionResourceKind.Text,
                                                      StartIndex = (int) numStartIndex.Value,
                                                      Count = (int) numCount.Value
                                                  };

                _feed = null;
                _reader = _sdataResourceCollectionRequest.ExecuteReader();

                tbReaderCount.Text = _reader.Count.ToString();

                UpdateReaderGrid();
            }
            catch (SDataClientException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #17
0
ファイル: Bot.cs プロジェクト: rjledger/Demo-Bot
        // Functional
        public void completeActivity()
        {
            try
            {
                // Initiates a value to keep track of amount of activities created.
                int i = 0;
                float previous = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;

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

                // From the Whitepaper pdf to get the user payload
                var getUserRequest = new SDataServiceOperationRequest(service)
                { OperationName = "getCurrentUser", 
                 Entry = new Sage.SData.Client.Atom.AtomEntry() }; 
                 var temp = getUserRequest.Create();
                 var userPayload = temp.GetSDataPayload();
                 userPayload = (SDataPayload)userPayload.Values["response"];

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

                var feed = activities.Read();

                // From the Whitepaper pdf to get the user payload
                //var getUserRequest = new SDataServiceOperationRequest(service)
                //{ OperationName = "getCurrentUser", 
                // Entry = new Sage.SData.Client.Atom.AtomEntry() }; 
                // var temp = getUserRequest.Create();
                // var userPayload = temp.GetSDataPayload();
                // userPayload = (SDataPayload)userPayload.Values["response"];
                // var user = userPayload.Values["userName"];
                // string userID = user.ToString().ToLower();


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

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


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

                            if (activityCompleteAmount == i)
                                break;

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

                }
            }
            catch (ArgumentNullException e)
            {
                Log(e.ToString(), fileName);
            }
        }
コード例 #18
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); 
            }
        }
コード例 #19
0
ファイル: Bot.cs プロジェクト: rjledger/Demo-Bot
        private Sage.SData.Client.Atom.AtomEntry fetchLead()
        {
            Random rand = new Random();
            int i = rand.Next(250);
            Sage.SData.Client.Atom.AtomEntry tempEntry = null;

            try
            {
                SDataResourceCollectionRequest leads = new SDataResourceCollectionRequest(dynamic)
                {
                    ResourceKind = "leads",
                    QueryValues = { { "startIndex", i.ToString() } }
                };

                var feed = leads.Read();
                foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                {
                    tempEntry = entry;
                    break;
                }
            }
            catch (Exception e)
            {
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileName, true))
                                {
                                    file.WriteLine(e);
                                }
                //Log(e.ToString(),fileName);;
                SetText("Connection to server lost... Please check your connection");
                //this.stop();
            }

            return tempEntry;
        }
コード例 #20
0
        private string EmailSearch(string address, string entity)
        {
            try
            {
                mydataService = SDataDataService.mydataService();

                mydataCollection = new SDataResourceCollectionRequest(mydataService);
                mydataCollection.ResourceKind = entity;
                mydataCollection.QueryValues.Add("where", "Email eq '" + address + "'");
                AtomFeed contactfeed = mydataCollection.Read();
                string contactId;

                if (contactfeed.Entries.Count() > 0)
                {
                    foreach (AtomEntry entry in contactfeed.Entries)
                    {
                        string tempURI = entry.Id.Uri.AbsoluteUri;
                        contactId = tempURI.Substring(tempURI.IndexOf("'") + 1, tempURI.LastIndexOf("'") - tempURI.IndexOf("'") - 1);
                        return contactId;
                    }
                }

                return null;
            }
            catch (System.Exception ex)
            {
                return null;
            }
        }
コード例 #21
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);
            }

        }
コード例 #22
0
        /// <summary>
        /// Initialises a new instance of the <see cref="AtomFeedReader"/> class.
        /// </summary>
        /// <param name="request">The request used to fetch pages of feed entries.</param>
        internal AtomFeedReader(SDataResourceCollectionRequest request)
        {
            Guard.ArgumentNotNull(request, "request");

            _request = request;
        }
コード例 #23
0
        private static void Main()
        {
            var service = new SDataService();

            // set user name to authenticate with
            service.UserName = "******";
            // set password to authenticate with
            service.Password = "";

            service.Protocol = "HTTP";
            service.ServerName = "sdata.acme.com";
            service.ApplicationName = "sageApp";
            service.VirtualDirectory = "sdata";

            AtomFeed feed;
            AtomEntry entry;
            SDataPayload payload;

            #region CREATE an Entry

            // read the template for accounts
            var tru1 = new SDataTemplateResourceRequest(service);
            tru1.ContractName = "test";
            tru1.ResourceKind = "accounts";
            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts/$template 

            // read the entry from the server
            entry = service.ReadEntry(tru1);

            // TODO: Make changes to the entry payload
            payload = entry.GetSDataPayload();

            var sru1 = new SDataSingleResourceRequest(service);
            sru1.ContractName = "test";
            sru1.ResourceKind = "accounts";

            var newEntry = service.CreateEntry(sru1, entry);

            #endregion

            #region CREATE a BATCH Operaton (Synchronous)

            // create the BatchURL
            var sbu = new SDataBatchRequest(service);
            sbu.ContractName = "test";
            sbu.ResourceKind = "products";
            // the configuration above generates http://sdata.acme.com/sageApp/test/-/products/$batch 

            using (var batch = new SDataBatchRequest(service))
            {
                // read the template for accounts
                var templateResourceRequest = new SDataTemplateResourceRequest(service);
                templateResourceRequest.ContractName = "test";
                templateResourceRequest.ResourceKind = "accounts";
                // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts/$template 

                // read the entry from the server
                var templateEntry = service.ReadEntry(templateResourceRequest);

                var insertRequest = new SDataSingleResourceRequest(service);
                insertRequest.ContractName = "test";
                insertRequest.ResourceKind = "accounts";

                // do some stuff with the entry

                service.CreateEntry(insertRequest, templateEntry);

                // build, submit and get
                var result = batch.Commit();
            }

            #endregion

            #region CREATE a BATCH Operation (Asynchronous)

            // create the BatchURL
            sbu = new SDataBatchRequest(service);
            sbu.ContractName = "test";
            sbu.ResourceKind = "products";

            // the configuration above generates http://sdata.acme.com/sageApp/test/-/products/$batch 

            using (var batch = new SDataBatchRequest(service))
            {
                // read the template for accounts
                var templateResourceRequest = new SDataTemplateResourceRequest(service);
                templateResourceRequest.ContractName = "test";
                templateResourceRequest.ResourceKind = "accounts";
                // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts/$template 

                // read the entry from the server
                var templateEntry = service.ReadEntry(templateResourceRequest);

                var insertRequest = new SDataSingleResourceRequest(service);
                insertRequest.ContractName = "test";
                insertRequest.ResourceKind = "accounts";

                // do some stuff with the entry

                var request = batch.CreateAsync();
                ISyndicationResource result;

                // wait around until the response is ready
                do
                {
                    var progress = request.Progress;
                } while ((result = request.Refresh()) == null);

                feed = result as AtomFeed;
            }

            #endregion

            #region READ a Resource Collection Feed

            // Read a Resource Collection Feed
            var rcu = new SDataResourceCollectionRequest(service);
            rcu.ContractName = "test";
            rcu.DataSet = "prod";
            rcu.ResourceKind = "accounts";

            // pageing
            rcu.StartIndex = 21;
            rcu.Count = 10;

            // query
            rcu.QueryValues.Add("where", "accountid='123456789abc'");
            rcu.QueryValues.Add("orderby", "'account'");

            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/prod/accounts?startIndex=21&count=10 
            // Read the feed from the server
            feed = service.ReadFeed(rcu);

            #endregion

            #region READ a Single Resource Entry

            // Read a Single Resource Entry
            var sru = new SDataSingleResourceRequest(service);
            sru.ContractName = "test";
            sru.ResourceKind = "accounts";
            sru.ResourceSelector = "'A001'";
            // the above configuration generates  http://sdata.acme.com/sdata/sageApp/test/-/accounts('A001') 

            // read the entry from the server
            entry = service.ReadEntry(sru);

            #endregion

            #region READ a Resource Property

            var rpu = new SDataResourcePropertyRequest(service);
            rpu.ContractName = "test";
            rpu.ResourceKind = "accounts";
            rpu.ResourceSelector = "'A001'";
            rpu.ResourceProperties.Add("postalAddress");
            rpu.ResourceProperties.Add("country");
            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/accounts('A001')/postalAddress/country

            // read the entry from the server
            entry = service.ReadEntry(rpu);

            // now reconfigure and read property as a feed
            rpu.ResourceProperties.Add("salesOrders('0023')");
            rpu.ResourceProperties.Add("orderLines");
            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts('A001')/salesOrders('0023')/orderLines

            // read the feed from the server
            service.ReadFeed(rpu);

            #endregion

            #region READ a Template Resource

            var tru = new SDataTemplateResourceRequest(service);
            tru.ContractName = "test";
            tru.ResourceKind = "accounts";
            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts/$template 

            // read the entry from the server
            entry = service.ReadEntry(tru);

            #endregion

            #region READ a Resource Schema

            var rsu = new SDataResourceSchemaRequest(service);
            rsu.ContractName = "test";
            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/$schema

            // read the feed from the server
            var schema = service.ReadSchema(rsu);

            // now reconfigurate and set resource kind and version
            rsu.ResourceKind = "accounts";
            rsu.Version = "5";
            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts/$schema?version=5

            // read the entry from the server
            schema = service.ReadSchema(rsu);

            #endregion

            #region READ System Resources or Services

            var su = new SDataSystemRequest(service);

            // the above configuration generates http://sdata.acme.com/sdata/$system
            // read the feed from the server
            service.ReadFeed(su);

            #endregion

            #region READ Intermediate URLS

            #region READ Enumeration of Applications

            var iau = new IntermediateApplicationsRequest(service);

            // the above configuration generates http://sdata.acme.com/sdata

            // read the feed from the server
            service.ReadFeed(iau);

            #endregion

            #region READ Enumeration of DataSets

            var idu = new IntermediateDataSetsRequest(service);
            // the above configuration generates http://sdata.acme.com/sdata/sageApp

            // read the feed from the server
            feed = service.ReadFeed(idu);

            #endregion

            #region READ Enumeration of Contracts

            var icu = new IntermediateContractsRequest(service);

            // the above configuration generates http://sdata.acme.com/sdata/sageApp

            // read the feed from the server
            feed = service.ReadFeed(icu);

            #endregion

            #region READ Enumeration of Resource Collections

            var ircu = new IntermediateResourceCollectionsRequest(service);
            ircu.ContractName = "test";
            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test

            // read the feed from the server
            feed = service.ReadFeed(ircu);

            #endregion

            #region READ Enumeration of Services

            var isu = new IntermediateServicesRequest(service);
            isu.ContractName = "test";
            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/$service

            // read the feed from the server
            service.ReadFeed(isu);

            // reconfigure and set the resource kind
            isu.ResourceKind = "accounts";
            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/accounts/$service
            // read the feed from the server
            service.ReadFeed(isu);

            #endregion

            #endregion

            #region Update an Entry

            // Read a Single Resource Entry
            var sru2 = new SDataSingleResourceRequest(service);
            sru2.ContractName = "test";
            sru2.ResourceKind = "accounts";
            sru2.ResourceSelector = "'A001'";
            // the above configuration generates  http://sdata.acme.com/sdata/sageApp/test/accounts('A001') 

            // TODO: Make changes to the entry payload
            payload = newEntry.GetSDataPayload();
            // update the server
            service.UpdateEntry(sru2, newEntry);

            #endregion

            #region DELETE an Entry

            service.DeleteEntry(sru2, newEntry);

            #endregion
        }
コード例 #24
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);;
            }

        }
コード例 #25
0
ファイル: Bot.cs プロジェクト: rjledger/Demo-Bot
        private Sage.SData.Client.Atom.AtomEntry fetchOpportunity()
        {
            Random rand = new Random();
            Sage.SData.Client.Atom.AtomEntry returnEntry = null;
            //SDataPayload payload = null;
            int i = rand.Next(100);

            try
            {
                SDataResourceCollectionRequest opportunities = new SDataResourceCollectionRequest(dynamic)
                {
                    ResourceKind = "opportunities",
                    QueryValues = { {"where", "Status eq 'Open'"} , { "startIndex", i.ToString() } }
                };

                var feed = opportunities.Read();
                foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                {
                    if (entry != null)
                    {
                        returnEntry = entry;
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileName, true))
                                {
                                    file.WriteLine(e);
                                }
                //Log(e.ToString(),fileName);;
                SetText("Connection to server lost... Please check your connection");
                //this.stop();
            }

            return returnEntry;
        }
コード例 #26
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); 
            }
        }
コード例 #27
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);;
            }
        }
コード例 #28
0
        private bool testSettings()
        {
            try
            {

                string userName = Properties.Settings.Default.UserName;
                string password = Properties.Settings.Default.Password;
                string url = Properties.Settings.Default.SDATA;

                if (String.IsNullOrEmpty(userName) || String.IsNullOrEmpty(url))
                {
                    return false;
                }

                string temp = url.Substring(url.Length - 1, 1);

                if (temp == "/")
                {
                    url += "sdata/slx/dynamic/-/";
                }
                else
                {
                    url += "/sdata/slx/dynamic/-/";
                }

                ISDataService service;
                service = new SDataService(url, userName, password);

                SDataResourceCollectionRequest sdataCollection = new SDataResourceCollectionRequest(service);

                sdataCollection.ResourceKind = "Accounts";

                AtomFeed accountFeed = sdataCollection.Read();

                if (accountFeed.Entries.Count() > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (SDataClientException ex)
            {
                return false;
            }
        }
コード例 #29
0
ファイル: Bot.cs プロジェクト: rjledger/Demo-Bot
        private SDataPayload fetchLeadSource()
        {
            Random rand = new Random();
            int i = rand.Next(0, 8);
            SDataPayload payload = null;

            try
            {
                SDataResourceCollectionRequest leadSources = new SDataResourceCollectionRequest(dynamic)
                {
                    ResourceKind = "leadSources",
                    QueryValues = { { "startIndex", i.ToString() } }
                    //QueryValues = { { "orderBy", "StartDate" } }
                };

                var feed = leadSources.Read();
                foreach (Sage.SData.Client.Atom.AtomEntry entry in feed.Entries)
                {
                    payload = entry.GetSDataPayload();
                    if (payload != null)
                    {
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileName, true))
                                {
                                    file.WriteLine(e);
                                }
                //Log(e.ToString(), fileName);
                SetText("Connection to server lost... Please check your connection");
                //this.stop();
            }

            return payload;
        }
コード例 #30
0
        public void AtomFeedReader_MultiPageEnumerator()
        {
            var page1 = new AtomFeed();
            var page2 = new AtomFeed();

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(Resources.TestFeed)))
            {
                page1.Load(stream);
                stream.Seek(0, SeekOrigin.Begin);
                page2.Load(stream);
            }

            page1.SetOpenSearchStartIndex(1);
            page1.SetOpenSearchItemsPerPage(1);
            ((IList<AtomEntry>) page1.Entries).RemoveAt(1);

            page2.SetOpenSearchStartIndex(2);
            page2.SetOpenSearchItemsPerPage(1);
            ((IList<AtomEntry>) page2.Entries).RemoveAt(0);

            var pages = new Stack<AtomFeed>(new[] {page2, page1});

            var request = new SDataResourceCollectionRequest(_service);
            _mock.Setup(s => s.ReadFeed(request)).Returns(pages.Pop).AtMost(2);

            var reader = request.ExecuteReader();
            reader.ToList();
        }
コード例 #31
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);
            }
        }