Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the SelectResult class with the cursor and the result.
        /// </summary>
        /// <param name="cursor">The cursor with the selected data.</param>
        /// <param name="result">The select request result.</param>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <since_tizen> 3 </since_tizen>
        public SelectResult(ICursor cursor, bool result)
        {
            int i;

            if (result == true && cursor == null)
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "cursor");
            }

            if (result == true && (cursor is MatrixCursor) == false)
            {
                if (cursor.GetColumnCount() <= 0)
                {
                    ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "column count");
                }

                for (i = 0; i < cursor.GetColumnCount(); i++)
                {
                    if (string.IsNullOrEmpty(cursor.GetColumnName(i)))
                    {
                        ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "column name index " + i.ToString());
                    }

                    if (cursor.GetColumnType(i) < ColumnType.ColumnTypeInt || cursor.GetColumnType(i) > ColumnType.ColumnTypeBlob)
                    {
                        ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "column type index" + i.ToString());
                    }
                }
            }

            ResultCursor = cursor;
            Result       = result;
        }
 public static bool GetURIValue(ICursor cursor, Android.Net.Uri uri, IDIResultCallbacks resultCallbacks)
 {
     while (cursor.MoveToNext())
     {
         if (cursor.ColumnCount == 0)
         {
             //  No data in the cursor.  I have seen this happen on non-WAN devices
             String errorMsg = "Error: " + uri + " does not exist on this device";
             resultCallbacks.OnDebugStatus(errorMsg);
         }
         else
         {
             for (int i = 0; i < cursor.ColumnCount; i++)
             {
                 try
                 {
                     String data = cursor.GetString(cursor.GetColumnIndex(cursor.GetColumnName(i)));
                     resultCallbacks.OnSuccess(data);
                     cursor.Close();
                     return(true);
                 }
                 catch (Exception e)
                 {
                     resultCallbacks.OnDebugStatus(e.Message);
                 }
             }
         }
     }
     cursor.Close();
     resultCallbacks.OnError("Data not found in Uri:" + uri);
     return(true);
 }
Ejemplo n.º 3
0
        public void ReadRecentText()
        {
            // Open user's sms inbox
            ICursor cursor = MainActivity.Instance.ContentResolver.Query(Android.Net.Uri.Parse("content://sms/inbox"), null, null, null);

            if (cursor.MoveToFirst()) // Let's get the data for the first message pointed to by cursor
                                      // (Should be the only message we need)
            {
                string sms_body = "";
                string address  = "";
                for (int i = 0; i < cursor.ColumnCount; i++)
                {
                    switch (cursor.GetColumnName(i))
                    {
                    case "address":
                        string number          = cursor.GetString(i);
                        string resolved_number = getContactbyPhoneNumber(number);
                        if (resolved_number == number)
                        {
                            if (number.Length >= 10)
                            {
                                number  = number.Substring(number.Length - 10);
                                address = "(" + number.Substring(0, 3) + ") " + number.Substring(3, 3) + "-" + number.Substring(6, 4);
                            }
                            else
                            {
                                address = string.Join(" ", number.ToCharArray());
                            }
                        }
                        else
                        {
                            address = resolved_number;
                        }
                        break;

                    case "body":
                        sms_body = cursor.GetString(i);
                        break;
                    }
                }
                var readAloud = new TextToAudio("Message from: " + address + ". " + sms_body);
            }
            cursor.Close();
        }
Ejemplo n.º 4
0
        private static void SendNativeProtocol(int socketFd, ICursor cursor, int requestId)
        {
            uint write_len;
            int  DATACONTROL_RESULT_NO_DATA = -1;
            int  COLUMN_TYPE_NULL = 5;
            int  column_count, i, rowcount, size = 0, total_len_of_column_names = 0;

            byte[]       type_array, length_array, string_array, int_tmp, value_array = null;
            string       txt;
            ResultType   result;
            MemoryStream ms;

            if (cursor.Reset() == false)
            {
                Log.Error(LogTag, "Reset is failed  :  " + requestId.ToString());
                return;
            }

            if (cursor.GetRowCount() <= 0)
            {
                Log.Error(LogTag, "The DB does not have another row : " + requestId.ToString());
                int_tmp = BitConverter.GetBytes(DATACONTROL_RESULT_NO_DATA);
                result  = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, int_tmp, int_tmp.Length, out write_len);
                return;
            }

            /* 1. column count */
            column_count = cursor.GetColumnCount();
            int_tmp      = BitConverter.GetBytes(column_count);
            result       = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, int_tmp, int_tmp.Length, out write_len);
            if (result != ResultType.Success)
            {
                Log.Error(LogTag, "Writing a column_count to a file descriptor is failed.");
                return;
            }

            Log.Info(LogTag, "Writing a column_count " + column_count.ToString());

            /* 2.column type x column_count */
            for (i = 0; i < column_count; i++)
            {
                type_array = BitConverter.GetBytes((int)cursor.GetColumnType(i));
                result     = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, type_array, type_array.Length, out write_len);
                if (result != ResultType.Success)
                {
                    Log.Error(LogTag, "Writing a type to a file descriptor is failed.");
                    return;
                }

                Log.Info(LogTag, "Writing a column_type " + cursor.GetColumnType(i).ToString());
            }

            /* 3. column name x column_count */
            for (i = 0; i < column_count; i++)
            {
                Log.Info(LogTag, "Writing a name " + cursor.GetColumnName(i));

                total_len_of_column_names += cursor.GetColumnName(i).Length;
                string_array = Encoding.UTF8.GetBytes(cursor.GetColumnName(i));
                value_array  = new byte[string_array.Length + 1];/*insert null */
                string_array.CopyTo(value_array, 0);
                length_array = BitConverter.GetBytes(value_array.Length);

                result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, length_array, length_array.Length, out write_len);
                if (result != ResultType.Success)
                {
                    Log.Error(LogTag, "Writing a type to a file descriptor is failed.");
                    return;
                }

                result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, value_array, value_array.Length, out write_len);
                if (result != ResultType.Success)
                {
                    Log.Error(LogTag, "Writing a type to a file descriptor is failed.");
                    return;
                }
            }

            /* 4. total length of column names */
            length_array = BitConverter.GetBytes(total_len_of_column_names);
            result       = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, length_array, length_array.Length, out write_len);
            if (result != ResultType.Success)
            {
                Log.Error(LogTag, "Writing a total_len_of_column_names to a file descriptor is failed");
                return;
            }

            Log.Info(LogTag, "Writing  total length of column namese " + total_len_of_column_names.ToString());

            /* 5. row count */
            length_array = BitConverter.GetBytes(cursor.GetRowCount());
            Log.Error(LogTag, "=========================== select rowcount " + cursor.GetRowCount().ToString());
            result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, length_array, length_array.Length, out write_len);
            if (result != ResultType.Success)
            {
                Log.Error(LogTag, "Writing a row count to a file descriptor is failed");
                return;
            }

            Log.Error(LogTag, "Writing a row count " + cursor.GetRowCount().ToString());

            rowcount = 0;
            do
            {
                ms = new MemoryStream();

                for (i = 0; i < column_count; i++)
                {
                    type_array = BitConverter.GetBytes((int)cursor.GetColumnType(i));
                    switch (cursor.GetColumnType(i))
                    {
                    case ColumnType.ColumnTypeInt:
                        value_array = BitConverter.GetBytes(cursor.GetInt64Value(i));
                        size        = value_array.Length;
                        break;

                    case ColumnType.ColumnTypeDouble:
                        value_array = BitConverter.GetBytes(cursor.GetDoubleValue(i));
                        size        = value_array.Length;
                        break;

                    case ColumnType.ColumnTypeString:
                        txt = cursor.GetStringValue(i);
                        if (txt == null)
                        {
                            type_array = BitConverter.GetBytes(COLUMN_TYPE_NULL);
                            size       = 0;
                            break;
                        }

                        string_array = Encoding.UTF8.GetBytes(txt);
                        value_array  = new byte[string_array.Length + 1];   /*insert null */
                        string_array.CopyTo(value_array, 0);
                        size = value_array.Length;
                        break;

                    case ColumnType.ColumnTypeBlob:
                        int_tmp = cursor.GetBlobValue(i);
                        if (int_tmp == null)
                        {
                            type_array = BitConverter.GetBytes(COLUMN_TYPE_NULL);
                            size       = 0;
                            break;
                        }

                        value_array = int_tmp;
                        size        = value_array.Length;
                        break;
                    }

                    ms.Write(type_array, 0, type_array.Length);

                    length_array = BitConverter.GetBytes(size);
                    ms.Write(length_array, 0, length_array.Length);
                    if (size > 0)
                    {
                        ms.Write(value_array, 0, value_array.Length);
                    }
                }

                value_array = ms.ToArray();

                result = (ResultType)Interop.DataControl.UnsafeCode.WriteResult(socketFd, value_array, value_array.Length, out write_len);
                if (result != ResultType.Success)
                {
                    Log.Error(LogTag, "Writing a row to a file descriptor is failed");
                    ms.Dispose();
                    return;
                }

                ms.Dispose();
                Log.Info(LogTag, "row_count ~~~~ ", rowcount.ToString());
            }while (cursor.Next());
        }