Exemple #1
0
        static void Main(string[] args)
        {
            InitAllController();

            #region 1、日志,配置,建立Socket,监听端口
            BaseProgram.PubMain1(ServerType, m_Port);
            #endregion

            #region 2、连接事件
            Thread mThread = new Thread(ListenClientCallBack);
            mThread.Start();
            #endregion

            #region 主循环
            while (true)
            {
                Thread.CurrentThread.Join(10);
                try
                {
                    ServerHeartbeat.Heartbeat();
                }
                catch (Exception ex)
                {
                    Loger.Error($"服务器错误{ex}");
                }
            }
            #endregion
        }
Exemple #2
0
        public static int Main(string[] args)
        {
            return(BaseProgram <CommandLineOptions> .Run(args, options =>
            {
                var database = new UnifaceLibrary.UnifaceDatabase(options.DatabaseConnectionString);
                var codeRootDir = new DirectoryInfo(options.CodeRootDir);

                Action <string> pullObject = (string objectIdString) => {
                    var objectId = UnifaceObjectId.Parse(objectIdString);
                    database.PullObject(objectId, codeRootDir);

                    Console.WriteLine($"Pulled {objectId}");
                };

                if (options.UseStdIn)
                {
                    string objectIdLine;

                    while (!string.IsNullOrEmpty(objectIdLine = Console.ReadLine()))
                    {
                        pullObject(objectIdLine);
                    }
                }
                else
                {
                    pullObject(options.ObjectId);
                }

                return 0;
            }));
        }
Exemple #3
0
        public static float ProgramRunner(BaseProgram progEvaulateProgram,
                                          BaseProgram progOpponents, Graphics grpGraphics, bool fDisplayProgress)
        {
            // Reset the variables of all the programs.
            for (int i = 0; i < progEvaulateProgram.Variables.Length; i++)
            {
                progEvaulateProgram.Variables[i].Value = 0;
            }

            CAMatrix matMatrix = InitialiseMatrix(progEvaulateProgram, progOpponents);

            // Running the matrix players.
            for (int i = 0; i < 200; i++)
            {
                if (fDisplayProgress == true)
                {
                    DisplayMatrix(matMatrix, grpGraphics);
                    Thread.Sleep(100);
                }

                RunTimeStep(matMatrix);
            }

            return(GetFitnessForMatrix(matMatrix));
        }
Exemple #4
0
        public static float ConstructNewCell(CACell celCurrCell, Direction dirDirection)
        {
            // If there is no energy left, don't do it.
            if (celCurrCell.fAvaliableEnergy < ENERGY_NEEDED_FOR_CONSTRUCTION)
            {
                return(3);
            }

            int nNextCellX = celCurrCell.x + dirDirection.xDir;
            int nNextCellY = celCurrCell.y + dirDirection.yDir;

            // Test if the location is valid
            if (!(celCurrCell.matParentMatrix.IsLocationValid(nNextCellX, nNextCellY)))
            {
                return(2);
            }

            // Test if there's an already cell there :
            if (celCurrCell.matParentMatrix.GetCell(nNextCellX, nNextCellY) != null)
            {
                return(0);
            }

            // Clone the current program, assigning it the same "TeamID" :
            // The new cell would have zero energy.
            BaseProgram progClonedProgram = (BaseProgram)celCurrCell.progProgram.Clone();

            celCurrCell.matParentMatrix.CreateCell(nNextCellX, nNextCellY, progClonedProgram,
                                                   celCurrCell.clrTeamColor, 0);

            // Substract the total energy the cell has.
            celCurrCell.fAvaliableEnergy -= ENERGY_NEEDED_FOR_CONSTRUCTION;

            return(1);
        }
Exemple #5
0
        public void engEngine_EvalFitnessForProgramEvent(BaseProgram progProgram,
                                                         BaseEngine sender)
        {
            if (progBestProgramInPreviousGeneration == null)
            {
                progBestProgramInPreviousGeneration = sender.Population[0][0];
            }

            float dAbsoluteFitness = 0;

            // Attempt to gather from 10 different tests.
            float dWorstCaseScenario = 99999999;

            for (int nTestNum = 0; nTestNum < 5; nTestNum++)
            {
                float dFitness = RunnerEvolution.ProgramRunner(m_cWorld, progProgram,
                                                               null, false);
                if (dFitness < dWorstCaseScenario)
                {
                    dWorstCaseScenario = dFitness;
                }

                /* dAbsoluteFitness += RunnerEvolution.ProgramRunner(m_cWorld, progProgram,
                 *   null, false);*/
            }

            progProgram.Fitness = 1000000 - dWorstCaseScenario;
        }
 public Terminal(int width, int height, BaseProgram context)
 {
     this.width   = width;
     this.height  = height;
     this.context = context;
     clear();
 }
        static void Main(string[] args)
        {
            ReadConfiguration();

            var client  = new LUISAuthoringClient(new Uri("https://" + Region + ".api.cognitive.microsoft.com/luis/api/v2.0/"), new ApiKeyServiceClientCredentials(ProgrammaticKey));
            var program = new BaseProgram(client, ProgrammaticKey);

            program.Run();
        }
        static void Main(string[] args)
        {
            ReadConfiguration();

            EndPoint = EndPoint.Insert(EndPoint.Length - 5, "/api");
            var client  = new LUISAuthoringClient(new Uri(EndPoint), new ApiKeyServiceClientCredentials(ProgrammaticKey));
            var program = new BaseProgram(client, ProgrammaticKey);

            program.Run();
        }
Exemple #9
0
        static void Main(string[] args)
        {
            BaseProgram.PubMain1(args, EServerType.登陆);

            #region 启动服务器后执行服务器数据初始化

            OnServerStart();

            #endregion 启动服务器后执行服务器数据初始化


            #region  务器事件

            //新连接事件
            BaseServerInfo.AppServer.NewSessionConnected += new SessionHandler <LunarSession>(Dispatcher.OnSessionConnected);

            //连接断开事件
            BaseServerInfo.AppServer.SessionClosed += new SessionHandler <LunarSession, CloseReason>(Dispatcher.OnSessionClosed);

            //收到消息事件
            BaseServerInfo.AppServer.NewRequestReceived += new RequestHandler <LunarSession, LunarRequestInfo>(BaseDispatch.OnDispatch);

            #endregion  务器事件

            BaseProgram.PubMain2();

            BaseProgram.PubMain3();

            #region 添加读取指令的线程

            BaseServerInfo.threadDriverCmds = new Thread(new ThreadStart(DriverCmds.ThreadDriverCmds));
            BaseServerInfo.threadDriverCmds.Start();
            Thread.Sleep(1000);

            #endregion 添加读取指令的线程

            BaseProgram.StartThreadDbMysqlSecond();

            #region 进入主循环

            while (true)
            {
                System.Threading.Thread.CurrentThread.Join(BaseServerInfo.ServerHeartbeat);
                try
                {
                    ServerHeartbeat.Heartbeat();
                }
                catch (Exception ex)
                {
                    loger.Fatal("服务器错误", ex);
                }
            }

            #endregion 进入主循环
        }
Exemple #10
0
        static void Main(string[] args)
        {
            ReadConfiguration();

            var client = new LUISAuthoringClient(new ApiKeyServiceClientCredentials(ProgrammaticKey));

            client.Endpoint = EndPoint;
            var program = new BaseProgram(client, ProgrammaticKey);

            program.Run();
        }
Exemple #11
0
        static void Main(string[] args)
        {
            #region 1、日志,配置,建立Socket,监听端口
            BaseProgram.PubMain1(ServerType, m_Port);
            #endregion

            #region 2、连接事件
            Thread mThread = new Thread(ListenClientCallBack);
            mThread.Start();
            #endregion
            Console.ReadLine();
        }
Exemple #12
0
        public void CreateCell(int x, int y, BaseProgram progProgram, Color clrTeamColor, float fAvaliableEnergy)
        {
            CACell celCell = new CACell();

            celCell.progProgram      = progProgram;
            celCell.clrTeamColor     = clrTeamColor;
            celCell.fAvaliableEnergy = fAvaliableEnergy;
            celCell.x = x;
            celCell.y = y;
            celCell.matParentMatrix = this;
            lstNewCellsForNextTime.Add(celCell);
        }
        void engEngine_EvalFitnessForProgramEvent(BaseProgram progProgram,
                                                  BaseEngine sender)
        {
            progProgram.Fitness = 0;
            Hashtable hsVariables = progProgram.GetVariables();
            Variable  varX        = (Variable)hsVariables["X"];
            Variable  varY        = (Variable)hsVariables["Y"];

            for (int nY = 0;
                 nY < fstBitmap.Height;
                 nY += nSkippedPixelsInImage)
            {
                for (int nX = 0;
                     nX < fstBitmap.Width;
                     nX += nSkippedPixelsInImage)
                {
                    varX.Value = (float)nX / fstBitmap.Width;
                    varY.Value = (float)nY / fstBitmap.Height;
                    Color clrPixel        = fstBitmap.GetPixel(nX, nY);
                    byte  nGrayScaleColor = (byte)((clrPixel.R + clrPixel.G + clrPixel.B) / 3);
                    float fExpectedResult = (float)((nGrayScaleColor / 128.0) - 1);
                    progProgram.Run();
                    float fActualResult = progProgram.Result;
                    float fDifference   = Math.Abs(fExpectedResult - fActualResult);
                    progProgram.Fitness += fDifference;
                    byte nActualGrayScaleColor = (byte)((fActualResult + 1) * 128.0);
                }
            }

            // @debug 6.2.2013 : in each generation, we select different pixels.

            /*for (int nY = 0;
             *   nY < fstBitmap.Height;
             *   nY ++)
             * {
             *  for (int nX = (sender.GenerationNum % nSkippedPixelsInImage);
             *       nX < fstBitmap.Width;
             *       nX += nSkippedPixelsInImage)
             *  {
             *      varX.Value = (float)nX / fstBitmap.Width;
             *      varY.Value = (float)nY / fstBitmap.Height;
             *      Color clrPixel = fstBitmap.GetPixel(nX, nY);
             *      byte nGrayScaleColor = (byte)((clrPixel.R + clrPixel.G + clrPixel.B) / 3);
             *      float fExpectedResult = (float)((nGrayScaleColor / 128.0) - 1);
             *      progProgram.Run();
             *      float fActualResult = progProgram.Result;
             *      float fDifference = Math.Abs(fExpectedResult - fActualResult);
             *      progProgram.Fitness += fDifference;
             *      byte nActualGrayScaleColor = (byte)((fActualResult + 1) * 128.0);
             *  }
             * }*/
        }
        static void Main(string[] args)
        {
            ReadConfiguration();

            var client = new LuisProgrammaticAPI(new ApiKeyServiceClientCredentials(ProgrammaticKey))
            {
                AzureRegion = AzureRegions.Westus
            };

            var program = new BaseProgram(client);

            program.Run();
        }
Exemple #15
0
        public static int Main(string[] args)
        {
            return(BaseProgram <CommandLineOptions> .Run(args, options =>
            {
                var database = new UnifaceLibrary.UnifaceDatabase(options.DatabaseConnectionString);

                foreach (var unifaceObject in database.GetAllObjects())
                {
                    Console.WriteLine(unifaceObject.Id);
                }

                return 0;
            }));
        }
Exemple #16
0
        public static int Main(string[] args)
        {
            return(BaseProgram <CommandLineOptions> .Run(args, options =>
            {
                var database = new UnifaceLibrary.UnifaceDatabase(options.DatabaseConnectionString);

                foreach (var unifaceObjectChange in database.GetAllObjectsChangedSince(options.SinceVersion))
                {
                    Console.WriteLine($"{unifaceObjectChange.ChangeOperation.ToString()} {unifaceObjectChange.Object.Id}");
                }

                return 0;
            }));
        }
Exemple #17
0
        public void engEngine_GenerationIsCompleteEvent(Statistics stsStatistics,
                                                        BaseEngine sender)
        {
            strLabelString = "Generation num = " + stsStatistics.GenerationNumber + ", Min fitness = " +
                             stsStatistics.MinFitnessProgram.Fitness + ", Min fitness nodes = " + stsStatistics.MinFitnessProgram.Size;
            ((TreeProgram)stsStatistics.MinFitnessProgram).Draw(pnlDrawProgram.CreateGraphics(), pnlDrawProgram.Width, pnlDrawProgram.Height, this);

            if (((stsStatistics.GenerationNumber % 10) == 0) && (stsStatistics.GenerationNumber != 0))
            {
                for (int i = 0; i < 5; i++)
                {
                    RunnerEvolution.ProgramRunner(m_cWorld, stsStatistics.MinFitnessProgram,
                                                  pnlWorldView.CreateGraphics(), true);
                }
            }


            // Show statistics about the islands. Make a graph about the islands fitnesses.
            progBestProgramInPreviousGeneration = stsStatistics.MinFitnessProgram;

            float dMinimalFitnessInPopulation = stsStatistics.MinFitnessProgram.Fitness;
            float dMaxMinFitnessInIslands     = 0;

            for (int i = 0; i < sender.NumberOfIslands; i++)
            {
                BaseProgram cMinFitnessProgramForIsland = stsStatistics.GetMinFitnessProgramForIsland(i);
                if (cMinFitnessProgramForIsland.Fitness > dMaxMinFitnessInIslands)
                {
                    dMaxMinFitnessInIslands = cMinFitnessProgramForIsland.Fitness;
                }
            }

            int      ISLAND_BAR_WIDTH = (int)(pnlViewIslands.Width / sender.NumberOfIslands);
            Graphics g = pnlViewIslands.CreateGraphics();

            g.Clear(Color.Black);
            for (int i = 0; i < sender.NumberOfIslands; i++)
            {
                float dIslandFitness          = stsStatistics.GetMinFitnessProgramForIsland(i).Fitness;
                float dPrecentageOfMinFitness = (dIslandFitness - dMinimalFitnessInPopulation) / (dMaxMinFitnessInIslands - dMinimalFitnessInPopulation);
                g.FillRectangle(Brushes.RoyalBlue, i * ISLAND_BAR_WIDTH, pnlViewIslands.Height - (pnlViewIslands.Height * dPrecentageOfMinFitness), ISLAND_BAR_WIDTH, pnlViewIslands.Height);
            }

            // Write the max and min fitnesses value on the graph.
            g.DrawString(dMaxMinFitnessInIslands.ToString(), new Font("Times New Roman", 12.0f), Brushes.Red, 0, 0);
            g.DrawString(dMinimalFitnessInPopulation.ToString(), new Font("Times New Roman", 12.0f), Brushes.Red, 0, pnlViewIslands.Height - 20);
        }
Exemple #18
0
        /// <summary>
        /// 判断PHP,mysql,nginx是否在wnmp目录中
        /// </summary>
        public static void CheckForApps(BaseProgram nginx, BaseProgram mysql, BaseProgram php)
        {
            Log.wnmp_log_notice("Checking for applications", Log.LogSection.WNMP_MAIN);
            if (!Directory.Exists(nginx.workingDir))
            {
                Log.wnmp_log_error("Error: Nginx Not Found", Log.LogSection.WNMP_NGINX);
            }

            if (!Directory.Exists(mysql.workingDir))
            {
                Log.wnmp_log_error("Error: Mysql Not Found", Log.LogSection.WNMP_MARIADB);
            }

            if (!Directory.Exists(Common.APP_STARTUP_PATH + Common.Settings.PHPDirName.Value))
            {
                Log.wnmp_log_error("Error: PHP Not Found", Log.LogSection.WNMP_PHP);
            }
        }
Exemple #19
0
        public override void Assign(BaseProgram other)
        {
            base.Assign(other);
            if (!(other is SystemProgram))
            {
                return;
            }

            SystemProgram program = other as SystemProgram;

            this.ProgramPrivilegeId = program.Privielges.Where(x => x.PrivilegeCode == ProgramPrivilege.PRIVILEGE_RUN).Single().RecordId;

            this.Children = new ProgramWithPrivilgeViewModel[program.Children.Count];
            this.DataType = "app.model.admin.SystemMenuTreeModel";

            for (int i = 0; i < this.Children.Length; i++)
            {
                ProgramWithPrivilgeViewModel childMenu = new ProgramWithPrivilgeViewModel();
                SystemProgram childProgram             = program.Children[i];
                childMenu.Assign(childProgram);
                this.Children[i] = childMenu;
            }

            if (this.Children.Length == 0)
            {
                this.Children = (from item in program.Privielges
                                 where item.PrivilegeCode != ProgramPrivilege.PRIVILEGE_RUN
                                 select new
                {
                    item.RecordId,
                    item.ProgramId,
                    item.PrivilegeCode,
                    item.PrivilegeName,
                    Checked = false,
                    DataType = "app.model.admin.ProgramPrivilegeModel"
                }).ToArray();
            }

            if (this.Children.Length > 0)
            {
                this.Expanded = true;
            }
        }
Exemple #20
0
        public void engEngine_EvalFitnessForProgramEvent(BaseProgram progProgram,
                                                         BaseEngine sender)
        {
            if (progBestProgramInPreviousGeneration == null)
            {
                progBestProgramInPreviousGeneration = sender.Population[0][0];
            }

            float dAbsoluteFitness = 0;

            // Attempt to gather from 20 different tests.
            for (int nTestNum = 0; nTestNum < 5; nTestNum++)
            {
                dAbsoluteFitness += CAEvolution.ProgramRunner(progProgram,
                                                              progBestProgramInPreviousGeneration, null, false);
            }

            progProgram.Fitness = 100000 - dAbsoluteFitness;
        }
Exemple #21
0
        public void engEngine_GenerationIsCompleteEvent(Statistics stsStatistics,
                                                        BaseEngine sender)
        {
            strLabelString = "Generation num = " + stsStatistics.GenerationNumber + ", Min fitness = " +
                             stsStatistics.MinFitnessProgram.Fitness + ", Min fitness nodes = " + stsStatistics.MinFitnessProgram.Size;
            ((TreeProgram)stsStatistics.MinFitnessProgram).Draw(pnlDrawProgram.CreateGraphics(), pnlDrawProgram.Width, pnlDrawProgram.Height, this);

            if ((stsStatistics.GenerationNumber % 20) == 0)
            {
                CAEvolution.ProgramRunner(stsStatistics.MinFitnessProgram,
                                          progBestProgramInPreviousGeneration, pnlMatrixDisplay.CreateGraphics(), true);

                CAEvolution.ProgramRunner(stsStatistics.MinFitnessProgram,
                                          progBestProgramInPreviousGeneration, pnlMatrixDisplay.CreateGraphics(), true);

                CAEvolution.ProgramRunner(stsStatistics.MinFitnessProgram,
                                          progBestProgramInPreviousGeneration, pnlMatrixDisplay.CreateGraphics(), true);
            }

            progBestProgramInPreviousGeneration = stsStatistics.MinFitnessProgram;
        }
Exemple #22
0
        public static CAMatrix InitialiseMatrix(BaseProgram progEvaulateProgram,
                                                BaseProgram progOpponents)
        {
            CAMatrix matMatrix = new CAMatrix();

            // Position player 0 on board
            ImprovedRandom rndRandom       = GlobalRandom.m_rndRandom;
            int            nMinXToGenerate = matMatrix.Width * 4 / 10;
            int            nMaxXToGenerate = matMatrix.Width * 6 / 10;
            int            nMinYToGenerate = matMatrix.Height * 4 / 10;
            int            nMaxYToGenerate = matMatrix.Height * 6 / 10;

            matMatrix.CreateCell(rndRandom.Next(nMinXToGenerate, nMaxXToGenerate),
                                 rndRandom.Next(nMinYToGenerate, nMaxYToGenerate),
                                 progEvaulateProgram,
                                 PLAYER_COLOR, STARTING_ENERGY);

            // Create possible colors
            List <Color> arrColors = new List <Color>();

            arrColors.Add(Color.RoyalBlue);
            arrColors.Add(Color.Silver);
            arrColors.Add(Color.Salmon);

            // Position other players on board
            BaseProgram progOpponent0 = (BaseProgram)progOpponents.Clone();

            matMatrix.CreateCell(rndRandom.Next(nMinXToGenerate, nMaxXToGenerate),
                                 rndRandom.Next(nMinYToGenerate, nMaxYToGenerate),
                                 progOpponent0, arrColors[0], STARTING_ENERGY);
            BaseProgram progOpponent1 = (BaseProgram)progOpponents.Clone();

            matMatrix.CreateCell(rndRandom.Next(nMinXToGenerate, nMaxXToGenerate),
                                 rndRandom.Next(nMinYToGenerate, nMaxYToGenerate),
                                 progOpponent1, arrColors[1], STARTING_ENERGY);

            return(matMatrix);
        }
 public AddFlowersPage(BaseProgram program) : base("Add Flowers", program)
 {
 }
 public ShareAppPage(BaseProgram program) : base("Share", program)
 {
 }
 public FlowerpotPage(BaseProgram program) : base("Flowerpot entity", program)
 {
 }
 public FindFlightsIntentPage(BaseProgram program) : base("FindFlights Intent", program)
 {
 }
 public AppDeletePage(BaseProgram program) : base("Delete", program)
 {
 }
 public AppDetailsPage(BaseProgram program) : base("Details", program)
 {
 }
Exemple #29
0
 public AppVersionInfoPage(BaseProgram program) : base("Details", program)
 {
 }
 public FlightsEntityPage(BaseProgram program) : base("Flights Composite Entity", program)
 {
 }