/// <summary>
        /// Gets Sample Events
        /// </summary>
        /// <param name="seconds">seconds for which the sample data is fetched</param>
        /// <returns>Returns EventsData object</returns>
        public async Task <EventsData> GetSampleEvents(int seconds)
        {
            EventsData eventsData = new EventsData();
            const int  numberOfDocumentsToRead = 500;

            foreach (var batchInput in _batchInputs)
            {
                var connection = Helper.GetSecretFromKeyvaultIfNeeded(batchInput.Properties.Connection);
                var wasbPath   = Helper.GetSecretFromKeyvaultIfNeeded(batchInput.Properties.Path);

                if (!Uri.TryCreate(wasbPath, UriKind.Absolute, out var uri))
                {
                    throw new ArgumentException($"Malformed Uri for the blob path:'{wasbPath}'. The blob path should be a wasbs url. e.g. wasbs://[email protected]/mypath");
                }

                var path          = uri.Host + "/" + uri.UserInfo + uri.LocalPath;
                var pathPattern   = BlobHelper.GenerateRegexPatternFromPath(path);
                var containerName = uri.UserInfo;
                var prefix        = BlobHelper.ParsePrefix(wasbPath);

                var contents = await BlobHelper.GetLastModifiedBlobContentsInBlobPath(connection, containerName, prefix, pathPattern, numberOfDocumentsToRead).ConfigureAwait(false);

                foreach (var content in contents)
                {
                    // Get raw data
                    EventRaw er = new EventRaw
                    {
                        Raw        = content,
                        Properties = new Dictionary <string, string>()
                        {
                            { "Length", content.Length.ToString() }
                        },
                        SystemProperties = new Dictionary <string, string>()
                        {
                            { "Length", content.Length.ToString() }
                        }
                    };

                    er.Json = JsonConvert.SerializeObject(er);

                    eventsData.EventsJson += er.Json + "\r\n";

                    eventsData.Events.Add(er);
                }
            }

            return(eventsData);
        }
예제 #2
0
        public void BlobPathPrefixTest()
        {
            List <Tuple <string, string, string, string> > blobPaths = new List <Tuple <string, string, string, string> >
            {
                new Tuple <string, string, string, string>(
                    @"wasbs://[email protected]/mypath/mypath2/mypath3/{yyyy}/{MM}/{dd}",
                    "mycontainer",
                    @"mypath/mypath2/mypath3/",
                    @"mysa.blob.core.windows.net/mycontainer/mypath/mypath2/mypath3/(\w+)/(\w+)/(\w+)"
                    ),
                new Tuple <string, string, string, string>(
                    @"wasbs://[email protected]/mypath/mypath2/mypath3/2018/07/12/subfolder/00/test",
                    "mycontainer",
                    @"mypath/mypath2/mypath3/2018/07/12/subfolder/00/test",
                    @"mysa.blob.core.windows.net/mycontainer/mypath/mypath2/mypath3/2018/07/12/subfolder/00/test"
                    ),
                new Tuple <string, string, string, string>(
                    @"wasbs://[email protected]/Test/{yyyy-MM-dd}",
                    "myoutputs",
                    @"Test/",
                    @"somesa.blob.core.windows.net/myoutputs/Test/(\w+)-(\w+)-(\w+)"
                    ),
                new Tuple <string, string, string, string>(
                    @"wasbs://[email protected]/{yyyy-MM-dd}",
                    "myoutputs",
                    @"",
                    @"somesa.blob.core.windows.net/myoutputs/(\w+)-(\w+)-(\w+)"
                    ),
                new Tuple <string, string, string, string>(
                    @"wasbs://[email protected]/Test/{yyyy}/{MM}/{dd}",
                    "myoutputs",
                    @"Test/",
                    @"somesa.blob.core.windows.net/myoutputs/Test/(\w+)/(\w+)/(\w+)"
                    ),
                new Tuple <string, string, string, string>(
                    @"wasbs://[email protected]/{yyyy}/{MM}/{dd}",
                    "myoutputs",
                    @"",
                    @"somesa.blob.core.windows.net/myoutputs/(\w+)/(\w+)/(\w+)"
                    ),
                new Tuple <string, string, string, string>(
                    @"wasbs://[email protected]/{yyyy}/{MM}/{dd}/Test",
                    "myoutputs",
                    @"",
                    @"somesa.blob.core.windows.net/myoutputs/(\w+)/(\w+)/(\w+)/Test"
                    ),
                new Tuple <string, string, string, string>(
                    @"wasbs://[email protected]/{yyyy-MM-dd}/Test",
                    "myoutputs",
                    @"",
                    @"somesa.blob.core.windows.net/myoutputs/(\w+)-(\w+)-(\w+)/Test"
                    ),
                new Tuple <string, string, string, string>(
                    @"wasbs://[email protected]/mypath/mypath2/mypath3/{yyyy/MM/dd}",
                    "mycontainer",
                    @"mypath/mypath2/mypath3/",
                    @"mysa.blob.core.windows.net/mycontainer/mypath/mypath2/mypath3/(\w+)/(\w+)/(\w+)"
                    ),
                new Tuple <string, string, string, string>(
                    @"wasbs://[email protected]/mypath/mypath2/mypath3/{yyyy/MM/dd}/test",
                    "mycontainer",
                    @"mypath/mypath2/mypath3/",
                    @"mysa.blob.core.windows.net/mycontainer/mypath/mypath2/mypath3/(\w+)/(\w+)/(\w+)/test"
                    )
            };

            foreach (var blobPath in blobPaths)
            {
                var wasbPath = blobPath.Item1;
                if (!Uri.TryCreate(wasbPath, UriKind.Absolute, out var uri))
                {
                    Assert.Fail("blob path is incorrect");
                }

                var containerName = uri.UserInfo;
                Assert.AreEqual(blobPath.Item2, containerName, "container name is incorrect");

                var path        = uri.Host + "/" + uri.UserInfo + uri.LocalPath;
                var pathPattern = BlobHelper.GenerateRegexPatternFromPath(path);
                Assert.AreEqual(blobPath.Item4, pathPattern, "pattern is incorrect");

                var prefix = BlobHelper.ParsePrefix(wasbPath);
                Assert.AreEqual(blobPath.Item3, prefix, "Prefix generation is incorrect");
            }
        }