Beispiel #1
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);
        }
Beispiel #2
0
        public static ViewDTO GetViewCache(long viewCacheId, bool isSchedulerCall)
        {
            ViewDTO view;

            using (var avrTran = new AvrDbTransaction())
            {
                DbManagerProxy manager   = avrTran.Manager;
                DbManager      headerCmd = manager.SetSpCommand("spAsViewCacheGetHeader",
                                                                manager.Parameter("idfViewCache", viewCacheId),
                                                                manager.Parameter("blnSchedulerCall", isSchedulerCall));

                lock (m_DbSyncLock)
                {
                    int packetCount;
                    using (IDataReader reader = headerCmd.ExecuteReader())
                    {
                        if (!reader.Read())
                        {
                            return(null);
                        }

                        BaseTableDTO viewTableDTO = new BaseTableDTO
                        {
                            Header =
                            {
                                RowCount   = (int)reader["intViewColumnCount"],
                                BinaryBody = new ChunkByteArray((byte[])reader["blbViewSchema"])
                            }
                        };

                        var binaryHeader = (byte[])reader["blbViewHeader"];
                        view = new ViewDTO(viewTableDTO, binaryHeader);

                        packetCount = (int)reader["intPacketCount"];
                    }
                    for (int packetNumber = 0; packetNumber < packetCount; packetNumber++)
                    {
                        DbManager packetCmd = manager.SetSpCommand("spAsViewCacheGetPacket",
                                                                   manager.Parameter("idfViewCache", viewCacheId),
                                                                   manager.Parameter("intViewCachePacketNumber", packetNumber));

                        var packetDTO = new BaseTablePacketDTO();
                        using (IDataReader packetReader = packetCmd.ExecuteReader())
                        {
                            if (!packetReader.Read())
                            {
                                return(null);
                            }

                            packetDTO.RowCount   = (int)packetReader["intTableRowCount"];
                            packetDTO.BinaryBody = new ChunkByteArray((byte[])packetReader["blbViewCachePacket"]);
                        }
                        view.BodyPackets.Add(packetDTO);
                    }

                    avrTran.CommitTransaction();
                }
            }
            return(view);
        }
Beispiel #3
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();
            }
        }
Beispiel #4
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);
        }
Beispiel #5
0
        public static BaseTableDTO Zip(BaseTableDTO sourceTable)
        {
            var result = new BaseTableDTO
            {
                TableName   = sourceTable.TableName,
                Header      = Zip(sourceTable.Header),
                BodyPackets = sourceTable.BodyPackets.Select(Zip).ToList(),
            };

            return(result);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public static DataTable DeserializeToTable(BaseTableDTO dto)
        {
            List <BaseColumnModel> deserializedHeader = DeserializeHeader(dto.Header);
            var result = new DataTable();

            result.BeginInit();
            result.TableName = dto.TableName;
            foreach (BaseColumnModel columnModel in deserializedHeader)
            {
                var column = new DataColumn(columnModel.Name, columnModel.FinalType)
                {
                    Caption = columnModel.Caption
                };
                result.Columns.Add(column);
            }
            result.EndInit();

            AvrDataTable avrTable = new AvrDataTable(result);

            result.BeginLoadData();
            Type[] types = deserializedHeader.Select(c => c.FinalType).ToArray();

            foreach (BaseTablePacketDTO packet in dto.BodyPackets)
            {
                DeserializeBodyPacket(packet, types, avrTable);
            }
            avrTable.AcceptChanges();

            foreach (AvrDataRowBase avrRow in avrTable.Rows)
            {
                object[] array = new object[avrRow.Count];
                for (int j = 0; j < avrRow.Count; j++)
                {
                    array[j] = avrRow[j];
                }
                result.Rows.Add(array);
            }

            result.AcceptChanges();
            result.EndLoadData();

            return(result);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }
Beispiel #10
0
        public static BaseTableDTO SerializeFromTable(DataTable table, int maxPacketRows = 0)
        {
            var columnModels = new List <BaseColumnModel>();

            foreach (DataColumn column in table.Columns)
            {
                var columnModel = new BaseColumnModel(column.ColumnName, column.Caption, column.DataType);
                columnModels.Add(columnModel);
            }

            DataTableReader    reader = table.CreateDataReader();
            BaseTablePacketDTO packet = SerializeBodyPacket(reader, columnModels, maxPacketRows);
            var result = new BaseTableDTO {
                TableName = table.TableName
            };

            while (packet.RowCount != 0)
            {
                result.BodyPackets.Add(packet);
                packet = SerializeBodyPacket(reader, columnModels, maxPacketRows);
            }
            result.Header = SerializeHeader(columnModels);
            return(result);
        }
Beispiel #11
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();
            }
        }