Esempio n. 1
0
        public bool validInputRestAPi(string url)
        {
            APICalls api = new APICalls();

            if (!api.isValidUrl(url))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            //timer1.Stop();

            /*int column_format_In = 1; // Type of Input
             * int column_format_out = 2; // Type of Output
             * int col_in_params = 3; // Which as Input Params
             * int col_out_params = 4; // Which as Output Params
             * string result = "";
             * string resultOutput = "";
             * int i;
             * int j = 0;*/
            listView1.Invoke(new Action(() =>
            {
                int progressBarIncrementvalue = (100 * j) / listView1.Items.Count;
                ListViewItem item             = listView1.Items[j];
                //foreach (ListViewItem item in listView1.Items)
                //{
                string val_listView_input         = item.SubItems[column_format_In].Text;
                string val_listView_output        = item.SubItems[column_format_out].Text;
                string val_listView_input_params  = item.SubItems[col_in_params].Text;
                string val_listView_output_params = item.SubItems[col_out_params].Text;
                var inputJson  = JsonConvert.DeserializeObject <List <JSON> >(val_listView_input_params);
                var outputJson = JsonConvert.DeserializeObject <List <JSON> >(val_listView_output_params);
                i = listView2.Items.Count;
                progressBarLoading.Value = 0;

                // TODO - verify is empty value from KEY & VALUE
                var inputURL  = "";
                var outputURL = "";
                string path   = "";
                switch (val_listView_input)
                {
                case COMBOBOX_EXCEL:
                    // GET input values

                    try
                    {
                        bool h = false;
                        if (inputJson.Find(x => x.Key == KEY_PATH) != null)
                        {
                            path = inputJson.Find(x => x.Key == KEY_PATH).Value;
                        }

                        if (inputJson.Find(x => x.Key == EXCEL_KEY_HEADER) != null)
                        {
                            h = true;
                        }

                        // CONVERT data to JSON
                        ExcelFunctions ex = new ExcelFunctions();
                        result            = ex.ExcelToJson(@path, h);
                    }
                    catch (Exception) { result = "Error While getting Excel data."; }

                    break;

                case COMBOBOX_XML:
                    if (inputJson.Find(x => x.Key == KEY_PATH) != null)
                    {
                        path = inputJson.Find(x => x.Key == KEY_PATH).Value;
                    }

                    try
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.Load(@path);

                        // Converting XML to JSON
                        //doc..FirstChild.NextSibling -- remove XML declaration from converted Json
                        string json = JsonConvert.SerializeXmlNode(doc.FirstChild.NextSibling);
                        result      = Regex.Replace(json, "\"(\\d+)\"", "$1");
                    }catch (Exception) {
                        result = "Directory not Found.";
                    }

                    break;

                case COMBOBOX_REST_API:
                    try
                    {
                        using (WebDownload wc = new WebDownload())
                        {
                            string url = "";
                            if (inputJson.Find(x => x.Key == COMBOBOX_REST_API) != null)
                            {
                                url = inputJson.Find(x => x.Key == COMBOBOX_REST_API).Value;
                            }
                            //string url = item.SubItems[3] .Text.ToString();
                            result = wc.DownloadString(url);
                        }
                    }
                    catch (Exception) { result = ""; }
                    break;

                default:
                    break;
                }
                // Output Values
                switch (val_listView_output)
                {
                case COMBOBOX_HTML:
                    try
                    {
                        var type_result = 0;
                        // Convert Data
                        if (outputJson.Find(x => x.Key == HTML_OUTPUT) != null)
                        {
                            type_result = Convert.ToInt32(outputJson.Find(x => x.Key == HTML_OUTPUT).Value);
                        }
                        AppFucntions p = new AppFucntions();
                        resultOutput   = p.DataToHtml(i, result, type_result);
                    }
                    catch (Exception) { resultOutput = "Error while output to HTML."; }
                    break;

                case COMBOBOX_REST_API:
                    try
                    {
                        APICalls apiCalls = new APICalls();
                        inputURL          = inputJson[0].Value;
                        outputURL         = outputJson[0].Value;
                        resultOutput      = apiCalls.JsonToApi(outputURL, result);
                    }
                    catch (Exception) { resultOutput = "Error while sending data to Rest API."; }
                    break;

                default:
                    break;
                }

                // Print data in the "results"  (Add to List View result)
                // resultOutput
                // # | Result
                string[] row =
                {
                    i.ToString(),
                    resultOutput
                };
                var listViewItem = new ListViewItem(row);
                listView2.Items.Add(listViewItem);

                progressBarLoading.Increment(progressBarIncrementvalue += progressBarIncrementvalue);
                i++;
                j++;

                //}
            }));
            if (j >= listView1.Items.Count)
            {
                reiniciar();
            }
        }
Esempio n. 3
0
        private void TestFunction_Click(object sender, EventArgs e)
        {
            APICalls api = new APICalls();

            MessageBox.Show(api.GetFromApi(textBoxPathFile.Text));
        }