Exemple #1
0
 public void SetRetracted()
 {
     if (this.VoteState == VoteState.Active)
     {
         this.VoteState = VoteState.Retracted;
     }
 }
Exemple #2
0
        internal bool CanVote()
        {
            bool Return;

            switch (State)
            {
            case VoteState.None:
            default:
                return(true);

            case VoteState.InProgress:
            case VoteState.Fail:
            case VoteState.Captcha:

                Return = (DateTime.Now - StateTime).TotalMinutes > 5;
                break;

            case VoteState.Success:
                Return = (DateTime.Now - StateTime).TotalHours > 24;
                break;

            case VoteState.Wait:
                Return = (DateTime.Now - StateTime).TotalHours > 1;
                break;
            }

            if (Return && State != VoteState.None)
            {
                State     = VoteState.None;
                StateTime = DateTime.Now;
            }
            return(Return);
        }
Exemple #3
0
        private EventsViewModel Vote(int Id, VoteState newVote)
        {
            var currEvent = this.Data
                            .Events
                            .All()
                            .FirstOrDefault(a => a.Id == Id);

            var vote = this.GetUserVote(currEvent);

            if (vote != null && vote.State == newVote)
            {
                return(this.Data
                       .Events
                       .All()
                       .Where(a => a.Id == Id)
                       .Project().To <EventsViewModel>()
                       .FirstOrDefault());
            }

            if (vote != null && vote.State != newVote)
            {
                currEvent.Votes.Remove(vote);
            }

            var voteModel = this.AddVote(currEvent, newVote);

            return(voteModel);
        }
Exemple #4
0
        internal bool CanVote()
        {
            bool Return;

            switch (State)
            {
                case VoteState.None:
                default:
                    return true;

                case VoteState.InProgress:
                case VoteState.Fail:
                case VoteState.Captcha:

                    Return = (DateTime.Now - StateTime).TotalMinutes > 5;
                    break;

                case VoteState.Success:
                    Return = (DateTime.Now - StateTime).TotalHours > 24;
                    break;

                case VoteState.Wait:
                    Return = (DateTime.Now - StateTime).TotalHours > 1;
                    break;
            }

            if (Return && State != VoteState.None)
            {
                State = VoteState.None;
                StateTime = DateTime.Now;
            }
            return Return;
        }
Exemple #5
0
    /**
     * Démarrage de la phase de rythme
     */
    public void StartVoteState()
    {
        state = RoundState.Vote;
        VoteState.MakeVoteState(this, game);

        gameObject.GetComponent <AudioSource> ().clip = machineStop;
        gameObject.GetComponent <AudioSource> ().Play();
    }
Exemple #6
0
 private VoteState VoteState()
 {
     if (_voteState == null)
     {
         _voteState = _voteStorage.InitialState;
     }
     return(_voteState);
 }
Exemple #7
0
 public CommentVoteRequest(Comment comment, VoteState vote)
     : base(comment)
 {
     if (vote != VoteState.Down && vote != VoteState.Up)
     {
         throw new ArgumentOutOfRangeException(nameof(vote));
     }
     Vote = vote;
 }
Exemple #8
0
 private TagRequest(TagCollection collection, string tags, VoteState vote)
     : base(collection.Owner)
 {
     this.Vote = vote;
     if (tags.Length >= 200)
     {
         throw new ArgumentException(LocalizedStrings.Resources.TagsTooLong, nameof(tags));
     }
     this.Tags = tags;
 }
Exemple #9
0
 public Player(string name, Profile profile)
 {
     this.name    = name;
     this.profile = profile;
     this.vices   = new int[40];
     // when a player is created, it means the player just connected
     this.is_connected = true;
     this.is_alive     = false;
     this.vote         = VoteState.NOTHING;
 }
Exemple #10
0
        public override IEnumerable <VoteState> GetVotes(IEnumerable <Transaction> others)
        {
            VoteState vs = new VoteState()
            {
                Count = Fixed8.FromDecimal(1), PublicKeys = TestUtils.StandbyValidators
            };

            return(new VoteState[]
            {
                vs
            });
        }
Exemple #11
0
	/**
	 * Créer une voteState
	 */
	public static VoteState MakeVoteState(Round round, ExecGame game) {
		bool voteStarted = false;
		if (voteStarted == false) {
		
			GameObject go = new GameObject ("VoteState");
			vs = go.AddComponent<VoteState> ();
			vs.transform.SetParent (round.transform);
		
			vs.round = round;
			vs.game = game;

			voteStarted = true;
		}
		return vs;
	}
Exemple #12
0
    /**
     * Créer une voteState
     */
    public static VoteState MakeVoteState(Round round, ExecGame game)
    {
        bool voteStarted = false;

        if (voteStarted == false)
        {
            GameObject go = new GameObject("VoteState");
            vs = go.AddComponent <VoteState> ();
            vs.transform.SetParent(round.transform);

            vs.round = round;
            vs.game  = game;

            voteStarted = true;
        }
        return(vs);
    }
Exemple #13
0
        private ArticlesViewModel AddVote(Article currArticle, VoteState state)
        {
            if (currArticle == null)
            {
                ModelState.AddModelError("ArticleId", "Article not founed!");
            }

            var uId = this.User.Identity.GetUserId();

            var vote = new Vote()
            {
                State  = state,
                UserId = this.User.Identity.GetUserId()
            };

            currArticle.Votes.Add(vote);
            this.Data.SaveChanges();

            var upsCount   = currArticle.Votes.Where(v => v.State == VoteState.Up).Count();
            var downsCount = currArticle.Votes.Where(v => v.State == VoteState.Down).Count();

            var newVoteModel = new VotesViewModel()
            {
                Ups   = upsCount,
                Downs = downsCount
            };

            //Mapper.CreateMap<Article, ArticlesViewModel>()
            //    .ForMember(a => a.Ups, opt => opt.MapFrom(u => u.Votes.Where(v => v.State == VoteState.Up).Count()));

            //Mapper.CreateMap<Article, ArticlesViewModel>()
            //    .ForMember(a => a.Downs, opt => opt.MapFrom(u => u.Votes.Where(v => v.State == VoteState.Down).Count()));


            var article = this.Data
                          .Articles
                          .All()
                          .Where(a => a.Id == currArticle.Id)
                          .Project().To <ArticlesViewModel>()
                          .FirstOrDefault();

            return(article);
        }
Exemple #14
0
        public long Vote(long postId, VoteState voteState)
        {
            if (!this.PostExists(postId))
            {
                throw new ApiException(x => x.BadRequestResult(
                                           (ErrorCode.Parse(ErrorCodeType.PropertyInvalidData, OctopostEntityName.Post, PropertyName.Post.Id),
                                            new ErrorDefinition(postId, "Post does not exist", PropertyName.Post.Id))));
            }

            using (var unitOfWork = this.unitOfWorkFactory.CreateUnitOfWork())
            {
                var voteRepo = unitOfWork.CreateEntityRepository <Vote>();
                var vote     = new Vote
                {
                    PostId = postId,
                    State  = voteState
                };
                voteRepo.Create(vote);
                unitOfWork.Save();
                return(vote.Id);
            }
        }
Exemple #15
0
        private EventsViewModel AddVote(Event currEvent, VoteState state)
        {
            if (currEvent == null)
            {
                ModelState.AddModelError("ArticleId", "Article not founed!");
            }

            var uId = this.User.Identity.GetUserId();

            var vote = new Vote()
            {
                State  = state,
                UserId = this.User.Identity.GetUserId()
            };

            currEvent.Votes.Add(vote);
            this.Data.SaveChanges();

            var upsCount   = currEvent.Votes.Where(v => v.State == VoteState.Up).Count();
            var downsCount = currEvent.Votes.Where(v => v.State == VoteState.Down).Count();

            var newVoteModel = new VotesViewModel()
            {
                Ups   = upsCount,
                Downs = downsCount
            };

            var eventt = this.Data
                         .Events
                         .All()
                         .Where(a => a.Id == currEvent.Id)
                         .Project().To <EventsViewModel>()
                         .FirstOrDefault();

            return(eventt);
        }
Exemple #16
0
 public void SetVoted(VoteState voted)
 {
     collab.Voted = voted;
     RaisePropertyChanged("Voted");
 }
Exemple #17
0
 public void Connected()
 {
     this.is_connected = true;
     this.vote         = VoteState.NOTHING;
 }
Exemple #18
0
 public GameState(VoteState voteState)
 {
     this.voteState = voteState;
     players        = new List <Player>();
 }
Exemple #19
0
        public void ClientRead(IReadMessage inc)
        {
            AllowSubVoting = inc.ReadBoolean();
            if (allowSubVoting)
            {
                UpdateVoteTexts(null, VoteType.Sub);
                int votableCount = inc.ReadByte();
                for (int i = 0; i < votableCount; i++)
                {
                    int    votes   = inc.ReadByte();
                    string subName = inc.ReadString();
                    List <SubmarineInfo> serversubs = new List <SubmarineInfo>();
                    foreach (GUIComponent item in GameMain.NetLobbyScreen?.SubList?.Content?.Children)
                    {
                        if (item.UserData != null && item.UserData is SubmarineInfo)
                        {
                            serversubs.Add(item.UserData as SubmarineInfo);
                        }
                    }
                    SubmarineInfo sub = serversubs.FirstOrDefault(s => s.Name == subName);
                    SetVoteText(GameMain.NetLobbyScreen.SubList, sub, votes);
                }
            }
            AllowModeVoting = inc.ReadBoolean();
            if (allowModeVoting)
            {
                UpdateVoteTexts(null, VoteType.Mode);
                int votableCount = inc.ReadByte();
                for (int i = 0; i < votableCount; i++)
                {
                    int            votes          = inc.ReadByte();
                    string         modeIdentifier = inc.ReadString();
                    GameModePreset mode           = GameModePreset.List.Find(m => m.Identifier == modeIdentifier);
                    SetVoteText(GameMain.NetLobbyScreen.ModeList, mode, votes);
                }
            }
            AllowEndVoting = inc.ReadBoolean();
            if (AllowEndVoting)
            {
                GameMain.NetworkMember.EndVoteCount = inc.ReadByte();
                GameMain.NetworkMember.EndVoteMax   = inc.ReadByte();
            }
            AllowVoteKick = inc.ReadBoolean();

            byte      subVoteStateByte = inc.ReadByte();
            VoteState subVoteState     = VoteState.None;

            try
            {
                subVoteState = (VoteState)subVoteStateByte;
            }
            catch (System.Exception e)
            {
                DebugConsole.ThrowError("Failed to cast vote type \"" + subVoteStateByte + "\"", e);
            }

            if (subVoteState != VoteState.None)
            {
                byte     voteTypeByte = inc.ReadByte();
                VoteType voteType     = VoteType.Unknown;

                try
                {
                    voteType = (VoteType)voteTypeByte;
                }
                catch (System.Exception e)
                {
                    DebugConsole.ThrowError("Failed to cast vote type \"" + voteTypeByte + "\"", e);
                }

                if (voteType != VoteType.Unknown)
                {
                    byte yesClientCount = inc.ReadByte();
                    for (int i = 0; i < yesClientCount; i++)
                    {
                        byte clientID       = inc.ReadByte();
                        var  matchingClient = GameMain.NetworkMember.ConnectedClients.Find(c => c.ID == clientID);
                        matchingClient?.SetVote(voteType, 2);
                    }

                    byte noClientCount = inc.ReadByte();
                    for (int i = 0; i < noClientCount; i++)
                    {
                        byte clientID       = inc.ReadByte();
                        var  matchingClient = GameMain.NetworkMember.ConnectedClients.Find(c => c.ID == clientID);
                        matchingClient?.SetVote(voteType, 1);
                    }

                    GameMain.NetworkMember.SubmarineVoteYesCount = yesClientCount;
                    GameMain.NetworkMember.SubmarineVoteNoCount  = noClientCount;
                    GameMain.NetworkMember.SubmarineVoteMax      = inc.ReadByte();

                    switch (subVoteState)
                    {
                    case VoteState.Started:
                        Client myClient = GameMain.NetworkMember.ConnectedClients.Find(c => c.ID == GameMain.Client.ID);
                        if (!myClient.InGame)
                        {
                            VoteRunning = true;
                            return;
                        }

                        string        subName1 = inc.ReadString();
                        SubmarineInfo info     = GameMain.Client.ServerSubmarines.FirstOrDefault(s => s.Name == subName1);

                        if (info == null)
                        {
                            DebugConsole.ThrowError("Failed to find a matching submarine, vote aborted");
                            return;
                        }

                        VoteRunning = true;
                        byte   starterID     = inc.ReadByte();
                        Client starterClient = GameMain.NetworkMember.ConnectedClients.Find(c => c.ID == starterID);
                        float  timeOut       = inc.ReadByte();
                        GameMain.Client.ShowSubmarineChangeVoteInterface(starterClient, info, voteType, timeOut);
                        break;

                    case VoteState.Running:
                        // Nothing specific
                        break;

                    case VoteState.Passed:
                    case VoteState.Failed:
                        VoteRunning = false;

                        bool          passed   = inc.ReadBoolean();
                        string        subName2 = inc.ReadString();
                        SubmarineInfo subInfo  = GameMain.Client.ServerSubmarines.FirstOrDefault(s => s.Name == subName2);

                        if (subInfo == null)
                        {
                            DebugConsole.ThrowError("Failed to find a matching submarine, vote aborted");
                            return;
                        }

                        if (GameMain.Client.VotingInterface != null)
                        {
                            GameMain.Client.VotingInterface.EndVote(passed, yesClientCount, noClientCount);
                        }
                        else if (GameMain.Client.ConnectedClients.Count > 1)
                        {
                            GameMain.NetworkMember.AddChatMessage(VotingInterface.GetSubmarineVoteResultMessage(subInfo, voteType, yesClientCount.ToString(), noClientCount.ToString(), passed), ChatMessageType.Server);
                        }

                        if (passed)
                        {
                            int deliveryFee = inc.ReadInt16();
                            switch (voteType)
                            {
                            case VoteType.PurchaseAndSwitchSub:
                                GameMain.GameSession.PurchaseSubmarine(subInfo);
                                GameMain.GameSession.SwitchSubmarine(subInfo, 0);
                                break;

                            case VoteType.PurchaseSub:
                                GameMain.GameSession.PurchaseSubmarine(subInfo);
                                break;

                            case VoteType.SwitchSub:
                                GameMain.GameSession.SwitchSubmarine(subInfo, deliveryFee);
                                break;
                            }

                            SubmarineSelection.ContentRefreshRequired = true;
                        }
                        break;
                    }
                }
            }

            GameMain.NetworkMember.ConnectedClients.ForEach(c => c.SetVote(VoteType.StartRound, false));
            byte readyClientCount = inc.ReadByte();

            for (int i = 0; i < readyClientCount; i++)
            {
                byte clientID       = inc.ReadByte();
                var  matchingClient = GameMain.NetworkMember.ConnectedClients.Find(c => c.ID == clientID);
                matchingClient?.SetVote(VoteType.StartRound, true);
            }
            UpdateVoteTexts(GameMain.NetworkMember.ConnectedClients, VoteType.StartRound);

            inc.ReadPadBits();
        }
Exemple #20
0
 internal void Fail()
 {
     State     = VoteState.Fail;
     StateTime = DateTime.Now;
 }
Exemple #21
0
 internal VoteIP(DateTime time, VoteState state = VoteState.None)
 {
     State     = state;
     StateTime = time;
 }
Exemple #22
0
 public static string ToValString(this VoteState state)
 => StateVals[state];
Exemple #23
0
 public VoteHub(VoteState voteState)
 {
     this.voteState = voteState;
 }
Exemple #24
0
        public async Task <CommentResponse> ManageCommentVote(int commentId, int userId, int foodId, VoteState voteState)
        {
            var commentVotes = await _mouthfeel.CommentVotes.ToListAsync();

            var comments = await GetCommentsByFood(foodId, userId);

            var foodExists = await _foods.FoodExists(foodId);

            if (!foodExists)
            {
                throw new ErrorResponse(HttpStatusCode.NotFound, ErrorMessages.FoodNotFound, DescriptiveErrorCodes.FoodNotFound);
            }

            var userExists = await _users.UserExists(userId);

            if (!userExists)
            {
                throw new ErrorResponse(HttpStatusCode.BadRequest, ErrorMessages.UserNotFound, DescriptiveErrorCodes.UserNotFound);
            }

            if (!comments.Any(c => c.Id == commentId))
            {
                throw new ErrorResponse(HttpStatusCode.BadRequest, ErrorMessages.CommentDoesNotExist, DescriptiveErrorCodes.CommentDoesNotExist);
            }

            var existingVoteByUser = commentVotes.FirstOrDefault(v => v.CommentId == commentId && v.UserId == userId);
            var newVote            = new CommentVote {
                CommentId = commentId, UserId = userId, Vote = (int)voteState
            };

            if (existingVoteByUser != null)
            {
                if (voteState == VoteState.Neutral)
                {
                    _mouthfeel.CommentVotes.Remove(existingVoteByUser);
                }
                else
                {
                    existingVoteByUser.Vote = (int)voteState;
                }
            }

            else
            {
                _mouthfeel.CommentVotes.Add(newVote);
            }

            await _mouthfeel.SaveChangesAsync();

            return((await GetCommentsByFood(foodId, userId)).FirstOrDefault(c => c.Id == commentId));
        }
Exemple #25
0
 public void TestSetup()
 {
     uut = new VoteState();
 }
Exemple #26
0
 public int VoteValue(VoteState vote)
 {
     return(vote == VoteState.plus ? 1 : -1);
 }
Exemple #27
0
 internal void Fail()
 {
     State = VoteState.Fail;
     StateTime = DateTime.Now;
 }
Exemple #28
0
 public void DisableVoting()
 {
     VoteState = VoteState.Disabled;
 }
Exemple #29
0
 public TagRequest(TagCollection collection, IEnumerable <Tag> tags, VoteState vote)
     : this(collection, string.Join(",", tags), vote)
 {
 }
Exemple #30
0
 private void UpdateMotionState(VoteState state)
 {
     SelectedMotion.State = state;
     motionsDataGrid.Rows[_SelectedMotion].Cells[5].Value = state.ToValString();
 }
Exemple #31
0
 internal VoteIP(DateTime time, VoteState state = VoteState.None)
 {
     State = state;
     StateTime = time;
 }
Exemple #32
0
 public void Disconnected()
 {
     this.is_connected = false;
     this.vote         = VoteState.OFFLINE;
 }
Exemple #33
0
 public TagRequest(TagCollection collection, Tag tag, VoteState vote)
     : this(collection, tag.ToString(), vote)
 {
 }
Exemple #34
0
 public void EnableVoting()
 {
     VoteState = VoteState.Enabled;
 }