Example #1
0
        public static int RemoveRef(this Authentication authentication, ICremaServiceItem obj)
        {
            lock (authentications)
            {
                var description = authentications[authentication];
                description.ServiceItems.Remove(obj);

                try
                {
                    if (description.ServiceItems.Any() == false)
                    {
                        authentications.Remove(authentication);
                        description.Dispose();
                    }

                    return(description.ServiceItems.Count);
                }
                finally
                {
                    if (authentications.Any() == false && timer != null)
                    {
                        timer.Stop();
                        timer.Dispose();
                        timer = null;
                    }
                }
            }
        }
Example #2
0
        public static int AddRef(this Authentication authentication, ICremaServiceItem obj)
        {
            lock (authentications)
            {
                if (authentications.ContainsKey(authentication) == false)
                {
                    throw new ArgumentException(nameof(authentication));
                }

                var description = authentications[authentication];
                description.ServiceItems.Add(obj);

                return(description.ServiceItems.Count);
            }
        }
Example #3
0
        public static int AddRef(this Authentication authentication, ICremaServiceItem obj, Action <Authentication> action)
        {
            lock (authentications)
            {
                if (authentications.Any() == false && timer == null)
                {
                    timer          = new Timer(30000);
                    timer.Elapsed += Timer_Elapsed;
                    timer.Start();
                }

                if (authentications.ContainsKey(authentication) == false)
                {
                    authentications[authentication] = new Description(authentication, action);
                }

                var description = authentications[authentication];
                description.ServiceItems.Add(obj);
                return(description.ServiceItems.Count);
            }
        }