예제 #1
0
 public void Run(string url, IUnitOfWork _uow, StreamSesson sesson)
 {
     using (var client = new HttpClient())
     {
         using (var stream = client.GetStreamAsync(url).Result)
         {
             using (var reader = new StreamReader(stream))
             {
                 string result;
                 while (true)
                 {
                     result = reader.ReadLine();
                     if (result != string.Empty && result != null)
                     {
                         if (result != ": ping")
                         {
                             result = "{" + result + "}";
                             var commentResult = JsonConvert.DeserializeObject <commentResult>(result);
                             Console.WriteLine(commentResult.data.from.name + ":" + commentResult.data.message);
                             var user = CheckUser(_uow, commentResult);
                             // WILL CHECK USER BEFORE ADD COMMENT
                             var comment = AddComment(_uow, commentResult, user, sesson);
                         }
                     }
                 }
             }
         }
     }
 }
예제 #2
0
 public Comment(commentClass result, User user, StreamSesson sesson)
 {
     CommentId      = result.id;
     Message        = result.message;
     StreamSessonId = sesson.Id;
     UserId         = user.Id;
     DisplayName    = user.DisplayName;
 }
예제 #3
0
        public void Run()
        {
            //START READ CONFIG
            Console.WriteLine("fbChatbot running\n");
            var curPath = Directory.GetCurrentDirectory();

            if (!File.Exists(curPath + "/config.json"))
            {
                Console.WriteLine("[ERROR] config.json File Not Found!");
                Console.ReadKey();
                Environment.Exit(1);
            }
            else
            {
                Console.WriteLine("[INFO] config.json Found!");
            }
            StreamReader sr = new StreamReader("config.json");

            jsonParse = (JObject)JsonConvert.DeserializeObject(sr.ReadToEnd());
            //READ CONFIG END


            Console.WriteLine("GET USER STREAM ID VIDEO ...");
            String url = jsonParse.GetValue("userID").ToString() + "/live_videos";

            RestRequest rNewStream = new RestRequest(url, Method.GET);

            //Stream Info
            rNewStream.AddParameter("broadcast_status", jsonParse.GetValue("status").ToString());
            rNewStream.AddParameter("access_token", jsonParse.GetValue("token").ToString());

            var tempResult = rClient.Execute(rNewStream).Content;

            // Console.WriteLine(tempResult);
            result = JsonConvert.DeserializeObject <LiveVideoResult>(tempResult);

            //GET STREAM SESSON
            sesson = StreamInfo(result.data);

            DisplayStreamInfo(sesson);

            Console.WriteLine("[INFO]Attempting to initiate a Server-Sent Events subscription");

            var serverSentClinet = new SeverSentClient();

            Task.Run(() => serverSentClinet.Run(getRequestURL(), _uow, sesson));

            Console.WriteLine("[INFO]Sever update live video comments run on http://localhost:5000/");
        }
예제 #4
0
 public StreamSesson StreamInfo(StreamVideo[] arr)
 {
     foreach (StreamVideo video in arr)
     {
         var sesson = _uow.StreamSessonReporitory.Get(p => p.StreamId == video.id);
         if (sesson == null)
         {
             var newSesson = new StreamSesson(video);
             _uow.StreamSessonReporitory.Add(newSesson);
             _uow.SaveChanges();
             return(newSesson);
         }
         else
         {
             return(sesson);
         }
     }
     return(null);
 }
예제 #5
0
 public static void DisplayStreamInfo(StreamSesson sesson)
 {
     Console.WriteLine("[INFO] Stream Request Success!\nStream URL : rtmps://live-api-s.facebook.com:443/rtmp/");
     Console.WriteLine("Stream sesson Id : " + sesson.StreamId);
     Console.WriteLine("Stream sesson Key : " + sesson.StreamUrl);
 }
예제 #6
0
        public Comment AddComment(IUnitOfWork _uow, commentResult comment, User user, StreamSesson sesson)
        {
            var newComment = new Comment(comment.data, user, sesson);

            _uow.CommentRepository.Add(newComment);
            _uow.SaveChanges();
            return(newComment);
        }