Exemplo n.º 1
0
        public static List <DayProfile> CreateDayProfiles(this XmlFactory builder, HanAdapterExampleConfig hanConfiguration)
        {
            var dayProfiles = new List <DayProfile>();

            foreach (DayProfileConfig config in hanConfiguration.XmlConfig.DayProfiles)
            {
                var dayProfile      = new DayProfile();
                var dayTimeProfiles = new List <DayTimeProfile>();

                dayProfile.DayId = config.DayId;

                foreach (DayTimeProfileConfig dayTimeConfig in config.DayTimeProfiles)
                {
                    var time = dayTimeConfig.Start;

                    while (time <= dayTimeConfig.End)
                    {
                        var dayTimeProfile = new DayTimeProfile();
                        dayTimeProfile.StartTime.Hour   = (byte)time.Hour;
                        dayTimeProfile.StartTime.Minute = (byte)time.Minute;
                        dayTimeProfile.TariffNumber     = dayTimeConfig.TariffNumber;
                        time = time.AddSeconds(900);
                        dayTimeProfiles.Add(dayTimeProfile);
                    }
                }

                dayProfile.DayTimeProfiles = dayTimeProfiles;
                dayProfiles.Add(dayProfile);
            }

            return(dayProfiles);
        }
Exemplo n.º 2
0
 // Validation of an DayProfile instance
 private static void ValidateDayProfile(DayProfile dayProfile, List <Exception> exceptions)
 {
     if (dayProfile.DayTimeProfiles.Count < 1)
     {
         exceptions.Add(new InvalidOperationException("Das Element \"DayProfile\" muss ein Element \"DayTimeProfile\" enthalten."));
     }
     else
     {
         foreach (DayTimeProfile profile in dayProfile.DayTimeProfiles)
         {
             ValidateDayTimeProfile(profile, exceptions);
         }
     }
 }
Exemplo n.º 3
0
        public void TestGetValidDayProfilesForMeterReading()
        {
            var dayTimeProfiles1 = new List <DayTimeProfile>();
            var dayTimeProfiles2 = new List <DayTimeProfile>();
            var dayTimeProfiles3 = new List <DayTimeProfile>();
            var dayTimeProfiles4 = new List <DayTimeProfile>();

            var hours   = 0;
            var minutes = new int[] { 0, 15, 30, 45 };

            // Initialize dayTimeProfiles1 (just one tariff for the whole day)
            for (int i = 0; i < 96; i++)
            {
                var index = i % (minutes.Length);
                var dtp   = new DayTimeProfile()
                {
                    TariffNumber = 1,

                    StartTime = new TimeVarType()
                    {
                        Hour = (byte)hours, Minute = (byte)minutes[index]
                    }
                };

                hours = index == 3 ? hours + 1 : hours;
                dayTimeProfiles1.Add(dtp);
            }

            // Initialize dayTimeProfiles2 (tariff 2 from 0 to 6; tariff 1 from 6 to 21; tariff 2 from 21 to 0)
            hours = 0;
            for (int i = 0; i < 96; i++)
            {
                var index = i % (minutes.Length);
                var dtp   = new DayTimeProfile()
                {
                    StartTime = new TimeVarType()
                    {
                        Hour = (byte)hours, Minute = (byte)minutes[index]
                    }
                };

                if (hours > 5 && hours < 21)
                {
                    dtp.TariffNumber = 1;
                }
                else
                {
                    dtp.TariffNumber = 2;
                }

                hours = index == 3 ? hours + 1 : hours;
                dayTimeProfiles2.Add(dtp);
            }

            // Initialize dayTimeProfiles3 (tariff 3 from 0 to 12; tariff 4 from 12 to 0)
            hours = 0;
            for (int i = 0; i < 96; i++)
            {
                var index = i % (minutes.Length);
                var dtp   = new DayTimeProfile()
                {
                    StartTime = new TimeVarType()
                    {
                        Hour = (byte)hours, Minute = (byte)minutes[index]
                    }
                };

                if (hours < 12)
                {
                    dtp.TariffNumber = 3;
                }
                else
                {
                    dtp.TariffNumber = 4;
                }

                hours = index == 3 ? hours + 1 : hours;
                dayTimeProfiles3.Add(dtp);
            }

            // Initialize dayTimeProfiles4 (tariff 1 from 0 to 12; tariff 4 from 12 to 0)
            hours = 0;
            for (int i = 0; i < 96; i++)
            {
                var index = i % (minutes.Length);
                var dtp   = new DayTimeProfile()
                {
                    StartTime = new TimeVarType()
                    {
                        Hour = (byte)hours, Minute = (byte)minutes[index]
                    }
                };

                if (hours < 12)
                {
                    dtp.TariffNumber = 1;
                }
                else
                {
                    dtp.TariffNumber = 4;
                }

                hours = index == 3 ? hours + 1 : hours;
                dayTimeProfiles4.Add(dtp);
            }


            // The MeterReading ObisIds
            var oc1 = new ObisId("0100010800FF");
            var oc2 = new ObisId("0100020800FF");

            // Create the list of DayProfiles
            var dayProfiles = new List <DayProfile>();

            var dp1 = new DayProfile()
            {
                DayId = 1, DayTimeProfiles = dayTimeProfiles1
            };
            var dp2 = new DayProfile()
            {
                DayId = 2, DayTimeProfiles = dayTimeProfiles2
            };
            var dp3 = new DayProfile()
            {
                DayId = 3, DayTimeProfiles = dayTimeProfiles3
            };

            dayProfiles.Add(dp1);
            dayProfiles.Add(dp2);
            dayProfiles.Add(dp3);

            var tariffStages = new List <TariffStage>();

            var obisId181 = "0100010801FF";
            var obisId182 = "0100010802FF";
            var obisId281 = "0100020801FF";
            var obisId282 = "0100020802FF";

            var tariffStage1 = new TariffStage()
            {
                Description = "T1", ObisCode = obisId181, TariffNumber = 1
            };
            var tariffStage2 = new TariffStage()
            {
                Description = "T2", ObisCode = obisId182, TariffNumber = 2
            };
            var tariffStage3 = new TariffStage()
            {
                Description = "T3", ObisCode = obisId281, TariffNumber = 3
            };
            var tariffStage4 = new TariffStage()
            {
                Description = "T4", ObisCode = obisId282, TariffNumber = 4
            };

            tariffStages.Add(tariffStage1);
            tariffStages.Add(tariffStage2);
            tariffStages.Add(tariffStage3);
            tariffStages.Add(tariffStage4);

            var target = dayProfiles.GetValidDayProfilesForMeterReading(oc1, tariffStages);

            Assert.AreEqual(2, target.Count);
            Assert.AreEqual((ushort)1, target[0]);
            Assert.AreEqual((ushort)2, target[1]);

            target = dayProfiles.GetValidDayProfilesForMeterReading(oc2, tariffStages);

            Assert.AreEqual(1, target.Count);
            Assert.AreEqual((ushort)3, target[0]);

            var obisId381 = "0100030801FF";
            var obisId482 = "0100040802FF";

            var tariffStage5 = new TariffStage()
            {
                Description = "T5", ObisCode = obisId381, TariffNumber = 5
            };
            var tariffStage6 = new TariffStage()
            {
                Description = "T6", ObisCode = obisId482, TariffNumber = 6
            };

            var tariffStages2 = new List <TariffStage>();

            tariffStages2.Add(tariffStage5);
            tariffStages2.Add(tariffStage6);

            target = dayProfiles.GetValidDayProfilesForMeterReading(oc1, tariffStages2);

            Assert.AreEqual(0, target.Count);

            target = dayProfiles.GetValidDayProfilesForMeterReading(oc2, tariffStages2);

            Assert.AreEqual(0, target.Count);

            var dayProfiles2 = new List <DayProfile>();

            var dp4 = new DayProfile()
            {
                DayId = 4, DayTimeProfiles = dayTimeProfiles4
            };

            dayProfiles2.Add(dp4);

            target = dayProfiles2.GetValidDayProfilesForMeterReading(oc1, tariffStages);

            Assert.AreEqual(0, target.Count);

            target = dayProfiles2.GetValidDayProfilesForMeterReading(oc2, tariffStages);

            Assert.AreEqual(0, target.Count);

            target = dayProfiles2.GetValidDayProfilesForMeterReading(oc1, tariffStages2);

            Assert.AreEqual(0, target.Count);

            target = dayProfiles2.GetValidDayProfilesForMeterReading(oc2, tariffStages2);

            Assert.AreEqual(0, target.Count);

            Assert.ThrowsException <ArgumentNullException>(() => dayProfiles.GetValidDayProfilesForMeterReading(null, null));

            Assert.ThrowsException <ArgumentNullException>(() => dayProfiles.GetValidDayProfilesForMeterReading(null, tariffStages));

            Assert.ThrowsException <ArgumentNullException>(() => dayProfiles.GetValidDayProfilesForMeterReading(oc1, null));

            Assert.ThrowsException <ArgumentException>(() => dayProfiles.GetValidDayProfilesForMeterReading(oc1, new List <TariffStage>()));

            var dayProfilesEmpty = new List <DayProfile>();

            Assert.ThrowsException <ArgumentException>(() => dayProfilesEmpty.GetValidDayProfilesForMeterReading(oc1, tariffStages));
        }