public static Poll ToEntity(this PollModel model, Poll destination) { return(Mapper.Map(model, destination)); }
public static Poll ToEntity(this PollModel model) { return(model.MapTo <PollModel, Poll>()); }
public static Poll ToEntity(this PollModel model, Poll destination) { return model.MapTo(destination); }
public static Poll ToEntity(this PollModel model) { return(Mapper.Map <PollModel, Poll>(model)); }
public static AnalysePollData GetAnalizedPollDataModel(long ownerid, string ownerType, long pollId) { poll pollMaster = EntityConnectionService.Poll.GetSingle(x => x.pollid.Equals(pollId) && x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType)); if (pollMaster == null) { return(null); } Stopwatch analyseStopwatch = new Stopwatch(); analyseStopwatch.Start(); List <question> questionList = EntityConnectionService.Question.GetList( x => x.pollid.Equals(pollId) && x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType)).ToList(); PollModel poll = new PollModel(); poll.PollId = pollMaster.pollid; poll.PollTitle = pollMaster.polltitle; poll.Questions = new List <Question>(); poll.Fields = pollMaster.fielddata; poll.Active = pollMaster.active; for (int i = 0; i < questionList.Count; i++) { Question localQuestion = new Question { Content = questionList[i].content, QuestionId = questionList[i].questionid, QuestionType = questionList[i].questiontype, Answers = new List <Answer>() }; localQuestion.VoteCount = EntityConnectionService.GuestAnswer.GetDataCount( x => x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType) && x.pollid.Equals(pollId) && x.questionid.Equals(localQuestion.QuestionId)); List <answer> answerList = EntityConnectionService.Answer.GetList( x => x.pollid.Equals(pollId) && x.questionid.Equals(localQuestion.QuestionId) && x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType)).ToList(); for (int j = 0; j < answerList.Count; j++) { Answer localAnswer = new Answer { AnswerId = answerList[j].answerid, Content = answerList[j].content, AnswerType = answerList[j].answertype }; localAnswer.VoteCount = EntityConnectionService.GuestAnswer.GetDataCount( x => x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType) && x.answerid.Equals(localAnswer.AnswerId) && x.questionid.Equals(localQuestion.QuestionId)); localQuestion.Answers.Add(localAnswer); } poll.Questions.Add(localQuestion); } AnalysePollData analysePoll = new AnalysePollData(); analysePoll.GuestAnswers = new List <GuestAnswer>(); var guestAnswerList = EntityConnectionService.GuestAnswer.GetList( x => x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType) && x.pollid.Equals(pollId)); for (int i = 0; i < guestAnswerList.Count; i++) { analysePoll.GuestAnswers.Add(new GuestAnswer() { GuestId = guestAnswerList[i].guestid, AnswerId = guestAnswerList[i].answerid, QuestionId = guestAnswerList[i].questionid, }); } analysePoll.Poll = poll; analysePoll.GuestList = EntityConnectionService.Guest.GetDataPart( x => x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType) && x.pollid.Equals(pollId), x => new { x.guestid, x.fielddata, x.crdat, x.crtim, x.complatesecond }, x => new { x.crdat, x.crtim }).ToList(); int totalComplateSecond = 0; foreach (var guest in analysePoll.GuestList) { if (!string.IsNullOrEmpty(guest.complatesecond.ToString())) { totalComplateSecond += int.Parse(guest.complatesecond.ToString()); } } if (analysePoll.GuestList.Count > 0) { TimeSpan avarageTime = TimeSpan.FromSeconds(totalComplateSecond / analysePoll.GuestList.Count); analysePoll.AvarageComplateTime = new DateTime(avarageTime.Ticks).ToStringHhmmss(); analysePoll.AvarageComplateSeconds = (totalComplateSecond / analysePoll.GuestList.Count).ToString(); analysePoll.TotalComplate = analysePoll.GuestList.Count.ToString(); analysePoll.TotalView = pollMaster.viewcount.ToString(); analysePoll.AnalyseDateTime = DateTime.Now.ToStringYyyyMMddHhmmss(); } else { analysePoll.AvarageComplateTime = "000000"; analysePoll.AvarageComplateSeconds = "0"; analysePoll.TotalComplate = "0"; analysePoll.TotalView = "0"; analysePoll.AnalyseDateTime = DateTime.Now.ToStringYyyyMMddHhmmss(); } analyseStopwatch.Stop(); analysePoll.AnalyseTime = string.Format("{0}:{1}:{2}.{3}", analyseStopwatch.Elapsed.Hours, analyseStopwatch.Elapsed.Minutes, analyseStopwatch.Elapsed.Seconds, analyseStopwatch.Elapsed.Milliseconds); Log.Info(string.Format("Analyse Time :{0}", analysePoll.AnalyseTime)); return(analysePoll); }
public static string AddPoll(long ownerid, string ownerType, long crusr, string isPrivate, string isIpCheck, string isCookieCheck, string isPassword, string password, string fieldData, string isShowResult, PollModel poll) { poll newPoll = new poll { ownertype = ownerType, ownerid = ownerid, polltitle = poll.PollTitle, crusr = crusr, isprivate = isPrivate, isipcheck = isIpCheck, iscookiecheck = isCookieCheck, ispassword = isPassword, password = password, fielddata = fieldData, isshowresult = isShowResult, active = "X", viewcount = 0 }; List <answer> pollAnswers = new List <answer>(); if (EntityConnectionService.Poll.Add(newPoll)) { for (int i = 0; i < poll.Questions.Count; i++) { question addQuestion = new question { ownerid = ownerid, ownertype = ownerType, pollid = newPoll.pollid, questionid = poll.Questions[i].QuestionId, content = poll.Questions[i].Content, questiontype = poll.Questions[i].QuestionType, }; EntityConnectionService.Question.Add(addQuestion); for (int j = 0; j < poll.Questions[i].Answers.Count; j++) { pollAnswers.Add(new answer { ownerid = ownerid, ownertype = ownerType, pollid = newPoll.pollid, questionid = addQuestion.questionid, content = poll.Questions[i].Answers[j].Content, answertype = poll.Questions[i].Answers[j].AnswerType }); } EntityConnectionService.Answer.Add(pollAnswers.ToArray()); pollAnswers = new List <answer>(); } return(Helper.GetResult(true, newPoll.pollid)); } return(Helper.GetResult(false, "0x0010")); }
public static int GetBarLength(this PollModel poll, Guid answerId, int controlWidth) { var percentage = poll.GetPercentage(answerId); return(percentage * controlWidth / 100); }
public IActionResult Index(PollModel model) { var polls = _pollStorage.Search(model.Name, model.Text, model.Options); return(Ok(polls)); }
protected override async Task PerformInternal(CommandParametersModel parameters) { if (this.ActionType == TwitchActionType.Host) { string channelName = await ReplaceStringWithSpecialModifiers(this.Username, parameters); await ChannelSession.Services.Chat.SendMessage("/host @" + channelName, sendAsStreamer : true, platform : StreamingPlatformTypeEnum.Twitch); } else if (this.ActionType == TwitchActionType.Raid) { string channelName = await ReplaceStringWithSpecialModifiers(this.Username, parameters); await ChannelSession.Services.Chat.SendMessage("/raid @" + channelName, sendAsStreamer : true, platform : StreamingPlatformTypeEnum.Twitch); } else if (this.ActionType == TwitchActionType.RunAd) { AdResponseModel response = await ChannelSession.TwitchUserConnection.RunAd(ChannelSession.TwitchUserNewAPI, this.AdLength); if (response == null) { await ChannelSession.Services.Chat.SendMessage("ERROR: We were unable to run an ad, please try again later"); } else if (!string.IsNullOrEmpty(response.message) && !response.message.Contains(StartinCommercialBreakMessage, System.StringComparison.OrdinalIgnoreCase)) { await ChannelSession.Services.Chat.SendMessage("ERROR: " + response.message); } } else if (this.ActionType == TwitchActionType.VIPUser || this.ActionType == TwitchActionType.UnVIPUser) { string targetUsername = null; if (!string.IsNullOrEmpty(this.Username)) { targetUsername = await ReplaceStringWithSpecialModifiers(this.Username, parameters); } else { targetUsername = parameters.User.TwitchUsername; } if (targetUsername != null) { if (this.ActionType == TwitchActionType.VIPUser) { await ChannelSession.Services.Chat.SendMessage("/vip @" + targetUsername, sendAsStreamer : true, platform : StreamingPlatformTypeEnum.Twitch); } else if (this.ActionType == TwitchActionType.UnVIPUser) { await ChannelSession.Services.Chat.SendMessage("/unvip @" + targetUsername, sendAsStreamer : true, platform : StreamingPlatformTypeEnum.Twitch); } } } else if (this.ActionType == TwitchActionType.Clip) { ClipCreationModel clipCreation = await ChannelSession.TwitchUserConnection.CreateClip(ChannelSession.TwitchUserNewAPI, this.ClipIncludeDelay); if (clipCreation != null) { for (int i = 0; i < 12; i++) { await Task.Delay(5000); ClipModel clip = await ChannelSession.TwitchUserConnection.GetClip(clipCreation); if (clip != null && !string.IsNullOrEmpty(clip.url)) { if (this.ShowInfoInChat) { await ChannelSession.Services.Chat.SendMessage(string.Format(MixItUp.Base.Resources.ClipCreatedMessage, clip.url)); } parameters.SpecialIdentifiers[ClipURLSpecialIdentifier] = clip.url; GlobalEvents.TwitchClipCreated(clip); return; } } } await ChannelSession.Services.Chat.SendMessage(MixItUp.Base.Resources.ClipCreationFailed); } else if (this.ActionType == TwitchActionType.StreamMarker) { string description = await ReplaceStringWithSpecialModifiers(this.StreamMarkerDescription, parameters); if (!string.IsNullOrEmpty(description) && description.Length > TwitchActionModel.StreamMarkerMaxDescriptionLength) { description = description.Substring(0, TwitchActionModel.StreamMarkerMaxDescriptionLength); } CreatedStreamMarkerModel streamMarker = await ChannelSession.TwitchUserConnection.CreateStreamMarker(ChannelSession.TwitchUserNewAPI, description); if (streamMarker != null) { if (this.ShowInfoInChat) { await ChannelSession.Services.Chat.SendMessage(string.Format(MixItUp.Base.Resources.StreamMarkerCreatedMessage, streamMarker.URL)); } parameters.SpecialIdentifiers[StreamMarkerURLSpecialIdentifier] = streamMarker.URL; return; } await ChannelSession.Services.Chat.SendMessage(MixItUp.Base.Resources.StreamMarkerCreationFailed); } else if (this.ActionType == TwitchActionType.UpdateChannelPointReward) { JObject jobj = new JObject() { { "is_enabled", this.ChannelPointRewardState }, }; #pragma warning disable CS0612 // Type or member is obsolete if (this.ChannelPointRewardCost >= 0) { this.ChannelPointRewardCostString = this.ChannelPointRewardCost.ToString(); this.ChannelPointRewardMaxPerStreamString = this.ChannelPointRewardMaxPerStream.ToString(); this.ChannelPointRewardMaxPerUserString = this.ChannelPointRewardMaxPerUser.ToString(); this.ChannelPointRewardGlobalCooldownString = this.ChannelPointRewardGlobalCooldown.ToString(); this.ChannelPointRewardCost = -1; this.ChannelPointRewardMaxPerStream = -1; this.ChannelPointRewardMaxPerUser = -1; this.ChannelPointRewardGlobalCooldown = -1; } #pragma warning restore CS0612 // Type or member is obsolete int.TryParse(await ReplaceStringWithSpecialModifiers(this.ChannelPointRewardCostString, parameters), out int cost); if (cost > 0) { jobj["cost"] = cost; } if (this.ChannelPointRewardUpdateCooldownsAndLimits) { int.TryParse(await ReplaceStringWithSpecialModifiers(this.ChannelPointRewardMaxPerStreamString, parameters), out int maxPerStream); if (maxPerStream > 0) { jobj["max_per_stream_setting"] = new JObject() { { "is_enabled", true }, { "max_per_stream", maxPerStream } }; } else { jobj["max_per_stream_setting"] = new JObject() { { "is_enabled", false }, }; } int.TryParse(await ReplaceStringWithSpecialModifiers(this.ChannelPointRewardMaxPerUserString, parameters), out int maxPerUser); if (maxPerUser > 0) { jobj["max_per_user_per_stream_setting"] = new JObject() { { "is_enabled", true }, { "max_per_user_per_stream", maxPerUser } }; } else { jobj["max_per_user_per_stream_setting"] = new JObject() { { "is_enabled", false }, }; } int.TryParse(await ReplaceStringWithSpecialModifiers(this.ChannelPointRewardGlobalCooldownString, parameters), out int globalCooldown); if (globalCooldown > 0) { jobj["global_cooldown_setting"] = new JObject() { { "is_enabled", true }, { "global_cooldown_seconds", globalCooldown * 60 } }; } else { jobj["global_cooldown_setting"] = new JObject() { { "is_enabled", false }, }; } } CustomChannelPointRewardModel reward = await ChannelSession.TwitchUserConnection.UpdateCustomChannelPointReward(ChannelSession.TwitchUserNewAPI, this.ChannelPointRewardID, jobj); if (reward == null) { await ChannelSession.Services.Chat.SendMessage(MixItUp.Base.Resources.TwitchActionChannelPointRewardCouldNotBeUpdated); } } else if (this.ActionType == TwitchActionType.CreatePoll) { List <CreatePollChoiceModel> choices = new List <CreatePollChoiceModel>(); foreach (string choice in this.PollChoices) { choices.Add(new CreatePollChoiceModel() { title = await ReplaceStringWithSpecialModifiers(choice, parameters) }); } PollModel poll = await ChannelSession.TwitchUserConnection.CreatePoll(new CreatePollModel() { broadcaster_id = ChannelSession.TwitchUserNewAPI.id, title = await ReplaceStringWithSpecialModifiers(this.PollTitle, parameters), duration = this.PollDurationSeconds, channel_points_voting_enabled = this.PollChannelPointsCost > 0, channel_points_per_vote = this.PollChannelPointsCost, bits_voting_enabled = this.PollBitsCost > 0, bits_per_vote = this.PollBitsCost, choices = choices }); if (poll == null) { await ChannelSession.Services.Chat.SendMessage(MixItUp.Base.Resources.TwitchPollFailedToCreate); return; } if (this.Actions.Count > 0) { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed AsyncRunner.RunAsyncBackground(async(cancellationToken) => { await Task.Delay(1000 * (this.PollDurationSeconds + 2)); for (int i = 0; i < 5; i++) { PollModel results = await ChannelSession.TwitchUserConnection.GetPoll(ChannelSession.TwitchUserNewAPI, poll.id); if (results != null) { if (string.Equals(results.status, "COMPLETED", StringComparison.OrdinalIgnoreCase)) { int maxVotes = results.choices.Max(c => c.votes); IEnumerable <PollChoiceModel> winningChoices = results.choices.Where(c => c.votes == maxVotes); parameters.SpecialIdentifiers[PollChoiceSpecialIdentifier] = string.Join(" & ", winningChoices.Select(c => c.title)); await ChannelSession.Services.Command.RunDirectly(new CommandInstanceModel(this.Actions, parameters)); return; } else if (!string.Equals(results.status, "ACTIVE", StringComparison.OrdinalIgnoreCase)) { return; } } await Task.Delay(2000); } await ChannelSession.Services.Chat.SendMessage(MixItUp.Base.Resources.TwitchPollFailedToGetResults); }, new CancellationToken()); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } } else if (this.ActionType == TwitchActionType.CreatePrediction) { List <CreatePredictionOutcomeModel> outcomes = new List <CreatePredictionOutcomeModel>(); foreach (string outcome in this.PredictionOutcomes) { outcomes.Add(new CreatePredictionOutcomeModel() { title = await ReplaceStringWithSpecialModifiers(outcome, parameters) }); } PredictionModel prediction = await ChannelSession.TwitchUserConnection.CreatePrediction(new CreatePredictionModel() { broadcaster_id = ChannelSession.TwitchUserNewAPI.id, title = await ReplaceStringWithSpecialModifiers(this.PredictionTitle, parameters), prediction_window = this.PredictionDurationSeconds, outcomes = outcomes }); if (prediction == null) { await ChannelSession.Services.Chat.SendMessage(MixItUp.Base.Resources.TwitchPredictionFailedToCreate); return; } if (this.Actions.Count > 0) { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed AsyncRunner.RunAsyncBackground(async(cancellationToken) => { await Task.Delay(1000 * this.PredictionDurationSeconds); while (true) { await Task.Delay(10000); PredictionModel results = await ChannelSession.TwitchUserConnection.GetPrediction(ChannelSession.TwitchUserNewAPI, prediction.id); if (results != null) { if (string.Equals(results.status, "RESOLVED", StringComparison.OrdinalIgnoreCase)) { PredictionOutcomeModel outcome = results.outcomes.FirstOrDefault(o => string.Equals(o.id, results.winning_outcome_id)); parameters.SpecialIdentifiers[PredictionOutcomeSpecialIdentifier] = outcome?.title; await ChannelSession.Services.Command.RunDirectly(new CommandInstanceModel(this.Actions, parameters)); return; } else if (string.Equals(results.status, "CANCELED", StringComparison.OrdinalIgnoreCase)) { return; } } } }, new CancellationToken()); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } } }