Exemple #1
0
        public object Get(SafeDelete request)
        {
            _logger.Info("GET SafeDelete: {0}", request);

            long     item_id = long.Parse(request.item_id);
            BaseItem item    = _lm.GetItemById(item_id);

            List <FileSystemMetadata> del_paths = item.GetDeletePaths(false);

            foreach (var del_item in del_paths)
            {
                _logger.Info("Item Delete Path: " + del_item.FullName);
            }

            PathWalker walker = new PathWalker(del_paths, _fs);

            foreach (var path_item in walker.GetFileList())
            {
                _logger.Info("Item Delete Walked Path: " + path_item.FullName);
            }

            List <KeyValuePair <string, long> > file_list  = walker.GetFileNames();
            Dictionary <string, int>            ext_counts = walker.GetExtCounts();

            // calculate delete token based on files and sizes
            string file_info_string = "";
            string file_list_hash   = "";

            foreach (var file_item in file_list)
            {
                file_info_string += file_item.Key + "|" + file_item.Value + "|";
            }
            using (MD5 md5Hash = MD5.Create())
            {
                byte[]        hashBytes = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(file_info_string));
                StringBuilder sb        = new StringBuilder();
                for (int i = 0; i < hashBytes.Length; i++)
                {
                    sb.Append(hashBytes[i].ToString("X2"));
                }
                file_list_hash = sb.ToString();
            }

            Dictionary <string, object> results = new Dictionary <string, object>();

            results.Add("file_list", file_list);
            results.Add("ext_counts", ext_counts);
            results.Add("action_token", file_list_hash);

            foreach (var file_item in file_list)
            {
                _logger.Info("Item Delete Walked Files: " + file_item.Key + " - " + file_item.Value);
            }

            foreach (KeyValuePair <string, int> ext_count in ext_counts)
            {
                _logger.Info("Item Delete Walked Ext: " + ext_count.Key + " - " + ext_count.Value);
            }

            return(results);
        }