Пример #1
0
        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);
        }
Пример #2
0
        public async Task IndexHubAsync(string userId, string hubId, PerformContext context)
        {
            Credentials credentials = await Credentials.FromDatabaseAsync(userId);

            // ToDo: check if hub is already indexed

            await IndexProjectsAsync(credentials, hubId, context);

            await ModelDerivativeHub.NotifyHubComplete(_hubContext, hubId);
        }
        public async Task <IActionResult> DerivativeCallback([FromBody] JObject body)
        {
            await ModelDerivativeHub.ExtractionFinished(_hubContext, body);

            return(Ok());
        }
Пример #4
0
        public async Task ProcessFile(string userId, string hubId, string projectId, string folderUrn, string itemUrn, string versionUrn, string fileName, PerformContext console)
        {
            await ModelDerivativeController.ProcessFileAsync(userId, hubId, projectId, folderUrn, itemUrn, versionUrn, fileName, console);

            await ModelDerivativeHub.NotifyFileComplete(_hubContext, hubId);
        }