Esempio n. 1
0
        //TODO: Actually make a queue facility that allows more than one message to
        // be added asynchronously. Pop messages off the stack when one message has
        // finished displaying.
		public void Queue_Message(OverlayMessage message, int time)
		{
			InfoLine1Header.Content = message.Line1Header;
			InfoLine1Body.Content = message.Line1Content;
			InfoLine2Header.Content = message.Line2Header;
			InfoLine2Body.Content = message.Line2Content;
			InfoLine3Header.Content = message.Line3Header;
			InfoLine3Body.Content = message.Line3Content;
			InfoLine4Header.Content = message.Line4Header;
			InfoLine4Body.Content = message.Line4Content;
            // Fairly certain this is 3 lines in XAML, but I can't get the f****r to work, damnit.
            Storyboard sb = new Storyboard();
            sb.Duration = TimeSpan.FromSeconds(time);
            DoubleAnimation fadein = new DoubleAnimation
            {
                To = 1,
                BeginTime = TimeSpan.FromSeconds(0),
                Duration = TimeSpan.FromSeconds(2),
                FillBehavior = FillBehavior.HoldEnd,
            };
            DoubleAnimation fadeout = new DoubleAnimation
            {
                To = 0,
                BeginTime = TimeSpan.FromSeconds(time-2),
                Duration = TimeSpan.FromSeconds(2),
                FillBehavior = FillBehavior.HoldEnd,
            };
            sb.Children.Add(fadein);
            sb.Children.Add(fadeout);
            Storyboard.SetTarget(fadein, MessageGrid);
            Storyboard.SetTarget(fadeout, MessageGrid);
            Storyboard.SetTargetProperty(fadein, new PropertyPath(UIElement.OpacityProperty));
            Storyboard.SetTargetProperty(fadeout, new PropertyPath(UIElement.OpacityProperty));
            sb.Begin();
		}
Esempio n. 2
0
		public void Queue_Message(OverlayMessage message, int time)
		{
			InfoLine1Header.Content = message.line1header;
			InfoLine1Body.Content = message.line1content;
			InfoLine2Header.Content = message.line2header;
			InfoLine2Body.Content = message.line2content;
			InfoLine3Header.Content = message.line3header;
			InfoLine3Body.Content = message.line3content;
			InfoLine4Header.Content = message.line4header;
			InfoLine4Body.Content = message.line4content;
		}
Esempio n. 3
0
		private async void button_Click_1(object sender, RoutedEventArgs e)
		{
			//TriggerSystemChange("Lave");
			//TriggerSystemChange("Blaa Hypai AI-I b26-1");
			//DateTime testdate = DateTime.Now;
/*            myTravelLog.Add(new TravelLog{ system=new EDSMSystem(){ name = "Sol" }, lastvisited=testdate});
			myTravelLog.Add(new TravelLog { system = new EDSMSystem() { name = "Fuelum" }, lastvisited = testdate});
			myTravelLog.Add(new TravelLog { system = new EDSMSystem() { name= "Leesti" }, lastvisited = testdate}); */
			//AppendStatus("Travellog now contains " + myTravelLog.Count() + " systems. Timestamp of first is " + myTravelLog.First().lastvisited +" name "+myTravelLog.First().system.name);
			//CalculateEDSMDistance("Sol", SystemName.Text);
			OverlayMessage mymessage = new OverlayMessage();
			mymessage.line1header = "Nearest station:";
			mymessage.line1content = "Wollheim Vision, Fuelum (0LY)";
			mymessage.line2header = "Pad size:";
			mymessage.line2content = "Large";
			mymessage.line3header = "Capabilities:";
			mymessage.line3content = "Refuel, Rearm, Repair";
			//overlay.Queue_Message(mymessage, 30);
			EDDBData edworker = new EDDBData();
			string status = await edworker.UpdateEDDBData();
			AppendStatus("EDDB: " + status);

			EDDBSystem eddbSystem = edworker.systems.First(s => s.name == "Fuelum");
			var station = edworker.GetClosestStation(new EdsmCoords {X = eddbSystem.x, Y = eddbSystem.y, Z = eddbSystem.z});
			AppendStatus("Closest system to 'Fuelum' is '" + eddbSystem.name +
						"', closest station to star with known coordinates (should be 'Wollheim Vision') is '" + station.name + "'.");
		}
Esempio n. 4
0
		/* Moved WS connection to the apworker, but to actually parse the messages we have to hook the event
         * handler here too.
         */
		private async void websocketClient_MessageReceieved(object sender, MessageReceivedEventArgs e)
		{
			Dispatcher disp = Dispatcher;
			try
			{
				//logger.Debug("Raw JSON from WS: " + e.Message);
				dynamic data = JsonConvert.DeserializeObject(e.Message);
				dynamic meta = data.meta;
				dynamic realdata = data.data;
				Logger.Debug("Meta data from API: " + meta);
				switch ((string)meta.action)
				{
					case "welcome":
						Logger.Info("API MOTD: " + data.data);
						break;
					case "assignment":
						Logger.Debug("Got a new assignment datafield: " + data.data);
						break;
					case "rescues:read":
						if (realdata == null)
						{
							Logger.Error("Null list of rescues received from rescues:read!");
							break;
						}
						Logger.Debug("Got a list of rescues: " + realdata);
						_rescues = JsonConvert.DeserializeObject<RootObject>(e.Message);
						await disp.BeginInvoke(DispatcherPriority.Normal, (Action)(() => ItemsSource.Clear()));
						await disp.BeginInvoke(DispatcherPriority.Normal, (Action)(() => _rescues.Data.ForEach(datum => ItemsSource.Add(datum))));
						//await disp.BeginInvoke(DispatcherPriority.Normal,
						//	(Action)(() => RescueGrid.ItemsSource = rescues.Data));
						await GetMissingRats(_rescues);
						break;
					case "message:send":
						/* We got a message broadcast on our channel. */
						AppendStatus("Test 3PA data from WS receieved: " + realdata);
						break;
					case "users:read":
						Logger.Info("Parsing login information..." + meta.count + " elements");
                        if (!realdata)
                        {
                            Logger.Debug("Null realdata during login! Data element: "+data.ToString());
                            AppendStatus("RatTracker failed to get your user data from the API. This makes RatTracker unable to verify your identity for jump calls and messages.");
                            break;
                        }
						//Logger.Debug("Raw: " + realdata[0]);

						AppendStatus("Got user data for " + realdata[0].email);
						MyPlayer.RatId = new List<string>();
						foreach (dynamic cmdrdata in realdata[0].CMDRs)
						{
							AppendStatus("RatID " + cmdrdata + " added to identity list.");
							MyPlayer.RatId.Add(cmdrdata.ToString());
						}
						_myplayer.RatName = await GetRatName(MyPlayer.RatId.FirstOrDefault()); // This will have to be redone when we go WS, as we can't load the variable then.
						break;
					case "rats:read":
						Logger.Info("Received rat identification: " + meta.count + " elements");
						Logger.Debug("Raw: " + realdata[0]);
						break;

					case "rescue:updated":
						Datum updrescue = realdata.ToObject<Datum>();
						if (updrescue == null)
						{
							Logger.Debug("null rescue update object, breaking...");
							break;
						}
						Logger.Debug("Updrescue _ID is " + updrescue.id);
						Datum myRescue = _rescues.Data.FirstOrDefault(r => r.id == updrescue.id);
						if (myRescue == null)
						{
							Logger.Debug("Myrescue is null in updaterescue, reinitialize grid.");
							APIQuery rescuequery = new APIQuery
							{
								action = "rescues:read",
								data = new Dictionary<string, string> {{"open", "true"}}
							};
							_apworker.SendQuery(rescuequery);
							break;
						}
						if (updrescue.Open == false)
						{
							AppendStatus("Rescue closed: " + updrescue.Client);
							Logger.Debug("Rescue closed: " + updrescue.Client);
							await disp.BeginInvoke(DispatcherPriority.Normal, (Action)(() => ItemsSource.Remove(myRescue)));
						}
						else
						{
							_rescues.Data[_rescues.Data.IndexOf(myRescue)] = updrescue;
							await disp.BeginInvoke(DispatcherPriority.Normal, (Action)(() => ItemsSource[ItemsSource.IndexOf(myRescue)] = updrescue));
							Logger.Debug("Rescue updated: " + updrescue.Client);
						}
						break;
					case "rescue:created":
						Datum newrescue = realdata.ToObject<Datum>();
						AppendStatus("New rescue: " + newrescue.Client);
						OverlayMessage nr = new OverlayMessage
						{
							Line1Header = "New rescue:",
							Line1Content = newrescue.Client,
							Line2Header = "System:",
							Line2Content = newrescue.System,
							Line3Header = "Platform:",
							Line3Content = newrescue.Platform,
							Line4Header = "Press Ctrl-Alt-C to copy system name to clipboard"
						};
						if (_overlay != null)
						{
							await disp.BeginInvoke(DispatcherPriority.Normal, (Action)(() => _overlay.Queue_Message(nr, 30)));
						}

						await disp.BeginInvoke(DispatcherPriority.Normal, (Action)(() => ItemsSource.Add(newrescue))); 
						break;
					case "stream:subscribe":
						Logger.Debug("Subscribed to 3PA stream " + data.ToString());
						break;
					case "stream:broadcast":
						Logger.Debug("3PA broadcast message received:" + data.ToString());
						break;
                    case "authorization":
                        Logger.Debug("Authorization callback: " + realdata.ToString());
                        if (realdata.errors)
                        {
                            AppendStatus("Error during WS Authentication: " + realdata.errors.code + ": " + realdata.errors.detail);
                            Logger.Error("Error during WS Authentication: " + realdata.errors.code + ": " + realdata.errors.detail);
                            MessageBoxResult reauth = MessageBox.Show("RatTracker has failed to authenticate with WebSocket. This is usually caused by an invalid OAuth token. If you would like to retry the OAuth process, press OK. To leave the OAuth token intact, press cancel.");
                            if (reauth==MessageBoxResult.Yes)
                            {
                                Logger.Info("Clearing OAuth keys...");
                                Settings.Default.OAuthToken = "";
                                Settings.Default.Save();
                                string _rtPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                                if (File.Exists(_rtPath + @"\RatTracker\OAuthToken.tmp"))
                                    File.Delete(_rtPath+@"\RatTracker\OAuthToken.tmp");
                                AppendStatus("OAuth information cleared. Please restart RatTracker to reauthenticate it.");
                            }
                        }
                        else if (realdata.email)
                        {
                            AppendStatus("Got user data for " + realdata.email);
                            MyPlayer.RatId = new List<string>();
                            foreach (dynamic cmdrdata in realdata.rats)
                            {
                                AppendStatus("RatID " + cmdrdata.id + " added to identity list.");
                                MyPlayer.RatId.Add(cmdrdata.id.ToString());
                            }
                            _myplayer.RatName = await GetRatName(MyPlayer.RatId.FirstOrDefault());
                        }
                        break;

                        break;
					default:
						Logger.Info("Unknown API action field: " + meta.action);
						//tc.TrackMetric("UnknownAPIField", 1, new IDictionary<string,string>["type", meta.action]);
						break;
				}
				if (meta.id != null)
				{
					AppendStatus("My connID: " + meta.id);
				}
			}
			catch (Exception ex)
			{
				Logger.Fatal("Exception in WSClient_MessageReceived: " + ex.Message);
				_tc.TrackException(ex);
			}
		}
Esempio n. 5
0
		private async void Button2_Click(object sender, RoutedEventArgs e)
		{
			Logger.Debug("Querying EDDB for closest station to " + _myplayer.CurrentSystem);
			IEnumerable<EdsmSystem> mysys = await QueryEdsmSystem(_myplayer.CurrentSystem);
			var edsmSystems = mysys as EdsmSystem[] ?? mysys.ToArray();
			if (edsmSystems.Any())
			{
				Logger.Debug("Got a mysys with " + edsmSystems.Count() + " elements");
				var station = Eddbworker.GetClosestStation(edsmSystems.First().Coords);
				EddbSystem system = Eddbworker.GetSystemById(station.system_id);
				AppendStatus("Closest populated system to '"+_myplayer.CurrentSystem+"' is '" + system.name+
							"', closest station to star with known coordinates is '" + station.name + "'.");
				double distance = await CalculateEdsmDistance(_myplayer.CurrentSystem, edsmSystems.First().Name);
				OverlayMessage mymessage = new OverlayMessage
				{
					Line1Header = "Nearest station:",
					Line1Content = station.name + ", " + system.name + " (" + Math.Round(distance, 2) + "LY)",
					Line2Header = "Pad size:",
					Line2Content = station.max_landing_pad_size,
					Line3Header = "Capabilities:",
					Line3Content = new StringBuilder()
						.AppendIf(station.has_refuel, "Refuel,")
						.AppendIf(station.has_repair, "Repair,")
						.AppendIf(station.has_outfitting, "Outfit").ToString()
				};

				_overlay?.Queue_Message(mymessage, 30);
				return;
			}

			AppendStatus("Unable to find a candidate system for location " + MyClient.ClientSystem);
		}