source: extensions/PiwigoLib/PiwigoUpload/Helper/LocalDataHelper.cs @ 13847

Last change on this file since 13847 was 13847, checked in by bayral, 12 years ago

add forgotten files

File size: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using Com.Piwigo.Uploader.DTO;
6
7namespace 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}
Note: See TracBrowser for help on using the repository browser.