public async Task <ActionResult <Result> > InsertWatching(MongoWatching newWatch)
 {
     _ws.Create(newWatch);
     return(new Result {
         Text = "Done"
     });
 }
        public ActionResult <WatchingResult> Check([Bind("User_Id", "Media_Id", "Type", "SeekPosition")] NewSeek newSeek)
        {
            String resultText = "";


            //Stopwatch t_sw = new Stopwatch();
            //t_sw.Start();
            MongoWatching query = _ws.Get(newSeek.User_Id.ToString(), newSeek.Media_Id, newSeek.Type);

            //t_sw.Stop();
            //Console.WriteLine("check read takes: " + t_sw.ElapsedMilliseconds + " ms");


            if (query != null)
            {
                resultText = "Watching";
            }
            else
            {
                resultText = "Not Watching";
            }

            WatchingResult watchingResult = new WatchingResult {
                Status = resultText, Watchings = query
            };

            return(watchingResult);
        }
        private void task()
        {
            while (true)
            {
                if (Vars.still_s.Count > 0)
                {
                    Console.WriteLine("in");
                    List <Still_Watching> toChange       = new List <Still_Watching>();
                    List <MongoWatching>  mongoWatchings = Vars.still_s;
                    List <MongoWatching>  removed        = Vars.removed;


                    toChange = mongoWatchings.Select(x => new Still_Watching {
                        Media_Id = x.Media_Id, Type = x.Type, User_id = int.Parse(x.User_id)
                    }).ToList();

                    foreach (MongoWatching mongoWatching in removed)
                    {
                        int u_id  = int.Parse(mongoWatching.User_id);
                        var watch = (from q in _context.Still_Watchings where q.Media_Id == mongoWatching.Media_Id && q.User_id == u_id && q.Type == mongoWatching.Type select q).ToList();
                        if (watch.Count > 0)
                        {
                            _context.Still_Watchings.Remove(watch[0]);
                        }
                    }

                    _context.Still_Watchings.AddRange(toChange);
                    _context.SaveChanges();

                    foreach (MongoWatching mw in mongoWatchings)
                    {
                        MongoWatching query = _ws.Get(mw.User_id, mw.Media_Id, mw.Type);
                        if (query != null)
                        {
                            query.SeekPosition = mw.SeekPosition;
                            _ws.Update(query.Id, query);
                        }
                        else
                        {
                            _ws.Create(mw);
                        }
                    }

                    Vars.still_s.Clear();
                    Vars.removed.Clear();
                    Vars.still_s = Vars.still_s_temp.Where(x => true).ToList();
                    Vars.removed = Vars.removed_temp.Where(x => true).ToList();
                }
                Thread.Sleep(8000);
                // Thread.Sleep(6 * 3600000);
            }
        }
        public async Task <ActionResult <Result> > Seek([Bind("User_Id", "Media_Id", "Type", "SeekPosition")] NewSeek newSeek)
        {
            //To be used while watching, it dosent return a seek position so that it wont update the seek position if there were two persons using the same account on different devices and watching the same media

            Result res = null;

            String resultText;

            //Stopwatch t_sw = new Stopwatch();
            //t_sw.Start();
            MongoWatching query = _ws.Get(newSeek.User_Id.ToString(), newSeek.Media_Id, newSeek.Type);

            //t_sw.Stop();
            //Console.WriteLine("seek read takes: " + t_sw.ElapsedMilliseconds + " ms");
            if (query == null)
            {
                query = new MongoWatching {
                    User_id = newSeek.User_Id.ToString(), Media_Id = newSeek.Media_Id, Type = newSeek.Type, SeekPosition = newSeek.SeekPosition
                };

                //Stopwatch s_sw = new Stopwatch();
                //s_sw.Start();
                _ws.Create(query);
                //s_sw.Stop();
                //Console.WriteLine("seek create takes: " + s_sw.ElapsedMilliseconds + " ms");
                resultText = "Added";
            }
            else
            {
                if (IsCompleted(newSeek.SeekPosition, newSeek.Media_Id, newSeek.Type))
                {
                    //Stopwatch s_sw = new Stopwatch();
                    //s_sw.Start();
                    _ws.Remove(query);
                    //s_sw.Stop();
                    //Console.WriteLine("seek remove takes: " + s_sw.ElapsedMilliseconds + " ms");
                    resultText = "Completed";
                }
                else
                {
                    query.SeekPosition = newSeek.SeekPosition;
                    resultText         = "Watching";
                }
            }

            return(new Result {
                Text = resultText
            });
        }
        public async Task <ActionResult <WatchingResult> > Register([Bind("User_Id", "Media_Id", "Type", "SeekPosition")] NewSeek newSeek)
        {
            String resultText;
            //Stopwatch t_sw = new Stopwatch();
            //t_sw.Start();
            MongoWatching query = _ws.Get(newSeek.User_Id.ToString(), newSeek.Media_Id, newSeek.Type);

            //t_sw.Stop();
            //Console.WriteLine("register read takes: " + t_sw.ElapsedMilliseconds + " ms");
            if (query == null)
            {
                query = new MongoWatching {
                    User_id = newSeek.User_Id.ToString(), Media_Id = newSeek.Media_Id, Type = newSeek.Type, SeekPosition = newSeek.SeekPosition
                };

                //Stopwatch s_sw = new Stopwatch();
                //s_sw.Start();
                _ws.Create(query);
                //s_sw.Stop();
                //Console.WriteLine("register create takes: " + s_sw.ElapsedMilliseconds + " ms");
                resultText = "Added";
            }
            else
            {
                if (IsCompleted(newSeek.SeekPosition, newSeek.Media_Id, newSeek.Type))
                {
                    //var q = from qu in _context.Still_Watchings where qu.User_id == newSeek.User_Id && qu.Media_Id == newSeek.Media_Id && qu.Type == newSeek.Type select qu;
                    //if (q.Count() > 0)
                    //    _context.Still_Watchings.Remove(q.SingleOrDefault());

                    //Stopwatch s_sw = new Stopwatch();
                    //s_sw.Start();
                    _ws.Remove(query);
                    //s_sw.Stop();
                    //Console.WriteLine("register remove takes: " + s_sw.ElapsedMilliseconds + " ms");
                    resultText = "Completed";
                }
                else
                {
                    resultText = "Watching";
                }
            }

            return(new WatchingResult {
                Status = resultText, Watchings = query
            });
        }
Exemplo n.º 6
0
 public void Remove(MongoWatching watchingIn) =>
 _mongoWatchings.DeleteOne(watching => watching.User_id == watchingIn.User_id && watching.Media_Id == watchingIn.Media_Id && watching.Type == watchingIn.Type);
Exemplo n.º 7
0
 public void Update(string id, MongoWatching watchingIn) =>
 _mongoWatchings.ReplaceOne(watching => watching.Id == id, watchingIn);
Exemplo n.º 8
0
 public void Update(string user_id, int media_id, int type, MongoWatching watchingIn) =>
 _mongoWatchings.ReplaceOne(watching => watching.User_id == user_id && watching.Media_Id == media_id && watching.Type == type, watchingIn);
Exemplo n.º 9
0
 public MongoWatching Create(MongoWatching watching)
 {
     _mongoWatchings.InsertOne(watching);
     return(watching);
 }