Example #1
0
        /// <summary>
        /// CODE BY SAJID
        /// THIS CODE IS USED TO CHECK VENDOR-SIDE CONNECTIVITY TO THE INTERNET
        /// </summary>
        /// <returns>RETURNS FALSE (0) IF NOT CONNECTED, IN THE ELSE CASE RETURNS TRUE(1)</returns>
        public static bool IsConnectedToInternet()
        {
            bool returnValue = false;

            try
            {
                int Desc;
                returnValue = InternetConnection.InternetGetConnectedState(out Desc, 0);
            }
            catch
            {
                returnValue = false;
            }
            return(returnValue);
        }
Example #2
0
        public static void SendClientStatus()
        {
            string      connectionError = "";
            NetworkInfo netInfo         = new NetworkInfo();

            //netInfo.UserName = "******";
            //netInfo.Password = "******";
            netInfo.UserID = 1;
            //  InternetConnection ic = new InternetConnection();
            netInfo.BusinessIDLocal     = InternetConnection.GetBusinessID();
            netInfo.NetworkAvailability = IsConnectedToInternet().ToString();
            netInfo.BusinessCode        = InternetConnection.GetBusinessCode().ToString();

            HttpClient client = new HttpClient();

            client = BusinessAuthentication.SendAuthentication();

            string              apiUrl       = ConfigurationManager.AppSettings["api_url"] + "Connectivity";
            string              inputJson    = (new JavaScriptSerializer()).Serialize(netInfo);
            HttpContent         inputContent = new StringContent(inputJson, Encoding.UTF8, "application/json");
            HttpResponseMessage response     = null;

            try
            {
                response = client.PostAsync(apiUrl + "/insertstatus", inputContent).Result;
                if (response.IsSuccessStatusCode)
                {
                    var readTask = response.Content.ReadAsAsync <NetworkInfo>();
                    // lblNetworkInfo.Text = readTask.ToString();
                }
                else
                {
                    ///code for no status of 200 OK
                }
            }
            catch (AggregateException ex)
            {
                foreach (Exception inner in ex.InnerExceptions)
                {
                    Console.WriteLine("Exception type {0} from {1}", inner.GetType(), inner.Source);
                }
            }
        }