Exemple #1
0
 public void websocketClient_Opened(object sender, EventArgs e)
 {
     _failing = false;
     Logger.Info("Websocket: Connection to API established.");
     if (Properties.Settings.Default.OAuthToken == null)
     {
         Logger.Error("Oops! I am attempting to connect without an OAuth token. That's probably bad.");
     }
     else
     {
         AuthQuery auth = new AuthQuery()
         {
             action = "authorization",
             bearer = Properties.Settings.Default.OAuthToken
         };
         SendAuth(auth);
         SubscribeStream("0xDEADBEEF");
         APIQuery login = new APIQuery
         {
             action = "rescues:read",
             data   = new Dictionary <string, string> {
                 { "open", "true" }
             }
         };
         SendQuery(login);
         Logger.Info("Sent RescueGrid Update request.");
     }
     //TODO: Put stream subscription messages here when Mecha goes live. Do we want to listen to ourselves?
 }
Exemple #2
0
        public void SendWs(string action, IDictionary <string, string> data)
        {
            if (Ws == null)
            {
                Logger.Debug("Attempt to send data over uninitialized WS connection!");
                return;
            }

            switch (action)
            {
            case "rescues:read":
                Logger.Debug("SendWS is requesting a rescues update.");
                break;
            }

            APIQuery myquery = new APIQuery
            {
                action = action,
                data   = data
            };
            string json = JsonConvert.SerializeObject(myquery);

            Logger.Debug("sendWS Serialized to: " + json);
            Ws.Send(json);
        }
Exemple #3
0
        public void SendQuery(APIQuery myquery)
        {
            string json = JsonConvert.SerializeObject(myquery);

            Logger.Debug("Sent an APIQuery serialized as: " + json);
            Ws.Send(json);
        }
        public ActionResult Index()
        {
            //Récupération de la liste des devises dispo en base
            List <CurrencyModel> currenciesList = QueryDBHelper.getConverterModelFromDB();

            ViewData["CurrenciesList"] = currenciesList;

            //On vérifie si la table est vide, si oui on la remplit pour l'utilisation du mode offline

            if (QueryDBHelper.isExchangeEmpty())
            {
                //Pour l'utilisation du mode offline on ajoute en base les taux de changes des 7 monnaies les plus utilisées
                APIQuery.storeAllCurrenciesPobisiblitiesInDB();
            }
            return(View());
        }
Exemple #5
0
        public async Task <IActionResult> GetAll([FromBody] APIQuery query)
        {
            var source = DbContext.EstoqueHistorico.AsQueryable();
            var pager  = new Pager
            {
                page     = query.page,
                perPage  = query.perPage,
                usePager = query.usePager
            };

            var selector = new Selector <EstoqueHistorico, StockHistory>(EntMapper.ConfigurationProvider, source, query.fields);
            var items    = await selector
                           .Filter(query.filters)
                           .Ordering(query.sort, eh => eh.Id)
                           .Paginate(pager)
                           .ToPagedRecordsAsync(pager);

            return(Ok(items));
        }
Exemple #6
0
 public override Task <IActionResult> GetAll([FromBody] APIQuery query) => _GetAll(query);
		/* 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);
			}
		}
		private async void InitRescueGrid()
		{
			try {
				Logger.Info("Initializing Rescues grid");
				Dictionary<string, string> data = new Dictionary<string, string> {{"open", "true"}};
				_rescues = new RootObject();
				if (_apworker.Ws.State != WebSocketState.Open)
				{
					Logger.Info("No available WebSocket connection, falling back to HTML API.");
					string col = await _apworker.QueryApi("rescues", data);
					Logger.Debug(col == null ? "No COL returned from Rescues." : "Rescue data received from HTML API.");
				}
				else
				{
					Logger.Info("Fetching rescues from WS API.");
                    RescueGrid.AutoGenerateColumns = false;
                    APIQuery rescuequery = new APIQuery
					{
						action = "rescues:read",
						data = new Dictionary<string, string> {{"open", "true"}}
					};
					_apworker.SendQuery(rescuequery);
				}

				//await disp.BeginInvoke(DispatcherPriority.Normal, (Action)(() => ItemsSource.Clear()));
				//await disp.BeginInvoke(DispatcherPriority.Normal, (Action)(() => rescues.Data.ForEach(datum => ItemsSource.Add(datum))));
				//await GetMissingRats(rescues);
			}
			catch(Exception ex)
			{
				Logger.Fatal("Exception in InitRescueGrid: " + ex.Message);
				_tc.TrackException(ex);
			}
		}
Exemple #9
0
		public void SendQuery(APIQuery myquery)
		{
			string json = JsonConvert.SerializeObject(myquery);
			Logger.Debug("Sent an APIQuery serialized as: " + json);
			Ws.Send(json);
		}
Exemple #10
0
		public void SendWs(string action, IDictionary<string, string> data)
		{
			if (Ws == null)
			{
				Logger.Debug("Attempt to send data over uninitialized WS connection!");
				return;
			}

			switch (action)
			{
				case "rescues:read":
					Logger.Debug("SendWS is requesting a rescues update.");
					break;
			}

			APIQuery myquery = new APIQuery
			{
				action = action,
				data = data
			};
			string json = JsonConvert.SerializeObject(myquery);
			Logger.Debug("sendWS Serialized to: " + json);
			Ws.Send(json);
		}
Exemple #11
0
		public void websocketClient_Opened(object sender, EventArgs e)
		{
			_failing = false;
			Logger.Info("Websocket: Connection to API established.");
			if (Properties.Settings.Default.OAuthToken == null)
				Logger.Error("Oops! I am attempting to connect without an OAuth token. That's probably bad.");
			else
			{
				AuthQuery auth = new AuthQuery()
				{
					action = "authorization",
					bearer = Properties.Settings.Default.OAuthToken
				};
				SendAuth(auth);
				SubscribeStream("0xDEADBEEF");
				APIQuery login = new APIQuery
				{
					action = "rescues:read",
					data = new Dictionary<string, string> {{"open", "true"}}
				};
				SendQuery(login);
				Logger.Info("Sent RescueGrid Update request.");
			}
			//TODO: Put stream subscription messages here when Mecha goes live. Do we want to listen to ourselves?
		}
Exemple #12
0
        public void PostAPITestcase()
        {
            try
            {
                _qvizClient.Authenticate(QVizUser, QVizPassword);
                var project = _qvizClient.GetProject(QVizProject);

                var testTags = new List <Tag>
                {
                    new Tag {
                        tagId = null, tagName = "TestTag1"
                    },
                    new Tag {
                        tagId = null, tagName = "TestTag2"
                    }
                };

                /// Test PAI
                List <TestAPI> listTestAPI = new List <TestAPI>();

                #region API header
                APIHeaderValue apiHeaderValue = new APIHeaderValue
                {
                    headerValueId = null,
                    key           = "ContentType",
                    value         = "application/json"
                };

                APIHeader header = new APIHeader
                {
                    headerValueId = null,
                    headerValue   = apiHeaderValue,
                    apiId         = null,
                    apiHeaderId   = null,
                    srNo          = 1,
                };

                List <APIHeader> headers = new List <APIHeader>
                {
                    header
                };


                #endregion

                #region API Query
                APIQueryValue apiQueryValue = new APIQueryValue
                {
                    queryValueId = null,
                    key          = "projectId",
                    value        = "12334",
                };

                APIQuery query = new APIQuery
                {
                    queryValueId = null,
                    queryValue   = apiQueryValue,
                    apiId        = null,
                    apiQueryId   = null,
                    srNo         = 1,
                };

                List <APIQuery> queries = new List <APIQuery>
                {
                    query
                };

                APIBodyValue apiBodyValue = new APIBodyValue
                {
                    bodyValueId = null,
                    jsonString  = "{ id=\"100\", name=\"Cars\"}",
                };

                APIBody body = new APIBody
                {
                    srNo        = 1,
                    apiBodyId   = null,
                    bodyValueId = null,
                    apiId       = null,
                    bodyValue   = apiBodyValue,
                };

                #endregion
                API api = new API
                {
                    apiId              = null,
                    uri                = "/Products",
                    method             = "GET",
                    expectedHTTPStatus = 200,
                    expectedJSONResult = "[{ id=\"100\", name=\"Cars\"}]",
                    apiHeaders         = headers,
                    apiQueries         = queries,
                    apiBody            = body,
                    moduleId           = null,
                    subModuleId        = null,
                    apiTags            = null,
                    testAPIs           = null,
                };


                var testAPI = new TestAPI
                {
                    srNo       = 1,
                    testAPIId  = null,
                    testCaseId = null,
                    apiId      = null,
                    api        = api,
                };

                List <TestAPI> apis = new List <TestAPI>
                {
                    testAPI
                };

                // Test case
                TestCaseAPI apiTC = new TestCaseAPI
                {
                    testCaseId     = null,
                    projectId      = project.projectId,
                    moduleId       = modules.FirstOrDefault().moduleId,
                    subModuleId    = subModules.FirstOrDefault().subModuleId,
                    description    = "Demo API Test case " + DateTime.Now.Ticks,
                    isAutomated    = false,
                    priority       = "P1",
                    severity       = "1",
                    expectedResult = "Demo API TC expected result",
                    testCaseTypeId = testcaseTypes.FirstOrDefault(f => f.name.ToLower() == "api").testCaseTypeId,
                    testToolID     = "DemoTool1",
                    testTags       = testTags,
                    testAPIs       = apis,
                    module         = null,
                    subModule      = null,
                };
                _qvizClient.PostAPITest(apiTC);

                string response = _qvizClient.LastResponse();
                QVizResponseObject <TestCaseAPI> qVizResponse = JsonConvert.DeserializeObject <QVizResponseObject <TestCaseAPI> >(response);

                Assert.AreEqual("Test case created successfully", qVizResponse.Message);
            }
            catch (Exception error)
            {
                Assert.Fail(error.Message);
            }
        }