2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 using System.Collections.Generic;
19 namespace Tizen.Applications.DataControl
22 /// Represents the BulkData class for the DataControl bulk request.
24 public class BulkData : IDisposable
26 private bool _disposed = false;
27 private Interop.DataControl.SafeBulkDataHandle _handle;
30 /// Initializes the BulkData class.
32 /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
37 ret = Interop.DataControl.BulkCreate(out _handle);
38 if (ret != ResultType.Success)
40 ErrorFactory.ThrowException(ret, true, "BulkCreate");
45 internal BulkData(Interop.DataControl.SafeBulkDataHandle handle)
50 ret = Interop.DataControl.BulkCreate(out _handle);
51 if (ret != ResultType.Success)
53 ErrorFactory.ThrowException(ret, true, "BulkCreate");
56 ret = Interop.DataControl.BulkGetCount(handle, out count);
57 for ( i = 0; i < count; i++)
62 ret = Interop.DataControl.BulkGetData(handle, i, out bundleHandle);
63 if (ret != ResultType.Success)
65 ErrorFactory.ThrowException(ret, true, "BulkGetData");
68 bundle = new Bundle(new SafeBundleHandle(bundleHandle, false));
69 ret = Interop.DataControl.BulkAdd(_handle, bundle.SafeBundleHandle);
70 if (ret != ResultType.Success)
72 ErrorFactory.ThrowException(ret, true, "BulkAdd");
77 internal Interop.DataControl.SafeBulkDataHandle SafeBulkDataHandle
79 get { return _handle; }
83 /// Adds the bulk data.
85 /// <param name="data">Bulk data</param>
86 /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
87 public void Add(Bundle data)
91 if (data == null || data.SafeBundleHandle.IsInvalid)
93 ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "data");
96 ret = Interop.DataControl.BulkAdd(_handle, data.SafeBundleHandle);
97 if (ret != ResultType.Success)
99 ErrorFactory.ThrowException(ret, true, "BulkAdd");
104 /// Gets the current data count.
106 public int GetCount()
111 ret = Interop.DataControl.BulkGetCount(_handle, out count);
112 if (ret != ResultType.Success)
114 ErrorFactory.ThrowException(ret, true, "BulkGetCount");
121 /// Returns the data at the given zero-based data index.
123 /// <param name="index">The target data index.</param>
124 /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
125 public Bundle GetData(int index)
133 ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "index");
136 ret = Interop.DataControl.BulkGetData(_handle, index, out bundlePtr);
137 if (ret != ResultType.Success)
139 ErrorFactory.ThrowException(ret, true, "BulkGetData");
142 bundle = new Bundle(new SafeBundleHandle(bundlePtr, false));
147 /// Releases all the resources used by the BulkData class.
149 public void Dispose()
152 GC.SuppressFinalize(this);
156 /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
158 /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
159 protected virtual void Dispose(bool disposing)
163 if (_handle != null && !_handle.IsInvalid)
173 /// Destructor of the BulkData class.
182 /// Represents the BulkResultData class for the DataControl bulk request.
184 public class BulkResultData : IDisposable
186 private const string LogTag = "Tizen.Applications.DataControl";
187 private bool _disposed = false;
188 private Interop.DataControl.SafeBulkResultDataHandle _handle;
190 /// Initializes the BulkResultData class.
192 /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
193 public BulkResultData()
197 ret = Interop.DataControl.BulkResultCreate(out _handle);
198 if (ret != ResultType.Success)
200 ErrorFactory.ThrowException(ret, true,"BulkResultCreate");
204 internal BulkResultData(Interop.DataControl.SafeBulkResultDataHandle handle)
208 ret = Interop.DataControl.BulkResultCreate(out _handle);
209 if (ret != ResultType.Success)
211 ErrorFactory.ThrowException(ret, true,"BulkResultCreate");
215 ret = Interop.DataControl.BulkResultGetCount(handle, out count);
216 for (int i = 0; i < count; i++)
222 ret = Interop.DataControl.BulkResultGetData(handle, i, out bundleHandle, out result);
223 if (ret != ResultType.Success)
225 ErrorFactory.ThrowException(ret, true, "BulkResultGetData");
228 bundle = new Bundle(new SafeBundleHandle(bundleHandle, false));
229 ret = Interop.DataControl.BulkResultAdd(_handle, bundle.SafeBundleHandle, result);
230 if (ret != ResultType.Success)
232 ErrorFactory.ThrowException(ret, true, "BulkResultAdd");
238 /// Adds the bulk operation result data.
240 /// <param name="data">The result data.</param>
241 /// <param name="result">Result.</param>
242 /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
243 public void Add(Bundle data, int result)
247 if (data == null || data.SafeBundleHandle.IsInvalid)
249 ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "data");
252 ret = Interop.DataControl.BulkResultAdd(_handle, data.SafeBundleHandle, result);
253 if (ret != ResultType.Success)
255 ErrorFactory.ThrowException(ret, true, "BulkResultAdd");
259 internal Interop.DataControl.SafeBulkResultDataHandle SafeBulkDataHandle
261 get { return _handle; }
265 /// Gets the current result data count.
267 public int GetCount()
272 ret = Interop.DataControl.BulkResultGetCount(_handle, out count);
273 if (ret != ResultType.Success)
275 ErrorFactory.ThrowException(ret, true,"BulkResultGetCount");
282 /// Returns the result data at the given zero-based data index.
284 /// <param name="index">The target result data index.</param>
285 /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
286 public Bundle GetData(int index)
295 ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "index");
298 ret = Interop.DataControl.BulkResultGetData(_handle, index, out bundlePtr, out result);
299 if (ret != ResultType.Success)
301 ErrorFactory.ThrowException(ret, true, "BulkResultGetData");
304 bundle = new Bundle(new SafeBundleHandle(bundlePtr, false));
309 /// Returns the result at the given zero-based data index.
311 /// <param name="index">The target result index.</param>
312 /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
313 public int GetResult(int index)
321 ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "index");
324 ret = Interop.DataControl.BulkResultGetData(_handle, index, out bundlePtr, out result);
325 if (ret != ResultType.Success)
327 ErrorFactory.ThrowException(ret, true, "BulkResultGetData");
334 /// Releases all the resources used by the BulkResultData class.
336 public void Dispose()
339 GC.SuppressFinalize(this);
343 /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
345 /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
346 protected virtual void Dispose(bool disposing)
350 if (_handle != null && !_handle.IsInvalid)
360 /// Destructor of the BulkResultData class.