Esempio n. 1
0
        private static async Task WriteToXml(XmlDocument xd, XmlElement parent, Directory directory)
        {
            DirectoryContent content = await GetDirectoryContent(directory.Path);

            foreach (Directory dir in content.Directories)
            {
                XmlElement de = xd.CreateElement("Directory");
                de.SetAttribute("Path", dir.Path);
                de.SetAttribute("Name", dir.Name);
                parent.AppendChild(de);

                await WriteToXml(xd, de, dir);
            }
            foreach (File file in content.Files)
            {
                XmlElement fe = xd.CreateElement("File");
                fe.SetAttribute("Path", file.Path);
                fe.SetAttribute("Name", file.FileName);
                fe.SetAttribute("Size", file.FileSize());
                fe.SetAttribute("Type", file.Type.ToString());
                fe.SetAttribute("MD5SUM", file.MD5SUM);
                fe.SetAttribute("Bytes", file.Size.ToString());
                parent.AppendChild(fe);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Deletes a file or directory
        /// </summary>
        /// <param name="brickDirectoryPath">The relative path, must start with ../ and end with /</param>
        /// <param name="recursive">if true deletes the directory and all its contents</param>
        /// <returns><c>true</c> if deleted otherwise <c>false</c></returns>
        public static async Task <bool> DeleteDirectory(string brickDirectoryPath, bool recursive = false)
        {
            brickDirectoryPath = Firmware.FileSystem.ToBrickDirectoryPath(brickDirectoryPath);
            if (recursive)
            {
                DirectoryContent content = await GetDirectoryContent(brickDirectoryPath);

                foreach (File file in content.Files)
                {
                    await DeleteFile(file.Path);
                }

                foreach (Directory directory in content.Directories)
                {
                    await DeleteDirectory(directory.Path, recursive);
                }
            }
            return(await SystemMethods.Delete(Brick.Socket, brickDirectoryPath));
        }
Esempio n. 3
0
        /// <summary>
        /// Gets file handles to files on the brick. Use with great care upon deleting!!
        /// </summary>
        /// <param name="brickDirectoryPath">The relative path, must start with ../ and end with /</param>
        /// <returns></returns>
        public static async Task <File[]> GetFiles(string brickDirectoryPath)
        {
            DirectoryContent content = await SystemMethods.GetDirectoryContent(Brick.Socket, brickDirectoryPath);

            return(content.Files);
        }