Ejemplo n.º 1
0
        //TODO: Exception handling, throwing exception when for file directory there is no file. When there is no date, set DateTime.Now
        private async Task <MeteoDataFileUrl> GetMeteoDataFileUrlAsync(MeteoDataFileDirectory fileDirectory)
        {
            var root = await GetRootDocumentAsync(fileDirectory.DirectoryUrl);

            var rowWithMeteoDataZip = GetRowsWithMeteoData(root, _zipRegex).FirstOrDefault();


            if (rowWithMeteoDataZip != null)
            {
                var anchorNode = GetChildAnchorNode(rowWithMeteoDataZip, _zipRegex);
                var dateNode   = GetChildAnchorNode(rowWithMeteoDataZip, _dateRegex);

                if (anchorNode != null && dateNode != null)
                {
                    var meteoDataFileUrl = new MeteoDataFileUrl(
                        anchorNode.TextContent,
                        $"{anchorNode.BaseUri}{anchorNode.TextContent}",
                        DateTime.Parse(dateNode.TextContent));

                    return(meteoDataFileUrl);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        private IEnumerable <MeteoDataFileDirectory> GetMetoeDataFileDirectoriesFromRows(IEnumerable <IElement> rows)
        {
            var meteoDataDirectories = new List <MeteoDataFileDirectory>();

            rows.Aggregate(meteoDataDirectories,
                           (list, element) =>
            {
                var anchorNode = GetChildAnchorNode(element, _folderNameRegexTemplate);
                var dateNode   = GetChildAnchorNode(element, _dateRegex);

                if (anchorNode != null && dateNode != null)
                {
                    var meteoDataFileDirectory          = new MeteoDataFileDirectory();
                    meteoDataFileDirectory.DirectoryUrl = $"{anchorNode.BaseUri}{anchorNode.TextContent}";
                    meteoDataFileDirectory.ModifyDate   = DateTime.Parse(dateNode.TextContent);

                    list.Add(meteoDataFileDirectory);
                }

                return(list);
            });

            return(meteoDataDirectories);
        }