public static IEventStoreConnection Create(EventStoreLocation eventStoreLocation, IEventStoreConfiguration configuration)
        {
            IEventStore eventStore;

            if (eventStoreLocation == EventStoreLocation.Embedded)
            {
                eventStore = new EmbeddedEventStore();
            }
            else
            {
                eventStore = new ExternalEventStore(EventStoreUri.FromConfig(configuration));
            }

            return(eventStore.Connection);
        }
        public static IEventStoreConnection Create(EventStoreLocation eventStoreLocation, IEventStoreConfiguration configuration)
        {
            IEventStore eventStore;

            if (eventStoreLocation == EventStoreLocation.Embedded)
            {
                //eventStore = new EmbeddedEventStore();
                throw new NotSupportedException();
            }
            else
            {
                eventStore = new ExternalEventStore(EventStoreUri.FromConfig(configuration));
            }

            return eventStore.Connection;
        }
示例#3
0
        private TeslaEvent ParseEvent(IReadOnlyList <StorageFile> files, string filePath, string eventText)
        {
            var folderName = _eventFolderNameRegex.Match(filePath).Groups["EventFolderName"].Value;

            EventStoreLocation storeLocation = EventStoreLocation.Unkown;

            if (filePath.Contains(SavedClipsFolderName, StringComparison.InvariantCultureIgnoreCase))
            {
                storeLocation = EventStoreLocation.SavedClip;
            }
            else if (filePath.Contains(SentryClipsFolderName, StringComparison.InvariantCultureIgnoreCase))
            {
                storeLocation = EventStoreLocation.SentryClip;
            }

            var metadata = JsonSerializer.Deserialize <TeslaEventJson>(eventText);

            var teslaEvent = new TeslaEvent(metadata);

            teslaEvent.StoreLocation = storeLocation;
            teslaEvent.FolderPath    = filePath;

            var thumbnailFile = files.FirstOrDefault(f => f.FileType.Equals(EventThumbnailFileExtension) && f.Path.Contains(folderName));

            if (thumbnailFile != null)
            {
                teslaEvent.ThumbnailFile = thumbnailFile;
                teslaEvent.ThumbnailPath = thumbnailFile.Path;
            }

            var results = files.Where(f => f.Path.Contains(folderName) && f.FileType.Equals(EventVideoFileExtension)).GroupBy(
                f => ParseTimestampFromFilename(f.Name),
                f => f,
                (key, g) => new { SegmentTimestamp = key, ClipFiles = g.ToList() });


            foreach (var fileGroup in results.OrderBy(r => r.SegmentTimestamp))
            {
                var eventSegment = new EventSegment();
                eventSegment.SegmentTimestamp = fileGroup.SegmentTimestamp;

                eventSegment.Clips = new List <Clip>();
                foreach (var clipFile in fileGroup.ClipFiles)
                {
                    eventSegment.Clips.Add(ParseClipFile(clipFile));
                }

                teslaEvent.Segments.Add(eventSegment);
            }

            // Link event timestamps
            for (int i = 0; i < teslaEvent.Segments.Count - 1; i++)
            {
                teslaEvent.Segments[i].NextSegmentTimestamp = teslaEvent.Segments[i + 1].SegmentTimestamp;
            }

            // Sets flag if a segment period contains the event timestamp
            var hotSegment = teslaEvent.Segments.Where(s => s.SegmentTimestamp < teslaEvent.Timestamp && (!s.NextSegmentTimestamp.HasValue || teslaEvent.Timestamp < s.NextSegmentTimestamp.Value)).FirstOrDefault();

            if (hotSegment != null)
            {
                hotSegment.ContainsEventTimestamp = true;
            }
            return(teslaEvent);
        }