コード例 #1
0
ファイル: AdManager.cs プロジェクト: elshaikh-amir/AdServices
 public AdList()
 {
     olock    = new object();
     Links    = new List <AdLink>();
     Pointer  = null;
     HasRound = false;
 }
コード例 #2
0
ファイル: AdManager.cs プロジェクト: elshaikh-amir/AdServices
        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
ファイル: AdManager.cs プロジェクト: elshaikh-amir/AdServices
        private byte[] getNext()
        {
            AdLink item = AdList.GetNext();

            if (item != null)
            {
                return(item.linkbytes);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
ファイル: AdManager.cs プロジェクト: elshaikh-amir/AdServices
 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
ファイル: AdManager.cs プロジェクト: elshaikh-amir/AdServices
        /*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
ファイル: AdManager.cs プロジェクト: elshaikh-amir/AdServices
        /*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
ファイル: AdManager.cs プロジェクト: elshaikh-amir/AdServices
 public void MarkAsRemoved(AdLink link)
 {
     AdList.Remove(link);
 }
コード例 #8
0
ファイル: AdManager.cs プロジェクト: elshaikh-amir/AdServices
 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);
 }