Пример #1
0
 public User Login([FromBody] User user)
 {
     _conn = new Connection(_connectionString);
     try
     {
         _conn.OpenConnection();
         string token = _conn.Login(user.Username, user.PasswordHash);
         if (!string.IsNullOrEmpty(token))
         {
             user.Token = token;
             return user;
         }
         else
         {
             throw new Exception("Error login");
         }
     }
     finally
     {
         _conn.CloseConnection();
     }
 }
Пример #2
0
        //Fetches information from 'VNDB.org'
        private int fetchInformation(bool Update)
        {
            //This basically fetches information from vndb using the API
            //First it establishes a connection and logs in
            //using the entered LoginName or a random loginname

            //Then it request basic vn information
            //and deserializes the jsonresponse
            //After that it displays the reponse in
            //the matching textboxes

            //Now it requets detailed information
            //deserializes it again....
            //and stores information in matching controls

            //Now it requests tags
            //deserializes them
            //and stores them in txtTags-Textbox
            //mind you: The tags are all in int format(only ID's)!

            //Now we read our tags-dump
            //deserialize them
            //and change our int tags to the matching string tags

            //That's it.

            Connection conn = new Connection();
            string nice = " ";
            int id = 0, vns_number = 0;
            Random rnd = new Random();

            int error = 0;

            int login_id = rnd.Next(1000);

            conn.Open();

            if (txtLoginName.Text != "")
                error = conn.Login(txtLoginName.Text);
            else
                error = conn.Login(Convert.ToString("asd" + login_id));

            if (error == 1)
            {
                MessageBox.Show("Error while logging in. Response: " + conn.jsonresponse, "Login Error", MessageBoxButtons.OK);
                return 0;
            }

            if (Update == false)
                error = conn.Query("get vn basic (id = " + txtID.Text + " )"); //request basic information
            else
            {
                foreach (Visual_Novel novel in VNS)
                {
                    if (novel.englishName == lbVN.SelectedItem.ToString().Trim())
                    {
                        id = novel.id;
                        error = conn.Query("get vn basic (id = " + id + " )");
                        break;
                    }
                    vns_number++;
                }
            }

            if (error == 1)
            {
                MessageBox.Show("Error while requesting information. Response: " + conn.jsonresponse, "Query Error", MessageBoxButtons.OK);
                return 0;
            }

            BasicRootObject basic_information = Newtonsoft.Json.JsonConvert.DeserializeObject<BasicRootObject>(conn.jsonresponse); //deserialize it
            List<BasicItem> basic_item = basic_information.items;

            if (Update == false)
            {
                txtName.Text = basic_item[0].title;
                txtOriginalName.Text = basic_item[0].original;
                txtVNID.Text = Convert.ToString(basic_item[0].id);
                txtTags.Text = "";
            }
            else
            {
                VNS[vns_number].englishName = basic_item[0].title;
                VNS[vns_number].originalName = basic_item[0].original;
                VNS[vns_number].id = basic_item[0].id;
            }

            if (Update == false)
                error = conn.Query("get vn details (id = " + txtID.Text + " )");
            else
            {
                error = conn.Query("get vn details (id = " + id + " )");
            }

            if (error == 1)
            {
                MessageBox.Show("Error while requesting information. Response: " + conn.jsonresponse, "Query Error", MessageBoxButtons.OK);
                return 0;
            }

            DetailsRootObject detailed_information = Newtonsoft.Json.JsonConvert.DeserializeObject<DetailsRootObject>(conn.jsonresponse); //deserialize it
            List<DetailsItem> details_item = detailed_information.items;

            if (Update == false)
            {
                rtbDescription.Text = details_item[0].description;
                pcbImages.ImageLocation = details_item[0].image;
            }
            else
                VNS[vns_number].description = details_item[0].description;

            if (Update == false)
                error = conn.Query("get character details (vn = " + txtID.Text + " )");
            else
                error = conn.Query("get character details (vn = " + id + " )");

            if (error == 1)
            {
                MessageBox.Show("Error while requesting information. Response: " + conn.jsonresponse, "Query Error", MessageBoxButtons.OK);
                return 0;
            }

            CharacterRootObject character_information = Newtonsoft.Json.JsonConvert.DeserializeObject<CharacterRootObject>(conn.jsonresponse);
            List<CharacterItem> character_item = character_information.items;

            character_images = new List<string>();
            character_images.Clear();

            foreach (CharacterItem item in character_item)
            {
                if (item.image != null)
                    character_images.Add(item.image);
            }

            if (Update == false)
                error = conn.Query("get vn tags (id = " + txtID.Text + " )");
            else
                error = conn.Query("get vn tags (id = " + id + " )");

            if (error == 1)
            {
                MessageBox.Show("Error while requesting information. Response: " + conn.jsonresponse, "Query Error", MessageBoxButtons.OK);
                return 0;
            }

            TagsRootObject tags_information = Newtonsoft.Json.JsonConvert.DeserializeObject<TagsRootObject>(conn.jsonresponse); //deserialize them
            List<TagsItem> tags_item = tags_information.items;

            if (Update == false)
            {
                for (int i = 0; i < tags_item[0].tags.Count; i++) //Store them in textbox
                {
                    if (txtTags.Text == "")
                        nice = "";
                    else
                        nice = " ";

                    txtTags.Text = txtTags.Text + nice + Convert.ToString(tags_item[0].tags[i][0]);
                }
            }
            else
            {
                VNS[vns_number].tags = "";
                for (int i = 0; i < tags_item[0].tags.Count; i++) //Store them in textbox
                {
                    if (VNS[vns_number].tags == "")
                        nice = "";
                    else
                        nice = " ";

                    VNS[vns_number].tags = VNS[vns_number].tags + nice + Convert.ToString(tags_item[0].tags[i][0]);
                }
            }

            if (plain_tags == null) //Read tag-dump and deserialize it (only once -> needs time!)
                plain_tags = JsonConvert.DeserializeObject<List<WrittenTagsRootObject>>(File.ReadAllText(@"tags.json"));

            string[] tags;

            if (Update == false)
                tags = txtTags.Text.Split(' ');
            else
                tags = VNS[vns_number].tags.Split(' ');

            if (Update == false)
                txtTags.Text = "";
            else
                VNS[vns_number].tags = "";

            foreach (string tmp in tags) //Change our 'int'-tags into matching 'string'-tags
            {
                foreach (WrittenTagsRootObject tmp2 in plain_tags)
                {
                    if ((((Convert.ToInt32(tmp) == tmp2.id) && (tmp2.cat == "ero") && (chkSexual.Checked == true)) ||
                        ((Convert.ToInt32(tmp) == tmp2.id) && (tmp2.cat == "cont") && (chkContent.Checked == true)) ||
                        ((Convert.ToInt32(tmp) == tmp2.id) && (tmp2.cat == "tech") && (chkTechnical.Checked == true))) && Update == false)
                    {
                        if (txtTags.Text == "")
                            nice = "";
                        else
                            nice = ", ";

                        txtTags.Text = txtTags.Text + nice + tmp2.name;
                    }
                    else if ((((Convert.ToInt32(tmp) == tmp2.id) && (tmp2.cat == "ero") && (chkSexual.Checked == true)) ||
                        ((Convert.ToInt32(tmp) == tmp2.id) && (tmp2.cat == "cont") && (chkContent.Checked == true)) ||
                        ((Convert.ToInt32(tmp) == tmp2.id) && (tmp2.cat == "tech") && (chkTechnical.Checked == true))) && Update == true)
                    {
                        if (VNS[vns_number].tags == "")
                            nice = "";
                        else
                            nice = ", ";

                        VNS[vns_number].tags = VNS[vns_number].tags + nice + tmp2.name;
                    }
                }
            }
            conn.CloseConnection();
            return vns_number;
        }