Example #1
0
 public void FillCompareTable()
 {
     Data   = null;
     socket = new WebSocket(wsURL);
     socket.Connect();
     socket.OnMessage += Socket_OnMessage;
     socket.Send(sessionReq);
     while (!dataArrived)
     {
         Task.Delay(1000).ConfigureAwait(false);
     }
     foreach (var sport in Data["sport"].First)
     {
         if (!mappings.SportMappings.ContainsKey(sport["alias"].ToObject <string>()))
         {
             continue;
         }
         foreach (var region in sport["region"])
         {
             JObject regionObj  = (JObject)region.First;
             string  regionName = regionObj["alias"].ToObject <string>();
             foreach (var competition in regionObj["competition"])
             {
                 JObject league     = (JObject)competition.First;
                 string  leagueName = league["name"].ToObject <string>();
                 foreach (var game in league["game"])
                 {
                     try
                     {
                         Compare_Events ev      = new Compare_Events();
                         JObject        gameObj = (JObject)game.First;
                         ev.Home   = gameObj["team1_name"].ToObject <string>();
                         ev.Away   = gameObj["team2_name"].ToObject <string>();
                         ev.Region = regionName;
                         ev.League = leagueName;
                         ev.Start  = DateHelpers.TimeStampToDateTime(gameObj["start_ts"].ToObject <double>());
                         var a = gameObj["start_ts"];
                         ev.PrematchEnd = ev.Start;
                         ev.SportID     = mappings.SportMappings[sport["alias"].ToObject <string>()].ID;
                         ev.SiteID      = mappings.ID;
                         context.Compare_Events.Add(ev);
                     }
                     catch
                     {
                         continue;
                     }
                 }
             }
         }
     }
     int count = context.SaveChanges();
 }
Example #2
0
        public void FillCompareTable()
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_allEventsApiUrl);

            request.Method = "GET";
            string json;

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                Stream       dataStream = response.GetResponseStream();
                StreamReader reader     = new StreamReader(dataStream);
                json = reader.ReadToEnd();
                reader.Close();
                dataStream.Close();
            }
            int     added = 0;
            JObject obj;

            try
            {
                obj = JObject.Parse(json);
                foreach (var item in obj["events"])
                {
                    JObject        itemObj   = ((JObject)item);
                    JObject        eventObj  = (JObject)itemObj["event"];
                    Compare_Events ev        = new Compare_Events();
                    string         eventData = eventObj["id"].ToObject <string>();

                    ev.Home        = eventObj["homeName"].ToObject <string>();
                    ev.Away        = eventObj["awayName"].ToObject <string>();
                    ev.Start       = DateHelpers.TimeStampMSToDateTime(eventObj["start"].ToObject <double>());
                    ev.PrematchEnd = DateHelpers.TimeStampMSToDateTime(eventObj["prematchEnd"].ToObject <double>());
                    JArray paths = ((JArray)eventObj["path"]);
                    if (!mappings.SportMappings.ContainsKey(paths[0]["name"].ToObject <string>()))
                    {
                        continue;
                    }
                    Sport sport = mappings.SportMappings[paths[0]["name"].ToObject <string>()].DBCopy(context);
                    if (sport != null)
                    {
                        ev.Sport = sport;
                    }
                    else
                    {
                        break;
                    }
                    if (paths.Count == 2)
                    {
                        ev.League = paths[1]["name"].ToObject <string>();
                    }
                    else if (paths.Count == 3)
                    {
                        ev.Region = paths[1]["name"].ToObject <string>();
                        ev.League = paths[2]["name"].ToObject <string>();
                    }
                    ev.SiteID = mappings.ID;
                    context.Compare_Events.Add(ev);
                }
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine("888 invalid json, or changed json formatting");
            }
        }