public void Append(DateTime timestamp, IEnumerable <double> values, string tag = null)
        {
            if (Session.DocumentsById.TryGetValue(DocId, out DocumentInfo documentInfo) &&
                Session.DeletedEntities.Contains(documentInfo.Entity))
            {
                ThrowDocumentAlreadyDeletedInSession(DocId, Name);
            }

            var op = new TimeSeriesOperation.AppendOperation
            {
                Timestamp = timestamp.EnsureUtc(),
                Tag       = tag,
                Values    = values.ToArray()
            };

            if (Session.DeferredCommandsDictionary.TryGetValue((DocId, CommandType.TimeSeries, Name), out var command))
            {
                var tsCmd = (TimeSeriesBatchCommandData)command;
                tsCmd.TimeSeries.Append(op);
            }
Beispiel #2
0
        public void RavenDB_14877()
        {
            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new User(), "users/1-A");
                    session.SaveChanges();
                }

                var op = new TimeSeriesOperation.AppendOperation
                {
                    Timestamp = DateTime.Now,
                    Tag       = "as",
                    Values    = new double[] { 73 }
                };
                var op2 = new TimeSeriesOperation.AppendOperation
                {
                    Timestamp = DateTime.Now,
                    Tag       = "as",
                    Values    = new double[] { 78 }
                };
                var op3 = new TimeSeriesOperation.AppendOperation
                {
                    Timestamp = new DateTime(2019, 4, 23) + TimeSpan.FromMinutes(5),
                    Tag       = "as",
                    Values    = new double[] { 798 }
                };

                var a = new TimeSeriesOperation
                {
                    Name = "test",
                };
                a.Append(op3);
                a.Append(op2);
                a.Append(op);
                store.Operations.Send(new TimeSeriesBatchOperation("users/1-A", a));

                var opDelete = new TimeSeriesOperation.DeleteOperation
                {
                    From = DateTime.Now - TimeSpan.FromDays(2),
                    To   = DateTime.Now + TimeSpan.FromDays(2)
                };

                var ab = new TimeSeriesOperation
                {
                    Name = "test",
                };
                ab.Delete(opDelete);
                store.Operations.Send(new TimeSeriesBatchOperation("users/1-A", ab));

                var abc = new TimeSeriesOperation
                {
                    Name = "test",
                };
                abc.Delete(new TimeSeriesOperation.DeleteOperation {
                    From = DateTime.MinValue, To = DateTime.MaxValue
                });
                store.Operations.Send(new TimeSeriesBatchOperation("users/1-A", abc));
                var ts = store.Operations.Send(new GetTimeSeriesOperation("users/1-A", "test", DateTime.MinValue, DateTime.MaxValue));

                // GetTimeSeriesOperation should return null on non-existing timeseries
                Assert.Null(ts);
            }
        }