internal StatsValueDocument(Dictionary <string, Models.Stat> statMap, int revision = 0)
        {
            this.IsDirty          = false;
            this.pendingEventList = new List <StatPendingState>();
            this.Revision         = revision;

            if (statMap != null)
            {
                this.Stats = new Dictionary <string, StatValue>(statMap.Count);

                foreach (var stat in statMap)
                {
                    StatValue statValue;
                    if (stat.Value.Value is string)
                    {
                        statValue = new StatValue(stat.Key, stat.Value.Value, StatValueType.String);
                    }
                    else
                    {
                        statValue = new StatValue(stat.Key, stat.Value.Value, StatValueType.Number);
                    }
                    this.Stats.Add(stat.Key, statValue);
                }
            }
            else
            {
                this.Stats = new Dictionary <string, StatValue>();
            }
        }
        internal void DoWork()
        {
            if (this.State != StatValueDocumentState.NotLoaded)
            {
                lock (this.Stats)
                {
                    foreach (var svdEvent in this.pendingEventList)
                    {
                        switch (svdEvent.PendingEventType)
                        {
                        case StatPendingEventType.StatChange:
                        {
                            if (!this.Stats.ContainsKey(svdEvent.Name))
                            {
                                var statValue = new StatValue(svdEvent.Name, svdEvent.Value, svdEvent.Type);
                                this.Stats.Add(svdEvent.Name, statValue);
                            }
                            else
                            {
                                this.Stats[svdEvent.Name].SetStat(svdEvent.Value, svdEvent.Type);
                            }

                            this.IsDirty = true;
                            break;
                        }

                        case StatPendingEventType.StatDelete:
                        {
                            this.Stats.Remove(svdEvent.Name);
                            break;
                        }
                        }
                    }

                    this.pendingEventList.Clear();
                }
            }
        }