Esempio n. 1
0
        public void ThrowsWhenGroupIsAddedTwice()
        {
            // Arrange
            var famosFile = new FamosFileHeader();
            var group     = new FamosFileGroup("Group 1");

            famosFile.Groups.Add(group);
            famosFile.Groups.Add(group);

            // Act
            Assert.Throws <FormatException>(() => famosFile.Validate());
        }
Esempio n. 2
0
        public void ThrowsWhenChannelIsAddedTwice()
        {
            // Arrange
            var famosFile = new FamosFileHeader();
            var group     = new FamosFileGroup("Group 1");
            var channel   = new FamosFileChannel("Channel 1");

            group.Channels.Add(channel);
            famosFile.Channels.Add(channel);
            famosFile.Groups.Add(group);

            // Act
            Assert.Throws <FormatException>(() => famosFile.Validate());
        }
Esempio n. 3
0
        public void ThrowsWhenSingleValueIsAddedTwice()
        {
            // Arrange
            var famosFile   = new FamosFileHeader();
            var group       = new FamosFileGroup("Group 1");
            var singleValue = new FamosFileSingleValue <float>("Single Value 1", 1);

            group.SingleValues.Add(singleValue);
            famosFile.SingleValues.Add(singleValue);
            famosFile.Groups.Add(group);

            // Act
            Assert.Throws <FormatException>(() => famosFile.Validate());
        }
Esempio n. 4
0
        public void ThrowsWhenTextIsAddedTwice()
        {
            // Arrange
            var famosFile = new FamosFileHeader();
            var group     = new FamosFileGroup("Group 1");
            var text      = new FamosFileText("Text 1", "Value 1");

            group.Texts.Add(text);
            famosFile.Texts.Add(text);
            famosFile.Groups.Add(group);

            // Act
            Assert.Throws <FormatException>(() => famosFile.Validate());
        }
Esempio n. 5
0
        private void OpenFile(string dataFilePath, DateTime startDateTime, List <ChannelContextGroup> channelContextGroupSet)
        {
            if (File.Exists(dataFilePath))
            {
                throw new Exception($"The file {dataFilePath} already exists. Extending an already existing file with additional channels is not supported.");
            }

            var famosFile = new FamosFileHeader();

            // file
            var metadataGroup = new FamosFileGroup("Metadata");

            metadataGroup.PropertyInfo = new FamosFilePropertyInfo(new List <FamosFileProperty>()
            {
                new FamosFileProperty("format_version", this.FormatVersion),
                new FamosFileProperty("system_name", this.DataWriterContext.SystemName),
                new FamosFileProperty("date_time", startDateTime),
            });

            foreach (var customMetadataEntry in this.DataWriterContext.CustomMetadataEntrySet.Where(customMetadataEntry => customMetadataEntry.CustomMetadataEntryLevel == CustomMetadataEntryLevel.File))
            {
                metadataGroup.PropertyInfo.Properties.Add(new FamosFileProperty(customMetadataEntry.Key, customMetadataEntry.Value));
            }

            famosFile.Groups.Add(metadataGroup);

            // file -> project
            var projectGroup = new FamosFileGroup($"{this.DataWriterContext.ProjectDescription.PrimaryGroupName} / {this.DataWriterContext.ProjectDescription.SecondaryGroupName} / {this.DataWriterContext.ProjectDescription.ProjectName}");

            projectGroup.PropertyInfo = new FamosFilePropertyInfo(new List <FamosFileProperty>()
            {
                new FamosFileProperty("project_version", this.DataWriterContext.ProjectDescription.Version)
            });

            foreach (var customMetadataEntry in this.DataWriterContext.CustomMetadataEntrySet.Where(customMetadataEntry => customMetadataEntry.CustomMetadataEntryLevel == CustomMetadataEntryLevel.Project))
            {
                projectGroup.PropertyInfo.Properties.Add(new FamosFileProperty(customMetadataEntry.Key, customMetadataEntry.Value));
            }

            famosFile.Groups.Add(projectGroup);

            // for each context group
            foreach (var contextGroup in channelContextGroupSet)
            {
                var totalSeconds = (int)Math.Round(_settings.FilePeriod.TotalSeconds, MidpointRounding.AwayFromZero);
                var totalLength  = (int)(totalSeconds * contextGroup.SampleRate.SamplesPerSecond);

                if (totalLength * (double)NexusUtilities.SizeOf(NexusDataType.FLOAT64) > 2 * Math.Pow(10, 9))
                {
                    throw new Exception(ErrorMessage.FamosWriter_DataSizeExceedsLimit);
                }

                // file -> project -> channels
                var field = new FamosFileField(FamosFileFieldType.MultipleYToSingleEquidistantTime);

                foreach (ChannelContext channelContext in contextGroup.ChannelContextSet)
                {
                    var dx      = contextGroup.SampleRate.Period.TotalSeconds;
                    var channel = this.PrepareChannel(field, channelContext.ChannelDescription, (int)totalLength, startDateTime, dx);

                    projectGroup.Channels.Add(channel);
                }

                famosFile.Fields.Add(field);
                _spdToFieldIndexMap[contextGroup.SampleRate.SamplesPerDay] = famosFile.Fields.Count - 1;
            }

            //
            famosFile.Save(dataFilePath, _ => { });
            _famosFile = FamosFile.OpenEditable(dataFilePath);
        }