public void ShouldThrowArgumentExceptionOnCreateGivenOptionsWithNullAddressAndTypeFile() { // Items Needing Cleanup ISQLiteConnection conn = null; try { // Arrange #if __IOS__ ISQLiteConnectionFactoryEx factory = new MvxTouchSQLiteConnectionFactory(); #elif __ANDROID__ ISQLiteConnectionFactoryEx factory = new MvxDroidSQLiteConnectionFactory(); #else ISQLiteConnectionFactoryEx factory = new MvxWpfSqLiteConnectionFactory(); #endif SQLiteConnectionOptions options = new SQLiteConnectionOptions { Address = null, Type = SQLiteConnectionOptions.DatabaseType.File }; // Act conn = factory.CreateEx(options); } finally // Cleanup in Finally { if (conn != null) // In case test fails and connection was created { conn.Close(); } } }
public void ShouldThrowArgumentNullExceptionOnCreateGivenNullOptions() { // Items Needing Cleanup ISQLiteConnection conn = null; try { // Arrange #if __IOS__ ISQLiteConnectionFactoryEx factory = new MvxTouchSQLiteConnectionFactory(); #elif __ANDROID__ ISQLiteConnectionFactoryEx factory = new MvxDroidSQLiteConnectionFactory(); #else ISQLiteConnectionFactoryEx factory = new MvxWpfSqLiteConnectionFactory(); #endif // Act conn = factory.CreateEx(null); } finally // Cleanup in Finally { if (conn != null) // In case test fails and connection was created { conn.Close(); } } }
private void saveOutput(Bitmap croppedImage) { if (saveUri != null) { try { using (var outputStream = ContentResolver.OpenOutputStream(saveUri)) { if (outputStream != null) { croppedImage.Compress(outputFormat, 75, outputStream); } } } catch (Exception ex) { Log.Error(this.GetType().Name, ex.Message); } Bundle extras = new Bundle(); SetResult(Result.Ok, new Intent(saveUri.ToString()) .PutExtras(extras)); } else { Log.Error(this.GetType().Name, "not defined image url"); } //sqlite save 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 filename = sqlitedir.Path + "/mysqliteimage.db"; //Toast.MakeText(Application.Context, filename, ToastLength.Long).Show(); Java.IO.File f = new Java.IO.File(filename); conn = factory.Create(filename); conn.CreateTable <Myimage>(); conn.Insert(new Myimage() { Date = "30-12-2016", Imagepath = saveUri.ToString() }); var mycount = 0; foreach (var e in conn.Table <Myimage>().Where(e => e.Date == "30-12-2016")) { mycount++; } //Toast.MakeText(this, mycount.ToString(), ToastLength.Short).Show(); conn.Close(); //sqlite save end croppedImage.Recycle(); Finish(); }
public void CloseQueryLogSqliteConnection(ISQLiteConnection conn) { if (isPoolingEnabled) { logPool.CloseSqliteConnection(conn); } else { conn.Close(); } }
public void CloseSqliteConnection(ISQLiteConnection conn) { if (isPoolingEnabled) { mainPool.CloseSqliteConnection(conn); } else { conn.Close(); } }
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 }
public void ShouldCreateFileDatabase() { // Items Needing Cleanup ISQLiteConnection conn = null; string expectedFilePath = null; try { // Arrange #if __IOS__ ISQLiteConnectionFactory factory = new MvxTouchSQLiteConnectionFactory(); #elif __ANDROID__ ISQLiteConnectionFactory factory = new MvxDroidSQLiteConnectionFactory(); #else ISQLiteConnectionFactory factory = new MvxWpfSqLiteConnectionFactory(); #endif string filename = Guid.NewGuid().ToString() + ".db"; #if __IOS__ || __ANDROID__ expectedFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), filename); #else expectedFilePath = Path.Combine(Directory.GetCurrentDirectory(), filename); #endif // Act conn = factory.Create(filename); conn.CreateTable <Person>(); conn.Insert(new Person() { FirstName = "Bob", LastName = "Smith" }); Person expected = conn.Table <Person>().FirstOrDefault(); // Asset Assert.That(File.Exists(expectedFilePath), Is.True); Assert.That(expected.FirstName, Is.EqualTo("Bob")); Assert.That(expected.LastName, Is.EqualTo("Smith")); } finally // Cleanup in Finally { if (conn != null) { conn.Close(); } if (!string.IsNullOrWhiteSpace(expectedFilePath) && File.Exists(expectedFilePath)) { File.Delete(expectedFilePath); } } }
public void ShouldCreateInMemoryDatabase() { // Items Needing Cleanup ISQLiteConnection conn = null; try { // Arrange #if __IOS__ ISQLiteConnectionFactory factory = new MvxTouchSQLiteConnectionFactory(); #elif __ANDROID__ ISQLiteConnectionFactory factory = new MvxDroidSQLiteConnectionFactory(); #else ISQLiteConnectionFactory factory = new MvxWpfSqLiteConnectionFactory(); #endif // Act conn = factory.CreateInMemory(); conn.CreateTable <Person>(); conn.Insert(new Person() { FirstName = "Bob", LastName = "Smith" }); Person expected = conn.Table <Person>().FirstOrDefault(); // Asset Assert.That(expected.FirstName, Is.EqualTo("Bob")); Assert.That(expected.LastName, Is.EqualTo("Smith")); } finally // Cleanup in Finally { if (conn != null) { conn.Close(); } } }
public AzureListAdapter(Activity context) //We need a context to inflate our row view from : base() { this.context = context; //Get list Blob Images from Azure host //Get userid from sqlite 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>(); foreach (var e in conn.Table <Azurecon>()) { myuseridazure = e.UserId; } //Toast.MakeText(this, "Your Google UserId:" + myuseridazure, ToastLength.Short).Show(); conn.Close(); //var myurl = "http://93.118.34.239:8888/listblobs/" + myuseridazure; var myurl = "http://93.118.34.239:8888/listblobs/115708452302383620142"; Uri azureuri = new Uri(myurl); var myanimallist = new List <Animal>(); //Toast.MakeText(this, "Connect SAS String:" + myurl, ToastLength.Short).Show(); /* * HttpWebRequest request = new HttpWebRequest(azureuri); * request.Method = "GET"; * * * HttpWebResponse response = request.GetResponse() as HttpWebResponse; * var myanimallist = new List<Animal>(); * using (StreamReader sr = new StreamReader(response.GetResponseStream())) * { * * string responseString = sr.ReadToEnd(); * * JArray bloburlarr = JArray.Parse(responseString); * var countidx = 0; * foreach (var perlurl in bloburlarr) * { * var newanialele = new Animal() { Name = "Test Azure", Description = perlurl["imgname"].ToString(), Image = "Test Path", Mycheckbox = countidx }; * countidx++; * myanimallist.Add(newanialele); * } * * * * this.items = myanimallist; * } */ string auzremainurl = "https://spc.blob.core.windows.net/"; string usercontainer = ""; //Get SAS connection string 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>(); foreach (var e in connacc.Table <Azurecon>().Where(e => e.Sastring == "using")) { usercontainer = e.UserId; } connacc.Close(); usercontainer = usercontainer.Replace("@", ""); usercontainer = usercontainer.Replace(".", ""); string azureurltoken = "http://93.118.34.239:8888/gettoken/" + usercontainer; var clienttk = new RestClient(azureurltoken); var requesttk = new RestRequest(); IRestResponse responsetk = clienttk.Execute(requesttk); var myjsonstrtk = responsetk.Content; //End Get SAS connection string var client = new RestClient("http://93.115.97.151/azureservice/list.php?action=list&containerid=" + usercontainer); var request = new RestRequest(); IRestResponse response = client.Execute(request); var myjsonstr = response.Content; JArray bloburlarr = JArray.Parse(myjsonstr); var countidx = 0; HashSet <string> myazureimagelist = new HashSet <string>(); foreach (var perlurl in bloburlarr) { myazureimagelist.Add(perlurl["imgname"].ToString()); //myazureimagenamelist.Add(perlurl["imgfilename"].ToString()); /* * var newanialele = new Animal() { Name = "Test Azure", Description = perlurl["imgname"].ToString(), Image = "Test Path", Mycheckbox = countidx }; * countidx++; * myanimallist.Add(newanialele); * */ } foreach (var perlurlh in myazureimagelist) { string mymainazureurl = auzremainurl + usercontainer + "/" + perlurlh + "?" + myjsonstrtk; //Toast.MakeText(Application.Context, "Connect SAS String:" + mymainazureurl, ToastLength.Short).Show(); var newanialele = new Animal() { Name = "Test Azure", Description = mymainazureurl, Image = "Test Path", Mycheckbox = countidx }; countidx++; myanimallist.Add(newanialele); } this.items = myanimallist; }
public override View GetView(int position, View convertView, ViewGroup parent) { //Get our object for this position var item = items[position]; //Try to reuse convertView if it's not null, otherwise inflate it from our item layout // This gives us some performance gains by not always inflating a new view // This will sound familiar to MonoTouch developers with UITableViewCell.DequeueReusableCell() var view = (convertView ?? context.LayoutInflater.Inflate( Resource.Layout.MyListRows, parent, false)) as LinearLayout; //Find references to each subview in the list item's view var imageItem = view.FindViewById(Resource.Id.imageItem) as ImageView; var textTop = view.FindViewById(Resource.Id.textTop) as TextView; var textBottom = view.FindViewById(Resource.Id.textBottom) as TextView; var mycheckbox = view.FindViewById(Resource.Id.CheckboxItem) as CheckBox; mycheckbox.Text = item.Name; mycheckbox.Click += (o, e) => { if (mycheckbox.Checked) { var mycbitemid = mycheckbox.Text; Toast.MakeText(Application.Context, mycbitemid, ToastLength.Short).Show(); ISQLiteConnection connactionc = null; ISQLiteConnectionFactory factoryc = new MvxDroidSQLiteConnectionFactory(); var sqlitedir = new Java.IO.File(global::Android.OS.Environment.GetExternalStoragePublicDirectory(global::Android.OS.Environment.DirectoryPictures), "Boruto"); string filename = sqlitedir.Path + "/mysqliteaction.db"; //Toast.MakeText(Application.Context, filename, ToastLength.Long).Show(); connactionc = factoryc.Create(filename); connactionc.CreateTable <MyCheckbox>(); connactionc.Insert(new MyCheckbox() { Name = mycbitemid }); connactionc.Close(); //var mycbitemid = mycheckbox.Text; //myCollection.Add(mycbitemid); //Toast.MakeText(Application.Context, myCollection.Count.ToString(), ToastLength.Short).Show(); } }; //Assign this item's values to the various subviews //Bitmap bitmap; //bitmap = BitmapFactory.DecodeFile(item.Image); // First we get the the dimensions of the file on disk //var myuri = getImageUri(item.Description); //Uri contentUri = Uri.FromFile(myimgfile); Koush.UrlImageViewHelper.SetUrlDrawable(imageItem, item.Image); //Koush.UrlImageViewHelper.SetUrlDrawable(imageItem, "https://s.gravatar.com/avatar/7d1f32b86a6076963e7beab73dddf7ca?s=300"); //imageItem.SetImageBitmap(resizedBitmap); //imageItem.SetImageBitmap(resizedBitmap); textTop.SetText(item.Name, TextView.BufferType.Normal); //textBottom.SetText(item.Description, TextView.BufferType.Normal); textBottom.SetText(item.Description, TextView.BufferType.Normal); //Finally return the view return(view); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); RequestWindowFeature(Android.Views.WindowFeatures.NoTitle); SetContentView(Resource.Layout.cropimage); imageView = FindViewById <CropImageView>(Resource.Id.image); showStorageToast(this); Bundle extras = Intent.Extras; if (extras != null) { imagePath = extras.GetString("image-path"); saveUri = getImageUri(imagePath); if (extras.GetString(MediaStore.ExtraOutput) != null) { saveUri = getImageUri(extras.GetString(MediaStore.ExtraOutput)); } bitmap = getBitmap(imagePath); aspectX = extras.GetInt("aspectX"); aspectY = extras.GetInt("aspectY"); outputX = extras.GetInt("outputX"); outputY = extras.GetInt("outputY"); scale = extras.GetBoolean("scale", true); scaleUp = extras.GetBoolean("scaleUpIfNeeded", true); if (extras.GetString("outputFormat") != null) { outputFormat = Bitmap.CompressFormat.ValueOf(extras.GetString("outputFormat")); } } if (bitmap == null) { Finish(); return; } Window.AddFlags(WindowManagerFlags.Fullscreen); FindViewById <Button>(Resource.Id.discard).Click += (sender, e) => { SetResult(Result.Canceled); Finish(); }; //FindViewById<Button>(Resource.Id.save).Click += async delegate { onSaveClicked(); }; FindViewById <Button>(Resource.Id.save).Click += async delegate { if (Saving) { return; } Saving = true; var r = Crop.CropRect; int width = r.Width(); int height = r.Height(); Bitmap croppedImage = Bitmap.CreateBitmap(width, height, Bitmap.Config.Rgb565); { Canvas canvas = new Canvas(croppedImage); Rect dstRect = new Rect(0, 0, width, height); canvas.DrawBitmap(bitmap, r, dstRect, null); } // If the output is required to a specific size then scale or fill if (outputX != 0 && outputY != 0) { if (scale) { // Scale the image to the required dimensions Bitmap old = croppedImage; croppedImage = Util.transform(new Matrix(), croppedImage, outputX, outputY, scaleUp); if (old != croppedImage) { old.Recycle(); } } else { // Don't scale the image crop it to the size requested. // Create an new image with the cropped image in the center and // the extra space filled. Bitmap b = Bitmap.CreateBitmap(outputX, outputY, Bitmap.Config.Rgb565); Canvas canvas = new Canvas(b); Rect srcRect = Crop.CropRect; Rect dstRect = new Rect(0, 0, outputX, outputY); int dx = (srcRect.Width() - dstRect.Width()) / 2; int dy = (srcRect.Height() - dstRect.Height()) / 2; // If the srcRect is too big, use the center part of it. srcRect.Inset(Math.Max(0, dx), Math.Max(0, dy)); // If the dstRect is too big, use the center part of it. dstRect.Inset(Math.Max(0, -dx), Math.Max(0, -dy)); // Draw the cropped bitmap in the center canvas.DrawBitmap(bitmap, srcRect, dstRect, null); // Set the cropped bitmap as the new bitmap croppedImage.Recycle(); croppedImage = b; } } // Return the cropped image directly or save it to the specified URI. Bundle myExtras = Intent.Extras; if (myExtras != null && (myExtras.GetParcelable("data") != null || myExtras.GetBoolean("return-data"))) { Bundle extrasas = new Bundle(); extras.PutParcelable("data", croppedImage); SetResult(Result.Ok, (new Intent()).SetAction("inline-data").PutExtras(extrasas)); Finish(); } else { //Toast.MakeText(Application.Context, saveUri.ToString(), ToastLength.Long).Show(); //Toast.MakeText(Application.Context, "Upload Complete", ToastLength.Long).Show(); //Upload to Azure 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 eu in connacc.Table <Azurecon>().Where(eu => eu.Sastring == "using")) { useridconnc = eu.UserId; } connacc.Close(); //myuserid = "115708452302383620142"; useridconnc = useridconnc.Replace("@", ""); useridconnc = useridconnc.Replace(".", ""); 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; try { using (StreamReader sr = new StreamReader(response.GetResponseStream())) { string responseString = sr.ReadToEnd(); Toast.MakeText(this, saveUri.ToString(), ToastLength.Short).Show(); try { await UseContainerSAS(responseString, saveUri.ToString()); } catch { } } } catch { } //End Upload to Azure Bitmap b = croppedImage; BackgroundJob.StartBackgroundJob(this, null, "Saving image", () => saveOutput(b), mHandler); } }; FindViewById <Button>(Resource.Id.rotateLeft).Click += (o, e) => { bitmap = Util.rotateImage(bitmap, -90); RotateBitmap rotateBitmap = new RotateBitmap(bitmap); imageView.SetImageRotateBitmapResetBase(rotateBitmap, true); addHighlightView(); }; FindViewById <Button>(Resource.Id.rotateRight).Click += (o, e) => { bitmap = Util.rotateImage(bitmap, 90); RotateBitmap rotateBitmap = new RotateBitmap(bitmap); imageView.SetImageRotateBitmapResetBase(rotateBitmap, true); addHighlightView(); }; imageView.SetImageBitmapResetBase(bitmap, true); addHighlightView(); }
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 { } } }; }
static async Task UseContainerSAS(string sas) { //Toast toast1 = Toast.MakeText(Application.Context, "BBBBBBBBBBBBBBBBBBBBBBBBB", ToastLength.Short); //toast1.Show(); //Try performing container operations with the SAS provided. //Return a reference to the container using the SAS URI. //CloudStorageAccount account; CloudBlobContainer container = new CloudBlobContainer(new Uri(sas)); string date = DateTime.Now.ToString(); try { try { //MemoryStream memoryStream = new MemoryStream(); var sqlitedir = new Java.IO.File(global::Android.OS.Environment.GetExternalStoragePublicDirectory(global::Android.OS.Environment.DirectoryPictures), "Boruto"); //string filename = sqlitedir.Path + "/myPhoto_3c2e2adb-b374-466b-b32d-b1a2fdea65a0.jpg"; ISQLiteConnection connactionc = null; ISQLiteConnectionFactory factoryc = new MvxDroidSQLiteConnectionFactory(); string sqlfilename = sqlitedir.Path + "/mysqliteaction.db"; //Toast.MakeText(Application.Context, filename, ToastLength.Long).Show(); connactionc = factoryc.Create(sqlfilename); connactionc.CreateTable <MyCheckbox>(); List <string> myCollection = new List <string>(); var countidx = 0; foreach (var e in connactionc.Table <MyCheckbox>()) { string imgfilename = sqlitedir.Path + "/" + e.Name; myCollection.Add(imgfilename); Toast.MakeText(Application.Context, imgfilename, ToastLength.Short).Show(); using (FileStream fileStream = new FileStream(imgfilename, FileMode.Open, FileAccess.Read)) { MemoryStream memoryStream = new MemoryStream(); CloudBlockBlob blob = container.GetBlockBlobReference(e.Name); fileStream.CopyTo(memoryStream); memoryStream.Position = 0; Toast.MakeText(Application.Context, memoryStream.Length.ToString(), ToastLength.Short).Show(); using (memoryStream) { await blob.UploadFromStreamAsync(memoryStream); Toast toast = Toast.MakeText(Application.Context, "Upload Complete", ToastLength.Short); toast.Show(); } } countidx++; } connactionc.Close(); } catch (Java.Lang.Exception e) { } } catch (Java.Lang.Exception eerror) { } }
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)); * }; * */ }