public async Task <bool> WriteData(JObject root, ISessionWriter writer)
        {
            var pathArr = Meta["attachments"].ToObject <string[]>() ?? throw new ArgumentException("Table is missing 'attachments'");

            //TODO: Implement?
            if (false && IsSaved)
            {
                var stream = await _archive.OpenFile(_zipEntry);

                writer.StoreFileId(stream, pathArr[0]);
            }
            else
            {
                // This stream will be disposed by the sessionWriter
                var ms = new MemoryStream();

                // Make a copy of the Remembering reader that later can be discarded
                // This to avoid to read in all tables in memory at the same time.
                var fullReader = new RememberingParquetReader(_reader);
                fullReader.LoadAll();
                using (var tableWriter = new ParquetWriter(fullReader.Schema, ms))
                {
                    using (var rowGroup = tableWriter.CreateRowGroup())  // Using construction assure correct storage of final rowGroup details in parquet file
                    {
                        foreach (var field in fullReader.Schema.GetDataFields())
                        {
                            var column = new DataColumn(field, fullReader.GetColumn(field));
                            rowGroup.WriteColumn(column);
                        }
                    }
                }

                ms.Position = 0;
                writer.StoreFileId(ms, pathArr[0]);
            }

            // TODO AUTOACTIVE-58 - Generalize copy of previous metadata for save

            // Copy previous
            root["meta"] = Meta;
            root["user"] = User;

            // Overwrite potentially changed
            // TODO root["meta"]["is_world_clock"] = ;
            // TODO root["meta"]["synced_to"] =  ;

            return(true);
        }
Example #2
0
        public Task <bool> WriteTable(string fileId, ISessionWriter writer)
        {
            // This stream will be disposed by the sessionWriter
            var ms = new MemoryStream();

            var dataColAndSchema = MakeDataColumnAndSchema();

            using (var tableWriter = new Parquet.ParquetWriter(dataColAndSchema.Schema, ms))
            {
                //tableWriter.CompressionMethod = Parquet.CompressionMethod.Gzip;

                using (var rowGroup = tableWriter.CreateRowGroup())  // Using construction assure correct storage of final rowGroup details in parquet file
                {
                    foreach (var dataCol in dataColAndSchema.DataColumns)
                    {
                        rowGroup.WriteColumn(dataCol);
                    }
                }
            }

            ms.Position = 0;
            writer.StoreFileId(ms, fileId);

            return(Task.FromResult(true));
        }
Example #3
0
        public async Task <bool> WriteData(JObject root, ISessionWriter writer)
        {
            Stream stream;
            string fileId;

            if (_readerFactory == null)
            {
                var pathArr = Meta["attachments"].ToObject <string[]>() ??
                              throw new ArgumentException("Video is missing 'attachments'");
                stream = await _archive.OpenFile(_zipEntry);

                fileId = pathArr[0];
            }
            else
            {
                stream = await _readerFactory.GetReadStream();

                // TODO: give a better name?
                fileId = "/videos" + "/" + Name + "." + Guid.NewGuid();
                Meta["attachments"] = new JArray(new object[] { fileId });
            }

            writer.StoreFileId(stream, fileId);

            var offset = _video.VideoTime.Offset;

            // TODO AUTOACTIVE-58 - Generalize copy of previous metadata for save

            // Copy previous
            root["meta"] = Meta;
            root["user"] = User;

            // Overwrite potentially changed
            root["meta"]["start_time"]   = offset;
            root["meta"]["video_length"] = _video.VideoTime.VideoLength;
            // TODO root["meta"]["is_world_clock"] =  ;
            // TODO root["meta"]["synced_to"] =  ;

            return(true);
        }
        public virtual async Task <bool> WriteData(JObject root, ISessionWriter writer)
        {
            if (Meta.ContainsKey("attachments"))
            {
                // There are attachments...
                var pathArr = Meta["attachments"].ToObject <string[]>();
                foreach (var path in pathArr)
                {
                    // Fetch from sourceArchive
                    var fullSourcePath = "" + _sourceSessionId + path;
                    var zipEntry       = _archive.FindFile(fullSourcePath) ?? throw new ZipException($"{Meta["type"]} file '{path}' not found in archive");
                    var stream         = await _archive.OpenFile(zipEntry);

                    // Store in new session
                    writer.StoreFileId(stream, path);
                }
            }

            // Copy previous
            root["meta"] = Meta;
            root["user"] = User;

            return(true);
        }