<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: ExportTileCacheTask.EstimateTileCacheAsync in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/exporttilecachetask-estimatetilecacheasync/m-p/721070#M9094</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good to know. Can you mark this thread answered, please?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 24 Jul 2015 09:17:55 GMT</pubDate>
    <dc:creator>AnttiKajanus1</dc:creator>
    <dc:date>2015-07-24T09:17:55Z</dc:date>
    <item>
      <title>ExportTileCacheTask.EstimateTileCacheAsync</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/exporttilecachetask-estimatetilecacheasync/m-p/721066#M9090</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Currently, I'm testing ExportTileCacheTask.EstimateTileCacheAsync(..). While it's pretty easy to get started with this API, I'm having a hard time to get it really stable and user-friendly. I'm not sure if I'm using it wrong or if anything should be improved behind the scenes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;No detail information, if number of tiles &amp;gt; 100.000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Querying the Sampleserver (&lt;A href="http://sampleserver6.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer" title="http://sampleserver6.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer" rel="nofollow noopener noreferrer" target="_blank"&gt;World_Street_Map (MapServer))&lt;/A&gt; for the whole world with LOD == 9 results in an Exception with the message "Export tile operation failed".&lt;/P&gt;&lt;P&gt;If I use the REST API, I do find the reason why, it clearly states: "ERROR 001564: Requested tile count(262144) exceeds the maximum allowed number of tiles(100000) to be exported for service World_Street_Map:MapServer".&lt;/P&gt;&lt;P&gt;The only way to get access to this information is to parse all messages of ExportTileCacheJob.Messages &lt;EM&gt;after execution finished&lt;/EM&gt;... which brings to the next problem:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;await exportTilesTask.EstimateTileCacheSizeAsync(...) immediately returns&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The method call immediately returns to the execution of the method. At this point, the returned job contains close to zero information. I &lt;EM&gt;think&lt;/EM&gt; the method immediately returns because of "submit and query" pattern implemented at server side. The callback "(result, ex)" does not provide me with job information, so right now I extended my method with a "TaskCompletionSource":&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var taskCompletionSource = new TaskCompletionSource&amp;lt;EstimateTileCacheSizeResult&amp;gt;();
var job = await exportTilesTask.EstimateTileCacheSizeAsync(options,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (result, ex) =&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (ex == null) &lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;{ taskCompletionSource.SetResult(result); &lt;/SPAN&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;}&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else { taskCompletionSource.SetException(ex); }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }, .....);
await taskCompletionSource.Task;
// job finished with all information here
&lt;/PRE&gt;&lt;P&gt;This works (for me), but I really don't know if that's a correct / good pattern. It seems like a much of overhead to simply get an estimation. Is this pattern correct? Should it be integrated into the SDK itself? Is there a simpler way to get finished job information?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Randomly getting HTTP 500 Errors&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I do get random 500 errors, raising an exception and exiting the estimation. I'm not absolutely sure, but I think I do get those errors more often, the smaller I set checkInterval argument.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Maybe&lt;/EM&gt;, this is what happens behind the scenes:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Runtime SDK asks server to start the job&lt;/LI&gt;&lt;LI&gt;Server returns the job id, while still starting the job&lt;/LI&gt;&lt;LI&gt;Runtime SDK asks (kind of) immediately for the job status&lt;/LI&gt;&lt;LI&gt;Server is still starting the job and replies with 500&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Taking the job id of the error message and looking at the state with the Web Browser, the job states "succeeded", so I guess it must be some kind of timing problem (see step 3).&lt;/P&gt;&lt;P&gt;Any ideas on that?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;Jens Buchta&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:50:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/exporttilecachetask-estimatetilecacheasync/m-p/721066#M9090</guid>
      <dc:creator>JensBuchta</dc:creator>
      <dc:date>2021-12-12T06:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: ExportTileCacheTask.EstimateTileCacheAsync</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/exporttilecachetask-estimatetilecacheasync/m-p/721067#M9091</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could anyone please comment on why this UnitTest code (MSTest Project) fails in "onCompletedCallback"?&lt;/P&gt;&lt;P&gt;The job itself runs fine and I am able to query results using "CheckEstimateTileCacheSizeJobStatusAsync", but "onCompleteCallback" passes a NullReferenceException.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Jul 2015 09:54:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/exporttilecachetask-estimatetilecacheasync/m-p/721067#M9091</guid>
      <dc:creator>JensBuchta</dc:creator>
      <dc:date>2015-07-17T09:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: ExportTileCacheTask.EstimateTileCacheAsync</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/exporttilecachetask-estimatetilecacheasync/m-p/721068#M9092</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;It seems that the issue is based on the SyncronizationContext. If you just define as below, it doesn't actually set&amp;nbsp; SynchronizationContext.Current so task crashes to it because it is null. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The error that we get isn't very informative in this case and this is something that we need to improve for the future.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a helper class to get WPF syncronization context by &lt;SPAN style="color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px;"&gt;Stephen Toub&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;public static class Helper
&amp;nbsp; {
&amp;nbsp; public static void RunInWpfSyncContext( Func&amp;lt;Task&amp;gt; function )
&amp;nbsp; {
&amp;nbsp;&amp;nbsp; if (function == null) throw new ArgumentNullException("function");
&amp;nbsp;&amp;nbsp; var prevCtx = SynchronizationContext.Current;
&amp;nbsp;&amp;nbsp; try
&amp;nbsp;&amp;nbsp; {
&amp;nbsp; var syncCtx = new DispatcherSynchronizationContext();
&amp;nbsp; SynchronizationContext.SetSynchronizationContext(syncCtx);


&amp;nbsp; var task = function();
&amp;nbsp; if (task == null) throw new InvalidOperationException();


&amp;nbsp; var frame = new DispatcherFrame();
&amp;nbsp; var t2 = task.ContinueWith(x=&amp;gt;{frame.Continue = false;}, TaskScheduler.Default);
&amp;nbsp; Dispatcher.PushFrame(frame);&amp;nbsp;&amp;nbsp; // execute all tasks until frame.Continue == false


&amp;nbsp; task.GetAwaiter().GetResult(); // rethrow exception when task has failed 
&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp; finally
&amp;nbsp;&amp;nbsp; { 
&amp;nbsp; SynchronizationContext.SetSynchronizationContext(prevCtx);
&amp;nbsp;&amp;nbsp; }
&amp;nbsp; }
&amp;nbsp; }&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And you can run the test like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN&gt;private const string MapServerUri = "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http://sampleserver6.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer" target="_blank"&gt;http://sampleserver6.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer&lt;/A&gt;&lt;SPAN&gt;";&lt;/SPAN&gt;


[TestMethod]
public async Task EstimateTileCacheSize()
{
&amp;nbsp; // Run test in WPF syncronization context
&amp;nbsp; Helper.RunInWpfSyncContext(async () =&amp;gt;
&amp;nbsp; {
&amp;nbsp; Assert.IsNotNull(SynchronizationContext.Current);


&amp;nbsp; // Create completation source to see when onCompletedCallback is called
&amp;nbsp; var tcs = new TaskCompletionSource&amp;lt;Tuple&amp;lt;EstimateTileCacheSizeResult, Exception&amp;gt;&amp;gt;();


&amp;nbsp; // Create filter
&amp;nbsp; var filter = Envelope.FromJson(
&amp;nbsp; "{\"xmin\":-123.96726562499894,\"ymin\":36.737415380601156,\"xmax\":-119.57273437500105,\"ymax\":38.481185065451001,\"spatialReference\":{\"wkid\":4326}}");


&amp;nbsp; var options = new GenerateTileCacheParameters
&amp;nbsp; {
&amp;nbsp; Format = ExportTileCacheFormat.TilePackage,
&amp;nbsp; GeometryFilter = filter,
&amp;nbsp; };


&amp;nbsp; ExportTileCacheTask exportTilesTask = new ExportTileCacheTask(new Uri(MapServerUri));


&amp;nbsp; // Create job and await that it's submitted ok.
&amp;nbsp; ExportTileCacheJob estimateJob = await exportTilesTask.EstimateTileCacheSizeAsync(options,
&amp;nbsp; (result, ex) =&amp;gt;
&amp;nbsp; {
&amp;nbsp; tcs.SetResult(Tuple.Create(result, ex));
&amp;nbsp; },
&amp;nbsp; TimeSpan.FromSeconds(3),
&amp;nbsp; CancellationToken.None);


&amp;nbsp; // Wait until onCompletedCallback is called. This prevents unit test to complete before we get the results.
&amp;nbsp; var results = await tcs.Task;


&amp;nbsp; Assert.IsNotNull(results.Item1);
&amp;nbsp; Assert.IsNull(results.Item2);
&amp;nbsp; });
}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:51:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/exporttilecachetask-estimatetilecacheasync/m-p/721068#M9092</guid>
      <dc:creator>AnttiKajanus1</dc:creator>
      <dc:date>2021-12-12T06:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: ExportTileCacheTask.EstimateTileCacheAsync</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/exporttilecachetask-estimatetilecacheasync/m-p/721069#M9093</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Antti,&lt;/P&gt;&lt;P&gt;thanks a lot for your reply!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using your Helper-Class, I am able to unit test the class right now, great!&lt;/P&gt;&lt;P&gt;Just for reference, if other users come across this, here is some detail information about the helper class:&lt;/P&gt;&lt;P&gt;&lt;A href="http://blogs.msdn.com/b/pfxteam/archive/2012/01/20/10259049.aspx"&gt;http://blogs.msdn.com/b/pfxteam/archive/2012/01/20/10259049.aspx&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://blogs.msdn.com/b/pfxteam/archive/2012/01/21/10259307.aspx"&gt;http://blogs.msdn.com/b/pfxteam/archive/2012/01/21/10259307.aspx&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;Jens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Jul 2015 06:43:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/exporttilecachetask-estimatetilecacheasync/m-p/721069#M9093</guid>
      <dc:creator>JensBuchta</dc:creator>
      <dc:date>2015-07-24T06:43:20Z</dc:date>
    </item>
    <item>
      <title>Re: ExportTileCacheTask.EstimateTileCacheAsync</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/exporttilecachetask-estimatetilecacheasync/m-p/721070#M9094</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good to know. Can you mark this thread answered, please?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Jul 2015 09:17:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/exporttilecachetask-estimatetilecacheasync/m-p/721070#M9094</guid>
      <dc:creator>AnttiKajanus1</dc:creator>
      <dc:date>2015-07-24T09:17:55Z</dc:date>
    </item>
  </channel>
</rss>

