Ejemplo n.º 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;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// dotnet RedisDemo.dll --id=1 --minute=04
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //开始命令行模式,这样可以获取命令行启动服务时输入的参数
            var config = new ConfigurationBuilder()
                         .AddCommandLine(args)//支持命令行参数
                         .Build();

            //1.秒杀:
            string id     = config["id"];
            int    minute = Convert.ToInt32(config["minute"]);

            Console.WriteLine("请输入您要运行的方法");
            string inputStr = Console.ReadLine();

            if (inputStr == "Seckill1")
            {
                Seckill.Seckill1(id, minute);
                Seckill.Seckill2(id, minute);
            }
            else if (inputStr == "Transaction")
            {
                //2.事务
                RedisTransaction.TransationDemo();
                RedisTransaction.TransationDemo2();
            }
            else if (inputStr == "DistributedLock")
            {
                //3.分布式锁
                RedisDistributedLockDemo.Skills(minute, 30);
            }
            else if (inputStr == "PublishMsg") //发布消息
            {
                RedisMq.PublishMsg();
            }
            else if (inputStr == "SubscriptionMsg") //订阅消息
            {
                RedisMq.SubscriptionMsg();
            }
            else
            {
                RedisDistributedLockDemo.Skills(minute, 30);
            }
        }
Ejemplo n.º 3
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);
            }
        }