Exemplo n.º 1
0
        private void bValidateClientToken_Click(object sender, EventArgs e)
        {
            string token = Base64.Base64Encode(MainConfig.Instance.ClientToken);


            string uri = UrlConfig.Build(UrlConfig.Instance.ValidateTokenRoute, token);

            try
            {
                string result = RestClient.MakeSimpleRequest(uri);
                this.TokenValid = (result.Trim().ToLower() == "yes");
                if (this.TokenValid.Value)
                {
                    MessageBox.Show("Token is valid");
                }
                else
                {
                    MessageBox.Show("Token is not valid");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            this.LoadUI();
        }
        public static UrlConfig Load()
        {
            string fileName    = GetFileName();
            string jsonContent = null;

            if (File.Exists(fileName))
            {
                jsonContent = File.ReadAllText(fileName);
            }
            else
            {
                jsonContent = RessourcesReader.TextFileRessourceToString(Properties.Resources.UrlConfig);
            }

            UrlConfig instance = JsonConvert.DeserializeObject <UrlConfig>(jsonContent);

            instance.Save();

            return(instance);
        }
        private bool Publish()
        {
            try
            {
                BadgeDto dto = new BadgeDto();
                dto.BadgeKeys     = this.Data.DiscoveredEntries;
                dto.ClientToken   = MainConfig.Instance.ClientToken;
                dto.GlobalName    = this.Data.GlobalName;//MainConfig.Instance.SelectedAccount.Name;
                dto.CharacterName = this.Data.ToonName;


                if (!dto.IsValid())
                {
                    throw new Exception("Processing Data is not valid!");
                }

                string json = dto.ToJSON();



                string uri = UrlConfig.Build(UrlConfig.Instance.PublishRoute);

                string content = RestBasicDto.Prep(json);
                string result  = RestClient.MakePostRequest(uri, content);
                result = $"{result}".Trim().ToLower();
                if (!string.IsNullOrEmpty(result) && result != "success")
                {
                    MessageBox.Show(result);
                    this.Close();
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                this.Close();
                return(false);
            }
        }