Esempio n. 1
0
        private async Task <SimResult> getResult(string contactNumber)
        {
            SimResult msg       = new SimResult();
            var       queryList = new List <string>();

            queryList.Add("query {{  sims(msisdn:\"{0}\", first:20) {{edges {{node{{contactNumber:msisdn description active network {{name}}airtimeBalance dataBalanceInMb smsBalance  }}}}}}}}");

            var cl = new GraphQLHttpClient(_configOptions.Value.GraphUrl, new NewtonsoftJsonSerializer());

            cl.HttpClient.DefaultRequestHeaders.Add("simcontrol-api-key", _configOptions.Value.ApiKey);

            var content = new GraphQLRequest(string.Format(queryList[0], contactNumber));
            var res     = await cl.SendQueryAsync <Data>(content);

            if (res.Data.Sims.Edges.Any())
            {
                var data = res.Data.Sims.Edges.First().Node;
                _logger.LogInformation("\r\n\r\n\r\n");
                _logger.LogInformation("\t\tDescription : " + data.Description);
                _logger.LogInformation("\t\tNumber : " + data.ContactNumber);
                _logger.LogInformation("\t\tActive: " + data.Active);
                _logger.LogInformation("\t\tAirtime Balance : " + data.AirtimeBalance);
                _logger.LogInformation("\t\tData Balance: " + data.DataBalanceInMb);
                msg.Active         = data.Active;
                msg.AirtimeBalance = data.AirtimeBalance;
                msg.DataBalance    = data.DataBalanceInMb;
                msg.ContactNumber  = data.ContactNumber;
                msg.Description    = data.Description;
            }
            cl.Dispose();
            return(msg);
        }
Esempio n. 2
0
        /// <summary>
        /// Makes many (~15) HTTP requests - use sparingly.
        /// </summary>
        public async Task <List <TarkovToolsItem> > GetAllItemsAsync()
        {
            var tarkovToolsClient = new GraphQLHttpClient(_appSettings.TarkovToolsGQLUrl, new NewtonsoftJsonSerializer());

            var allItems = new List <TarkovToolsItem>();

            foreach (ItemType type in Enum.GetValues(typeof(ItemType)))
            {
                var items = await GetItemsByTypeAsync(type, tarkovToolsClient);

                allItems.AddRange(items);
            }

            tarkovToolsClient.Dispose();
            return(allItems);
        }
Esempio n. 3
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            try
            {
                var lowData = "";
                while (!stoppingToken.IsCancellationRequested)
                {
                    var cl = new GraphQLHttpClient(_configOptions.Value.GraphUrl, new NewtonsoftJsonSerializer());
                    cl.HttpClient.DefaultRequestHeaders.Add("simcontrol-api-key", _configOptions.Value.ApiKey);

                    foreach (string contactNumber in _configOptions.Value.ContactNumbers)
                    {
                        var content = new GraphQLRequest(string.Format(queryList[0], contactNumber));
                        var res     = await cl.SendQueryAsync <Data>(content);

                        if (res.Data.Sims.Edges.Any())
                        {
                            var data = res.Data.Sims.Edges.First().Node;
                            _logger.LogInformation("\r\n\r\n\r\n");
                            _logger.LogInformation("\t\tDescription : " + data.Description);
                            _logger.LogInformation("\t\tNumber : " + data.ContactNumber);
                            _logger.LogInformation("\t\tActive: " + data.Active);
                            _logger.LogInformation("\t\tAirtime Balance : " + data.AirtimeBalance);
                            _logger.LogInformation("\t\tData Balance: " + data.DataBalanceInMb);
                            if (data.DataBalanceInMb == null || long.Parse(_configOptions.Value.MinimumLimit) > data.DataBalanceInMb)
                            {
                                lowData += string.Format("{0} - {1} - {2}Mb\r\n", data.ContactNumber, data.Description, data.DataBalanceInMb);
                            }
                        }
                    }
                    cl.Dispose();
                    if (lowData.Length > 1)
                    {
                        var mm = new Message(_emailOptions.Value.AdministratorEmails, "Sim Control - Low Data Report", "The following users has low data : \r\n" + lowData);
                        _emailClient.SendEmail(mm);
                        _logger.LogInformation("\t\tSending SMS...");
                        _smsClient.Send("You have a few low data items");
                    }
                    _logger.LogInformation("Next check will be at " + DateTime.Now.AddMilliseconds(_configOptions.Value.Delay));
                    await Task.Delay(_configOptions.Value.Delay, stoppingToken);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
            }
        }
Esempio n. 4
0
        public async Task <Rootobject> GetAsync(GraphQLRequest nrequest)
        {
            string local = "http://localhost:4001/graphql";

            GraphQLHttpClient graphQLClient = new GraphQLHttpClient(local, new NewtonsoftJsonSerializer());

            JsonSerializerOptions jso = new JsonSerializerOptions
            {
                Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
            };

            var graphQLResponse = await graphQLClient.SendQueryAsync <Data>(nrequest);

            graphQLClient.Dispose();
            //return System.Text.Json.JsonSerializer.Serialize(graphQLResponse, jso);
            return(JsonConvert.DeserializeObject <Rootobject>(System.Text.Json.JsonSerializer.Serialize(graphQLResponse, jso)));
        }
Esempio n. 5
0
        public async void CanCreateObservableSubscription()
        {
            var callbackMonitor = ChatClient.ConfigureMonitorForOnWebsocketConnected();
            await ChatClient.InitializeWebsocketConnection();

            callbackMonitor.Should().HaveBeenInvokedWithPayload();

            Debug.WriteLine("creating subscription stream");
            var observable = ChatClient.CreateSubscriptionStream <MessageAddedSubscriptionResult>(_subscriptionRequest);

            Debug.WriteLine("subscribing...");
            using var observer = observable.Observe();
            await observer.Should().PushAsync(1);

            observer.RecordedMessages.Last().Errors.Should().BeNullOrEmpty();
            observer.RecordedMessages.Last().Data.MessageAdded.Content.Should().Be(InitialMessage.Content);

            const string message1 = "Hello World";
            var          response = await ChatClient.AddMessageAsync(message1);

            response.Errors.Should().BeNullOrEmpty();
            response.Data.AddMessage.Content.Should().Be(message1);
            await observer.Should().PushAsync(2);

            observer.RecordedMessages.Last().Data.MessageAdded.Content.Should().Be(message1);

            const string message2 = "lorem ipsum dolor si amet";

            response = await ChatClient.AddMessageAsync(message2);

            response.Data.AddMessage.Content.Should().Be(message2);
            await observer.Should().PushAsync(3);

            observer.RecordedMessages.Last().Data.MessageAdded.Content.Should().Be(message2);

            // disposing the client should throw a TaskCanceledException on the subscription
            ChatClient.Dispose();
            await observer.Should().CompleteAsync();
        }
Esempio n. 6
0
 public Task DisposeAsync()
 {
     ChatClient?.Dispose();
     StarWarsClient?.Dispose();
     return(Task.CompletedTask);
 }
Esempio n. 7
0
 public void Dispose()
 {
     _client.Dispose();
 }