aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Library/ChildrenChangedEventArgs.cs
blob: 94f4c540ff46366ebcd69b30af7a14422250c194 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System.Collections.Concurrent;
using MediaBrowser.Controller.Entities;
using System;
using System.Collections.Generic;

namespace MediaBrowser.Controller.Library
{
    /// <summary>
    /// Class ChildrenChangedEventArgs
    /// </summary>
    public class ChildrenChangedEventArgs : EventArgs
    {
        /// <summary>
        /// Gets or sets the folder.
        /// </summary>
        /// <value>The folder.</value>
        public Folder Folder { get; set; }
        /// <summary>
        /// Gets or sets the items added.
        /// </summary>
        /// <value>The items added.</value>
        public ConcurrentBag<BaseItem> ItemsAdded { get; set; }
        /// <summary>
        /// Gets or sets the items removed.
        /// </summary>
        /// <value>The items removed.</value>
        public List<BaseItem> ItemsRemoved { get; set; }
        /// <summary>
        /// Gets or sets the items updated.
        /// </summary>
        /// <value>The items updated.</value>
        public ConcurrentBag<BaseItem> ItemsUpdated { get; set; }

        /// <summary>
        /// Create the args and set the folder property
        /// </summary>
        /// <param name="folder">The folder.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        public ChildrenChangedEventArgs(Folder folder)
        {
            if (folder == null)
            {
                throw new ArgumentNullException();
            }

            //init the folder property
            Folder = folder;
            //init the list
            ItemsAdded = new ConcurrentBag<BaseItem>();
            ItemsRemoved = new List<BaseItem>();
            ItemsUpdated = new ConcurrentBag<BaseItem>();
        }

        /// <summary>
        /// Adds the new item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        public void AddNewItem(BaseItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException();
            }
            
            ItemsAdded.Add(item);
        }

        /// <summary>
        /// Adds the updated item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        public void AddUpdatedItem(BaseItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException();
            }
            
            ItemsUpdated.Add(item);
        }

        /// <summary>
        /// Adds the removed item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        public void AddRemovedItem(BaseItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException();
            }

            ItemsRemoved.Add(item);
        }

        /// <summary>
        /// Lists the has change.
        /// </summary>
        /// <param name="list">The list.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        private bool ListHasChange(List<BaseItem> list)
        {
            return list != null && list.Count > 0;
        }

        /// <summary>
        /// Lists the has change.
        /// </summary>
        /// <param name="list">The list.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        private bool ListHasChange(ConcurrentBag<BaseItem> list)
        {
            return list != null && !list.IsEmpty;
        }
        
        /// <summary>
        /// Gets a value indicating whether this instance has change.
        /// </summary>
        /// <value><c>true</c> if this instance has change; otherwise, <c>false</c>.</value>
        public bool HasChange
        {
            get { return HasAddOrRemoveChange || ListHasChange(ItemsUpdated); }
        }

        /// <summary>
        /// Gets a value indicating whether this instance has add or remove change.
        /// </summary>
        /// <value><c>true</c> if this instance has add or remove change; otherwise, <c>false</c>.</value>
        public bool HasAddOrRemoveChange
        {
            get { return ListHasChange(ItemsAdded) || ListHasChange(ItemsRemoved); }
        }
    }
}