public bool TableExists(string tableName) { string text = "SELECT count(*) FROM sqlite_master WHERE type = 'table' AND name = '" + tableName + "'"; ISQLiteCommand cmd = _liteConnection.CreateCommand(text); int r = cmd.ExecuteScalar <Int32>(); return(r != 0); }
public CustomListAdapter(Activity context) //We need a context to inflate our row view from : base() { this.context = context; //For demo purposes we hard code some data here //sqlite save var myanimallist = new List <Animal>(); ISQLiteConnection conn = null; ISQLiteConnection connactiond = null; ISQLiteConnectionFactory factory = new MvxDroidSQLiteConnectionFactory(); ISQLiteConnectionFactory factoryd = new MvxDroidSQLiteConnectionFactory(); var sqlitedir = new Java.IO.File(global::Android.OS.Environment.GetExternalStoragePublicDirectory(global::Android.OS.Environment.DirectoryPictures), "Boruto"); string filenameaction = sqlitedir.Path + "/mysqliteaction.db"; connactiond = factoryd.Create(filenameaction); connactiond.CreateTable <MyCheckbox>(); connactiond.CreateCommand("DELETE FROM MyCheckbox").ExecuteNonQuery(); connactiond.Dispose(); connactiond.Commit(); connactiond.Close(); if (File.Exists(filenameaction)) { File.Delete(filenameaction); } string filename = sqlitedir.Path + "/mysqliteimage.db"; //Toast.MakeText(Application.Context, filename, ToastLength.Long).Show(); conn = factory.Create(filename); conn.CreateTable <Myimage>(); var countidx = 0; foreach (var e in conn.Table <Myimage>().Where(e => e.Date == "30-12-2016")) { var mystrarray = e.Imagepath.Split('/'); var myeleidx = mystrarray.Length - 1; var newanialele = new Animal() { Name = mystrarray[myeleidx], Description = e.Imagepath, Image = e.Imagepath, Mycheckbox = countidx }; myanimallist.Add(newanialele); countidx++; } //Toast.MakeText(this, mycount.ToString(), ToastLength.Short).Show(); conn.Close(); this.items = myanimallist; //sqlite save end }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); //Set the Activity's view to our list layout SetContentView(Resource.Layout.ListActivity); //sqlite for sas azure ISQLiteConnection conn = null; ISQLiteConnectionFactory factory = new MvxDroidSQLiteConnectionFactory(); var sqlitedir = new Java.IO.File(global::Android.OS.Environment.GetExternalStoragePublicDirectory(global::Android.OS.Environment.DirectoryPictures), "Boruto"); string filenameaction = sqlitedir.Path + "/mysqlitesas.db"; string filenameactionazure = sqlitedir.Path + "/mysqlitesasazure.db"; conn = factory.Create(filenameaction); conn.CreateTable <Azurecon>(); var myuserid = ""; foreach (var e in conn.Table <Azurecon>()) { myuserid = e.UserId; } conn.Close(); //sqlite for sas azure end //Create our adapter listAdapter = new CustomListAdapter(this); //Find the listview reference var listView = FindViewById <ListView>(Resource.Id.listView); //Hook up our adapter to our ListView listView.Adapter = listAdapter; //Wire up the click event //listView.ItemClick += new EventHandler<ItemEventArgs>(listView_ItemClick); Button deleteselectedfiles = FindViewById <Button>(Resource.Id.deleteselectfiles); deleteselectedfiles.Click += async delegate { //Delete files in sqlite table MyImage and in sdcard var myfiledir = new Java.IO.File(global::Android.OS.Environment.GetExternalStoragePublicDirectory(global::Android.OS.Environment.DirectoryPictures), "Boruto"); ISQLiteConnection conncf = null; ISQLiteConnection connactiondf = null; ISQLiteConnectionFactory factorydf = new MvxDroidSQLiteConnectionFactory(); string sqlfilenamed = sqlitedir.Path + "/mysqliteaction.db"; //Toast.MakeText(Application.Context, filename, ToastLength.Long).Show(); connactiondf = factorydf.Create(sqlfilenamed); connactiondf.CreateTable <MyCheckbox>(); List <string> myCollection = new List <string>(); var countidx = 0; HashSet <string> myimgspath = new HashSet <string>(); foreach (var e in connactiondf.Table <MyCheckbox>()) { string imgfilename = "file://" + sqlitedir.Path + "/" + e.Name; myimgspath.Add(imgfilename); var myfilepath = myfiledir + "/" + e.Name; if (File.Exists(myfilepath)) { File.Delete(myfilepath); } } connactiondf.Close(); List <string> myimglistdeletecmd = new List <string>(); var myvaridx = 0; foreach (string permyimg in myimgspath) { var myquerycmd = "Delete from Myimage where Imagepath = '" + permyimg + "'"; myimglistdeletecmd.Add(myquerycmd); } ISQLiteConnection connactioncf = null; ISQLiteConnectionFactory factorycf = new MvxDroidSQLiteConnectionFactory(); var sqlitedirc = new Java.IO.File(global::Android.OS.Environment.GetExternalStoragePublicDirectory(global::Android.OS.Environment.DirectoryPictures), "Boruto"); string filenameactionc = sqlitedirc.Path + "/mysqliteimage.db"; connactioncf = factorycf.Create(filenameactionc); connactioncf.CreateTable <Myimage>(); //var permyimgfile = new Myimage(){Date = "30-12-2016",Imagepath = myimgfile}; //myconn.CreateCommand("Delete from Myimage where Imagepath ='" + myimgfile + "'"); //myconn.Dispose(); //myconn.Commit(); //connactioncf.CreateCommand("Delete from Myimage where Imagepath ='" + "file:///storage/emulated/0/Pictures/Boruto/myPhoto_69d38ce2-0a96-41ed-884d-021a24890f88.jpg" + "'").ExecuteNonQuery(); foreach (var cmd in myimglistdeletecmd) { connactioncf.CreateCommand(cmd).ExecuteNonQuery(); } connactioncf.Commit(); connactioncf.Close(); }; Button uploadtoazure = FindViewById <Button>(Resource.Id.uploadtoazure); uploadtoazure.Click += async delegate { uploadtoazure.Text = string.Format("{0} clicks!", count++); //Get userid from sqlite db file ISQLiteConnection connacc = null; ISQLiteConnectionFactory factoryacc = new MvxDroidSQLiteConnectionFactory(); var sqlitediracc = new Java.IO.File(global::Android.OS.Environment.GetExternalStoragePublicDirectory(global::Android.OS.Environment.DirectoryPictures), "Boruto"); string filenameactionacc = sqlitediracc.Path + "/mysqlitesas.db"; connacc = factoryacc.Create(filenameactionacc); connacc.CreateTable <Azurecon>(); var useridconnc = ""; foreach (var e in connacc.Table <Azurecon>()) { useridconnc = e.UserId; } connacc.Close(); //myuserid = "115708452302383620142"; var myurl = "http://93.118.34.239:8888/" + useridconnc; Uri azureuri = new Uri(myurl); HttpWebRequest request = new HttpWebRequest(azureuri); request.Method = "GET"; HttpWebResponse response = request.GetResponse() as HttpWebResponse; using (StreamReader sr = new StreamReader(response.GetResponseStream())) { string responseString = sr.ReadToEnd(); Toast.MakeText(this, "Connect SAS String:" + responseString, ToastLength.Short).Show(); try { await UseContainerSAS(responseString); } catch { } } }; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); /* * //Facebook login api * var auth = new OAuth2Authenticator( * clientId: "1270606036289960", * scope: "", * authorizeUrl: new Uri("https://m.facebook.com/dialog/oauth/"), * // redirectUrl: new Uri("http://www.facebook.com/connect/login_success.html")); * redirectUrl: new Uri("http://myjobupwork.com/fblogin/")); * * * //StartActivity (auth.GetUI(Application.Context)); * * auth.Completed += (sender, eventArgs) => * { * // We presented the UI, so it's up to us to dimiss it on iOS. * * * if (eventArgs.IsAuthenticated) * { * // Use eventArgs.Account to do wonderful things * * string access_token; * eventArgs.Account.Properties.TryGetValue("access_token", out access_token); * //Toast.MakeText(this, "Authenticate Token:" + access_token, ToastLength.Short).Show(); * var myurl = "https://graph.facebook.com/me?access_token=" + access_token; * Uri uri = new Uri(myurl); * HttpWebRequest request = new HttpWebRequest(uri); * request.Method = "GET"; * * * HttpWebResponse response = request.GetResponse() as HttpWebResponse; * using (StreamReader sr = new StreamReader(response.GetResponseStream())) * { * string responseString = sr.ReadToEnd(); * Newtonsoft.Json.Linq.JObject myjObject = Newtonsoft.Json.Linq.JObject.Parse(responseString); * var myid = (string)myjObject["id"]; * Toast.MakeText(this, "Your Facebook UserId:" + myid, ToastLength.Short).Show(); * * } * response.Close(); * } * }; */ /* * //Google Login * var auth = new OAuth2Authenticator(clientId: "544771199531-lfe6dn212h2ch38f5i4uaah5j7c2qs00.apps.googleusercontent.com", * scope: "https://www.googleapis.com/auth/userinfo.email", * authorizeUrl: new Uri("https://accounts.google.com/o/oauth2/auth"), * redirectUrl: new Uri("http://myjobupwork.com/ggplus/"), * getUsernameAsync: null); * * * auth.Completed += async (sender, e) => * { * if (!e.IsAuthenticated) * { * Toast.MakeText(this, "Fail to authenticate!", ToastLength.Short).Show(); * return; * } * string access_token; * e.Account.Properties.TryGetValue("access_token", out access_token); * * var myurl = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=" + access_token; * Uri uri = new Uri(myurl); * HttpWebRequest request = new HttpWebRequest(uri); * request.Method = "GET"; * * * HttpWebResponse response = request.GetResponse() as HttpWebResponse; * using (StreamReader sr = new StreamReader(response.GetResponseStream())) * { * string responseString = sr.ReadToEnd(); * Newtonsoft.Json.Linq.JObject myjObject = Newtonsoft.Json.Linq.JObject.Parse(responseString); * var myid = (string)myjObject["id"]; * ISQLiteConnection conn = null; * * ISQLiteConnectionFactory factory = new MvxDroidSQLiteConnectionFactory(); * * var sqlitedir = new Java.IO.File(global::Android.OS.Environment.GetExternalStoragePublicDirectory(global::Android.OS.Environment.DirectoryPictures), "Boruto"); * string filenameaction = sqlitedir.Path + "/mysqlitesas.db"; * * conn = factory.Create(filenameaction); * conn.CreateTable<Azurecon>(); * conn.DeleteAll<Azurecon>(); * conn.Insert(new Azurecon() { Sastring = "", UserType = "Google", UserId = myid }); * Toast.MakeText(this, "Your Google UserId:" + myid, ToastLength.Short).Show(); * conn.Close(); * } * response.Close(); * }; * * var intent = auth.GetUI(this); * StartActivity(intent); * * // Set our view from the "main" layout resource */ //login layout xml SetContentView(Resource.Layout.Main); Button buttonfacelogin = FindViewById <Button>(Resource.Id.buttonfacebooklogin); Button buttongooglelogin = FindViewById <Button>(Resource.Id.buttongooglelogin); buttonfacelogin.Click += delegate { //Facebook login api var auth = new OAuth2Authenticator( clientId: "1270606036289960", scope: "email", authorizeUrl: new Uri("https://m.facebook.com/dialog/oauth/"), // redirectUrl: new Uri("http://www.facebook.com/connect/login_success.html")); redirectUrl: new Uri("http://myjobupwork.com/fblogin/")); //StartActivity (auth.GetUI(Application.Context)); auth.Completed += (sender, eventArgs) => { // We presented the UI, so it's up to us to dimiss it on iOS. if (!eventArgs.IsAuthenticated) { Toast.MakeText(this, "Fail to authenticate!", ToastLength.Short).Show(); return; } if (eventArgs.IsAuthenticated) { // Use eventArgs.Account to do wonderful things string access_token; eventArgs.Account.Properties.TryGetValue("access_token", out access_token); //Toast.MakeText(this, "Authenticate Token:" + access_token, ToastLength.Short).Show(); var myurl = "https://graph.facebook.com/me?fields=id,email&access_token=" + access_token; Uri uri = new Uri(myurl); HttpWebRequest request = new HttpWebRequest(uri); request.Method = "GET"; HttpWebResponse response = request.GetResponse() as HttpWebResponse; using (StreamReader sr = new StreamReader(response.GetResponseStream())) { string responseString = sr.ReadToEnd(); Newtonsoft.Json.Linq.JObject myjObject = Newtonsoft.Json.Linq.JObject.Parse(responseString); var myid = (string)myjObject["id"]; var myemail = (string)myjObject["email"]; var myurlui = "https://graph.facebook.com/me/permissions" + "?fields=id,email" + "&access_token=" + access_token; ISQLiteConnection conn = null; ISQLiteConnectionFactory factory = new MvxDroidSQLiteConnectionFactory(); var sqlitedir = new Java.IO.File(global::Android.OS.Environment.GetExternalStoragePublicDirectory(global::Android.OS.Environment.DirectoryPictures), "Boruto"); string filenameaction = sqlitedir.Path + "/mysqlitesas.db"; string myuseridfb = "fb" + myid; if (myemail.Length < 3) { myemail = myuseridfb; } conn = factory.Create(filenameaction); conn.CreateTable <Azurecon>(); //conn.CreateCommand("Delete from Azurecon").ExecuteNonQuery(); int countrow = 0; foreach (var eu in conn.Table <Azurecon>().Where(eu => eu.UserType == "Facebook")) { countrow++; } if (countrow > 0) { conn.CreateCommand("Update Azurecon set Sastring = '' where UserType='Google'").ExecuteNonQuery(); conn.CreateCommand("Update Azurecon set UserId = '" + myemail + "' where UserType='Facebook'").ExecuteNonQuery(); } else { conn.Insert(new Azurecon() { Sastring = "", UserType = "Facebook", UserId = myemail }); } //conn.Insert(new Azurecon() { Sastring = "", UserType = "Facebook", UserId = myemail }); Toast.MakeText(this, "Your Facebook UserId:" + myemail, ToastLength.Short).Show(); //Create new container for Google userid var myemailtrim = myemail.Replace("@", ""); myemailtrim = myemailtrim.Replace(".", ""); string myauzreafaceusercon = "http://93.118.34.239:8888/createcon/" + myemailtrim; var browser = new WebView(Application.Context); browser.LoadUrl(myauzreafaceusercon); conn.Close(); } response.Close(); SetContentView(Resource.Layout.Main1); Button button = FindViewById <Button>(Resource.Id.button); Button showlistbutton = FindViewById <Button>(Resource.Id.mylist); //Button uploadtoazure = FindViewById<Button>(Resource.Id.); button.Click += (s, e) => doTakePhotoAction(); showlistbutton.Click += delegate { StartActivity(typeof(MyListviewActivity)); }; Button showauzreimagebutton = FindViewById <Button>(Resource.Id.azureimagelist); showauzreimagebutton.Click += delegate { StartActivity(typeof(AzureActivity)); }; } }; ISQLiteConnection connch = null; ISQLiteConnectionFactory factorych = new MvxDroidSQLiteConnectionFactory(); var sqlitedirch = new Java.IO.File(global::Android.OS.Environment.GetExternalStoragePublicDirectory(global::Android.OS.Environment.DirectoryPictures), "Boruto"); string filenameactionch = sqlitedirch.Path + "/mysqlitesas.db"; connch = factorych.Create(filenameactionch); connch.CreateTable <Azurecon>(); //conn.CreateCommand("Delete from Azurecon").ExecuteNonQuery(); int countrowch = 0; foreach (var euch in connch.Table <Azurecon>().Where(euch => euch.UserType == "Facebook")) { countrowch++; } if (countrowch > 0) { connch.CreateCommand("Update Azurecon set Sastring = '' where UserType='Google'").ExecuteNonQuery(); connch.CreateCommand("Update Azurecon set Sastring = 'using' where UserType='Facebook'").ExecuteNonQuery(); SetContentView(Resource.Layout.Main1); Button button = FindViewById <Button>(Resource.Id.button); Button showlistbutton = FindViewById <Button>(Resource.Id.mylist); //Button uploadtoazure = FindViewById<Button>(Resource.Id.); button.Click += (s, e) => doTakePhotoAction(); showlistbutton.Click += delegate { StartActivity(typeof(MyListviewActivity)); }; Button showauzreimagebutton = FindViewById <Button>(Resource.Id.azureimagelist); showauzreimagebutton.Click += delegate { StartActivity(typeof(AzureActivity)); }; } else { var intent = auth.GetUI(this); StartActivity(intent); } }; buttongooglelogin.Click += delegate { //Google Login var auth = new OAuth2Authenticator(clientId: "544771199531-lfe6dn212h2ch38f5i4uaah5j7c2qs00.apps.googleusercontent.com", scope: "https://www.googleapis.com/auth/userinfo.email", authorizeUrl: new Uri("https://accounts.google.com/o/oauth2/auth"), redirectUrl: new Uri("http://myjobupwork.com/ggplus/"), getUsernameAsync: null); auth.Completed += async(sender, e) => { if (!e.IsAuthenticated) { Toast.MakeText(this, "Fail to authenticate!", ToastLength.Short).Show(); return; //SetContentView(Resource.Layout.Main); } else { string access_token; e.Account.Properties.TryGetValue("access_token", out access_token); var myurl = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=" + access_token; Uri uri = new Uri(myurl); HttpWebRequest request = new HttpWebRequest(uri); request.Method = "GET"; HttpWebResponse response = request.GetResponse() as HttpWebResponse; using (StreamReader sr = new StreamReader(response.GetResponseStream())) { string responseString = sr.ReadToEnd(); Newtonsoft.Json.Linq.JObject myjObject = Newtonsoft.Json.Linq.JObject.Parse(responseString); var myid = (string)myjObject["id"]; var myemail = (string)myjObject["email"]; ISQLiteConnection conn = null; ISQLiteConnectionFactory factory = new MvxDroidSQLiteConnectionFactory(); var sqlitedir = new Java.IO.File(global::Android.OS.Environment.GetExternalStoragePublicDirectory(global::Android.OS.Environment.DirectoryPictures), "Boruto"); string filenameaction = sqlitedir.Path + "/mysqlitesas.db"; conn = factory.Create(filenameaction); conn.CreateTable <Azurecon>(); int countrow = 0; foreach (var eu in conn.Table <Azurecon>().Where(eu => eu.UserType == "Google")) { countrow++; } if (countrow > 0) { conn.CreateCommand("Update Azurecon set Sastring = '' where UserType='Facebook'").ExecuteNonQuery(); conn.CreateCommand("Update Azurecon set Sastring = 'using',UserId = '" + myemail + "' where UserType='Google'").ExecuteNonQuery(); } else { conn.Insert(new Azurecon() { Sastring = "", UserType = "Google", UserId = myemail }); } //get googleuser email Toast.MakeText(this, "Your Google UserId:" + myemail, ToastLength.Short).Show(); //Create new container for Google userid var myemailtrim = myemail.Replace("@", ""); myemailtrim = myemailtrim.Replace(".", ""); string myauzregoogleusercon = "http://93.118.34.239:8888/createcon/" + myemailtrim; var browser = new WebView(Application.Context); browser.LoadUrl(myauzregoogleusercon); conn.Close(); } response.Close(); SetContentView(Resource.Layout.Main1); Button button = FindViewById <Button>(Resource.Id.button); Button showlistbutton = FindViewById <Button>(Resource.Id.mylist); //Button uploadtoazure = FindViewById<Button>(Resource.Id.); button.Click += (s, ea) => doTakePhotoAction(); showlistbutton.Click += delegate { StartActivity(typeof(MyListviewActivity)); }; Button showauzreimagebutton = FindViewById <Button>(Resource.Id.azureimagelist); showauzreimagebutton.Click += delegate { StartActivity(typeof(AzureActivity)); }; } }; ISQLiteConnection connch = null; ISQLiteConnectionFactory factorych = new MvxDroidSQLiteConnectionFactory(); var sqlitedirch = new Java.IO.File(global::Android.OS.Environment.GetExternalStoragePublicDirectory(global::Android.OS.Environment.DirectoryPictures), "Boruto"); string filenameactionch = sqlitedirch.Path + "/mysqlitesas.db"; connch = factorych.Create(filenameactionch); connch.CreateTable <Azurecon>(); //conn.CreateCommand("Delete from Azurecon").ExecuteNonQuery(); int countrowch = 0; foreach (var euch in connch.Table <Azurecon>().Where(euch => euch.UserType == "Google")) { countrowch++; } if (countrowch > 0) { connch.CreateCommand("Update Azurecon set Sastring = '' where UserType='Facebook'").ExecuteNonQuery(); connch.CreateCommand("Update Azurecon set Sastring = 'using' where UserType='Google'").ExecuteNonQuery(); SetContentView(Resource.Layout.Main1); Button button = FindViewById <Button>(Resource.Id.button); Button showlistbutton = FindViewById <Button>(Resource.Id.mylist); //Button uploadtoazure = FindViewById<Button>(Resource.Id.); button.Click += (s, e) => doTakePhotoAction(); showlistbutton.Click += delegate { StartActivity(typeof(MyListviewActivity)); }; Button showauzreimagebutton = FindViewById <Button>(Resource.Id.azureimagelist); showauzreimagebutton.Click += delegate { StartActivity(typeof(AzureActivity)); }; } else { var intent = auth.GetUI(this); StartActivity(intent); } }; // Get our button from the layout resource, // and attach an event to it /* * SetContentView(Resource.Layout.Main1); * Button buttonmain = FindViewById<Button>(Resource.Id.button); * Button showlistbuttonmain = FindViewById<Button>(Resource.Id.mylist); * //Button uploadtoazure = FindViewById<Button>(Resource.Id.); * buttonmain.Click += (s, e) => doTakePhotoAction(); * showlistbuttonmain.Click += delegate * { * StartActivity(typeof(MyListviewActivity)); * }; * Button showauzreimagebuttonmain = FindViewById<Button>(Resource.Id.azureimagelist); * showauzreimagebuttonmain.Click += delegate * { * StartActivity(typeof(AzureActivity)); * }; * */ }