Пример #1
0
        private async void btnGetAPI_Clicked(object sender, EventArgs e)
        {
            var newParam = new MyParam
            {
                start_time = "2017/12/01",
                stop_time  = "2020/12/19",
                lstNoPOL   = new List <string> {
                    "B 9181 UCN"
                }
            };

            try
            {
                var listNopol = await GetAPI(newParam);

                lblResult.Text = $"Hasil: {listNopol.ResponseCode} - {listNopol.ResponseMessage} \n\n";
                foreach (var data in listNopol.Data)
                {
                    lblResult.Text += $"{data.company_nm} - {data.idle.addr} \n";
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error", $"{ex.Message}", "OK");
            }
        }
Пример #2
0
        //ambil api dari easy go API
        private async Task <MyResult> GetAPI(MyParam param)
        {
            using (HttpClient client = new HttpClient())
            {
                var url = "https://vtsapi.easygo-gps.co.id/api/report/idle";

                try
                {
                    var jsonData = JsonConvert.SerializeObject(param);
                    var content  = new StringContent(jsonData, Encoding.UTF8, "application/json");

                    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                    content.Headers.Add("Token", "<isi token>");
                    //await DisplayAlert("Ket", $"{await content.ReadAsStringAsync()}", "OK");
                    var response = await client.PostAsync(url, content);

                    if (!response.IsSuccessStatusCode)
                    {
                        throw new Exception("Gagal !");
                    }
                    else
                    {
                        var result = await response.Content.ReadAsStringAsync();

                        MyResult myResult = JsonConvert.DeserializeObject <MyResult>(result);
                        return(myResult);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }
Пример #3
0
 public static void DeleteUsers(string uIds, string apiKey)
 {
     Sync.SendRequest("deleteuser", new List <MyParam>
     {
         MyParam.Create("uids", uIds)
     }.ToArray(), apiKey);
 }
Пример #4
0
 public static void UpdateProfile(int uId, string userName, string apiKey)
 {
     Sync.SendRequest("updateprofile", new List <MyParam>
     {
         MyParam.Create("uid", uId),
         MyParam.Create("user_name", userName)
     }.ToArray(), apiKey);
 }
Пример #5
0
 public static void UpdatePassword(string userName, string password, string apiKey)
 {
     Sync.SendRequest("updatepwd", new List <MyParam>
     {
         MyParam.Create("user_name", userName),
         MyParam.Create("password", password)
     }.ToArray(), apiKey);
 }
Пример #6
0
 public static void UpdateCredits(int uId, int creditIndex, string amount, string apiKey)
 {
     Sync.SendRequest("updatecredits", new List <MyParam>
     {
         MyParam.Create("uid", uId),
         MyParam.Create("credit_index", creditIndex.ToString()),
         MyParam.Create("amount", amount)
     }.ToArray(), apiKey);
 }
Пример #7
0
 public static void RenameUser(int uId, string oldUserName, string newUserName, string apiKey)
 {
     Sync.SendRequest("renameuser", new List <MyParam>
     {
         MyParam.Create("uid", uId),
         MyParam.Create("old_user_name", oldUserName),
         MyParam.Create("new_user_name", newUserName)
     }.ToArray(), apiKey);
 }
Пример #8
0
 //public static string Test(string asyncUrl)
 //{
 //	return Utils.GetHttpWebResponse(string.Format("{0}?action={1}", asyncUrl, "test"));
 //}
 public static void UserRegister(int uId, string userName, string password, string apiKey)
 {
     Sync.SendRequest("register", new List <MyParam>
     {
         MyParam.Create("uid", uId),
         MyParam.Create("user_name", userName),
         MyParam.Create("password", password)
     }.ToArray(), apiKey);
 }
Пример #9
0
 public static void UpdateSignature(int uId, string userName, string signature, string apiKey)
 {
     Sync.SendRequest("updatesignature", new List <MyParam>
     {
         MyParam.Create("uid", uId),
         MyParam.Create("user_name", userName),
         MyParam.Create("signature", signature)
     }.ToArray(), apiKey);
 }
Пример #10
0
        protected string GetUrlforParam(string url, MyParam param)
        {
            Type type = param.GetType();

            PropertyInfo[] properties = type.GetProperties();
            foreach (var item in properties)
            {
                if (item.Name.ToLower() == "fromdate" || item.Name.ToLower() == "todate" || item.Name.ToLower() == "max" || item.Name.ToLower() == "min")
                {
                    if (item.GetValue(param) != null)
                    {
                        url += item.Name.ToLower() + "=" + this.DateTimetoUnixStamp(Convert.ToDateTime(item.GetValue(param))) + "&";
                    }
                }
                else
                {
                    if (item.GetValue(param) != null)
                    {
                        url += item.Name.ToLower() + "=" + item.GetValue(param).ToString() + "&";
                    }
                }
                //switch (item.Name.ToLower())
                //{
                //    case "page":
                //        url += "page=" + item.GetValue(param).ToString() + "&";
                //        break;
                //    case "pagesize":
                //        url += "pagesize=" + param.Pagesize + "&";
                //        break;
                //    case "fromdate":
                //        url += "fromdate=" + this.DateTimetoUnixStamp(param.Fromdate) + "&";
                //        break;
                //    case "todate":
                //        url += "todate=" + this.DateTimetoUnixStamp(param.Todate) + "&";
                //        break;
                //    case "max":
                //        url += "max=" + this.DateTimetoUnixStamp(param.Max) + "&";
                //        break;
                //    case "min":
                //        url += "min=" + this.DateTimetoUnixStamp(param.Min) + "&";
                //        break;
                //    case "order":
                //        url += "order=" + param.Order + "&";
                //        break;
                //    case "sort":
                //        url += "sort=" + param.Sort + "&";
                //        break;
                //    case "tagged":
                //        url += "tagged=" + item.GetValue(param).ToString() + "&";
                //        break;
                //}
            }
            url = url.Remove(url.LastIndexOf('&'));
            return(url);
        }
Пример #11
0
 public static void NewTopic(string topicId, string title, string author, string authorId, string fid, string apiKey)
 {
     Sync.SendRequest("newtopic", new List <MyParam>
     {
         MyParam.Create("tid", topicId),
         MyParam.Create("title", title),
         MyParam.Create("author", author),
         MyParam.Create("author_id", authorId),
         MyParam.Create("fid", fid)
     }.ToArray(), apiKey);
 }
Пример #12
0
 private static XElement ConditionalElement(MyParam arg)
 {
     if (arg.Size < 5)
     {
         return(new XElement("Type", "Small"));
     }
     else
     {
         return(new XElement("Type", "Big"));
     }
 }
Пример #13
0
            public MyParam DummyWithUnhandledException(MyParam p)
            {
                f.Invoke(new Action(() => f.mRichTextBox.AppendText($"Run task {taskName}.\r\n")));

                f.Invoke(new Action(() => f.mRichTextBox.AppendText($"    {p.StringFromPreivousTask}.\r\n")));
                f.Invoke(new Action(() => f.mRichTextBox.AppendText($"I'm going to throw an exception in 1 sec...\r\n")));

                Thread.Sleep(1000);

                throw new Exception($"Exception thrown by {taskName}!");
            }
Пример #14
0
        public static string GetLogoutScript(int uId)
        {
            var stringBuilder = new StringBuilder();
            var list          = new List <MyParam>();

            list.Add(MyParam.Create("uid", uId));
            foreach (var current in Sync.GetAsyncTarget("logout"))
            {
                stringBuilder.AppendFormat("<script src=\"{0}\" reload=\"1\"></script>", Sync.GetUrl(current.SyncUrl, current.Secret, "logout", list.ToArray()));
            }
            return(stringBuilder.ToString());
        }
Пример #15
0
 public static void Reply(string postId, string topicId, string topicTitle, string poster, string posterId, string fid, string apiKey)
 {
     Sync.SendRequest("reply", new List <MyParam>
     {
         MyParam.Create("pid", postId),
         MyParam.Create("tid", topicId),
         MyParam.Create("topic_title", topicTitle),
         MyParam.Create("poster", poster),
         MyParam.Create("poster_id", posterId),
         MyParam.Create("fid", fid)
     }.ToArray(), apiKey);
 }
Пример #16
0
            public MyParam DummyWithAnotherHandledException(MyParam p)
            {
                f.Invoke(new Action(() => f.mRichTextBox.AppendText($"Run task {taskName}.\r\n")));

                f.Invoke(new Action(() => f.mRichTextBox.AppendText($"    {p.StringFromPreivousTask}.\r\n")));
                f.Invoke(new Action(() => f.mRichTextBox.AppendText($"I'm going to throw an exception in 1 sec...\r\n")));

                Thread.Sleep(1000);

                try
                {
                    throw new Exception($"Exception thrown by {taskName}!");
                }
                catch
                {
                    p.NextState = nameof(f.AnotherHandledExceptionTask);
                }
                return(p);
            }
Пример #17
0
    static void Main()
    {
        int[] array = new int[5] {
            1, 2, 3, 4, 5
        };
        MyParam sa = new MyParam();

        //в списке параметров и обычные параметр и параметры переменной длины
        //параметры переменной длины должны быть в конце и дб только один параметр переменной длины
        sa.Show("Некая строка:", array);
        sa.Show("Другая строка", 23, 34, 454, 56);
        sa.Show("Другая строка", 23, 34, 454, 56, 67, 87, 345);

        Console.WriteLine();
        Rectangle r1 = new Rectangle(1, 2);
        Rectangle r2 = r1.RectTo2();

        r1.Show();
        r1.ShowArea();
        r2.Show();
        r2.ShowArea();
    }
Пример #18
0
        private static string GetUrl(string asyncUrl, string secret, string action, MyParam[] parameters)
        {
            var list = new List <MyParam>(parameters);

            list.Add(MyParam.Create("time", Time()));
            list.Add(MyParam.Create("action", action));
            list.Sort();
            var stringBuilder = new StringBuilder();

            foreach (var current in list)
            {
                if (!string.IsNullOrEmpty(current.Value))
                {
                    stringBuilder.Append(current.ToString());
                }
            }
            stringBuilder.Append(secret);
            byte[] array          = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(stringBuilder.ToString()));
            var    stringBuilder2 = new StringBuilder();

            byte[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                byte b = array2[i];
                stringBuilder2.Append(b.ToString("x2"));
            }
            list.Add(MyParam.Create("sig", stringBuilder2.ToString()));
            var stringBuilder3 = new StringBuilder();

            for (int j = 0; j < list.Count; j++)
            {
                if (j > 0)
                {
                    stringBuilder3.Append("&");
                }
                stringBuilder3.Append(list[j].ToEncodedString());
            }
            return(string.Format("{0}?{1}", asyncUrl, stringBuilder3.ToString()));
        }
Пример #19
0
            public MyParam DummyWithConditions(MyParam p)
            {
                f.Invoke(new Action(() => f.mRichTextBox.AppendText($"Run task {taskName}.\r\n")));
                Thread.Sleep(500);
                if (p.StringFromPreivousTask != null)
                {
                    f.Invoke(new Action(() => f.mRichTextBox.AppendText($"    {p.StringFromPreivousTask}.\r\n")));
                }

                p.StringFromPreivousTask = $"A message comes from task {taskName}";

                int counter = 1;

                while (counter++ <= 10)
                {
                    f.Invoke(new Action(() => f.mRichTextBox.AppendText($"    ..{counter}")));
                    if (p.cancellationToken.IsCancellationRequested)
                    {
                        f.Invoke(new Action(() => f.mRichTextBox.AppendText($"    ........Cancelled.\r\n")));
                        return(p);
                    }
                    Thread.Sleep(100);
                }

                f.Invoke(new Action(() => f.mRichTextBox.AppendText($"\r\nTask {taskName} finished.\r\n")));

                SelectReturnCaseForm selectReturnCaseForm = new SelectReturnCaseForm(numberOfCases);
                int caseNumber = 0;

                if (selectReturnCaseForm.ShowDialog() == DialogResult.OK)
                {
                    caseNumber = selectReturnCaseForm.Return;
                }

                p.NextState = f.tbsm.Flow[f.tbsm.CurrentTaskName][caseNumber];
                return(p);
            }
Пример #20
0
            public MyParam Dummy(MyParam p)
            {
                f.Invoke(new Action(() => f.mRichTextBox.AppendText($"Run task {taskName}.\r\n")));

                f.Invoke(new Action(() => f.mRichTextBox.AppendText($"    {p.StringFromPreivousTask}.\r\n")));
                int counter = 1;

                while (counter++ <= 10)
                {
                    f.Invoke(new Action(() => f.mRichTextBox.AppendText($"    ..{counter}")));
                    if (p.cancellationToken.IsCancellationRequested)
                    {
                        f.Invoke(new Action(() => f.mRichTextBox.AppendText($"    ........Cancelled.\r\n")));
                        return(p);
                    }
                    Thread.Sleep(100);
                }

                f.Invoke(new Action(() => f.mRichTextBox.AppendText($"\r\nTask {taskName} finished.\r\n")));

                p.StringFromPreivousTask = $"A message comes from task {taskName}";

                return(p);
            }
Пример #21
0
 public MyParam ComplexParamsMethod(int param1, MyParam param2)
 {
     return(param2);
 }
Пример #22
0
 public void UpdateDataInfoTable(MyParam mytagparam)
 {
     UpdateByCreationdate((QuestionParam)mytagparam);
 }
Пример #23
0
 public NamedConstructor(
     [BeanReference] MyParam myParam)
 {
 }