Пример #1
0
        private async Task <List <AiBlobInfo> > GetNewerBlobsFromSameFolderAsync(AiBlobInfo latestFetchedTraceAiBlobInfo)
        {
            // 1: Investigate if new blobs have arrived to the last folder we investigated
            var newBlobsInLastFolder = await _blobReader.GetBlobInfosFromFolderAsync(latestFetchedTraceAiBlobInfo.Folder);

            newBlobsInLastFolder = newBlobsInLastFolder.Where(p => p.LastModified > latestFetchedTraceAiBlobInfo.LastModified).ToList();
            return(newBlobsInLastFolder);
        }
Пример #2
0
        public string[] ToStringsForEveryLine(AiBlobInfo aiBlobInfo)
        {
            var blobRef = _blobClient.GetBlobReferenceFromServer(aiBlobInfo.Uri);

            string text;

            using (var memStream = new MemoryStream())
            {
                blobRef.DownloadToStream(memStream);
                text = Encoding.Default.GetString(memStream.ToArray());
            }
            var stringlines = text.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);

            return(stringlines);
        }
Пример #3
0
        private async void PollTraces(object sender, ElapsedEventArgs e)
        {
            // Stop timer
            var timer = (Timer)sender;

            timer.Stop();

            _latestFetchedTraceAiBlobInfo = await ProcessItemsReturnLatestFetchedBlobAsync(
                topFolder : TracesFolderName
                , latestAiBlob : _latestFetchedTraceAiBlobInfo
                , itemAddingAction : AddTraces);

            // Resume timer
            timer.Start();
        }
Пример #4
0
        private async Task <AiBlobInfo> ProcessItemsReturnLatestFetchedBlobAsync(string topFolder, AiBlobInfo latestAiBlob, Action <List <AiBlobInfo> > itemAddingAction)
        {
            var returnBlob = latestAiBlob;

            if (latestAiBlob == null)
            { // Nothing has been fetched from this folder yet, we will try to do inital population
                //The reason may be: 1. initial populate 2. the folder is missing on the storage 3. no blobs exist in that folder
                latestAiBlob = await _blobReader.GetLatestBlobInfoAsync(topFolder);

                if (latestAiBlob != null)
                {
                    // A blob, time for the initial item-adding!
                    var initalBlobs = await _blobReader.GetBlobInfosFromFolderAsync(latestAiBlob.Folder);

                    itemAddingAction(initalBlobs);
                }
                return(latestAiBlob);
            }

            // We already have items, time to populate new items if any
            // First check for remaining blobs in the lastly checked folder and add them
            var newerBlobsSameFolder = await GetNewerBlobsFromSameFolderAsync(latestAiBlob);

            if (newerBlobsSameFolder != null && newerBlobsSameFolder.Any())
            {
                Console.WriteLine("Add new items from same folder as last!");
                itemAddingAction(newerBlobsSameFolder);
                returnBlob = newerBlobsSameFolder.Last();
            }

            // Then check for blobs in the newest folder if any exist, and add them.
            var newerBlobsInOtherFolder = await GetNewerBlobsFromNewestFolderAsync(topFolder, latestAiBlob);

            if (newerBlobsInOtherFolder != null && newerBlobsInOtherFolder.Any())
            {
                Console.WriteLine("Add new items from completely new folder!");
                itemAddingAction(newerBlobsInOtherFolder);
                returnBlob = newerBlobsInOtherFolder.Last();
            }
            return(returnBlob);
        }
Пример #5
0
        private async Task <List <AiBlobInfo> > GetNewerBlobsFromNewestFolderAsync(string topFolder, AiBlobInfo compareAiBlob)
        {
            var latestBlobInNewestFolder = await _blobReader.GetLatestBlobInfoAsync(topFolder);

            if (latestBlobInNewestFolder == null || latestBlobInNewestFolder.LastModified <= compareAiBlob.LastModified)
            {
                return(null); // Nothing new
            }
            var blobs = await _blobReader.GetBlobInfosFromFolderAsync(latestBlobInNewestFolder.Folder);

            blobs = blobs.Where(p => p.LastModified > compareAiBlob.LastModified).ToList();
            return(blobs);
        }