コード例 #1
0
        private async Task <List <DeserializedInfo> > GetToolsAsync()
        {
            Logger.LogDebug("Getting tools list from ToolShed.");
            using var client = new HttpClient();
            HttpResponseMessage response = await client.GetAsync(new Uri(Repo.URI + _repositoriesEndpoint)).ConfigureAwait(false);

            string content;

            if (response.IsSuccessStatusCode)
            {
                content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
            }
            else
            {
                /// TODO: replace with an exception.
                return(null);
            }

            Logger.LogDebug("Received tools from ToolShed, deserializing them.");
            DeserializedInfo.TryDeserialize(
                content,
                ToolJsonSerializerSettings,
                ToolRepoAssoJsonSerializerSettings,
                out List <DeserializedInfo> deserializedInfos);
            foreach (var info in deserializedInfos)
            {
                info.SetStagingArea(SessionTempPath);
            }
            return(deserializedInfos);
        }
コード例 #2
0
        private void TraverseArchive(string archiveFileName)
        {
            try
            {
                using ZipArchive archive = ZipFile.OpenRead(archiveFileName);
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.FullName.EndsWith("meta.yaml", StringComparison.OrdinalIgnoreCase))
                    {
                        string extractedFileName = SessionTempPath + Utilities.GetRandomString() + ".yaml";
                        try
                        {
                            entry.ExtractToFile(extractedFileName);
                            using var reader = new StreamReader(extractedFileName);
                            var yaml = new YamlStream();
                            yaml.Load(reader);
                            if (!DeserializedInfo.TryDeserialize(yaml, out DeserializedInfo deserializedInfo))
                            {
                                Logger.LogInformation($"Cannot deserialize tool info from {entry.FullName}.");
                                continue;
                            }

                            if (deserializedInfo.ToolRepoAssociation != null &&
                                deserializedInfo.ToolRepoAssociation.Tool != null &&
                                deserializedInfo.ToolRepoAssociation.Tool.Name != null &&
                                _addedDates.ContainsKey(deserializedInfo.ToolRepoAssociation.Tool.Name))
                            {
                                deserializedInfo.ToolRepoAssociation.DateAddedToRepository =
                                    _addedDates[deserializedInfo.ToolRepoAssociation.Tool.Name];
                            }

                            if (!TryAddEntities(deserializedInfo))
                            {
                                // TODO: log why this tool will not be added to db.
                            }
                        }
                        catch (Exception e) when(e is YamlDotNet.Core.YamlException ||
                                                 e is YamlDotNet.Core.SyntaxErrorException ||
                                                 e is YamlDotNet.Core.SemanticErrorException)
                        {
                            Logger.LogDebug($"Cannot parse the YAML file {entry.FullName}: {e.Message}");
                        }
                        finally
                        {
                            File.Delete(extractedFileName);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.LogError($"Error occurred traversing Bioconda repository: {e.Message}");
            }
            finally
            {
                File.Delete(archiveFileName);
            }
        }
コード例 #3
0
        private void TraverseArchive(string archiveFileName)
        {
            try
            {
                using ZipArchive archive = ZipFile.OpenRead(archiveFileName);
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.FullName.EndsWith(".json", StringComparison.OrdinalIgnoreCase) &&
                        !entry.FullName.EndsWith("oeb.json", StringComparison.OrdinalIgnoreCase))
                    {
                        string extractedFileName = SessionTempPath + Utilities.GetRandomString() + ".json";
                        try
                        {
                            entry.ExtractToFile(extractedFileName);
                            using var reader = new StreamReader(extractedFileName);
                            if (!DeserializedInfo.TryDeserialize(
                                    reader.ReadToEnd(),
                                    ToolJsonSerializerSettings,
                                    ToolRepoAssoJsonSerializerSettings,
                                    PublicationSerializerSettings,
                                    CategorySerializerSettings,
                                    out DeserializedInfo deserializedInfo))
                            {
                                // TODO: log this.
                                continue;
                            }

                            if (!TryAddEntities(deserializedInfo))
                            {
                                // TODO: log why this tool will not be added to db.
                            }
                        }
                        catch (IOException e)
                        {
                            // TODO: log this.
                        }
                        finally
                        {
                            File.Delete(extractedFileName);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // TODO: log the exception.
                // TODO: if this exception has occurred, the caller job's status should be set to failed.
            }
            finally
            {
                File.Delete(archiveFileName);
            }
        }