Make the AppShortcutStorage checks storage(xml) starting time. 20/134120/2
authorChulSeung Kim <charles0.kim@samsung.com>
Thu, 15 Jun 2017 00:08:33 +0000 (09:08 +0900)
committerChulSeung Kim <charles0.kim@samsung.com>
Thu, 15 Jun 2017 00:25:41 +0000 (09:25 +0900)
Change-Id: I02d52de4cf8b72250915c651cc87b451a53add6d

LibTVRefCommonPortable/Stubs/FileWatcherAPITestStub.cs
LibTVRefCommonPortable/Utils/AppShortcutStorage.cs
LibTVRefCommonPortable/Utils/IFileSystemWatcherAPIs.cs
LibTVRefCommonTizen/Ports/FileSystemWatcherPort.cs
TVHome/TVHome/TVHome.cs

index fe4aa6b..24709b5 100644 (file)
@@ -32,7 +32,9 @@ namespace LibTVRefCommonPortable.Stubs
         /// <summary>
         /// A method starts the file system watcher.
         /// </summary>
-        public void Run()
+        /// <param name="path">Target file path</param>
+        /// <param name="fileName">Target file name</param>
+        public void Run(String path, String fileName)
         {
             CustomChanged?.Invoke(this, EventArgs.Empty);
 
index 47baace..67b5ae1 100644 (file)
@@ -58,37 +58,46 @@ namespace LibTVRefCommonPortable.Utils
         {
             StoragePath = FileSystemUtils.Instance.PlatformShareStorage + "pinned_apps_info.xml";
 
-            fileSystemWatcher.Run();
+            CheckStorage();
+
+            fileSystemWatcher.Run(FileSystemUtils.Instance.PlatformShareStorage, "pinned_apps_info.xml");
         }
 
         /// <summary>
-        /// A method provides an app Shortcut list.
+        /// Check if the storage is exist
         /// </summary>
-        /// <returns>An app Shortcut list.</returns>
-        public static async Task<IEnumerable<AppShortcutInfo>> Read()
+        private static void CheckStorage()
         {
             if (FileSystemUtils.Instance.IsFileExist(StoragePath) == false)
             {
                 DebuggingUtils.Err("Set Default Pinned Apps" + StoragePath);
                 List<AppShortcutInfo> result = new List<AppShortcutInfo>();
                 Write(result);
-                return result;
             }
+        }
+
+        /// <summary>
+        /// A method provides an app Shortcut list.
+        /// </summary>
+        /// <returns>An app Shortcut list.</returns>
+        public static async Task<IEnumerable<AppShortcutInfo>> Read()
+        {
+            CheckStorage();
 
-            for (int i = 0; i < 5; i++)
+            for (int i = 0; i <= 6; i++)
             {
                 if (FileSystemUtils.Instance.IsFileReady(StoragePath))
                 {
                     break;
                 }
-                else if (i >= 4)
+                else if (i == 6)
                 {
                     DebuggingUtils.Err("Can't open storage" + StoragePath);
                     return new List<AppShortcutInfo>();
                 }
 
                 await Task.Delay(100);
-                DebuggingUtils.Dbg("[" + i + "/5] Waiting for Writing" + StoragePath);
+                DebuggingUtils.Dbg("[" + i + "] Waiting for Writing" + StoragePath);
             }
 
             using (Stream fileStream = FileSystemUtils.Instance.OpenFile(StoragePath, UtilFileMode.Open))
index fda442d..43ecb20 100644 (file)
@@ -31,6 +31,8 @@ namespace LibTVRefCommonPortable.Utils
         /// <summary>
         /// A method starts the file system watcher.
         /// </summary>
-        void Run();
+        /// <param name="path">Target file path</param>
+        /// <param name="fileName">Target file name</param>
+        void Run(String path, String fileName);
     }
 }
index b1dc3d5..731690a 100755 (executable)
@@ -35,15 +35,22 @@ namespace LibTVRefCommonTizen.Ports
         /// Listens to the file system change notifications and raises events when a directory, or file in a directory, changes
         /// If the 'pinned_apps_info.xml' is created, changed, or deleted, invokes event handler method
         /// </summary>
+        /// <param name="path">A file path which has the target file</param>
+        /// <param name="fileName">A file name to be watching</param>
         /// <remarks>
         /// https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher(v=vs.110).aspx
         /// </remarks>
-        public void Run()
+        public void Run(String path, String fileName)
         {
+            if (File.Exists(path + fileName) == false)
+            {
+                DbgPort.E("Watching File is not exist!!!" + path + fileName);
+            }
+
             watcher = new FileSystemWatcher();
-            watcher.Path = "/opt/usr/home/owner/share/";
+            watcher.Path = path;
             watcher.NotifyFilter = NotifyFilters.LastWrite;
-            watcher.Filter = "pinned_apps_info.xml";
+            watcher.Filter = fileName;
 
             watcher.Created += new FileSystemEventHandler(WatcherChanged);
             watcher.Changed += new FileSystemEventHandler(WatcherChanged);
index ac5121d..717e365 100755 (executable)
@@ -238,7 +238,7 @@ namespace TVHome
         }
 
         /// <summary>
-        /// A method for receiving application pinned noficiation and invoke pinned event
+        /// A method for receiving application pinned notification and invoke pinned event
         /// </summary>
         /// <param name="appID">A pinned app ID</param>
         public void OnAppPinnedNotificationReceived(String appID)