public async Task PostRepAsync(responses reponses) { var client = new HttpClient(); //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", // accessToken); var json = JsonConvert.SerializeObject(reponses); HttpContent content = new StringContent(json); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await client.PostAsync($"{Uri}/api/Quests", content); }
private async void getResponses(string ticket_id) { bool val = true; if (comfun.isConnected()) { try { var client = new HttpClient(); client.BaseAddress = new Uri(App.api_url); var values = new Dictionary <string, string>(); values.Add("session_string", App.session_string); values.Add("data", "{\"table\":\"ticket_responses\"}"); values.Add("extra", "{\"ticket_id\": \"" + ticket_id + "\"}"); values.Add("global", val.ToString()); var content = new FormUrlEncodedContent(values); HttpResponseMessage response = await client.PostAsync("/itcrm/getElements/", content); var result = await response.Content.ReadAsStringAsync(); statusCheck chk_status = JsonConvert.DeserializeObject <statusCheck>(result); if (chk_status.status) { responses response_list = JsonConvert.DeserializeObject <responses>(result); ObservableCollection <SetResponseList> dt = new ObservableCollection <SetResponseList>(); var lst = response_list.result; for (int i = 0; i < lst.Length; i++) { // get all response in string array try { iList.Add(lst[i].response_content); } catch (Exception e) { // await DisplayAlert("Error!", e.Message, "ok"); } } for (int i = 0; i <= lst.Length; i++) { try { dt.Add(new SetResponseList() { full_name = lst[i].full_name, created = lst[i].created, response_content = StripHTML(lst[i].response_content), icon = "https://cloudschool.management/itcrm/media/images/person-flat.png", }); } catch (Exception e) { // await DisplayAlert("Error!", e.Message, "ok"); } } lvResponseList.ItemsSource = dt; } else { // await DisplayAlert("status!", "false", "ok"); } } catch (Exception e) { //await DisplayAlert("Response Error!", "", "ok"); } } else { await DisplayAlert("Connection", "Internet Connection Disabled", "Ok"); } }
private void Process(object objPlurks) { Console.WriteLine("[Module AutoGetFifthFloor] Start"); plurks plurks = (plurks)objPlurks; if (plurks == null) return; //轉換失敗就不處理 List<Int64> listProcessPlurk = new List<long>(); //int iStart = 0; foreach (plurk plurk in plurks) { #region Get each plurk content,if fail then resume next int ResCount = 0; //iStart = System.Environment.TickCount; try { plurk pPlurk = this.MApi.getPlurk(plurk.plurk_id); if (pPlurk == null) { Console.WriteLine(string.Format("[Module AutoGetFifthFloor]取得Plurk錯誤,ID:{0}{1}內容:{2}", plurk.plurk_id.ToString(), Environment.NewLine, plurk.content_raw)); continue; } ResCount = pPlurk.response_count; } catch (Exception ex) { Console.WriteLine(string.Format("[Module AutoGetFifthFloor]Error in AutoGetFifthFloor.AddMyPlurk{0}Description:{1} ", Environment.NewLine, ex.Message)); if (ex.InnerException!=null) Console.WriteLine(string.Format(" AutoGetFifthFloor.AddMyPlurk{0}Description:{1} ", Environment.NewLine, ex.InnerException.Message)); continue; } //Common.PrintUseTime("AutoGetFifthFloor/Process/1", iStart); #endregion #region Get the fifth floor if (ResCount == 4) { //iStart = System.Environment.TickCount; #region Old Code //MApi.responseAdd(Qualifier.says, "上五樓的快活 http://img196.imageshack.us/img196/6992/cover7q.jpg", plurk.plurk_id); //string[] aryStrResponse = new string[15] { // "各位觀眾,專業的**五樓** !" // ,"這噗的五樓,很好**我要了**" // ,"我想起一張專輯,陳奕迅的**上五樓的快活**" // ,"五樓AT力場展開!" // ,"鬼神前鬼,在5樓現臨" // ,"五樓是新世界的神!" // ,"這就叫「搶到五樓」嗎?" // ,"搶到五樓了,是也!" // ,"五樓搶到了的說~~" // ,"使徒來襲,五樓準備好了!" // ,"我要成為五樓王!" // ,"青眼白龍加上黑暗魔導師也打不過我的五樓!" // ,"貫徹愛與真實的邪惡,可愛又迷人的反派角色,五樓!" // ,"就決定是你了!五樓!" // ,"天靈靈,地靈靈,噗仙噗仙,五樓降臨!" // }; #endregion try { Random randObj = new Random(); string strResponse = aryStrResponse[randObj.Next(0, aryStrResponse.Length)]; MApi.responseAdd(Qualifier.says, strResponse, plurk.plurk_id); Console.WriteLine(string.Format("[Module AutoGetFifthFloor]id:{0},內容:{1},五樓成功!{2}回應內容:{3}", plurk.plurk_id.ToString(), plurk.content, Environment.NewLine, strResponse)); listProcessPlurk.Add(plurk.plurk_id); //MApi.mutePlurk(plurk.plurk_id); } catch (Exception ex) { Console.WriteLine(string.Format("[Module AutoGetFifthFloor]Error in AutoGetFifthFloor.AddMyPlurk{0}Description:{1} ", Environment.NewLine, ex.Message)); continue; } //Common.PrintUseTime("AutoGetFifthFloor/Process/2", iStart); } #endregion #region Check 5th response if (ResCount >= 5) { //iStart = System.Environment.TickCount; responses res = new responses(); try { res = MApi.getResponses(plurk.plurk_id, 0); bool addYN = true; int iSEQ = 0; foreach (response nowRes in res) { iSEQ += 1; if (iSEQ > 5 && nowRes.user_id == this.MApi.uid) { addYN = false; break; } if (iSEQ >= 6) break; } if (res.Count < 5) continue; if (!addYN) continue; } catch (Exception ex) { Console.WriteLine(string.Format("[Module AutoGetFifthFloor]Error in AutoGetFifthFloor.AddMyPlurk{0}Description:{1} ", Environment.NewLine, ex.Message)); Console.WriteLine(string.Format(" AutoGetFifthFloor.AddMyPlurk{0}Description:{1} ", Environment.NewLine, ex.InnerException.Message)); continue; } //Common.PrintUseTime("AutoGetFifthFloor/Process/3", iStart); //iStart = System.Environment.TickCount; try { response the5thRes = res[4]; if (the5thRes.user_id == this.MApi.uid) continue; if (the5thRes == null) continue; //若是該回應時間已經超過每次作動時間+1分鐘時,就不回應被搶的五樓 if (the5thRes.posted < DateTime.Now.AddMinutes(0 - ((this._TimerBootMSec / 60000) + 10))) continue; #region 檢查第六個以後的回應,要是噗仙已經回應過了,就不再回應,回應超過10個也不回應了 int iSeq = 0; bool blnContinue = true; if (res.Count >= 10) continue;//回應超過10個也不回應了 foreach (response response in res) { iSeq += 1; if (iSeq <= 5) continue; if (response.user_id == this.MApi.uid) { blnContinue = false; break; } } if (!blnContinue) continue; #endregion #region 檢查被搶 if (the5thRes.content_raw.Replace("~", "").IndexOf("五樓", 0) != -1 || the5thRes.content_raw.Replace("~", "").IndexOf("5樓", 0) != -1 || the5thRes.content_raw.Replace("~", "").IndexOf("5F", 0) != -1 || the5thRes.content_raw.Replace("~", "").IndexOf("5f", 0) != -1 ) { //取得五樓暱稱 string the5thResBelonerNickName = Common.GetPlurkNickName(this.MApi, the5thRes.user_id); //string the5thResBelonerNickName = Common.GetPlurkerLink(this.MApi, the5thRes.user_id); if (the5thResBelonerNickName == "") return; //加入連結 the5thResBelonerNickName = @"http://www.plurk.com/" + the5thResBelonerNickName; #region Old Code //string aa = Common.GetPlurkerLink(this.MApi, the5thRes.user_id); //string[] aryResponse = new string[5]{ // "{0} 你何苦搶我的專業五樓?!" // ,"{0} ,別得意,五樓被你搶走了,那是因為我還沒發功咧!" // ,"既然五樓被{0} 搶走了,我只好搶個"+(ResCount+1).ToString() +"樓來坐坐嘍" // ,"我都已經沒有五樓可以搶了,還留在這裡惹人嫌嗎?!" // ,"哇心愛ㄟ五樓係把郎ㄟ~~~" // }; #endregion Random randObj = new Random(); string strResponse = string.Format(aryResponse[randObj.Next(0, aryResponse.Length)], the5thResBelonerNickName); MApi.responseAdd(Qualifier.says, strResponse, plurk.plurk_id); Console.WriteLine(string.Format("[Module AutoGetFifthFloor]id:{0},內容:{1},五樓被搶走了!{2}回應內容:{3}", plurk.plurk_id.ToString(), plurk.content, Environment.NewLine, strResponse)); //MApi.mutePlurk(plurk.plurk_id); listProcessPlurk.Add(plurk.plurk_id); } #endregion } catch (Exception ex) { Console.WriteLine(string.Format("[Module AutoGetFifthFloor]Error in AutoGetFifthFloor.AddMyPlurk{0}Description:{1} ", Environment.NewLine, ex.Message)); Console.WriteLine(string.Format(" AutoGetFifthFloor.AddMyPlurk{0}Description:{1} ", Environment.NewLine, ex.InnerException.Message)); //return sb.ToString(); continue; } //Common.PrintUseTime("AutoGetFifthFloor/Process/4", iStart); } #endregion } //iStart = System.Environment.TickCount; if (listProcessPlurk != null && listProcessPlurk.Count > 0) { MApi.markAsRead(listProcessPlurk); MApi.mutePlurks(listProcessPlurk); } //Common.PrintUseTime("AutoGetFifthFloor/Process/5", iStart); Console.WriteLine("[Module AutoGetFifthFloor] End"); }