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

            Assert.AreEqual(1, result[0]);
        }
Ejemplo n.º 2
0
        public ViewDTO GetCachedView(string sessionId, long layoutId, string lang)
        {
            try
            {
                m_ViewSemaphore.Wait();

                Console.WriteLine(" Waited {0} tics for the semaphore", (DateTime.Now.Ticks - m_Ticks) / 100000 * 100000);

                Thread.Sleep(100);
                byte[] viewBytes       = BinarySerializer.SerializeFromString(SerializedViewStub.ViewXml);
                byte[] viewZippedBytes = BinaryCompressor.Zip(viewBytes);

                DataTable sourceData = DataTableSerializer.Deserialize(SerializedViewStub.DataXml);

                BaseTableDTO serializedDTO = BinarySerializer.SerializeFromTable(sourceData);
                BaseTableDTO zippedDTO     = BinaryCompressor.Zip(serializedDTO);

                var result = new ViewDTO(zippedDTO, viewZippedBytes);

                return(result);
            }
            finally
            {
                m_ViewSemaphore.Release();
            }
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
        public void ZeroChunkCompressTest()
        {
            ChunkByteArray zip    = BinaryCompressor.Zip(new ChunkByteArray(new byte[0]));
            ChunkByteArray result = BinaryCompressor.Unzip(zip);

            Assert.AreEqual(0, result.Length);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 6
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]);
                }
            }
        }
Ejemplo n.º 7
0
        private static ViewDTO GetCachedView()
        {
            byte[] viewBytes       = BinarySerializer.SerializeFromString(SerializedViewStub.ViewXml);
            byte[] viewZippedBytes = BinaryCompressor.Zip(viewBytes);

            DataTable sourceData = DataTableSerializer.Deserialize(SerializedViewStub.DataXml);

            BaseTableDTO serializedDTO = BinarySerializer.SerializeFromTable(sourceData);
            BaseTableDTO zippedDTO     = BinaryCompressor.Zip(serializedDTO);

            var result = new ViewDTO(zippedDTO, viewZippedBytes);

            return(result);
        }
Ejemplo n.º 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]);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 11
0
        public AVRFacadeStub(long queryCacheId, int multiplier = 1)
        {
            QueryTableModel tableModel;

            using (DbManagerProxy manager = DbManagerFactory.Factory.Create())
            {
                using (DbManager command = manager.SetCommand(@"select  * from dbo.AVR_HumanCaseReport"))
                {
                    tableModel = BinarySerializer.SerializeFromCommand(command, 123, "en", false, 10);
                }
            }

            m_ZippedBody = tableModel.BodyPackets.Select(BinaryCompressor.Zip).ToList();

            m_ZippedHeader = new QueryTableHeaderDTO(BinaryCompressor.Zip(tableModel.Header), queryCacheId, m_ZippedBody.Count * multiplier);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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]);
            }
        }
Ejemplo n.º 14
0
        public static QueryTableModel GetQueryResult(long queryId, string lang, bool isArchive)
        {
            string          queryString;
            QueryTableModel zippedTable;

            var watch = new Stopwatch();

            watch.Start();
            m_Trace.Trace(TraceTitle, "Executing actual query '{0}' for lang '{1}'", queryId, lang);
            using (DbManagerProxy manager = DbManagerFactory.Factory.Create())
            {
                queryString = QueryHelper.GetQueryText(manager, queryId, false);

                QueryTableModel serializedTable = QueryHelper.GetInnerQueryResult(manager, queryString, lang,
                                                                                  c => BinarySerializer.SerializeFromCommand(c, queryId, lang, false));
                zippedTable = BinaryCompressor.Zip(serializedTable);
            }

            if (isArchive)
            {
                m_Trace.Trace(TraceTitle, "Executing archive query '{0}' for lang '{1}'", queryId, lang);
                using (DbManagerProxy archiveManager = DbManagerFactory.Factory[DatabaseType.Archive].Create())
                {
                    using (DbManagerProxy manager = DbManagerFactory.Factory.Create())
                    {
                        QueryHelper.DropAndCreateArchiveQuery(manager, archiveManager, queryId);
                    }
                    QueryTableModel serializedArchiveTable = QueryHelper.GetInnerQueryResult(archiveManager, queryString, lang,
                                                                                             c => BinarySerializer.SerializeFromCommand(c, queryId, lang, true));
                    QueryTableModel zippedArchiveTable = BinaryCompressor.Zip(serializedArchiveTable);

                    zippedTable.UseArchivedData = true;
                    foreach (QueryTablePacketDTO packet in zippedArchiveTable.BodyPackets)
                    {
                        packet.IsArchive = true;
                        zippedTable.BodyPackets.Add(packet);
                    }
                }
            }
            m_Trace.Trace(TraceTitle, "Executing query '{0}' for lang '{1}' finished, duration={2},", queryId, lang, watch.Elapsed);
            return(zippedTable);
        }
Ejemplo n.º 15
0
        public ViewDTO GetCachedView(string sessionId, long layoutId, string lang)
        {
            try
            {
                m_ViewSemaphore.Wait();

                var       layout = AvrDbHelper.GetLayoutDTO(layoutId);
                Stopwatch watch  = TraceMethodCall(sessionId, layoutId, layout.DefaultLayoutName, lang);
                EidssAvrServiceInitializer.CheckAndInitEidssCore();

                ViewDTO view         = null;
                var     cacheKey     = new QueryCacheKey(layout.QueryId, lang, layout.UseArchivedData);
                long?   queryCacheId = AvrDbHelper.GetQueryCacheId(cacheKey, RefreshedCacheOnUserCallAfterDays);
                if (queryCacheId.HasValue)
                {
                    var viewCacheId = AvrDbHelper.GetViewCacheId(queryCacheId.Value, layoutId, RefreshedCacheOnUserCallAfterDays);
                    if (viewCacheId.HasValue)
                    {
                        view = AvrDbHelper.GetViewCache(viewCacheId.Value, false);
                    }
                }

                if (view == null)
                {
                    AvrPivotViewModel model = VirtualPivot.CreateAvrPivotViewModel(layoutId, lang, m_Container);

                    string xmlViewHeader    = AvrViewSerializer.Serialize(model.ViewHeader);
                    byte[] zippedViewHeader = BinaryCompressor.ZipString(xmlViewHeader);

                    BaseTableDTO serializedDTO = BinarySerializer.SerializeFromTable(model.ViewData);
                    BaseTableDTO zippedDTO     = BinaryCompressor.Zip(serializedDTO);

                    view = new ViewDTO(zippedDTO, zippedViewHeader);

                    queryCacheId = AvrDbHelper.GetQueryCacheId(cacheKey, RefreshedCacheOnUserCallAfterDays);
                    if (queryCacheId.HasValue)
                    {
                        AvrDbHelper.SaveViewCache(queryCacheId.Value, layoutId, view);
                    }
                }
                TraceMethodCallFinished(watch, sessionId, layoutId, layout.DefaultLayoutName, lang);
                return(view);
            }
            catch (OutOfMemoryException ex)
            {
                m_Trace.TraceMethodException(ex, Utils.GetCurrentMethodName(), m_TraceTitle, sessionId, layoutId, lang);
                throw new AvrDataException(EidssMessages.Get("ErrAVROutOfMemory"), ex);
            }
            catch (Exception ex)
            {
                m_Trace.TraceMethodException(ex, Utils.GetCurrentMethodName(), m_TraceTitle, sessionId, layoutId, lang);
                string format = EidssMessages.Get("msgCouldNotGetViewData",
                                                  "Could not get View Data from Layout. LayoutID={0}, Lang={1}, SessionId={2}");
                string msg = String.Format(format, layoutId, lang, sessionId);
                throw new AvrDataException(msg, ex);
            }
            finally
            {
                m_ViewSemaphore.Release();
            }
        }
Ejemplo n.º 16
0
 public void ZeroCompressTest()
 {
     byte[] zip    = BinaryCompressor.Zip(new byte[0]);
     byte[] result = BinaryCompressor.Unzip(zip);
     Assert.AreEqual(0, result.Length);
 }
Ejemplo n.º 17
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]);
        }
Ejemplo n.º 18
0
 public void SimpleCompressTest()
 {
     byte[] zip    = BinaryCompressor.Zip(new byte[] { 1 });
     byte[] result = BinaryCompressor.Unzip(zip);
     Assert.AreEqual(1, result[0]);
 }