示例#1
0
        /// <summary>
        /// Sends the select request to the provider application.
        /// </summary>
        /// <remarks>The OnSelectResult will recieve the result of this API.</remarks>
        /// <param name="columnList">Select the target column list.</param>
        /// <param name="where">The Where statement for the select query.</param>
        /// <param name="order">The Order statement for the select query.</param>
        /// <param name="pageNumber">Select the target page number.</param>
        /// <param name="countPerPage">Select the row count per page.</param>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parmaeter.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case if a permission is denied..</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/datasharing</privilege>
        /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
        /// <since_tizen> 3 </since_tizen>
        public void Select(string[] columnList, string where, string order, int pageNumber = 1, int countPerPage = 20)
        {
            int        reqId, i;
            ResultType ret;

            if (columnList == null || columnList.Length == 0)
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "column_list");
            }

            for (i = 0; i < columnList.Length; i++)
            {
                if (string.IsNullOrEmpty(columnList[i]))
                {
                    ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "column_list index " + i.ToString());
                }
            }

            _lock.WaitOne();
            ret = Interop.DataControl.Select(_handle, columnList, columnList.Length, where, order, pageNumber, countPerPage, out reqId);
            _lock.ReleaseMutex();
            if (ret != ResultType.Success)
            {
                ErrorFactory.ThrowException(ret, false, "Select");
            }
            Log.Info(LogTag, "select end. " + reqId.ToString());

            CallbackManager.RegisterReqId(reqId, this);
        }
示例#2
0
        /// <summary>
        /// Initializes the Consumer class with the providerId and the ataId.
        /// </summary>
        /// <param name="providerId">The DataControl Provider ID.</param>
        /// <param name="dataId">The DataControl Data ID.</param>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parmaeter.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <since_tizen> 3 </since_tizen>
        public Consumer(string providerId, string dataId)
        {
            ResultType ret;

            if (string.IsNullOrEmpty(providerId))
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "providerId");
            }

            if (string.IsNullOrEmpty(dataId))
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "dataId");
            }

            ret = Interop.DataControl.DataControlCreate(out _handle);
            if (ret != ResultType.Success)
            {
                ErrorFactory.ThrowException(ret, false, "Creating data control handle is failed");
            }

            Interop.DataControl.DataControlSetProviderId(_handle, providerId);
            Interop.DataControl.DataControlSetDataId(_handle, dataId);
            _lock.WaitOne();
            CallbackManager.RegisterCallback(_handle, providerId);
            _lock.ReleaseMutex();
            _dataID     = dataId;
            _providerID = providerId;
        }
示例#3
0
        internal BulkData(Interop.DataControl.SafeBulkDataHandle handle)
        {
            ResultType ret;
            int        count, i;

            ret = Interop.DataControl.BulkCreate(out _handle);
            if (ret != ResultType.Success)
            {
                ErrorFactory.ThrowException(ret, true, "BulkCreate");
            }

            ret = Interop.DataControl.BulkGetCount(handle, out count);
            for (i = 0; i < count; i++)
            {
                IntPtr bundleHandle;
                Bundle bundle;

                ret = Interop.DataControl.BulkGetData(handle, i, out bundleHandle);
                if (ret != ResultType.Success)
                {
                    ErrorFactory.ThrowException(ret, true, "BulkGetData");
                }

                bundle = new Bundle(new SafeBundleHandle(bundleHandle, false));
                ret    = Interop.DataControl.BulkAdd(_handle, bundle.SafeBundleHandle);
                if (ret != ResultType.Success)
                {
                    ErrorFactory.ThrowException(ret, true, "BulkAdd");
                }
            }
        }
示例#4
0
        /// <summary>
        /// Sends the update request to the provider application.
        /// </summary>
        /// <remarks>The OnUpdateResult will recieve result of this API.</remarks>
        /// <param name="updateData">The update data.</param>
        /// <param name="where">The Where statement for the query.</param>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parmaeter.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case if a permission is denied.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when the message has exceeded the maximum limit (1MB).</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/datasharing</privilege>
        /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
        /// <since_tizen> 3 </since_tizen>
        public void Update(Bundle updateData, string where)
        {
            int        reqId;
            ResultType ret;

            if (updateData == null || updateData.SafeBundleHandle.IsInvalid)
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "insertData");
            }

            if (string.IsNullOrEmpty(where))
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "where");
            }

            _lock.WaitOne();
            ret = Interop.DataControl.Update(_handle, updateData.SafeBundleHandle, where, out reqId);
            _lock.ReleaseMutex();
            if (ret != ResultType.Success)
            {
                ErrorFactory.ThrowException(ret, false, "Update");
            }

            CallbackManager.RegisterReqId(reqId, this);
        }
示例#5
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;
        }
示例#6
0
        /// <summary>
        /// Returns the column name at the given zero-based column index.
        /// </summary>
        /// <param name="index">The target column index.</param>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <since_tizen> 3 </since_tizen>
        public string GetColumnName(int index)
        {
            if (index < 0 || index >= _columnTypes.Length)
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false);
            }

            return(_columnNames[index]);
        }
示例#7
0
        /// <summary>
        /// Initializes the Provider class with the dataID.
        /// </summary>
        /// <param name="dataID">The DataControl Data ID.</param>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <since_tizen> 3 </since_tizen>
        public Provider(string dataID)
        {
            if (string.IsNullOrEmpty(dataID))
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "dataID");
            }

            DataID = dataID;
        }
示例#8
0
        /// <summary>
        /// Initializes the BulkData class.
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <since_tizen> 3 </since_tizen>
        public BulkData()
        {
            ResultType ret;

            ret = Interop.DataControl.BulkCreate(out _handle);
            if (ret != ResultType.Success)
            {
                ErrorFactory.ThrowException(ret, true, "BulkCreate");
            }
        }
示例#9
0
        /// <summary>
        /// Initializes the MapGetResult class with the data and the result.
        /// </summary>
        /// <param name="valueLIst">The MapGet request result data.</param>
        /// <param name="result">The MapGet request result.</param>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <since_tizen> 3 </since_tizen>
        public MapGetResult(string[] valueLIst, bool result)
        {
            if (result == true && valueLIst == null)
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "valueLIst");
            }

            ValueList = valueLIst;
            Result    = result;
        }
示例#10
0
        /// <summary>
        /// Initializes the InsertResult class with the bulkResultData and the result.
        /// </summary>
        /// <param name="bulkResultData">The bulk insert request result data.</param>
        /// <param name="result">The bulk insert request result.</param>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <since_tizen> 3 </since_tizen>
        public BulkInsertResult(BulkResultData bulkResultData, bool result)
        {
            if (result == true && (bulkResultData == null || bulkResultData.SafeBulkDataHandle.IsInvalid))
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "bulkResultData");
            }

            BulkResultData = bulkResultData;
            Result         = result;
        }
示例#11
0
        /// <summary>
        /// Returns the value of the requested column as a BLOB.
        /// </summary>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <since_tizen> 3 </since_tizen>
        public byte[] GetBlobValue(int index)
        {
            byte[] byte_array;

            if (index < 0 || index >= _columnTypes.Length)
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false);
            }

            byte_array = GetValue(index);
            return(byte_array);
        }
示例#12
0
        /// <summary>
        /// Gets the current result data count.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        public int GetCount()
        {
            int        count;
            ResultType ret;

            ret = Interop.DataControl.BulkResultGetCount(_handle, out count);
            if (ret != ResultType.Success)
            {
                ErrorFactory.ThrowException(ret, true, "BulkResultGetCount");
            }

            return(count);
        }
示例#13
0
        private byte[] GetValue(int index)
        {
            byte[]     int_tmp = new byte[sizeof(int)];
            byte[]     ret_array;
            ColumnType type;
            int        size, read_len;

            MoveToColumn(index);

            read_len = _fs.Read(int_tmp, 0, int_tmp.Length);
            if (read_len != int_tmp.Length)
            {
                ErrorFactory.ThrowException(ResultType.IoError, true, "Column Type " + index.ToString());
            }

            type = (ColumnType)BitConverter.ToInt32(int_tmp, 0);

            if (type != _columnTypes[index])
            {
                if ((int)type == ColumnTypeNull &&
                    (_columnTypes[index] == ColumnType.ColumnTypeBlob || _columnTypes[index] == ColumnType.ColumnTypeString))
                {
                    return(null); /* null type */
                }

                ErrorFactory.ThrowException(ResultType.IoError, true, "Type mismatch " + index.ToString());
            }

            read_len = _fs.Read(int_tmp, 0, int_tmp.Length);
            if (read_len != int_tmp.Length)
            {
                ErrorFactory.ThrowException(ResultType.IoError, true, "Column size " + index.ToString());
            }

            size = BitConverter.ToInt32(int_tmp, 0);

            if (size < 0)
            {
                ErrorFactory.ThrowException(ResultType.IoError, true, "Invalid data size " + index.ToString());
            }

            ret_array = new byte[size];
            read_len  = _fs.Read(ret_array, 0, ret_array.Length);
            if (read_len != ret_array.Length)
            {
                ErrorFactory.ThrowException(ResultType.IoError, true, "Column value size " + index.ToString());
                return(null);
            }

            return(ret_array);
        }
示例#14
0
        /// <summary>
        /// Sends the delete request to the provider application.
        /// </summary>
        /// <remarks>The OnDeleteResult will recieve the result of this API</remarks>
        /// <param name="where">The Where statement for the delete query.</param>
        /// <exception cref="UnauthorizedAccessException">Thrown in case if a permission is denied.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/datasharing</privilege>
        /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
        /// <since_tizen> 3 </since_tizen>
        public void Delete(string where)
        {
            int        reqId;
            ResultType ret;

            _lock.WaitOne();
            ret = Interop.DataControl.Delete(_handle, where, out reqId);
            _lock.ReleaseMutex();
            if (ret != ResultType.Success)
            {
                ErrorFactory.ThrowException(ret, false, "Delete");
            }

            CallbackManager.RegisterReqId(reqId, this);
        }
示例#15
0
        /// <summary>
        /// Adds the bulk data.
        /// </summary>
        /// <param name="data">Bulk data</param>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <since_tizen> 3 </since_tizen>
        public void Add(Bundle data)
        {
            ResultType ret;

            if (data == null || data.SafeBundleHandle.IsInvalid)
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "data");
            }

            ret = Interop.DataControl.BulkAdd(_handle, data.SafeBundleHandle);
            if (ret != ResultType.Success)
            {
                ErrorFactory.ThrowException(ret, true, "BulkAdd");
            }
        }
示例#16
0
        /// <summary>
        /// Sends a data change notification to consumer applications which have successfully added a data change listen.
        /// </summary>
        /// <param name="type">The changed data type.</param>
        /// <param name="changedData">Customized information about the changed data.</param>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case a permission is denied.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/datasharing</privilege>
        /// <since_tizen> 3 </since_tizen>
        public void SendDataChange(ChangeType type, Bundle changedData)
        {
            ResultType ret;

            if (changedData == null || changedData.SafeBundleHandle.IsInvalid)
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "changedData");
            }

            ret = Interop.DataControl.SendDataChange(this.DataID, type, changedData.SafeBundleHandle);
            if (ret != ResultType.Success)
            {
                ErrorFactory.ThrowException(ret, false);
            }
        }
示例#17
0
        /// <summary>
        /// Returns the result at the given zero-based data index.
        /// </summary>
        /// <param name="index">The target result index.</param>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <since_tizen> 3 </since_tizen>
        public int GetResult(int index)
        {
            IntPtr     bundlePtr;
            ResultType ret;
            int        result;

            if (index < 0)
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "index");
            }

            ret = Interop.DataControl.BulkResultGetData(_handle, index, out bundlePtr, out result);
            if (ret != ResultType.Success)
            {
                ErrorFactory.ThrowException(ret, true, "BulkResultGetData");
            }

            return(result);
        }
示例#18
0
        /// <summary>
        /// Sends the map set request to the provider application.
        /// </summary>
        /// <remarks>The OnMapSetResult will recieve the result of this API.</remarks>
        /// <param name="key">The key of the value to replace.</param>
        /// <param name="oldValue">The value to be replaced.</param>
        /// <param name="newValue"> The new value that replaces the existing value.</param>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parmaeter.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case if a permission is denied.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when message has exceeded the maximum limit (1MB).</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/datasharing</privilege>
        /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
        /// <since_tizen> 3 </since_tizen>
        public void MapSet(string key, string oldValue, string newValue)
        {
            int        reqId;
            ResultType ret;

            if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(oldValue) || string.IsNullOrEmpty(newValue))
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false);
            }

            _lock.WaitOne();
            ret = Interop.DataControl.MapSet(_handle, key, oldValue, newValue, out reqId);
            _lock.ReleaseMutex();
            if (ret != ResultType.Success)
            {
                ErrorFactory.ThrowException(ret, false, "MapSet");
            }

            CallbackManager.RegisterReqId(reqId, this);
        }
示例#19
0
        /// <summary>
        /// Sends the map get request to the provider application.
        /// </summary>
        /// <remarks>The OnMapGetResult will recieve the result of this API.</remarks>
        /// <param name="key">The key of the value list to obtain.</param>
        /// <param name="pageNumber">The page number of the value set.</param>
        /// <param name="countPerPage">The desired maximum count of the data items per page.</param>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parmaeter.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case if a permission is denied.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/datasharing</privilege>
        /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
        /// <since_tizen> 3 </since_tizen>
        public void MapGet(string key, int pageNumber = 1, int countPerPage = 20)
        {
            int        reqId;
            ResultType ret;

            if (string.IsNullOrEmpty(key) || pageNumber <= 0 || countPerPage <= 0)
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false);
            }

            _lock.WaitOne();
            ret = Interop.DataControl.MapGet(_handle, key, out reqId, pageNumber, countPerPage);
            _lock.ReleaseMutex();
            if (ret != ResultType.Success)
            {
                ErrorFactory.ThrowException(ret, false, "MapGet");
            }

            CallbackManager.RegisterReqId(reqId, this);
        }
示例#20
0
        /// <summary>
        /// Sends the insert request to the provider application.
        /// </summary>
        /// <remarks>The OnInsertResult will recieve the result of this API.</remarks>
        /// <param name="insertData">The insert data.</param>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parmaeter.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case if a permission is denied.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when the message has exceeded the maximum limit (1MB).</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/datasharing</privilege>
        /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
        /// <since_tizen> 3 </since_tizen>
        public void Insert(Bundle insertData)
        {
            int        reqId;
            ResultType ret;

            if (insertData == null || insertData.SafeBundleHandle.IsInvalid)
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "insertData");
            }

            _lock.WaitOne();
            ret = Interop.DataControl.Insert(_handle, insertData.SafeBundleHandle, out reqId);
            _lock.ReleaseMutex();
            if (ret != ResultType.Success)
            {
                ErrorFactory.ThrowException(ret, false, "Insert");
            }

            CallbackManager.RegisterReqId(reqId, this);
        }
示例#21
0
        /// <summary>
        /// Returns the value of the requested column as a double.
        /// </summary>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <since_tizen> 3 </since_tizen>
        public double GetDoubleValue(int index)
        {
            double ret;

            byte[] byte_array;

            if (index < 0 || index >= _columnTypes.Length)
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false);
            }

            byte_array = GetValue(index);
            if (byte_array == null)
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false);
            }
            ret = BitConverter.ToDouble(byte_array, 0);

            return(ret);
        }
示例#22
0
        /// <summary>
        /// Sends the map bulk add request to the provider application.
        /// </summary>
        /// <remarks>The OnMapBulkAddResult will recieve the result of this API.</remarks>
        /// <param name="addData">The map bulk add data.</param>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parmaeter.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case if a permission is denied.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when the message has exceeded the maximum limit (1MB).</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/datasharing</privilege>
        /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
        /// <since_tizen> 3 </since_tizen>
        public void MapBulkAdd(BulkData addData)
        {
            int        reqId;
            ResultType ret;

            if (addData == null || addData.SafeBulkDataHandle.IsInvalid)
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "addData");
            }

            _lock.WaitOne();
            ret = Interop.DataControl.BulkAdd(_handle, addData.SafeBulkDataHandle, out reqId);
            _lock.ReleaseMutex();
            if (ret != ResultType.Success)
            {
                ErrorFactory.ThrowException(ret, false, "BulkAdd");
            }

            CallbackManager.RegisterReqId(reqId, this);
        }
示例#23
0
        /// <summary>
        /// Returns the data at the given zero-based data index.
        /// </summary>
        /// <param name="index">The target data index.</param>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <since_tizen> 3 </since_tizen>
        public Bundle GetData(int index)
        {
            IntPtr     bundlePtr;
            Bundle     bundle;
            ResultType ret;

            if (index < 0)
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "index");
            }

            ret = Interop.DataControl.BulkGetData(_handle, index, out bundlePtr);
            if (ret != ResultType.Success)
            {
                ErrorFactory.ThrowException(ret, true, "BulkGetData");
            }

            bundle = new Bundle(new SafeBundleHandle(bundlePtr, false));
            return(bundle);
        }
示例#24
0
        /// <summary>
        /// Returns the value of the requested column as a string.
        /// </summary>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <since_tizen> 3 </since_tizen>
        public string GetStringValue(int index)
        {
            string ret;

            byte[] byte_array;

            if (index < 0 || index >= _columnTypes.Length)
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false);
            }

            byte_array = GetValue(index);

            if (byte_array == null)
            {
                return(null);
            }

            ret = Encoding.UTF8.GetString(byte_array).TrimEnd('\0');
            return(ret);
        }
示例#25
0
        /// <summary>
        /// Listens the DataChange event.
        /// </summary>
        /// <remarks>The OnDataChangeListenResult will recieve the result of this API.</remarks>
        /// <remarks>If success, the OnDataChange will recieve the DataChange event.</remarks>
        /// <exception cref="UnauthorizedAccessException">Thrown in case if a permission is denied.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/datasharing</privilege>
        /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
        /// <since_tizen> 3 </since_tizen>
        public void DataChangeListen()
        {
            ResultType ret;

            _lock.WaitOne();
            /* Only one callback is allowed for every obejct */
            if (_changeCallbackID > 0)
            {
                _lock.ReleaseMutex();
                return;
            }
            _dataChangeCallback        = new Interop.DataControl.DataChangeCallback(DataChange);
            _addCallbackResultCallback = new Interop.DataControl.AddCallbackResultCallback(DataChangeListenResult);
            ret = Interop.DataControl.AddDataChangeCallback(_handle, _dataChangeCallback, IntPtr.Zero,
                                                            _addCallbackResultCallback, IntPtr.Zero, out _changeCallbackID);
            _lock.ReleaseMutex();
            if (ret != ResultType.Success)
            {
                ErrorFactory.ThrowException(ret, false, "DataChangeListen");
            }
        }
示例#26
0
        private void MoveToColumn(int ColumnIndex)
        {
            int i, tmp_position;

            byte[] int_tmp = new byte[sizeof(int)];
            int    read_len;
            long   seek_len;

            seek_len = _fs.Seek(_rowFieldOffset[_currentRowIndex], SeekOrigin.Begin);
            if (seek_len != _rowFieldOffset[_currentRowIndex])
            {
                ErrorFactory.ThrowException(ResultType.IoError, true, "Row index " + _currentRowIndex.ToString());
            }

            for (i = 0; i < ColumnIndex; i++)
            {
                /* type(int) size(int) value */
                switch (_columnTypes[i])
                {
                case ColumnType.ColumnTypeInt:
                    tmp_position = sizeof(int) * 2 + sizeof(Int64);
                    _fs.Seek(tmp_position, SeekOrigin.Current);
                    break;

                case ColumnType.ColumnTypeDouble:
                    tmp_position = sizeof(int) * 2 + sizeof(double);
                    _fs.Seek(tmp_position, SeekOrigin.Current);
                    break;

                case ColumnType.ColumnTypeString:
                    tmp_position = sizeof(int);
                    _fs.Seek(tmp_position, SeekOrigin.Current);
                    read_len = _fs.Read(int_tmp, 0, int_tmp.Length);
                    if (read_len != int_tmp.Length)
                    {
                        ErrorFactory.ThrowException(ResultType.IoError, true, "Column Index " + ColumnIndex.ToString());
                    }

                    tmp_position = BitConverter.ToInt32(int_tmp, 0);

                    if (tmp_position > 0)
                    {
                        _fs.Seek(tmp_position, SeekOrigin.Current);
                    }

                    break;

                case ColumnType.ColumnTypeBlob:
                    tmp_position = sizeof(int);
                    _fs.Seek(tmp_position, SeekOrigin.Current);

                    read_len = _fs.Read(int_tmp, 0, int_tmp.Length);
                    if (read_len != int_tmp.Length)
                    {
                        ErrorFactory.ThrowException(ResultType.IoError, true, "Column Index " + ColumnIndex.ToString());
                    }

                    tmp_position = BitConverter.ToInt32(int_tmp, 0);

                    if (tmp_position > 0)
                    {
                        _fs.Seek(tmp_position, SeekOrigin.Current);
                    }

                    break;
                }
            }
        }
示例#27
0
        /// <summary>
        /// Initializes the MatrixCursor class with columnNames and columnTypes.
        /// </summary>
        /// <param name="columnNames">The MatrixCursor's column name list.</param>
        /// <param name="columnTypes">The MatrixCursor's column type list.</param>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        ///  <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <since_tizen> 3 </since_tizen>
        public MatrixCursor(string[] columnNames, ColumnType[] columnTypes)
        {
            byte[] byte_tmp, length_tmp, string_tmp;
            int    i, total_len_of_column_names = 0;

            if (columnNames == null || columnTypes == null ||
                (columnNames.Length != columnTypes.Length) || columnNames.Length < 1)
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false);
            }

            for (i = 0; i < columnNames.Length; i++)
            {
                if (string.IsNullOrEmpty(columnNames[i]))
                {
                    ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "columnNames index " + i.ToString());
                }
            }

            for (i = 0; i < columnTypes.Length; i++)
            {
                if (columnTypes[i] < ColumnType.ColumnTypeInt || columnTypes[i] > ColumnType.ColumnTypeBlob)
                {
                    ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "columnTypes index" + i.ToString());
                }
            }

            _columnNames = columnNames;
            _columnTypes = columnTypes;

            _cursorPath = FileManager.OpenFileStream(Thread.CurrentThread.ManagedThreadId);
            if (_cursorPath == null)
            {
                Log.Error(LogTag, "Unable to create a cursor file : " + _cursorPath);
                ErrorFactory.ThrowException(ResultType.IoError, true);
            }

            _fs = new FileStream(_cursorPath, FileMode.Create);
            /* column count */
            byte_tmp = BitConverter.GetBytes(columnNames.Length);
            _fs.Write(byte_tmp, 0, byte_tmp.Length);

            /* column type */
            for (i = 0; i < columnTypes.Length; i++)
            {
                byte_tmp = BitConverter.GetBytes((int)_columnTypes[i]);
                _fs.Write(byte_tmp, 0, byte_tmp.Length);
            }

            /* column name */
            for (i = 0; i < columnTypes.Length; i++)
            {
                string_tmp = Encoding.UTF8.GetBytes(columnNames[i]);
                byte_tmp   = new byte[string_tmp.Length + 1];/*insert null */

                string_tmp.CopyTo(byte_tmp, 0);

                length_tmp = BitConverter.GetBytes(byte_tmp.Length);
                total_len_of_column_names += length_tmp.Length;

                _fs.Write(length_tmp, 0, length_tmp.Length);
                _fs.Write(byte_tmp, 0, byte_tmp.Length);
            }

            /* total length of column names */
            byte_tmp = BitConverter.GetBytes(total_len_of_column_names);
            _fs.Write(byte_tmp, 0, byte_tmp.Length);

            _rowCountPosition = _fs.Position;
            /* row count */
            byte_tmp = BitConverter.GetBytes(_rowCount);
            _fs.Write(byte_tmp, 0, byte_tmp.Length);
            _fs.Flush();
        }
示例#28
0
        /// <summary>
        /// Adds a new row to the end with the given column values.
        /// </summary>
        /// <param name="columnValues">New column values</param>
        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
        /// <since_tizen> 3 </since_tizen>
        public void AddRow(object[] columnValues)
        {
            int i, size = 0;

            byte[] type_array, length_array, value_array = null, string_array, byte_tmp;

            if (columnValues == null || columnValues.Length <= 0 || columnValues.Length != _columnTypes.Length)
            {
                ErrorFactory.ThrowException(ResultType.InvalidParameter, false);
            }

            using (MemoryStream ms = new MemoryStream())
            {
                for (i = 0; i < _columnTypes.Length; i++)
                {
                    type_array = BitConverter.GetBytes((int)_columnTypes[i]);
                    switch (_columnTypes[i])
                    {
                    case ColumnType.ColumnTypeInt:
                        if (!(columnValues[i] is Int64) && !(columnValues[i] is Int32))
                        {
                            ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "Type mismatch :Index " + i.ToString());
                        }

                        value_array = BitConverter.GetBytes(Convert.ToUInt64(columnValues[i]));
                        size        = value_array.Length;
                        break;

                    case ColumnType.ColumnTypeDouble:
                        if (!(columnValues[i] is Double))
                        {
                            ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "Type mismatch :Index " + i.ToString());
                        }

                        value_array = BitConverter.GetBytes(Convert.ToDouble(columnValues[i]));
                        size        = value_array.Length;
                        break;

                    case ColumnType.ColumnTypeString:
                        if (columnValues[i] == null)
                        {
                            type_array = BitConverter.GetBytes(ColumnTypeNull);
                            size       = 0;
                            break;
                        }

                        if (!(columnValues[i] is string))
                        {
                            ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "Type mismatch :Index " + i.ToString());
                        }

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

                    case ColumnType.ColumnTypeBlob:
                        if (columnValues[i] == null)
                        {
                            type_array = BitConverter.GetBytes(ColumnTypeNull);
                            size       = 0;
                            break;
                        }

                        if (!(columnValues[i] is byte[]))
                        {
                            ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "Type mismatch :Index " + i.ToString());
                        }

                        value_array = (byte[])columnValues[i];
                        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);
                    }
                }

                /* update row count */
                _rowCount++;
                byte_tmp = BitConverter.GetBytes(_rowCount);
                _fs.Seek(_rowCountPosition, SeekOrigin.Begin);
                _fs.Write(byte_tmp, 0, byte_tmp.Length);

                _fs.Seek(0, SeekOrigin.End);

                _rowFieldOffset.Add(_fs.Position);
                ms.WriteTo(_fs);/* row data */
                _fs.Flush();

                Log.Debug(LogTag, "_fs pos = " + _fs.Position.ToString());
                Log.Debug(LogTag, "_fs len = " + _fs.Length.ToString());
            }
        }
示例#29
0
        /// <summary>
        /// Starts the Provider service.
        /// </summary>
        /// <remarks>Only one Provider service can be run for each process.</remarks>
        /// <exception cref="UnauthorizedAccessException">Thrown in case a permission is denied.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        /// <privilege>http://tizen.org/privilege/datasharing</privilege>
        /// <since_tizen> 3 </since_tizen>
        public void Run()
        {
            ResultType ret;

            _lock.WaitOne();
            if (_providerDict.ContainsKey(DataID))
            {
                _lock.ReleaseMutex();
                ErrorFactory.ThrowException((ResultType)1, true, "The provider is already running");
                return;
            }

            if (_providerDict.Count == 0)
            {
                Log.Debug(LogTag, "Provider create");

                _sqlRequestCallbacks.Insert = new Interop.DataControl.SqlInsertRequestCallback(InsertRequest);
                _sqlRequestCallbacks.Select = new Interop.DataControl.SqlSelectRequestCallback(SelectRequest);
                _sqlRequestCallbacks.Update = new Interop.DataControl.SqlUpdateRequestCallback(UpdateRequest);
                _sqlRequestCallbacks.Delete = new Interop.DataControl.SqlDeleteRequestCallback(DeleteRequest);

                ret = Interop.DataControl.RegisterSqlRequest(ref _sqlRequestCallbacks, IntPtr.Zero);
                if (ret != ResultType.Success)
                {
                    _lock.ReleaseMutex();
                    ErrorFactory.ThrowException(ret, false);
                }

                _sqlBulkCallback = new Interop.DataControl.SqlBulkInsertRequestCallback(BulkInsertRequest);
                ret = Interop.DataControl.RegisterSqlBulkRequest(_sqlBulkCallback, IntPtr.Zero);
                if (ret != ResultType.Success)
                {
                    _lock.ReleaseMutex();
                    ErrorFactory.ThrowException(ret, false);
                }

                _mapRequestCallbacks.Add    = new Interop.DataControl.MapAddRequestCallback(MapAddRequest);
                _mapRequestCallbacks.Remove = new Interop.DataControl.MapRemoveRequestCallback(MapRemoveRequest);
                _mapRequestCallbacks.Set    = new Interop.DataControl.MapSetRequestCallback(MapSetRequest);
                _mapRequestCallbacks.Get    = new Interop.DataControl.MapGetRequestCallback(MapGetRequest);
                ret = Interop.DataControl.RegisterMapRequest(ref _mapRequestCallbacks, IntPtr.Zero);
                if (ret != ResultType.Success)
                {
                    _lock.ReleaseMutex();
                    ErrorFactory.ThrowException(ret, false);
                }

                _mapBulkCallback = new Interop.DataControl.MapBulkAddRequestCallback(MapBulkAddRequest);
                ret = Interop.DataControl.RegisterMapBulkRequest(_mapBulkCallback, IntPtr.Zero);
                if (ret != ResultType.Success)
                {
                    _lock.ReleaseMutex();
                    ErrorFactory.ThrowException(ret, false);
                }

                if (_filterRegistered == false)
                {
                    if (_filterCallback == null)
                    {
                        _filterCallback = new Interop.DataControl.DataChangeConsumerFilterCb(DataChangeListenFilter);
                    }

                    ret = Interop.DataControl.AddDataChangeConsumerFilterCallback(
                        _filterCallback,
                        IntPtr.Zero, out _filterCallbackID);

                    if (ret != ResultType.Success)
                    {
                        _lock.ReleaseMutex();
                        ErrorFactory.ThrowException(ret, false);
                    }
                }

                _filterRegistered = true;
            }

            _providerDict.Add(DataID, this);
            Log.Info(LogTag, "DataID :" + DataID + ", hash code : " + this.GetHashCode().ToString());
            _isRunning = true;
            _lock.ReleaseMutex();
        }
示例#30
0
            internal static void RegisterCallback(Interop.DataControl.SafeDataControlHandle handle, string providerId)
            {
                ResultType ret;

                Interop.DataControl.SqlResponseCallbacks          sqlCallbacks;
                Interop.DataControl.SqlBulkInsertResponseCallback sqlBulkCallbacks;
                Interop.DataControl.MapResponseCallbacks          mapCallbacks;
                Interop.DataControl.MapBulkAddResponseCallback    mapBulkCallbacks;
                bool sqlRegistered = false;
                bool mapRegistered = false;

                if (_reqProviderList.ContainsKey(providerId))
                {
                    _reqProviderList[providerId]++;
                    Log.Error(LogTag, "The data control is already set");
                    return;
                }

                sqlCallbacks.Insert = new Interop.DataControl.SqlInsertResponseCallback(InsertResponse);
                sqlCallbacks.Select = new Interop.DataControl.SqlSelectResponseCallback(SelectResponse);
                sqlCallbacks.Update = new Interop.DataControl.SqlUpdateResponseCallback(UpdateResponse);
                sqlCallbacks.Delete = new Interop.DataControl.SqlDeleteResponseCallback(DeleteResponse);
                ret = Interop.DataControl.RegisterSqlResponseCallback(handle, ref sqlCallbacks, IntPtr.Zero);
                if (ret != ResultType.Success)
                {
                    Log.Error(LogTag, "Registering the sql callback function is failed : " + ret);
                }
                else
                {
                    _sqlResponseCallbacks.Add(providerId, sqlCallbacks);
                    sqlRegistered = true;
                }

                sqlBulkCallbacks = new Interop.DataControl.SqlBulkInsertResponseCallback(BulkInsertResponse);
                ret = Interop.DataControl.RegisterSqlBulkResponseCallback(handle, sqlBulkCallbacks, IntPtr.Zero);
                if (ret != ResultType.Success)
                {
                    Log.Error(LogTag, "Registering the sql bulk callback function is failed : " + ret);
                }
                else
                {
                    _sqlBulkResponseCallback.Add(providerId, sqlBulkCallbacks);
                }

                mapCallbacks.Add    = new Interop.DataControl.MapAddResponseCallback(MapAddResponse);
                mapCallbacks.Set    = new Interop.DataControl.MapSetResponseCallback(MapSetResponse);
                mapCallbacks.Get    = new Interop.DataControl.MapGetResponseCallback(MapGetResponse);
                mapCallbacks.Remove = new Interop.DataControl.MapRemoveResponseCallback(MapRemoveResponse);
                ret = Interop.DataControl.RegisterMapResponse(handle, ref mapCallbacks, IntPtr.Zero);

                if (ret != ResultType.Success)
                {
                    Log.Error(LogTag, "Registering the map callback function is failed : " + ret);
                }
                else
                {
                    _mapResponseCallbacks.Add(providerId, mapCallbacks);
                    mapRegistered = true;
                }

                mapBulkCallbacks = new Interop.DataControl.MapBulkAddResponseCallback(MapBulkAddResponse);
                ret = Interop.DataControl.RegisterMapBulkResponseCallback(handle, mapBulkCallbacks, IntPtr.Zero);
                if (ret != ResultType.Success)
                {
                    Log.Error(LogTag, "Registering the map bulk callback function is failed : " + ret);
                }
                else
                {
                    _mapBulkResponseCallback.Add(providerId, mapBulkCallbacks);
                }

                if (!mapRegistered && !sqlRegistered)
                {
                    ErrorFactory.ThrowException(ret, true, "Registering the response callback function is failed");
                }

                _reqProviderList.Add(providerId, 1);
            }