예제 #1
0
 public AdList()
 {
     olock    = new object();
     Links    = new List <AdLink>();
     Pointer  = null;
     HasRound = false;
 }
예제 #2
0
        public void Update(AdLink old, string neww)
        {
            //AdLink item = AdList.Find(a => a != null && !a.isRemoved && a.linkstring.Equals(old));

            if (old != null && neww != null)
            {
                AdLink.Update(old, neww);
            }
            //item = new AdLink(neww);
        }
예제 #3
0
        private byte[] getNext()
        {
            AdLink item = AdList.GetNext();

            if (item != null)
            {
                return(item.linkbytes);
            }
            else
            {
                return(null);
            }
        }
예제 #4
0
 private void Next()
 {
     lock (olock)
     {
         if (Pointer == null)
         {
             if (Links.Count > 0)
             {
                 Pointer = Links.First(); // gets first obj
             }
         }
         else// if(Pointer != null)
         {
             if (Links.Last() == Pointer) // last index pointer. Call GC and reset pointer
             {
                 HasRound = true;
                 if (Links.Count > 1)
                 {
                     Links.RemoveAll(l => l.isRemoved); // can't call GC inside of locked object, -----> DeadLock Fixed <-----
                 }
                 //GC();
                 //Pointer = Links.FirstOrDefault(); // works too, but i dont use it here
                 if (Links.Count > 0)
                 {
                     Pointer = Links.First(); // can be null element, but np
                 }
                 else
                 {
                     Pointer = null;
                 }
             }
             else
             {
                 int index = Links.IndexOf(Pointer);
                 if (index < 0 || index + 1 >= Count) // Dafuq.. this case isn't allowed to trigger!
                 {
                     return;
                 }
                 Pointer = Links[index + 1];
             }
         }
     }
 }
예제 #5
0
        /*public void Remove(AdLink link)
         * {
         * // AdLink ad = Find(l => l.linkstring.Equals(link));
         *  if (link != null)
         *      Remove(link);
         * }*/

        public void Remove(AdLink link)
        {
            // lock here? Yes, Client's Thread might access obj onError Event
            lock (olock)
                link.Remove();
        }
예제 #6
0
        /*public AdLink Last
         * {
         *  get
         *  {
         *      lock (olock)
         *          return Links.Last();
         *  }
         * }
         *
         * public AdLink First
         * {
         *  get
         *  {
         *      lock (olock)
         *          return Links.First();
         *  }
         * }*/

        public void Add(AdLink link)
        {
            lock (olock)
                Links.Add(link);
        }
예제 #7
0
 public void MarkAsRemoved(AdLink link)
 {
     AdList.Remove(link);
 }
예제 #8
0
 public void AddToNext(AdLink link) // some sync needed here!
 {
     lock (olock)
         NextList.Add(link);
 }
예제 #9
0
 public static void Update(AdLink old, string nw)
 {
     old.linkstring = nw;
     old.linkbytes  = System.Text.ASCIIEncoding.UTF8.GetBytes(nw);
 }