コード例 #1
0
        /// <summary>
        /// Is the provided mediaId unsafe?
        /// </summary>
        /// <param name="mediaId"></param>
        /// <returns></returns>
        public bool IsUnsafeMedia(string mediaId)
        {
            bool updateList = false;
            bool found      = false;

            for (int i = _unsafeItems.Count - 1; i >= 0; i--)
            {
                UnsafeItem item = _unsafeItems[i];
                if (item.Type == UnsafeItemType.Media && item.Id == mediaId)
                {
                    // Test the Ttl
                    if (DateTime.Now > item.DateTime.AddSeconds(item.Ttl))
                    {
                        _unsafeItems.RemoveAt(i);
                        updateList = true;
                    }
                    else
                    {
                        found = true;
                        break;
                    }
                }
            }

            if (updateList)
            {
                ClientInfo.Instance.UpdateUnsafeList(UnsafeListAsString());
            }

            return(found);
        }
コード例 #2
0
        /// <summary>
        /// Add an unsafe item to the list
        /// </summary>
        /// <param name="type"></param>
        /// <param name="layoutId"></param>
        /// <param name="id"></param>
        /// <param name="reason"></param>
        /// <param name="ttl"></param>
        public void AddUnsafeItem(UnsafeItemType type, int layoutId, string id, string reason, int ttl)
        {
            if (ttl == 0)
            {
                ttl = 86400;
            }

            try
            {
                UnsafeItem item = _unsafeItems
                                  .Where(i => i.Type == type && i.LayoutId == layoutId && i.Id == id)
                                  .First();

                item.DateTime = DateTime.Now;
                item.Reason   = reason;
            }
            catch
            {
                _unsafeItems.Add(new UnsafeItem
                {
                    DateTime = DateTime.Now,
                    Type     = type,
                    LayoutId = layoutId,
                    Id       = id,
                    Reason   = reason,
                    Ttl      = ttl
                });
            }

            ClientInfo.Instance.UpdateUnsafeList(UnsafeListAsString());
        }