private IEnumerable<XElement> AddDirectoryAsync(DirectoryInfo dir, string collectionId, ref int count, int fnumber,
BackgroundWorker worker)
{
List<XElement> addedElements = new List<XElement>();
// добавление коллекции
string subCollectionId;
List<XElement> ae = this.cass.AddCollection(dir.Name, collectionId, out subCollectionId).ToList();
if (ae.Count > 0) addedElements.AddRange(ae);
count++;
foreach (FileInfo f in dir.GetFiles())
{
if (worker.CancellationPending) break;
if (f.Name != "Thumbs.db")
addedElements.AddRange(this.cass.AddFile(f, subCollectionId));
count++;
worker.ReportProgress(100 * count / fnumber);
}
foreach (DirectoryInfo d in dir.GetDirectories())
{
if (worker.CancellationPending) break;
addedElements.AddRange(AddDirectoryAsync(d, subCollectionId, ref count, fnumber, worker));
}
return addedElements;
}