예제 #1
0
        /// <summary>
        /// Sets the Lease for an event hub partition in the current namespace. If the lease is null,
        /// the function removes the lease from the internal structure.
        /// </summary>
        /// <param name="ns">Namespace name.</param>
        /// <param name="eventHub">Event hub name.</param>
        /// <param name="leases">A dictionary of partition leases.</param>
        public static void SetLease(string ns, string eventHub, Dictionary <string, Lease> leases)
        {
            if (string.IsNullOrWhiteSpace(ns) ||
                string.IsNullOrWhiteSpace(eventHub))
            {
                return;
            }
            var key = string.Format(KeyFormat, ns, eventHub);

            if (mapDictionary.ContainsKey(key))
            {
                if (leases != null)
                {
                    mapDictionary[key].Leases = leases;
                }
                else
                {
                    lock (mapDictionary)
                    {
                        itemList.Remove(mapDictionary[key]);
                        mapDictionary.Remove(key);
                    }
                }
            }
            else
            {
                if (leases == null)
                {
                    return;
                }

                var item = new EventProcessorCheckpointInfo
                {
                    Namespace = ns,
                    EventHub  = eventHub,
                    Leases    = leases
                };
                lock (mapDictionary)
                {
                    itemList.Add(item);
                    mapDictionary.Add(key, item);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Sets the Lease for an event hub partition in the current namespace. If the lease is null,
        /// the function removes the lease from the internal structure.
        /// </summary>
        /// <param name="ns">Namespace name.</param>
        /// <param name="eventHub">Event hub name.</param>
        /// <param name="partitionId">Partition Id.</param>
        /// <param name="lease">The lease for the event hub partition.</param>
        public static void SetLease(string ns, string eventHub, string partitionId, Lease lease)
        {
            if (string.IsNullOrWhiteSpace(ns) ||
                string.IsNullOrWhiteSpace(eventHub) ||
                string.IsNullOrWhiteSpace(partitionId))
            {
                return;
            }
            var key = string.Format(KeyFormat, ns, eventHub);

            if (mapDictionary.ContainsKey(key))
            {
                if (lease != null)
                {
                    if (mapDictionary[key].Leases == null)
                    {
                        mapDictionary[key].Leases = new Dictionary <string, Lease>();
                    }
                    mapDictionary[key].Leases[partitionId] = lease;
                }
                else
                {
                    if (mapDictionary[key].Leases == null ||
                        !mapDictionary[key].Leases.ContainsKey(partitionId))
                    {
                        return;
                    }
                    mapDictionary[key].Leases.Remove(partitionId);
                }
            }
            else
            {
                if (lease == null)
                {
                    return;
                }
                var item = new EventProcessorCheckpointInfo
                {
                    Namespace = ns,
                    EventHub  = eventHub,
                    Leases    = new Dictionary <string, Lease> {
                        { partitionId, lease }
                    }
                };
                lock (mapDictionary)
                {
                    itemList.Add(item);
                    if (mapDictionary.ContainsKey(key))
                    {
                        mapDictionary[key].Leases[partitionId] = lease;
                    }
                    else
                    {
                        mapDictionary.Add(key, item);
                    }
                }
            }
            if (lease != null)
            {
                mapDictionary[key].Leases[partitionId] = lease;
            }
            else
            {
                mapDictionary[key].Leases.Remove(partitionId);
            }
        }
 /// <summary>
 /// Sets the Lease for an event hub partition in the current namespace. If the lease is null,
 /// the function removes the lease from the internal structure.
 /// </summary>
 /// <param name="ns">Namespace name.</param>
 /// <param name="eventHub">Event hub name.</param>
 /// <param name="partitionId">Partition Id.</param>
 /// <param name="lease">The lease for the event hub partition.</param>
 public static void SetLease(string ns, string eventHub, string partitionId, Lease lease)
 {
     if (string.IsNullOrWhiteSpace(ns) ||
         string.IsNullOrWhiteSpace(eventHub) ||
         string.IsNullOrWhiteSpace(partitionId))
     {
         return;
     }
     var key = string.Format(KeyFormat, ns, eventHub);
     if (mapDictionary.ContainsKey(key))
     {
         if (lease != null)
         {
             if (mapDictionary[key].Leases == null)
             {
                 mapDictionary[key].Leases = new Dictionary<string, Lease>();
             }
             mapDictionary[key].Leases[partitionId] = lease;
         }
         else
         {
             if (mapDictionary[key].Leases == null ||
                 !mapDictionary[key].Leases.ContainsKey(partitionId))
             {
                 return;
             }
             mapDictionary[key].Leases.Remove(partitionId);
         }
     }
     else
     {
         if (lease == null)
         {
             return;
         }
         var item = new EventProcessorCheckpointInfo
         {
             Namespace = ns,
             EventHub = eventHub,
             Leases = new Dictionary<string, Lease> { { partitionId, lease } }
         };
         lock (mapDictionary)
         {
             itemList.Add(item);
             if (mapDictionary.ContainsKey(key))
             {
                 mapDictionary[key].Leases[partitionId] = lease;
             }
             else
             {
                 mapDictionary.Add(key, item);
             }
         }
     }
     if (lease != null)
     {
         mapDictionary[key].Leases[partitionId] = lease;
     }
     else
     {
         mapDictionary[key].Leases.Remove(partitionId);
     }
 }
        /// <summary>
        /// Sets the Lease for an event hub partition in the current namespace. If the lease is null,
        /// the function removes the lease from the internal structure.
        /// </summary>
        /// <param name="ns">Namespace name.</param>
        /// <param name="eventHub">Event hub name.</param>
        /// <param name="leases">A dictionary of partition leases.</param>
        public static void SetLease(string ns, string eventHub, Dictionary<string, Lease> leases)
        {
            if (string.IsNullOrWhiteSpace(ns) ||
                string.IsNullOrWhiteSpace(eventHub))
            {
                return;
            }
            var key = string.Format(KeyFormat, ns, eventHub);
            if (mapDictionary.ContainsKey(key))
            {
                if (leases != null)
                {
                    mapDictionary[key].Leases = leases;
                }
                else
                {
                    lock (mapDictionary)
                    {
                        itemList.Remove(mapDictionary[key]);
                        mapDictionary.Remove(key);
                    }
                }
            }
            else
            {
                if (leases == null)
                {
                    return;
                }

                var item = new EventProcessorCheckpointInfo
                {
                    Namespace = ns,
                    EventHub = eventHub,
                    Leases = leases
                };
                lock (mapDictionary)
                {
                    itemList.Add(item);
                    mapDictionary.Add(key, item);
                }
            }
        }