async Task DownloadSyncModel(StreamAsset streamAsset, CancellationToken token)
        {
            var result = new ObjectDownloadResult();

            try
            {
                result.assetEntry = await DownloadSyncModel(streamAsset.key, streamAsset.hash, token);
            }
            catch (Exception ex)
            {
                result.exception = ex;
                m_DownloadedModels.Enqueue(result);
                return;
            }

            var tasks = new List <Task <AssetEntry <ISyncModel> > >();

            if (result.assetEntry.asset is SyncMaterial syncMaterial)
            {
                DownloadTextures(streamAsset.key.source, syncMaterial, ref tasks, token);
            }

            try
            {
                await Task.WhenAll(tasks);

                foreach (var task in tasks)
                {
                    m_DownloadedModels.Enqueue(new ObjectDownloadResult {
                        assetEntry = task.Result
                    });
                }

                m_DownloadedModels.Enqueue(new ObjectDownloadResult {
                    assetEntry = result.assetEntry
                });
            }
            catch (Exception ex)
            {
                foreach (var task in tasks)
                {
                    m_DownloadedModels.Enqueue(new ObjectDownloadResult {
                        exception = task.Exception
                    });
                }

                result.exception = ex;
                m_DownloadedModels.Enqueue(result);
            }
        }
Example #2
0
        async Task DownloadInstance(StreamAsset request, CancellationToken token)
        {
            DownloadResult result;

            try
            {
                var instance = (SyncObjectInstance)await m_Client.GetSyncModelAsync(request.key, request.hash); // TODO Cancellation Token

                result = new DownloadResult(request, instance, null);
            }
            catch (Exception ex)
            {
                result = new DownloadResult(request, null, ex);
            }

            m_DownloadResults.Enqueue(result);
        }
Example #3
0
        async Task GetManifests(CancellationToken token)
        {
            var time  = DateTime.Now;
            var start = time;

            var manifests = await m_Client.GetSyncManifestsAsync(); // TODO Cancellation Token

            m_GettingSourcesTime = GetElapsedTime(ref time);

            foreach (var manifest in manifests)
            {
                token.ThrowIfCancellationRequested();

                // Parse SyncManifest
                var newManifest = manifest;

                m_Manifests.TryGetValue(manifest.SourceId, out var oldManifest);

                // Update the hash cache before sending events
                m_Manifests[manifest.SourceId] = newManifest.Content.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

                if (oldManifest != null)
                {
                    ComputeDiff(oldManifest, newManifest.Content, out var addedEntries, out var modifiedEntries, out var removedEntries);

                    foreach (var manifestEntry in addedEntries)
                    {
                        token.ThrowIfCancellationRequested();

                        var reference = new StreamAsset(manifest.SourceId, manifestEntry.key, manifestEntry.entry.Hash, manifestEntry.entry.BoundingBox);
                        m_PendingAdded.Enqueue(reference);
                    }

                    foreach (var manifestEntry in modifiedEntries)
                    {
                        token.ThrowIfCancellationRequested();

                        var key = manifestEntry.key;

                        var reference = new StreamAsset(manifest.SourceId, key, manifestEntry.entry.Hash, manifestEntry.entry.BoundingBox);
                        m_PendingModified.Enqueue(reference);
                    }

                    foreach (var manifestEntry in removedEntries)
                    {
                        token.ThrowIfCancellationRequested();

                        var reference = new StreamAsset(manifest.SourceId, manifestEntry.key, manifestEntry.entry.Hash, manifestEntry.entry.BoundingBox);
                        m_PendingRemoved.Enqueue(reference);
                    }
                }
                else
                {
                    foreach (var manifestEntry in manifest.Content)
                    {
                        token.ThrowIfCancellationRequested();

                        if (!manifestEntry.Key.IsKeyFor <SyncObjectInstance>())
                        {
                            continue;
                        }

                        var reference = new StreamAsset(manifest.SourceId, manifestEntry.Key, manifestEntry.Value.Hash, manifestEntry.Value.BoundingBox);
                        m_PendingAdded.Enqueue(reference);
                    }
                }
            }

            m_CompareManifests = GetElapsedTime(ref time);

            m_TotalTime = GetElapsedTime(ref start);
        }
Example #4
0
 public DownloadResult(StreamAsset streamAsset, SyncObjectInstance streamInstance, Exception exception)
 {
     this.streamAsset    = streamAsset;
     this.streamInstance = streamInstance;
     this.exception      = exception;
 }
Example #5
0
 void EnqueueDownloadRequest(StreamAsset item)
 {
     m_DownloadRequests.Enqueue(item);
     m_DownloadRequestEvent.Set();
 }