Beispiel #1
0
        void HandleMessage(string messageType, string messageData)
        {
            _log.Debug("Event '{0}': {1}", messageType, messageData);
            switch (messageType)
            {
            case Constants.PUT:
            {
                var allData = DataModelSerialization.DeserializeV1Schema(messageData);
                _updateSink.Init(_user, allData);
                if (!_initialized.GetAndSet(true))
                {
                    _initTask.SetResult(true);
                }
                break;
            }

            case Constants.PATCH:
            {
                try
                {
                    var parsed      = LdValue.Parse(messageData);
                    var flagkey     = parsed.Get(Constants.KEY).AsString;
                    var featureFlag = DataModelSerialization.DeserializeFlag(messageData);
                    _updateSink.Upsert(_user, flagkey, featureFlag.ToItemDescriptor());
                }
                catch (Exception ex)
                {
                    LogHelpers.LogException(_log, "Error parsing PATCH message", ex);
                    _log.Debug("Message data follows: {0}", messageData);
                }
                break;
            }

            case Constants.DELETE:
            {
                try
                {
                    var    parsed      = LdValue.Parse(messageData);
                    int    version     = parsed.Get(Constants.VERSION).AsInt;
                    string flagKey     = parsed.Get(Constants.KEY).AsString;
                    var    deletedItem = new ItemDescriptor(version, null);
                    _updateSink.Upsert(_user, flagKey, deletedItem);
                }
                catch (Exception ex)
                {
                    LogHelpers.LogException(_log, "Error parsing DELETE message", ex);
                    _log.Debug("Message data follows: {0}", messageData);
                }
                break;
            }

            case Constants.PING:
            {
                Task.Run(async() =>
                    {
                        try
                        {
                            var response          = await _requestor.FeatureFlagsAsync();
                            var flagsAsJsonString = response.jsonResponse;
                            var allData           = DataModelSerialization.DeserializeV1Schema(flagsAsJsonString);
                            _updateSink.Init(_user, allData);
                            if (!_initialized.GetAndSet(true))
                            {
                                _initTask.SetResult(true);
                            }
                        }
                        catch (Exception ex)
                        {
                            LogHelpers.LogException(_log, "Error in handling PING message", ex);
                        }
                    });
                break;
            }

            default:
                break;
            }
        }
Beispiel #2
0
 internal void DoUpdate(string key, ItemDescriptor item)
 {
     _log.Debug("updating \"{0}\" to {1}", key, LogValues.Defer(() =>
                                                                item.Item is null ? "<null>" : DataModelSerialization.SerializeFlag(item.Item)));
     _updateSink.Upsert(User, key, item);
 }