示例#1
0
        public string GetStream(string stream)
        {
            using (entity = new coverageEntities1())
            {
                string query = "SELECT * FROM stream WHERE name = '" + stream + "'";

                var thisStream = entity.streams.SqlQuery(query).FirstOrDefault();

                StringBuilder sb = new StringBuilder();
                sb.Append("<a href='")
                    .Append(GetStreamLink(stream))
                    .Append("' target='_blank'/>")
                    .Append(stream)
                    .Append(" is <img src='../Images/").Append(thisStream != null && thisStream.online == 1 ? "online.png' alt='Online'" : "offline.png' alt='Offline'")
                    .Append("/></a>");

                return sb.ToString();

            }
        }
示例#2
0
        private void UpdateStreams()
        {
            foreach (string stream in Streams)
            {
                var url = "https://api.twitch.tv/kraken/streams/" + stream + "?client_id=" + clientID;
                var textFromFile = (new WebClient()).DownloadString(url);

                JToken token = JObject.Parse(textFromFile);

                var online = token.SelectToken("stream").HasValues ? 1 : 0;

                using (entity = new coverageEntities1())
                {
                    string query = "UPDATE stream SET online = " + online + " WHERE name = '" + stream + "'";
                    entity.Database.ExecuteSqlCommand(query);
                    entity.SaveChanges();
                }

            }
        }