/// <summary> /// ADD IF NOT EXIST /// </summary> /// <param name="IP"></param> /// <returns></returns> public static IPHolder IP_Get(string IP, int ToAddIfNeeded, out string exception, ref DateTime apicreatedate_ISR, ref enumProject Project) { exception = string.Empty; IPHolder current = null; if (DateTime.UtcNow.Date > LastClear_UTC.Date) { Update(); } try { if (IPs.ContainsKey(IP)) { if (ToAddIfNeeded > 0) { lock (getLocker) { lock (locker1) { IPHolder cur = IPs[IP]; cur.Count++; IPs[IP] = cur; } } } return(IPs[IP]); } else { lock (getLocker) { current = new IPHolder(null, IP, ToAddIfNeeded, AppManager.IP_AllowedPerCycle, new DateTime(DateTime.UtcNow.Ticks).AddMinutes(AppManager.IP_MinuteCycle)); current = AddUpdate_IP(IP, current, out exception, ref Project); } } } catch (Exception ex) { exception = UtilsException.GetMSG(ref ex); #region MyRegion LOG UtilsDB.API_Log_Insert(enumAction.LocalCache, enumLogType._1_Exception, enumLogType._1_Exception, "IP_Get", IP, exception, true, "", "", "", ref apicreatedate_ISR, ref apicreatedate_ISR, ref CacheGuid, true, IP, Project); #endregion } return(current); }
public void Clone(IPHolder toclone) { IP_ID = toclone.IP_ID; IP = toclone.IP; ExpDT = new DateTime(toclone.ExpDT.Ticks); Count = toclone.Count; Max = toclone.Max; }
/// <summary> /// IF NOT EXIST ADD NEW, ELSE UPDTAE EXISTING AND RETURN EXISTING /// </summary> /// <param name="IP"></param> /// <param name="ip"></param> /// <param name="exception"></param> /// <returns></returns> public static IPHolder AddUpdate_IP(string IP, IPHolder ip, out string exception, ref enumProject Project) { exception = string.Empty; if (DateTime.UtcNow.Date > LastClear_UTC.Date) { Update(); } try { lock (locker1) { if (!IPs.ContainsKey(IP)) { IPs.Add(IP, ip); } else { IPHolder current = IPs[IP]; current.Update(ip.IP_ID.GetValueOrDefault(), ip.Max, ip.Count, ip.ExpDT); IPs[IP] = current; ip.Clone(current); } } } catch (Exception ex) { exception = UtilsException.GetMSG(ref ex); NowException = new DateTime(DateTime.UtcNow.Ticks); #region MyRegion LOG UtilsDB.API_Log_Insert(enumAction.LocalCache, enumLogType._1_Exception, enumLogType._1_Exception, "AddUpdate_IP", IP, exception, true, "", "", "", ref NowException, ref NowException, ref CacheGuid, true, IP, Project); #endregion } return(ip); }