1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using System.Linq; |
---|
4 | using System.Text; |
---|
5 | using Com.Piwigo.Uploader.DTO; |
---|
6 | |
---|
7 | namespace Com.Piwigo.Uploader.Helper |
---|
8 | { |
---|
9 | public static class LocalDataHelper |
---|
10 | { |
---|
11 | public static void DeleteWhenFoundInTree(LocalAlbum alb, ref LocalAlbumList lstAlbum) |
---|
12 | { |
---|
13 | LocalAlbum treeAlb = null; |
---|
14 | |
---|
15 | for (int i = 0; i < lstAlbum.Count; i += 1) |
---|
16 | { |
---|
17 | treeAlb = lstAlbum.FirstOrDefault(a => a.LocalDir == alb.LocalDir); |
---|
18 | if (treeAlb != default(LocalAlbum)) |
---|
19 | { |
---|
20 | DeleteAlbum(ref treeAlb); |
---|
21 | lstAlbum.RemoveAt(i); |
---|
22 | return; |
---|
23 | } |
---|
24 | } |
---|
25 | for (int i = 0; i < lstAlbum.Count; i += 1) |
---|
26 | { |
---|
27 | LocalAlbumList FoundInLstAlb = lstAlbum[i].SubAlbums; |
---|
28 | DeleteWhenFoundInTree(alb, ref FoundInLstAlb); |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | public static void DeleteAlbum(ref LocalAlbum alb) |
---|
33 | { |
---|
34 | //on vire les images |
---|
35 | alb.LocalImages.Clear(); |
---|
36 | foreach (LocalAlbum subAlb in alb.SubAlbums) |
---|
37 | { |
---|
38 | LocalAlbum subAlbtoDel = subAlb; |
---|
39 | // on boucle sur les sous-albums |
---|
40 | DeleteAlbum(ref subAlbtoDel); |
---|
41 | } |
---|
42 | // on vide les sous-album |
---|
43 | alb.SubAlbums.Clear(); |
---|
44 | } |
---|
45 | |
---|
46 | public static void DeleteInTree (LocalAlbum alb) |
---|
47 | { |
---|
48 | //si l'album depend de la racine |
---|
49 | LocalAlbum treeAlb = ModelManager.Instance.lstAlbumLocaux.FirstOrDefault(a => a.LocalDir == alb.LocalDir); |
---|
50 | if (treeAlb != default(LocalAlbum)) |
---|
51 | { |
---|
52 | DeleteAlbum(ref treeAlb); |
---|
53 | ModelManager.Instance.lstAlbumLocaux.Remove(treeAlb); |
---|
54 | } |
---|
55 | else |
---|
56 | { |
---|
57 | LocalAlbumList lal = ModelManager.Instance.lstAlbumLocaux; |
---|
58 | DeleteWhenFoundInTree(alb,ref lal); |
---|
59 | } |
---|
60 | } |
---|
61 | } |
---|
62 | } |
---|