private void OnSseClient_MessageReceived(object sender, SseClient.Message e)
        {
            switch (e.EventType)
            {
            case FeaturesUpdatedEventType:
                try
                {
                    Dictionary <string, FeatureControl> entries = JsonConvert.DeserializeObject <Dictionary <string, FeatureControl> >(e.Value);
                    if (_canReinitializeControlCache)
                    {
                        _canReinitializeControlCache = false;
                        _controlCache.Update(entries);
                        foreach (var entry in entries)
                        {
                            FeatureUpdated?.Invoke(this, new FeatureUpdatedEventArgs(entry.Key));
                        }

                        _initializationEvent.Set();
                    }
                    else
                    {
                        foreach (var entry in entries)
                        {
                            _controlCache.Set(entry.Value);
                            FeatureUpdated?.Invoke(this, new FeatureUpdatedEventArgs(entry.Key));
                        }
                    }
                }
                catch (Exception)
                {
                    _canReinitializeControlCache = false;
                }

                break;

            case FeaturesDeletedEventType:
                try
                {
                    List <string> entries = JsonConvert.DeserializeObject <List <string> >(e.Value);
                    foreach (var entry in entries)
                    {
                        _controlCache.Delete(entry);
                        FeatureDeleted?.Invoke(this, new FeatureDeletedEventArgs(entry));
                    }
                }
                catch (Exception)
                {
                }

                break;
            }
        }
        private async void OnTimer(object state)
        {
            try
            {
                if (_cts.IsCancellationRequested)
                {
                    return;
                }

                var newFeatures = await _restClient.GetFeatureControlsAsync(_cts.Token).ConfigureAwait(false);

                if (_cts.IsCancellationRequested)
                {
                    return;
                }

                var oldKeys = new HashSet <string>(_featureControlCache.GetAll().Keys);

                _featureControlCache.Update(newFeatures);

                foreach (var newFeature in newFeatures)
                {
                    FeatureUpdated?.Invoke(this, new FeatureUpdatedEventArgs(newFeature.Key));
                }

                oldKeys.ExceptWith(newFeatures.Keys);
                foreach (var missingKey in oldKeys)
                {
                    FeatureDeleted?.Invoke(this, new FeatureDeletedEventArgs(missingKey));
                }
            }
            finally
            {
                if (!_cts.IsCancellationRequested)
                {
                    InitializeTimer();
                }
            }
        }
Example #3
0
        private int OnDeleteItemNotify(int EntityType, string itemName)
        {
            m_Logger.Log($"Deleting item {itemName} of {EntityType}");

            if (EntityType == (int)swNotifyEntityType_e.swNotifyFeature)
            {
                IFeature feat;

                if (m_UnloadQueue.TryGetValue(itemName, out feat))
                {
                    FeatureDeleted?.Invoke(m_Model, feat);
                    m_UnloadQueue.Remove(itemName);

                    Marshal.ReleaseComObject(feat);
                    feat = null;
                    GC.Collect();
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
            }

            return(S_OK);
        }
 private void OnFeatureDeleted(object sender, FeatureDeletedEventArgs e)
 {
     FeatureDeleted?.Invoke(this, e);
 }