상속: IWriter
예제 #1
0
        public TIM Map(IEnumerable<WorkingData> workingData)
        {
            var tim =  new TIM
            {
                ASpecified = true,
                A = null,
                BSpecified = false,
                B = null,
                CSpecified = false,
                C = null,
                DSpecified = true,
                D = TIMD.Item4,
            };

            // TODO:  This is not mapping the PTN Header?
            var ptn = _ptnHeaderMapper.Map();
            var dlvs = _dlvHeaderMapper.Map(workingData).ToList();
            var iWriters = new List<IWriter>();

            if(ptn != null)
                iWriters.Add(ptn);

            if(dlvs != null)
                iWriters.AddRange(dlvs);

            tim.Items = iWriters.ToArray();

            return tim;
        }
예제 #2
0
        private static void AreEqual(TimeScope timeScope, TIM tim)
        {
            Assert.AreEqual(timeScope.TimeStamp1, tim.A);
            Assert.AreEqual(timeScope.TimeStamp2, tim.B);

            // todo.  check other attributes and PTN, dlvs,....
        }
예제 #3
0
        public IEnumerable<ISOSpatialRow> Read(string dataPath, string fileName, TIM tim)
        {
            if (tim == null)
                yield break;

            if (!File.Exists(Path.Combine(dataPath, fileName)))
                yield break;

            using (var binaryReader = new System.IO.BinaryReader(File.Open(Path.Combine(dataPath, fileName), FileMode.Open)))
            {
                while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length)
                {
                    var ptn = tim.Items.FirstOrDefault(x => x.GetType() == typeof (PTN)) as PTN;

                    var record = new ISOSpatialRow { TimeStart = GetStartTime(tim, binaryReader) };

                    if (ptn != null)
                    {
                        record.NorthPosition = ReadInt32(ptn.A, ptn.ASpecified, binaryReader).GetValueOrDefault(0);
                        record.EastPosition = ReadInt32(ptn.B, ptn.BSpecified, binaryReader).GetValueOrDefault(0);
                        record.Elevation = ReadInt32(ptn.C, ptn.CSpecified, binaryReader);
                        record.PositionStatus = ReadByte(ptn.D, ptn.DSpecified, binaryReader);
                        record.PDOP = ReadShort(ptn.E, ptn.ESpecified, binaryReader);
                        record.HDOP = ReadShort(ptn.F, ptn.FSpecified, binaryReader);
                        record.NumberOfSatellites = ReadByte(ptn.G, ptn.GSpecified, binaryReader);

                        SetGpsUtcDateTime(ptn, record, binaryReader);
                    }

                    SetSpatialValues(tim, record, binaryReader);
                    yield return record;
                }
            }
        }
예제 #4
0
 public List<WorkingData> Map(TIM tim, IEnumerable<ISOSpatialRow> isoSpatialRows, int sectionId)
 {
     var meters = new List<WorkingData>();
     var dlvs = tim.Items.Where(x => (x as DLV) != null).Cast<DLV>();
     for (int order = 0; order < dlvs.Count(); order++)
     {
         var dlv = dlvs.ElementAt(order);
         meters.AddRange(Map(dlv, isoSpatialRows, sectionId, order));
     }
     return meters;
 }
예제 #5
0
        public void GivenTimWHenMapThenStamp1IsMapped()
        {
            var tim = new TIM
            {
                A = DateTime.Now.AddDays(2),
            };
            _tims.Add(tim);

            var timescope = MapSingle();
            Assert.AreEqual(tim.A, timescope.TimeStamp1);
            Assert.AreEqual(DateContextEnum.ActualStart, timescope.DateContext);
        }
예제 #6
0
        public void GivenDataPathAndFileNameWhenReadTlgXmlDataThenTimReturned()
        {
            _xml = "<TIM></TIM>";
            File.AppendAllText(Path.Combine(_dataPath, "TASKDATA", _fileName), _xml);

            var tim = new TIM();
            _timReaderMock.Setup(x => x.Read(It.IsAny<XPathDocument>())).Returns(new List<TIM>{tim});

            var result = _xmlReader.ReadTlgXmlData(_dataPath, _fileName);
            Assert.AreEqual(1, result.Count);
            Assert.AreSame(tim, result[0]);
        }
예제 #7
0
        public void GivenTimWhenMapThenStamp2IsMapped()
        {
            var tim = new TIM
            {
                A = DateTime.Now,
                B = DateTime.Now.AddHours(8)
            };
            _tims.Add(tim);

            var timescope = MapSingle();
            Assert.AreEqual(tim.B, timescope.TimeStamp2);
            Assert.AreEqual(DateContextEnum.ActualStart, timescope.DateContext);
        }
예제 #8
0
        public void GivenTimHeaderWhenMapThenGetMetersIsMapped()
        {
            var tim = new TIM();
            var tims = new List<TIM> {tim};
            var isoSpatialRows = new List<ISOSpatialRow>();

            var meterMapperMock = new Mock<IMeterMapper>();

            var meters = new List<WorkingData>();
            meterMapperMock.Setup(x => x.Map(tim, isoSpatialRows, It.IsAny<int>())).Returns(meters);

            var result = new SectionMapper(meterMapperMock.Object).Map(tims, isoSpatialRows).First();

            Assert.AreSame(meters, result.GetWorkingDatas());
        }
예제 #9
0
        private TimeScope Map(TIM tim, Catalog catalog)
        {
            DateTime? stamp1 = null;
            if (tim.A.HasValue)
                stamp1 = tim.A.Value;

            DateTime? stamp2 = null;
            if (tim.B.HasValue)
                stamp2 = tim.B.Value;

            var timeScope = new TimeScope {TimeStamp1 = stamp1, TimeStamp2 = stamp2, DateContext = DateContextEnum.ActualStart};

            if(catalog.TimeScopes == null)
                catalog.TimeScopes = new List<TimeScope>();
            catalog.TimeScopes.Add(timeScope);
            return timeScope;
        }
예제 #10
0
        public IEnumerable<TIM> Read(XPathNodeIterator xPathNodeIterator)
        {
            var tims = new List<TIM>();
            if (xPathNodeIterator.Count == 0)
                return tims;
            foreach (XPathNavigator node in xPathNodeIterator)
            {
                var tim = new TIM
                {
                    A = CreateDateTime(node, "A"),
                    B = CreateDateTime(node, "B"),
                    D = FindEnumValue(node, "D"),
                    Items = GetItems(node)
                };
                tims.Add(tim);
            }

            return tims;
        }
예제 #11
0
        public void GivenTwoTimHeadersWhenMapThenGetMetersIsMapped()
        {
            var tim1 = new TIM();
            var tim2 = new TIM();
            var tims = new List<TIM> { tim1, tim2 };
            var isoSpatialRows = new List<ISOSpatialRow>();

            var meterMapperMock = new Mock<IMeterMapper>();

            var meters1 = new List<WorkingData>();
            var meters2 = new List<WorkingData>();
            meterMapperMock.Setup(x => x.Map(tim1, isoSpatialRows, It.IsAny<int>())).Returns(meters1);
            meterMapperMock.Setup(x => x.Map(tim2, isoSpatialRows, It.IsAny<int>())).Returns(meters2);

            var result = new SectionMapper(meterMapperMock.Object).Map(tims, isoSpatialRows);

            Assert.AreEqual(2, result.Count);
            Assert.AreSame(meters1, result.ElementAt(0).GetWorkingDatas());
            Assert.AreSame(meters2, result.ElementAt(1).GetWorkingDatas());
        }
예제 #12
0
        private static SpatialValue CreateSpatialValue(TIM tim, byte order, int value)
        {
            var dlvs = tim.Items.Where(x => x.GetType() == typeof (DLV));
            var matchingDlv = dlvs.ElementAtOrDefault(order) as DLV;

            if (matchingDlv == null)
                return null;

            var ddis = DdiLoader.Ddis;

            var resolution = 1d;
            if (matchingDlv.A != null && ddis.ContainsKey(Convert.ToInt32(matchingDlv.A, 16)))
                resolution = ddis[Convert.ToInt32(matchingDlv.A, 16)].Resolution;

            var spatialValue = new SpatialValue
            {
                Id = order,
                Dlv = matchingDlv,
                Value = value * resolution,
            };

            return spatialValue;
        }
예제 #13
0
 public void Setup()
 {
     _tim = new TIM();
     _isoSpatialRows = new List<ISOSpatialRow>();
     _representationMapperMock = new Mock<IRepresentationMapper>();
     _enumeratorMeterFactoryMock = new Mock<IEnumeratedMeterFactory>();
     _uniqueIdMapperMock = new Mock<IUniqueIdMapper>();
     _meterMapper = new MeterMapper(_representationMapperMock.Object, _enumeratorMeterFactoryMock.Object, _uniqueIdMapperMock.Object);
 }
예제 #14
0
        public void GivenTimHeaderWithIsNullStateWhenWriteThenPtnDoesntAddAtributes()
        {
            var ptn = new PTN
            {
                ASpecified = false,
                A = null,

                BSpecified = false,
                B = null,

                CSpecified = false,
                C = null,

                DSpecified = false,
                D = null,

                ESpecified = false,
                E = null,

                FSpecified = false,
                F = null,

                GSpecified = false,
                G = null,

                HSpecified = false,
                H = null,

                ISpecified = false,
                I = null

            };
            var tim = new TIM
            {
                Items = new List<IWriter> { ptn }.ToArray()
            };

            var xdoc = _xmlReader.WriteTlgXmlData(_dataPath, _fileName, tim);
            var actualPtn = xdoc.Element("TIM").Element("PTN");

            Assert.IsNull(actualPtn.Attribute("A"));
            Assert.IsNull(actualPtn.Attribute("B"));
            Assert.IsNull(actualPtn.Attribute("C"));
            Assert.IsNull(actualPtn.Attribute("D"));
            Assert.IsNull(actualPtn.Attribute("E"));
            Assert.IsNull(actualPtn.Attribute("F"));
            Assert.IsNull(actualPtn.Attribute("G"));
            Assert.IsNull(actualPtn.Attribute("H"));
            Assert.IsNull(actualPtn.Attribute("I"));
        }
예제 #15
0
        public void GivenTimHeaderWithIsNullStatesWhenMapThenTimAttributesAreNull()
        {
            var tim = new TIM
            {
                ASpecified = false,
                A = null,
                BSpecified = false,
                B = null,
                CSpecified = false,
                C = null,
                DSpecified = false,
            };

            var xdoc = _xmlReader.WriteTlgXmlData(_dataPath, _fileName, tim);
            var actualTim = xdoc.Element("TIM");

            Assert.IsNull(actualTim.Attribute("A"));
            Assert.IsNull(actualTim.Attribute("B"));
            Assert.IsNull(actualTim.Attribute("C"));
            Assert.IsNull(actualTim.Attribute("D"));
        }
예제 #16
0
        public void GivenTimHeaderWithIsNullStatesWhenMapThenTimAttributeHasValues()
        {
            var tim = new TIM
            {
                ASpecified = true,
                A = DateTime.Now,
                BSpecified = true,
                B = DateTime.Now.AddMinutes(15),
                CSpecified = true,
                C = 12354127851,
                DSpecified = true,
                D = TIMD.Item5
            };

            var xdoc = _xmlReader.WriteTlgXmlData(_dataPath, _fileName, tim);
            var actualTim = xdoc.Element("TIM");

            Assert.AreEqual(tim.A.Value.ToString(), actualTim.Attribute("A").Value);
            Assert.AreEqual(tim.B.Value.ToString(), actualTim.Attribute("B").Value);
            Assert.AreEqual(tim.C.Value.ToString(), actualTim.Attribute("C").Value);
            Assert.AreEqual(((int)(tim.D.Value)).ToString(), actualTim.Attribute("D").Value);
        }
예제 #17
0
        public void GivenTimHeaderWhenWriteThenDlvHasAttributes()
        {
            var dlv = new DLV
            {
                A = "123",
                B = 456,
                C = "DLV-1",
                D = 2,
                E = new byte(),
                F = new byte()
            };

            var timHeader = new TIM
            {
                Items = new List<DLV> { dlv }.ToArray()
            };
            var xdoc = _xmlReader.WriteTlgXmlData(_dataPath, _fileName, timHeader);
            var actualDlv = xdoc.Element("TIM").Elements("DLV").First();

            var expected = "007B";
            Assert.AreEqual(expected, actualDlv.Attribute("A").Value);
            Assert.AreEqual(dlv.B.Value.ToString(), actualDlv.Attribute("B").Value);
            Assert.AreEqual(dlv.C, actualDlv.Attribute("C").Value);
            Assert.AreEqual(dlv.D.Value.ToString(), actualDlv.Attribute("D").Value);
            Assert.AreEqual(dlv.E.Value.ToString(), actualDlv.Attribute("E").Value);
            Assert.AreEqual(dlv.F.Value.ToString(), actualDlv.Attribute("F").Value);
        }
예제 #18
0
        public void GivenTimHeaderWhenWriteThenPtnHasValues()
        {
            var ptn = new PTN
            {
                ASpecified = true,
                A = -123,

                BSpecified = true,
                B = 145,

                CSpecified = true,
                C = 123415,

                DSpecified = true,
                D = 7,

                ESpecified = true,
                E = 98.3,

                FSpecified = true,
                F = 33.2,

                GSpecified = true,
                G = 231,

                HSpecified = true,
                H = 21344,

                ISpecified = true,
                I = 231

            };
            var tim = new TIM
            {
                Items = new List<IWriter> { ptn }.ToArray()
            };

            var xdoc = _xmlReader.WriteTlgXmlData(_dataPath, _fileName, tim);
            var actualPtn = xdoc.Element("TIM").Element("PTN");

            Assert.AreEqual(ptn.A.Value.ToString(), actualPtn.Attribute("A").Value);
            Assert.AreEqual(ptn.B.Value.ToString(), actualPtn.Attribute("B").Value);
            Assert.AreEqual(ptn.C.Value.ToString(), actualPtn.Attribute("C").Value);
            Assert.AreEqual(ptn.D.Value.ToString(), actualPtn.Attribute("D").Value);
            Assert.AreEqual(ptn.E.Value.ToString(), actualPtn.Attribute("E").Value);
            Assert.AreEqual(ptn.F.Value.ToString(), actualPtn.Attribute("F").Value);
            Assert.AreEqual(ptn.G.Value.ToString(), actualPtn.Attribute("G").Value);
            Assert.AreEqual(ptn.H.Value.ToString(), actualPtn.Attribute("H").Value);
            Assert.AreEqual(ptn.I.Value.ToString(), actualPtn.Attribute("I").Value);
        }
예제 #19
0
        public void GivenPathAndTimHeaderWithMultipleDlvsWhenWriteTheOneDlvElementPerDlv()
        {
            var dlvs = new List<DLV>
            {
                new DLV(),
                new DLV(),
                new DLV(),
            };
            var tim = new TIM
            {
                Items = dlvs.ToArray()
            };

            var xdoc =_xmlReader.WriteTlgXmlData(_dataPath, _fileName, tim);
            var expectedTim = xdoc.Element("TIM");

            Assert.AreEqual(dlvs.Count, expectedTim.Elements("DLV").Count());
        }
예제 #20
0
        public void GivenTimHeaderWhenMapThenTimHasAttributes()
        {
            var tim = new TIM
            {
                ASpecified = true,
                A = null,
                BSpecified = true,
                B = null,
                CSpecified = true,
                C = null,
                DSpecified = true,
                D = null
            };

            var xdoc = _xmlReader.WriteTlgXmlData(_dataPath, _fileName, tim);
            var actualTim = xdoc.Element("TIM");

            Assert.AreEqual("", actualTim.Attribute("A").Value);
            Assert.AreEqual("", actualTim.Attribute("B").Value);
            Assert.AreEqual("", actualTim.Attribute("C").Value);
            Assert.AreEqual("", actualTim.Attribute("D").Value);
        }
예제 #21
0
        public void GivenPathAndTimHeaderWhenWriteTlgXmlDataThenTlgFileIsCreated()
        {
            var tim = new TIM();
            _xmlReader.WriteTlgXmlData(Path.Combine(_dataPath, "TASKDATA"), _fileName, tim);

            var expectedPath = Path.Combine(_dataPath, "TASKDATA", _fileName);
            Assert.IsTrue(File.Exists(expectedPath));
        }
예제 #22
0
        private DateTime GetStartTime(TIM tim, System.IO.BinaryReader binaryReader)
        {
            if (tim.ASpecified && tim.A == null)
            {
                var milliseconds = (double) binaryReader.ReadInt32();
                var daysFrom1980 = binaryReader.ReadInt16();
                return _firstDayOf1980.AddDays(daysFrom1980).AddMilliseconds(milliseconds);
            }
            else if(tim.ASpecified)
                return (DateTime) tim.A.Value;

            return _firstDayOf1980;
        }
예제 #23
0
 public void Setup()
 {
     _tim = new TIM();
     _output = new StringBuilder();
     _xmlBuilder = XmlWriter.Create(_output);
 }
예제 #24
0
        public void GivenNullTimHeaderWhenReadThenReturnedEmpty()
        {
            _tim = null;
            _bytes.Add(_numberOfDlvs);

            var result = Read();

            Assert.IsEmpty(result);
        }
예제 #25
0
        public void Setup()
        {
            _datacardPath = "dataCardPath";
            _tlg = new TLG();
            _tlgs = new List<TLG>{ _tlg };
            _tim = new TIM();
            _tims = new List<TIM> {_tim};
            _linkedIds = new Dictionary<string, List<UniqueId>>();

            _spatialRecordMapperMock = new Mock<ISpatialRecordMapper>();
            _xmlReaderMock = new Mock<IXmlReader>();
            _binaryReaderMock = new Mock<IBinaryReader>();
            _sectionMapperMock = new Mock<ISectionMapper>();
            _uniqueIdMapperMock = new Mock<IUniqueIdMapper>();

            _tlg.A = "fileName";
            _xmlReaderMock.Setup(x => x.ReadTlgXmlData(_datacardPath, _tlg.A + ".xml")).Returns(_tims);

            _isoSpatialRows = new List<ISOSpatialRow>();
            _binaryReaderMock.Setup(x => x.Read(_datacardPath, _tlg.A + ".bin", _tim)).Returns(_isoSpatialRows);

            _sections = new List<DeviceElementUse>();
            _sectionMapperMock.Setup(x => x.Map(_tims, _isoSpatialRows)).Returns(_sections);

            _operationDataMapper = new OperationDataMapper(_xmlReaderMock.Object, _binaryReaderMock.Object, _spatialRecordMapperMock.Object, _sectionMapperMock.Object, _uniqueIdMapperMock.Object);
        }
예제 #26
0
        public void Setup()
        {
            _numberOfDlvs = 0;
            _bytes = new List<byte>();
            _ptn = new PTN
            {
                A = 94.1234,
                ASpecified = true,
                B = 49.4321,
                BSpecified = true,
                C = 5,
                CSpecified = true,
                D = 1,
                DSpecified = true,
                E = 33,
                ESpecified = true,
                F = 44,
                FSpecified = true,
                G = 13,
                GSpecified = true,
                H = 123123213,
                HSpecified = true,
                I = 13213,
                ISpecified = true
            };
            _tim = new TIM
            {
                A = DateTime.Today,
                ASpecified = true,
                Items = new List<IWriter>
                {
                    _ptn,
                    new DLV
                    {
                        A = "0075",
                        B = 32,
                        C = "DEC-1",
                        D = null,
                        E = null,
                        F = null
                    }
                }.ToArray()
            };

            _binaryReader = new BinaryReader();
        }
예제 #27
0
        public void GivenOperationDataWhenMapThenXmlReaderIsCalled()
        {
            _operationData.Id.UniqueIds.Add(new UniqueId
            {
                Id = "TLG00016",
                CiTypeEnum = CompoundIdentifierTypeEnum.String,
                Source = UniqueIdMapper.IsoSource
            });

            var meters = new List<WorkingData> { new NumericWorkingData() };
            var sections = new List<DeviceElementUse>
            {
                new DeviceElementUse
                {
                    GetWorkingDatas = () => meters
                }
            };
            var sectionsByDepth = new Dictionary<int, IEnumerable<DeviceElementUse>>
            {
                { 0, sections }
            };
            _operationData.GetDeviceElementUses = x => sectionsByDepth[x];
            _operationData.MaxDepth = 0;

            var tim = new TIM();
            _timHeaderMock.Setup(x => x.Map(meters)).Returns(tim);

            MapSingle();

            _xmlReaderMock.Verify(x => x.WriteTlgXmlData(_datacardPath, "TLG00016.xml", tim));
        }
예제 #28
0
        public void GivenNullProcessDataValueWhenWriteThenAttributeIsNull()
        {
            var dlv = new DLV
            {
                A = "123",
                B = null,
                C = "DLV-1",
                D = 2,
                E = new byte(),
                F = new byte()
            };

            var tim = new TIM
            {
                Items = new List<DLV> { dlv }.ToArray()
            };

            var xdoc = _xmlReader.WriteTlgXmlData(_dataPath, _fileName, tim);
            var expectedDlv = xdoc.Element("TIM").Elements("DLV").First();

            Assert.IsNull(expectedDlv.Attribute("B"));
        }
예제 #29
0
        private static void SetSpatialValues(TIM tim, ISOSpatialRow record, System.IO.BinaryReader binaryReader)
        {
            var numberOfDLVs = binaryReader.ReadByte();
            record.SpatialValues = new List<SpatialValue>();

            for (int i = 0; i < numberOfDLVs; i++)
            {
                var order = binaryReader.ReadByte();
                var value = binaryReader.ReadInt32();

                record.SpatialValues.Add(CreateSpatialValue(tim, order, value));
            }
        }