Exemplo n.º 1
0
    public void SetTaskTestStatus(string ttid, string failed, string userphone)
    {
        try
        {
            MPSUser bsu = MPSUser.FindUserbyPhone(userphone);
            if (bsu == null)
            {
                Logger.Log($"Cannot update task {ttid} by testing system. User was not found by phone number: {userphone}");
                return;
            }

            Defect d = new Defect(ttid);
            d.SetUpdater(bsu);
            string lockguid = Guid.NewGuid().ToString();
            var    lt       = Defect.Locktask(ttid.ToString(), lockguid, bsu.ID.ToString());
            bool   locked   = lt.globallock != lockguid;
            bool   testFail;
            bool   testcancel = false;
            if (!bool.TryParse(failed, out testFail))
            {
                testcancel = true;
            }
            if (locked)
            {
                MPSUser lu = new MPSUser(lt.lockedby);
                TasksBot.SendMessage(lu.CHATID, $"You was disconnected from the task by the testing system to update task status!{Settings.CurrentSettings.GetTTAnchor(int.Parse(ttid), "disconnect.png")}");
                NotifyHub.lockTaskForceUpdatePages(int.Parse(ttid), lockguid, bsu.ID);
                lt = Defect.Locktask(ttid.ToString(), lockguid, bsu.ID.ToString());
            }
            List <DefectDispo> disp = (testcancel || testFail) ? DefectDispo.EnumTestsFailed() : DefectDispo.EnumTestsPassed();
            if (disp.Count > 0)
            {
                if (!testcancel)
                {
                    d.DISPO = disp[0].ID.ToString();
                }
                else
                {
                    d.AddMessage("Test request have been ignored", bsu.ID);
                }
                d.Store();
                Defect.UnLocktask(ttid, lt.globallock);

                if (!testcancel)
                {
                    DefectUser du = new DefectUser(d.AUSER);
                    if (du.TRID > -1)
                    {
                        MPSUser worker = new MPSUser(du.TRID);
                        string  result = "Succeeded!";
                        string  img    = "taskokay.png";
                        if (testcancel)
                        {
                            result = "Cancelled!";
                            img    = "bin.png";
                        }
                        else if (testFail)
                        {
                            result = "Failed!";
                            img    = "taskfail.png";
                        }
                        TasksBot.SendMessage(worker.CHATID, $"The task tests have been marked as BST {result} by {bsu.PERSON_NAME}{Settings.CurrentSettings.GetTTAnchor(int.Parse(ttid), img)}");
                    }
                }
            }
        }
        catch (Exception e)
        {
            Logger.Log(e);
        }
    }