Esempio n. 1
0
        public List <YoutubeLiveStreamInfo> GetYoutubeLiveStreamInfo(Channels inChannel)
        {
            List <YoutubeLiveStreamInfo> streamInfos = new List <YoutubeLiveStreamInfo>();
            SqlCommand    command = new SqlCommand();
            SqlDataReader reader  = null;

            try
            {
                command.Connection  = SqlConnection;
                command.CommandText = @"SELECT * FROM YoutubeLiveStreamInfo where ChannelId = @ChannlelId";

                command.Parameters.AddWithValue("@ChannlelId", inChannel.ChannelId);

                reader = command.ExecuteReader();

                while (reader.Read())
                {
                    string   videoId             = (string)reader["VideoId"];
                    string   channelId           = (string)reader["ChannelId"];
                    string   liveChatId          = (string)reader["LiveChatId"];
                    DateTime liveStreamStartDate = (DateTime)reader["LiveStreamStartDate"];
                    DateTime liveStreamEndDate   = (DateTime)reader["LiveStreamEndDate"];
                    int      liveStreamTimeSpan  = (int)reader["LiveStreamTimeSpan"];

                    TimeSpan span = new TimeSpan(liveStreamTimeSpan);

                    YoutubeLiveStreamInfo streamInfo = new YoutubeLiveStreamInfo(videoId,
                                                                                 channelId,
                                                                                 liveChatId,
                                                                                 liveStreamStartDate,
                                                                                 liveStreamEndDate,
                                                                                 span);

                    streamInfos.Add(streamInfo);
                }

                return(streamInfos);
            }
            catch (SqlException sqlEx)
            {
                string srr = sqlEx.StackTrace;

                reader.Close();
                command.Dispose();

                SqlConnection.Close();                  //閉じて
                SqlConnection.Dispose();                //解放する
            }
            finally
            {
                reader.Close();
                command.Dispose();
                //SqlConnection.Close();  //閉じて
                //SQLConnection.Dispose();//解放する
            }
            return(null);
        }
Esempio n. 2
0
        public List <YoutubeLiveComment> GetYoutubeLiveComments(YoutubeLiveStreamInfo inStreamInfo)
        {
            List <YoutubeLiveComment> comments = new List <YoutubeLiveComment>();
            SqlCommand    command = new SqlCommand();
            SqlDataReader reader  = null;

            try
            {
                command.Connection  = SqlConnection;
                command.CommandText = SelectSQL;

                command.Parameters.AddWithValue("@VieoId", inStreamInfo.VideoId);
                command.Parameters.AddWithValue("@LiveChatId", inStreamInfo.LiveChatId);

                reader = command.ExecuteReader();

                while (reader.Read())
                {
                    string   videoId         = (string)reader["VideoId"];
                    string   liveChatId      = (string)reader["LiveChatId"];
                    string   commentId       = (string)reader["CommentId"];
                    string   displayName     = (string)reader["DisplayName"];
                    string   displayMessage  = (string)reader["DisplayMessage"];
                    DateTime publishedAt     = (DateTime)reader["PublishedAt"];
                    bool     isChatOwner     = (bool)reader["IsChatOwner"];
                    bool     isChatSponsor   = (bool)reader["IsChatSponsor"];
                    bool     isChatModerator = (bool)reader["IsChatModerator"];

                    YoutubeLiveComment comment = new YoutubeLiveComment(commentId,
                                                                        displayName,
                                                                        displayMessage,
                                                                        publishedAt,
                                                                        isChatOwner,
                                                                        isChatSponsor,
                                                                        isChatModerator);

                    comments.Add(comment);
                }

                comments = comments.OrderBy(x => x.PublishedAt).ThenBy(x => x.CommentId).ToList();
                inStreamInfo.Commnents.AddRange(comments);

                return(comments);
            }
            catch (SqlException sqlEx)
            {
                string srr = sqlEx.StackTrace;

                reader.Close();
                command.Dispose();

                SqlConnection.Close();                  //閉じて
                SqlConnection.Dispose();                //解放する
            }
            finally
            {
                reader.Close();
                command.Dispose();
                //SQLConnection.Close();	//閉じて
                //SQLConnection.Dispose();//解放する
            }
            return(null);
        }