Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sourceM"></param>
        public void Init(HisDataMemoryBlockCollection3 sourceM)
        {
            mTagIds.Clear();
            long lsize = 0;

            StartId = Id * TagCountPerMemory;

            foreach (var vv in CompressUnitManager2.Manager.CompressUnit)
            {
                mCompressCach.Add(vv.Key, vv.Value.Clone());
            }

            foreach (var vv in sourceM.TagAddress.Where(e => e.Key >= Id * TagCountPerMemory && e.Key < (Id + 1) * TagCountPerMemory))
            {
                mTagIds.Add(vv.Key);
                dtmp.Add(vv.Key, 0);
                lsize += (sourceM.ReadDataSizeByIndex(vv.Value) + 24);
            }

            this.ReAlloc2(HeadSize + (long)(lsize));
            this.Clear();

            if (IsEnableCompress)
            {
                mCompressedDataPointer = Marshal.AllocHGlobal((int)this.AllocSize);
            }

            mStaticsMemoryBlock = new MarshalMemoryBlock(TagCountPerMemory * 52, TagCountPerMemory * 52);
        }
Esempio n. 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="startTime"></param>
 /// <param name="memory"></param>
 public void RequestToSave(DateTime startTime, DateTime endTime, DateTime baseTime, HisDataMemoryBlockCollection3 memory)
 {
     mNeedSaveMemory1 = memory;
     mStartTime       = startTime;
     mEndTime         = endTime;
     mBaseTime        = baseTime;
     resetEvent.Set();
 }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="memory"></param>
        public void ClearMemoryHisData(HisDataMemoryBlockCollection3 memory)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            while (memory.IsBusy())
            {
                ;
            }
            memory.Clear();
            sw.Stop();
            LoggerService.Service.Info("Record", memory.Name + "清空数据区耗时:" + sw.ElapsedMilliseconds);
        }
Esempio n. 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="dataMemory"></param>
 public void RequestToCompress(HisDataMemoryBlockCollection3 dataMemory)
 {
     lock (mSourceMemorys)
         mSourceMemorys.Enqueue(dataMemory);
     // mCurrentTime = dataMemory.CurrentDatetime;
     foreach (var vv in mTargetMemorys)
     {
         vv.Value.CurrentTime = dataMemory.CurrentDatetime;
         vv.Value.EndTime     = dataMemory.EndDateTime;
     }
     lock (resetEvent)
         resetEvent.Set();
 }
Esempio n. 5
0
        /// <summary>
        ///
        /// </summary>
        private void CheckAndResize(HisDataMemoryBlockCollection3 sourceM)
        {
            //mTagIds.Clear();
            long lsize = 0;

            foreach (var vv in sourceM.TagAddress.Where(e => e.Key >= Id * TagCountPerMemory && e.Key < (Id + 1) * TagCountPerMemory))
            {
                if (!mTagIds.Contains(vv.Key))
                {
                    mTagIds.Add(vv.Key);

                    if (!dtmp.ContainsKey(vv.Key))
                    {
                        dtmp.Add(vv.Key, 0);
                    }

                    var cpt = mHisTagService.GetHisTag(vv.Key).CompressType;
                    if (!mCompressCach.ContainsKey(cpt))
                    {
                        mCompressCach.Add(cpt, CompressUnitManager2.Manager.GetCompressQuick(cpt).Clone());
                    }
                }
                if (vv.Value >= 0)
                {
                    lsize += sourceM.ReadDataSizeByIndex(vv.Value) + 24;
                }
            }

            if (lsize > this.AllocSize)
            {
                this.ReAlloc2(HeadSize + lsize);
                this.Clear();
            }

            if (IsEnableCompress)
            {
                Marshal.FreeHGlobal(mCompressedDataPointer);
                mCompressedDataPointer = Marshal.AllocHGlobal((int)this.AllocSize);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 执行压缩
        /// </summary>
        public void Compress(HisDataMemoryBlockCollection3 source)
        {
            lock (mLockObj)
            {
                /*
                 * 内存结构:Head+数据指针区域+数据区
                 * Head:数据区大小(4)+变量数量(4)
                 * 数据区指针:[ID(4) + address(4)]
                 * 数据区:[data block]
                 */
                mIsRunning = true;

                CheckAndResize(source);

                try
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();

                    //CheckTagAddress(source);
                    long datasize   = 0;
                    int  headOffset = 4 + 4;

                    int tagheadoffset = headOffset + mTagIds.Count * 8;

                    long Offset = tagheadoffset;

                    this.MakeMemoryBusy();
                    this.StaticsMemoryBlock.MakeMemoryBusy();

                    long ltmp1 = sw.ElapsedMilliseconds;

                    //更新数据区域
                    foreach (var vv in mTagIds)
                    {
                        var val = source.TagAddress[vv];
                        if (val >= 0)
                        {
                            cachblock.Reset(new IntPtr(source.ReadDataBaseAddressByIndex(val)), source.ReadDataSizeByIndex(val));
                            var size = CompressBlockMemory(cachblock, Offset, source.ReadQualityOffsetAddressByIndex(val), source.ReadDataSizeByIndex(val), vv);
                            if (dtmp.ContainsKey(vv))
                            {
                                dtmp[vv] = Offset;
                            }
                            Offset   += size;
                            datasize += size;
                        }
                        else
                        {
                            dtmp[vv] = 0;
                        }
                    }

                    //更新指针区域
                    this.WriteInt(0, (int)datasize); //写入整体数据大小
                    this.Write((int)mTagIds.Count);  //写入变量个数

                    //写入变量、数据区对应的索引
                    int count = 0;
                    foreach (var vv in dtmp)
                    {
                        this.WriteInt(headOffset + count, (int)vv.Key);
                        this.WriteInt(headOffset + count + 4, (int)(vv.Value - tagheadoffset));
                        count += 8;
                    }

                    if (IsEnableCompress)
                    {
                        ZipCompress(headOffset + mTagIds.Count * 8, (int)datasize);
                    }

                    ServiceLocator.Locator.Resolve <IDataSerialize3>().RequestToSeriseFile(this);
                    sw.Stop();
                    LoggerService.Service.Info("CompressEnginer", this.Name + " 压缩完成 耗时:" + sw.ElapsedMilliseconds + " CPU Id:" + ThreadHelper.GetCurrentProcessorNumber(), ConsoleColor.Blue);
                }
                catch (Exception ex)
                {
                    LoggerService.Service.Erro("CompressEnginer", ex.StackTrace + "  " + ex.Message);
                }
                mIsRunning = false;
            }
        }