private UPnPError OnGetStates(DvAction action, IList <object> inParams, out IList <object> outParams, CallContext context)
        {
            uint cacheKey = (uint)inParams[0];
            List <ServerState> states;

            lock (_syncObj)
                states = _stateCache.GetStates(ref cacheKey);
            outParams = new List <object> {
                ServerStateSerializer.Serialize(states), cacheKey
            };
            return(null);
        }
Beispiel #2
0
        protected void GetStates()
        {
            try
            {
                uint cacheKey;
                lock (_syncObj)
                    cacheKey = _currentCacheKey;

                CpAction       action       = GetAction(Consts.ACTION_GET_STATES);
                IList <object> inParameters = new List <object> {
                    cacheKey
                };
                IList <object> outParameters = action.InvokeAction(inParameters);
                var            states        = ServerStateSerializer.Deserialize <List <ServerState> >((string)outParameters[0]);
                if (states == null || states.Count == 0)
                {
                    return;
                }

                var updatedStates = new Dictionary <Guid, object>();
                lock (_syncObj)
                {
                    uint newCacheKey = (uint)outParameters[1];
                    //Due to threading the update might be being done out of order. e.g. a different thread has already updated with newer states.
                    //Check if the current key has been modified and whether our key is newer.
                    if (_currentCacheKey != cacheKey && newCacheKey <= _currentCacheKey)
                    {
                        return;
                    }
                    _currentCacheKey = newCacheKey;
                    foreach (ServerState state in states)
                    {
                        object stateObject = state.DeserializeState();
                        _currentStates[state.Id] = stateObject;
                        updatedStates[state.Id]  = stateObject;
                    }
                }
                ServerStateMessaging.SendStatesChangedMessage(updatedStates);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
 protected IList <ServerState> GetServerStates(uint cacheKey, out uint newCacheKey)
 {
     try
     {
         CpAction       action       = GetAction(Consts.ACTION_GET_STATES);
         IList <object> inParameters = new List <object> {
             cacheKey
         };
         IList <object> outParameters = action.InvokeAction(inParameters);
         newCacheKey = (uint)outParameters[1];
         return(ServerStateSerializer.Deserialize <List <ServerState> >((string)outParameters[0]));
     }
     catch (Exception ex)
     {
         ServiceRegistration.Get <ILogger>().Warn("ServerStateService: Error getting states from the server", ex);
         newCacheKey = 0;
         return(null);
     }
 }