/// <inheritdoc />
        public Task CreateDataAsync(TelemetryEvent <TContext> telemetry)
        {
            return(Task.Run(() =>
            {
                string filePath = this.GetFilePath(telemetry.EventName, telemetry.CorrelationId);
                string fileDirectory = Path.GetDirectoryName(filePath);
                string fileContent = FileSystemTelemetryDataStore <TContext> .SerializeItem(telemetry);

                if (!Directory.Exists(fileDirectory))
                {
                    Directory.CreateDirectory(fileDirectory);
                }

                File.WriteAllText(filePath, fileContent);
            }));
        }
        /// <inheritdoc />
        public Task <IEnumerable <TelemetryEvent <TContext> > > SearchDataAsync(FilterOptions filter = null)
        {
            return(Task.Run(() =>
            {
                List <TelemetryEvent <TContext> > matchingEvents = new List <TelemetryEvent <TContext> >();

                if (filter.EventName == null && filter.CorrelationId != null)
                {
                    throw new NotSupportedException(
                        "When a correlation ID is provided in the filter, an event name must be provided as well.");
                }

                FileInfo[] matchingFiles = null;
                DirectoryInfo matchingDirectory = new DirectoryInfo(this.GetFilePath(filter));
                if (matchingDirectory.Exists)
                {
                    if (filter.CorrelationId != null)
                    {
                        // A given correlation ID corresponds to a single directory only.
                        matchingFiles = matchingDirectory.GetFiles("*.json", SearchOption.TopDirectoryOnly);
                    }
                    else if (filter.Latest == true)
                    {
                        DirectoryInfo latestDirectory = matchingDirectory.GetDirectories()?.OrderByDescending(dir => dir.CreationTime)
                                                        .FirstOrDefault();

                        matchingFiles = latestDirectory?.GetFiles("*.json");
                    }
                    else
                    {
                        matchingFiles = matchingDirectory.GetFiles("*.json", SearchOption.AllDirectories);
                    }

                    if (matchingFiles != null)
                    {
                        foreach (FileInfo file in matchingFiles)
                        {
                            string fileContent = File.ReadAllText(file.FullName);
                            matchingEvents.Add(FileSystemTelemetryDataStore <TContext> .DeserializeItem(fileContent));
                        }
                    }
                }

                return matchingEvents as IEnumerable <TelemetryEvent <TContext> >;
            }));
        }