Exemplo n.º 1
0
 public IModelTime CreateModelTime(ISource aSource)
 {
     if (aSource != null && aSource is Source)
     {
         Source source = aSource as Source;
         if (aSource.Type == kSourceUpnpAv)
         {
             ModelSourceMediaRendererUpnpAv result = CheckModelCache(iModelSourceCache, source) as ModelSourceMediaRendererUpnpAv;
             if (result == null)
             {
                 result = new ModelSourceMediaRendererUpnpAv(source);
                 AddToCache(iModelSourceCache, (result as ModelSource), source);
             }
             return(result);
         }
         else
         {
             IModelTime result = CheckModelCache(iModelTimeCache, source);
             if (result == null)
             {
                 result = new ModelTime(source);
                 AddToCache(iModelTimeCache, result, source);
             }
             return(result);
         }
     }
     return(null);
 }
Exemplo n.º 2
0
        private void AddToCache(IModelTime aModelTime, Source aSource)
        {
            string id = string.Format("{0},{1}", aSource.Device, aSource);

            if (iModelTimeCache.ContainsKey(id))
            {
                iModelTimeCache[id] = aModelTime;
            }
            else
            {
                iModelTimeCache.Add(id, aModelTime);
            }
        }
Exemplo n.º 3
0
        private IModelTime CheckModelTimeCache(Source aSource)
        {
            string     id     = string.Format("{0},{1}", aSource.Device, aSource);
            IModelTime result = null;

            if (iModelTimeCache.TryGetValue(id, out result))
            {
                if (result.Device != aSource.Device)
                {
                    iModelTimeCache.Remove(id);
                    result = null;
                }
            }
            return(result);
        }