private async Task GetItemVersionsAsync(Credentials credentials, string hubId, string folderUrn, string itemHref, PerformContext context) { await credentials.RefreshAsync(); BackgroundJobClient metadataQueue = new BackgroundJobClient(); IState state = new EnqueuedState("metadata"); // the API SDK ItemsApi itemApi = new ItemsApi(); itemApi.Configuration.AccessToken = credentials.TokenInternal; // extract the projectId & itemId from the href string[] idParams = itemHref.Split('/'); string itemUrn = idParams[idParams.Length - 1]; string projectId = idParams[idParams.Length - 3]; var item = await itemApi.GetItemAsync(projectId, itemUrn); string versionUrn = (string)item.data.relationships.tip.data.id; string fileName = (string)item.data.attributes.displayName; string extension = fileName.Split(".").Last().ToLower(); if (Config.SupportedFormats.IndexOf(extension) == -1) { return; } string absolutePath = string.Format("/manifest/_doc/{0}", ModelDerivativeController.Base64Encode(itemUrn)); RestClient client = new RestClient(Config.ElasticSearchServer); RestRequest request = new RestRequest(absolutePath, RestSharp.Method.GET); if (!string.IsNullOrEmpty(Config.AWSKey) && !string.IsNullOrEmpty(Config.AWSSecret)) { SortedDictionary <string, string> headers = AWS.Signature.SignatureHeader( Amazon.RegionEndpoint.GetBySystemName(Config.AWSRegion), new Uri(Config.ElasticSearchServer).Host, "GET", string.Empty, absolutePath); foreach (var entry in headers) { request.AddHeader(entry.Key, entry.Value); } } IRestResponse res = await client.ExecuteTaskAsync(request); if (res.StatusCode == HttpStatusCode.OK && Config.SkipAlreadyIndexed) { context.WriteLine(string.Format("{0}: already indexed, skip", fileName)); System.Threading.Thread.Sleep(1000); // otherwise we'll reach the rate limit... return; } context.WriteLine(string.Format("{0}: {1}", fileName, versionUrn)); await ModelDerivativeHub.NotifyFileFound(_hubContext, hubId); metadataQueue.Create(() => ProcessFile(credentials.UserId, hubId, projectId, folderUrn, itemUrn, versionUrn, fileName, null), state); }