Exemple #1
0
        /// <summary>
        /// Invio risposta a messaggi aventi messagedata di tipo <typeparamref name="MsgData"/>
        /// </summary>
        /// <param name="receivedMsg">Messaggio a cui viene inviata risposta</param>
        /// <param name="MsgCode">Codice messaggio di risposta</param>
        /// <param name="MessageData">Dato da inviare (contiene Validation)</param>
        /// <param name="Result">Risultato dell'operazione richiesta</param>
        /// <returns>true se tutto bene, altrimenti false</returns>
        private bool SendResponse(IIncomingMessage receivedMsg, MsgCodes MsgCode, MsgData MessageData, bool Result)
        {
            bool bOK     = true;
            var  message = mdsClient.CreateMessage();

            // Set message data
            MessageData.MsgCode    = MsgCode;
            MessageData.validation = Result;

            // Set message params
            message.MessageData = GeneralHelper.SerializeObject(MessageData);
            message.DestinationApplicationName = receivedMsg.SourceApplicationName;
            message.TransmitRule = MessageTransmitRules.NonPersistent;


            try
            {
                //Send message
                message.Send();
                Logger.InfoFormat("Inviato msg a {0}", message.DestinationApplicationName);
            }
            catch (Exception exc)
            {
                // non sono riuscito a inviare il messaggio
                Logger.WarnFormat("Messaggio non inviato - {0}", exc.Message);
                bOK = false;
            }

            return(bOK);
        }
 public string this[MsgCodes code]
 {
     get
     {
         var ci = CultureInfo.CurrentUICulture;
         try
         {
             return(GetMessage(code, ci));
         }
         catch (FileNotFoundException)
         {
             throw new Exception($"Data file for {ci.Name} is not found.");
         }
     }
 }
        public static int GetMsgCode(Type type)
        {
            if (!MsgCodes.TryGetValue(type, out int result))
            {
                if (type.BaseType == typeof(Enum))
                {
                    return(MsgCodes[typeof(int)]);
                }
                else
                {
                    throw new Exception($"MessageType:{type} 不存在.");
                }
            }

            return(result);
        }
 protected override string GetMessage(MsgCodes code, CultureInfo ci)
 {
     if (!_dataByCi.ContainsKey(ci))
     {
         var json     = File.ReadAllText(GetDataFileName(ci));
         var dataDict = JsonSerializer.Deserialize <Dictionary <string, string> >(json);
         var data     = new string[MessagesCount];
         for (var i = 0; i < MessagesCount; i++)
         {
             data[i] = dataDict[i.ToString()];
         }
         _dataByCi[ci] = data;
         return(data[(int)code]);
     }
     return(_dataByCi[ci][(int)code]);
 }
Exemple #5
0
        /// <summary>
        /// Opens the airport and variation selection form.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">     </param>
        private void OpenAirport_Click(object sender, System.EventArgs e)
        {
            AirportSelection airportSelector = new AirportSelection();
            MsgCodes msg = new MsgCodes();

            // open the dialog and check the result.
            if (airportSelector.ShowDialog(this) == DialogResult.OK)
            {
                bool addNewVariation = airportSelector.AddNewVariation;
                ReturnCodes.FsVersion code = airportSelector.Code;
                string icaoCode = airportSelector.IcaoCode;
                string variatioName = airportSelector.VariatioName;

                // Ok load the bgl file and covert it.
                if (openBglXmlFileDialog.ShowDialog() == DialogResult.OK)
                {
                    CurrentStatusLabel.Text = "Cleaning up old stuff ...";

                    if (!Directory.Exists(Directory.GetCurrentDirectory() + "\\temp"))
                    {
                        Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\temp");
                    }

                    DataReader.ReadBglData bglReader = new DataReader.ReadBglData();

                    CurrentStatusLabel.Text = "Resetting temp database ...";

                    if (bglReader.ConvertAndResetDb(this.fields.Config.ReadConfig("bgltool"), openBglXmlFileDialog.FileName, Directory.GetCurrentDirectory() + "\\temp\\temp.xml") == ReturnCodes.Codes.ResetOk)
                    {
                        CurrentStatusLabel.Text = "Loading new stuff ...";
                        MessageBox.Show(msg.CreateMessage(bglReader.StoreParkingPos()));
                        MessageBox.Show(msg.CreateMessage(bglReader.StoreTaxiway()));
                        MessageBox.Show(msg.CreateMessage(bglReader.StorePoints()));
                    }
                    else
                    {
                        MessageBox.Show("Error");
                    }

                    this.CreateMap();
                }
            }
        }
Exemple #6
0
 protected override string GetMessage(MsgCodes code, CultureInfo ci)
 {
     using (var reader = new StreamReader(GetDataFileName(ci)))
     {
         using (var jsonReader = new JsonTextReader(reader))
         {
             while (jsonReader.Read())
             {
                 if (jsonReader.TokenType == JsonToken.PropertyName &&
                     jsonReader.Value is string s &&
                     int.TryParse(s, out int val) &&
                     val == (int)code)
                 {
                     jsonReader.Read();
                     return(jsonReader.Value as string);
                 }
             }
         }
     }
     throw new Exception($"data_{ci.Name}.json is not valid: missed message with code {(int)code}");
 }
 protected abstract string GetMessage(MsgCodes code, CultureInfo ci);