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 BulkData class for DataControl bulk request.
24 public class BulkData : IDisposable
26 private bool _disposed = false;
27 private Interop.DataControl.SafeBulkDataHandle _handle;
30 /// Initializes 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; }
85 /// <param name="data">Bulk data</param>
86 /// <exception cref="ArgumentException">Thrown in case of Invalid parmaeter.</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 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">Target data index</param>
124 /// <exception cref="ArgumentException">Thrown in case of Invalid parmaeter.</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 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)
179 /// Represents BulkResultData class for DataControl bulk request.
181 public class BulkResultData : IDisposable
183 private const string LogTag = "Tizen.Applications.DataControl";
184 private bool _disposed = false;
185 private Interop.DataControl.SafeBulkResultDataHandle _handle;
187 /// Initializes BulkResultData class.
189 /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
190 public BulkResultData()
194 ret = Interop.DataControl.BulkResultCreate(out _handle);
195 if (ret != ResultType.Success)
197 ErrorFactory.ThrowException(ret, true,"BulkResultCreate");
201 internal BulkResultData(Interop.DataControl.SafeBulkResultDataHandle handle)
205 ret = Interop.DataControl.BulkResultCreate(out _handle);
206 if (ret != ResultType.Success)
208 ErrorFactory.ThrowException(ret, true,"BulkResultCreate");
212 ret = Interop.DataControl.BulkResultGetCount(handle, out count);
213 for (int i = 0; i < count; i++)
219 ret = Interop.DataControl.BulkResultGetData(handle, i, out bundleHandle, out result);
220 if (ret != ResultType.Success)
222 ErrorFactory.ThrowException(ret, true, "BulkResultGetData");
225 bundle = new Bundle(new SafeBundleHandle(bundleHandle, false));
226 ret = Interop.DataControl.BulkResultAdd(_handle, bundle.SafeBundleHandle, result);
227 if (ret != ResultType.Success)
229 ErrorFactory.ThrowException(ret, true, "BulkResultAdd");
235 /// Adds bulk operation result data.
237 /// <param name="data">Result data</param>
238 /// <param name="result">Result</param>
239 /// <exception cref="ArgumentException">Thrown in case of Invalid parmaeter.</exception>
240 public void Add(Bundle data, int result)
244 if (data == null || data.SafeBundleHandle.IsInvalid)
246 ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "data");
249 ret = Interop.DataControl.BulkResultAdd(_handle, data.SafeBundleHandle, result);
250 if (ret != ResultType.Success)
252 ErrorFactory.ThrowException(ret, true, "BulkResultAdd");
256 internal Interop.DataControl.SafeBulkResultDataHandle SafeBulkDataHandle
258 get { return _handle; }
262 /// Gets current result data count.
264 public int GetCount()
269 ret = Interop.DataControl.BulkResultGetCount(_handle, out count);
270 if (ret != ResultType.Success)
272 ErrorFactory.ThrowException(ret, true,"BulkResultGetCount");
279 /// Returns the result data at the given zero-based data index.
281 /// <param name="index">Target result data index</param>
282 /// <exception cref="ArgumentException">Thrown in case of Invalid parmaeter.</exception>
283 public Bundle GetData(int index)
292 ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "index");
295 ret = Interop.DataControl.BulkResultGetData(_handle, index, out bundlePtr, out result);
296 if (ret != ResultType.Success)
298 ErrorFactory.ThrowException(ret, true, "BulkResultGetData");
301 bundle = new Bundle(new SafeBundleHandle(bundlePtr, false));
306 /// Returns the result at the given zero-based data index.
308 /// <param name="index">Target result index</param>
309 /// <exception cref="ArgumentException">Thrown in case of Invalid parmaeter.</exception>
310 public int GetResult(int index)
318 ErrorFactory.ThrowException(ResultType.InvalidParameter, false, "index");
321 ret = Interop.DataControl.BulkResultGetData(_handle, index, out bundlePtr, out result);
322 if (ret != ResultType.Success)
324 ErrorFactory.ThrowException(ret, true, "BulkResultGetData");
331 /// Releases all resources used by the BulkResultData class.
333 public void Dispose()
336 GC.SuppressFinalize(this);
340 /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
342 /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
343 protected virtual void Dispose(bool disposing)
347 if (_handle != null && !_handle.IsInvalid)