[shortcut] update exception handling 24/150224/6 preview1-00211
authorMyungki Lee <mk5004.lee@samsung.com>
Fri, 15 Sep 2017 01:06:23 +0000 (10:06 +0900)
committerMyungki Lee <mk5004.lee@samsung.com>
Fri, 15 Sep 2017 06:14:55 +0000 (15:14 +0900)
Change-Id: I02b5d6ebe74a2d061fe63e064b3b3d65f876821a
Signed-off-by: Myungki Lee <mk5004.lee@samsung.com>
src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutManager.cs
src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutEventManager.cs

index f27507d..3b4e7c4 100755 (executable)
@@ -51,7 +51,7 @@ namespace Tizen.Applications.Shortcut
             {
                 int type;
 
-                if (shortcut.Uri == null || shortcut.Uri == String.Empty)
+                if (string.IsNullOrEmpty(shortcut.Uri))
                 {
                     type = 0;
                 }
index fba8ab1..fca6ef2 100755 (executable)
@@ -66,8 +66,6 @@ namespace Tizen.Applications.Shortcut
         /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
         public static void RegisterEventHandler(ShortcutAdded addedEvent)
         {
-            shortcutAdded = addedEvent;
-
             if (shortcutAddCallback == null)
             {
                 shortcutAddCallback = new Interop.Shortcut.AddCallback(AddCallback);
@@ -75,8 +73,15 @@ namespace Tizen.Applications.Shortcut
                 Interop.Shortcut.ErrorCode err = Interop.Shortcut.SetShortcutAddCallback(shortcutAddCallback, IntPtr.Zero);
                 if (err != Interop.Shortcut.ErrorCode.None)
                 {
+                    shortcutAddCallback = null;
                     throw ShortcutErrorFactory.GetException(err, "unable to register callback");
                 }
+
+                shortcutAdded = addedEvent;
+            }
+            else
+            {
+                throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, null);
             }
         }
 
@@ -97,8 +102,6 @@ namespace Tizen.Applications.Shortcut
         /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
         public static void RegisterEventHandler(ShortcutDeleted deletedEvent)
         {
-            shortcutDeleted = deletedEvent;
-
             if (shortcutDeleteCallback == null)
             {
                 shortcutDeleteCallback = new Interop.Shortcut.DeleteCallback(DeleteCallback);
@@ -106,8 +109,15 @@ namespace Tizen.Applications.Shortcut
                 Interop.Shortcut.ErrorCode err = Interop.Shortcut.SetShortcutDeleteCallback(shortcutDeleteCallback, IntPtr.Zero);
                 if (err != Interop.Shortcut.ErrorCode.None)
                 {
+                    shortcutDeleteCallback = null;
                     throw ShortcutErrorFactory.GetException(err, "unable to register callback");
                 }
+
+                shortcutDeleted = deletedEvent;
+            }
+            else
+            {
+                throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, null);
             }
         }
 
@@ -123,7 +133,7 @@ namespace Tizen.Applications.Shortcut
         /// <exception cref="NotSupportedException">Thrown when Shortcut is not supported.</exception>
         public static void UnregisterEventHandler(ShortcutAdded addedEvent)
         {
-            if (shortcutAdded.Equals(addedEvent))
+            if (shortcutAdded != null && shortcutAdded.Equals(addedEvent))
             {
                 shortcutAdded = null;
 
@@ -157,13 +167,12 @@ namespace Tizen.Applications.Shortcut
         /// <exception cref="NotSupportedException">Thrown when Shortcut is not supported.</exception>
         public static void UnregisterEventHandler(ShortcutDeleted deletedEvent)
         {
-            if (shortcutDeleted.Equals(deletedEvent))
+            if (shortcutDeleted != null && shortcutDeleted.Equals(deletedEvent))
             {
                 shortcutDeleted = null;
 
                 if (shortcutDeleteCallback != null)
                 {
-
                     Interop.Shortcut.UnsetShortcutDeleteCallback();
                     shortcutDeleteCallback = null;