Esempio n. 1
0
            /// <summary>
            /// 为缓存设置更新指定的数据,先清空再添加
            /// </summary>
            /// <param name="values"></param>
            private void UpdateByDifference(ScopeVersionList values)
            {
                UpdateTime(values);

                if (values.Count > 0)
                {
                    for (int i = 0, c = values.Count; i < c; i++)
                    {
                        var item = values[i] as ScopeVersion;

                        string classRegion = item.ClassRegion;

                        //在字典中找到对应ClassRegion的列表
                        List <ScopeVersion> oldVersions = null;
                        if (!this._regionValues.TryGetValue(classRegion, out oldVersions))
                        {
                            oldVersions = new List <ScopeVersion>();
                            this._regionValues.Add(classRegion, oldVersions);
                        }

                        //把Value的值更新到oldVersions列表中。
                        var oldItem = oldVersions.FirstOrDefault(v => v.ScopeClass == item.ScopeClass && v.ScopeId == item.ScopeId);
                        if (oldItem != null)
                        {
                            oldItem.Value = item.Value;
                        }
                        else
                        {
                            oldVersions.Add(item);
                        }
                    }
                }
            }
Esempio n. 2
0
            /// <summary>
            /// 为缓存设置所有的数据
            /// </summary>
            /// <param name="values"></param>
            private void SetAllValues(ScopeVersionList values)
            {
                UpdateTime(values);

                var dic = values.AsEnumerable().Cast <ScopeVersion>()
                          .GroupBy(v => v.ClassRegion)
                          .ToDictionary(g => g.Key, g => g.ToList());

                this._regionValues = new SortedDictionary <string, List <ScopeVersion> >(dic);
            }
Esempio n. 3
0
 /// <summary>
 /// 更新两个时间戳
 /// </summary>
 /// <param name="values"></param>
 private void UpdateTime(ScopeVersionList values)
 {
     this._localTime  = DateTime.Now;
     this._serverTime = values.ServerTime;
 }