Beispiel #1
0
        public override bool Setup()
        {
            using (var setupForm = new SetupForm(_Data)) {
                if (setupForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
                    _Data= setupForm.RdsData;

                    return true;
                }
                return false;
            }
        }
Beispiel #2
0
		public SetupForm(Data data)
		{
			InitializeComponent();
			ForeColor = ThemeColorTable.ForeColor;
			BackColor = ThemeColorTable.BackgroundColor;
			ThemeUpdateControls.UpdateControls(this);
			cboPortName.Items.Clear();

			var ports =	SerialPort.GetPortNames().OrderBy(o => o).ToList();
			ports.ForEach(a => cboPortName.Items.Add((a)));

			RdsData = data;
			chkRequiresAuthentication.Checked= data.RequireHTTPAuthentication;

			txtHttpUsername.Text= data.HttpUsername;
			txtHttpPassword.Text= data.HttpPassword;

			chkBiDirectional.Checked= data.BiDirectional;
			chkSlow.Checked= data.Slow;
			this.txtUrl.Text = data.HttpUrl ?? "http://127.0.0.1:8080/?action=update_rt&update_rt={text}";
			if (ports.Contains(data.PortName))
			{
				cboPortName.SelectedItem = data.PortName;
			}
			 

			switch (data.HardwareID) {
				case Hardware.MRDS1322:
					radioMRDS1322.Checked=true;
					break;
				case Hardware.MRDS192:
					radioMRDS192.Checked=true;
					break;
				case Hardware.VFMT212R:
					radioVFMT212R.Checked=true;
					break;
				case Hardware.HTTP:
					radioHttp.Checked=true;
					break;
			}

			chkHideLaunchedWindows.Checked= data.HideLaunchedWindows;

		}
Beispiel #3
0
        internal static bool Send(Data RdsData, string rdsText, string rdsArtist = null, bool sendps=false)
        {
            //We dont want to keep hammering the RDS device with updates if they havent changed.
            if (lastRdsText.Equals(rdsText))
                return true;
            else
                lastRdsText=rdsText;

            Console.WriteLine("Sending {0}: {1}", rdsText, DateTime.Now);
            switch (RdsData.HardwareID) {
                case Hardware.MRDS192:
                case Hardware.MRDS1322:
                    var portName = string.Format("COM{0}", RdsData.PortNumber);
                    using (var rdsPort = new RdsSerialPort(portName, RdsData.Slow ? 2400 : 19200))
                    {
                        rdsPort.Send(rdsText);
                    }

                    //NativeMethods.ConnectionSetup(RdsData.ConnectionMode, RdsData.PortNumber, RdsData.BiDirectional, RdsData.Slow );
                    //if (NativeMethods.Connect()) {
                    //	try {
                    //		int i, Len;
                    //		byte[] Data;

                    //		if (sendps) {
                    //			Data = new byte[9];
                    //			Data[0] = 0x02;             // buffer address
                    //			Len = 8;
                    //		} else {
                    //			//need to set byte at 0x1F to 1 to enable RT
                    //			NativeMethods.Send(1, new byte[1] { 0x1F });

                    //			Data = new byte[65];
                    //			Data[0] = 0x20;             // buffer address for RadioText
                    //			Len = 64;                   // character length
                    //		}

                    //		for (i = 1; i <= Len; i++)
                    //			Data[i] = 0x20; // fill 64 blank spaces first

                    //		for (i = 0; i < rdsText.Length; i++) {
                    //			byte vOut = Convert.ToByte(rdsText[i]);
                    //			Data[i + 1] = vOut;
                    //		}
                    //		if (NativeMethods.Send(Len, Data))
                    //			return true;
                    //		else
                    //			return false;
                    //	} finally {
                    //		NativeMethods.Disconnect();
                    //	}
                    //}
                    return false;
                case Hardware.VFMT212R:
                case Hardware.HTTP:
                    System.Threading.Tasks.Task.Factory.StartNew(() => {
                        try {
                            string url = RdsData.HttpUrl.ToLower().Replace("{text}",HttpUtility.UrlEncode(rdsText)).Replace("{time}", HttpUtility.UrlEncode(DateTime.Now.ToLocalTime().ToShortTimeString()));
                            if (sendps) {
                                //TODO: Enable the sendps code here.
                            }
                            WebRequest request = WebRequest.Create(url);
                            if (RdsData.RequireHTTPAuthentication) {
                                request.Credentials= new NetworkCredential(RdsData.HttpUsername, RdsData.HttpPassword);
                            }
                            var response = request.GetResponse();
                        } catch (Exception e) {
                            Logging.ErrorException(e.Message, e);
                            lastRdsText=string.Empty;
                        }
                    });
                    return true;
                default:
                    return false;
            }
        }
Beispiel #4
0
        internal static bool Launch(Data RdsData, string Executable, string Arguments)
        {
            if (File.Exists(Executable)) {
                Logging.Info(string.Format("Launching Executable: {0} with arguments [{1}]", Executable, Arguments));
                Task.Factory.StartNew(() => {
                    try {
                        Stopwatch w = Stopwatch.StartNew();
                        Process proc = new Process();

                        proc.StartInfo.FileName   = Executable;
                        if (!string.IsNullOrWhiteSpace(Arguments))
                            proc.StartInfo.Arguments = Arguments;

                        proc.StartInfo.CreateNoWindow= RdsData.HideLaunchedWindows;

                        proc.Start();
                        proc.WaitForExit();
                        w.Stop();
                        Logging.Info(string.Format("Process {0} Completed After {1} with Exit code {2}", Executable, w.Elapsed, proc.ExitCode));

                    } catch (Exception e) {

                        Logging.ErrorException(e.Message, e);
                    }

                });
            } else
                Logging.Error(string.Format("File Not found to Launch: [{0}]", Executable));
            return false;
        }