コード例 #1
0
 internal static void SpecAssertMessage(List <MessageCode> msgCodeList, MessageCode code, bool isTrue)
 {
     if (isTrue)
     {
         Assert.IsTrue(msgCodeList.Contains(code), code.ToString());
     }
     else
     {
         Assert.IsFalse(msgCodeList.Contains(code), code.ToString());
     }
 }
コード例 #2
0
        /// <summary>
        /// GetMessage method creates a single string with replaced placeholders from message.
        /// </summary>
        /// <param name="language">Language of the message from the LanguageEnum enum.</param>
        /// <returns>String representing the message.</returns>
        public string GetMessage(LanguageEnum language = LanguageEnum.En)
        {
            // Build a new message
            StringBuilder sb = new StringBuilder();

            // Add attribute, if present
            if (AttributeName != null)
            {
                sb.Append(AttributeName + " - ");
            }
            // Try to get message text
            if (MessagesEn.Messages.ContainsKey(MessageCode))
            {
                sb.Append(MessagesEn.Messages[MessageCode]);
            }
            else
            {
                sb.Append(MessageCode.ToString());
                Logger.LogToConsole($"Unknown message code {MessageCode}");
            }

            // Replace placeholders
            for (int i = 0; i < Placeholders.Count; i++)
            {
                sb.Replace($"{{{i}}}", Placeholders[i]);
            }
            return(sb.ToString());
        }
コード例 #3
0
 public static void AddListener(MessageCode msgCode, MessageHandler handler)
 {
     Debug.Log("监听消息" + msgCode.ToString() + handler.ToString());
     if (!s_messageHandlers.ContainsKey(msgCode))
     {
         s_messageHandlers.Add(msgCode, new List <MessageHandler>());
     }
     s_messageHandlers[msgCode].Add(handler);
 }
コード例 #4
0
ファイル: Form1.cs プロジェクト: qbasic16/Factorio-RCON
        void sr_Errors(MessageCode code, string data)
        {
            MethodInvoker m = () =>
            {
                OutputBox.SelectionColor = Color.Red;
                OutputBox.SelectedText   = "} " + code.ToString() + "\n" + (data == null ? "" : "} " + data + "\n");
            };

            this.Invoke(m);
        }
コード例 #5
0
 public static string Description(this MessageCode code)
 {
     if (Enum.IsDefined(typeof(MessageCode), code))
     {
         return(string.Format("{0}({1})", code.ToString(), (int)code));
     }
     else
     {
         return(string.Format("UNKNOWN({0})", (int)code));
     }
 }
コード例 #6
0
        public StartRecord()
        {
            // Set default values.
            StandardVersion    = 4;
            StandardSubversion = 2;
            MessageCode        = 117;

            // Make this a test message by default.
            Type = MessageType.Test;

            InvoiceId    = string.Empty;
            CurrencyCode = "EUR";

            // Define the fields for this record.
            MapField(2, 3, "Code").Numeric().Getter(x => MessageCode.ToString("000"));
            MapField(5, 2, "Versienummer berichtstandaard").Numeric().Getter(x => StandardVersion.ToString());
            MapField(7, 2, "Subversienummer berichtstandaard").Numeric().Getter(x => StandardSubversion.ToString());
            MapField(9, 1, "Soortbericht").Numeric().Getter(x =>
            {
                switch (Type)
                {
                case MessageType.Production:
                    return("P");

                case MessageType.Test:
                    return("T");

                default:
                    throw new InvalidOperationException("Message type is not specified.");
                }
            });

            MapField(10, 6, "Code informatiesysteem softwareleverancier").Numeric();

            MapField(26, 4, "UZOVI-nummer").Numeric().Getter(x => UzoviId.ToString());
            MapField(30, 8, "Code servicebureau").Numeric();
            MapField(38, 8, "Zorgverlenerscode").Numeric().Getter(x => CareProviderAgbId.ToString());
            MapField(46, 8, "Praktijkcode").Numeric();
            MapField(54, 8, "Instellingcode").Numeric();

            MapField(62, 2, "Identificatiecode betaling aan").Numeric().Getter(x => PaymentRecipientCode.ToString("D"));
            MapField(64, 8, "Begindatum declaratieperiode").Numeric().Getter(x => StartDate.ToString("yyyyMMdd"));
            MapField(72, 8, "Einddatum declaratieperiode").Numeric().Getter(x => EndDate.ToString("yyyyMMdd"));

            MapField(80, 12, "Factuurnummer declarant").Alphanumeric().Getter(x => InvoiceId);
            MapField(92, 8, "Dagtekening factuur").Numeric().Getter(x => InvoiceDate.ToString("yyyyMMdd"));

            MapField(114, 3, "Valutacode").Alphanumeric().Getter(x => CurrencyCode);
        }
コード例 #7
0
 public override string ToString()
 {
     return(string.Format("{0};Command={1}", base.ToString(), Command.ToString()));
 }
コード例 #8
0
 /// <summary>
 /// Response Result as JSON
 /// </summary>
 /// <param name="data"></param>
 /// <param name="message"></param>
 /// <param name="messageCode"></param>
 /// <returns></returns>
 public JsonResult ResponseResult(Object data, string message = MessageHelper.Success, MessageCode messageCode = MessageCode.OK)
 {
     return(Json(new { data, message, messagecode = messageCode.ToString() }, JsonRequestBehavior.AllowGet));
 }
コード例 #9
0
 private static string GetDescriptionOfEnum(MessageCode enums)
 {
     System.Reflection.FieldInfo fieldInfo             = enums.GetType().GetField(enums.ToString());
     DescriptionAttribute[]      descriptionAttributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
     return(descriptionAttributes.Length > 0 ? descriptionAttributes[0].Description : enums.ToString());
 }
コード例 #10
0
 public string GetMessage(MessageCode code)
 {
     CatchedCodes.Add(code);
     ReturnList.Add(code.ToString());
     return(code.ToString());
 }
コード例 #11
0
ファイル: Program.cs プロジェクト: qbasic16/Factorio-RCON
        static int Main(string[] args)
        {
            // Grab English strings for the interface.
            ILanguage lang = new English();

            string    password, command;
            IPAddress ip;
            int       port;

            bool interactive;

            // Parse command-line to tell if we're doing a one-shot command or if we're running interactive.
            if (args.Length > 0)
            {
                // There are arguments, so not interactive.
                interactive = false;

                // Four arguments indicates this is a one-shot command.
                if (args.Length == 4)
                {
                    try
                    {
                        ip   = IPAddress.Parse(args[0]);
                        port = int.Parse(args[1]);
                    }
                    catch (FormatException fe)
                    {
                        Console.WriteLine(lang["invalidparams"], fe.Message);
                        return(-1);
                    }
                    catch (OverflowException oe)
                    {
                        Console.WriteLine(lang["invalidparams"], oe.Message);
                        return(-1);
                    }
                    password = args[2];
                    command  = args[3];
                }

                else
                {
                    // Print out the usage instructions.
                    Console.WriteLine(lang["usage_instructions"]);
                    return(1);
                }
            }
            else
            {
                interactive = true;

                #if DEBUG
                Console.WriteLine("Use quick debug? Press y, else anything else!");
                if (Console.ReadKey().KeyChar == 'y')
                {
                    Console.ReadLine();
                    Console.WriteLine();
                    ip       = IPAddress.Parse("192.168.2.6");
                    port     = 27015;
                    password = "******";
                }
                else
                {
                #endif


                // Walk the user through entering parameters, & prevent them from entering anything invalid:

                do
                {
                    Console.WriteLine(lang["enterip"]);
                }while (!IPAddress.TryParse(Console.ReadLine(), out ip));

                do
                {
                    do
                    {
                        Console.WriteLine(lang["enterport"]);
                    }while (!int.TryParse(Console.ReadLine(), out port));
                }while (port < IPEndPoint.MinPort && port > IPEndPoint.MaxPort);

                // Valve's problem to stop people breaking the server with malformed passwords, not mine!
                Console.WriteLine(lang["enterpassword"]);
                password = Console.ReadLine();

                #if DEBUG
            }
                #endif

                command = null;
            }

            using (Rcon Sr = new Rcon())
            {
                #if DEBUG
                // Wire up our event handlers to receive errors from the server:
                Sr.Errors += (MessageCode, Message) => Console.WriteLine(lang["error"], MessageCode.ToString());
                #endif

                bool IsConnected = false;

                // Now, we'll actually try to connect!
                try
                {
                    IsConnected = Sr.ConnectBlocking(new IPEndPoint(ip, (int)port), password);
                }
                catch (ArgumentOutOfRangeException e)
                {
                    Console.WriteLine(lang["invalidparams"], e.Message);
                    return(-1);
                }

                if (IsConnected)
                {
                    if (interactive)
                    {
                        Console.WriteLine(lang["commandready"]);
                        // Just pull lines from the input and send them off.
                        while (true)
                        {
                            // Sr.ServerCommand(Console.ReadLine());
                            Console.WriteLine(Sr.ServerCommandBlocking(Console.ReadLine()));
                        }
                    }
                    else
                    {
                        // Fire a one-shot command.
                        Console.WriteLine(Sr.ServerCommandBlocking(command));
                    }
                }
                else
                {
                    // Not connected, so complain about it.
                    Console.WriteLine(lang["noconn"]);
                }

                return(0);
            }
        }
コード例 #12
0
ファイル: Form1.cs プロジェクト: Jake1305/SourceRcon
 void sr_Errors(MessageCode code, string data)
 {
     MethodInvoker m = () =>
     {
         OutputBox.SelectionColor = Color.Red;
         OutputBox.SelectedText = "} " + code.ToString() + "\n" + (data == null ? "" : "} " + data + "\n");
     };
     this.Invoke(m);
 }