if (AppId == null || AppId.Length <= 0)
{
- DebuggingUtils.Err("The AppID is null or black");
+ DebuggingUtils.Err("The AppID is null or blank");
return;
}
/// <summary>
/// Gets the information of the specified application with the app ID
/// </summary>
- /// <param name="appID">The app Id you want to get</param>
- /// <returns>The information of the installed applications</returns>
+ /// <param name="appID">The app Id to get</param>
+ /// <returns>The information of the installed application</returns>
public Dictionary<string, string> GetInstalledApplication(string appID)
{
Dictionary<string, string> result = null;
}
/// <summary>
- ///Displays a dialog with a given message
+ /// Displays a dialog with a given message
/// </summary>
/// <param name="message"> A debugging message </param>
public void Popup(string message)
*/
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using System.IO;
-
-using Tizen;
-using Tizen.Applications;
using LibTVRefCommonPortable.Utils;
namespace LibTVRefCommonTizen.Ports
{
+ /// <summary>
+ /// Handles FileSystem APIs
+ /// </summary>
public class FileSystemPort : IFileSystemAPIs
{
+ /// <summary>
+ /// Opens the given file
+ /// </summary>
+ /// <param name="filePath">A relative or absolute path for the file that the current FileStream object will encapsulate</param>
+ /// <param name="mode">A constant that determines how to open or create the file</param>
+ /// <returns>A generic view of a sequence of bytes</returns>
public Stream OpenFile(string filePath, UtilFileMode mode)
{
Stream fileStream = null;
return fileStream;
}
+ /// <summary>
+ /// Flushes the given steam
+ /// </summary>
+ /// <param name="stream">The stream to flush</param>
public void Flush(Stream stream)
{
var fileStream = stream as FileStream;
fileStream.Flush();
}
+ /// <summary>
+ /// Closes the given stream
+ /// </summary>
+ /// <param name="stream">The stream to close</param>
public void CloseFile(Stream stream)
{
var fileStream = stream as FileStream;
fileStream.Dispose();
}
+ /// <summary>
+ /// Checks whether the given file exist
+ /// </summary>
+ /// <param name="fileName">The file to check</param>
+ /// <returns>
+ /// true if the caller has the required permissions and path contains the name of an existing file, otherwise, false
+ /// </returns>
+ /// <remarks>
+ /// https://msdn.microsoft.com/en-us/library/system.io.file.exists(v=vs.110).aspx
+ /// </remarks>
public bool IsFileExist(String fileName)
{
return File.Exists(fileName);
}
+ /// <summary>
+ /// Checks whether the given file ready
+ /// </summary>
+ /// <param name="fileName">The file to check</param>
+ /// <returns>
+ /// true if the file is ready to open, otherwise, false
+ /// </returns>
+ /// <remarks>
+ /// https://msdn.microsoft.com/en-us/library/y973b725(v=vs.110).aspx
+ /// </remarks>
public bool IsFileReady(String fileName)
{
try
{
using (FileStream inputStream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.None))
{
- if (inputStream.Length > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
+ return (inputStream.Length > 0) ? true : false;
}
}
catch (Exception)
namespace LibTVRefCommonTizen.Ports
{
+ /// <summary>
+ /// Handles FileSystemWatcher APIs
+ /// </summary>
public class FileSystemWatcherPort : IFileSystemWatcherAPIs
{
static FileSystemWatcher watcher;
public event EventHandler<EventArgs> CustomChanged;
private FileSystemEventCustomArgs args;
+ /// <summary>
+ /// 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>
+ /// <remarks>
+ /// https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher(v=vs.110).aspx
+ /// </remarks>
public void Run()
{
watcher = new FileSystemWatcher();
watcher.EnableRaisingEvents = true;
}
+ /// <summary>
+ /// Represents the method that will handle the Changed, Created, or Deleted event of a FileSystemWatcher class
+ /// </summary>
+ /// <param name="sender">The source of the event</param>
+ /// <param name="e">The FileSystemEventArgs that contains the event data</param>
+ /// <remarks>
+ /// https://msdn.microsoft.com/en-us/library/system.io.filesystemeventhandler(v=vs.110).aspx
+ /// </remarks>
private void WatcherChanged(object sender, FileSystemEventArgs e)
{
args = new FileSystemEventCustomArgs((WatcherType)e.ChangeType, e.FullPath, e.Name);
using Tizen.Applications;
using LibTVRefCommonPortable.Utils;
+using System;
namespace LibTVRefCommonTizen.Ports
{
+ /// <summary>
+ /// Handles PackageManager APIs
+ /// </summary>
public class PackageManagerPort : IPackageManager
{
private static IPlatformNotification Notification
set;
}
+ /// <summary>
+ /// The constructor for this class
+ /// </summary>
public PackageManagerPort()
{
}
+ /// <summary>
+ /// Registers a callback function to be invoked when the package is installed or uninstalled
+ /// </summary>
+ /// <param name="app"></param>
public static void RegisterCallbacks(IPlatformNotification app)
{
Notification = app;
PackageManager.UninstallProgressChanged += PackageManager_UninstallProgressChanged;
}
- public static void DeregisterCallbacks()
+ /// <summary>
+ /// Unregisters the callback function
+ /// </summary>
+ public static void UnregisterCallbacks()
{
Notification = null;
PackageManager.InstallProgressChanged -= PackageManager_InstallProgressChanged;
PackageManager.UninstallProgressChanged -= PackageManager_UninstallProgressChanged;
}
+ /// <summary>
+ /// UninstallProgressChanged event
+ /// This event is occurred when a package is getting uninstalled and the progress of the request to the package manager changes
+ /// </summary>
+ /// <param name="sender">The source of the event</param>
+ /// <param name="e">An object that contains no event data</param>
private static void PackageManager_UninstallProgressChanged(object sender, PackageManagerEventArgs e)
{
if (e.State == PackageEventState.Completed)
}
}
+ /// <summary>
+ /// InstallProgressChanged event
+ /// This event is occurred when a package is getting installed and the progress of the request to the package manager changes
+ /// </summary>
+ /// <param name="sender">The source of the event</param>
+ /// <param name="e">An object that contains no event data</param>
private static void PackageManager_InstallProgressChanged(object sender, PackageManagerEventArgs e)
{
if (e.State == PackageEventState.Completed)
}
}
+ /// <summary>
+ /// Retrieves package information of all installed packages
+ /// </summary>
+ /// <returns>The list of packages.</returns>
public Dictionary<string, string[]> GetPackageList()
{
Dictionary<string, string[]> pkgList = new Dictionary<string, string[]>();
foreach (var item in packages)
{
- if (item.Label == null ||
- item.Id == null)
+ if (item.Id == null)
{
continue;
}
result = new string[3];
- result[0] = item.Label;
+ result[0] = (item.Label == null || item.Label.Length <= 0) ? "No Name" : item.Label;
result[1] = item.Id;
result[2] = (System.IO.File.Exists(item.IconPath)) ? item.IconPath : "AppIcon.png";
return pkgList;
}
- public string GetPackage(string PkgID)
+ /// <summary>
+ /// Gets the package information for the given package
+ /// </summary>
+ /// <param name="pkgID">The ID of the package</param>
+ /// <returns>The package name for the given package ID</returns>
+ public string GetPackage(string pkgID)
{
- Package tempItem = PackageManager.GetPackage(PkgID);
+ try
+ {
+ Package tempItem = PackageManager.GetPackage(pkgID);
+
+ return tempItem.Label;
+ }
+ catch (Exception e)
+ {
+ DebuggingUtils.Err("Failed to get package information(" + pkgID + ") : " + e.Message);
- return (tempItem != null) ? tempItem.Label : null;
+ return null;
+ }
}
+ /// <summary>
+ /// Uninstalls package with the given package
+ /// </summary>
+ /// <param name="pkgID">The ID of the package to be uninstalled</param>
+ /// <returns>Returns true if uninstalltion request is successful, false otherwise</returns>
public bool UninstallPackage(string pkgID)
{
- Package tempItem = PackageManager.GetPackage(pkgID);
- if (tempItem == null)
+ try
+ {
+ Package tempItem = PackageManager.GetPackage(pkgID);
+
+ return PackageManager.Uninstall(tempItem.Id, tempItem.PackageType);
+ }
+ catch (Exception e)
{
+ DebuggingUtils.Err("Failed to get package information(" + pkgID + ") : " + e.Message);
+
return false;
}
- return PackageManager.Uninstall(tempItem.Id, tempItem.PackageType);
}
+ /// <summary>
+ /// Uninstalls package with the given app ID
+ /// </summary>
+ /// <param name="appID">The app ID to be uninstalled<</param>
+ /// <returns>Returns true if uninstallation request is successful, false otherwise</returns>
public bool UninstallPackageByAppID(string appID)
{
- string pkgID = PackageManager.GetPackageIdByApplicationId(appID);
- if (pkgID == null ||
- pkgID.Length == 0)
+ try
{
- return false;
+ string pkgID = PackageManager.GetPackageIdByApplicationId(appID);
+
+ return UninstallPackage(pkgID);
}
+ catch (Exception e)
+ {
+ DebuggingUtils.Err("Failed to uninstall by AppID(" + appID + ") : " + e.Message);
- return UninstallPackage(pkgID);
+ return false;
+ }
}
}
}
\ No newline at end of file
base.OnTerminate();
notification = null;
- PackageManagerPort.DeregisterCallbacks();
+ PackageManagerPort.UnregisterCallbacks();
MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformBackButtonName);
MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName);
base.OnTerminate();
notification = null;
- PackageManagerPort.DeregisterCallbacks();
+ PackageManagerPort.UnregisterCallbacks();
MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName);
MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName);
}