示例#1
0
        private ErrorCode TryGetRandomGame(string queryData, JoinRandomGameRequest joinRequest, ILobbyPeer peer, out GameState gameState, out string message)
        {
            message = null;

            int skipCount = 0;

            while (true)
            {
                string id;
                try
                {
                    id = this.gameDatabase.FindMatch(queryData, skipCount++);
                }
                catch (DbException sqlException)
                {
                    gameState = null;
                    message   = sqlException.Message;
                    return(ErrorCode.OperationInvalid);
                }

                if (string.IsNullOrEmpty(id))
                {
                    gameState = null;
                    return(ErrorCode.NoMatchFound);
                }

                if (!this.gameDict.TryGet(id, out gameState))
                {
                    return(ErrorCode.NoMatchFound);
                }

                if (IsGameJoinable(joinRequest, peer, gameState))
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug($"Random Game '{gameState}', CheckUserOnJoin:{gameState.CheckUserIdOnJoin}, " +
                                  $"UserLists: {gameState.GetUserListsAsString()} Properties:{ValueToString.ToString(gameState.ToHashTable())}" +
                                  $"is joinable for request: {ValueToString.OperationToString(joinRequest.OperationRequest)}, Joining User:{peer.UserId}");
                    }
                    return(ErrorCode.Ok);
                }
            }
        }
示例#2
0
        private ErrorCode GetFirstJoinableGame(JoinRandomGameRequest joinRequest, ILobbyPeer peer, out GameState gameState)
        {
            var node = this.gameDict.First;

            while (node != null)
            {
                gameState = node.Value;
                if (IsGameJoinable(joinRequest, peer, gameState))
                {
                    log.Debug($"First Joinable Game '{gameState}', CheckUserOnJoin:{gameState.CheckUserIdOnJoin}, " +
                              $"UserLists: {gameState.GetUserListsAsString()} Properties:{ValueToString.ToString(gameState.ToHashTable())}" +
                              $"is joinable for request: {ValueToString.OperationToString(joinRequest.OperationRequest)}, Joining User:{peer.UserId}");
                    return(ErrorCode.Ok);
                }

                node = node.Next;
            }

            gameState = null;
            return(ErrorCode.NoMatchFound);
        }
示例#3
0
        private static void GetGenericCounters(string category, string counter, string instance, string[] hosts, int nThreads, int nReads, int sleep, ValueToString func)
        {
            DateTime startTime = DateTime.Now;
            Dictionary<string, float> dtData = new Dictionary<string, float>();

            MySpace.DataMining.Threading.ThreadTools<string>.Parallel(
            new Action<string>(
            delegate(string slave)
            {
                if (string.Compare(slave, "localhost", true) == 0)
                {
                    slave = System.Net.Dns.GetHostName();
                }

                lock (dtData)
                {
                    Console.WriteLine();
                    Console.WriteLine("Waiting to connect: {0}", slave);
                }

                try
                {
                    System.Diagnostics.PerformanceCounter pc = new System.Diagnostics.PerformanceCounter(category, counter, instance, slave);

                    lock (dtData)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Connected: {0}", slave);
                    }

                    //Initial reading.
                    pc.NextValue();

                    float data = 0;

                    for (int i = 0; i < nReads; i++)
                    {
                        System.Threading.Thread.Sleep(sleep);
                        data += pc.NextValue();
                    }

                    if (nReads > 1)
                    {
                        data = data / (float)nReads;
                    }

                    lock (dtData)
                    {
                        Console.WriteLine();
                        Console.WriteLine("{0}: {1}: {2}", counter, slave, func == null ? data.ToString("N2") : func(data));
                        dtData.Add(slave, data);
                    }
                }
                catch (Exception e)
                {
                    lock (dtData)
                    {
                        Console.Error.WriteLine("Error: {0}: {1}", slave, e.Message);
                    }
                }
            }
            ), hosts, nThreads);

            if (dtData.Count > 0)
            {
                //Sort
                List<KeyValuePair<string, float>> sData = new List<KeyValuePair<string, float>>(dtData);
                sData.Sort(CompareFloat);

                //Max, min
                Console.WriteLine();
                Console.WriteLine("Min {0}: {1}: {2}", counter, sData[0].Key, func == null ? sData[0].Value.ToString("N2") : func(sData[0].Value));
                Console.WriteLine("Max {0}: {1}: {2}", counter, sData[sData.Count - 1].Key, func == null ? sData[sData.Count - 1].Value.ToString("N2") : func(sData[sData.Count - 1].Value));

                double totalData = 0;

                foreach (float f in dtData.Values)
                {
                    totalData += f;
                }

                //Avg
                double avg = totalData / (double)sData.Count;

                Console.WriteLine();
                Console.WriteLine("Avg {0}: {1}", counter, func == null ? avg.ToString("N2") : func(avg));
            }           

            //Dt
            Console.WriteLine();
            Console.WriteLine("Perfmon Request Time: {0}", startTime.ToString());
            Console.WriteLine("Perfmon End Time: {0}", DateTime.Now.ToString());
        }
        OperationResponse IOperationHandler.OnOperationRequest(PeerBase peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            try
            {
                return(this.OnOperationRequest(peer, operationRequest, sendParameters));
            }
            catch (Exception e)
            {
                /// we do not use LogExtensions log methods here to reduce cpu loading if message will be skipped anyway
                if (exceptionLogGuard.IncrementAndCheck())
                {
                    var message = LogExtensions.AddSkipedMessagesInfo(exceptionLogGuard,
                                                                      $"OnOperationRequest Exception: p:{peer}, Exception Msg:{e.Message}, request:{ValueToString.OperationToString(operationRequest)}");
                    log.Error(message, e);
                }

                return(new OperationResponse(operationRequest.OperationCode)
                {
                    ReturnCode = (short)ErrorCode.InternalServerError,
                    DebugMessage = e.ToString()
                });
            }
        }
示例#5
0
        private static void GetGenericCounters(string category, string counter, string instance, string[] hosts, int nThreads, int nReads, int sleep, ValueToString func)
        {
            DateTime startTime = DateTime.Now;
            Dictionary <string, float> dtData = new Dictionary <string, float>();

            MySpace.DataMining.Threading.ThreadTools <string> .Parallel(
                new Action <string>(
                    delegate(string slave)
            {
                if (string.Compare(slave, "localhost", true) == 0)
                {
                    slave = System.Net.Dns.GetHostName();
                }

                lock (dtData)
                {
                    Console.WriteLine();
                    Console.WriteLine("Waiting to connect: {0}", slave);
                }

                try
                {
                    System.Diagnostics.PerformanceCounter pc = new System.Diagnostics.PerformanceCounter(category, counter, instance, slave);

                    lock (dtData)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Connected: {0}", slave);
                    }

                    //Initial reading.
                    pc.NextValue();

                    float data = 0;

                    for (int i = 0; i < nReads; i++)
                    {
                        System.Threading.Thread.Sleep(sleep);
                        data += pc.NextValue();
                    }

                    if (nReads > 1)
                    {
                        data = data / (float)nReads;
                    }

                    lock (dtData)
                    {
                        Console.WriteLine();
                        Console.WriteLine("{0}: {1}: {2}", counter, slave, func == null ? data.ToString("N2") : func(data));
                        dtData.Add(slave, data);
                    }
                }
                catch (Exception e)
                {
                    lock (dtData)
                    {
                        Console.Error.WriteLine("Error: {0}: {1}", slave, e.Message);
                    }
                }
            }
                    ), hosts, nThreads);

            if (dtData.Count > 0)
            {
                //Sort
                List <KeyValuePair <string, float> > sData = new List <KeyValuePair <string, float> >(dtData);
                sData.Sort(CompareFloat);

                //Max, min
                Console.WriteLine();
                Console.WriteLine("Min {0}: {1}: {2}", counter, sData[0].Key, func == null ? sData[0].Value.ToString("N2") : func(sData[0].Value));
                Console.WriteLine("Max {0}: {1}: {2}", counter, sData[sData.Count - 1].Key, func == null ? sData[sData.Count - 1].Value.ToString("N2") : func(sData[sData.Count - 1].Value));

                double totalData = 0;

                foreach (float f in dtData.Values)
                {
                    totalData += f;
                }

                //Avg
                double avg = totalData / (double)sData.Count;

                Console.WriteLine();
                Console.WriteLine("Avg {0}: {1}", counter, func == null ? avg.ToString("N2") : func(avg));
            }

            //Dt
            Console.WriteLine();
            Console.WriteLine("Perfmon Request Time: {0}", startTime.ToString());
            Console.WriteLine("Perfmon End Time: {0}", DateTime.Now.ToString());
        }