コード例 #1
0
ファイル: NFigMemoryStore.cs プロジェクト: crazyants/NFig
        protected override OverridesSnapshot <TSubApp, TTier, TDataCenter> RestoreSnapshotImpl(OverridesSnapshot <TSubApp, TTier, TDataCenter> snapshot, string user)
        {
            var data = _appData;

            lock (data)
            {
                data.Commit = NewCommit();

                var log = new NFigLogEvent <TDataCenter>(
                    type: NFigLogEventType.RestoreSnapshot,
                    globalAppName: snapshot.GlobalAppName,
                    commit: data.Commit,
                    timestamp: DateTime.UtcNow,
                    settingName: null,
                    settingValue: null,
                    restoredCommit: snapshot.Commit,
                    dataCenter: default(TDataCenter),
                    user: user);

                data.LastEvent = log.BinarySerialize();

                data.Overrides.Clear();
                foreach (var o in snapshot.Overrides)
                {
                    var key = GetOverrideKey(o.Name, o.SubApp, o.DataCenter);
                    data.Overrides.Add(key, o.Value);
                }

                return(CreateSnapshot(data));
            }
        }
コード例 #2
0
 public static OverridesSnapshot <SubApp, Tier, DataCenter> CreateSnapshot(
     string globalAppName = GLOBAL_APP_1,
     string commit        = NFigStore.INITIAL_COMMIT,
     List <SettingValue <SubApp, Tier, DataCenter> > overrides = null,
     NFigLogEvent <DataCenter> lastEvent = null)
 {
     return(new OverridesSnapshot <SubApp, Tier, DataCenter>(globalAppName, commit, overrides, lastEvent));
 }
コード例 #3
0
ファイル: NFigMemoryStore.cs プロジェクト: crazyants/NFig
        OverridesSnapshot <TSubApp, TTier, TDataCenter> CreateSnapshot(InMemoryAppData data)
        {
            var overrides = new List <SettingValue <TSubApp, TTier, TDataCenter> >();

            foreach (var kvp in data.Overrides)
            {
                SettingValue <TSubApp, TTier, TDataCenter> value;
                if (TryGetValueFromOverride(kvp.Key, kvp.Value, out value))
                {
                    overrides.Add(value);
                }
            }

            var lastEvent = NFigLogEvent <TDataCenter> .BinaryDeserialize(data.LastEvent);

            return(new OverridesSnapshot <TSubApp, TTier, TDataCenter>(GlobalAppName, data.Commit, overrides, lastEvent));
        }
コード例 #4
0
ファイル: NFigMemoryStore.cs プロジェクト: crazyants/NFig
        protected override OverridesSnapshot <TSubApp, TTier, TDataCenter> ClearOverrideImpl(
            string settingName,
            TDataCenter dataCenter,
            string user,
            TSubApp subApp,
            string commit)
        {
            var key  = GetOverrideKey(settingName, subApp, dataCenter);
            var data = _appData;

            lock (data)
            {
                if (commit != null && commit != data.Commit)
                {
                    return(null);
                }

                if (!data.Overrides.ContainsKey(key))
                {
                    return(null);
                }

                data.Overrides.Remove(key);
                data.Commit = NewCommit();

                var log = new NFigLogEvent <TDataCenter>(
                    type: NFigLogEventType.ClearOverride,
                    globalAppName: GlobalAppName,
                    commit: data.Commit,
                    timestamp: DateTime.UtcNow,
                    settingName: settingName,
                    settingValue: null,
                    restoredCommit: null,
                    dataCenter: dataCenter,
                    user: user);

                data.LastEvent = log.BinarySerialize();

                return(CreateSnapshot(data));
            }
        }
コード例 #5
0
        /// <summary>
        /// Initializes a new snapshot object.
        /// </summary>
        /// <param name="globalAppName">The "Global" application name.</param>
        /// <param name="commit">The commit ID at the time of the snapshot.</param>
        /// <param name="overrides">A list of the overrides which exist at the time of the snapshot.</param>
        /// <param name="lastEvent">The last event which occurred before the snapshot.</param>
        public OverridesSnapshot(
            [NotNull] string globalAppName,
            [NotNull] string commit,
            IList <SettingValue <TSubApp, TTier, TDataCenter> > overrides,
            NFigLogEvent <TDataCenter> lastEvent)
        {
            if (globalAppName == null)
            {
                throw new ArgumentNullException(nameof(globalAppName));
            }

            if (commit == null)
            {
                throw new ArgumentNullException(nameof(commit));
            }

            GlobalAppName = globalAppName;
            Commit        = commit;
            Overrides     = overrides;
            LastEvent     = lastEvent;
        }