1. Add FileSystemWatcher Interface, Port
authorHeonjae Jang <heonjae.jang@samsung.com>
Thu, 23 Feb 2017 07:47:43 +0000 (16:47 +0900)
committerChulSeung Kim <charles0.kim@samsung.com>
Thu, 8 Jun 2017 09:34:44 +0000 (18:34 +0900)
2. Add DataType for FileSystemWatcher Event
3. Add methods for attaching event listener in MainPageViewModel, AppShortcutController and AppShortcutStorage.

Change-Id: I2148a2a2f3c2874d4fe322310062554fbf515426

TVHome/TVHome.TizenTV/Ports/FileSystemWatcherPort.cs [new file with mode: 0644]
TVHome/TVHome.TizenTV/TVHome.TizenTV.cs
TVHome/TVHome/DataModels/FileSystemEventCustomArgs.cs [new file with mode: 0644]
TVHome/TVHome/DataModels/WatcherType.cs [new file with mode: 0644]
TVHome/TVHome/Models/AppShortcutController.cs
TVHome/TVHome/Utils/AppShortcutStorage.cs
TVHome/TVHome/Utils/IFileSystemWatcherAPIs.cs [new file with mode: 0644]
TVHome/TVHome/ViewModels/MainPageViewModel.cs

diff --git a/TVHome/TVHome.TizenTV/Ports/FileSystemWatcherPort.cs b/TVHome/TVHome.TizenTV/Ports/FileSystemWatcherPort.cs
new file mode 100644 (file)
index 0000000..7c7cc17
--- /dev/null
@@ -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<EventArgs> 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);
+        }
+    }
+}
index bbc97e89a111b286f4763be8e65cfedff5350936..da476667d8704a7d451ad53196a46a52038746c1 100644 (file)
@@ -40,7 +40,8 @@ namespace TVHome.TizenTV
             global::Xamarin.Forms.DependencyService.Register<PackageManagerPort>();\r
             global::Xamarin.Forms.DependencyService.Register<WifiModulePort>();\r
             global::Xamarin.Forms.DependencyService.Register<BTModulePort>();\r
-                       global::Xamarin.Forms.DependencyService.Register<ApplicationManagerPort>();\r
+            global::Xamarin.Forms.DependencyService.Register<FileSystemWatcherPort>();\r
+            global::Xamarin.Forms.DependencyService.Register<ApplicationManagerPort>();\r
                        global::Xamarin.Forms.Platform.Tizen.Forms.Init(app);\r
             app.Run(args);\r
         }\r
diff --git a/TVHome/TVHome/DataModels/FileSystemEventCustomArgs.cs b/TVHome/TVHome/DataModels/FileSystemEventCustomArgs.cs
new file mode 100644 (file)
index 0000000..d5345f2
--- /dev/null
@@ -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 (file)
index 0000000..e47bbbc
--- /dev/null
@@ -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
+    }
+}
index e3e63904be6dbceb7777242606f911491611e8a5..56b62a29586c09fa3049e60d88c85bd8cb2caa76 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.\r
  */\r
 \r
+using System;\r
 using System.Collections.Generic;\r
 using TVHome.DataModels;\r
 using TVHome.Utils;\r
@@ -47,7 +48,7 @@ namespace TVHome.Models
 \r
         public IEnumerable<AppShortcutInfo> GetPackageList()\r
         {\r
-            IEnumerable<AppShortcutInfo> appList = AppShortcutStorage.Read();\r
+            IEnumerable<AppShortcutInfo> appList = AppShortcutStorage.Instance.Read();\r
             return appList;\r
         }\r
 \r
@@ -62,5 +63,17 @@ namespace TVHome.Models
             // TODO : register to Tizen app framework to get notification of app list change.\r
             return false;\r
         }\r
+\r
+        public void AddFileSystemChangedListener(EventHandler<EventArgs> eventListener)\r
+        {\r
+            if (AppShortcutStorage.Instance != null)\r
+            {\r
+                AppShortcutStorage.Instance.AddFileSystemChangedListener(eventListener);\r
+            }\r
+            else\r
+            {\r
+                DebuggingUtils.Dbg("AppShortcutStorage Instance is NULL");\r
+            }\r
+        }\r
     }\r
 }\r
index 219410b17c0b0e07426e58d9526f1a2f5a3fc2fc..19a031e92795dde2d298c780c64ff715cc28c29c 100644 (file)
@@ -27,10 +27,11 @@ namespace TVHome.Utils
 {\r
     public class AppShortcutStorage\r
     {\r
-        private static AppShortcutStorage instance = new AppShortcutStorage();\r
-\r
         private static List<HomeMenuAppShortcutInfo> HomeMenuList = new List<HomeMenuAppShortcutInfo>();\r
         private static List<AppShortcutInfo> list = new List<AppShortcutInfo>();\r
+        private static IFileSystemWatcherAPIs fileSystemWatcher = DependencyService.Get<IFileSystemWatcherAPIs>();\r
+\r
+        private static AppShortcutStorage instance = new AppShortcutStorage();\r
 \r
         private string DBName = "tvhome.apps";\r
         //private string CreateTableStatement = "CREATE TABLE IF NOT EXISTS app_shortcut(" +\r
@@ -39,100 +40,18 @@ namespace TVHome.Utils
 \r
         public static AppShortcutStorage Instance\r
         {\r
-            get;\r
+            get { return instance; }\r
         }\r
 \r
         private AppShortcutStorage()\r
         {\r
-            DebuggingUtils.Err("AppShortcutStorage ------------------------------");\r
-\r
-            DebuggingUtils.Err("Create Table");\r
-            if (DependencyService.Get<IDBAPIs>().ExecSQL(DBName, CreateTableStatement) == false)\r
-            {\r
-                DebuggingUtils.Err("DB Creation Failed!!! " + CreateTableStatement);\r
-            }\r
-\r
-            DebuggingUtils.Err("Create Apps ------------------------------");\r
-            AppShortcutInfo app1 = new AppShortcutInfo()\r
-            {\r
-                ID = "app1",\r
-                AppName = "app1",\r
-                PackageID = "org.tizen.settings",\r
-                AppID = "org.tizen.settings",\r
-                StateDescriptions =\r
-                    {\r
-                        {\r
-                            "default",\r
-                            new StateDescription\r
-                            {\r
-                                Label = "default",\r
-                                IconPath = "wifion.png",    // result[2]\r
-                                Action = new AppControlAction()\r
-                                {\r
-                                    PkgID = "org.tizen.settings"    // result[1]\r
-                                }\r
-                            }\r
-                        },\r
-                    }\r
-            };\r
-            Create(app1);\r
-            AppShortcutInfo app2 = new AppShortcutInfo()\r
-            {\r
-                ID = "app2",\r
-                AppName = "app2",\r
-                PackageID = "org.tizen.settings",\r
-                AppID = "org.tizen.settings",\r
-                StateDescriptions =\r
-                    {\r
-                        {\r
-                            "default",\r
-                            new StateDescription\r
-                            {\r
-                               Label = "default",\r
-                                IconPath = "wifion.png",    // result[2]\r
-                                Action = new AppControlAction()\r
-                                {\r
-                                    PkgID = "org.tizen.settings"    // result[1]\r
-                                }\r
-                            }\r
-                        },\r
-                    }\r
-            };\r
-            Create(app2);\r
-            AppShortcutInfo app3 = new AppShortcutInfo()\r
-            {\r
-                ID = "app3",\r
-                AppName = "app3",\r
-                PackageID = "org.tizen.settings",\r
-                AppID = "org.tizen.settings",\r
-                StateDescriptions =\r
-                    {\r
-                        {\r
-                            "default",\r
-                            new StateDescription\r
-                            {\r
-                                Label = "default",\r
-                                IconPath = "wifion.png",    // result[2]\r
-                                Action = new AppControlAction()\r
-                                {\r
-                                    PkgID = "org.tizen.settings"    // result[1]\r
-                                }\r
-                            }\r
-                        },\r
-                    }\r
-            };\r
-            Create(app3);\r
-\r
-            // DB Test code\r
-            DebuggingUtils.Err("Read Apps ------------------------------");\r
-            Read();\r
+            fileSystemWatcher.run();\r
         }\r
-\r
         public bool Create(AppShortcutInfo app)\r
         {\r
             string query = "INSERT INTO app_shortcut VALUES(";\r
 \r
-            foreach(var value in app.GetColumnValues())\r
+            foreach (var value in app.GetColumnValues())\r
             {\r
                 query += "'";\r
                 query += value;\r
@@ -166,10 +85,10 @@ namespace TVHome.Utils
             return null;\r
         }\r
 \r
-        public static IEnumerable<AppShortcutInfo> Read()\r
+        public IEnumerable<AppShortcutInfo> Read()\r
         {\r
             // DB Test code\r
-                       /*\r
+            /*\r
             {\r
                 DebuggingUtils.Dbg("Read test");\r
                 string query = "SELECT * FROM app_shortcut;";\r
@@ -249,5 +168,10 @@ namespace TVHome.Utils
                 return false;\r
             }\r
         }\r
+\r
+        public void AddFileSystemChangedListener(EventHandler<EventArgs> eventListener)\r
+        {\r
+            fileSystemWatcher.CustomChanged += eventListener;\r
+        }\r
     }\r
 }\r
diff --git a/TVHome/TVHome/Utils/IFileSystemWatcherAPIs.cs b/TVHome/TVHome/Utils/IFileSystemWatcherAPIs.cs
new file mode 100644 (file)
index 0000000..9c6bd3f
--- /dev/null
@@ -0,0 +1,11 @@
+using System;
+using TVHome.DataModels;
+
+namespace TVHome.Utils
+{
+    public interface IFileSystemWatcherAPIs
+    {
+        event EventHandler<EventArgs> CustomChanged;
+        void run();
+    }
+}
index 0f70c1621762d041c9b75f857a9ef4dec89a702f..aead3f891c8bbb3f6908baa30c2d1d6f1ad6073d 100644 (file)
@@ -74,25 +74,33 @@ namespace TVHome.ViewModels
             MainList = TempList;\r
             OnPropertyChanged("MainList");\r
 \r
-                       MakeRecentButtons();\r
-\r
-                       AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPackageList();\r
+            MakeRecentButtons();\r
 \r
+            AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPackageList();\r
             OnPropertyChanged("AppList");\r
 \r
             //SettingsList = TVHomeImpl.GetInstance.AppShortcutControllerInstnace.GetPackageList();\r
             SettingsList = TVHomeImpl.GetInstance.SettingShortcutControllerInstance.GetList();\r
             OnPropertyChanged("SettingsList");\r
+\r
+            TVHomeImpl.GetInstance.AppShortcutControllerInstance.AddFileSystemChangedListener(TestFunction);\r
         }\r
 \r
-               private async void MakeRecentButtons()\r
-               {\r
-                       RecentList = await TVHomeImpl.GetInstance.RecentShortcutControllerInstance.GetList();\r
-                       if (RecentList != null)\r
-                       {\r
-                               OnPropertyChanged("RecentList");\r
-                       }\r
-               }\r
 \r
-       }\r
+        private void TestFunction(object sender, EventArgs e)\r
+        {\r
+            AppList = TVHomeImpl.GetInstance.AppShortcutControllerInstance.GetPackageList();\r
+            OnPropertyChanged("AppList");\r
+        }\r
+\r
+        private async void MakeRecentButtons()\r
+        {\r
+            RecentList = await TVHomeImpl.GetInstance.RecentShortcutControllerInstance.GetList();\r
+            if (RecentList != null)\r
+            {\r
+                OnPropertyChanged("RecentList");\r
+            }\r
+        }\r
+\r
+    }\r
 }\r