/// <summary> /// Убрать все привязки на мёртвые ссылки /// </summary> /// <param name="doWriteHistory"></param> public async Task <int> RemoveDeadLinks(bool doWriteHistory) { var z = _cloud.GetItem(@"/__enc/3/_linked_test", MailRuCloud.ItemType.Folder, false).Result; var removes = _itemList.Items .AsParallel() .WithDegreeOfParallelism(5) .Select(it => GetItemLink(WebDavPath.Combine(it.MapTo, it.Name)).Result) .Where(itl => itl.IsBad || _cloud.GetItem(itl.MapPath, MailRuCloud.ItemType.Folder, false).Result == null) .ToList(); if (removes.Count == 0) { return(0); } _itemList.Items.RemoveAll(it => removes.Any(rem => WebDavPath.PathEquals(rem.MapPath, it.MapTo) && rem.Name == it.Name)); if (removes.Any()) { if (doWriteHistory) { foreach (var link in removes) { _itemCache.Invalidate(link.FullPath, link.MapPath); } string path = WebDavPath.Combine(WebDavPath.Root, HistoryContainerName); string res = await _cloud.DownloadFileAsString(path); var history = new StringBuilder(res ?? string.Empty); foreach (var link in removes) { history.Append($"{DateTime.Now} REMOVE: {link.Href} {link.Name}\r\n"); } _cloud.UploadFile(path, history.ToString()); } Save(); return(removes.Count); } return(0); }