private void sendTbListMsg(GalleryProviderConnection connection)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final TBListRespMsg uRMessage = new TBListRespMsg(mResult, mReason, mTb.size(), mTb);
            ImageFetchModelImpl.TBListRespMsg uRMessage = new ImageFetchModelImpl.TBListRespMsg(mResult, mReason, mTb.Count, mTb);
            string uJsonStringToSend = "";

            try
            {
                uJsonStringToSend = uRMessage.toJSON().ToString();
            }
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final org.json.JSONException e)
            catch (JSONException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            if (mConnectionsMap != null)
            {
                try
                {
                    connection.send(GALLERY_CHANNEL_ID, uJsonStringToSend.GetBytes());
                }
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final java.io.IOException e)
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                }
            }
        }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: private void onDataAvailableonChannel(final GalleryProviderConnection connection, final long channelId, final String data)
        private void onDataAvailableonChannel(GalleryProviderConnection connection, long channelId, string data)
        {
            mBackgroundHandler.post(() =>
            {
                if (data.Contains(Model.THUMBNAIL_LIST_REQ))
                {
                    sendThumbnails(connection, data);
                }
                else if (data.Contains(Model.DOWNSCALE_IMG_REQ))
                {
                    sendDownscaledImage(connection, data);
                }
            });
        }
        protected internal override void onServiceConnectionResponse(SAPeerAgent peerAgent, SASocket socket, int result)
        {
            if (result == CONNECTION_SUCCESS && socket != null)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final GalleryProviderConnection myConnection = (GalleryProviderConnection) socket;
                GalleryProviderConnection myConnection = (GalleryProviderConnection)socket;
                if (mConnectionsMap == null)
                {
                    mConnectionsMap = new SparseArray <GalleryProviderConnection>();
                }
                myConnection.mConnectionId = (int)(DateTimeHelperClass.CurrentUnixTimeMillis() & 255);
                mConnectionsMap.put(myConnection.mConnectionId, myConnection);
                mBackgroundHandler.post(() =>
                {
                    Toast.makeText(BaseContext, [email protected], Toast.LENGTH_SHORT).show();
                });
            }
        }
        private void sendImgRsp(GalleryProviderConnection connection, long id, string orgName, long orgSize, int orgWidth, int orgHeight)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final TBModelJson msg = new TBModelJson(id, orgName, mImgData, orgSize, orgWidth, orgHeight);
            ImageFetchModelImpl.TBModelJson msg = new ImageFetchModelImpl.TBModelJson(id, orgName, mImgData, orgSize, orgWidth, orgHeight);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ImgRespMsg uresponse = new ImgRespMsg(mResult, mReason, msg);
            ImageFetchModelImpl.ImgRespMsg uresponse = new ImageFetchModelImpl.ImgRespMsg(mResult, mReason, msg);
            string uJsonStringToSend = "";

            try
            {
                uJsonStringToSend = uresponse.toJSON().ToString();
            }
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final org.json.JSONException e)
            catch (JSONException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            if (mConnectionsMap != null)
            {
                try
                {
                    connection.send(GALLERY_CHANNEL_ID, uJsonStringToSend.GetBytes());
                }
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final java.io.IOException e)
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                }
            }
        }
        private void sendDownscaledImage(GalleryProviderConnection connection, string request)
        {
            // put a upper cap like say 320x240 for image
            mImgData = "";
            mResult  = "failure";
            mReason  = REASON_IMAGE_ID_INVALID;
            int        orgWidth = 0, orgHeight = 0;
            long       orgSize = 0;
            string     orgName = "";
            JSONObject obj     = null;

            try
            {
                obj = new JSONObject(request);
            }
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final org.json.JSONException e)
            catch (JSONException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                return;
            }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ImgReqMsg uMessage = new ImgReqMsg();
            ImageFetchModelImpl.ImgReqMsg uMessage = new ImageFetchModelImpl.ImgReqMsg();
            try
            {
                uMessage.fromJSON(obj);
            }
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final org.json.JSONException e)
            catch (JSONException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                return;
            }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long id = uMessage.getID();
            long id = uMessage.ID;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int width = uMessage.getWidth();
            int width = uMessage.Width;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int height = uMessage.getHeight();
            int    height      = uMessage.Height;
            Cursor imageCursor = ContentResolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, mProjection, MediaStore.Images.Media._ID + " = " + id, null, null);

            if (imageCursor != null && imageCursor.moveToFirst())
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String path = imageCursor.getString(imageCursor.getColumnIndex(android.provider.MediaStore.Images.Media.DATA));
                string path = imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DATA));
                orgWidth  = imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media.WIDTH));
                orgHeight = imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media.HEIGHT));
                orgName   = imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME));
                orgSize   = imageCursor.getLong(imageCursor.getColumnIndex(MediaStore.Images.Media.SIZE));
                if (!imageCursor.Closed)
                {
                    imageCursor.close();
                }
                pullDownscaledImg(path, width, height);
            }
            else
            {
                mResult = "failure";
                mReason = REASON_IMAGE_ID_INVALID;
            }
            sendImgRsp(connection, id, orgName, orgSize, orgWidth, orgHeight);
        }
        private void sendThumbnails(GalleryProviderConnection connection, string request)
        {
            bool ret = true;

            mResult = "failure";
            mReason = REASON_IMAGE_ID_INVALID;
            int count = 0;

            if (mTb.Count > 0)
            {
                mTb.Clear();
            }
            JSONObject obj = null;

            try
            {
                obj = new JSONObject(request);
            }
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final org.json.JSONException e)
            catch (JSONException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                return;
            }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final TBListReqMsg uRequest = new TBListReqMsg();
            ImageFetchModelImpl.TBListReqMsg uRequest = new ImageFetchModelImpl.TBListReqMsg();
            try
            {
                uRequest.fromJSON(obj);
            }
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final org.json.JSONException e)
            catch (JSONException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                return;
            }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long id = uRequest.getID();
            long   id          = uRequest.ID;
            Cursor imageCursor = ContentResolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, mProjection, null, null, null);

            if (imageCursor == null)
            {
                mReason = REASON_DATABASE_ERROR;
                sendTbListMsg(connection);
                return;
            }
            imageCursor.moveToFirst();
            publishMediaStoreInfo(imageCursor);
            if (id != INITIAL_IMAGE_INDEX)
            {
                for (int i = 0; i < imageCursor.Count; i++)
                {
                    if (id == imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media._ID)))
                    {
                        ret = imageCursor.moveToNext();
                        break;
                    }
                    if (imageCursor.moveToNext() == false)
                    {
                        ret = false;
                        break;
                    }
                }
            }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int size = imageCursor.getCount();
            int size = imageCursor.Count;

            if ((ret == true) && (size > 0))
            {
                do
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final boolean status = pullThumbnails(imageCursor);
                    bool status = pullThumbnails(imageCursor);
                    if (status == true)
                    {
                        count++;
                    }
                } while (count < 3 && imageCursor.moveToNext());
                mResult = "success";
                mReason = REASON_OK;
            }             // check to ignore in case id is last record in DB
            else
            {
                mReason = REASON_EOF_IMAGE;
            }
            if (!imageCursor.Closed)
            {
                imageCursor.close();
            }
            sendTbListMsg(connection);
        }
		private void sendImgRsp(GalleryProviderConnection connection, long id, string orgName, long orgSize, int orgWidth, int orgHeight)
		{
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final TBModelJson msg = new TBModelJson(id, orgName, mImgData, orgSize, orgWidth, orgHeight);
			ImageFetchModelImpl.TBModelJson msg = new ImageFetchModelImpl.TBModelJson(id, orgName, mImgData, orgSize, orgWidth, orgHeight);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ImgRespMsg uresponse = new ImgRespMsg(mResult, mReason, msg);
			ImageFetchModelImpl.ImgRespMsg uresponse = new ImageFetchModelImpl.ImgRespMsg(mResult, mReason, msg);
			string uJsonStringToSend = "";
			try
			{
				uJsonStringToSend = uresponse.toJSON().ToString();
			}
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final org.json.JSONException e)
			catch (JSONException e)
			{
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
			}
			if (mConnectionsMap != null)
			{
				try
				{
					connection.send(GALLERY_CHANNEL_ID, uJsonStringToSend.GetBytes());
				}
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final java.io.IOException e)
				catch (IOException e)
				{
					Console.WriteLine(e.ToString());
					Console.Write(e.StackTrace);
				}
			}
		}
		private void sendDownscaledImage(GalleryProviderConnection connection, string request)
		{
			// put a upper cap like say 320x240 for image
			mImgData = "";
			mResult = "failure";
			mReason = REASON_IMAGE_ID_INVALID;
			int orgWidth = 0, orgHeight = 0;
			long orgSize = 0;
			string orgName = "";
			JSONObject obj = null;
			try
			{
				obj = new JSONObject(request);
			}
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final org.json.JSONException e)
			catch (JSONException e)
			{
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
				return;
			}
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ImgReqMsg uMessage = new ImgReqMsg();
			ImageFetchModelImpl.ImgReqMsg uMessage = new ImageFetchModelImpl.ImgReqMsg();
			try
			{
				uMessage.fromJSON(obj);
			}
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final org.json.JSONException e)
			catch (JSONException e)
			{
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
				return;
			}
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long id = uMessage.getID();
			long id = uMessage.ID;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int width = uMessage.getWidth();
			int width = uMessage.Width;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int height = uMessage.getHeight();
			int height = uMessage.Height;
			Cursor imageCursor = ContentResolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, mProjection, MediaStore.Images.Media._ID + " = " + id, null, null);
			if (imageCursor != null && imageCursor.moveToFirst())
			{
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String path = imageCursor.getString(imageCursor.getColumnIndex(android.provider.MediaStore.Images.Media.DATA));
				string path = imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DATA));
				orgWidth = imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media.WIDTH));
				orgHeight = imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media.HEIGHT));
				orgName = imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME));
				orgSize = imageCursor.getLong(imageCursor.getColumnIndex(MediaStore.Images.Media.SIZE));
				if (!imageCursor.Closed)
				{
					imageCursor.close();
				}
				pullDownscaledImg(path, width, height);
			}
			else
			{
				mResult = "failure";
				mReason = REASON_IMAGE_ID_INVALID;
			}
			sendImgRsp(connection, id, orgName, orgSize, orgWidth, orgHeight);
		}
		private void sendTbListMsg(GalleryProviderConnection connection)
		{
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final TBListRespMsg uRMessage = new TBListRespMsg(mResult, mReason, mTb.size(), mTb);
			ImageFetchModelImpl.TBListRespMsg uRMessage = new ImageFetchModelImpl.TBListRespMsg(mResult, mReason, mTb.Count, mTb);
			string uJsonStringToSend = "";
			try
			{
				uJsonStringToSend = uRMessage.toJSON().ToString();
			}
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final org.json.JSONException e)
			catch (JSONException e)
			{
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
			}
			if (mConnectionsMap != null)
			{
				try
				{
					connection.send(GALLERY_CHANNEL_ID, uJsonStringToSend.GetBytes());
				}
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final java.io.IOException e)
				catch (IOException e)
				{
					Console.WriteLine(e.ToString());
					Console.Write(e.StackTrace);
				}
			}
		}
		private void sendThumbnails(GalleryProviderConnection connection, string request)
		{
			bool ret = true;
			mResult = "failure";
			mReason = REASON_IMAGE_ID_INVALID;
			int count = 0;
			if (mTb.Count > 0)
			{
				mTb.Clear();
			}
			JSONObject obj = null;
			try
			{
				obj = new JSONObject(request);
			}
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final org.json.JSONException e)
			catch (JSONException e)
			{
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
				return;
			}
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final TBListReqMsg uRequest = new TBListReqMsg();
			ImageFetchModelImpl.TBListReqMsg uRequest = new ImageFetchModelImpl.TBListReqMsg();
			try
			{
				uRequest.fromJSON(obj);
			}
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final org.json.JSONException e)
			catch (JSONException e)
			{
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
				return;
			}
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long id = uRequest.getID();
			long id = uRequest.ID;
			Cursor imageCursor = ContentResolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, mProjection, null, null, null);
			if (imageCursor == null)
			{
				mReason = REASON_DATABASE_ERROR;
				sendTbListMsg(connection);
				return;
			}
			imageCursor.moveToFirst();
			publishMediaStoreInfo(imageCursor);
			if (id != INITIAL_IMAGE_INDEX)
			{
				for (int i = 0; i < imageCursor.Count; i++)
				{
					if (id == imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media._ID)))
					{
						ret = imageCursor.moveToNext();
						break;
					}
					if (imageCursor.moveToNext() == false)
					{
						ret = false;
						break;
					}
				}
			}
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int size = imageCursor.getCount();
			int size = imageCursor.Count;
			if ((ret == true) && (size > 0))
			{
				do
				{
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final boolean status = pullThumbnails(imageCursor);
					bool status = pullThumbnails(imageCursor);
					if (status == true)
					{
						count++;
					}
				} while (count < 3 && imageCursor.moveToNext());
				mResult = "success";
				mReason = REASON_OK;
			} // check to ignore in case id is last record in DB
			else
			{
				mReason = REASON_EOF_IMAGE;
			}
			if (!imageCursor.Closed)
			{
				imageCursor.close();
			}
			sendTbListMsg(connection);
		}
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: private void onDataAvailableonChannel(final GalleryProviderConnection connection, final long channelId, final String data)
		private void onDataAvailableonChannel(GalleryProviderConnection connection, long channelId, string data)
		{
			mBackgroundHandler.post(() =>
			{
				if (data.Contains(Model.THUMBNAIL_LIST_REQ))
				{
					sendThumbnails(connection, data);
				}
				else if (data.Contains(Model.DOWNSCALE_IMG_REQ))
				{
					sendDownscaledImage(connection, data);
				}
			});
		}