Example #1
0
        public List<Event> ParseAll()
        {
            var eventsList = new List<Event>();
            try
            {
                Debug.WriteLine("[Bet365]Start parsing Bet365");

                SetConnection();
            }
            catch (Exception e)
            {
                Debug.WriteLine("[Bet365]Ex: " + e.Message + "stack: " + e.StackTrace);
                return default(List<Event>);
            }
            var matches = new List<string>();
            var success = false;
            try
            {
                foreach (var channel in CHANNELS)
                {
                    Debug.WriteLine("[Bet365]Trying to get events list from " + channel + " channel.");
                    var result = GetAvailableMatches(channel);
                    if (result == null)
                    {
                        Debug.WriteLine("[Bet365] Result is null");
                        success = false;
                        continue;
                    }
                    if (matches.Count == 0)
                    {
                        if (result.Count != 0)
                        {
                            matches = result;
                            Debug.WriteLine("[BET365] ALL OK WE FOUND ELEMS");
                            success = true;
                            break;
                        }
                    }
                    if (matches.Count < result.Count)
                    {
                        matches = result;
                        Debug.WriteLine("[Bet365] matches is more elements than previus: " + matches.Count + " : " +
                                        result.Count);
                        success = true;
                        break;
                    }
                    success = true;
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("[Bet365]Ex in Chanel Get Mathes: " + e.Message + "stack: " + e.StackTrace);
                return default(List<Event>);
            }
            if (!success) return null;
            try
            {
                foreach (var match in matches)
                {
                    var eventInfo = GetTennisEventInformation(match);
                    if (eventInfo == null)
                    {
                        eventInfo = new Event(null, null, new Team(), new Team()) {IsClose = true};
                        Debug.WriteLine("[Bet365]Finnishd");
                    }
                    eventsList.Add(eventInfo);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("[Bet365]Ex in getTennisEvent Score: " + e.Message + "stack: " + e.StackTrace);
                return default(List<Event>);
            }
            return eventsList;
        }
Example #2
0
        public Event GetTennisEventInformation(string id)
        {
            Subscribe(id);

            var header = new WebHeaderCollection {{"method", "1"}};
            var requestPow = powRequest(2, header);
            if (requestPow.Length < 50)
            {
                Debug.Write("Error. Repsonse from server" + requestPow);
                Unsubscribe(id);
                GetTennisEventInformation(id);
            }
            var eventExpandedData = requestPow.Split((char) 0x01);
            eventExpandedData = eventExpandedData[eventExpandedData.Length - 1].Split((char) 0x7c);

            var resultList = new List<Dictionary<string, string>>();
            var currentRoot = new Dictionary<string, string>();

            resultList.Add(new Dictionary<string, string>());
            resultList.Add(new Dictionary<string, string>());

            var firstItem = true;

            string currentKey = null;
            string competitionType = null;
            string eventName = null;

            string team1Score = null;
            string team2Score = null;

            string name1Player = null;
            string name2Player = null;

            foreach (var anEventExpandedData in eventExpandedData)
            {
                var parsedLine = parameterizeLine(anEventExpandedData);

                if (parsedLine == null)
                    continue;

                if (parsedLine.ContainsKey("EV"))
                {
                    //Event
                    parsedLine.TryGetValue("EV", out currentRoot);
                    Debug.Assert(currentRoot != null, "currentRoot != null");
                    currentRoot?.TryGetValue("CT", out competitionType);
                    currentRoot?.TryGetValue("NA", out eventName);
                }
                else if (parsedLine.ContainsKey("SC"))
                {
                    parsedLine.TryGetValue("SC", out currentRoot);
                    if (firstItem)
                    {
                        currentKey = "name";
                        firstItem = false;
                    }
                    else
                    {
                        Debug.Assert(currentRoot != null, "currentRoot != null");
                        currentRoot.TryGetValue("NA", out currentKey);
                    }
                }
                else if (parsedLine.ContainsKey("TE"))
                {
                    parsedLine.TryGetValue("TE", out currentRoot);
                    var equelsValue = "";
                    currentRoot.TryGetValue("OR", out equelsValue);
                    if (string.Equals(equelsValue, "0"))
                    {
                        currentRoot.TryGetValue("PO", out team1Score);
                        currentRoot.TryGetValue("NA", out name1Player);
                    }
                    else
                    {
                        currentRoot.TryGetValue("NA", out name2Player);
                        currentRoot.TryGetValue("PO", out team2Score);
                    }
                }
            }
            Unsubscribe(id);
            if (competitionType == null)
            {
                Debug.WriteLine("[Bet365] Competition Type null");
                Debug.Write("Repsonse from server" + requestPow);
                return null;
            }
            var team1 = new Team(name1Player, team1Score);
            var team2 = new Team(name2Player, team2Score);
            var eEvent = new Event(id, competitionType, team1, team2);
            return eEvent;
        }