internal static void ThrowException(Interop.AppEvent.ErrorCode errorCode, string errorMessage = null, [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0) { Log.Error(LogTag, $"{memberName}({lineNumber.ToString()}) : {filePath}"); switch (errorCode) { case Interop.AppEvent.ErrorCode.None: return; case Interop.AppEvent.ErrorCode.OutOfMemory: case Interop.AppEvent.ErrorCode.IoError: throw new InvalidOperationException(string.IsNullOrEmpty(errorMessage) ? "error code : " + errorCode.ToString() : $"{errorMessage} - {errorCode}"); case Interop.AppEvent.ErrorCode.InvalidParameter: Log.Error(LogTag, "Invalid parameter : " + errorMessage); throw new ArgumentException(string.IsNullOrEmpty(errorMessage) ? "Invalid parameter" : "Invalid parameter : " + errorMessage); case Interop.AppEvent.ErrorCode.PermissionDenied: Log.Error(LogTag, "Permission denied : " + errorMessage); throw new UnauthorizedAccessException(string.IsNullOrEmpty(errorMessage) ? "Permission denied" : "Permission denied : " + errorMessage); case Interop.AppEvent.ErrorCode.TimeOut: Log.Error(LogTag, "Timeout : " + errorMessage); throw new TimeoutException(string.IsNullOrEmpty(errorMessage) ? "Timeout" : "Timeout : " + errorMessage); default: Log.Error(LogTag, $"Unknown error : {errorMessage} - {errorCode}"); throw new InvalidOperationException(string.IsNullOrEmpty(errorMessage) ? "Unknown error : " + errorCode.ToString() : $"Unknown error : {errorMessage} - {errorCode}"); } }
/// <summary> /// Keeps last User-Event data for receiver applications. /// </summary> /// <param name="eventName">The event's name to send.</param> /// <remarks>The receiver applications will receive this last event data after adding their new handlers via ApplicationEventReceiver since the sender application called this method. /// If a sender application sends same event via trusted method and non-trusted method, then a trusted receiver will get latest data regardless of trusted or non-trusted, /// but non-trusted receiver will get the last data only from non-trusted method. The effect of this API continues during runtime. /// That means when the sender application process restarts, the sender application needs to call this api again to make the event to keep the last event.</remarks> /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception> /// <since_tizen> 6 </since_tizen> public static void KeepLastEvent(string eventName) { Interop.AppEvent.ErrorCode err = Interop.AppEvent.EventKeepLastEventData(eventName); if (err != Interop.AppEvent.ErrorCode.None) { ErrorFactory.ThrowException(err, "Keep last event"); } }
/// <summary> /// Sends the User-Event to receiver applications. /// </summary> /// <param name="eventName">The event's name to send.</param> /// <param name="eventData"> The event's data to send.</param> /// <remarks>The format of User-Event's name MUST be "event.{sender's appid}.{user-defined name}", refer to 'The name-format of User-Event' section, /// If the event_name is invalid, throw InvalidOperationException</remarks> /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception> /// <since_tizen> 6 </since_tizen> public static void Publish(string eventName, Bundle eventData) { Interop.AppEvent.ErrorCode err = Interop.AppEvent.EventPublishAppEvent(eventName, eventData.SafeBundleHandle); if (err != Interop.AppEvent.ErrorCode.None) { ErrorFactory.ThrowException(err, "Publish event"); } }
/// <summary> /// Sends the User-Event to trusted receiver-applications. /// </summary> /// <param name="eventName">The event's name to send.</param> /// <param name="eventData"> The event's data to send.</param> /// <param name="isTrusted"> Whether the event is trusted or not.</param> /// <remarks>The application which has same certification with sender can receive the event. /// The format of User-Event's name MUST be "event.{sender's appid}.{user-defined name}", refer to 'The name-format of User-Event' section, /// If the event_name is invalid, throw InvalidOperationException</remarks> /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception> /// <since_tizen> 6 </since_tizen> public static void Publish(string eventName, Bundle eventData, bool isTrusted) { if (isTrusted) { Interop.AppEvent.ErrorCode err = Interop.AppEvent.EventPublishTrustedAppEvent(eventName, eventData.SafeBundleHandle); if (err != Interop.AppEvent.ErrorCode.None) { ErrorFactory.ThrowException(err, "Publish trusted event"); } } else { Publish(eventName, eventData); } }
/// <summary> /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects. /// </summary> /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param> /// <since_tizen> 6 </since_tizen> protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { } if (eventHandler != null) { Interop.AppEvent.ErrorCode err = Interop.AppEvent.EventRemoveHandler(_eventHandle); } disposedValue = true; } }