From 94457f0f47313bcf763026647df8b182d3d161c7 Mon Sep 17 00:00:00 2001 From: ChulSeung Kim Date: Thu, 15 Jun 2017 09:08:33 +0900 Subject: [PATCH] Make the AppShortcutStorage checks storage(xml) starting time. Change-Id: I02d52de4cf8b72250915c651cc87b451a53add6d --- .../Stubs/FileWatcherAPITestStub.cs | 4 +++- LibTVRefCommonPortable/Utils/AppShortcutStorage.cs | 25 +++++++++++++++------- .../Utils/IFileSystemWatcherAPIs.cs | 4 +++- LibTVRefCommonTizen/Ports/FileSystemWatcherPort.cs | 13 ++++++++--- TVHome/TVHome/TVHome.cs | 2 +- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/LibTVRefCommonPortable/Stubs/FileWatcherAPITestStub.cs b/LibTVRefCommonPortable/Stubs/FileWatcherAPITestStub.cs index fe4aa6b..24709b5 100644 --- a/LibTVRefCommonPortable/Stubs/FileWatcherAPITestStub.cs +++ b/LibTVRefCommonPortable/Stubs/FileWatcherAPITestStub.cs @@ -32,7 +32,9 @@ namespace LibTVRefCommonPortable.Stubs /// /// A method starts the file system watcher. /// - public void Run() + /// Target file path + /// Target file name + public void Run(String path, String fileName) { CustomChanged?.Invoke(this, EventArgs.Empty); diff --git a/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs b/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs index 47baace..67b5ae1 100644 --- a/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs +++ b/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs @@ -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"); } /// - /// A method provides an app Shortcut list. + /// Check if the storage is exist /// - /// An app Shortcut list. - public static async Task> Read() + private static void CheckStorage() { if (FileSystemUtils.Instance.IsFileExist(StoragePath) == false) { DebuggingUtils.Err("Set Default Pinned Apps" + StoragePath); List result = new List(); Write(result); - return result; } + } + + /// + /// A method provides an app Shortcut list. + /// + /// An app Shortcut list. + public static async Task> 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(); } 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)) diff --git a/LibTVRefCommonPortable/Utils/IFileSystemWatcherAPIs.cs b/LibTVRefCommonPortable/Utils/IFileSystemWatcherAPIs.cs index fda442d..43ecb20 100644 --- a/LibTVRefCommonPortable/Utils/IFileSystemWatcherAPIs.cs +++ b/LibTVRefCommonPortable/Utils/IFileSystemWatcherAPIs.cs @@ -31,6 +31,8 @@ namespace LibTVRefCommonPortable.Utils /// /// A method starts the file system watcher. /// - void Run(); + /// Target file path + /// Target file name + void Run(String path, String fileName); } } diff --git a/LibTVRefCommonTizen/Ports/FileSystemWatcherPort.cs b/LibTVRefCommonTizen/Ports/FileSystemWatcherPort.cs index b1dc3d5..731690a 100755 --- a/LibTVRefCommonTizen/Ports/FileSystemWatcherPort.cs +++ b/LibTVRefCommonTizen/Ports/FileSystemWatcherPort.cs @@ -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 /// + /// A file path which has the target file + /// A file name to be watching /// /// https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher(v=vs.110).aspx /// - 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); diff --git a/TVHome/TVHome/TVHome.cs b/TVHome/TVHome/TVHome.cs index ac5121d..717e365 100755 --- a/TVHome/TVHome/TVHome.cs +++ b/TVHome/TVHome/TVHome.cs @@ -238,7 +238,7 @@ namespace TVHome } /// - /// A method for receiving application pinned noficiation and invoke pinned event + /// A method for receiving application pinned notification and invoke pinned event /// /// A pinned app ID public void OnAppPinnedNotificationReceived(String appID) -- 2.7.4