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();
        }
        public void Typical_Feed()
        {
            var xml = @"<feed xmlns=""http://www.w3.org/2005/Atom""
                              xmlns:sync=""http://schemas.sage.com/sdata/sync/2008/1"">
                          <sync:syncMode>catchUp</sync:syncMode>
                          <sync:digest>
                            <sync:origin>http://www.example.com/sdata/myApp1/myContract/-/accounts</sync:origin>
                            <sync:digestEntry>
                              <sync:endpoint>http://www.example.com/sdata/myApp1/myContract/-/accounts</sync:endpoint>
                              <sync:tick>6</sync:tick>
                              <sync:stamp>2008-10-30T17:23:08Z</sync:stamp>
                              <sync:conflictPriority>2</sync:conflictPriority>
                            </sync:digestEntry>
                            <sync:digestEntry>
                              <sync:endpoint>http://www.example.com/sdata/myApp2/myContract/-/accounts</sync:endpoint>
                              <sync:tick>10</sync:tick>
                              <sync:stamp>2008-10-30T12:16:51Z</sync:stamp>
                              <sync:conflictPriority>1</sync:conflictPriority>
                            </sync:digestEntry>
                          </sync:digest>
                        </feed>";
            var feed = new AtomFeed();
            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
            {
                feed.Load(stream);
            }

            var syncMode = feed.GetSDataSyncMode();
            Assert.That(syncMode, Is.EqualTo(SyncMode.CatchUp));

            var digest = feed.GetSDataSyncDigest();
            Assert.That(digest, Is.Not.Null);
            Assert.That(digest.Origin, Is.EqualTo("http://www.example.com/sdata/myApp1/myContract/-/accounts"));
            Assert.That(digest.Entries.Length, Is.EqualTo(2));

            var entry = digest.Entries[0];
            Assert.That(entry.EndPoint, Is.EqualTo("http://www.example.com/sdata/myApp1/myContract/-/accounts"));
            Assert.That(entry.Tick, Is.EqualTo(6L));
            Assert.That(entry.Stamp, Is.EqualTo(new DateTime(2008, 10, 30, 17, 23, 08)));
            Assert.That(entry.ConflictPriority, Is.EqualTo(2));

            entry = digest.Entries[1];
            Assert.That(entry.EndPoint, Is.EqualTo("http://www.example.com/sdata/myApp2/myContract/-/accounts"));
            Assert.That(entry.Tick, Is.EqualTo(10L));
            Assert.That(entry.Stamp, Is.EqualTo(new DateTime(2008, 10, 30, 12, 16, 51)));
            Assert.That(entry.ConflictPriority, Is.EqualTo(1));
        }
        public void Extension_Namespace_Declared_On_Root_Element_Test()
        {
            const string xml = @"<feed xmlns=""http://www.w3.org/2005/Atom"" xmlns:opensearch=""http://a9.com/-/spec/opensearch/1.1/"">
                                   <entry>
                                     <opensearch:startIndex>33</opensearch:startIndex>
                                   </entry>
                                 </feed>";
            var feed = new AtomFeed();

            using (var reader = new StringReader(xml))
            using (var xmlReader = XmlReader.Create(reader))
            {
                feed.Load(xmlReader);
            }

            Assume.That(feed.Entries, Is.Not.Empty);
            var entry = feed.Entries.First();
            Assert.That(entry.Extensions.OfType<OpenSearchExtension>().Any());
        }
        public void Nested_And_Unnested_Resource_Diagnoses_Test()
        {
            const string xml = @"
            <feed xmlns=""http://www.w3.org/2005/Atom"" xmlns:sdata=""http://schemas.sage.com/sdata/2008/1"">
              <sdata:diagnoses>
            <sdata:diagnosis>
              <sdata:message>one</sdata:message>
            </sdata:diagnosis>
              </sdata:diagnoses>
              <sdata:diagnosis>
            <sdata:message>two</sdata:message>
              </sdata:diagnosis>
              <entry>
            <sdata:diagnoses>
              <sdata:diagnosis>
            <sdata:message>three</sdata:message>
              </sdata:diagnosis>
            </sdata:diagnoses>
            <sdata:diagnosis>
              <sdata:message>four</sdata:message>
            </sdata:diagnosis>
              </entry>
            </feed>";
            var feed = new AtomFeed();
            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
            {
                feed.Load(stream);
            }

            var diagnoses = feed.GetSDataDiagnoses();
            Assert.That(diagnoses.Count, Is.EqualTo(2));
            Assert.That(diagnoses[0].Message, Is.EqualTo("one"));
            Assert.That(diagnoses[1].Message, Is.EqualTo("two"));

            Assume.That(feed.Entries.Any());
            diagnoses = feed.Entries.First().GetSDataDiagnoses();
            Assert.That(diagnoses.Count, Is.EqualTo(2));
            Assert.That(diagnoses[0].Message, Is.EqualTo("three"));
            Assert.That(diagnoses[1].Message, Is.EqualTo("four"));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds a new syndication resource to the data source.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="feed"></param>
        /// <param name="eTag"></param>
        /// <returns></returns>
        public virtual AtomFeed CreateFeed(SDataBaseRequest request, AtomFeed feed, out string eTag)
        {
            Guard.ArgumentNotNull(request, "request");
            Guard.ArgumentNotNull(feed, "feed");

            try
            {
                var requestUrl = request.ToString();
                var operation = new RequestOperation(HttpMethod.Post, feed);
                var response = ExecuteRequest(requestUrl, operation, MediaType.Atom, MediaType.Xml);
                eTag = response.ETag;
                return (AtomFeed) response.Content;
            }
            catch (Exception ex)
            {
                throw new SDataClientException(ex.Message, ex);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Adds a new syndication resource to the data source.
 /// </summary>
 /// <param name="request">The request that identifies the resource within the syndication data source.</param>
 /// <param name="feed"></param>
 public virtual AtomFeed CreateFeed(SDataBaseRequest request, AtomFeed feed)
 {
     string eTag;
     return CreateFeed(request, feed, out eTag);
 }
        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);
            }
        }
        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);
            }
        }
        /// <summary>
        /// Modifies the <see cref="AtomFeed"/> to match the data source.
        /// </summary>
        /// <param name="resource">The <see cref="AtomFeed"/> to be filled.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        public void Fill(AtomFeed resource)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(resource, "resource");

            //------------------------------------------------------------
            //	Create namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager     = AtomUtility.CreateNamespaceManager(this.Navigator.NameTable);

            //------------------------------------------------------------
            //	Attempt to fill syndication resource
            //------------------------------------------------------------
            XPathNavigator feedNavigator    = this.Navigator.SelectSingleNode("atom:feed", manager);

            if (feedNavigator != null)
            {
                AtomUtility.FillCommonObjectAttributes(resource, feedNavigator);

                XPathNavigator idNavigator      = feedNavigator.SelectSingleNode("atom:id", manager);
                XPathNavigator titleNavigator   = feedNavigator.SelectSingleNode("atom:title", manager);
                XPathNavigator updatedNavigator = feedNavigator.SelectSingleNode("atom:updated", manager);

                if (idNavigator != null)
                {
                    resource.Id = new AtomId();
                    resource.Id.Load(idNavigator, this.Settings);
                }

                if (titleNavigator != null)
                {
                    resource.Title  = new AtomTextConstruct();
                    resource.Title.Load(titleNavigator, this.Settings);
                }

                if (updatedNavigator != null)
                {
                    DateTime updatedOn;
                    if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updatedNavigator.Value, out updatedOn))
                    {
                        resource.UpdatedOn  = updatedOn;
                    }
                }

                Atom10SyndicationResourceAdapter.FillFeedOptionals(resource, feedNavigator, manager, this.Settings);
                Atom10SyndicationResourceAdapter.FillFeedCollections(resource, feedNavigator, manager, this.Settings);

                SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(feedNavigator, this.Settings);
                adapter.Fill(resource, manager);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates a new <see cref="AtomFeed"/> instance using the specified <see cref="Uri"/>, <see cref="ICredentials"/>, <see cref="IWebProxy"/>, and <see cref="SyndicationResourceLoadSettings"/> object.
        /// </summary>
        /// <param name="source">A <see cref="Uri"/> that represents the URL of the syndication resource XML data.</param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the <see cref="AtomFeed"/> instance. This value can be <b>null</b>.</param>
        /// <returns>An <see cref="AtomFeed"/> object loaded using the <paramref name="source"/> data.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="FormatException">The <paramref name="source"/> data does not conform to the expected syndication content format. In this case, the feed remains empty.</exception>
        public static AtomFeed Create(Uri source, WebRequestOptions options, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            AtomFeed syndicationResource = new AtomFeed();

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

            //------------------------------------------------------------
            //	Create new instance using supplied parameters
            //------------------------------------------------------------
            syndicationResource.Load(source, options, settings);

            return syndicationResource;
        }
 public bool Read(AtomFeed feed)
 {
     return ExecuteReader() != null;
 }
        private AtomFeed GetFeed()
        {
            var feed = new AtomFeed
                       {
                           Title = new AtomTextConstruct("Batch"),
                           Id = new AtomId(new Uri(ToString())),
                           UpdatedOn = DateTime.Now
                       };

            foreach (var request in Requests)
            {
                var entry = request.Entry ?? new AtomEntry {Id = new AtomId(new Uri(request.Url))};
                entry.SetSDataHttpMethod(request.Method);
                entry.SetSDataHttpIfMatch(request.ETag);
                feed.AddEntry(entry);
            }

            return feed;
        }
        /// <summary>
        /// Modifies the <see cref="AtomFeed"/> optional entities to match the supplied <see cref="XPathNavigator"/> data source.
        /// </summary>
        /// <param name="feed">The <see cref="AtomFeed"/> to be filled.</param>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomFeed"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="feed"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <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>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        private static void FillFeedOptionals(AtomFeed feed, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(feed, "feed");
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            XPathNavigator generatorNavigator       = source.SelectSingleNode("atom:generator", manager);
            XPathNavigator iconNavigator            = source.SelectSingleNode("atom:icon", manager);
            XPathNavigator logoNavigator            = source.SelectSingleNode("atom:logo", manager);
            XPathNavigator rightsNavigator          = source.SelectSingleNode("atom:rights", manager);
            XPathNavigator subtitleNavigator        = source.SelectSingleNode("atom:subtitle", manager);

            if (generatorNavigator != null)
            {
                feed.Generator  = new AtomGenerator();
                feed.Generator.Load(generatorNavigator, settings);
            }

            if (iconNavigator != null)
            {
                feed.Icon   = new AtomIcon();
                feed.Icon.Load(iconNavigator, settings);
            }

            if (logoNavigator != null)
            {
                feed.Logo   = new AtomLogo();
                feed.Logo.Load(logoNavigator, settings);
            }

            if (rightsNavigator != null)
            {
                feed.Rights = new AtomTextConstruct();
                feed.Rights.Load(rightsNavigator, settings);
            }

            if (subtitleNavigator != null)
            {
                feed.Subtitle   = new AtomTextConstruct();
                feed.Subtitle.Load(subtitleNavigator, settings);
            }
        }
        /// <summary>
        /// Modifies the <see cref="AtomFeed"/> collection entities to match the supplied <see cref="XPathNavigator"/> data source.
        /// </summary>
        /// <param name="feed">The <see cref="AtomFeed"/> to be filled.</param>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomFeed"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="feed"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <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>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        private static void FillFeedCollections(AtomFeed feed, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(feed, "feed");
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            XPathNodeIterator authorIterator        = source.Select("atom:author", manager);
            XPathNodeIterator categoryIterator      = source.Select("atom:category", manager);
            XPathNodeIterator contributorIterator   = source.Select("atom:contributor", manager);
            XPathNodeIterator linkIterator          = source.Select("atom:link", manager);
            XPathNodeIterator entryIterator         = source.Select("atom:entry", manager);

            if (authorIterator != null && authorIterator.Count > 0)
            {
                while (authorIterator.MoveNext())
                {
                    AtomPersonConstruct author  = new AtomPersonConstruct();
                    if (author.Load(authorIterator.Current, settings))
                    {
                        feed.Authors.Add(author);
                    }
                }
            }

            if (categoryIterator != null && categoryIterator.Count > 0)
            {
                while (categoryIterator.MoveNext())
                {
                    AtomCategory category   = new AtomCategory();
                    if (category.Load(categoryIterator.Current, settings))
                    {
                        feed.Categories.Add(category);
                    }
                }
            }

            if (contributorIterator != null && contributorIterator.Count > 0)
            {
                while (contributorIterator.MoveNext())
                {
                    AtomPersonConstruct contributor = new AtomPersonConstruct();
                    if (contributor.Load(contributorIterator.Current, settings))
                    {
                        feed.Contributors.Add(contributor);
                    }
                }
            }

            if (entryIterator != null && entryIterator.Count > 0)
            {
                int counter = 0;
                while (entryIterator.MoveNext())
                {
                    AtomEntry entry = new AtomEntry();
                    counter++;

                    Atom10SyndicationResourceAdapter.FillEntry(entry, entryIterator.Current, manager, settings);

                    if (settings.RetrievalLimit != 0 && counter > settings.RetrievalLimit)
                    {
                        break;
                    }

                    ((Collection<AtomEntry>)feed.Entries).Add(entry);
                }
            }

            if (linkIterator != null && linkIterator.Count > 0)
            {
                while (linkIterator.MoveNext())
                {
                    AtomLink link   = new AtomLink();
                    if (link.Load(linkIterator.Current, settings))
                    {
                        feed.Links.Add(link);
                    }
                }
            }
        }
 private static AtomFeed LoadFeedContent(Stream stream)
 {
     var feed = new AtomFeed();
     feed.Load(stream);
     return feed;
 }
Exemplo n.º 16
0
        /// <summary>
        /// Adds a new syndication resource to the data source.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="feed"></param>
        /// <param name="eTag"></param>
        /// <returns></returns>
        public virtual AtomFeed CreateFeed(SDataBaseRequest request, AtomFeed feed, out string eTag)
        {
            Guard.ArgumentNotNull(request, "request");
            Guard.ArgumentNotNull(feed, "feed");

            try
            {
                var url = request.ToString();
                var operation = new RequestOperation(HttpMethod.Post, feed);
                return ExecuteFeedRequest(url, operation, out eTag);
            }
            catch (SDataClientException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new SDataClientException(ex.Message, ex);
            }
        }
Exemplo n.º 17
0
        private RequestOperation CreateBatchOperation()
        {
            var uri = new SDataUri(Uri);

            if (uri.PathSegments.Length != 4)
            {
                throw new InvalidOperationException("Batch requests can only be made on collection end points");
            }

            var feed = new AtomFeed();
            var batchOp = new RequestOperation(HttpMethod.Post, feed);

            foreach (var op in _operations)
            {
                AtomEntry entry;

                if (op.Resource == null)
                {
                    if (op.Method != HttpMethod.Post)
                    {
                        throw new InvalidOperationException("A predicate must be specified for GET, PUT and DELETE batch requests");
                    }

                    var entryUri = new SDataUri(uri) {CollectionPredicate = op.Predicate};
                    entry = new AtomEntry {Id = new AtomId(entryUri.Uri)};
                }
                else
                {
                    entry = op.Resource as AtomEntry;

                    if (entry == null)
                    {
                        throw new InvalidOperationException("Only atom entry resources can be submitted in batch requests");
                    }
                }

                entry.SetSDataHttpMethod(op.Method);

                if (!string.IsNullOrEmpty(op.ETag))
                {
                    entry.SetSDataHttpIfMatch(op.ETag);
                }

                feed.AddEntry(entry);

                foreach (var file in op.Files)
                {
                    batchOp.Files.Add(file);
                }
            }

            return batchOp;
        }
Exemplo n.º 18
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); 
            }
        }