示例#1
0
 public Question(string description, int value, AnswerType answerType)
 {
     this.description = description;
     this.value       = value;
     this.answerType  = answerType;
     this.answerUser  = "";
 }
示例#2
0
        public async Task <bool> UpdateAnswer(int userId, int questionId, AnswerType answerType)
        {
            var answered = DateTime.Now;

            return(await _context.Database.ExecuteSqlCommandAsync(
                       $"updateAnswer {userId}, {questionId}, {answerType}, {answered}") > 0);
        }
示例#3
0
        public static void InsertTransaction(IMessageActivity activity,
                                             string originalQuestion, int counter,
                                             double maxScore, string maxScoreQuestion,
                                             string LuisIntent, AnswerType answerType)
        {
            var persistency = SharedObjects.DatabaseManager;

            BotTracking tracking = new BotTracking
            {
                IdActivity        = activity.Id,
                IdConversation    = activity.Conversation.Id,
                EntryQuestion     = originalQuestion,
                NumAnswer         = counter,
                AnswerType        = answerType,
                MaxScore          = maxScore,
                LuisIntent        = LuisIntent,
                MaxScoredQuestion = maxScoreQuestion
            };
            var transactionResult = persistency.AddData(tracking);

            if (!transactionResult.Success)
            {
                if (transactionResult.Ex != null)
                {
                    Trace.TraceWarning($"{transactionResult.Message}: {transactionResult.Ex.Message} ");
                }
                else
                {
                    Trace.TraceWarning(transactionResult.Message);
                }
            }
        }
示例#4
0
 public HandleAnswer(CommandContext context, BooleanAnswerHandler handler)
 {
     _type    = AnswerType.Boolean;
     _options = context.HttpContext.RequestServices.GetRequiredService <IOptions <BeavisCliOptions> >().Value;
     _booleanAnswerHandler = handler;
     _context = context;
 }
示例#5
0
 public PlayerInteraction()
 {
     this.title       = string.Empty;
     this.description = string.Empty;
     this.answerType  = AnswerType.VoidAnswer;
     this.footer      = string.Empty;
 }
示例#6
0
 public Question(String question, Answer answers, int score, AnswerType answerType)
 {
     QuestionText    = question;
     QuestionAnswers = answers;
     Score           = score;
     RightAnswer     = answerType;
 }
 public static string ValidateAnswerText(string answerText, AnswerType answerType)
 {
     answerText = (String.IsNullOrWhiteSpace(answerText) ? "" : answerText);
     if (answerType == AnswerType.Email)
     {
         if (!Regex.IsMatch(answerText, "^[a-z0-9_\\+-]+(\\.[a-z0-9_\\+-]+)*@[a-z0-9-]+(\\.[a-z0-9]+)*\\.([a-z]{2,4})$"))
         {
             return("Your answer to {0} must be a valid email address");
         }
     }
     else if (answerType == AnswerType.Url)
     {
         if (!Regex.IsMatch(answerText, @"(http|https)://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"))
         {
             return("Your answer to {0} must be a valid internet address");
         }
     }
     else if (answerType == AnswerType.Date)
     {
         DateTime date = new DateTime();
         if (!DateTime.TryParse(answerText, out date))
         {
             return("Your answer to {0} must be a valid date");
         }
     }
     else if (answerType == AnswerType.Datetime)
     {
         DateTime date = new DateTime();
         if (!DateTime.TryParse(answerText, out date))
         {
             return("Your answer to {0} must be a valid date and time");
         }
     }
     return("");
 }
示例#8
0
 public void Answer(object context, AnswerType answer)
 {
     if (answer == AnswerType.Yes && context is IThreatEvent threatEvent &&
         threatEvent.Model is IThreatModel model)
     {
         var threatType = threatEvent.ThreatType;
         if (threatType != null)
         {
             threatType.Name        = threatEvent.Name;
             threatType.Description = threatEvent.Description;
             var threatEvents = model.GetThreatEvents(threatType)?.ToArray();
             if (threatEvents?.Any() ?? false)
             {
                 foreach (var t in threatEvents)
                 {
                     if (t != threatEvent)
                     {
                         t.Name        = threatEvent.Name;
                         t.Description = threatEvent.Description;
                     }
                 }
             }
         }
     }
 }
    public IEnumerator RestartGame()
    {
        for (int i = 0; i < AnswersTextList.Count; i++)
        {
            AnswersTextList [i].transform.parent.transform.DOScale(Vector3.zero, 1f);
        }
        yield return(new WaitForSeconds(1));

        if (ActiveAnswer == AnswerType.Moon)
        {
            ActiveAnswer  = AnswerType.Sun;
            Question.text = "اختار الكلمات التى بها لام شمسية";
            AS.PlayOneShot(Sun_Q);
        }
        else
        {
            Question.text = "اختار الكلمات التى بها لام قمرية";
            ActiveAnswer  = AnswerType.Moon;
            AS.PlayOneShot(Moon_Q);
        }

        RandomAnswers();
        for (int i = 0; i < AnswersTextList.Count; i++)
        {
            AnswersTextList [i].transform.parent.transform.DOScale(Vector3.one, 1f);
        }
    }
示例#10
0
        public void TestSecondAnswerType()
        {
            //Testlet -- Collection
            var testletCollection = new Dictionary <int, Question>();

            testletCollection = LoadQuestions.QuestionInformation();

            /*
             * Question -Id
             *          Question
             *          Order
             *          AnswerList
             *                      Id
             *                      Answer
             *                      AnswerType - Enum Type {Pretest , Operational}
             * var dictionary = new Dictionary<int, Question>
             * {
             *       { question1.Id, question1 },
             *       { question2.Id, question2 }
             * }
             */
            // Return the Question with ID 1
            var        question    = testletCollection[1];
            AnswerType pretestType = question.Answers[1].Answertype;

            Assert.AreEqual(pretestType, AnswerType.Pretest);
        }
示例#11
0
        private bool AnswerMatches(AnswerType answerType, string givenAnswer, string possibleAnswer)
        {
            Console.WriteLine(answerType);
            switch (answerType)
            {
            case AnswerType.Number:
                if (double.TryParse(givenAnswer, out double a) &&
                    double.TryParse(possibleAnswer, out double b))
                {
                    return(a == b);
                }
                else
                {
                    return(false);
                }

            case AnswerType.Contains:
                var given    = NormalizeAnswer(givenAnswer);
                var possible = NormalizeAnswer(possibleAnswer);
                Console.WriteLine("{0}, {1}", given, possible);
                return(given.Contains(possible));

            default:
                return(NormalizeAnswer(givenAnswer) == NormalizeAnswer(possibleAnswer));
            }
        }
示例#12
0
    private void CreateAnswer(GameObject go, AnswerType answerType, string content)
    {
        GameObject baloon;

        if (answerType == AnswerType.IMAGE)
        {
            baloon = CreateSmallBaloon();
            baloon.transform.SetParent(go.transform, false);
            baloon.transform.localPosition = Vector3.zero;
            GameObject imageGO = CanvasUtilsFactory.Instance.CreateImage("Images/Icons/" + content);
            imageGO.transform.SetParent(go.transform, false);
            imageGO.transform.localPosition = Vector3.zero;
            go.transform.localPosition      = new Vector3(_smallX, go.transform.localPosition.y);
        }
        else   // answerType == AnswerType.TEXT
        {
            GameObject    textGO = CanvasUtilsFactory.Instance.CreateQuestionAnswerText(content);
            RectTransform rt     = textGO.GetComponent <RectTransform>();
            if (rt.sizeDelta.x <= AnswersSettings.Instance.maxSmallXSize)
            {
                baloon = CreateSmallBaloon();
                go.transform.localPosition = new Vector3(_smallX, go.transform.localPosition.y);
            }
            else
            {
                baloon = CreateMediumBaloon();
                go.transform.localPosition = new Vector3(_mediumX, go.transform.localPosition.y);
            }
            baloon.transform.SetParent(go.transform, false);
            baloon.transform.localPosition = Vector3.zero;
            rt.SetParent(go.transform, false);
            rt.localPosition = Vector3.zero;
        }
    }
 public void Answer(object context, AnswerType answer)
 {
     if (answer == AnswerType.Yes || answer == AnswerType.Ok || answer == AnswerType.No)
     {
         if (context is IEntity entity)
         {
             if (entity.GenerateThreatEvents(answer == AnswerType.No))
             {
                 ShowMessage?.Invoke(Resources.SuccessGeneration);
             }
             else
             {
                 ShowWarning?.Invoke(Resources.WarningNothingGenerated);
             }
         }
         else if (context is IDataFlow flow)
         {
             if (flow.GenerateThreatEvents(answer == AnswerType.No))
             {
                 ShowMessage?.Invoke(Resources.SuccessGeneration);
             }
             else
             {
                 ShowWarning?.Invoke(Resources.WarningNothingGenerated);
             }
         }
     }
 }
        public virtual void FillTextboxAnswer(TextBox txtBox, object answer, AnswerType typeOfAnswer)
        {
            if (answer != null)
            {
                switch (typeOfAnswer)
                {
                case AnswerType.String:
                    txtBox.Text = answer.ToString();
                    break;

                case AnswerType.Date:
                    txtBox.Text = Convert.ToDateTime(answer).ToString(CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern);
                    break;

                case AnswerType.Float:
                    txtBox.Text = Convert.ToDouble(answer).ToString("2f");
                    break;

                case AnswerType.Int:
                    txtBox.Text = answer.ToString();
                    break;

                default:
                    txtBox.Text = string.Empty;
                    break;
                }
            }
        }
示例#15
0
 public void Answer(object context, AnswerType answer)
 {
     if (answer == AnswerType.Yes && context is IIdentity identity)
     {
         IdentityRemovingRequired?.Invoke(identity);
     }
 }
示例#16
0
        public static AnswerType toAnswerType(this string text)
        {
            AnswerType str = AnswerType.Point;

            switch (text)
            {
            case "คะแนน":
                str = AnswerType.Point;
                break;

            case "วิชาย่อย":
                str = AnswerType.SubjectSub;
                break;

            case "0":
                str = AnswerType.Point;
                break;

            case "1":
                str = AnswerType.SubjectSub;
                break;

            default:
                break;
            }
            return(str);
        }
        private void rb_Option_Checked(object sender, RoutedEventArgs e)
        {
            RadioButton rb_Option = e.Source as RadioButton;

            int.TryParse(rb_Option.Content.ToString(), out currentFrequency);
            ComboBoxItem item     = cb_OptionType.SelectedItem as ComboBoxItem;
            string       _tempStr = "";

            switch (int.Parse(item.Tag.ToString()))
            {
            case 1:
                currentAnswerType = AnswerType.Month;
                _tempStr          = "近4周" + rb_Option.Content.ToString() + "次";
                break;

            case 2:
                currentAnswerType = AnswerType.Week;
                _tempStr          = "每周" + rb_Option.Content.ToString() + "次";
                break;

            case 3:
                currentAnswerType = AnswerType.Day;
                _tempStr          = "每天" + rb_Option.Content.ToString() + "次";
                break;

            default:
                return;
            }
            textblock_Frequency.Text = _tempStr;
        }
示例#18
0
 public PlayerInteraction(string title, string description, string footer, AnswerType answerType)
 {
     this.title       = title;
     this.description = description;
     this.answerType  = answerType;
     this.footer      = footer;
 }
示例#19
0
        public byte[] ToBinary()
        {
            var mem = new MemoryStream();
            var w   = new BinaryWriter(mem);

            w.Write(Title);
            w.Write(Text);
            w.Write(ValueType.ToString());
            w.Write(AnswerType.ToString());

            w.Write(RightAnswerId.Length);
            Array.ForEach(RightAnswerId, i => w.Write(i));

            w.Write(Answers.Length);
            Array.ForEach(Answers, i =>
            {
                if (ValueType == QValueEnum.Text)
                {
                    w.Write(i.ToString());
                }
                else
                {
                    var bin = new MemoryStream();
                    ((Image)i).Save(bin, ImageFormat.Png);
                    w.Write(Convert.ToBase64String(bin.ToArray()));
                }
            });

            return(mem.ToArray());
        }
示例#20
0
    public void ReadBook(Progress progress)
    {
        string xmlpath = BookDirectory() + m_bookName + ".xml";

        XmlDocument doc = new XmlDocument();

        doc.Load(xmlpath);
        XmlNodeList headerList = doc.DocumentElement.GetElementsByTagName(m_headerTag);
        IEnumerator headerEnum = headerList.GetEnumerator();

        if (headerEnum.MoveNext())
        {
            XmlNode headerNode = (XmlNode)headerEnum.Current;
            var     typeAttr   = headerNode.Attributes[m_typeTag];
            if (typeAttr != null)
            {
                m_type = typeAttr.Value;
            }
            m_answerType = AnswerType.Default;
            var answerAttr = headerNode.Attributes[m_answerTag];
            if (answerAttr != null)
            {
                m_answerType = (AnswerType)Enum.Parse(typeof(AnswerType), answerAttr.Value);
            }

            var timeAttr = headerNode.Attributes[m_timeTag];
            if (timeAttr != null)
            {
                m_timer = Convert.ToInt32(timeAttr.Value);
            }
        }

        XmlNodeList contentList = doc.DocumentElement.GetElementsByTagName(m_contentTag);
        IEnumerator contentEnum = contentList.GetEnumerator();

        while (contentEnum.MoveNext())
        {
            XmlNode     contentNode = (XmlNode)contentEnum.Current;
            XmlNodeList itemList    = contentNode.SelectNodes(m_itemTag);
            IEnumerator itemEnum    = itemList.GetEnumerator();
            while (itemEnum.MoveNext())
            {
                XmlNode itemNode = (XmlNode)itemEnum.Current;
                string  word     = itemNode.Attributes[m_idTag].Value;
                if (!m_wordSet.Contains(word))
                {
                    m_wordSet.Add(word);
                    m_bookWords.Add(word);
                    BookItem item = new BookItem(word, this);
                    item.ReadItem(itemNode);
                    progress.AddWord(item);
                    m_bookItems.Add(item);
                }
            }
        }
        ItemComparer comparer = new ItemComparer();

        m_bookItems.Sort(comparer);
    }
 public async Task <List <AnsweredListDb> > GetVoters(int userId, int questionId, int offset, int count,
                                                      AnswerType answerType, DateTime bornAfter, DateTime bornBefore, SexType sexType, string searchedLogin)
 {
     return(await _db.AnsweredListDb.AsNoTracking()
            .FromSql(
                $"select * from dbo.getAnsweredList({userId}, {questionId},   {answerType}, {bornAfter}, {bornBefore}, {sexType}, {searchedLogin})")
            .Skip(offset).Take(count).ToListAsync() ?? new List <AnsweredListDb>());
 }
 public void Answer(object context, AnswerType answer)
 {
     if (answer == AnswerType.Yes && context is Context c)
     {
         c.Container?.SetRule(c.Rule);
         ShowMessage?.Invoke("Auto Gen Rule copied successfully.");
     }
 }
示例#23
0
 public Answer(Texture2D txAnswerGood, Texture2D txAnswerBad)
 {
     this.txAnswerBad  = txAnswerBad;
     this.txAnswerGood = txAnswerGood;
     responseTime      = 0;
     answer            = AnswerType.Bad;
     opacity           = 1.0f;
 }
示例#24
0
        private void Select(AnswerType answer)
        {
            Answer = answer;

            Hide();

            _routine = null;
        }
示例#25
0
 public DataTable GetProbType(AnswerType answertype)
 {
     SqlParameter[] parms =
     {
         data.MakeInParam("@lang_name", SqlDbType.VarChar, 20, answertype.Lang_name)
     };
     return(data.RunProcReturn("select distinct td_AnswerType.Prob_Type  from td_AnswerType  where Lang_Name = @lang_name", parms).Tables[0]);
 }
示例#26
0
        private void SendAnswer(Socket listener, AnswerType answerType)
        {
            AnswerPacket packet = new AnswerPacket {
                AnswerType = answerType
            };
            string packetJSON = JsonUtility.ToJson(packet);

            listener.Send(Encoding.UTF8.GetBytes(packetJSON));
        }
示例#27
0
    public AnswerController CreateDown(AnswerType answerType, string content)
    {
        GameObject down = Instantiate(answerPrefab);

        down.transform.SetParent(transform, false);
        down.transform.localPosition = new Vector3(down.transform.localPosition.x, _downY);
        CreateAnswer(down, answerType, content);
        return(down.GetComponent <AnswerController>());
    }
示例#28
0
    public AnswerController CreateUp(AnswerType answerType, string content)
    {
        GameObject up = Instantiate(answerPrefab);

        up.transform.SetParent(transform, false);
        up.transform.localPosition = new Vector3(up.transform.localPosition.x, _upY);
        CreateAnswer(up, answerType, content);
        return(up.GetComponent <AnswerController>());
    }
示例#29
0
 public Agent(Guid id, AnswerType answer, VoipPhone phone, string postFix)
     : this()
 {
     Id                 = id;
     Answer             = answer;
     PhoneNumber        = phone.Number;
     AllowOutgoingCalls = phone.Settings.AllowOutgoingCalls;
     Record             = phone.Settings.Record;
     PostFix            = postFix;
 }
示例#30
0
 public Agent(Guid id, AnswerType answer, VoipPhone phone, string postFix)
     : this()
 {
     Id = id;
     Answer = answer;
     PhoneNumber = phone.Number;
     AllowOutgoingCalls = phone.Settings.AllowOutgoingCalls;
     Record = phone.Settings.Record;
     PostFix = postFix;
 }
示例#31
0
 public Question(string question, string correctAnswer, string incorrectAnswer)
 {
     questionElementsType    = new QuestionElementType[1];
     questionElementsType[0] = QuestionElementType.TEXT;
     questionContent         = new string[1];
     questionContent[0]      = question;
     correctAnswerType       = AnswerType.TEXT;
     correctAnswerContent    = correctAnswer;
     incorrectAnswerType     = AnswerType.TEXT;
     incorrectAnswerContent  = incorrectAnswer;
 }
        public TriviaQuestionData(ref IniLoader iniIn, string qSection, int qNum)
        {
            string qTemplate = "q" + qNum.ToString();
            int answers;

            ini = iniIn;

            question = ini.GetIniString(qSection, qTemplate + "question", "Missing question...");
            category = ini.GetIniString(qSection, qTemplate + "cat", "");
            maxAttempts = ini.GetIniInteger(qSection, qTemplate + "maxattempts", -1);
            timeLimit = ini.GetIniInteger(qSection, qTemplate + "timelimit", -1);
            questionValue = ini.GetIniInteger(qSection, qTemplate + "value", -1);
            ansType = DetermineAnswerType(ini.GetIniString(qSection, qTemplate + "atype", "anyof"));
            answers = ini.GetIniInteger(qSection, qTemplate + "acount", 1);
            someOfCount = ini.GetIniInteger(qSection, qTemplate + "aneed", -1);
            anstokens = new ArrayList();

            if (ansType == AnswerType.Unknown)
            {
                MessageBox.Show("Unrecognized answer type in question #" + (qNum + 1).ToString() + ". Defaulting to \"Any Of\".",
                                "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                ansType = AnswerType.AnyOf;
            }

            if (answers > 26 && ansType == AnswerType.MultipleChoice)
            {
                MessageBox.Show("There are over 26 answers to multiple choice question #" + (qNum + 1).ToString() +
                                ". This quiz will not load in Parlour Trivia unless the number of answers is reduced.",
                                "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (answers < 1)
            {
                MessageBox.Show("There are no answers to question #" + (qNum + 1).ToString() + ".",
                                "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else for (int X = 0; X < answers; X++)
                    anstokens.Add(ini.GetIniString(qSection, qTemplate + "a" + X.ToString(), "Missing answer..."));

            unsavedChanges = false;
        }
示例#33
0
 public Answer(AnswerType answerType, string answer)
 {
     // TODO: Complete member initialization
     this.type = answerType;
     this.answer = answer;
 }
        public TriviaQuestionData(TriviaQuestionData questionIn)
        {
            ini = questionIn.Ini;
            question = questionIn.Question;
            category = questionIn.Category;
            maxAttempts = questionIn.MaxAttempts;
            timeLimit = questionIn.TimeLimit;
            questionValue = questionIn.QuestionValue;
            ansType = questionIn.AnsType;
            someOfCount = questionIn.SomeOfCount;
            anstokens = new ArrayList();
            for (int X = 0; X < questionIn.ACount; X++) anstokens.Add(questionIn.A(X));

            unsavedChanges = questionIn.UnsavedChanges;
        }
示例#35
0
 private bool CheckAnswer(AnswerType answer)
 {
     return _questions[_currentStep].Answers[(int)answer].IsCorrect == true;
 }
示例#36
0
 public string getJsonDataOfTags(AnswerType answer, string tags, string customTags)
 {
     string jsonData = "{\"isHappy\":" + (answer == AnswerType.Happy ? "true" : "false") + ",\"tags\":[" + tags + "],\"customTags\":[" + customTags + "]}";
     return jsonData;
 }
 private string WriteAnswerType(AnswerType aTypeIn)
 {
     switch (aTypeIn)
     {
         case AnswerType.AllOf: return "allof";
         case AnswerType.SomeOf: return "someof";
         case AnswerType.MultipleChoice: return "multi";
         case AnswerType.AnyOf: default: return "anyof";
     }
 }
示例#38
0
        public Agent UpdateOperator(Guid operatorId, AgentStatus? status, bool? allowOutgoingCalls, bool? record, AnswerType? answerType, string redirectToNumber)
        {
            if (!CRMSecurity.IsAdmin && !operatorId.Equals(SecurityContext.CurrentAccount.ID)) throw CRMSecurity.CreateSecurityException();

            var dao = DaoFactory.GetVoipDao();
            var phone = dao.GetNumbers().FirstOrDefault(r => r.Settings.Operators.Exists(a => a.Id == operatorId)).NotFoundIfNull();

            var oper = phone.Settings.Operators.Find(r => r.Id == operatorId);

            if (status.HasValue)
            {
                oper.Status = status.Value;
            }

            if (allowOutgoingCalls.HasValue)
            {
                oper.AllowOutgoingCalls = phone.Settings.AllowOutgoingCalls && allowOutgoingCalls.Value;
            }

            if (record.HasValue)
            {
                oper.Record = phone.Settings.Record && record.Value;
            }

            if (answerType.HasValue)
            {
                oper.Answer = answerType.Value;
            }

            if (!string.IsNullOrEmpty(redirectToNumber))
            {
                oper.RedirectToNumber = redirectToNumber;
            }

            dao.SaveOrUpdateNumber(phone);

            return oper;
        }
示例#39
0
        private string handleLoggedInRequest(RequestType type, List<string> parameters, Client client, out AnswerType answerType)
        {
            IPEndPoint ipEndPoint = client.TcpClient.Client.RemoteEndPoint as IPEndPoint;
            switch (type)
            {
                case RequestType.ChangeLogin:
                    answerType = AnswerType.ChangeLogin;
                    if (parameters[0].Length > 24)
                    {
                        throw new KickOutException("Invalid Change Login Request");
                    }
                    foreach (Registration registration in World.Registrations)
                    {
                        if (registration.Login == parameters[0])
                        {
                            return "1~";
                        }
                    }
                    foreach (Player player in World.Players)
                    {
                        if (player.Login == parameters[0])
                        {
                            return "2~";
                        }
                    }
                    client.Player.Login = parameters[0];
                    return "0~";

                case RequestType.ChangeName:
                    answerType = AnswerType.ChangeName;
                    if (parameters[0].Length > 16)
                    {
                        throw new KickOutException("Invalid Change Name Request");
                    }
                    foreach (Registration registration in World.Registrations)
                    {
                        if (registration.Name == parameters[0])
                        {
                            return "1~";
                        }
                    }
                    foreach (Player player in World.Players)
                    {
                        if (player.Name == parameters[0])
                        {
                            return "2~";
                        }
                    }
                    client.Player.Name = parameters[0];
                    return "0~";

                case RequestType.ChangePassword:
                    answerType = AnswerType.ChangePassword;

                    byte[] buffer = new byte[512];
                    int length = client.TcpClient.GetStream().Read(buffer, 0, 512);
                    byte[] passwordBuffer = new byte[length];
                    Array.Copy(buffer, passwordBuffer, length);
                    passwordBuffer = client.Encryptor.XorThis(passwordBuffer);

                    client.Player.Password = passwordBuffer;
                    return string.Empty;

                case RequestType.EnterGame:
                    int villagesCount = (from v in World.Villages where v.Owner == client.Player select v).Count();
                    if (villagesCount > 0)
                    {
                        answerType = AnswerType.Village;
                        return string.Empty; //TODO: return first village
                    }
                    answerType = AnswerType.Map;
                    return WorldController.GetNotifications(client.Player) + WorldController.GetMap(client.Player);
            }
            throw new KickOutException("Invalid Request from authorized Client");
        }
示例#40
0
文件: Answer.cs 项目: Lebby/Develia
 public Answer(long ID, string value, AnswerType type)
 {
     this.ID = ID;
     this.Value = value;
     this.Type = type;
 }
示例#41
0
 //This is actually giant switch
 private string handleRequest(RequestType type, List<string> parameters, Client client, out AnswerType answerType)
 {
     if (client.Player == null)
     {
         return handleUnloggedRequest(type, parameters, client, out answerType);
     }
     else
     {
         return handleLoggedInRequest(type, parameters, client, out answerType);
     }
 }
示例#42
0
        internal Question(string QuestionKey, DataRow row, DataSet xmlDataSet)
        {
            this.XmlDataSet = xmlDataSet;

            this._Key = QuestionKey;

            // get answer type
            this._AnswerType = Questionnarie.GetAnswerType(row[QuestionTableColumns.AnswerType].ToString());

            this._No = row[QuestionTableColumns.QuestionNo].ToString();
            this._HeaderID = row[QuestionTableColumns.QuestionHeader].ToString();
            this._Text = row[QuestionTableColumns.QuestionText].ToString();
            this._Minimum = row[QuestionTableColumns.Minimum].ToString();
            this._Maximum = row[QuestionTableColumns.Maximum].ToString();
            this._StringIDs = row[QuestionTableColumns.StringID].ToString();
            this._DefaultValue = row[QuestionTableColumns.Default].ToString();
            this._JumpNext = row[QuestionTableColumns.JumpNext].ToString();
            this._JumpPervious = row[QuestionTableColumns.JumpPrevious].ToString();

            this._IndicatorGId = row[QuestionTableColumns.IndicatorGID].ToString();
            this._UnitGId = row[QuestionTableColumns.UnitGid].ToString();
            this._SubgroupGId = row[QuestionTableColumns.SubGroupGid].ToString();

            // set question serial no only if question key starts with "Q" ( means not for mandatory questions)
            if (this._Key.StartsWith(Constants.QuestionPrefix))
            {
                this._QuestionSerialNo = Convert.ToInt32(row[QuestionTableColumns.QuestionKey].ToString().Replace(Constants.QuestionPrefix, "").ToString().Trim());
            }
            else
            {
                this._QuestionSerialNo = -1;
            }

            if (row[QuestionTableColumns.Required] is DBNull)
            {
                this._Required = false;
            }
            else
            {
                this._Required = (bool)(row[QuestionTableColumns.Required]);
            }

            if (row[QuestionTableColumns.Visible] is DBNull)
            {
                this.Visible = false;
            }
            else
            {
                this.Visible = (bool)row[QuestionTableColumns.Visible];
            }

            this._DataValue = row[QuestionTableColumns.DataValue].ToString();
            this._NumericValue = row[QuestionTableColumns.NumericValue].ToString();
            this._Source = row[QuestionTableColumns.Source].ToString();
            this._TimePeriod = row[QuestionTableColumns.TimePeriod].ToString();

            if (row[QuestionTableColumns.GridID] is DBNull | row[QuestionTableColumns.GridID].ToString() == "-1")
            {
                this._GridId = "-1";
            }
            else
            {

                this._GridId = row[QuestionTableColumns.GridID].ToString();
                if (this.AnswerType == AnswerType.GridType)
                {
                    this.ProcessGridTypeTable(xmlDataSet);
                    this._GridQuestions = GetGridQuestions(this._GridId, xmlDataSet);

                    //update grid table to show text value for SCB question type
                    this.ReprocessGridTypeTable(xmlDataSet);
                }
            }

            this.GetHeaderText();
            this.CreateOptions(xmlDataSet);
        }
示例#43
0
        private string handleUnloggedRequest(RequestType type, List<string> parameters, Client client, out AnswerType answerType)
        {
            IPEndPoint ipEndPoint = client.TcpClient.Client.RemoteEndPoint as IPEndPoint;
            switch (type)
            {
                case RequestType.Welcome:
                    Version clientVersion = new Version(int.Parse(parameters[1]), int.Parse(parameters[2]), int.Parse(parameters[3]), int.Parse(parameters[4]));
                    bool isSupported = (clientVersion.Major == supportedVersion.Major && clientVersion.Minor == supportedVersion.Minor && clientVersion.Build == supportedVersion.Build);
                    answerType = AnswerType.Welcome;
                    return string.Format("{0}~{1}~{2}~", isSupported, name, Message);

                case RequestType.Update:
                    answerType = AnswerType.Update;
                    return string.Format("{0}~", clientFileBuffer.Length);

                case RequestType.Registration:
                    byte[] buffer = new byte[512];
                    int length = client.TcpClient.GetStream().Read(buffer, 0, 512);
                    byte[] passwordBuffer = new byte[length];
                    Array.Copy(buffer, passwordBuffer, length);
                    passwordBuffer = client.Encryptor.XorThis(passwordBuffer);

                    if (parameters[0].Length > 24 || parameters[1].Length > 16 || parameters[2].Length > 1024)
                    {
                        throw new KickOutException("Invalid Registration Input");
                    }

                    Registration newRegistration = new Registration(parameters[0], parameters[1], parameters[2], passwordBuffer, ipEndPoint.Address);

                    answerType = AnswerType.Registration;
                    if (World.Registrations.Count >= 10)
                    {
                        return string.Format("{0}~", 6);
                    }

                    int errorCode = 0;

                    foreach (Registration registration in World.Registrations)
                    {
                        if (registration.IP.ToString() == newRegistration.IP.ToString())
                        {
                            errorCode = 3;
                            break;
                        }
                        if (registration.Login == newRegistration.Login)
                        {
                            errorCode = 1;
                            break;
                        }
                        if (registration.Name == newRegistration.Name)
                        {
                            errorCode = 2;
                            break;
                        }
                    }

                    if (errorCode == 0)
                    {
                        foreach (Player player in World.Players)
                        {
                            if (player.Login == newRegistration.Login)
                            {
                                errorCode = 4;
                                break;
                            }
                            if (player.Name == newRegistration.Name)
                            {
                                errorCode = 5;
                                break;
                            }
                        }

                        if (errorCode == 0)
                        {
                            World.Registrations.Add(newRegistration);
                        }
                    }
                    return string.Format("{0}~", errorCode);

                case RequestType.Login:
                    answerType = AnswerType.Login;
                    buffer = new byte[512];
                    length = client.TcpClient.GetStream().Read(buffer, 0, 512);
                    passwordBuffer = new byte[length];
                    Array.Copy(buffer, passwordBuffer, length);
                    passwordBuffer = client.Encryptor.XorThis(passwordBuffer);

                    foreach (Player player in World.Players)
                    {
                        if (player.Login == parameters[0])
                        {
                            bool passwordMatch = passwordBuffer.Length == player.Password.Length;
                            for (int i = 0; i < player.Password.Length; i++)
                            {
                                if (passwordBuffer[i] != player.Password[i])
                                {
                                    passwordMatch = false;
                                    break;
                                }
                            }
                            if (passwordMatch)
                            {
                                client.Player = player;
                                return "0~";
                            }
                        }
                    }
                    if (client.BadLoginAttempts >= 2)
                    {
                        banThis(ipEndPoint.Address, 5, 0, "Bad Logins");
                        throw new KickOutException("Banned IP, too many bad login attemts");
                    }
                    else
                    {
                        client.BadLoginAttempts++;
                        return "1~";
                    }
            }
            throw new KickOutException("Invalid Request from unauthorized Client");
        }
示例#44
0
        /// <summary>
        /// Returns the default value
        /// </summary>
        /// <param name="ansType"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public string GetDefaultValue(AnswerType ansType, string defaultValue)
        {
            string RetVal = string.Empty;
            DataRow[] Rows;
            try
            {
                switch (ansType)
                {
                    case AnswerType.TB:
                    case AnswerType.TBN:
                        RetVal = defaultValue;
                        break;
                    case AnswerType.CB:
                    case AnswerType.SCB:
                    case AnswerType.RB:
                    case AnswerType.SRB:
                    case AnswerType.CH:
                        // get value from string table
                        if (defaultValue.Length > 0)
                        {
                            Rows = this.QuestionnaireDataSet.Tables[TableNames.StringTable].Select(StringTableColumns.StringId + "=" + defaultValue);
                            if (Rows.Length > 0)
                            {
                                RetVal = Rows[0][StringTableColumns.DisplayString].ToString();
                            }
                        }
                        break;
                    case AnswerType.GridType:
                        break;
                    case AnswerType.Calculate:
                        break;
                    case AnswerType.Aggregate:
                        break;
                    default:
                        break;
                }
            }
            catch (Exception)
            {
                RetVal = string.Empty;
                //'MsgBox(ex.Message)

            }

            return RetVal;
        }
        public TriviaQuestionData()
        {
            ini = null;
            question = "";
            category = "";
            maxAttempts = -1;
            timeLimit = -1;
            questionValue = -1;
            ansType = AnswerType.AnyOf;
            someOfCount = 1;
            anstokens = new ArrayList();

            unsavedChanges = false;
        }