예제 #1
0
        /// <summary>
        /// Creates a file under the given directory.
        /// </summary>
        /// <param name="baseDirectory">The base Directory to create file under it.</param>
        /// <param name="fileName">The file name.</param>
        /// <returns>The file created, or null if file cannot be created.</returns>
        public FileData CreateFile(string fileName, DirectoryData baseDirectory)
        {
            FileData file     = null;
            string   path     = Path.Combine(baseDirectory.FullName, fileName);
            string   rootPath = GetDirectoryRoot().FullName;

            if (baseDirectory != null)
            {
                if (!path.StartsWith(rootPath))
                {
                    path = Path.Combine(rootPath, path);                       // concats root path to the given base path.
                }
            }
            else
            {
                path = rootPath;                 // creates file under root path.
            }

            if (!File.Exists(path))
            {
                try {
                    FileStream fs = File.Create(path);
                    file = new FileData(path, fs.Length);
                    fs.Close();
                } catch (Exception e) {
                    SystemLogger.Log(SystemLogger.Module.CORE, "Error creating file [" + path + "]", e);
                }
            }

            return(file);
        }
예제 #2
0
        /// <summary>
        /// Creates a directory under the given base directory.
        /// </summary>
        /// <param name="baseDirectory">>The base Directory to create directory under it.</param>
        /// <param name="directoryName">The directory name. If null, directory is created under root path.</param>
        /// <returns>The directory created, or null if file cannot be created.</returns>
        public DirectoryData CreateDirectory(string directoryName, DirectoryData baseDirectory)
        {
            DirectoryData directory = null;
            string        path      = Path.Combine(baseDirectory.FullName, directoryName);
            string        rootPath  = GetDirectoryRoot().FullName;

            if (baseDirectory != null)
            {
                if (!path.StartsWith(rootPath))
                {
                    path = Path.Combine(rootPath, path);                       // concats root path to the given base path.
                }
            }
            else
            {
                path = rootPath;                           // creates directory under root path.
            }
            if (!ExistsDirectory(new DirectoryData(path))) // creates directory if it does not already exist.
            {
                try {
                    directory = new DirectoryData(Directory.CreateDirectory(path).FullName);
                } catch (Exception e) {
                    SystemLogger.Log(SystemLogger.Module.CORE, "Error creating directory [" + path + "]", e);
                }
            }

            return(directory);
        }
        /// <summary>
        /// Deletes a directory (deleting first all its children).
        /// </summary>
        /// <param name="directory">The directory to be deleted.</param>
        /// <returns>True on successful deletion.</returns>
        public bool DeleteDirectory(DirectoryData directory)
        {
            bool deleted = false;

            if (directory != null)
            {
                string roothPath = GetDirectoryRoot().FullName;
                try {
                    if (!directory.FullName.StartsWith(roothPath))
                    {
                        directory.FullName = Path.Combine(roothPath, directory.FullName);
                    }
                    //TODO Review
                    if (!CheckSecurePath(directory.FullName))
                    {
                        return(false);
                    }
                    Directory.Delete(directory.FullName, true);                      // recursively delete contents
                    deleted = true;
                } catch (Exception e) {
                    SystemLogger.Log(SystemLogger.Module.CORE, "Error deleting directory [" + directory.FullName + "]", e);
                }
            }

            return(deleted);
        }
 public override async Task<bool> DeleteDirectory(DirectoryData directory)
 {
     var folderToDelete = await GetStorageItem(GetDirectoryPath(directory), true);
     if (folderToDelete == null || folderToDelete.Path.Equals(_LocalDocumentsFolder.Path) || folderToDelete.Path.Equals(ApplicationData.Current.LocalFolder.Path)) return false;
     await folderToDelete.DeleteAsync(StorageDeleteOption.PermanentDelete);
     return true;
 }
예제 #5
0
        /// <summary>
        /// Copies the given file on "fromPath" to the "toPath".
        /// </summary>
        /// <param name="fromPath">Relative path under configured application "resources" directory.
        /// A <see cref="System.String"/>
        /// </param>
        /// <param name="toPath">Relative path under configured application "documents" directory. See GetDirectoryRoot().
        /// A <see cref="System.String"/>
        /// </param>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// </returns>
        public bool CopyFromResources(string fromPath, string toPath)
        {
            try {
                DirectoryData resourcesDir = GetDirectoryResources();
                string        fromFilePath = Path.Combine(resourcesDir.FullName, fromPath);
                FileData      sourceFile   = new FileData(fromFilePath);

                if (ExistsFile(sourceFile))
                {
                    DirectoryData rootDir    = GetDirectoryRoot();
                    string        toFilePath = Path.Combine(rootDir.FullName, toPath);

                    try {
                        File.Copy(fromFilePath, toFilePath);
                    } catch (Exception ex) {
                        SystemLogger.Log(SystemLogger.Module.CORE, "Error copying from file [" + fromFilePath + "] to file [" + toFilePath + "]", ex);
                        return(false);
                    }
                    return(true);
                }
                else
                {
                    SystemLogger.Log(SystemLogger.Module.CORE, "Error copying from file [" + fromFilePath + "]. File does not exists.");
                }
            } catch (Exception) {
                SystemLogger.Log(SystemLogger.Module.CORE, "Error copying from file [" + fromPath + "]. Unhandled exception.");
            }

            return(false);
        }
예제 #6
0
		/// <summary>
		/// Lists the installed modules.
		/// </summary>
		/// <returns>The installed modules.</returns>
		public override Module[] ListInstalledModules ()
		{
			List<Module> list = new List<Module> ();

			string ModulesPath = this.GetModulesRootPath();
			SystemLogger.Log(SystemLogger.Module.PLATFORM, "Listing installed modules under path: " + ModulesPath);

			DirectoryData modulesDirectory = new DirectoryData(ModulesPath);

			if(this.GetFileSystemService().ExistsDirectory(modulesDirectory)) {
				DirectoryData[] apps = this.GetFileSystemService().ListDirectories(modulesDirectory);
				foreach(DirectoryData app in apps) {
					SystemLogger.Log(SystemLogger.Module.PLATFORM, "directory: " + app.FullName);
					DirectoryData[] versions = this.GetFileSystemService().ListDirectories(app);

					foreach(DirectoryData version in versions) {
						SystemLogger.Log(SystemLogger.Module.PLATFORM, "version: " + version.FullName);
						Module module = new Module();
						module.Id = Path.GetFileName(app.FullName);
						module.Version = this.ParseModuleVersion(Path.GetFileName(version.FullName));
						list.Add(module);
					}
				}
			} else {
				SystemLogger.Log(SystemLogger.Module.PLATFORM, "Modules directory does not exists: " + ModulesPath);
			}

			return list.ToArray();
		}
예제 #7
0
        /// <summary>
        /// Checks if given directory exists.
        /// </summary>
        /// <param name="directory">The directory to be checked.</param>
        /// <returns>True if directory exists.</returns>
        public bool ExistsDirectory(DirectoryData directory)
        {
            if (directory == null)
            {
                return(false);
            }
            string roothPath = GetDirectoryRoot().FullName;

            if (!directory.FullName.StartsWith(roothPath))
            {
                directory.FullName = Path.Combine(roothPath, directory.FullName);
            }
            return(Directory.Exists(directory.FullName));
        }
예제 #8
0
		public override void GenerateQRCode(MediaQRContent content)
		{
			SystemLogger.Log (SystemLogger.Module.PLATFORM, "1");
			try{
				MediaMetadata mediaData = new MediaMetadata();
				SystemLogger.Log (SystemLogger.Module.PLATFORM, "2");

				int size = content.Size;
				if (size == 0) {
					size = 256;
				}
				var writer = new ZXing.BarcodeWriter
				{ 
					Format = BarcodeFormat.QR_CODE, 
					Options = new EncodingOptions { Height = size, Width = size } 
				};
				//var img = writer.Write(content.Text);
				SystemLogger.Log (SystemLogger.Module.PLATFORM, "3");

				var uuid = Guid.NewGuid ();
				string s = uuid.ToString ();
				String filename = "QR_" + s;
				NSError err;
				DirectoryData dest = new DirectoryData(DEFAULT_ROOT_PATH);
				string path = Path.Combine(dest.FullName, filename+".png");
				SystemLogger.Log (SystemLogger.Module.PLATFORM, "4");
				content = encodeQRCodeContents(content);
				using(UIImage img = writer.Write(content.Text)) {
					
					using (var data = img.AsPNG ()) {
						data.Save (path, true, out err);
					}
				}
				SystemLogger.Log (SystemLogger.Module.PLATFORM, "5");

				mediaData.ReferenceUrl = filename+".png";
				mediaData.Title = filename;

				SystemLogger.Log (SystemLogger.Module.PLATFORM, "6");

				UIApplication.SharedApplication.InvokeOnMainThread (delegate {
					UIViewController viewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
					FireUnityJavascriptEvent(viewController, "Appverse.Scanner.onGeneratedQR", mediaData);

				});
			}catch(Exception ex)
			{
				SystemLogger.Log (SystemLogger.Module.PLATFORM, "GenerateQRCode - exception: " + ex.Message);
			}
		}
예제 #9
0
        /// <summary>
        /// List all files under given directory.
        /// </summary>
        /// <param name="directory">The directory to list files under it.</param>
        /// <returns>List of files.</returns>
        public FileData[] ListFiles(DirectoryData directory)
        {
            if (directory == null)
            {
                return(GetDirectoryRoot().GetFiles());
            }

            string roothPath = GetDirectoryRoot().FullName;

            if (!directory.FullName.StartsWith(roothPath))
            {
                directory.FullName = Path.Combine(roothPath, directory.FullName);
            }
            return(directory.GetFiles());
        }
예제 #10
0
        public DirectoryData[] GetDirectories()
        {
            List<DirectoryData> list = new List<DirectoryData> ();
            try {
                DirectoryInfo directory = new DirectoryInfo (this.FullName);
                DirectoryInfo[] directories = directory.GetDirectories ();
                foreach (DirectoryInfo dir in directories) {
                    DirectoryData dirData = new DirectoryData (dir.FullName);
                    list.Add (dirData);
                }
            } catch (Exception e) {
                SystemLogger.Log (SystemLogger.Module .CORE, "Error getting files for directory [" + this.FullName + "]", e);
            }

            return list.ToArray ();
        }
        /// <summary>
        /// Stores the file, under the given directory, with the given contents.
        /// </summary>
        /// <returns>
        /// The file. The file contents are overwritten if it already exists.
        /// </returns>
        /// <param name='directoryPath'>
        /// Directory path. The directory is created if it does not exist.
        /// </param>
        /// <param name='fileName'>
        /// File name.
        /// </param>
        /// <param name='fileData'>
        /// File data.
        /// </param>
        public string StoreFile(string directoryPath, string fileName, byte[] fileData)
        {
            // Create directory if it does not exists
            DirectoryData assetsDirectory = this.CreateDirectory(directoryPath);

            if (assetsDirectory == null)
            {
                // Directory already exists
                assetsDirectory = new DirectoryData(Path.Combine(this.GetDirectoryRoot().FullName, directoryPath));
            }
            //TODO Review
            if (!CheckSecurePath(assetsDirectory.FullName))
            {
                return(null);
            }

            SystemLogger.Log(SystemLogger.Module.CORE, "Directory created: " + assetsDirectory.FullName);

            // Create file on the directory
            FileData storedFile = this.CreateFile(fileName, assetsDirectory);

            if (storedFile == null)
            {
                // File already created (would be overwritten with the WriteFile call)
                storedFile = new FileData(Path.Combine(assetsDirectory.FullName, fileName), 0);
            }
            //TODO Review
            if (!CheckSecurePath(storedFile.FullName))
            {
                return(null);
            }
            // Write contents to file
            bool success = this.WriteFile(storedFile, fileData, false);

            if (success)
            {
                SystemLogger.Log(SystemLogger.Module.CORE, "File sucessfully stored locally: " + storedFile.FullName);
            }
            else
            {
                SystemLogger.Log(SystemLogger.Module.CORE, "File could not be stored locally to path: " + storedFile.FullName);
            }

            return(Path.Combine(directoryPath, fileName));
        }
예제 #12
0
        public DirectoryData[] GetDirectories()
        {
            List <DirectoryData> list = new List <DirectoryData> ();

            try {
                DirectoryInfo   directory   = new DirectoryInfo(this.FullName);
                DirectoryInfo[] directories = directory.GetDirectories();
                foreach (DirectoryInfo dir in directories)
                {
                    DirectoryData dirData = new DirectoryData(dir.FullName);
                    list.Add(dirData);
                }
            } catch (Exception e) {
                SystemLogger.Log(SystemLogger.Module.CORE, "Error getting files for directory [" + this.FullName + "]", e);
            }


            return(list.ToArray());
        }
        /// <summary>
        /// List all directories under given directory.
        /// </summary>
        /// <param name="directory">The directry to list files under it.</param>
        /// <returns>List of directories.</returns>
        public DirectoryData[] ListDirectories(DirectoryData directory)
        {
            if (directory == null)
            {
                return(ListDirectories());
            }

            string roothPath = GetDirectoryRoot().FullName;

            if (!directory.FullName.StartsWith(roothPath))
            {
                directory.FullName = Path.Combine(roothPath, directory.FullName);
            }
            //TODO Review
            if (!CheckSecurePath(directory.FullName))
            {
                return(null);
            }
            return(directory.GetDirectories());
        }
 private async Task<StorageFolder> CreateFolderTree(DirectoryData baseDirectory)
 {
     if (baseDirectory == null || String.IsNullOrWhiteSpace(baseDirectory.FullName)) return _LocalDocumentsFolder;
     var returnFolder = _LocalDocumentsFolder;
     if (Path.HasExtension(baseDirectory.FullName))
         baseDirectory.FullName = Path.GetDirectoryName(baseDirectory.FullName);
     foreach (var directoryName in baseDirectory.FullName.Split(new[] { @"/", @"\" },
         StringSplitOptions.RemoveEmptyEntries))
     {
         returnFolder = await returnFolder.CreateFolderAsync(directoryName, CreationCollisionOption.OpenIfExists);
     }
     return returnFolder;
 }
 private string GetDirectoryPath(DirectoryData folderObject)
 {
     return folderObject == null ? _LocalDocumentsFolder.Path : GetItemPath(folderObject.FullName);
 }
 public override async Task<bool> ExistsDirectory(DirectoryData directory)
 {
     var targetDirectory = await GetStorageItem(GetDirectoryPath(directory), true);
     return targetDirectory != null;
 }
예제 #17
0
 public abstract Task<FileData[]> ListFiles(DirectoryData directory);
예제 #18
0
 public abstract Task<DirectoryData[]> ListDirectories(DirectoryData directory);
예제 #19
0
 public abstract Task <bool> ExistsDirectory(DirectoryData directory);
예제 #20
0
 public abstract Task <bool> DeleteDirectory(DirectoryData directory);
예제 #21
0
 public abstract Task<FileData> CreateFile(string fileName, DirectoryData baseDirectory);
예제 #22
0
 public abstract Task <DirectoryData> CreateDirectory(string directoryName, DirectoryData baseDirectory);
예제 #23
0
        /// <summary>
        /// Stores the file, under the given directory, with the given contents.
        /// </summary>
        /// <returns>
        /// The file. The file contents are overwritten if it already exists.
        /// </returns>
        /// <param name='directoryPath'>
        /// Directory path. The directory is created if it does not exist.
        /// </param>
        /// <param name='fileName'>
        /// File name.
        /// </param>
        /// <param name='fileData'>
        /// File data.
        /// </param>
        public string StoreFile(string directoryPath, string fileName, byte[] fileData)
        {
            // Create directory if it does not exists
            DirectoryData assetsDirectory = this.CreateDirectory (directoryPath);
            if (assetsDirectory == null) {
                // Directory already exists
                assetsDirectory = new DirectoryData (Path.Combine (this.GetDirectoryRoot ().FullName, directoryPath));
            }

            SystemLogger.Log (SystemLogger.Module.CORE, "Directory created: " + assetsDirectory.FullName);

            // Create file on the directory
            FileData storedFile = this.CreateFile (fileName, assetsDirectory);
            if (storedFile == null) {
                // File already created (would be overwritten with the WriteFile call)
                storedFile = new FileData (Path.Combine (assetsDirectory.FullName, fileName), 0);
            }

            // Write contents to file
            bool success = this.WriteFile (storedFile, fileData, false);
            if (success) {
                SystemLogger.Log (SystemLogger.Module.CORE, "File sucessfully stored locally: " + storedFile.FullName);
            } else {
                SystemLogger.Log (SystemLogger.Module.CORE, "File could not be stored locally to path: " + storedFile.FullName);
            }

            return Path.Combine (directoryPath, fileName);
        }
예제 #24
0
 /// <summary>
 /// Checks if given directory exists.
 /// </summary>
 /// <param name="directory">The directory to be checked.</param>
 /// <returns>True if directory exists.</returns>
 public bool ExistsDirectory(DirectoryData directory)
 {
     if (directory == null) {
         return false;
     }
     string roothPath = GetDirectoryRoot ().FullName;
     if (!directory.FullName.StartsWith (roothPath)) {
         directory.FullName = Path.Combine (roothPath, directory.FullName);
     }
     return Directory.Exists (directory.FullName);
 }
예제 #25
0
        /// <summary>
        /// Creates a file under the given directory.
        /// </summary>
        /// <param name="baseDirectory">The base Directory to create file under it.</param>
        /// <param name="fileName">The file name.</param>
        /// <returns>The file created, or null if file cannot be created.</returns>
        public FileData CreateFile(string fileName, DirectoryData baseDirectory)
        {
            FileData file = null;
            string path = Path.Combine (baseDirectory.FullName, fileName);
            string rootPath = GetDirectoryRoot ().FullName;

            if (baseDirectory != null) {
                if (!path.StartsWith (rootPath)) {
                    path = Path.Combine (rootPath, path);  // concats root path to the given base path.
                }
            } else {
                path = rootPath; // creates file under root path.
            }

            if (!File.Exists (path)) {
                try {
                    FileStream fs = File.Create (path);
                    file = new FileData (path, fs.Length);
                    fs.Close ();
                } catch (Exception e) {
                    SystemLogger.Log (SystemLogger.Module .CORE, "Error creating file [" + path + "]", e);
                }
            }

            return file;
        }
예제 #26
0
 public abstract Task <FileData[]> ListFiles(DirectoryData directory);
예제 #27
0
 public abstract Task <DirectoryData[]> ListDirectories(DirectoryData directory);
 public override async Task<FileData> CreateFile(string fileName, DirectoryData baseDirectory)
 {
     var folder = await CreateFolderTree(baseDirectory);
     var createdFile = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
     return new FileData(createdFile.Path.Replace(_LocalDocumentsFolder.Path, String.Empty));
 }
 public override async Task<DirectoryData> CreateDirectory(string directoryName, DirectoryData baseDirectory)
 {
     var folder = await CreateFolderTree(baseDirectory);
     var createdFolder = await folder.CreateFolderAsync(directoryName, CreationCollisionOption.OpenIfExists);
     return new DirectoryData(createdFolder.Path.Replace(_LocalDocumentsFolder.Path, String.Empty));
 }
예제 #30
0
 public abstract Task<bool> DeleteDirectory(DirectoryData directory);
 public override async Task<DirectoryData[]> ListDirectories(DirectoryData directory)
 {
     var selectedFolder = await GetStorageItem(GetDirectoryPath(directory), true) as StorageFolder;
     return selectedFolder == null ? null : (await selectedFolder.GetFoldersAsync()).Select(folder => new DirectoryData(folder.Path.Remove(0, _LocalDocumentsFolder.Path.Length))).ToArray();
 }
예제 #32
0
 public abstract Task<bool> ExistsDirectory(DirectoryData directory);
예제 #33
0
        /// <summary>
        /// Deletes a directory (deleting first all its children).
        /// </summary>
        /// <param name="directory">The directory to be deleted.</param>
        /// <returns>True on successful deletion.</returns>
        public bool DeleteDirectory(DirectoryData directory)
        {
            bool deleted = false;
            if (directory != null) {
                string roothPath = GetDirectoryRoot ().FullName;
                try {
                    if (!directory.FullName.StartsWith (roothPath)) {
                        directory.FullName = Path.Combine (roothPath, directory.FullName);
                    }
                    Directory.Delete (directory.FullName, true); // recursively delete contents
                    deleted = true;
                } catch (Exception e) {
                    SystemLogger.Log (SystemLogger.Module .CORE, "Error deleting directory [" + directory.FullName + "]", e);
                }
            }

            return deleted;
        }
예제 #34
0
        /// <summary>
        /// List all files under given directory.
        /// </summary>
        /// <param name="directory">The directory to list files under it.</param>
        /// <returns>List of files.</returns>
        public FileData[] ListFiles(DirectoryData directory)
        {
            if (directory == null)
            {
                return GetDirectoryRoot().GetFiles();
            }

            string roothPath = GetDirectoryRoot().FullName;
            if (!directory.FullName.StartsWith(roothPath))
            {
                directory.FullName = Path.Combine(roothPath, directory.FullName);
            }
            //TODO Review
            if (!CheckSecurePath(directory.FullName))
                return null;
            return directory.GetFiles();
        }
예제 #35
0
        /// <summary>
        /// List all files under given directory.
        /// </summary>
        /// <param name="directory">The directory to list files under it.</param>
        /// <returns>List of files.</returns>
        public FileData[] ListFiles(DirectoryData directory)
        {
            if (directory == null) {
                return GetDirectoryRoot ().GetFiles ();
            }

            string roothPath = GetDirectoryRoot ().FullName;
            if (!directory.FullName.StartsWith (roothPath)) {
                directory.FullName = Path.Combine (roothPath, directory.FullName);
            }
            return directory.GetFiles ();
        }
예제 #36
0
 public abstract Task<DirectoryData> CreateDirectory(string directoryName, DirectoryData baseDirectory);
예제 #37
0
        /// <summary>
        /// Creates a directory under the given base directory.
        /// </summary>
        /// <param name="baseDirectory">>The base Directory to create directory under it.</param>
        /// <param name="directoryName">The directory name. If null, directory is created under root path.</param>
        /// <returns>The directory created, or null if file cannot be created.</returns>
        public DirectoryData CreateDirectory(string directoryName, DirectoryData baseDirectory)
        {
            DirectoryData directory = null;
            string path = Path.Combine (baseDirectory.FullName, directoryName);
            string rootPath = GetDirectoryRoot ().FullName;
            if (baseDirectory != null) {
                if (!path.StartsWith (rootPath)) {
                    path = Path.Combine (rootPath, path);  // concats root path to the given base path.
                }
            } else {
                path = rootPath; // creates directory under root path.
            }
            if (!ExistsDirectory (new DirectoryData (path))) {  // creates directory if it does not already exist.
                try {
                    directory = new DirectoryData (Directory.CreateDirectory (path).FullName);
                } catch (Exception e) {
                    SystemLogger.Log (SystemLogger.Module .CORE, "Error creating directory [" + path + "]", e);
                }
            }

            return directory;
        }
예제 #38
0
 public abstract Task <FileData> CreateFile(string fileName, DirectoryData baseDirectory);