예제 #1
0
        static void insertData(AHRootObject ahData, String realm)
        {
            String connectionString = "Data Source=(local);Initial Catalog=RealmData;"
                                      + "Integrated Security=SSPI;Max Pool Size=200;";

            Auction[] auctions = ahData.auctions.ToArray();

            using (SqlConnection connect = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand("SELECT ConnectID FROM RealmList WHERE RealmSlug = '" + realm + "';", connect);
                command.Connection.Open();
                int connectID = (int)command.ExecuteScalar();

                try
                {
                    command = new SqlCommand("SELECT * INTO AHData_" + connectID + " FROM AHDataTemplate;", connect);
                    command.ExecuteNonQuery();
                }
                catch (Exception)
                {
                    command = new SqlCommand("DELETE FROM AHData_" + connectID + ";", connect);
                    command.ExecuteNonQuery();
                }

                for (int i = 0; i < auctions.Length; i++)
                {
                    String bonusLists = auctions[i].bonusLists == null ? null : "Placeholderbl";
                    String modifiers  = auctions[i].modifiers == null ? null : "Placeholdermod";
                    String realmName  = auctions[i].ownerRealm.Contains("'") ? auctions[i].ownerRealm.Insert(auctions[i].ownerRealm.LastIndexOf("'"), "'") : auctions[i].ownerRealm;

                    command = new SqlCommand("INSERT INTO AHData_" + connectID +
                                             " VALUES(" + auctions[i].auc + ", " + auctions[i].item + ", '" + auctions[i].owner + "', '" +
                                             realmName + "', " + auctions[i].bid + ", " + auctions[i].buyout + ", " +
                                             auctions[i].quantity + ", '" + auctions[i].timeLeft + "', " + auctions[i].rand + ", " +
                                             auctions[i].seed + ", " + auctions[i].context + ", " +
                                             (bonusLists == null ? "null, " : "'" + bonusLists + "', ") +
                                             (modifiers == null ? "null, " : "'" + modifiers + "', ") +
                                             (auctions[i].petSpeciesId == null ? 0 : auctions[i].petSpeciesId) + ", " +
                                             (auctions[i].petBreedId == null ? 0 : auctions[i].petBreedId) + ", " +
                                             (auctions[i].petLevel == null ? 0 : auctions[i].petLevel) + ", " +
                                             (auctions[i].petQualityId == null ? 0 :auctions[i].petQualityId) + ");", connect);

                    command.ExecuteNonQuery();
                }
                connect.Close();
            }
        }
예제 #2
0
        static async Task getAHDataThread(int index, String realm)
        {
            try
            {
                AHFileRoot fileRoot = await getAPIAHRootFileData("auction/data/" + realm + "?locale=en_US&apikey=k7rsncmwup6nttk6vzeg6knyw4jrjjzj");

                String       ahRootDataPath = (fileRoot.files[0].url).Substring(55);
                AHRootObject ahData         = await getAPIAHRootData(ahRootDataPath);

                insertData(ahData, realm);
                Console.WriteLine(DateTime.Now + " SUCCESS!! I've succesfully updated " + realm + "'s auction data!");
                ahData.Dispose();
            }catch (Exception e)
            {
                Console.WriteLine(DateTime.Now + " It looks like there was an error updating " + realm + ". It will attempt to update on the next data collection attempt.\n" + e.Message);
            }
        }
예제 #3
0
        static async Task <AHRootObject> getAPIAHRootData(String path)
        {
            AHRootObject        ahRootObject = null;
            HttpResponseMessage response     = await ahDataClient.GetAsync(path);

            String responseData = "";

            if (response.IsSuccessStatusCode)
            {
                responseData = await response.Content.ReadAsStringAsync();
            }

            JObject realmData = JObject.Parse(responseData);

            ahRootObject = JsonConvert.DeserializeObject <AHRootObject>(responseData);

            return(ahRootObject);
        }