Exemple #1
0
        public void SimpleChunkCompressTest()
        {
            ChunkByteArray zip    = BinaryCompressor.Zip(new ChunkByteArray(new byte[] { 1 }));
            ChunkByteArray result = BinaryCompressor.Unzip(zip);

            Assert.AreEqual(1, result[0]);
        }
Exemple #2
0
        public void ZeroChunkCompressTest()
        {
            ChunkByteArray zip    = BinaryCompressor.Zip(new ChunkByteArray(new byte[0]));
            ChunkByteArray result = BinaryCompressor.Unzip(zip);

            Assert.AreEqual(0, result.Length);
        }
Exemple #3
0
        public ChartExportDTO ExportChartToJpg(ChartTableDTO zippedData, object syncLock)
        {
            Utils.CheckNotNull(zippedData, "zippedData");
            if (m_ChartDetail == null)
            {
                throw new AvrException("Chart already disposed.");
            }

            BaseTableDTO unzippedData = BinaryCompressor.Unzip(zippedData);
            DataTable    data         = BinarySerializer.DeserializeToTable(unzippedData);

            if (zippedData.TextPatterns != null)
            {
                foreach (string col in zippedData.TextPatterns.Keys)
                {
                    data.Columns[col].ExtendedProperties.Add("TextPattern", zippedData.TextPatterns[col]);
                }
            }

            ChartExportDTO result;

            lock (syncLock)
            {
                m_ChartDetail.DataSource = data;
                object id = zippedData.ViewId;

                m_ChartDetail.LoadData(ref id);

                m_ChartDetail.ChartControlSize = new Size(zippedData.Width, zippedData.Height);
                result = m_ChartDetail.ExportToJpgBytes(zippedData.ChartSettings, zippedData.ChartType);
            }
            return(result);
        }
Exemple #4
0
        public void SerializeIntegrationArchiveTest()
        {
            QueryTableModel tableModel;

            using (var manager = new DbManager(new SqlDataProvider(), Config.GetSetting("TestConnectionString")))
            {
                using (DbManager command = manager.SetCommand(@"select  * from dbo.AVR_HumanCaseReport"))
                {
                    tableModel = BinarySerializer.SerializeFromCommand(command, 123, "en", true, 10);
                }
            }

            Assert.AreEqual(54, tableModel.Header.RowCount);
            Assert.AreEqual(true, tableModel.UseArchivedData);
            Assert.AreEqual(true, tableModel.Header.IsArchive);

            QueryTablePacketDTO zippedHeader = BinaryCompressor.Zip(tableModel.Header);

            Assert.AreEqual(true, zippedHeader.IsArchive);
            List <QueryTablePacketDTO> zippedBody = tableModel.BodyPackets.Select(BinaryCompressor.Zip).ToList();

            Assert.IsFalse(zippedBody.Any(p => !p.IsArchive));

            QueryTablePacketDTO unzipedHeader = BinaryCompressor.Unzip(zippedHeader);

            Assert.AreEqual(true, unzipedHeader.IsArchive);
            List <QueryTablePacketDTO> unzippedBody = zippedBody.Select(BinaryCompressor.Unzip).ToList();

            Assert.IsFalse(unzippedBody.Any(p => !p.IsArchive));
        }
Exemple #5
0
        public void SerializeZipViewTableTest()
        {
            DataTable sourceData = DataTableSerializer.Deserialize(SerializedViewStub.DataXml);

            BaseTableDTO serializedDTO = BinarySerializer.SerializeFromTable(sourceData, 10000);
            BaseTableDTO zippedDTO     = BinaryCompressor.Zip(serializedDTO);
            BaseTableDTO unzippedDTO   = BinaryCompressor.Unzip(zippedDTO);
            DataTable    resultData    = BinarySerializer.DeserializeToTable(unzippedDTO);

            AssertTablesAreEqual(sourceData, resultData);
        }
Exemple #6
0
        public QueryTableHeaderModel(QueryTableHeaderDTO headerDTO)
        {
            QueryCacheId = headerDTO.QueryCacheId;
            PacketCount  = headerDTO.PacketCount;

            QueryTablePacketDTO    unzipedHeader      = BinaryCompressor.Unzip(headerDTO.BinaryHeader);
            List <BaseColumnModel> deserializedHeader = BinarySerializer.DeserializeHeader(unzipedHeader);

            ColumnTypeByName = deserializedHeader;
            ColumnTypes      = deserializedHeader.Select(c => c.FinalType).ToArray();
        }
Exemple #7
0
        public void TableCompressTest()
        {
            var source = new QueryTableModel(123, "en")
            {
                Header = new QueryTablePacketDTO
                {
                    RowCount   = 1,
                    BinaryBody = new ChunkByteArray(new byte[] { 1, 2, 3 }),
                    IsArchive  = true
                },
                BodyPackets = new List <QueryTablePacketDTO>
                {
                    new QueryTablePacketDTO
                    {
                        RowCount   = 2,
                        BinaryBody = new ChunkByteArray(new byte[] { 4, 5, 6, 7, 8, 9 }),
                        IsArchive  = false
                    },
                    new QueryTablePacketDTO
                    {
                        RowCount   = 3,
                        BinaryBody = new ChunkByteArray(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 10 }),
                        IsArchive  = true
                    },
                }
            };

            QueryTableModel zip    = BinaryCompressor.Zip(source);
            QueryTableModel result = BinaryCompressor.Unzip(zip);

            Assert.AreEqual(source.Header.RowCount, result.Header.RowCount);
            Assert.AreEqual(source.Language, result.Language);
            Assert.AreEqual(source.QueryId, result.QueryId);
            Assert.AreEqual(source.Header.BinaryBody.Length, result.Header.BinaryBody.Length);
            for (int i = 0; i < source.Header.BinaryBody.Length; i++)
            {
                Assert.AreEqual(source.Header.BinaryBody[i], result.Header.BinaryBody[i]);
            }

            Assert.AreEqual(source.BodyPackets.Count, result.BodyPackets.Count);

            for (int i = 0; i < source.BodyPackets.Count; i++)
            {
                var sourcePacket = source.BodyPackets[i];
                var resultPacket = result.BodyPackets[i];
                Assert.AreEqual(sourcePacket.BinaryBody.Length, resultPacket.BinaryBody.Length);
                for (int j = 0; j < sourcePacket.BinaryBody.Length; j++)
                {
                    Assert.AreEqual(sourcePacket.BinaryBody[j], resultPacket.BinaryBody[j]);
                }
            }
        }
Exemple #8
0
        public void ComplexCompressTest()
        {
            const int length = 1000000;
            var       source = new byte[length];

            new Random().NextBytes(source);
            byte[] zip    = BinaryCompressor.Zip(source);
            byte[] result = BinaryCompressor.Unzip(zip);
            Assert.AreEqual(source.Length, result.Length);
            for (int i = 0; i < length; i++)
            {
                Assert.AreEqual(source[i], result[i]);
            }
        }
Exemple #9
0
        public void TableEmptyCompressTest()
        {
            var source = new QueryTableModel(123, "en");

            QueryTableModel zip    = BinaryCompressor.Zip(source);
            QueryTableModel result = BinaryCompressor.Unzip(zip);

            Assert.AreEqual(0, result.Header.RowCount);
            Assert.AreEqual(source.Header.RowCount, result.Header.RowCount);
            Assert.AreEqual(source.Language, result.Language);
            Assert.AreEqual(source.QueryId, result.QueryId);
            Assert.AreEqual(source.UseArchivedData, result.UseArchivedData);
            Assert.AreEqual(source.Header.BinaryBody.Length, result.Header.BinaryBody.Length);
            Assert.AreEqual(0, result.Header.BinaryBody.Length);
        }
Exemple #10
0
        public void SerializeZipViewStrictureTest()
        {
            byte[] serializedView = BinarySerializer.SerializeFromString(SerializedViewStub.ViewXml);
            byte[] zippedView     = BinaryCompressor.Zip(serializedView);
            byte[] unzippedView   = BinaryCompressor.Unzip(zippedView);

            Assert.AreEqual(serializedView.Length, unzippedView.Length);
            for (int i = 0; i < serializedView.Length; i++)
            {
                Assert.AreEqual(serializedView[i], unzippedView[i]);
            }

            string viewXml = BinarySerializer.DeserializeToString(unzippedView);

            Assert.AreEqual(SerializedViewStub.ViewXml, viewXml);
        }
Exemple #11
0
        public void SerializeZipHumanTableTest()
        {
            DataTable sourceData;

            using (new StopwathTransaction("+++ Select from DB +++"))
            {
                using (var manager = new DbManager(new SqlDataProvider(), Config.GetSetting("EidssConnectionString")))
                {
                    using (DbManager command = manager.SetCommand(@"select * from fn_AVR_HumanCaseReport('en')"))
                    {
                        command.Command.CommandTimeout = 120;
                        sourceData = command.ExecuteDataTable();
                    }
                }
            }

            BaseTableDTO serializedDTO;

            using (new StopwathTransaction("+++ SerializeFromTable +++"))
            {
                serializedDTO = BinarySerializer.SerializeFromTable(sourceData, 10000);
            }
            BaseTableDTO zippedDTO;

            using (new StopwathTransaction("+++ ZipFromTable +++"))
            {
                zippedDTO = BinaryCompressor.Zip(serializedDTO);
            }
            BaseTableDTO unzippedDTO;

            using (new StopwathTransaction("+++ UnzipFromTable +++"))
            {
                unzippedDTO = BinaryCompressor.Unzip(zippedDTO);
            }

            DataTable resultData;

            using (new StopwathTransaction("+++ DeserializeToTable +++"))
            {
                resultData = BinarySerializer.DeserializeToTable(unzippedDTO);
            }

            AssertTablesAreEqual(sourceData, resultData);
        }
Exemple #12
0
        public void PacketCompressTest()
        {
            var source = new QueryTablePacketDTO
            {
                RowCount   = 1,
                BinaryBody = new ChunkByteArray(new byte[] { 1, 2, 3 }),
                IsArchive  = true
            };
            QueryTablePacketDTO zip    = BinaryCompressor.Zip(source);
            QueryTablePacketDTO result = BinaryCompressor.Unzip(zip);

            Assert.AreEqual(source.RowCount, result.RowCount);
            Assert.AreEqual(source.BinaryBody.Length, result.BinaryBody.Length);
            Assert.AreEqual(source.IsArchive, result.IsArchive);
            for (int i = 0; i < source.BinaryBody.Length; i++)
            {
                Assert.AreEqual(source.BinaryBody[i], result.BinaryBody[i]);
            }
        }
Exemple #13
0
        public void GetCachedViewTest()
        {
            BaseReportTests.InitDBAndLogin();

            var  facade   = new AVRFacade(m_Container);
            long layoutId = LayoutFormSave();

            List <long> queryIdList = facade.GetQueryIdList();

            Assert.IsNotNull(queryIdList);
            Assert.IsTrue(queryIdList.Count > 0);

            List <long> layoutIdList = facade.GetLayoutIdList();

            Assert.IsNotNull(layoutIdList);
            Assert.IsTrue(layoutIdList.Count > 0);

            ViewDTO model = facade.GetCachedView("xxx", layoutId, "en");

            Assert.IsNotNull(model);
            Assert.IsNotNull(model.BinaryViewHeader);
            Assert.IsNotNull(model.Header);
            Assert.IsNotNull(model.BodyPackets);

            byte[]  unzippedViewStructure = BinaryCompressor.Unzip(model.BinaryViewHeader);
            string  xmlViewStructure      = BinarySerializer.DeserializeToString(unzippedViewStructure);
            AvrView view       = AvrViewSerializer.Deserialize(xmlViewStructure);
            string  viewXmlNew = AvrViewSerializer.Serialize(view);

            Assert.IsNotNull(viewXmlNew);

            BaseTableDTO unzippedDTO = BinaryCompressor.Unzip(model);
            DataTable    viewData    = BinarySerializer.DeserializeToTable(unzippedDTO);
            string       dataXmlNew  = DataTableSerializer.Serialize(viewData);

            Assert.IsNotNull(dataXmlNew);
        }
Exemple #14
0
        public void ViewFacedeTest()
        {
            var facade = new AVRFacadeStub(123);

            ViewDTO model = facade.GetCachedView("xxx", -1, "en");

            Assert.IsNotNull(model);
            Assert.IsNotNull(model.BinaryViewHeader);
            Assert.IsNotNull(model.Header);
            Assert.IsNotNull(model.BodyPackets);

            byte[]  unzippedViewStructure = BinaryCompressor.Unzip(model.BinaryViewHeader);
            string  xmlViewStructure      = BinarySerializer.DeserializeToString(unzippedViewStructure);
            AvrView view       = AvrViewSerializer.Deserialize(xmlViewStructure);
            string  viewXmlNew = AvrViewSerializer.Serialize(view);

            Assert.AreEqual(SerializedViewStub.ViewXml, viewXmlNew);

            BaseTableDTO unzippedDTO = BinaryCompressor.Unzip(model);
            DataTable    viewData    = BinarySerializer.DeserializeToTable(unzippedDTO);
            string       dataXmlNew  = DataTableSerializer.Serialize(viewData);

            Assert.AreEqual(SerializedViewStub.DataXml, dataXmlNew);
        }
Exemple #15
0
        public void SerializeIntegrationTest()
        {
            QueryTableModel tableModel;

            using (var manager = new DbManager(new SqlDataProvider(), Config.GetSetting("TestConnectionString")))
            {
                using (DbManager command = manager.SetCommand(@"select  * from dbo.AVR_HumanCaseReport"))
                {
                    tableModel = BinarySerializer.SerializeFromCommand(command, 123, "en", false, 10);
                }
            }

            Assert.AreEqual(54, tableModel.Header.RowCount);
            Assert.AreEqual(false, tableModel.UseArchivedData);
            Assert.AreEqual(false, tableModel.Header.IsArchive);

            QueryTablePacketDTO zippedHeader = BinaryCompressor.Zip(tableModel.Header);

            Assert.AreEqual(false, zippedHeader.IsArchive);
            List <QueryTablePacketDTO> zippedBody = tableModel.BodyPackets.Select(BinaryCompressor.Zip).ToList();

            Assert.IsFalse(zippedBody.Any(p => p.IsArchive));

            QueryTablePacketDTO unzipedHeader = BinaryCompressor.Unzip(zippedHeader);

            Assert.AreEqual(false, unzipedHeader.IsArchive);
            List <QueryTablePacketDTO> unzippedBody = zippedBody.Select(BinaryCompressor.Unzip).ToList();

            Assert.IsFalse(unzippedBody.Any(p => p.IsArchive));

            List <BaseColumnModel> resultHeader = BinarySerializer.DeserializeHeader(unzipedHeader);

            Assert.IsTrue(resultHeader.Exists(c => c.Name == "sflHC_PatientDOB"));
            Assert.IsTrue(resultHeader.Exists(c => c.Name == "sflHC_PatientSex_ID"));
            Assert.IsTrue(resultHeader.Exists(c => c.Name == "sflHC_LabDiagBasis"));
            Assert.AreEqual(typeof(DateTime), resultHeader.Find(c => c.Name == "sflHC_PatientDOB").FinalType);
            Assert.AreEqual(typeof(long), resultHeader.Find(c => c.Name == "sflHC_PatientSex_ID").FinalType);
            Assert.AreEqual(typeof(string), resultHeader.Find(c => c.Name == "sflHC_LabDiagBasis").FinalType);

            Type[] types = resultHeader.Select(c => c.FinalType).ToArray();

            AvrDataTable resultBody = new AvrDataTable(new DataTable());

            foreach (var packetDTO in unzippedBody)
            {
                BinarySerializer.DeserializeBodyPacket(packetDTO, types, resultBody);
            }

            Assert.AreEqual(31, resultBody.Count);
            Assert.AreEqual(54, resultBody[0].Count);

            AvrDataRowEx row = (AvrDataRowEx)resultBody[30];

            Assert.AreEqual(new DateTime(1990, 02, 01), row[0]);
            Assert.AreEqual(23, row[1]);
            Assert.AreEqual(DBNull.Value, row[3]);
            Assert.AreEqual("xxx", row[4]);
            Assert.AreEqual("Male", row[6]);
            Assert.AreEqual(DBNull.Value, row[7]);
            Assert.AreEqual(DateTime.Now.Year, ((DateTime)row[50]).Year);
            Assert.AreEqual(DateTime.Now.Year, row[51]);
            Assert.AreEqual(25460000000m, row[52]);
            Assert.AreEqual("Yes", row[53]);
        }
Exemple #16
0
 public void ZeroCompressTest()
 {
     byte[] zip    = BinaryCompressor.Zip(new byte[0]);
     byte[] result = BinaryCompressor.Unzip(zip);
     Assert.AreEqual(0, result.Length);
 }
Exemple #17
0
        public void GetCachedQueryTest()
        {
            AVRFacade facade;

            using (new StopwathTransaction("AVRFacade .ctor"))
            {
                facade = new AVRFacade(m_Container);
            }
            QueryTableHeaderDTO headerDTO;

            using (new StopwathTransaction("GetCachedQueryTableHeader"))
            {
                //fn_AVR_HumanCaseReport
                headerDTO = facade.GetCachedQueryTableHeader(49539640000000, "en", false);
            }
            var headerModel = new QueryTableHeaderModel(headerDTO);

            Assert.AreEqual(m_FieldCount, headerModel.ColumnCount);
            Assert.IsTrue(headerModel.ColumnTypeByName.Exists(c => c.Name == "sflHC_FinalDiagnosis"));
            Type stringType = headerModel.ColumnTypeByName.Find(c => c.Name == "sflHC_FinalDiagnosis").FinalType;

            Assert.AreEqual(typeof(string), stringType);
            Assert.IsTrue(headerModel.ColumnTypeByName.Exists(c => c.Name == "sflHC_FinalDiagnosisDate"));
            stringType = headerModel.ColumnTypeByName.Find(c => c.Name == "sflHC_FinalDiagnosisDate").FinalType;
            Assert.AreEqual(typeof(DateTime), stringType);

            for (int i = 0; i < headerDTO.PacketCount; i++)
            {
                QueryTablePacketDTO packetDTO;
                using (new StopwathTransaction("GetCachedQueryTablePacket " + i))
                {
                    packetDTO = facade.GetCachedQueryTablePacket(headerModel.QueryCacheId, i, headerDTO.PacketCount);
                }
                QueryTablePacketDTO unzipped;
                using (new StopwathTransaction(string.Format("-Unzip Packet #{0}", i)))
                {
                    unzipped = BinaryCompressor.Unzip(packetDTO);
                }
                StreamTablePacketDTO unzippedStream;
                using (new StopwathTransaction(string.Format("-Unzip Packet #{0} into stream", i)))
                {
                    unzippedStream = BinaryCompressor.UnzipStream(packetDTO);
                }

                AvrDataTable deserialized = new AvrDataTable(headerModel, 10240);
                using (new StopwathTransaction(string.Format("--Deserialize Packet #{0}", i)))
                {
                    BinarySerializer.DeserializeBodyPacket(unzipped, headerModel.ColumnTypes, deserialized);
                }

                AvrDataTable deserializedStream = new AvrDataTable(headerModel, 10240);
                using (new StopwathTransaction(string.Format("--Deserialize Packet #{0} into stream", i)))
                {
                    BinarySerializer.DeserializeBodyPacket(unzippedStream, headerModel.ColumnTypes, deserializedStream);
                }

                Assert.AreNotSame(deserialized, deserializedStream);
                Assert.AreEqual(deserialized.Count, deserializedStream.Count);
                Assert.AreEqual(deserialized.Columns.Count, deserializedStream.Columns.Count);

                int diagnosisIndex = headerModel.ColumnTypeByName
                                     .Select(c => c.Name)
                                     .TakeWhile(key => key != "sflHC_FinalDiagnosis")
                                     .Count();

                bool found = false;
                for (int j = 0; j < deserialized.Count; j++)
                {
                    var row       = (AvrDataRowEx)deserialized[j];
                    var rowStream = (AvrDataRowEx)deserializedStream[j];

                    Assert.AreNotSame(row, rowStream);
                    Assert.AreEqual(row.Count, rowStream.Count);
                    for (int k = 0; k < row.Count; k++)
                    {
                        Assert.AreEqual(row[k], rowStream[k]);
                    }

                    if (row[diagnosisIndex].ToString() == "Smallpox")
                    {
                        found = true;
                    }
                }

                Assert.IsTrue(found);
            }
        }
Exemple #18
0
 public void SimpleCompressTest()
 {
     byte[] zip    = BinaryCompressor.Zip(new byte[] { 1 });
     byte[] result = BinaryCompressor.Unzip(zip);
     Assert.AreEqual(1, result[0]);
 }