Esempio n. 1
0
        /// <summary>
        /// Gets the access token based on a previously retrieved authorization code
        /// </summary>
        /// <param name="code">The authorization code</param>
        /// <param name="redirectUri">The redirect URI which was used during the login</param>
        /// <returns>Returns the access token if it could be retrieved; otherwise it returns an empty string</returns>
        public async Task <string> GetAccessTokenFromCodeAsync(string code, string redirectUri)
        {
            if (ClientData == null)
            {
                i5Debug.LogError("No client data supplied for the OpenID Connect Client.\n" +
                                 "Initialize this provider with an OpenID Connect Data file.", this);
                return("");
            }

            string uri = tokenEndpoint + $"?code={code}&client_id={ClientData.ClientId}" +
                         $"&client_secret={ClientData.ClientSecret}&redirect_uri={redirectUri}&grant_type=authorization_code";
            WebResponse <string> response = await RestConnector.PostAsync(uri, "");

            if (response.Successful)
            {
                LearningLayersAuthorizationFlowAnswer answer =
                    JsonSerializer.FromJson <LearningLayersAuthorizationFlowAnswer>(response.Content);
                if (answer == null)
                {
                    i5Debug.LogError("Could not parse access token in code flow answer", this);
                    return("");
                }
                return(answer.access_token);
            }
            else
            {
                Debug.LogError(response.ErrorMessage + ": " + response.Content);
                return("");
            }
        }
Esempio n. 2
0
        public async Task GetAsyncBlankUrlTests(string url)
        {
            var restConnector = new RestConnector();
            var result        = await restConnector.GetAsync(url);

            result.Should().BeNull($"because \"{url}\" is not a URL");
        }
Esempio n. 3
0
        protected internal string GetNextSampleXml(int from, int maxItems, out int next)
        {
            lock (SyncRoot)
            {
                next = 0;

                if (from == -1)
                {
                    var result = GetCurrentXml();
                    if (result.Length == 0)
                    {
                        return(result);
                    }
                    next = GetNextSequenceID(result);
                    return(result);
                }

                var path = GetSamplePath(from, maxItems);
                var xml  = RestConnector.GetString(path, RequestTimeout);
                if (xml != string.Empty)
                {
                    next = GetNextSequenceID(xml);
                }

                return(xml);
            }
        }
Esempio n. 4
0
        public static void Perform(IDatabaseConnectionSettings connectionSettings)
        {
            var rest  = new RestConnector(connectionSettings);
            var flwor = new Flwor(new XdmpNodeDelete(FnDoc.AllDocuments.Query));

            rest.Submit(flwor.Query);
        }
Esempio n. 5
0
        private async Task LoadWeatherData()
        {
            var response = await RestConnector.GetObjectAsync(
                "https://api.ipma.pt/open-data/forecast/meteorology/cities/daily/" + district.globalIdLocal + ".json");

            var weather = JsonConvert.DeserializeObject <Weather5Days>(response);

            localName.Text            = district.local;
            updatedAt.Text            = weather.dataUpdate.ToShortTimeString();
            todayBoard.BindingContext = weather.data.FirstOrDefault();

            var precipitationEntries = new List <Entry>();

            foreach (var item in weather.data)
            {
                precipitationEntries.Add(new Entry(float.Parse(item.precipitaProb))
                {
                    ValueLabel = item.precipitaProb, Label = item.forecastDate
                });
            }

            chartView.Chart = new PointChart()
            {
                Entries = precipitationEntries
            };
            listView.ItemsSource = weather.data;
        }
Esempio n. 6
0
 public OctaneApis(RestConnector restConnector, ConnectionDetails connectionDetails)
 {
     _restConnector     = restConnector;
     _connectionDetails = connectionDetails;
     PLUGIN_VERSION     = Helpers.GetPluginVersion();
     requestWatcher     = Task.Factory.StartNew(() => WatchRequests(_requestWatcherTaskCancellationToken.Token), TaskCreationOptions.LongRunning);
 }
Esempio n. 7
0
        public override void Delete(HtmlData entity)
        {
            var offerType = entity.OfferType == OfferType.Olx ? HtmlDataConstants.OlxHtmlData : HtmlDataConstants.OtoDomHtmlData;
            var query     = new XdmpDocumentDelete(new MlUri($"{offerType}_{entity.Id}", MlUriDocumentType.Xml)).Query;

            RestConnector.Submit(query);
        }
        public override SearchModel GetById(string id)
        {
            var query    = new CtsSearch("/", new CtsElementValueQuery(SearchModelConstants.Id, id)).Query;
            var response = RestConnector.Submit(query);

            if (!response.Content.IsMimeMultipartContent())
            {
                return(null);
            }

            var content = response.Content.ReadAsMultipartAsync().Result.Contents;

            foreach (var data in content)
            {
                var text    = data.ReadAsStringAsync().Result;
                var xml     = XDocument.Parse(text);
                var modelId = xml.Descendants().Where(x => x.Name == SearchModelConstants.Id).First().Value;
                if (modelId == id.ToString())
                {
                    return(ExtractSearchModelInfo(xml));
                }
            }

            return(null);
        }
Esempio n. 9
0
        public override void Delete(Link entity)
        {
            var linkKind = entity.LinkSourceKind == OfferType.Olx ? OfferTypeConstants.Olx : OfferTypeConstants.OtoDom;
            var query    = new XdmpDocumentDelete(new MlUri($"{linkKind}_link_{entity.Id}", MlUriDocumentType.Xml)).Query;

            RestConnector.Submit(query);
        }
Esempio n. 10
0
        private async Task SaveGameData(int gameId)
        {
            var result = await new Query().GetDbGameById(gameId);

            if (result.Count == 0)
            {
                var response = await RestConnector.GetObjectAsync(RestConnector.GAME_DATA + "?gameId=" + gameId);

                if (!string.IsNullOrEmpty(await response.Content.ReadAsStringAsync()))
                {
                    try
                    {
                        var gameData = JsonConvert.DeserializeObject <Models.Rest.GameData>(await response.Content.ReadAsStringAsync());
                        var db       = new Query();
                        _ = db.AddGameData(gameData);
                    }
                    catch (Exception e)
                    {
                        await DisplayAlert(ConstValues.TITLE_STATUS_ERROR, e.ToString(), ConstValues.OPTION_OK);
                    }
                }
            }
            else
            {
                await DisplayAlert(ConstValues.TITLE_STATUS_WARNING, ConstValues.MSG_SAVE_GAME_ERROR, ConstValues.OPTION_OK);
            }
        }
        public List <RestConnector.HostData> GetDNSResultsObject(string searchString, string searchBy)
        {
            searchString = searchString.ToLower();

            RestConnector restConnector = new RestConnector();

            List <RestConnector.HostData> temp    = new List <RestConnector.HostData>();
            List <RestConnector.HostData> results = new List <RestConnector.HostData>();
            List <string> searchLists             = new List <string>();

            if (searchString.Contains(","))
            {
                searchLists = searchString.Split(',').ToList();
            }
            else
            {
                searchLists.Add(searchString);
            }

            foreach (var searchList in searchLists)
            {
                temp = restConnector.GetHostDNS(searchList, searchBy);
                results.AddRange(temp);
            }

            return(results);
        }
Esempio n. 12
0
        private async void GetActiveMatches()
        {
            Task <string> resultTask = RestConnector.GetDataFromApi(RestConnector.ActiveGames);
            var           result     = await resultTask;
            var           matches    = JsonConvert.DeserializeObject <List <Game> >(result);

            ActiveMatchesList.ItemsSource = matches;
        }
Esempio n. 13
0
        public static string GetEntityLink(RestConnector connector, WorkspaceContext context, BaseEntity entity)
        {
            string entityType = entity.AggregateType != null ? entity.AggregateType : entity.TypeName;

            return(string.Format("{0}/ui/entity-navigation?p={1}/{2}&entityType={3}&id={4}",
                                 connector.Host, context.SharedSpaceId, context.WorkspaceId, entityType, entity.Id.ToString()
                                 ));
        }
Esempio n. 14
0
        private async Task LoadDistrictsFromApi()
        {
            var response = await RestConnector.GetObjectAsync("https://api.ipma.pt/open-data/distrits-islands.json");

            DistrictIslands districts = JsonConvert.DeserializeObject <DistrictIslands>(response);

            listView.ItemsSource = districts.data;
        }
Esempio n. 15
0
 protected internal string GetCurrentXml()
 {
     lock (SyncRoot)
     {
         var path = GetCurrentPath().Replace('\\', '/');
         var xml  = RestConnector.GetString(path, RequestTimeout);
         return(xml);
     }
 }
Esempio n. 16
0
        private void Initialize(RestConnector connector, string rootFolder)
        {
            RequestTimeout = 4000;

            SyncRoot      = new object();
            RestConnector = connector;
            AgentAddress  = connector.EndpointAddress;
            RootFolder    = rootFolder;
        }
Esempio n. 17
0
 protected internal string GetProbeXml()
 {
     lock (SyncRoot)
     {
         var path = GetProbePath();
         var xml  = RestConnector.GetString(path, RequestTimeout);
         return(xml);
     }
 }
Esempio n. 18
0
 protected internal string GetCurrentXml(string deviceName)
 {
     lock (SyncRoot)
     {
         var path = GetCurrentPath(deviceName);
         var xml  = RestConnector.GetString(path, RequestTimeout);
         return(xml);
     }
 }
Esempio n. 19
0
        public static async Task <string> Add(int eventType, int matchId, string matchTime)
        {
            var evt = new Event {
                EventType = eventType, GameId = matchId, Time = matchTime, UserId = 1
            };

            Task <string> response = RestConnector.PostObjectToApi(evt, RestConnector.RegisterEvent);

            return(await response);
        }
        public override void Delete(ICommand entity)
        {
            var flwor = new Flwor();

            flwor.Let(new VariableName("doc"), new CtsSearch("/",
                                                             new CtsElementValueQuery(CommandConstants.CommandId,
                                                                                      (entity as BaseCommand)?.Id)));
            flwor.Return(new XdmpNodeDelete(new VariableName("doc").Query));
            RestConnector.Submit(flwor.Query);
        }
Esempio n. 21
0
        public DataMonitor(EntityClient entityClient, int period)
        {
#if DEBUG
            Profiling = true;
#endif
            m_agentAddress = entityClient.RestConnector.EndpointAddress;
            m_client       = entityClient;
            RestConnector  = m_client.RestConnector;
            Period         = period;
        }
Esempio n. 22
0
 protected internal string GetPathFilteredCurrentXml(string filter)
 {
     lock (SyncRoot)
     {
         var path = GetCurrentPath();
         path += "?path=";
         path += filter;
         var xml = RestConnector.GetString(path, RequestTimeout);
         return(xml);
     }
 }
Esempio n. 23
0
        public static async Task <string> Delete(int id)
        {
            var values = new Dictionary <string, string>
            {
                { RestConnector.MatchKeys[0], id.ToString() }
            };

            Task <string> response = RestConnector.PostDataToApi(values, RestConnector.DeleteGame + "?gameId=" + id);

            return(await response);
        }
Esempio n. 24
0
        public static async Task <string> Start(int matchId)
        {
            var values = new Dictionary <string, string>
            {
                { RestConnector.MatchKeys[0], matchId.ToString() }
            };

            Task <string> response = RestConnector.PostDataToApi(values, RestConnector.StartGame + "?gameId=" + matchId);

            return(await response);
        }
Esempio n. 25
0
        public void TestSingleRequest(string subfolder, string fileName)
        {
            string path       = UnitTestHelper.GetTestFilePath(subfolder, fileName);
            var    xmlContent = File.ReadAllText(path);
            var    guid       = UnitTestHelper.ParseNewsContent(xmlContent).Guid;

            var postData = $"xml={System.Web.HttpUtility.UrlEncode(xmlContent)}&uid={ System.Web.HttpUtility.UrlEncode(guid)}";
            var res      = RestConnector.GetData(_endPointUrl, "POST", postData);

            Assert.AreEqual("OK", res);
        }
 public override void Insert(SearchModel entity, ITransaction transaction)
 {
     using (var writer = new StringWriter())
         using (var xmlWriter = XmlWriter.Create(writer))
         {
             new XmlSerializer(entity.GetType()).Serialize(writer, entity);
             var serializedModel = writer.GetStringBuilder().ToString();
             var content         = MarklogicContent.Xml($"{entity.Id}", serializedModel, new[] { SearchModelConstants.CollectionName });
             RestConnector.Insert(content, transaction.GetScope());
         }
 }
Esempio n. 27
0
        private async Task GetData()
        {
            var response = await RestConnector.GetObjectAsync(RestConnector.USER);

            var user = JsonConvert.DeserializeObject <User>(await response.Content.ReadAsStringAsync());

            if (user.DisplayOptions.ContainsKey("imageUrl"))
            {
                Img.Source = user.DisplayOptions["imageUrl"];
                Img.Aspect = Aspect.AspectFill;
            }
        }
Esempio n. 28
0
        public Client(string clientAddress)
        {
            if (!clientAddress.StartsWith("http", StringComparison.OrdinalIgnoreCase))
            {
                clientAddress = "http://" + clientAddress;
            }

            var uri       = new Uri(clientAddress, UriKind.Absolute);
            var connector = new RestConnector(uri);

            Initialize(connector, uri.LocalPath);
        }
Esempio n. 29
0
        public static async Task <string> Add(int eventType, int matchId, int teamId, int memberId, string description, string matchTime)
        {
            var evt = new Event
            {
                AthleteId = memberId, EventDescription = description, EventType = eventType, GameId = matchId, Id = 0,
                Reg       = "", Time = matchTime, UserId = 1
            };

            Task <string> response = RestConnector.PostObjectToApi(evt, RestConnector.RegisterEvent);

            return(await response);
        }
Esempio n. 30
0
        private async void SaveChanges_Clicked(object sender, EventArgs e)
        {
            if (await App.DisplayMessage(ConstValues.TITLE_STATUS_WARNING, ConstValues.MSG_UPDATE_USER_QUESTION, ConstValues.OPTION_NO, ConstValues.OPTION_YES))
            {
                var response = await RestConnector.PutObjectAsync(RestConnector.USER, user);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    await App.DisplayMessage(ConstValues.TITLE_STATUS_INFO, ConstValues.MSG_USER_UPDATED, ConstValues.OPTION_OK);
                }
            }
        }