/// <summary> /// Initializes a new instance of the <see cref="JsonStoreReader"/> class. /// </summary> /// <param name="name">The name of the application that generated the persisted files, or the root name of the files</param> /// <param name="path">The directory in which the main persisted file resides or will reside, or null to create a volatile data store</param> /// <param name="dataSchemaString">JSON schema used to validate data stream.</param> /// <param name="extension">The extension for the underlying file.</param> /// <param name="preloadSchemas">Dictionary of URis to JSON schemas to preload before validating any JSON. Would likely include schemas references by the catalog and data schemas.</param> public JsonStoreReader(string name, string path, string dataSchemaString, string extension = DefaultExtension, IDictionary <Uri, string> preloadSchemas = null) : base(dataSchemaString, extension, preloadSchemas) { this.Name = name; this.Path = StoreCommon.GetPathToLatestVersion(name, path); // load catalog string metadataPath = System.IO.Path.Combine(this.Path, StoreCommon.GetCatalogFileName(this.Name) + this.Extension); using (var file = File.OpenText(metadataPath)) using (var reader = new JsonTextReader(file)) using (var validatingReader = new JSchemaValidatingReader(reader)) { validatingReader.Schema = this.CatalogSchema; validatingReader.ValidationEventHandler += (s, e) => throw new InvalidDataException(e.Message); this.catalog = this.Serializer.Deserialize <List <JsonStreamMetadata> >(validatingReader); } // compute originating time interval this.originatingTimeInterval = TimeInterval.Empty; foreach (var metadata in this.catalog) { var metadataTimeInterval = new TimeInterval(metadata.FirstMessageOriginatingTime, metadata.LastMessageOriginatingTime); this.originatingTimeInterval = TimeInterval.Coverage(new TimeInterval[] { this.originatingTimeInterval, metadataTimeInterval }); } }
private void UpdateOriginatingTimeInterval(IPartition partition) { // compute the new originating time interval var oldOriginatingTimeInterval = this.OriginatingTimeInterval; this.OriginatingTimeInterval = this.Partitions.Count() == 0 ? partition.OriginatingTimeInterval : TimeInterval.Coverage(new TimeInterval[] { this.OriginatingTimeInterval, partition.OriginatingTimeInterval }); }
private SessionImporter(Pipeline pipeline, Session session) { foreach (var partition in session.Partitions) { this.importers.Add(partition.Name, Store.Open(pipeline, partition.StoreName, partition.StorePath)); } this.OriginatingTimeInterval = TimeInterval.Coverage(this.importers.Values.Select(i => i.OriginatingTimeInterval)); this.Name = session.Name; }
/// <inheritdoc /> public TimeInterval OriginatingTimeRange() { TimeInterval timeInterval = TimeInterval.Empty; foreach (var metadata in this.AvailableStreams) { var metadataTimeInterval = new TimeInterval(metadata.FirstMessageOriginatingTime, metadata.LastMessageOriginatingTime); timeInterval = TimeInterval.Coverage(new TimeInterval[] { timeInterval, metadataTimeInterval }); } return(timeInterval); }
private void OnDeserialized(StreamingContext context) { this.OriginatingTimeInterval = TimeInterval.Coverage(this.InternalPartitions.Select(p => p.OriginatingTimeInterval)); foreach (var partition in this.internalPartitions) { partition.Session = this; } this.partitions = new ReadOnlyObservableCollection <IPartition>(this.internalPartitions); this.RaisePropertyChanged(nameof(this.Partitions)); }
public void TimeIntervalCoverage() { var a = new TimeInterval(new DateTime(7), new DateTime(42)); var b = new TimeInterval(new DateTime(40), new DateTime(50)); var c = new TimeInterval(new DateTime(200), new DateTime(100)); // negative var e = TimeInterval.Empty; var empty = TimeInterval.Coverage(new TimeInterval[] { }); var single = TimeInterval.Coverage(new TimeInterval[] { a }); var ab = TimeInterval.Coverage(new TimeInterval[] { a, b }); var ba = TimeInterval.Coverage(new TimeInterval[] { b, a }); var ac = TimeInterval.Coverage(new TimeInterval[] { a, c }); var ca = TimeInterval.Coverage(new TimeInterval[] { c, a }); var ae = TimeInterval.Coverage(new TimeInterval[] { a, e }); var ea = TimeInterval.Coverage(new TimeInterval[] { e, a }); var bc = TimeInterval.Coverage(new TimeInterval[] { b, c }); var cb = TimeInterval.Coverage(new TimeInterval[] { c, b }); var be = TimeInterval.Coverage(new TimeInterval[] { b, e }); var eb = TimeInterval.Coverage(new TimeInterval[] { e, b }); var ce = TimeInterval.Coverage(new TimeInterval[] { c, e }); var ec = TimeInterval.Coverage(new TimeInterval[] { e, c }); Assert.IsTrue(c.IsNegative); Assert.AreEqual(default(DateTime), empty.Right); Assert.AreEqual(default(DateTime), empty.Left); Assert.AreEqual(a.Left, single.Left); Assert.AreEqual(a.Right, single.Right); Assert.AreEqual(ab.Left, a.Left); Assert.AreEqual(ab.Right, b.Right); Assert.AreEqual(ba.Left, a.Left); Assert.AreEqual(ba.Right, b.Right); Assert.AreEqual(ac.Left, a.Left); Assert.AreEqual(ac.Right, c.Left); // c is negative Assert.AreEqual(ae.Left, a.Left); Assert.AreEqual(ae.Right, a.Right); Assert.AreEqual(ea.Left, a.Left); Assert.AreEqual(ea.Right, a.Right); Assert.AreEqual(ca.Left, a.Left); Assert.AreEqual(ca.Right, c.Left); // c is negative Assert.AreEqual(bc.Left, b.Left); Assert.AreEqual(bc.Right, c.Left); // c is negative Assert.AreEqual(cb.Left, b.Left); Assert.AreEqual(cb.Right, c.Left); // c is negative Assert.AreEqual(be.Left, b.Left); Assert.AreEqual(be.Right, b.Right); Assert.AreEqual(eb.Left, b.Left); Assert.AreEqual(eb.Right, b.Right); Assert.AreEqual(ce.Left, c.Right); // c is negative Assert.AreEqual(ec.Right, c.Left); // c is negative Assert.IsTrue(TimeInterval.Coverage(new TimeInterval[] { }).IsEmpty); // empty sequence -> empty interval Assert.IsTrue(TimeInterval.Coverage(new TimeInterval[] { e }).IsEmpty); // sequence of only empty intervals -> empty interval }
private SessionImporter(Pipeline pipeline, Session session) { foreach (var partition in session.Partitions) { var reader = StreamReader.Create(partition.StoreName, partition.StorePath, partition.StreamReaderTypeName); var importer = new Importer(pipeline, reader); this.importers.Add(partition.Name, importer); } this.MessageOriginatingTimeInterval = TimeInterval.Coverage(this.importers.Values.Select(i => i.MessageOriginatingTimeInterval)); this.MessageCreationTimeInterval = TimeInterval.Coverage(this.importers.Values.Select(i => i.MessageCreationTimeInterval)); this.Name = session.Name; }
private void OnDeserialized(StreamingContext context) { this.OriginatingTimeInterval = TimeInterval.Coverage(this.internalSessions.Select(s => s.OriginatingTimeInterval)); this.CurrentSession = this.internalSessions.FirstOrDefault(); foreach (var session in this.internalSessions) { session.Dataset = this; } this.sessions = new ReadOnlyObservableCollection <Session>(this.internalSessions); this.RaisePropertyChanged(nameof(this.Sessions)); }
/// <summary> /// Creates and adds a session to this dataset using the specified parameters. /// </summary> /// <param name="sessionName">The name of the session.</param> /// <param name="storeName">The name of the data store.</param> /// <param name="storePath">The path of the data store.</param> /// <param name="partitionName">The partition name.</param> /// <returns>The newly added session.</returns> public Session AddSessionFromExistingStore(string sessionName, string storeName, string storePath, string partitionName = null) { var session = new Session(this, sessionName); var partition = session.AddStorePartition(storeName, storePath, partitionName); // compute the new originating time interval var oldOriginatingTimeInterval = this.OriginatingTimeInterval; this.OriginatingTimeInterval = this.Sessions.Count() == 0 ? session.OriginatingTimeInterval : TimeInterval.Coverage(new TimeInterval[] { this.OriginatingTimeInterval, session.OriginatingTimeInterval }); // add the session, then raise the event this.internalSessions.Add(session); // make new session current session this.CurrentSession = session; return(session); }
private void ZoomToPanel() { // Get a list of time intervals for all stream visualization objects in this panel List <TimeInterval> streamIntervals = new List <TimeInterval>(); foreach (VisualizationObject visualizationObject in this.VisualizationObjects) { IStreamVisualizationObject streamVisualizationObject = visualizationObject as IStreamVisualizationObject; IStreamMetadata streamMetadata = streamVisualizationObject?.StreamBinding?.StreamMetadata; if (streamMetadata != null) { streamIntervals.Add(new TimeInterval(streamMetadata.FirstMessageOriginatingTime, streamMetadata.LastMessageOriginatingTime)); } } // Zoom to the coverage of the stream visualization objects if (streamIntervals.Count > 0) { TimeInterval panelInterval = TimeInterval.Coverage(streamIntervals); this.Container.Navigator.Zoom(panelInterval.Left, panelInterval.Right); } }
/// <summary> /// Initializes a new instance of the <see cref="JsonStoreReader"/> class. /// </summary> /// <param name="name">The name of the application that generated the persisted files, or the root name of the files.</param> /// <param name="path">The directory in which the main persisted file resides or will reside, or null to create a volatile data store.</param> /// <param name="extension">The extension for the underlying file.</param> public JsonStoreReader(string name, string path, string extension = DefaultExtension) : base(extension) { this.Name = name; this.Path = PsiStoreCommon.GetPathToLatestVersion(name, path); // load catalog string metadataPath = System.IO.Path.Combine(this.Path, PsiStoreCommon.GetCatalogFileName(this.Name) + this.Extension); using (var file = File.OpenText(metadataPath)) using (var reader = new JsonTextReader(file)) { this.catalog = this.Serializer.Deserialize <List <JsonStreamMetadata> >(reader); } // compute originating time interval this.originatingTimeInterval = TimeInterval.Empty; foreach (var metadata in this.catalog) { var metadataTimeInterval = new TimeInterval(metadata.FirstMessageOriginatingTime, metadata.LastMessageOriginatingTime); this.originatingTimeInterval = TimeInterval.Coverage(new TimeInterval[] { this.originatingTimeInterval, metadataTimeInterval }); } }