public void SingleResource_Verify_CanCreate()
        {
            var request = new SDataSingleResourceRequest(_service) {ResourceKind = "employees"};

            var payload = new SDataPayload();
            payload.Values["Title"] = "create 1";
            payload.Values["NationalIdNumber"] = "44444";
            payload.Values["LoginId"] = "create 4";
            payload.Values["ContactId"] = "9999";
            payload.Values["BirthDate"] = SyndicationDateTimeUtility.ToRfc3339DateTime(new DateTime(1970, 8, 2));
            payload.Values["HireDate"] = SyndicationDateTimeUtility.ToRfc3339DateTime(DateTime.Now);
            payload.Values["ModifiedDate"] = SyndicationDateTimeUtility.ToRfc3339DateTime(DateTime.Now);
            payload.Values["MaritalStatus"] = "Single";
            payload.Values["SalariedFlag"] = XmlConvert.ToString(true);
            payload.Values["CurrentFlag"] = XmlConvert.ToString(true);
            payload.Values["Gender"] = "Male";
            payload.Values["RowGuid"] = Guid.NewGuid().ToString();

            var entry = new AtomEntry
                        {
                            UpdatedOn = DateTime.Now,
                            PublishedOn = DateTime.Now
                        };
            entry.SetSDataPayload(payload);
            request.Entry = entry;
            _mock.Setup(s => s.CreateEntry(request, request.Entry)).Returns(TestData.Entry);

            entry = request.Create();
            Expect(entry, Is.Not.Null);
        }
        private void ContactFound_Load(object sender, EventArgs e)
        {
            try
            {
                if (!String.IsNullOrEmpty(contactId))
                {
                    mydataService = SDataDataService.mydataService();

                    SDataSingleResourceRequest mydataSingleRequest;
                    mydataSingleRequest = new SDataSingleResourceRequest(mydataService);
                    mydataSingleRequest.ResourceKind = "Contacts";
                    mydataSingleRequest.ResourceSelector = "('" + contactId + "')";
                    AtomEntry myContact = mydataSingleRequest.Read();
                    mydataSingleRequest.Entry = myContact;

                    payload = mydataSingleRequest.Entry.GetSDataPayload();

                    if (payload != null)
                    {
                        txtAccount.Text = payload.Values["AccountName"].ToString().Trim();
                        txtFirstName.Text = payload.Values["FirstName"].ToString().Trim();
                        txtLastName.Text = payload.Values["LastName"].ToString().Trim();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 private static void WriteItemTo(string name, string ns, object value, XmlWriter writer)
 {
     if (value == null)
     {
         writer.WriteStartElement(name, ns);
         writer.WriteAttributeString("nil", Framework.Common.XSI.Namespace, XmlConvert.ToString(true));
         writer.WriteEndElement();
     }
     else
     {
         writer.WriteElementString(name, ns, SDataPayload.ValueToString(value));
     }
 }
        public static XPathNavigator WritePayload(SDataPayload payload)
        {
            using (var stream = new MemoryStream())
            {
                using (var writer = XmlWriter.Create(stream))
                {
                    payload.WriteTo(writer, Client.Framework.Common.Atom.Namespace);
                }

                stream.Seek(0, SeekOrigin.Begin);
                return new XPathDocument(stream).CreateNavigator();
            }
        }
        public static SDataPayload LoadPayload(string xml)
        {
            var payload = new SDataPayload();

            using (var strReader = new StringReader(xml))
            using (var xmlReader = XmlReader.Create(strReader))
            {
                var doc = new XPathDocument(xmlReader);
                var source = doc.CreateNavigator();
                var manager = new XmlNamespaceManager(source.NameTable);
                source.MoveToFirstChild();
                payload.Load(source, manager);
            }

            return payload;
        }
Beispiel #6
0
 internal ResourceLocator CreateResource(SDataService ws, String resourceName, IDictionary<String, object> values, string resourceKind = null)
 {
     var sru = new SDataSingleResourceRequest(ws);
     sru.ResourceKind = resourceKind == null ? resourceName.ToLower() + "s" : resourceKind;
     SDataPayload payload = new SDataPayload();
     payload.ResourceName = resourceName;
     payload.Namespace = SDATA_NS;
     sru.Entry = new AtomEntry();
     foreach (KeyValuePair<String, object> kvp in values)
     {
         payload.Values[kvp.Key] = kvp.Value;
     }
     sru.Entry.SetSDataPayload(payload);
     AtomEntry entry = sru.Create();
     payload = entry.GetSDataPayload();
     return new ResourceLocator { Id = payload.Key, ETag = entry.GetSDataHttpETag() };
 }
        private void cmdSave_Click(object sender, EventArgs e)
        {
            try
            {
                ISDataService service;
                service = SDataDataService.mydataService();

                string ownerId = UserNameToOwnerId.GetId(service.UserName);
                string userId = UserNameToId.GetId(service.UserName);

                var entry = new AtomEntry();
                var payload = new SDataPayload
                {
                    ResourceName = "Opportunity",
                    Namespace = "http://schemas.sage.com/dynamic/2007",
                    Values = {
                                {"Description", txtDescription.Text},
                                {"Account", (SDataPayload)contactPayload.Values["Account"]},
                                {"Owner", new SDataPayload{ Key = ownerId, ResourceName="Owner"}},
                                {"AccountManager", new SDataPayload{ Key = userId, ResourceName="AccountManager"}},
                                {"Contacts",
                                    new SDataPayloadCollection {
                                        new SDataPayload {
                                            ResourceName = "OpportunityContact",
                                            Values = {{"Contact",new SDataPayload{ Key = contactPayload.Key}},
                                                      {"IsPrimary","true"}}
                                        }
                                    }
                                }
                             }
                };

                entry.SetSDataPayload(payload);
                var request = new SDataSingleResourceRequest(service, entry) { ResourceKind = "Opportunities" };
                AtomEntry result = request.Create();

                this.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void cmdSave_Click(object sender, EventArgs e)
        {
            try
            {
                ISDataService service;
                service = SDataDataService.mydataService();

                string contactId = contactPayload.Key; ;
                string contactName = contactPayload.Values["FirstName"].ToString().Trim() + " " + contactPayload.Values["LastName"].ToString().Trim();

                SDataPayload accountPayload = (SDataPayload)contactPayload.Values["Account"];
                string accountId = accountPayload.Key;
                string accountName = contactPayload.Values["AccountName"].ToString().Trim();

                var entry = new AtomEntry();
                var payload = new SDataPayload
                {
                    ResourceName = "Activity",
                    Namespace = "http://schemas.sage.com/dynamic/2007",
                    Values = {
                    {"AccountId", accountId},
                    //{"AccountName", accountName},
                    {"ContactId", contactId},
                    {"Description", txtRegarding.Text}
                    }
                };

                entry.SetSDataPayload(payload);
                var request = new SDataSingleResourceRequest(service, entry) { ResourceKind = "Activities" };
                AtomEntry result = request.Create();

                if (result != null)
                {
                    //MessageBox.Show("Acctivity created");
                }

                this.Close();

            }
            catch (SDataClientException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void cmdSave_Click(object sender, EventArgs e)
        {
            try
            {
                ISDataService service;
                service = SDataDataService.mydataService();

                string ownerId = UserNameToOwnerId.GetId(service.UserName);

                var entry = new AtomEntry();
                var payload = new SDataPayload
                {
                    ResourceName = "Ticket",
                    Namespace = "http://schemas.sage.com/dynamic/2007",
                    Values = {
                    {"Account", (SDataPayload)contactPayload.Values["Account"]},
                    {"Contact", contactPayload},//,
                                {"AssignedTo", new SDataPayload{ Key = ownerId, ResourceName="Owner"}},
                                //{"Issue",txtSubject.Text},
                                {"TicketProblem", new SDataPayload{
                                    ResourceName="TicketProblem",
                                    Values = {
                                        {"Notes",txtSubject.Text}
                                    }
                                }
                                }
                    }
                };

                entry.SetSDataPayload(payload);
                var request = new SDataSingleResourceRequest(service, entry) { ResourceKind = "Tickets" };
                AtomEntry result = request.Create();

                this.Close();

            }
            catch (SDataClientException ex)
            {
                //MessageBox.Show(ex.Message);
                //Getting object reference error and have no idea why
                //Everything is created just fine and is working though still get error
                this.Close();
            }
        }
    public static string Create(string oppoId, string contactId)
    {
        try
            {
                ISDataService service;
                service = SDataDataService.mydataService();

                var entry = new AtomEntry();
                var payload = new SDataPayload
                {
                    ResourceName = "OpportunityContact",
                    Namespace = "http://schemas.sage.com/dynamic/2007",
                    Values = {
                                {"Contact", new SDataPayload{ Key = contactId, ResourceName="Contact"}},
                                {"Opportunity", new SDataPayload{ Key = oppoId, ResourceName="Opportunity"}}
                             }
                };

                entry.SetSDataPayload(payload);
                var request = new SDataSingleResourceRequest(service, entry) { ResourceKind = "OpportunityContacts" };
                AtomEntry result = request.Create();

                if (result != null)
                {
                    return result.Id.ToString();
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
    }
        private void cmdSave_Click(object sender, EventArgs e)
        {
            try
            {
                ISDataService service;
                service = SDataDataService.mydataService();

                var entry = new AtomEntry();
                var payload = new SDataPayload
                {
                    ResourceName = "Account",
                    Namespace = "http://schemas.sage.com/dynamic/2007",
                    Values = {
                        {"AccountName", txtAccount.Text},
                        {"Contacts", new SDataPayloadCollection {
                                new SDataPayload {
                                    ResourceName = "Contact",
                                    Values = {
                                        {"AccountName",  txtAccount.Text},
                                        {"LastName", txtLName.Text},
                                        {"FirstName", txtFName.Text},
                                        {"Email",txtEmail.Text}
                                    }
                                }
                            }
                        }
                    }
                };

                entry.SetSDataPayload(payload);
                var request = new SDataSingleResourceRequest(service, entry) { ResourceKind = "accounts" };
                AtomEntry result = request.Create();

                if(result != null)
                {
                    this.DialogResult = System.Windows.Forms.DialogResult.Yes;
                }

                this.Close();

            }
            catch (SDataClientException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 public CreateTicket(SDataPayload payload, SafeMailItem safeEmail)
 {
     InitializeComponent();
     contactPayload = payload;
     curEmail = safeEmail;
 }
Beispiel #13
0
 private void progressStage(SDataPayload oppPayload)
 {
     string currentStage = (string)oppPayload.Values["Stage"];
     switch (currentStage)
     {
         case null:
             oppPayload.Values["Stage"] = "1-Prospect";
             oppPayload.Values["CloseProbability"] = 1;
             oppPayload.Values["LeadSource"] = fetchLeadSource();
             break;
         case "1-Prospect":
             oppPayload.Values["Stage"] = "2-Qualification";
             oppPayload.Values["CloseProbability"] = 10;
             break;
         case "2-Qualification":
             oppPayload.Values["Stage"] = "3-Needs Analysis";
             oppPayload.Values["CloseProbability"] = 25;
             break;
         case "3-Needs Analysis":
             oppPayload.Values["Stage"] = "4-Demonstration";
             oppPayload.Values["CloseProbability"] = 50;
             break;
         case "4-Demonstration":
             oppPayload.Values["Stage"] = "5-Negotiation";
             oppPayload.Values["CloseProbability"] = 75;
             break;
         case "5-Negotiation":
             oppPayload.Values["Stage"] = "6-Decision";
             oppPayload.Values["CloseProbability"] = 100;
             break;
         case "6-Decision":
             oppPayload.Values["Stage"] = "6-Decision";
             oppPayload.Values["CloseProbability"] = 100;
             break;
     }
 }
        public void throws_exception_when_ItemElementName_is_not_set()
        {
            var payload = new SDataPayload
                              {
                                  ResourceName = "validationRule",
                                  Namespace = "",
                                  Values =
                                      {
                                          { "validatorType", new SDataSimpleCollection() {"item"} }
                                      }
                              };

            Assert.Throws(typeof (InvalidOperationException),
                          delegate {
                              var res = SDataPayloadUtility.WritePayload(payload);
                          });
        }
        public void Primitive_Values_Formatted_Appropriately()
        {
            var payload = new SDataPayload
                          {
                              ResourceName = "salesOrder",
                              Namespace = "",
                              Values =
                                  {
                                      {"byte", byte.MaxValue},
                                      {"sbyte", sbyte.MaxValue},
                                      {"short", short.MaxValue},
                                      {"ushort", ushort.MaxValue},
                                      {"int", int.MaxValue},
                                      {"uint", uint.MaxValue},
                                      {"long", long.MaxValue},
                                      {"ulong", ulong.MaxValue},
                                      {"bool", true},
                                      {"char", 'z'},
                                      {"float", float.MaxValue},
                                      {"double", double.MaxValue},
                                      {"decimal", decimal.MaxValue},
                                      {"Guid", Guid.NewGuid()},
                                      {"DateTime", DateTime.Now},
                                      {"DateTimeOffset", DateTimeOffset.Now},
                                      {"TimeSpan", DateTime.Now.TimeOfDay}
                                  }
                          };
            var nav = WritePayload(payload);
            nav = nav.SelectSingleNode("*/salesOrder");

            var assertDoesNotThrow = new Action<string, Action<string>>(
                (name, action) =>
                {
                    var node = nav.SelectSingleNode(name);
                    Assert.That(node, Is.Not.Null);
                    Assert.DoesNotThrow(() => action(node.Value));
                });
            assertDoesNotThrow("byte", x => XmlConvert.ToByte(x));
            assertDoesNotThrow("sbyte", x => XmlConvert.ToSByte(x));
            assertDoesNotThrow("short", x => XmlConvert.ToInt16(x));
            assertDoesNotThrow("ushort", x => XmlConvert.ToUInt16(x));
            assertDoesNotThrow("int", x => XmlConvert.ToInt32(x));
            assertDoesNotThrow("uint", x => XmlConvert.ToUInt32(x));
            assertDoesNotThrow("long", x => XmlConvert.ToInt64(x));
            assertDoesNotThrow("ulong", x => XmlConvert.ToUInt64(x));
            assertDoesNotThrow("bool", x => XmlConvert.ToBoolean(x));
            assertDoesNotThrow("char", x => XmlConvert.ToChar(x));
            assertDoesNotThrow("float", x => XmlConvert.ToSingle(x));
            assertDoesNotThrow("double", x => XmlConvert.ToDouble(x));
            assertDoesNotThrow("decimal", x => XmlConvert.ToDecimal(x));
            assertDoesNotThrow("Guid", x => XmlConvert.ToGuid(x));
            assertDoesNotThrow("DateTime", x => XmlConvert.ToDateTime(x, XmlDateTimeSerializationMode.RoundtripKind));
            assertDoesNotThrow("DateTimeOffset", x => XmlConvert.ToDateTimeOffset(x));
            assertDoesNotThrow("TimeSpan", x => XmlConvert.ToTimeSpan(x));
        }
        //============================================================
        //	PUBLIC METHODS
        //============================================================

        #region Load(XPathNavigator source, XmlNamespaceManager manager)

        /// <summary>
        /// Initializes the syndication extension context using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="SDataExtensionContext"/>.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> object used to resolve prefixed syndication extension elements and attributes.</param>
        /// <returns><b>true</b> if the <see cref="SDataExtensionContext"/> was able to be initialized using the supplied <paramref name="source"/>; otherwise <b>false</b>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source, XmlNamespaceManager manager)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            var wasLoaded = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            if (source.HasChildren)
            {
                var payloadNavigator = source.SelectSingleNode("sdata:payload/*", manager);
                if (payloadNavigator != null)
                {
                    var payload = new SDataPayload();
                    if (payload.Load(payloadNavigator, manager))
                    {
                        Payload   = payload;
                        wasLoaded = true;
                    }
                }

                var diagnosesNavigator = source.Select("sdata:diagnoses/sdata:diagnosis", manager);
                foreach (XPathNavigator item in diagnosesNavigator)
                {
                    var diagnosis = new Diagnosis();
                    if (diagnosis.Load(item, manager))
                    {
                        Diagnoses.Add(diagnosis);
                        wasLoaded = true;
                    }
                }

                var diagnosisNavigator = source.Select("sdata:diagnosis", manager);
                foreach (XPathNavigator item in diagnosisNavigator)
                {
                    var diagnosis = new Diagnosis();
                    if (diagnosis.Load(item, manager))
                    {
                        Diagnoses.Add(diagnosis);
                        wasLoaded = true;
                    }
                }

                var schemaNavigator = source.SelectSingleNode("sdata:schema", manager);
                if (schemaNavigator != null && !string.IsNullOrEmpty(schemaNavigator.InnerXml))
                {
                    schemaNavigator.MoveToFirstChild();

                    using (var reader = schemaNavigator.ReadSubtree())
                    {
                        reader.Read();
                        Schema = SDataSchema.Read(reader);
                    }

                    wasLoaded = true;
                }
            }

            return(wasLoaded);
        }
        private void cmdSave_Click(object sender, EventArgs e)
        {
            try
            {
                ISDataService service;
                service = SDataDataService.mydataService();

                var entry = new AtomEntry();
                var payload = new SDataPayload
                {
                    ResourceName = "Lead",
                    Namespace = "http://schemas.sage.com/dynamic/2007",
                    Values = {
                        {"Company", txtCompany.Text.Trim()},
                        {"FirstName",txtFName.Text.Trim()},
                        {"LastName",txtLName.Text.Trim()},
                        {"Email",txtEmail.Text.Trim()},
                        {"Address",
                                new SDataPayload {
                                    ResourceName = "LeadAddress",
                                    Values = {
                                        {"Address1",  txtAddress.Text.Trim()},
                                        {"City", txtCity.Text.Trim()},
                                        {"State", txtState.Text.Trim()},
                                        {"PostalCode",txtPostalCode.Text.Trim()}
                                    }
                                }
                        }
                    }
                };

                entry.SetSDataPayload(payload);
                var request = new SDataSingleResourceRequest(service, entry) { ResourceKind = "leads" };
                AtomEntry result = request.Create();

                if (result != null)
                {
                    this.DialogResult = System.Windows.Forms.DialogResult.Yes;
                }

                this.Close();

            }
            catch (SDataClientException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #18
0
        // 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);;
            }
        }
Beispiel #19
0
        // 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);;
            }
        }
Beispiel #20
0
        private string randomChineseNoteGenerator(string type, SDataPayload payload, string description)
        {
            Random rand = new Random();
            string note = "";
            // Array of note structures to be used
            string[] notes = new string[]
            {
                #region Notes
                "",
                // Meeting notes: (5 total)
                payload.Values["AccountName"] + "的代表通缉令扎堆谈论一下产品",
                "会议" + payload.Values["AccountName"] + " 应该帮助沿着与他们做生意",
                "跟" + payload.Values["AccountName"] + " 在手机上他们想说话亲自澄清",
                payload.Values["AccountName"] + " 想祝贺我们的人对我们的产品",
                "检查" + payload.Values["AccountName"] + " 有没有听说过他们在一段时间",
                // Phone call notes: (3 total)
                payload.Values["AccountName"] + " 想澄清",
                "继 " + payload.Values["AccountName"] + " 因为他们似乎对产品感兴趣的",
                payload.Values["AccountName"] + " 想谈谈移动实施",
                // Personal notes: (4 total)
                "如此兴奋" + description,
                "不能等待" + description,
                "期待" + description,
                "绝对需要" + description,
                // Notes/History notes: (12 total)
                "如果你需要能够继续之前",
                "在移动之前有两件事情想澄清",
                "一对夫妇朦胧应该讨论的主题",
                "欲望淘汰任何的建议的不确定性",
                "进展顺利",
                "似乎享受与我们合作的前景",
                "思想的产品所需的任务绰绰有余",
                "谈到该产品并得到了很多建设性的反馈意见",
                "聊天是短暂的但总体而言似乎是乐观的",
                "一对夫妇技术方面的东西要注意......",
                "只是想列出两个技术方面的东西我发现......",
                "科技笔记......"
                #endregion
            };

            int index = 0;


            switch (type)
            {
                case "任命":
                    index = rand.Next(1, 5);
                    note = notes[index];
                    break;
                case "电话呼叫":
                    if (description == "讨论机会")
                        index = 6;
                    if (description == "后续" || description == "随访 - 下一步" || description == "跟进建议")
                    {
                        int temp = rand.Next(0, 2);
                        if (temp == 0)
                            index = 6;
                        if (temp == 1)
                            index = 7;
                        if (temp == 2)
                            index = 8;
                    }
                    if (description == "讨论机会")
                        index = 8;

                    note = notes[index];
                    break;
                case "个人":
                    if (description == "支付帐单" || description == "提交费用" || description == "生日提醒" || description == "周年纪念提醒")
                        note = "";
                    else
                    {
                        index = rand.Next(9, 12);
                        note = notes[index];
                    }
                    break;
                case "注意":
                    if (description == "会议记录" || description == "电话会议")
                    {
                        int temp = rand.Next(7);
                        if (temp == 0)
                            index = 14;
                        if (temp == 1)
                            index = 15;
                        if (temp == 2)
                            index = 16;
                        if (temp == 3)
                            index = 17;
                        if (temp == 4)
                            index = 18;
                        if (temp == 5)
                            index = 19;
                        if (temp == 6)
                            index = 20;
                    }
                    if (description == "建议" || description == "合格")
                    {
                        int temp = rand.Next(0, 2);
                        if (temp == 0)
                            index = 16;
                        if (temp == 1)
                            index = 17;
                        if (temp == 2)
                            index = 18;
                    }
                    if (description == "问题")
                    {
                        int temp = rand.Next(0, 3);
                        if (temp == 0)
                            index = 12;
                        if (temp == 1)
                            index = 13;
                        if (temp == 2)
                            index = 14;
                        if (temp == 3)
                            index = 15;
                    }
                    if (description == "技术说明")
                    {
                        int temp = rand.Next(0, 2);
                        if (temp == 0)
                            index = 21;
                        if (temp == 1)
                            index = 22;
                        if (temp == 2)
                            index = 23;
                    }
                    note = notes[index];
                    break;
                default:
                    note = "";
                    break;
            }

            return note;
        }
Beispiel #21
0
        /*
        private string randomLeadSource()
        {
            Random rand = new Random();
            int x = rand.Next(0, 8);
            string source = "E-mail";

            int value = rand.Next(8);
            switch (value)
            {
                case 0:
                    source = "Advertising";
                    break;
                case 1:
                    source = "Direct Mail";
                    break;
                case 2:
                    source = "E-mail";
                    break;
                case 3:
                    source = "Event";
                    break;
                case 4:
                    source = "Seminar";
                    break;
                case 5:
                    source = "Telemarketing";
                    break;
                case 6:
                    source = "Trade Show";
                    break;
                case 7:
                    source = "Web";
                    break;
                case 8:
                    source = "Word of Mouth /Referral";
                    break;
                default:
                    source = "E-mail";
                    break;
            }
            return source;
        }

        private string randomChineseLeadSource()
        {
            Random rand = new Random();
            string source = "电子邮件";

            int value = rand.Next(8);
            switch (value)
            {
                case 0:
                    source = "广告";
                    break;
                case 1:
                    source = "商函";
                    break;
                case 2:
                    source = "电子邮件";
                    break;
                case 3:
                    source = "事件";
                    break;
                case 4:
                    source = "研讨会";
                    break;
                case 5:
                    source = "电话营销";
                    break;
                case 6:
                    source = "展会";
                    break;
                case 7:
                    source = "卷筒纸";
                    break;
                case 8:
                    source = "口碑 /转介";
                    break;
                default:
                    source = "电子邮件";
                    break;
            }
            return source;
        }
        */

        private string randomNoteGenerator(string type, SDataPayload payload, string description)
        {
            Random rand = new Random();
            string note = "";
            // Array of note structures to be used
            string[] notes = new string[]
            {
                #region Notes
                "",
                // Meeting notes: (5 total)
                "Representatives from " + payload.Values["AccountName"] + " wanted to get together to talk about the product.",
                "Meeting with " + payload.Values["AccountName"] + " should help move along business with them.",
                "Talked with " + payload.Values["AccountName"] + " on the phone and they wanted to speak in person for clarifications.",
                payload.Values["AccountName"] + " wanted to congratulate us in person on our product.",
                "Checking up on " + payload.Values["AccountName"] + ". Have not heard from them in a while.",
                // Phone call notes: (3 total)
                payload.Values["AccountName"] + " wanted clarifications",
                "Following up on " + payload.Values["AccountName"] + " because they seemed interested in the product",
                payload.Values["AccountName"] + " wanted to talk about mobile implementation",
                // Personal notes: (4 total)
                "So excited for " + description,
                "Can't wait to " + description,
                "Looking forward to " + description,
                "Definitely need " + description,
                // Notes/History notes: (12 total)
                "Need answers before being able to continue",
                "Wanted to clarify a couple things before moving on",
                "A couple hazy topics that should be discussed",
                "Desire to weed out any uncertainties about the proposal",
                "Went well",
                "Seemed to enjoy the prospect of working with us",
                "Thought the product was more than adequate for the desired tasks",
                "Talked about the product and got lots of constructive feedback",
                "The chat was brief, but overall seemed optimistic",
                "A couple technical things to note...",
                "Just wanted to list a couple technical things I found...",
                "Tech notes..."
                #endregion
            };

            int index = 0;
            

            switch (type)
            {
                case "Appointment":
                    index = rand.Next(1,5);
                    note = notes[index];
                    break;
                case "PhoneCall":
                    if (description == "Discuss Opportunities")
                        index = 6;
                    if (description == "Follow-up" || description == "Follow up - next step" || description == "Follow up on proposal")
                    {
                        int temp = rand.Next(0,2);
                        if (temp == 0)
                            index = 6;
                        if (temp == 1)
                            index = 7;
                        if (temp == 2)
                            index = 8;
                    }
                    if (description == "Discuss Opportunities")
                        index = 8;

                    note = notes[index];
                    break;
                case "Personal":
                    if (description == "Pay Bills" || description == "Submit expenses" || description == "Birthday Reminder" || description == "Anniversary Reminder")
                        note = "";
                    else
                    {
                        index = rand.Next(9,12);
                        note = notes[index];
                    }
                    break;
                case "Note":
                    if (description == "Meeting notes" || description == "Phone meeting")
                    {
                        int temp = rand.Next(7);
                        if (temp == 0)
                            index = 14;
                        if (temp == 1)
                            index = 15;
                        if (temp == 2)
                            index = 16;
                        if (temp == 3)
                            index = 17;
                        if (temp == 4)
                            index = 18;
                        if (temp == 5)
                            index = 19;
                        if (temp == 6)
                            index = 20;
                    }
                    if (description == "Proposal" || description == "Qualification")
                    {
                        int temp = rand.Next(0,2);
                        if (temp == 0)
                            index = 16;
                        if (temp == 1)
                            index = 17;
                        if (temp == 2)
                            index = 18;
                    }
                    if (description == "Questions")
                    {
                        int temp = rand.Next(0,3);
                        if (temp == 0)
                            index = 12;
                        if (temp == 1)
                            index = 13;
                        if (temp == 2)
                            index = 14;
                        if (temp == 3)
                            index = 15;
                    }
                    if (description == "Technical notes")
                    {
                        int temp = rand.Next(0,2);
                        if (temp == 0)
                            index = 21;
                        if (temp == 1)
                            index = 22;
                        if (temp == 2)
                            index = 23;
                    }
                    note = notes[index];
                    break;
                default:
                    note = "";
                    break;
            }

            return note;
        }
Beispiel #22
0
 private void progressChineseStage(SDataPayload oppPayload)
 {
     string currentStage = (string)oppPayload.Values["Stage"];
     switch (currentStage)
     {
         case null:
             oppPayload.Values["Stage"] = "1-展望";
             oppPayload.Values["CloseProbability"] = 1;
             oppPayload.Values["LeadSource"] = fetchLeadSource();
             break;
         case "1-展望":
             oppPayload.Values["Stage"] = "2-合格";
             oppPayload.Values["CloseProbability"] = 10;
             break;
         case "2-合格":
             oppPayload.Values["Stage"] = "3-需求分析";
             oppPayload.Values["CloseProbability"] = 25;
             break;
         case "3-需求分析":
             oppPayload.Values["Stage"] = "4-示范";
             oppPayload.Values["CloseProbability"] = 50;
             break;
         case "4-示范":
             oppPayload.Values["Stage"] = "5-谈判";
             oppPayload.Values["CloseProbability"] = 75;
             break;
         case "5-谈判":
             oppPayload.Values["Stage"] = "6-决策";
             oppPayload.Values["CloseProbability"] = 100;
             break;
         case "6-决策":
             oppPayload.Values["Stage"] = "6-决策";
             oppPayload.Values["CloseProbability"] = 100;
             break;
     }
 }
        private bool LoadItem(string name, IEnumerable <XPathNavigator> items, XmlNamespaceManager manager)
        {
            object value;

            if (items.Count() > 1)
            {
                var collection = new SDataPayloadCollection();

                if (!collection.Load(items, manager))
                {
                    return(false);
                }

                value = collection;
            }
            else
            {
                var item = items.First();

                switch (InferItemType(item))
                {
                case ItemType.Property:
                {
                    string nilValue;

                    if (item.TryGetAttribute("nil", Framework.Common.XSI.Namespace, out nilValue) && XmlConvert.ToBoolean(nilValue))
                    {
                        value = null;
                    }
                    else
                    {
                        value = item.Value;
                    }

                    break;
                }

                case ItemType.Object:
                {
                    var obj = new SDataPayload();

                    if (!obj.Load(item, manager))
                    {
                        return(false);
                    }

                    value = obj;
                    break;
                }

                case ItemType.PayloadCollection:
                {
                    var collection = new SDataPayloadCollection();

                    if (!collection.Load(item, manager))
                    {
                        return(false);
                    }

                    value = collection;
                    break;
                }

                case ItemType.SimpleCollection:
                {
                    var collection = new SDataSimpleCollection();

                    if (!collection.Load(item))
                    {
                        return(false);
                    }

                    value = collection;
                    break;
                }

                default:
                    return(false);
                }
            }

            Values.Add(name, value);
            return(true);
        }
 public PayloadCustomTypeDescriptor(ICustomTypeDescriptor inner, SDataPayload instance)
 {
     _inner    = inner;
     _instance = instance;
 }
        private bool LoadItem(string name, IEnumerable<XPathNavigator> items, XmlNamespaceManager manager)
        {
            object value;

            if (items.Count() > 1)
            {
                var collection = new SDataPayloadCollection();

                if (!collection.Load(items, manager))
                {
                    return false;
                }

                value = collection;
            }
            else
            {
                var item = items.First();

                switch (InferItemType(item))
                {
                    case ItemType.Property:
                    {
                        string nilValue;

                        if (item.TryGetAttribute("nil", Framework.Common.XSI.Namespace, out nilValue) && XmlConvert.ToBoolean(nilValue))
                        {
                            value = null;
                        }
                        else
                        {
                            value = item.Value;
                        }

                        break;
                    }
                    case ItemType.Object:
                    {
                        var obj = new SDataPayload();

                        if (!obj.Load(item, manager))
                        {
                            return false;
                        }

                        value = obj;
                        break;
                    }
                    case ItemType.PayloadCollection:
                    {
                        var collection = new SDataPayloadCollection();

                        if (!collection.Load(item, manager))
                        {
                            return false;
                        }

                        value = collection;
                        break;
                    }
                    case ItemType.SimpleCollection:
                    {
                        var collection = new SDataSimpleCollection();

                        if (!collection.Load(item))
                            return false;

                        value = collection;
                        break;
                    }
                    default:
                        return false;
                }
            }

            Values.Add(name, value);
            return true;
        }
 public PayloadCustomTypeDescriptor(ICustomTypeDescriptor inner, SDataPayload instance)
 {
     _inner = inner;
     _instance = instance;
 }
Beispiel #27
0
 public string localize(string language, string action, SDataPayload payload, string type, string description, bool won)
 {
     string value = null;
     switch (language)
     {
         case "English":
         switch (action)
         {
             case "Progress Stage":
                 progressStage(payload);
                 break;
             case "Type Generator":
                 value = randomTypeGenerator();
                 break;
             case "Account Type":
                 value = randomAccountType();
                 break;
             case "Account Status":
                 value = randomAccountStatus();
                 break;
             case "Category Generator":
                 value = randomCategoryGenerator(type);
                 break;
             case "Description Generator":
                 value = randomDescriptionGenerator(type);
                 break;
            /* case "Lead Source":
                 value = fetchLeadSource();
                 break; */
             case "Note Generator":
                 value = randomNoteGenerator(type, payload, description);
                 break;
             case "Location Generator":
                 value = randomLocationGenerator(type);
                 break;
             case "Reason":
                 value = randomReason(won);
                 break;
             case "Priority Generator":
                 value = randomPriorityGenerator();
                 break;
             case "Fake Company Name":
                 value = GetFakeCompanyName();
                 break;
             case "Fake First Name":
                 value = GetFakeFirstName();
                 break;
             case "Fake Last Name":
                 value = GetFakeLastName();
                 break;     
     }
     break;
         case "Chinese":
     switch (action)
     {
         case "Progress Stage":
             progressChineseStage(payload);
             break;
         case "Type Generator":
             value = randomChineseTypeGenerator();
             break;
         case "Account Type":
             value = randomChineseAccountType();
             break;
         case "Account Status":
             value = randomChineseAccountStatus();
             break;
         case "Category Generator":
             value = randomChineseCategoryGenerator(type);
             break;
         case "Description Generator":
             value = randomChineseDescriptionGenerator(type);
             break;
             /*
         case "Lead Source":
             value = randomChineseLeadSource();
             break; */
         case "Note Generator":
             value = randomChineseNoteGenerator(type, payload, description);
             break;
         case "Location Generator":
             value = randomChineseLocationGenerator(type);
             break;
         case "Reason":
             value = randomChineseReason(won);
             break;
         case "Priority Generator":
             value = randomChinesePriorityGenerator();
             break;
         case "Fake Company Name":
             value = GetFakeChineseCompanyName();
             break;
         case "Fake First Name":
             value = GetFakeChineseFirstName();
             break;
         case "Fake Last Name":
             value = GetFakeChineseLastName();
             break;
     }
     break;
 }
     return value;
 }
 public void Written_Collection_Uses_Item_Resource_Name()
 {
     var payload = new SDataPayload
                   {
                       ResourceName = "salesOrder",
                       Namespace = "",
                       Values =
                           {
                               {
                                   "orderLines", new SDataPayloadCollection("salesOrderLine")
                                                 {
                                                     new SDataPayload {Key = "43660-1"}
                                                 }
                                   }
                           }
                   };
     var nav = WritePayload(payload);
     var node = nav.SelectSingleNode("*/salesOrder/orderLines/salesOrderLine");
     Assert.That(node, Is.Not.Null);
 }
Beispiel #29
0
        // Functional
        public void completeActivity()
        {
            try
            {
                // Initiates a value to keep track of amount of activities created.
                int i = 0;
                float previous = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;

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

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

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

                var feed = activities.Read();

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


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

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


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

                            if (activityCompleteAmount == i)
                                break;

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

                }
            }
            catch (ArgumentNullException e)
            {
                Log(e.ToString(), fileName);
            }
        }
        /// <summary>
        /// Initializes the syndication extension context using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="SDataExtensionContext"/>.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> object used to resolve prefixed syndication extension elements and attributes.</param>
        /// <returns><b>true</b> if the <see cref="SDataExtensionContext"/> was able to be initialized using the supplied <paramref name="source"/>; otherwise <b>false</b>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source, XmlNamespaceManager manager)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            var wasLoaded = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            if (source.HasChildren)
            {
                var payloadNavigator = source.SelectSingleNode("sdata:payload/*", manager);
                if (payloadNavigator != null)
                {
                    var payload = new SDataPayload();
                    if (payload.Load(payloadNavigator, manager))
                    {
                        Payload = payload;
                        wasLoaded = true;
                    }
                }

                var diagnosesNavigator = source.Select("sdata:diagnoses", manager);
                foreach (XPathNavigator item in diagnosesNavigator)
                {
                    var diagnosis = new Diagnosis();
                    if (diagnosis.Load(item, manager))
                    {
                        Diagnoses.Add(diagnosis);
                        wasLoaded = true;
                    }
                }

                var schemaNavigator = source.SelectSingleNode("sdata:schema", manager);
                if (schemaNavigator != null && !string.IsNullOrEmpty(schemaNavigator.Value))
                {
                    Schema = schemaNavigator.Value;
                    wasLoaded = true;
                }
            }

            return wasLoaded;
        }
Beispiel #31
0
        // Needs help!
        public void promoteLead()
        {
            try
            {
                float previous = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                SDataTemplateResourceRequest contactTemplate = new SDataTemplateResourceRequest(dynamic);
                contactTemplate.ResourceKind = "contacts";

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

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

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

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

                if (i == 50)
                    return;

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

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

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

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


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

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

                    request.Entry.SetSDataPayload(
                       new SDataPayload
                       {
                           ResourceName = "LeadConvertLeadToAccount",
                           Namespace = "http://schemas.sage.com/dynamic/2007",
                           Values = {
                       {"request", new SDataPayload
                           {
                           Values = {
                               {"entity", leadPayload},
                               {"LeadId", entity},
                               {"account", accountPayload.Key}
                                    }
                           }
                        }
                                 }
                       });
                    request.Create();
                    float after = DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Second * 1000 + DateTime.Now.Millisecond;
                    float timed = (after - previous) / 1000;
                    Log(DateTime.Now + " - Converted " + leadPayload.Values["FirstName"] + " " + leadPayload.Values["LastName"] 
                        + " to a contact with Account " + leadPayload.Values["Company"] + " - " + timed + " seconds", fileName);
                }
                leadsPromotedCount++;
                SetLeadsPromoted(leadsPromotedCount.ToString());
            }
            catch (Exception e) { 
                Log(e.ToString(), fileName); 
            }
        }
        /// <summary>
        /// Extension method to set sdata payload
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="payload"></param>
        public static void SetSDataPayload(this AtomEntry entry, SDataPayload payload)
        {
            var context = GetContext(entry, true);

            context.Payload = payload;
        }
Beispiel #33
0
        // 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);;
            }
        }
 /// <summary>
 /// Extension method to set sdata payload
 /// </summary>
 /// <param name="entry"></param>
 /// <param name="payload"></param>
 public static void SetSDataPayload(this AtomEntry entry, SDataPayload payload)
 {
     var context = GetContext(entry, true);
     context.Payload = payload;
 }
 public CreateOpportunity(SDataPayload payload)
 {
     InitializeComponent();
     contactPayload = payload;
 }