//
        // GET: /Home/
        public ActionResult Index()
        {
            NameValueCollection appSettings = ConfigurationManager.AppSettings;
            ViewBag.APIKey = appSettings["opentok_key"];

            OpenTokSDK opentok = new OpenTokSDK();

            string sessionId = opentok.CreateSession(Request.ServerVariables["REMOTE_ADDR"]);

            Dictionary<string, object> tokenOptions = new Dictionary<string, object>();
            tokenOptions.Add(TokenPropertyConstants.ROLE, RoleConstants.MODERATOR);
            ViewBag.Token = opentok.GenerateToken(sessionId, tokenOptions);
            return View();
        }
Esempio n. 2
0
        public ActionResult StartPitch()
        {
            //options.Add(SessionPropertyConstants.MULTIPLEXER_SWITCHTYPE, "enabled");

            Guid userId = (Guid)Membership.GetUser(Membership.GetUserNameByEmail(User.Identity.Name)).ProviderUserKey;

            var tube = Session["currentTube"] as Tube;

            tube = tubeRepository.FirstOrDefault(t => t.TubeId == tube.TubeId);

            if (!participantRepository.IsCanFindPartner(userId, tube.TubeId))
                return RedirectToAction("TubeExcluded", "Tube", new { tubeId = tube.TubeId });

            int countPairs = participantRepository.CountPairsInTube(tube.TubeId);

            //Tube tubeWasChanged = HttpContext.Cache.Get("TubeChanged") == null ? null : (Tube)HttpContext.Cache["TubeChanged"];

            //if (tubeWasChanged == null)
            //{
            //    if ((int)tube.TubeMode == countPairs)
            //        tube.TubeMode = TubeMode.Nominations;
            //    else
            //        tube.TubeMode = (TubeMode)Enum.ToObject(typeof(TubeMode), mode);

            //    tubeRepository.Update(tube);
            //    HttpContext.Cache["TubeChanged"] = tube;
            //    Session["currentTube"] = tube;
            //}
            //else if (tube.TubeMode != tubeWasChanged.TubeMode && tube.TubeId == tubeWasChanged.TubeId)
            //{
            //    if ((int)tube.TubeMode == countPairs)
            //        tube.TubeMode = TubeMode.Nominations;
            //    else
            //        tube.TubeMode = (TubeMode)Enum.ToObject(typeof(TubeMode), mode); ;

            //    tubeRepository.Update(tube);
            //    Session["currentTube"] = tube;
            //}

            //if ((int)HttpContext.Application[tube.TubeId.ToString()] == countPairs * 2)
            //    HttpContext.Application[tube.TubeId.ToString()] = 0;

            ////----stub---
            //if (tube.TubeMode == TubeMode.Opened && countPairs != 5)
            //    participantRepository.DeleteFromTubeSingleUsers(tube.TubeId);
            ////-----------

            //if((int)HttpContext.Application[tube.TubeId.ToString()] == 0)
            //{
            //    if ((int)tube.TubeMode == countPairs)
            //        tube.TubeMode = TubeMode.Nominations;
            //    else
            //        tube.TubeMode += 1;

            //    tubeRepository.Update(tube);
            //}
            //HttpContext.Application[tube.TubeId.ToString()] = (int) HttpContext.Application[tube.TubeId.ToString()] + 1;

            int roundNumber = (int)tube.TubeMode;

            if ((int)tube.TubeMode > countPairs)
            {
                SetTubeMode((int)TubeMode.Nominations);

                if(User.IsInRole("Investor"))
                    return RedirectToAction("Nomination", new { tubeId = tube.TubeId });
                else
                    return RedirectToAction("Results", new { tubeId = tube.TubeId });
            }

            Participant currentParticipant = participantRepository.FindPartner(userId, tube.TubeId, roundNumber);

            string sessionId = HttpContext.Cache[userId.ToString()] == null ? null : HttpContext.Cache[userId.ToString()].ToString();

            if (sessionId == null)
            {
                OpenTokSDK opentok = new OpenTokSDK();
                Dictionary<string, object> options = new Dictionary<string, object>();
                options.Add(SessionPropertyConstants.P2P_PREFERENCE, "enabled");
                sessionId = opentok.CreateSession("::1");
                HttpContext.Cache[currentParticipant.UserId.ToString()] = sessionId;
            }

            NameValueCollection appSettings = ConfigurationManager.AppSettings;

            ViewData["apiKey"] = appSettings["opentok_key"];
            ViewData["sessionId"] = sessionId;

            UserInfo partnerModel = new UserInfo
            {
                UserId = currentParticipant.UserId,
                Name = currentParticipant.aspnet_Users.UserName,
                Description = currentParticipant.Description,
                AvatarPath = personRepository.FirstOrDefault(x => x.UserId == currentParticipant.UserId).AvatarPath,
                Role = User.IsInRole("Entrepreneur") ? "Investor" : "Entrepreneur"//currentParticipant.aspnet_Users.aspnet_Roles.FirstOrDefault().RoleName
            };

            List<UserInfo> currentPairsModel = Util.ConverUserDataListToUserModelList(participantRepository.FindCurrentPairs(userId,currentParticipant.UserId, tube.TubeId, roundNumber));

            partnerRepository.Insert(new Partner
                                            {
                                                UserId = userId,
                                                PartnerId = currentParticipant.UserId,
                                            });

            //ViewBag setup
            ViewBag.History = Util.ConverUserDataListToUserModelList(partnerRepository.History(userId, currentParticipant.UserId, tube.TubeId));

            ViewBag.CurrentPairs = currentPairsModel;

            ViewBag.CurrentPartner = partnerModel;

            ViewBag.TubeId = tube.TubeId;
            ViewBag.NextMode = roundNumber + 1;

            return View();
        }