/// <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);
{
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))
/// <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);
}
}
/// 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);
}
/// <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)