public void FamosWriterCreatesDatFile()
        {
            // Arrange
            var services = new ServiceCollection();

            ConfigureServices(services);

            var provider   = services.BuildServiceProvider();
            var dataWriter = provider.GetRequiredService <FamosWriter>();

            var projectGuid       = Guid.NewGuid();
            var dataDirectoryPath = Path.Combine(Path.GetTempPath(), projectGuid.ToString());

            Directory.CreateDirectory(dataDirectoryPath);

            var projectDescription     = new NexusProjectDescription(projectGuid, 1, "a", "b", "c");
            var customMetadataEntrySet = new List <CustomMetadataEntry>();
            var dataWriterContext      = new DataWriterContext("Nexus", dataDirectoryPath, projectDescription, customMetadataEntrySet);

            var channelDescriptionSet = new List <ChannelDescription>()
            {
                this.CreateChannelDescription("Var1", "Group1", NexusDataType.FLOAT64, new SampleRateContainer(8640000), "Unit1"),
                this.CreateChannelDescription("Var2", "Group2", NexusDataType.FLOAT64, new SampleRateContainer(8640000), "Unit2"),
                this.CreateChannelDescription("Var3", "Group1", NexusDataType.FLOAT64, new SampleRateContainer(86400), "Unit2"),
            };

            var currentDate = new DateTime(2019, 1, 1, 15, 0, 0);
            var period      = TimeSpan.FromMinutes(1);

            // Act
            dataWriter.Configure(dataWriterContext, channelDescriptionSet);

            for (int i = 0; i < 9; i++)
            {
                var buffers = channelDescriptionSet.Select(current =>
                {
                    var length = (int)current.SampleRate.SamplesPerDay / 1440;
                    var offset = length * i;
                    var data   = Enumerable.Range(offset, length).Select(value => value * 0 + (double)i + 1).ToArray();

                    return(BufferUtilities.CreateSimpleBuffer(data));
                }).ToList();

                dataWriter.Write(currentDate, period, buffers.Cast <IBuffer>().ToList());
                currentDate += period;
            }

            dataWriter.Dispose();

            // Assert
        }
Example #2
0
        public DataWriterContext(string systemName, string dataDirectoryPath, NexusProjectDescription projectDescription, IList <CustomMetadataEntry> customMetadataEntrySet)
        {
            Contract.Requires(customMetadataEntrySet != null);

            customMetadataEntrySet.ToList().ForEach(customMetaDataEntry =>
            {
                if (!NexusUtilities.CheckNamingConvention(customMetaDataEntry.Key, out errorDescription))
                {
                    throw new ArgumentException($"Argument '{ nameof(customMetadataEntrySet) }', value '{ customMetaDataEntry.Key }': { errorDescription }");
                }
            });

            this.SystemName             = systemName;
            this.DataDirectoryPath      = dataDirectoryPath;
            this.ProjectDescription     = projectDescription;
            this.CustomMetadataEntrySet = customMetadataEntrySet;
        }