Skip to main content

Calling Method

public async Task<string> Get_Method (string name)
        {
            
            if (name == "News") {
                request = (HttpWebRequest)HttpWebRequest.Create (new Uri (BaseUrl + Base_Blog));
                 //request = (HttpWebRequest)HttpWebRequest.Create (new Uri (parameter));
            } else {
                request = (HttpWebRequest)HttpWebRequest.Create (new Uri (BaseUrl + Base_Media));
                 //request = (HttpWebRequest)HttpWebRequest.Create (new Uri (parameter));
            }

            request.ContentType = "application/json";
            request.Method = "GET";
            JsonValue jsonDoc;
            string res = string.Empty;
            try {
                response = await request.GetResponseAsync ();
                {    
                    stream = response.GetResponseStream ();
                    {
                        jsonDoc = await Task.Run (() => JsonObject.Load (stream));
                        //Console.WriteLine("Response: {0}", jsonDoc);
                        if(name == "News"){
                            SQLClient.Instance.BlogDropTable();
                            postDataStore(jsonDoc);
                            res = "success";
                        }else if(name == "Media"){
                            SQLClient.Instance.MediaDropTable ();
                            mediaDataStore(jsonDoc);
                            res = "success";
                        }
                    }
                }
            }catch(Exception ex){
                Console.Error.WriteLine ("Blog Exception : " + ex.Message);
                res = "retry";
            }
            return res;
        }


 ////

public static void mediaDataStore(JsonValue mediaValue) {
            //Console.WriteLine ("Media Data : " + mediaValue.ToString());
            JArray mediaArray = JArray.Parse(mediaValue.ToString());

            // MediaData
            for (int i = 0; i < mediaArray.Count; i++) {
                JObject mediaObject = JObject.Parse (mediaArray [i].ToString ());
                Media mediaModel = new Media () {
                    ID = Convert.ToInt32 (mediaObject ["ID"].ToString ()),
                    title = mediaObject ["title"].ToString (),
                    status = mediaObject ["status"].ToString ()
                };


                // TermsData

                if (mediaObject ["terms"].Type == JTokenType.Object) {
                    JObject media_terms = JObject.Parse (mediaObject ["terms"].ToString ());
                    JArray media_category = JArray.Parse (media_terms ["media_category"].ToString ());
                    Console.WriteLine ("Media Length : " + media_category.Count);

                    for (int j = 0; j < media_category.Count; j++) {
                        JObject media_category_data = JObject.Parse (media_category [j].ToString ());
                        Console.WriteLine ("slug : " + media_category_data ["slug"].ToString ());

                        MediaTerms mediaTermsModel = new MediaTerms () {
                            ID = Convert.ToInt32 (media_category_data ["ID"].ToString ()),
                            Parent_ID = Convert.ToInt32 (mediaObject ["ID"].ToString ())
                        };

                    }
                }
            }
        }
 



 

Comments

Popular posts from this blog

"Timeouts & Waiting" function in Android Xamarin

Hello, I am here to start some of Good platform which name Xamarin , Its a Cross-Platform and its basically written in C#. First Blog for Set Timeout function  : Code : using  System . Threading ; System . Threading . Tasks . Task . Factory . StartNew (()   = >   {                 Thread . Sleep ( 5000 ) ;   //   delay   execution   for   500 0 ms }) ;

Open Webpage in Default Browser

Open webpage to default browser you need to write this code in Xamarin Andorid :) Code :  var   uri   =  Android . Net . Uri . Parse   ( " http : / / www . dharmik . me " ) ; var   intent   =   new   Intent   ( Intent . ActionView ,   uri ) ;      StartActivity   ( intent ) ;

Launch Phone Dialer in Xamarin

If you want to dial direct phone via in your application in Xamarin Android please use this code , This code is same as Andorid native code. Code:   var   uri   =  Android . Net . Uri . Parse ( " tel : 9999999999 " ) ; var   callIntent   =   new   Intent   ( Intent . ActionDial , uri ) ;     StartActivity ( callIntent ) ; For More detail prefer this URL :  https://developer.xamarin.com/recipes/android/fundamentals/intent/launch_the_phone_dialer/