Example #1
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="settings"></param>
        public void Connect(XPlaneSettings settings)
        {
            if (_SharedConfig == null)
            {
                _SharedConfig = Factory.ResolveSingleton <ISharedConfiguration>();
            }

            if (_XplaneUdp != null)
            {
                Disconnect();
            }

            var xplaneUdp = Factory.Resolve <IXPlaneUdp>();

            xplaneUdp.Initialise(
                settings.Host,
                settings.XPlanePort,
                settings.ReplyPort
                );

            xplaneUdp.SendRPOS(1);
            xplaneUdp.StartListener();

            _XplaneUdp = xplaneUdp;
            _XplaneUdp.RposReplyReceived += XPlaneUdp_RposReplyReceived;
        }
Example #2
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="view"></param>
        public void Connect(IXPlaneView view)
        {
            view.ConnectionStatus = "";

            var settings = new XPlaneSettings()
            {
                Host       = view.Host,
                XPlanePort = view.XPlanePort,
                ReplyPort  = view.ReplyPort,
            };

            var validationMessage = ValidateSettings(settings);

            view.ConnectionStatus = validationMessage ?? "";

            if (String.IsNullOrEmpty(validationMessage))
            {
                var connection = Factory.ResolveSingleton <IXPlaneConnection>();
                try {
                    connection.Connect(settings);
                    view.ConnectionStatus = Strings.Connected;

                    var storage = Factory.Resolve <IXPlaneSettingsStorage>();
                    storage.Save(settings);
                } catch (Exception ex) {
                    view.ConnectionStatus = $"Caught exception when connecting: {ex}";
                }
            }
        }
Example #3
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="settings"></param>
        public void Save(XPlaneSettings settings)
        {
            var fileName = FullPath;

            File.WriteAllText(
                fileName,
                JsonConvert.SerializeObject(settings, Formatting.Indented)
                );
        }
Example #4
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <returns></returns>
        public XPlaneSettings Load()
        {
            XPlaneSettings result = null;

            var fileName = FullPath;

            if (File.Exists(fileName))
            {
                result = JsonConvert.DeserializeObject <XPlaneSettings>(
                    File.ReadAllText(fileName)
                    );
            }

            return(result ?? new XPlaneSettings());
        }
Example #5
0
        private string ValidateSettings(XPlaneSettings settings)
        {
            string message = null;

            if (String.IsNullOrEmpty(settings.Host))
            {
                message = "Host must be supplied";
            }
            else if (!IPAddress.TryParse(settings.Host, out var address))
            {
                message = "Host is not a valid host";
            }
            else if (settings.XPlanePort < 1 || settings.XPlanePort > 65534)
            {
                message = "XPlanePort is out of range";
            }
            else if (settings.ReplyPort < 1 || settings.ReplyPort > 65534)
            {
                message = "ReplyPort is out of range";
            }

            return(message);
        }