Exemplo n.º 1
0
        public void AddFilesFromXml(string s, ListWriteMode mode = ListWriteMode.Append)
        {
            XmlDocument xml = new XmlDocument();

            xml.LoadXml(s);
            XmlElement         root      = xml.DocumentElement;
            List <MdpFileInfo> filesInfo = new List <MdpFileInfo>();

            foreach (XmlNode fileNode in root.ChildNodes)
            {
                string      fileRelativePath = fileNode.Attributes[MdpApi.FileList.Xml.FileNameAttributeName].Value;
                string      fileHash         = fileNode.Attributes[MdpApi.FileList.Xml.FileHashAttributeName].Value;
                byte[]      hash             = ConvertHexStringToByteArray(fileHash);
                MdpFileInfo fileInfo;
                if (fileNode.Name == MdpApi.FileList.Xml.DirectoryTagName)
                {
                    fileInfo = new MdpDirectoryInfo(fileRelativePath, hash);
                }
                else
                {
                    fileInfo = new MdpFileInfo(fileRelativePath, hash);
                }
                filesInfo.Add(fileInfo);
            }
            AddFiles(filesInfo, mode);
        }
Exemplo n.º 2
0
        public void AddFilesFromJson(string s, ListWriteMode mode = ListWriteMode.Append)
        {
            MdpFileList        mdpFileList = JsonConvert.DeserializeObject <MdpFileList>(s);
            List <MdpFileInfo> filesInfos  = new List <MdpFileInfo>();

            foreach (MdpFileInfo fileInfo in mdpFileList.Files)
            {
                string      fileRelativePath = fileInfo.Name;
                MdpFileInfo file;
                if (fileRelativePath.EndsWith("/"))
                {
                    file = new MdpDirectoryInfo(fileRelativePath, fileInfo.Hash);
                }
                else
                {
                    file = new MdpFileInfo(fileRelativePath, fileInfo.Hash);
                }
                filesInfos.Add(file);
            }
            AddFiles(filesInfos, mode);
        }
Exemplo n.º 3
0
 public void AddFiles(MdpDirectoryInfo directoryInfo, ListWriteMode mode = ListWriteMode.Append)
 {
     AddFiles(new MdpFileInfo[] { directoryInfo }, mode);
 }