예제 #1
0
        private void writeResToDb()
        {
            //Console.WriteLine(string.Format("merge outcome..., init num : {0}", this.GridStrengths.Count));
            //Console.ReadKey();
            DateTime d1, d2;

            d1 = DateTime.Now;
            CalcGridStrength calc = new CalcGridStrength(this.cellInfo, null);

            this.GridStrengths = calc.MergeMultipleTaskStrength(this.MultiTasksGridStrengths);
            d2 = DateTime.Now;
            Console.WriteLine(string.Format("merge done. now num : {0}, using time: {1}ms", this.GridStrengths.Count, (d2 - d1).TotalMilliseconds));

            // 2017.6.14
            Console.WriteLine();
            Console.WriteLine("射线所能达到的最远地面距离: {0} m,该点功率:{1} dbm", calc.maxDistGround, calc.dbm);
            Console.WriteLine("小区平面坐标:({0}, {1})", calc.cellInfo.SourcePoint.X, calc.cellInfo.SourcePoint.Y);
            Console.WriteLine("射线所能达到的最远地面坐标:({0}, {1})", calc.gx, calc.gy);
            Console.WriteLine("覆盖栅格总数: {0}", this.GridStrengths.Count);
            Console.WriteLine();

            //Console.WriteLine("connection = " + DB.DataUtil.ConnectionString);

            Console.WriteLine("writing to database ...");

            GridCover gc = GridCover.getInstance();

            gc.convertToDt(this.GridStrengths);
            this.GridStrengths.Clear();
            Hashtable ht = new Hashtable();

            ht["eNodeB"] = this.cellInfo.eNodeB;
            ht["CI"]     = this.cellInfo.CI;
            //gc.deleteGroundCover(ht);
            gc.wirteGroundCover(ht);
            gc.clearGround();
            //if (this.computeIndoor)
            {
                //gc.deleteBuildingCover(ht);
                gc.writeBuildingCover(ht);
                gc.clearBuilding();
            }
            Console.WriteLine("地面栅格总数: {0}", gc.ng);
            Console.WriteLine("立体栅格总数: {0}", gc.nb);
            end = DateTime.Now;
            string info = string.Format("总运行时间:{0}毫秒\n", (end - start).TotalMilliseconds);

            Console.WriteLine(info);
            Console.WriteLine("write done");

            RedisMq.Pub("cover2db_finish", this.cellInfo.eNodeB);

            //this.GridStrengths.Clear();
            //Console.ReadKey(); // 2019.04.12
            this.cs.free();
            this.Close();  // 2019.04.12
                           //this.procDoneNum = 0;
        }
예제 #2
0
        private void readCalcResultAsync(IntPtr Chandle, int dataSize)
        {
            //-1代表子进程写入共享内存失败
            if (dataSize == -1)
            {
                Console.WriteLine(string.Format("Write mmf {0} failed", Chandle));
                System.Environment.Exit(2);
            }
            //0代表当前共享内存中不存在数据,则直接返回,且让++this.procDoneNum
            if (dataSize == 0)
            {
                Console.WriteLine(string.Format("当前批{0}没有数据", Chandle));
                if (++this.procDoneNum == this.processNum)
                {
                    Task.Run(() => {
                        writeResToDb();
                    });
                }
                return;
            }

            DateTime t1, t2;

            t1 = DateTime.Now;
            Console.WriteLine(string.Format("read params :child handle = {0}, data size = {1}", Chandle, dataSize));

            string shareName = this.getMMFName(Chandle);

            Console.WriteLine(string.Format("read child outcome :{0}", shareName));
            IntPtr mmf = IntPtr.Zero;

            try
            {
                mmf = MMF.OpenFileMapping(MMF.FileMapAccess.FileMapRead, false, shareName);
                Console.WriteLine("open file ...");
            }
            catch (Exception e)
            {
                //MessageBox.Show(string.Format("open mmf {0} failed, error : {1}", shareName, e.Message));
                Console.WriteLine(string.Format("open mmf {0} failed, error : {1}", shareName, e.Message));
                System.Environment.Exit(2);
            }
            if (IntPtr.Zero == mmf)
            {
                //MessageBox.Show(string.Format("共享内存<{0}>打开失败,错误信息编号:{1}", shareName, MMF.GetLastError()));
                Console.WriteLine(string.Format("共享内存<{0}>打开失败,错误信息编号:{1}", shareName, MMF.GetLastError()));
                System.Environment.Exit(2);
                return;
            }
            IntPtr reader = IntPtr.Zero;

            try
            {
                reader = MMF.MapViewOfFile(mmf, MMF.FileMapAccess.FileMapRead, 0, 0, (uint)dataSize);
                Console.WriteLine("map view ...");
            }
            catch (Exception e)
            {
                Console.WriteLine("map view failed");
                System.Environment.Exit(2);
                return;
            }
            if (reader == IntPtr.Zero)
            {
                //MessageBox.Show(string.Format("共享内存<{0}>映射失败,错误信息编号:{1}", shareName, MMF.GetLastError()));
                Console.WriteLine(string.Format("共享内存<{0}>映射失败,错误信息编号:{1}", shareName, MMF.GetLastError()));
                System.Environment.Exit(2);
                return;
            }

            IntPtr tp    = IntPtr.Zero;
            Type   type  = typeof(MMFGSStruct);
            int    ssize = Marshal.SizeOf(type);

            Console.WriteLine("ssize = " + ssize);

            //tp = new IntPtr(reader.ToInt64());
            MMFGSStruct data = new MMFGSStruct();
            long        sp   = reader.ToInt64();

            for (int dsize = 0; dsize < dataSize; dsize += ssize)
            {
                try
                {
                    tp   = new IntPtr(sp + dsize);
                    data = (MMFGSStruct)Marshal.PtrToStructure(tp, typeof(MMFGSStruct));

                    // convertFromMMFGSStruct 将共享内存传递的计算结果转换为GridStrength
                    this.MultiTasksGridStrengths.Add(convertFromMMFGSStruct(data));
                }
                catch (Exception e)
                {
                    Console.WriteLine(string.Format("read error : tp = {0}, dsize = {1}, msg = {2}", tp.ToInt64(), dsize, e.Message));
                    System.Environment.Exit(2);
                    //MessageBox.Show(string.Format("read error : tp = {0}, dsize = {1}, msg = {2}", tp.ToInt32(), dsize, e.Message));
                }
            }
            Console.WriteLine("after read....");
            MMF.UnmapViewOfFile(reader);
            MMF.CloseHandle(mmf);
            mmf = reader = IntPtr.Zero;
            t2  = DateTime.Now;
            Console.WriteLine(string.Format("read {0} done. now total : {1}, using time: {2}", shareName, this.MultiTasksGridStrengths.Count, (t2 - t1).TotalMilliseconds));
            Console.WriteLine("**********************************************************************");
            this.procDoneNum++;
            Console.WriteLine(String.Format("已处理{0}/{1}个进程", this.procDoneNum, this.processNum));
            Console.WriteLine("**********************************************************************");
            //this.outGSs();

            //if (++this.procDoneNum == Math.Min(this.maxProcNum, this.processNum - this.procDoneNum1))
            if (this.procDoneNum == this.processNum)
            {
                Task.Run(() => {
                    writeResToDb();
                });
                RedisMq.Pub("rayTrace_finish", this.cellInfo.eNodeB);
            }
        }