internal async Task <BlizzardAPIResponse> GetCharacterAchievements(RequestLocalization requestLocalization)
        {
            Uri generatedLink = RequestLinkFormater.GenerateAPIRequestLink(BlizzardAPIProfiles.Data, requestLocalization,
                                                                           new List <KeyValuePair <string, string> >(),
                                                                           BlizzardAPIProfiles.Character.ToString(),
                                                                           EnumDictionaryWrapper.dataResourcesFieldsWrapper[DataResourcesFields.CharacterAchievements]);

            return(await new APIDataRequestManager(_comparerDatabaseContext).GetDataByHttpRequest <BlizzardAPIResponse>(generatedLink));
        }
Beispiel #2
0
        public void GenerateRaiderIOApiRequestLink_WhenGenerateLink_ShouldGenerateValidLinkForRadierIO()
        {
            //Arrange
            string expectedLink = "https://raider.io/api/v1/characters/profile?region=eu&realm=burning-legion&name=wykminiacz&fields=mythic_plus_best_runs%2Cmythic_plus_ranks";

            RequestLocalization requestLocalization = new RequestLocalization()
            {
                CoreRegionUrlAddress = APIConf.RaiderIOAdress,
                Realm = new Realm()
                {
                    Slug = "burning-legion", Locale = "en_GB", Timezone = "Europe/Paris"
                }
            };

            List <RaiderIOCharacterFields> characterFields = new List <RaiderIOCharacterFields>()
            {
                RaiderIOCharacterFields.MythicPlusBestRuns,
                RaiderIOCharacterFields.MythicPlusRanks
            };

            string region = requestLocalization.Realm.Timezone == "Europe/Paris" ? "eu" : throw new Exception("Chosen realm is not European");


            string localFields = string.Empty;

            foreach (RaiderIOCharacterFields field in characterFields)
            {
                string wrappedField = EnumDictionaryWrapper.rioCharacterFieldWrapper[field];
                localFields = localFields.AddFieldToUrl(wrappedField);

                localFields = localFields.EndsWith("+") ? localFields.Remove(localFields.Length - 1, 1)
                                       : localFields;
            }

            localFields = localFields.EndsWith("%2C") ? localFields.Remove(localFields.Length - 3, 3) // remove join parameters symbol at ending field
                                                       : localFields;

            List <KeyValuePair <string, string> > fields = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("fields", localFields)
            };

            List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>(RaiderIOCharacterParams.Region.ToString(), region),
                new KeyValuePair <string, string>(RaiderIOCharacterParams.Realm.ToString(), requestLocalization.Realm.Slug),
                new KeyValuePair <string, string>(RaiderIOCharacterParams.Name.ToString(), "Wykminiacz")
            };

            //Act
            Uri actualLink = RequestLinkFormater.GenerateRaiderIOApiRequestLink(fields, parameters);

            //Assert
            Assert.Equal(expectedLink, actualLink.AbsoluteUri);
        }
Beispiel #3
0
        private void TrackerMode_Click(object sender, EventArgs e)
        {
            try
            {
                BreakCurrentMode();

                ArduinoRequests arduinoRequests = new ArduinoRequests();
                List <KeyValuePair <string, float> > userLocalization = arduinoRequests.SetLocalizationDataByUserInput(LatitudeTextBox.Text, LongitudeTextBox.Text);

                if (userLocalization.Count == 0)
                {
                    MessageBox.Show(InternalMessages.NoDataFromCordsTextboxes, MessageCaptions.Error.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                portConnector.SendDataToCom(ApplicationProtocol.FirstModeCommand);
                DisplayPortDataInLogger(InternalMessages.SelectedTrackerMode);

                Uri processedUriAdress = new RequestLinkFormater().GenerateLocationIQLink(userLocalization);

                string       jsonApiData   = new HttpClient().GetStringAsync(processedUriAdress).Result;
                Localization parsedApiData = JsonConvert.DeserializeObject <Localization>(jsonApiData.ToString());

                List <KeyValuePair <string, double> > solarTimeCalculations = new SolarTimeCalculations().CalculateSolarTimes(parsedApiData.Longitude);
                Others others = new Others();
                SolarCalculationResults solarCalculationResults = new SolarCalculationResults()
                {
                    MagneticDeclination  = others.CountEarthMagneticDeclination(),
                    EquationOfTime       = solarTimeCalculations[0].Value,
                    TimeCorrectionFactor = solarTimeCalculations[1].Value,
                    LocalSolarTime       = solarTimeCalculations[2].Value,
                    HourAngle            = solarTimeCalculations[3].Value,
                };
                solarCalculationResults.Altitude = new AltitudeCalculations().CountCurrentSunAltitude(parsedApiData.Latitude, solarCalculationResults.MagneticDeclination, solarCalculationResults.HourAngle);
                solarCalculationResults.Azimuth  = new AzimuthCalculations().CalculateSunAzimuth(parsedApiData.Latitude, solarCalculationResults.Altitude, solarCalculationResults.MagneticDeclination, solarCalculationResults.HourAngle);
                solarCalculationResults.SunRise  = others.SunRiseTimeCalculation(parsedApiData.Latitude, parsedApiData.Longitude, solarCalculationResults.MagneticDeclination, solarCalculationResults.EquationOfTime);
                solarCalculationResults.SunSet   = others.SunSetTimeCalculation(parsedApiData.Latitude, parsedApiData.Longitude, solarCalculationResults.MagneticDeclination, solarCalculationResults.EquationOfTime);

                var limitedAltitude = solarCalculationResults.Altitude < 10 ? 10 : solarCalculationResults.Altitude;
                var mappedAzimuth   = (270.00 / 360.00) * solarCalculationResults.Azimuth;
                mappedAzimuth = mappedAzimuth > 180 ? 180: mappedAzimuth;
                portConnector.SendDataToCom($"{ApplicationProtocol.BottomServoCommand} {Math.Abs(mappedAzimuth - 180)}");
                portConnector.SendDataToCom($"{ApplicationProtocol.TopServoCommand} {limitedAltitude}");
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #4
0
        public void GenerateAPIRequestLink_WhenGenerateLink_ShouldGenerateValidLinkForCharacter()
        {
            // Arrange
            string expectedLink = "https://eu.api.blizzard.com/wow/character/burning-legion/selectus?locale=en_GB";

            // Act
            RequestLocalization requestLocalization = new RequestLocalization()
            {
                CoreRegionUrlAddress = APIConf.BlizzadAPIAddressWrapper[Region.Europe],
                Realm = new Realm()
                {
                    Slug = "burning-legion", Locale = "en_GB"
                }
            };

            Uri actualLink = RequestLinkFormater.GenerateAPIRequestLink(BlizzardAPIProfiles.Character, requestLocalization,
                                                                        new List <KeyValuePair <string, string> >(),
                                                                        requestLocalization.Realm.Slug, "Selectus");

            //Assert
            Assert.Equal(expectedLink, actualLink.AbsoluteUri);
        }
        internal async Task <RaiderIOAPIResponse> GetRaiderIODataAsync(string characterName, RequestLocalization requestLocalization, List <RaiderIOCharacterFields> characterFields)
        {
            string region = requestLocalization.Realm.Timezone == "Europe/Paris" ? "eu" : throw new Exception("Choosed realm is not European");

            List <KeyValuePair <string, string> > fields = new List <KeyValuePair <string, string> >();

            List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>(RaiderIOCharacterParams.Region.ToString(), region),
                new KeyValuePair <string, string>(RaiderIOCharacterParams.Realm.ToString(), requestLocalization.Realm.Slug),
                new KeyValuePair <string, string>(RaiderIOCharacterParams.Name.ToString(), characterName)
            };

            // check if there is any additional parameters to get. If not - just return basic informations
            if (characterFields.Any())
            {
                string localFields = string.Empty;

                foreach (RaiderIOCharacterFields field in characterFields)
                {
                    string wrappedField = EnumDictionaryWrapper.rioCharacterFieldWrapper[field];
                    localFields = localFields.AddFieldToUrl(wrappedField);

                    localFields = localFields.EndsWith("+") ? localFields.Remove(localFields.Length - 1, 1)
                                           : localFields;
                }

                localFields = localFields.EndsWith("%2C") ? localFields.Remove(localFields.Length - 3, 3) // remove join parameters symbol at ending field
                                                           : localFields;

                fields.Add(new KeyValuePair <string, string>("fields", localFields));
            }

            Uri uriAddress = RequestLinkFormater.GenerateRaiderIOApiRequestLink(fields, parameters);

            return(await new APIDataRequestManager(_comparerDatabaseContext).GetDataByHttpRequest <RaiderIOAPIResponse>(uriAddress));
        }
        internal async Task <List <string> > GetRealmListByRegion(Region region)
        {
            List <string> realmsNames      = new List <string>();
            string        regionCoreAdress = string.Empty;

            try
            {
                if (APIConf.BlizzadAPIAddressWrapper.TryGetValue(region, out regionCoreAdress) == false)
                {
                    throw new KeyNotFoundException($"Cannot find region in {APIConf.BlizzadAPIAddressWrapper.GetType().Name} dictionary");
                }

                var requestLocalization = new RequestLocalization()
                {
                    CoreRegionUrlAddress = regionCoreAdress,
                };

                RealmsRequests realmsRequests = new RealmsRequests(_comparerDatabaseContext);

                var         parameters    = new List <KeyValuePair <string, string> >();
                Uri         uriAddress    = RequestLinkFormater.GenerateAPIRequestLink(BlizzardAPIProfiles.Realm, requestLocalization, parameters, "status"); //TODO replace string
                var         realmResponse = await new APIDataRequestManager(_comparerDatabaseContext).GetDataByHttpRequest <BlizzardAPIResponse>(uriAddress);
                RealmStatus realmStatus   = JsonProcessing.DeserializeJsonData <RealmStatus>(realmResponse.Data);

                foreach (Realm realmsData in realmStatus.Realms)
                {
                    realmsNames.Add(realmsData.Name);
                }
            }
            catch (Exception)
            {
                realmsNames = new List <string>();
            }

            return(realmsNames);
        }
        internal async Task <BlizzardAPIResponse> GetCharacterDataAsJsonAsync(string characterName, RequestLocalization requestLocalization, List <CharacterFields> characterFields)
        {
            List <KeyValuePair <string, string> > characterParams = new List <KeyValuePair <string, string> >();

            // check if there is any additional parameters to get. If not - just return basic informations
            if (characterFields.Any())
            {
                string localFields = string.Empty;

                foreach (CharacterFields field in characterFields)
                {
                    string wrappedField = EnumDictionaryWrapper.characterFieldsWrapper[field];
                    localFields = localFields.AddFieldToUrl(wrappedField);
                }

                localFields = localFields.EndsWith("%2C+") ? localFields.Remove(localFields.Length - 4, 4) // remove join parameters symbol at ending field
                                                           : localFields;

                characterParams.Add(new KeyValuePair <string, string>("?fields", localFields));
            }
            Uri uriAddress = RequestLinkFormater.GenerateAPIRequestLink(BlizzardAPIProfiles.Character, requestLocalization, characterParams, requestLocalization.Realm.Slug, characterName); // generates link for request

            return(await _aPIDataRequestManager.GetDataByHttpRequest <BlizzardAPIResponse>(uriAddress));
        }