Ejemplo n.º 1
0
            /// <summary>
            /// Adds extra data.
            /// </summary>
            /// <remarks>
            /// The function replaces any existing value for the given key.
            /// </remarks>
            /// <param name="key">The name of the extra data.</param>
            /// <param name="value">The value associated with the given key.</param>
            /// <exception cref="ArgumentNullException">Thrown when key or value is a zero-length string.</exception>
            /// <exception cref="ArgumentException">Thrown when the application tries to use the same key with the system-defined key.</exception>
            /// <example>
            /// <code>
            /// AppControl appControl = new AppControl();
            /// string[] myValues = new string[] { "first", "second", "third" };
            /// appControl.ExtraData.Add("myKey", myValues);
            /// </code>
            /// </example>
            /// <since_tizen> 3 </since_tizen>
            public void Add(string key, IEnumerable <string> value)
            {
                if (string.IsNullOrEmpty(key))
                {
                    throw new ArgumentNullException("key");
                }
                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }
                string[] valueArray = value.ToArray();
                Interop.AppControl.ErrorCode err = Interop.AppControl.AddExtraDataArray(_handle, key, valueArray, valueArray.Length);
                if (err != Interop.AppControl.ErrorCode.None)
                {
                    switch (err)
                    {
                    case Interop.AppControl.ErrorCode.InvalidParameter:
                        throw new ArgumentException("Invalid parameter: key or value is a zero-length string");

                    case Interop.AppControl.ErrorCode.KeyRejected:
                        throw new ArgumentException("Key is rejected: the key is system-defined key.");

                    default:
                        throw new InvalidOperationException("Error = " + err);
                    }
                }
            }
Ejemplo n.º 2
0
            private string GetData(string key)
            {
                if (string.IsNullOrEmpty(key))
                {
                    throw new ArgumentNullException("key");
                }
                string value = string.Empty;

                Interop.AppControl.ErrorCode err = Interop.AppControl.GetExtraData(_handle, key, out value);
                if (err != Interop.AppControl.ErrorCode.None)
                {
                    switch (err)
                    {
                    case Interop.AppControl.ErrorCode.InvalidParameter:
                        throw new ArgumentException("Invalid parameter: key is a zero-length string");

                    case Interop.AppControl.ErrorCode.KeyNotFound:
                        throw new KeyNotFoundException("Key is not found");;

                    case Interop.AppControl.ErrorCode.InvalidDataType:
                        throw new ArgumentException("Invalid data type: value is data collection type");

                    case Interop.AppControl.ErrorCode.KeyRejected:
                        throw new ArgumentException("Key is rejected: the key is system-defined key.");

                    default:
                        throw new InvalidOperationException("Error = " + err);
                    }
                }
                return(value);
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieves all applications that can be launched to handle the given app_control request.
        /// </summary>
        /// <param name="control">The AppControl.</param>
        /// <returns>ApplicationIds.</returns>
        /// <exception cref="InvalidOperationException">Thrown when failed because of an invalid parameter.</exception>
        /// <example>
        /// <code>
        /// IEnumerable&lt;string&gt; applicationIds = AppControl.GetMatchedApplicationIds(control);
        /// if (applicationIds != null)
        /// {
        ///     foreach (string id in applicationIds)
        ///     {
        ///         // ...
        ///     }
        /// }
        /// </code>
        /// </example>
        /// <since_tizen> 3 </since_tizen>
        public static IEnumerable <string> GetMatchedApplicationIds(AppControl control)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }

            List <string> ids = new List <string>();

            Interop.AppControl.AppMatchedCallback callback = (handle, applicationId, userData) =>
            {
                if (applicationId == null)
                {
                    return(false);
                }

                ids.Add(applicationId);
                return(true);
            };

            Interop.AppControl.ErrorCode err = Interop.AppControl.ForeachAppMatched(control._handle, callback, IntPtr.Zero);
            if (err != Interop.AppControl.ErrorCode.None)
            {
                throw new InvalidOperationException("Failed to get matched application ids. err = " + err);
            }

            return(ids);
        }
Ejemplo n.º 4
0
            /// <summary>
            /// Removes the extra data.
            /// </summary>
            /// <param name="key">The name of the extra data.</param>
            /// <exception cref="ArgumentNullException">Thrown when the key is a zero-length string.</exception>
            /// <exception cref="KeyNotFoundException">Thrown when the key is not found.</exception>
            /// <exception cref="ArgumentException">Thrown when the key is rejected.</exception>
            /// <example>
            /// <code>
            /// AppControl appControl = new AppControl();
            /// appControl.ExtraData.Remove("myKey");
            /// </code>
            /// </example>
            /// <since_tizen> 3 </since_tizen>
            public void Remove(string key)
            {
                if (string.IsNullOrEmpty(key))
                {
                    throw new ArgumentNullException("key");
                }
                Interop.AppControl.ErrorCode err = Interop.AppControl.RemoveExtraData(_handle, key);
                if (err != Interop.AppControl.ErrorCode.None)
                {
                    switch (err)
                    {
                    case Interop.AppControl.ErrorCode.InvalidParameter:
                        throw new ArgumentException("Invalid parameter: key is a zero-length string");

                    case Interop.AppControl.ErrorCode.KeyNotFound:
                        throw new KeyNotFoundException("Key is not found");;

                    case Interop.AppControl.ErrorCode.KeyRejected:
                        throw new ArgumentException("Key is rejected: the key is system-defined key.");

                    default:
                        throw new InvalidOperationException("Error = " + err);
                    }
                }
            }
Ejemplo n.º 5
0
            /// <summary>
            /// Tries getting the extra data.
            /// </summary>
            /// <param name="key">The name of extra data.</param>
            /// <param name="value">The value associated with the given key.</param>
            /// <returns>The result whether getting the value is done.</returns>
            /// <exception cref="ArgumentNullException">Thrown when the key is an invalid parameter.</exception>
            /// <exception cref="KeyNotFoundException">Thrown when the key is not found.</exception>
            /// <exception cref="ArgumentException">Thrown when the key is rejected.</exception>
            /// <example>
            /// <code>
            /// AppControl appControl = new AppControl();
            /// IEnumerable&lt;string&gt; myValue = null;
            /// bool result = appControl.ExtraData.TryGet("myKey", out myValue);
            /// if (result)
            /// {
            ///     foreach (string value in myValue)
            ///     {
            ///         // ...
            ///     }
            /// }
            /// </code>
            /// </example>
            /// <since_tizen> 3 </since_tizen>
            public bool TryGet(string key, out IEnumerable <string> value)
            {
                if (string.IsNullOrEmpty(key))
                {
                    throw new ArgumentNullException("key");
                }
                IntPtr valuePtr = IntPtr.Zero;
                int    len      = -1;

                Interop.AppControl.ErrorCode err = Interop.AppControl.GetExtraDataArray(_handle, key, out valuePtr, out len);
                if (err == Interop.AppControl.ErrorCode.None && valuePtr != IntPtr.Zero)
                {
                    List <string> stringList = new List <string>();
                    for (int i = 0; i < len; ++i)
                    {
                        IntPtr charArr = Marshal.ReadIntPtr(valuePtr, IntPtr.Size * i);
                        stringList.Add(Marshal.PtrToStringAnsi(charArr));
                        Interop.Libc.Free(charArr);
                    }
                    Interop.Libc.Free(valuePtr);
                    value = stringList;
                    return(true);
                }
                else
                {
                    value = default(IEnumerable <string>);
                    return(false);
                }
            }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes the instance of the AppControl class.
 /// </summary>
 /// <exception cref="InvalidOperationException">Thrown when failed to create the AppControl handle.</exception>
 /// <since_tizen> 3 </since_tizen>
 public AppControl()
 {
     Interop.AppControl.ErrorCode err = Interop.AppControl.Create(out _handle);
     if (err != Interop.AppControl.ErrorCode.None)
     {
         throw new InvalidOperationException("Failed to create the appcontrol handle. Err = " + err);
     }
 }
Ejemplo n.º 7
0
 private AppControl(IntPtr handle)
 {
     Interop.AppControl.ErrorCode err = Interop.AppControl.DangerousClone(out _handle, handle);
     if (err != Interop.AppControl.ErrorCode.None)
     {
         throw new InvalidOperationException("Failed to clone the appcontrol handle. Err = " + err);
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Replies to the launch request sent by the caller.
 /// If the caller application sends the launch request to receive the result, the callee application can return the result back to the caller.
 /// </summary>
 /// <param name="replyRequest">The AppControl in which the results of the callee are contained.</param>
 /// <param name="result">The result code of the launch request.</param>
 /// <example>
 /// <code>
 ///     protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
 ///     {
 ///         ReceivedAppControl control = e.ReceivedAppControl;
 ///         if (control.IsReplyRequest)
 ///         {
 ///             AppControl replyRequest = new AppControl();
 ///             replyRequest.ExtraData.Add("myKey", "I'm replying");
 ///             control.ReplyToLaunchRequest(replyRequest, AppControlReplyResult.Succeeded);
 ///         }
 ///     }
 /// </code>
 /// </example>
 /// <since_tizen> 3 </since_tizen>
 public void ReplyToLaunchRequest(AppControl replyRequest, AppControlReplyResult result)
 {
     if (replyRequest == null)
     {
         throw new ArgumentNullException("replyRequest");
     }
     Interop.AppControl.ErrorCode err = Interop.AppControl.ReplyToLaunchRequest(replyRequest.SafeAppControlHandle, this.SafeAppControlHandle, (int)result);
     if (err != Interop.AppControl.ErrorCode.None)
     {
         throw new InvalidOperationException("Failed to reply. Err = " + err);
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes the instance of the AppControl class with the SafeAppControlHandle.
        /// </summary>
        /// <param name="handle"></param>
        /// <since_tizen> 3 </since_tizen>
        public AppControl(SafeAppControlHandle handle)
        {
            if (handle == null)
            {
                throw new ArgumentNullException("handle");
            }

            Interop.AppControl.ErrorCode err = Interop.AppControl.DangerousClone(out _handle, handle.DangerousGetHandle());
            if (err != Interop.AppControl.ErrorCode.None)
            {
                throw new InvalidOperationException("Failed to clone the appcontrol handle. Err = " + err);
            }
        }
Ejemplo n.º 10
0
            /// <summary>
            /// Checks whether the extra data associated with the given key is of the collection data type.
            /// </summary>
            /// <param name="key">The name of the extra data.</param>
            /// <returns>If true, the extra data is of the array data type, otherwise false.</returns>
            /// <exception cref="ArgumentNullException">Thrown when the key is a zero-length string.</exception>
            /// <exception cref="InvalidOperationException">Thrown when failed to check the key.</exception>
            /// <example>
            /// <code>
            /// AppControl appControl = new AppControl();
            /// bool result = appControl.ExtraData.IsCollection("myKey");
            /// </code>
            /// </example>
            /// <since_tizen> 3 </since_tizen>
            public bool IsCollection(string key)
            {
                if (string.IsNullOrEmpty(key))
                {
                    throw new ArgumentNullException("key");
                }
                bool isArray = false;

                Interop.AppControl.ErrorCode err = Interop.AppControl.IsExtraDataArray(_handle, key, out isArray);
                if (err != Interop.AppControl.ErrorCode.None)
                {
                    throw new InvalidOperationException("Error = " + err);
                }
                return(isArray);
            }
Ejemplo n.º 11
0
        /// <summary>
        /// Initializes the instance of the AppControl class with a parameter.
        /// </summary>
        /// <param name="enableAppStartedResultEvent">The flag value to receive an additional launch result event on the launch request.</param>
        /// <exception cref="InvalidOperationException">Thrown when failed to create the AppControl handle.</exception>
        /// <since_tizen> 3 </since_tizen>
        public AppControl(bool enableAppStartedResultEvent)
        {
            Interop.AppControl.ErrorCode err = Interop.AppControl.Create(out _handle);
            if (err != Interop.AppControl.ErrorCode.None)
            {
                throw new InvalidOperationException("Failed to create the appcontrol handle. Err = " + err);
            }

            if (enableAppStartedResultEvent)
            {
                err = Interop.AppControl.EnableAppStartedResultEvent(_handle);
                if (err != Interop.AppControl.ErrorCode.None)
                {
                    throw new InvalidOperationException("Failed to set EnableAppStartedResultEvent");
                }
            }
        }
Ejemplo n.º 12
0
            private IEnumerable <string> GetDataCollection(string key)
            {
                if (string.IsNullOrEmpty(key))
                {
                    throw new ArgumentNullException("key");
                }
                IntPtr valuePtr = IntPtr.Zero;
                int    len      = -1;

                Interop.AppControl.ErrorCode err = Interop.AppControl.GetExtraDataArray(_handle, key, out valuePtr, out len);
                if (err != Interop.AppControl.ErrorCode.None)
                {
                    switch (err)
                    {
                    case Interop.AppControl.ErrorCode.InvalidParameter:
                        throw new ArgumentException("Invalid parameter: key is a zero-length string");

                    case Interop.AppControl.ErrorCode.KeyNotFound:
                        throw new KeyNotFoundException("Key is not found");;

                    case Interop.AppControl.ErrorCode.InvalidDataType:
                        throw new ArgumentException("Invalid data type: value is data collection type");

                    case Interop.AppControl.ErrorCode.KeyRejected:
                        throw new ArgumentException("Key is rejected: the key is system-defined key.");

                    default:
                        throw new InvalidOperationException("Error = " + err);
                    }
                }

                List <string> valueArray = new List <string>();

                if (valuePtr != IntPtr.Zero)
                {
                    for (int i = 0; i < len; ++i)
                    {
                        IntPtr charArr = Marshal.ReadIntPtr(valuePtr, IntPtr.Size * i);
                        valueArray.Add(Marshal.PtrToStringAnsi(charArr));
                        Interop.Libc.Free(charArr);
                    }
                    Interop.Libc.Free(valuePtr);
                }
                return(valueArray);
            }
Ejemplo n.º 13
0
            /// <summary>
            /// Gets all keys in extra data.
            /// </summary>
            /// <returns>The keys in the AppControl.</returns>
            /// <exception cref="InvalidOperationException">Thrown when the key is an invalid parameter.</exception>
            /// <example>
            /// <code>
            /// AppControl appControl = new AppControl();
            /// IEnumerable&lt;string&gt; keys = appControl.GetKeys();
            /// if (keys != null)
            /// {
            ///     foreach (string key in keys)
            ///     {
            ///         // ...
            ///     }
            /// }
            /// </code>
            /// </example>
            /// <since_tizen> 3 </since_tizen>
            public IEnumerable <string> GetKeys()
            {
                List <string> keys = new List <string>();

                Interop.AppControl.ExtraDataCallback callback = (handle, key, userData) =>
                {
                    if (key == null)
                    {
                        return(false);
                    }

                    keys.Add(key);
                    return(true);
                };

                Interop.AppControl.ErrorCode err = Interop.AppControl.ForeachExtraData(_handle, callback, IntPtr.Zero);
                if (err != Interop.AppControl.ErrorCode.None)
                {
                    throw new InvalidOperationException("Failed to get keys. err = " + err);
                }

                return(keys);
            }