Revision b666b39a trunk/Pithos.Core/Agents/SnapshotDifferencer.cs

b/trunk/Pithos.Core/Agents/SnapshotDifferencer.cs
40 40
 */
41 41
#endregion
42 42
using System.Collections.Concurrent;
43
using System.Diagnostics.Contracts;
43 44
using Pithos.Interfaces;
44 45
using Pithos.Network;
45 46
using System;
......
71 72
            /// </summary>
72 73
            public readonly ObjectInfo[] Current;
73 74

  
75
            public readonly Dictionary<string, ObjectInfo> CurrentDict;
76

  
77
            public readonly Dictionary<string, ObjectInfo> PreviousDict;
78

  
79

  
74 80
            /// <summary>
75 81
            /// Common objects, lazily evalueated. 
76 82
            /// The common objects are used to calculate both the Changed and Unchanged objects
......
79 85

  
80 86
            private readonly static ObjectInfo[] Empty = new ObjectInfo[0];
81 87

  
88
            [ContractInvariantMethod]
89
            private void StatInvariant()
90
            {
91
// ReSharper disable InvocationIsSkipped
92
                Contract.Invariant(Current!=null);
93
                Contract.Invariant(Previous!=null);
94
                Contract.Invariant(CurrentDict!=null);
95
                Contract.Invariant(PreviousDict!=null);
96
                Contract.Invariant(Common!=null);
97
// ReSharper restore InvocationIsSkipped
98
            }
99

  
82 100
            public State(ObjectInfo[] previous, ObjectInfo[] current)
83 101
            {
84 102
                Previous = previous ?? Empty;
85 103
                Current = current ?? Empty;
104
                CurrentDict = Current.ToDictionary(info => info.UUID);
105
                PreviousDict = Previous.ToDictionary(info => info.UUID);
86 106

  
87 107
                Common=new Lazy<IEnumerable<ObjectInfo>>(() =>
88 108
                    Current.Join(Previous,
89 109
                                outKey => new { outKey.Account, outKey.Container, outKey.Name },
90 110
                                inKey => new { inKey.Account, inKey.Container, inKey.Name },
91
                                (outer, inner) =>
92
                                {
93
                                    outer.PreviousHash = inner.Hash;
94
                                    return outer;
95
                                }));            
111
                                (outer, inner) =>outer.SetPrevious(inner)));            
96 112
            }
97 113
        }
98 114

  
......
138 154
            return this;
139 155
        }
140 156
        
157
        /// <summary>
158
        /// Deleted objects are those that existed in the Previous listing
159
        /// but are not found in the Current listing, and their UUIDs do not
160
        /// appear in the Current listing (ie they were not renamed/moved)
161
        /// </summary>
141 162
        public IEnumerable<ObjectInfo> Deleted
142 163
        {
143
            get { return _state.Previous.Except(_state.Current,_comparer); }
164
            get { return _state.Previous.Except(_state.Current,_comparer)
165
                .Where(info=>!_state.CurrentDict.ContainsKey(info.UUID)); }
144 166
        }
167

  
168
        /// <summary>
169
        /// Created objects are those that exist in the Current listing
170
        /// but are not found in the Previous listing, and their UUIDs do not
171
        /// appear in the Previous listing (ie they were not renamed/moved)
172
        /// </summary>
145 173
        public IEnumerable<ObjectInfo> Created
146 174
        {
147
            get { return _state.Current.Except(_state.Previous,_comparer); }
175
            get { return _state.Current.Except(_state.Previous,_comparer)
176
                .Where(info=>!_state.PreviousDict.ContainsKey(info.UUID)); }
148 177
        }
149 178
                
150 179
        public IEnumerable<ObjectInfo> Common
......
160 189
        {
161 190
            get{ return Common.Where(i => i.PreviousHash == i.Hash);}
162 191
        }
192

  
193
        public IEnumerable<ObjectInfo>  Moved
194
        {
195
            get
196
            {
197
                                
198
                return _state.Current.Join(_state.Previous,
199
                                    outer => outer.UUID,
200
                                    inner => inner.UUID,
201
                                    (outer, inner) => (outer.Name == inner.Name ? null : outer.SetPrevious(inner)))
202
                    .Where(t => t != null);                
203
            }
204
        }
163 205
    }
164 206

  
165 207
    public class AccountsDifferencer

Also available in: Unified diff