예제 #1
0
        private void Create_Click(object sender, RoutedEventArgs e)
        {
            QuestionUser newuser = new QuestionUser();

            if (users.Count != 0)
            {
                foreach (var elem in users)
                {
                    if (Logintxt.Text == elem.Login)
                    {
                        MessageBox.Show("Login exist");
                        return;
                    }
                }
            }
            if (Passtxt.Password != RepPasstxt.Password)
            {
                MessageBox.Show(" Passwords are not match");
                return;
            }
            newuser.Login    = Logintxt.Text;
            newuser.Password = Passtxt.Password;
            users.Add(newuser);
            XmlSerializer xml = new XmlSerializer(typeof(List <QuestionUser>));

            using (TextWriter t = new StreamWriter("Users.xml"))
            {
                xml.Serialize(t, users);
            }
            this.Close();
        }
예제 #2
0
 public MainWindow(QuestionUser user)
 {
     InitializeComponent();
     AddQuestionLoad();
     Load();
     myuser = user;
 }
        /// <summary>
        /// Installs the tools.
        /// </summary>
        /// <param name="cxxwrapper">The cxx wrapper.</param>
        private void InstallTools(string cxxwrapper)
        {
            bool canInstall = QuestionUser.GetInput("this will install any third party tools using Chocolatey, elevated rights will be requested. Do you want to proceed?");

            if (canInstall)
            {
                using (var process = new Process())
                {
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.UseShellExecute        = false;
                    process.StartInfo.CreateNoWindow         = true;
                    process.StartInfo.FileName  = cxxwrapper;
                    process.StartInfo.Arguments = "/i";
                    process.Start();
                    process.WaitForExit();
                }
            }
            else
            {
                MessageDisplayBox.DisplayMessage(
                    "External tools have not been installed.",
                    "Tools will be installed when the wrapper for preview and full analysis runs. " +
                    "If you dont have permissions, the recommended way is to define tools paths in a configuration file in your home folder.",
                    helpurl: "https://github.com/jmecsoftware/sonar-cxx-msbuild-tasks#using-the-wrapper-behind-proxy-or-were-admin-rights-are-not-available");
            }
        }
예제 #4
0
        private static bool FirstTimeSetup(QuestionUser pMethod)
        {
            string userName = string.Empty;

            if (!File.Exists("Username.USER"))
            {
                userName = pMethod("UserName?")?.Result;
                if (userName == null)
                {
                    return(false);
                }
                File.WriteAllText("Username.USER", userName);
            }
            else
            {
                userName = File.ReadAllText("Username.USER");
            }

            if (!File.Exists("SecretTokenDontLOOK.TOKEN"))
            {
                var password = pMethod("Token?")?.Result;
                if (userName == null)
                {
                    return(false);
                }
                File.WriteAllText("SecretTokenDontLOOK.TOKEN", password);
            }

            if (!File.Exists("Channel.JOIN"))
            {
                var channel = pMethod("Channel?(Leave blank for your own channel)")?.Result;
                if (userName == null)
                {
                    return(false);
                }
                if (String.IsNullOrEmpty(channel))
                {
                    channel = "#" + userName;
                }

                if (!channel.StartsWith("#"))
                {
                    channel = "#" + channel;
                }

                File.WriteAllText("Channel.JOIN", channel);
                Twitch.TwitchAPI._channel = channel;
            }
            else
            {
                Twitch.TwitchAPI._channel = File.ReadAllText("Channel.JOIN");
            }
            return(true);
        }
예제 #5
0
        protected void rptQuestion_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (string.Compare(e.CommandName, "delete", true) == 0)
            {
                int id = 0;
                int.TryParse(e.CommandArgument.ToString(), out id);

                QuestionUser qu = DomainManager.GetObject <QuestionUser>(id);
                if (qu != null)
                {
                    DomainManager.Delete(qu);
                    TNHelper.RemoveRankingCaches();
                    LoadData();
                    Utils.ShowMessage(lblMsg, "Xóa thông tin game thử tài kiến thức của người chơi thành công.");
                }
            }
        }
        /// <summary>
        /// Called when [save search command].
        /// </summary>
        private void OnSaveSearchCommand()
        {
            var search = this.GetCurrentSearch();

            if (this.SelectedSearch != null)
            {
                var data = QuestionUser.GetInput("You will overwrite " + this.SelectedSearch + ", are you Sure?");
                if (data)
                {
                    search.Name = this.SelectedSearch;
                    this.savedSearchModel.SaveSearch(search);
                }
            }
            else
            {
                this.OnSaveAsSearchCommand();
            }
        }
예제 #7
0
        private void Signin_Click(object sender, RoutedEventArgs e)
        {
            QuestionUser user = null;

            if (Logintxt.Text == "admin" && Passtxt.Password == "admin")
            {
                Admin admin = new Admin();
                admin.Show();

                return;
            }
            if (CreateAcc.users.Count == 0)
            {
                XmlSerializer xml = new XmlSerializer(typeof(List <QuestionUser>));
                using (TextReader t = new StreamReader("Users.xml"))
                {
                    CreateAcc.users = (List <QuestionUser>)xml.Deserialize(t);
                }
            }
            foreach (var elem in CreateAcc.users)
            {
                if (elem.Login == Logintxt.Text)
                {
                    user = elem;
                    if (user.Password != Passtxt.Password)
                    {
                        MessageBox.Show("Error Password");
                        return;
                    }
                }
            }
            if (user == null)
            {
                MessageBox.Show("Error Login");
                return;
            }
            MainWindow main = new MainWindow(user);

            main.Show();
            this.Close();
        }
예제 #8
0
        protected void rptQuestion_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item ||
                e.Item.ItemType == ListItemType.AlternatingItem)
            {
                QuestionUser qu = e.Item.DataItem as QuestionUser;
                Literal      litTotalQuestion = e.Item.FindControl("litTotalQuestion") as Literal;
                Literal      litRightAnswer   = e.Item.FindControl("litRightAnswer") as Literal;
                Literal      litBonusPoint    = e.Item.FindControl("litBonusPoint") as Literal;
                Literal      litOnSiteTime    = e.Item.FindControl("litOnSiteTime") as Literal;
                if (litTotalQuestion != null)
                {
                    litTotalQuestion.Text = qu.QuestionUserDetailses.Count.ToString("N0");
                }

                if (litRightAnswer != null)
                {
                    int count = 0;
                    foreach (QuestionUserDetail detail in qu.QuestionUserDetailses)
                    {
                        if (detail.Question != null && detail.Question.CorrectAnswer != null &&
                            detail.Answer != null && detail.Question.CorrectAnswer.Id == detail.Answer.Id)
                        {
                            count++;
                        }
                    }

                    litRightAnswer.Text = count.ToString("N0");
                }

                if (litBonusPoint != null)
                {
                    litBonusPoint.Text = qu.WinPoint.ToString("N0");
                }

                if (litOnSiteTime != null)
                {
                    litOnSiteTime.Text = string.Format("{0} phút {1} giây", (qu.Time / 60), (qu.Time % 60));
                }
            }
        }
예제 #9
0
        public void Start()
        {
            QuestionUser = ((x) => UserDialog?.Invoke(x));
            Write        = ((x, z) => WriteToConsole?.Invoke(x, z));
            WriteLine    = ((x, z) => WriteLineToConsole?.Invoke(x, z));

            ThreadPool.QueueUserWorkItem(obj =>
            {
                if (!FirstTimeSetup(QuestionUser))
                {
                    throw new Exception("First Time Params Not Set");
                }

                IRCClient.Start(HandleUserCommands, Twitch.TwitchAPI._channel);

                TwitchAPI.Init();
                VoteSystem.Init();
                UserManager.Init();
                IRCClient.Init(ConsoleWrite);
                MemorySystem._instance.Init();
                Microphone.Init();
            });
        }
예제 #10
0
        public void Start(QuestionUser pMethod, WriteToUser pWriteMethod, WriteToUser pWriteLineMethod)
        {
            Write        = pWriteMethod;
            WriteLine    = pWriteLineMethod;
            QuestionUser = pMethod;

            if (!FirstTimeSetup(QuestionUser))
            {
                throw new Exception("First Time Params Not Set");
            }

            IRCClient.Start(HandleUserCommands, Twitch.TwitchAPI._channel);

            TwitchAPI.Init();
            VoteSystem.Init();
            UserManager.Init();
            IRCClient.Init(ConsoleWrite);
            MemorySystem._instance.Init();
            Microphone.Init();

            //IRCMessage message = new IRCMessage();
            //message.userName = userName;
            //message.channel = Twitch.TwitchAPI._channel;
        }
        /// <summary>
        /// The on associate command.
        /// </summary>
        private void OnPlanCommand()
        {
            try
            {
                if (this.CommandText.Equals("Associate to new plan"))
                {
                    var availablePlans = this.rest.GetAvailableActionPlan(this.config, this.associatedProject.Key);
                    var newPlan        = PromptUserForNewPlan.Prompt(availablePlans);

                    if (newPlan == null)
                    {
                        return;
                    }

                    foreach (var existentPlan in availablePlans)
                    {
                        if (existentPlan.Name.Equals(newPlan))
                        {
                            var associatedWithExistent = QuestionUser.GetInput("Plan exists already, do you want to associate with current plan?");

                            if (associatedWithExistent)
                            {
                                var replies = this.rest.PlanIssues(this.config, this.model.SelectedItems, existentPlan.Key.ToString());
                                foreach (var itemreply in replies)
                                {
                                    this.manager.ReportMessage(new Message()
                                    {
                                        Data = "Plan Operation Result: " + itemreply.Key + " : " + itemreply.Value
                                    });
                                }
                            }

                            return;
                        }
                    }

                    try
                    {
                        var plan    = this.rest.CreateNewPlan(this.config, this.associatedProject.Key, newPlan);
                        var replies = this.rest.PlanIssues(this.config, this.model.SelectedItems, plan.Key.ToString());
                        foreach (var itemreply in replies)
                        {
                            manager.ReportMessage(new Message()
                            {
                                Data = "Plan Operation Result: " + itemreply.Key + " : " + itemreply.Value
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        UserExceptionMessageBox.ShowException("Cannot Create Plan, Make sure you have permissions", ex);
                    }
                }
                else
                {
                    if (this.CommandText.Equals("Unplan"))
                    {
                        var replies = this.rest.UnPlanIssues(this.config, this.model.SelectedItems);
                        foreach (var itemreply in replies)
                        {
                            this.manager.ReportMessage(new Message()
                            {
                                Data = "Unplan Operation Result: " + itemreply.Key + " : " + itemreply.Value
                            });
                        }
                    }
                    else
                    {
                        var plans = this.rest.GetAvailableActionPlan(this.config, this.associatedProject.Key);
                        foreach (var plan in plans)
                        {
                            if (plan.Name.Equals(this.CommandText))
                            {
                                var replies = this.rest.PlanIssues(this.config, this.model.SelectedItems, plan.Key.ToString());
                                foreach (var itemreply in replies)
                                {
                                    this.manager.ReportMessage(new Message()
                                    {
                                        Data = "Plan Operation Result: " + itemreply.Key + " : " + itemreply.Value
                                    });
                                }

                                return;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                UserExceptionMessageBox.ShowException("Cannot Perform Operation in Plan: " + ex.Message + " please check vs output log for detailed information", ex);
            }
        }
예제 #12
0
        public void Start(QuestionUser pMethod, WriteToUser pWriteMethod, WriteLineToUser pWriteLineMethod)
        {
            Write     = pWriteMethod;
            WriteLine = pWriteLineMethod;

            string userName = string.Empty;

            if (!File.Exists("Username.USER"))
            {
                userName = pMethod("UserName?");
                File.WriteAllText("Username.USER", userName);
            }
            else
            {
                userName = File.ReadAllText("Username.USER");
            }

            if (!File.Exists("SecretTokenDontLOOK.TOKEN"))
            {
                var password = pMethod("Token?");
                File.WriteAllText("SecretTokenDontLOOK.TOKEN", password);
            }

            if (!File.Exists("Channel.JOIN"))
            {
                var channel = pMethod("Channel?(Leave blank for your own channel)");

                if (String.IsNullOrEmpty(channel))
                {
                    channel = "#" + userName;
                }

                if (!channel.StartsWith("#"))
                {
                    channel = "#" + channel;
                }

                File.WriteAllText("Channel.JOIN", channel);
                Twitch.TwitchAPI._channel = channel;
            }
            else
            {
                Twitch.TwitchAPI._channel = File.ReadAllText("Channel.JOIN");
            }

            IRCClient.Start(HandleUserCommands, Twitch.TwitchAPI._channel);

            TwitchAPI.Init();
            VoteSystem.Init();
            UserManager.Init();
            IRCClient.Init(ConsoleWrite);
            MemorySystem._instance.Init();
            Microphone.Init();

            IRCMessage message = new IRCMessage();

            message.userName = userName;
            message.channel  = Twitch.TwitchAPI._channel;
            while (true)
            {
                try
                {
                    var writeMessage = Console.ReadLine();
                    if (writeMessage?.Trim() == "q")
                    {
                        break;
                    }
                    if (writeMessage?.Trim() != string.Empty)
                    {
                        IRCClient.SendIRCMessage(writeMessage);
                        message.message = writeMessage;
                        HandleUserCommands(message);

                        //System Only Commands
                        IRCClient.HandleMessages(message);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex.ToString());
                }
            }
        }
예제 #13
0
        protected void rptQuestion_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item ||
                e.Item.ItemType == ListItemType.AlternatingItem)
            {
                BizQuestionGameSettings setting = TNHelper.GetQuestionGameSettings();
                QuestionUser            qu      = e.Item.DataItem as QuestionUser;
                Literal  litTotalQuestion       = e.Item.FindControl("litTotalQuestion") as Literal;
                Literal  litRightAnswer         = e.Item.FindControl("litRightAnswer") as Literal;
                Literal  litBonusPoint          = e.Item.FindControl("litBonusPoint") as Literal;
                Literal  litOnSiteTime          = e.Item.FindControl("litOnSiteTime") as Literal;
                Repeater rptQDetail             = e.Item.FindControl("rptQDetail") as Repeater;
                Literal  litQDetail             = e.Item.FindControl("litQDetail") as Literal;
                Panel    pnlPopupQDetail        = e.Item.FindControl("pnlPopupQDetail") as Panel;

                if (litTotalQuestion != null)
                {
                    litTotalQuestion.Text = qu.QuestionUserDetailses.Count.ToString("N0");
                }

                if (litRightAnswer != null)
                {
                    int count = 0;
                    foreach (QuestionUserDetail detail in qu.QuestionUserDetailses)
                    {
                        if (detail.Question != null && detail.Question.CorrectAnswer != null &&
                            detail.Answer != null && detail.Question.CorrectAnswer.Id == detail.Answer.Id)
                        {
                            count++;
                        }
                    }

                    litRightAnswer.Text = count.ToString("N0");
                }

                if (litBonusPoint != null)
                {
                    litBonusPoint.Text = qu.WinPoint.ToString("N0");
                }

                if (litOnSiteTime != null)
                {
                    litOnSiteTime.Text = string.Format("{0} phút {1} giây", (qu.Time / 60), (qu.Time % 60));
                }


                if (qu.QuestionGame != null && qu.QuestionGame.Id != setting.QuestionGameID)
                {
                    if (litQDetail != null)
                    {
                        litQDetail.Text = string.Format("<a class='fancybox' href='#q{0}'>Chi tiết</a>", qu.Id);
                    }

                    if (rptQDetail != null && qu.QuestionUserDetailses != null)
                    {
                        rptQDetail.DataSource     = qu.QuestionUserDetailses.Cast <QuestionUserDetail>();
                        rptQDetail.ItemDataBound += new RepeaterItemEventHandler(rptQDetail_ItemDataBound);
                        rptQDetail.DataBind();
                    }
                }
                else
                {
                    if (litQDetail != null)
                    {
                        litQDetail.Text = string.Format("<a href='javascript:void(0);' title='{0}'>Đang cập nhật</a>",
                                                        "Bạn chỉ được xem chi tiết đáp án khi bộ đề câu hỏi này không còn được sử dụng ở trang trò chơi thử tài kiến thức");
                    }

                    if (pnlPopupQDetail != null)
                    {
                        pnlPopupQDetail.Visible = false;
                    }
                }
            }
        }
예제 #14
0
        private void SavePlayGame(out int rightAnswer, out int bonusPoint)
        {
            bonusPoint  = 0;
            rightAnswer = 0;

            User curenttUser = Utils.GetCurrentUser();

            curenttUser = DomainManager.GetObject <User>(curenttUser.Id);
            if (curenttUser != null)
            {
                int          time = 0;
                QuestionUser qu   = new QuestionUser();
                qu.PlayDate = DateTime.Now;
                qu.User     = curenttUser;
                qu.Time     = time;

                string       key2  = hfCache.Value;
                QuestionGame qgame = CMSCache.Get(key2) as QuestionGame;
                if (qgame != null)
                {
                    qu.QuestionGame = qgame;

                    foreach (Question p in qgame.Questionses.Cast <Question>())
                    {
                        Answer   userAnswer = GetUserAnswer(p);
                        Question question   = DomainManager.GetObject <Question>(p.Id);

                        if (userAnswer != null)
                        {
                            QuestionUserDetail detail = new QuestionUserDetail();
                            detail.QuestionUser = qu;
                            detail.Question     = question;
                            detail.Answer       = userAnswer;
                            qu.QuestionUserDetailses.Add(detail);
                        }

                        if (question != null && question.CorrectAnswer != null &&
                            userAnswer != null && question.CorrectAnswer.Id == userAnswer.Id)
                        {
                            bonusPoint += question.BonusPoint;
                            rightAnswer++;
                        }
                    }
                }


                TimeSpan?onsiteTime = null;
                if (Page.Session[TNHelper.QuestionStarTimeKey] is DateTime)
                {
                    onsiteTime = DateTime.Now - (DateTime)Page.Session[TNHelper.QuestionStarTimeKey];
                    qu.Time    = onsiteTime.Value.Seconds;
                }

                qu.WinPoint = bonusPoint;
                if (qu.QuestionGame != null)
                {
                    DomainManager.Insert(qu);

                    curenttUser.PointQuestion += bonusPoint; // cộng vào tổng điểm của game trả lời câu hỏi
                    curenttUser.Point         += bonusPoint; // cộng điểm thưởng vào tổng điểm của game cá cược

                    DomainManager.Insert(curenttUser);
                    Utils.ResetCurrentUser();
                    if (bonusPoint == 0)
                    {
                        TNHelper.LogAction(LogType.QuestionLog, "Chơi game thử tài kiến thức");
                    }
                    else
                    {
                        TNHelper.LogAction(LogType.QuestionLog, string.Format("Cộng {0} điểm thưởng vào tổng điểm game thử tài kiến thức.<br/>Cộng {0} điểm thưởng vào tổng điểm game phân tích trận đấu", bonusPoint));
                    }
                }
                // remove all relate cache
                CMSCache.RemoveByPattern(hfCache.Value);
            }
        }