Esempio n. 1
0
        /// <summary>
        /// 送出更新的動作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            KBModel.UpdateKBModel objUpdate = new KBModel.UpdateKBModel()
            {
                add = new  KBModel.UpdateKBModel.Add()
                {
                    qnaPairs = new List <KBModel.QnAList>(),
                    urls     = new List <string>()
                },
                delete = new KBModel.UpdateKBModel.Delete()
                {
                    qnaPairs = new List <KBModel.QnAList>()
                },
            };

            for (int i = 0; i < objQnA.Count; i++)
            {
                if (objQnA[i].source == "delete")
                {
                    objUpdate.delete.qnaPairs.Add(new KBModel.QnAList()
                    {
                        answer   = objQnA[i].answer,
                        question = objQnA[i].question,
                    }
                                                  );
                }
                else if (objQnA[i].source == "add")
                {
                    objUpdate.add.qnaPairs.Add(new KBModel.QnAList()
                    {
                        answer   = objQnA[i].answer,
                        question = objQnA[i].question,
                    }
                                               );
                }
            }

            HttpStatusCode code   = HttpStatusCode.OK;
            string         strMsg = iQnAMaker.UpdateKB(base.KBList[cbxKbId.SelectedIndex].kbId, objUpdate, out code);

            if (code == HttpStatusCode.NoContent)
            {
                MessageBox.Show("Update KB Success");
                string strFilePath = this.DownloadData();
                this.BindData(strFilePath);
            }
            else
            {
                MessageBox.Show("Update KB Fail:" + code.ToString());
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 更新KB的資料
 /// </summary>
 /// <param name="strKbId"></param>
 /// <param name="value"></param>
 /// <param name="code"></param>
 /// <returns></returns>
 public string UpdateKB(string strKbId, KBModel.UpdateKBModel value, out HttpStatusCode code)
 {
     return(Utility.CallQnAMaker("/" + strKbId, "PATCH", JsonConvert.SerializeObject(value), this.SubscriptionKey, out code));
 }
Esempio n. 3
0
        /// <summary>
        /// 處理新增 Knowledge Base Q & A 問題
        /// </summary>
        /// <param name="pquestion"></param>
        private void QNAMakerAddQnA(string pquestion)
        {
            List <KBModel.QnAQueryList> objQnA = new List <KBModel.QnAQueryList>();

            KBModel.UpdateKBModel objUpdate = new KBModel.UpdateKBModel()
            {
                add = new KBModel.UpdateKBModel.Add()
                {
                    qnaPairs = new List <KBModel.QnAList>(),
                    urls     = new List <string>()
                },
                delete = new KBModel.UpdateKBModel.Delete()
                {
                    qnaPairs = new List <KBModel.QnAList>()
                },
            };

            int    startQ = pquestion.IndexOf("AddQ:");
            int    startA = pquestion.IndexOf("AddA:");
            string AddQ   = pquestion.Substring(startQ + 5, startA - 5);
            string AddA   = pquestion.Substring(startA + 5);

            Console.WriteLine(AddQ.Trim());
            Console.WriteLine(AddA.Trim());

            objQnA.Add(
                new KBModel.QnAQueryList()
            {
                answer   = AddA.Trim(),
                question = AddQ.Trim(),
                source   = "add",
            }
                );

            for (int i = 0; i < objQnA.Count; i++)
            {
                if (objQnA[i].source == "delete")
                {
                    objUpdate.delete.qnaPairs.Add(new KBModel.QnAList()
                    {
                        answer   = objQnA[i].answer,
                        question = objQnA[i].question,
                    }
                                                  );
                }
                else if (objQnA[i].source == "add")
                {
                    objUpdate.add.qnaPairs.Add(new KBModel.QnAList()
                    {
                        answer   = objQnA[i].answer,
                        question = objQnA[i].question,
                    }
                                               );
                }
            }

            maduka_QnAMakerLibrary.API.QnAMaker QNAMaker = new maduka_QnAMakerLibrary.API.QnAMaker();
            QNAMaker.SubscriptionKey = SubscriptionKey;
            HttpStatusCode code   = HttpStatusCode.OK;
            string         strMsg = QNAMaker.UpdateKB(strKbId, objUpdate, out code);

            if (code == HttpStatusCode.NoContent)
            {
                LintBot.ReplyMessage(ReceivedMessage.events[0].replyToken, string.Format("{0},{1}", username, "Update KB Success"));
            }
            else
            {
                LintBot.ReplyMessage(ReceivedMessage.events[0].replyToken, "Update KB Fail:" + code.ToString());
            }
        }