/// <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="consumerGroup">Consumer group</param> /// <param name="leases">A dictionary of partition leases.</param> public static void SetLease(string ns, string eventHub, string consumerGroup, Dictionary <string, Lease> leases) { if (string.IsNullOrWhiteSpace(ns) || string.IsNullOrWhiteSpace(eventHub) || string.IsNullOrWhiteSpace(consumerGroup)) { return; } var key = string.Format(KeyFormat, ns, eventHub, consumerGroup); 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, ConsumerGroup = consumerGroup, Leases = leases }; lock (mapDictionary) { itemList.Add(item); mapDictionary.Add(key, item); } } }
/// <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="consumerGroup"></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 consumerGroup, string partitionId, Lease lease) { if (string.IsNullOrWhiteSpace(ns) || string.IsNullOrWhiteSpace(eventHub) || string.IsNullOrWhiteSpace(consumerGroup) || string.IsNullOrWhiteSpace(partitionId)) { return; } var key = string.Format(KeyFormat, ns, eventHub, consumerGroup); 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, ConsumerGroup = consumerGroup, 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); } }