From: Heonjae Jang Date: Thu, 23 Feb 2017 07:47:43 +0000 (+0900) Subject: 1. Add FileSystemWatcher Interface, Port X-Git-Tag: submit/tizen/20170808.015446~241 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=845f15a81955abc313f3ffccc9cdc8d48c866110;p=profile%2Ftv%2Fapps%2Fdotnet%2Fhome.git 1. Add FileSystemWatcher Interface, Port 2. Add DataType for FileSystemWatcher Event 3. Add methods for attaching event listener in MainPageViewModel, AppShortcutController and AppShortcutStorage. Change-Id: I2148a2a2f3c2874d4fe322310062554fbf515426 --- diff --git a/TVHome/TVHome.TizenTV/Ports/FileSystemWatcherPort.cs b/TVHome/TVHome.TizenTV/Ports/FileSystemWatcherPort.cs new file mode 100644 index 0000000..7c7cc17 --- /dev/null +++ b/TVHome/TVHome.TizenTV/Ports/FileSystemWatcherPort.cs @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +using System; +using System.IO; +using TVHome.Utils; +using TVHome.DataModels; + +namespace TVHome.TizenTV.Ports +{ + public class FileSystemWatcherPort : IFileSystemWatcherAPIs + { + static FileSystemWatcher watcher; + public event EventHandler CustomChanged; + private FileSystemEventCustomArgs args; + + public void run() + { + watcher = new FileSystemWatcher(); + watcher.Path = "/opt/usr/home/owner/share/"; + watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.Size; + watcher.Filter = "apinnedapp.xml"; + + watcher.Created += new FileSystemEventHandler(WatcherChanged); + watcher.Changed += new FileSystemEventHandler(WatcherChanged); + watcher.Deleted += new FileSystemEventHandler(WatcherChanged); + watcher.IncludeSubdirectories = true; + watcher.EnableRaisingEvents = true; + } + + private void WatcherChanged(object sender, FileSystemEventArgs e) + { + args = new FileSystemEventCustomArgs((WatcherType)e.ChangeType, e.FullPath, e.Name); + if (e.ChangeType.Equals(WatcherChangeTypes.Changed)) + { + CustomChanged(this, args); + } + DebuggingPort.d(e.ChangeType + ", " + e.Name); + } + } +} diff --git a/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs b/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs index bbc97e8..da47666 100644 --- a/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs +++ b/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs @@ -40,7 +40,8 @@ namespace TVHome.TizenTV global::Xamarin.Forms.DependencyService.Register(); global::Xamarin.Forms.DependencyService.Register(); global::Xamarin.Forms.DependencyService.Register(); - global::Xamarin.Forms.DependencyService.Register(); + global::Xamarin.Forms.DependencyService.Register(); + global::Xamarin.Forms.DependencyService.Register(); global::Xamarin.Forms.Platform.Tizen.Forms.Init(app); app.Run(args); } diff --git a/TVHome/TVHome/DataModels/FileSystemEventCustomArgs.cs b/TVHome/TVHome/DataModels/FileSystemEventCustomArgs.cs new file mode 100644 index 0000000..d5345f2 --- /dev/null +++ b/TVHome/TVHome/DataModels/FileSystemEventCustomArgs.cs @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace TVHome.DataModels +{ + public class FileSystemEventCustomArgs : EventArgs + { + // + // Summary: + // Initializes a new instance of the System.IO.FileSystemEventArgs class. + // + // Parameters: + // changeType: + // One of the System.IO.WatcherChangeTypes values, which represents the kind of + // change detected in the file system. + // + // directory: + // The root directory of the affected file or directory. + // + // name: + // The name of the affected file or directory. + public FileSystemEventCustomArgs(WatcherType changeType, string directory, string name) + { + ChangeType = changeType; + FullPath = directory; + Name = name; + } + + // + // Summary: + // Gets the type of directory event that occurred. + // + // Returns: + // One of the System.IO.WatcherChangeTypes values that represents the kind of change + // detected in the file system. + public WatcherType ChangeType { set; get; } + // + // Summary: + // Gets the fully qualifed path of the affected file or directory. + // + // Returns: + // The path of the affected file or directory. + public string FullPath { set; get; } + // + // Summary: + // Gets the name of the affected file or directory. + // + // Returns: + // The name of the affected file or directory. + public string Name { set; get; } + } +} + diff --git a/TVHome/TVHome/DataModels/WatcherType.cs b/TVHome/TVHome/DataModels/WatcherType.cs new file mode 100644 index 0000000..e47bbbc --- /dev/null +++ b/TVHome/TVHome/DataModels/WatcherType.cs @@ -0,0 +1,27 @@ +namespace TVHome.DataModels +{ + public enum WatcherType + { + // + // Summary: + // The creation of a file or folder. + Created = 1, + // + // Summary: + // The deletion of a file or folder. + Deleted = 2, + // + // Summary: + // The change of a file or folder. The types of changes include: changes to size, + // attributes, security settings, last write, and last access time. + Changed = 4, + // + // Summary: + // The renaming of a file or folder. + Renamed = 8, + // + // Summary: + // The creation, deletion, change, or renaming of a file or folder. + All = 15 + } +} diff --git a/TVHome/TVHome/Models/AppShortcutController.cs b/TVHome/TVHome/Models/AppShortcutController.cs index e3e6390..56b62a2 100644 --- a/TVHome/TVHome/Models/AppShortcutController.cs +++ b/TVHome/TVHome/Models/AppShortcutController.cs @@ -14,6 +14,7 @@ * limitations under the License. */ +using System; using System.Collections.Generic; using TVHome.DataModels; using TVHome.Utils; @@ -47,7 +48,7 @@ namespace TVHome.Models public IEnumerable GetPackageList() { - IEnumerable appList = AppShortcutStorage.Read(); + IEnumerable appList = AppShortcutStorage.Instance.Read(); return appList; } @@ -62,5 +63,17 @@ namespace TVHome.Models // TODO : register to Tizen app framework to get notification of app list change. return false; } + + public void AddFileSystemChangedListener(EventHandler eventListener) + { + if (AppShortcutStorage.Instance != null) + { + AppShortcutStorage.Instance.AddFileSystemChangedListener(eventListener); + } + else + { + DebuggingUtils.Dbg("AppShortcutStorage Instance is NULL"); + } + } } } diff --git a/TVHome/TVHome/Utils/AppShortcutStorage.cs b/TVHome/TVHome/Utils/AppShortcutStorage.cs index 219410b..19a031e 100644 --- a/TVHome/TVHome/Utils/AppShortcutStorage.cs +++ b/TVHome/TVHome/Utils/AppShortcutStorage.cs @@ -27,10 +27,11 @@ namespace TVHome.Utils { public class AppShortcutStorage { - private static AppShortcutStorage instance = new AppShortcutStorage(); - private static List HomeMenuList = new List(); private static List list = new List(); + private static IFileSystemWatcherAPIs fileSystemWatcher = DependencyService.Get(); + + private static AppShortcutStorage instance = new AppShortcutStorage(); private string DBName = "tvhome.apps"; //private string CreateTableStatement = "CREATE TABLE IF NOT EXISTS app_shortcut(" + @@ -39,100 +40,18 @@ namespace TVHome.Utils public static AppShortcutStorage Instance { - get; + get { return instance; } } private AppShortcutStorage() { - DebuggingUtils.Err("AppShortcutStorage ------------------------------"); - - DebuggingUtils.Err("Create Table"); - if (DependencyService.Get().ExecSQL(DBName, CreateTableStatement) == false) - { - DebuggingUtils.Err("DB Creation Failed!!! " + CreateTableStatement); - } - - DebuggingUtils.Err("Create Apps ------------------------------"); - AppShortcutInfo app1 = new AppShortcutInfo() - { - ID = "app1", - AppName = "app1", - PackageID = "org.tizen.settings", - AppID = "org.tizen.settings", - StateDescriptions = - { - { - "default", - new StateDescription - { - Label = "default", - IconPath = "wifion.png", // result[2] - Action = new AppControlAction() - { - PkgID = "org.tizen.settings" // result[1] - } - } - }, - } - }; - Create(app1); - AppShortcutInfo app2 = new AppShortcutInfo() - { - ID = "app2", - AppName = "app2", - PackageID = "org.tizen.settings", - AppID = "org.tizen.settings", - StateDescriptions = - { - { - "default", - new StateDescription - { - Label = "default", - IconPath = "wifion.png", // result[2] - Action = new AppControlAction() - { - PkgID = "org.tizen.settings" // result[1] - } - } - }, - } - }; - Create(app2); - AppShortcutInfo app3 = new AppShortcutInfo() - { - ID = "app3", - AppName = "app3", - PackageID = "org.tizen.settings", - AppID = "org.tizen.settings", - StateDescriptions = - { - { - "default", - new StateDescription - { - Label = "default", - IconPath = "wifion.png", // result[2] - Action = new AppControlAction() - { - PkgID = "org.tizen.settings" // result[1] - } - } - }, - } - }; - Create(app3); - - // DB Test code - DebuggingUtils.Err("Read Apps ------------------------------"); - Read(); + fileSystemWatcher.run(); } - public bool Create(AppShortcutInfo app) { string query = "INSERT INTO app_shortcut VALUES("; - foreach(var value in app.GetColumnValues()) + foreach (var value in app.GetColumnValues()) { query += "'"; query += value; @@ -166,10 +85,10 @@ namespace TVHome.Utils return null; } - public static IEnumerable Read() + public IEnumerable Read() { // DB Test code - /* + /* { DebuggingUtils.Dbg("Read test"); string query = "SELECT * FROM app_shortcut;"; @@ -249,5 +168,10 @@ namespace TVHome.Utils return false; } } + + public void AddFileSystemChangedListener(EventHandler eventListener) + { + fileSystemWatcher.CustomChanged += eventListener; + } } } diff --git a/TVHome/TVHome/Utils/IFileSystemWatcherAPIs.cs b/TVHome/TVHome/Utils/IFileSystemWatcherAPIs.cs new file mode 100644 index 0000000..9c6bd3f --- /dev/null +++ b/TVHome/TVHome/Utils/IFileSystemWatcherAPIs.cs @@ -0,0 +1,11 @@ +using System; +using TVHome.DataModels; + +namespace TVHome.Utils +{ + public interface IFileSystemWatcherAPIs + { + event EventHandler CustomChanged; + void run(); + } +} diff --git a/TVHome/TVHome/ViewModels/MainPageViewModel.cs b/TVHome/TVHome/ViewModels/MainPageViewModel.cs index 0f70c16..aead3f8 100644 --- a/TVHome/TVHome/ViewModels/MainPageViewModel.cs +++ b/TVHome/TVHome/ViewModels/MainPageViewModel.cs @@ -74,25 +74,33 @@ namespace TVHome.ViewModels MainList = TempList; OnPropertyChanged("MainList"); - MakeRecentButtons(); - - AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPackageList(); + MakeRecentButtons(); + AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPackageList(); OnPropertyChanged("AppList"); //SettingsList = TVHomeImpl.GetInstance.AppShortcutControllerInstnace.GetPackageList(); SettingsList = TVHomeImpl.GetInstance.SettingShortcutControllerInstance.GetList(); OnPropertyChanged("SettingsList"); + + TVHomeImpl.GetInstance.AppShortcutControllerInstance.AddFileSystemChangedListener(TestFunction); } - private async void MakeRecentButtons() - { - RecentList = await TVHomeImpl.GetInstance.RecentShortcutControllerInstance.GetList(); - if (RecentList != null) - { - OnPropertyChanged("RecentList"); - } - } - } + private void TestFunction(object sender, EventArgs e) + { + AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPackageList(); + OnPropertyChanged("AppList"); + } + + private async void MakeRecentButtons() + { + RecentList = await TVHomeImpl.GetInstance.RecentShortcutControllerInstance.GetList(); + if (RecentList != null) + { + OnPropertyChanged("RecentList"); + } + } + + } }