public bool HasAffiliationForSampleEvent(CompoundIdentity sampleEventId, bool localOnly) { if (!sampleEventId.IsNullOrEmpty()) { HashSet <CompoundIdentity> orgs = GetUserAffils(); if (orgs != null && orgs.Count > 0) { if (localOnly) { CompoundIdentity org = SampleEventOrgs.Instance.GetLocalOrg(sampleEventId); if (org != null) { HashSet <CompoundIdentity> tmp = GetUserAffils(); if (tmp != null) { foreach (CompoundIdentity cur in tmp) { if (cur.Equals(org)) { return(true); } } } } } else { SampleEventOrgRollup eventOrgs = SampleEventOrgs.Instance.Get(sampleEventId); if (eventOrgs != null) { return(SampleEventOrgs.Matches(eventOrgs.AuthorizedOrganizationIds, orgs)); } } } } return(false); }
internal SampleEventOrgRollup Get(CompoundIdentity sampleEventId) { if (sampleEventId != null) { lock (this.cached) //TODO -- make this faster by dropping the lock { if (this.cached.ContainsKey(sampleEventId)) { return(this.cached[sampleEventId]); } SampleEventOrgRollup r = SampleEventOrgRollup.Create(sampleEventId); if (r != null) { this.cached[sampleEventId] = r; } if (this.cached.Count > maxSize) { //randomly remove int target = this.r.Next(maxSize); int ix = 0; CompoundIdentity rem = null; foreach (CompoundIdentity cur in this.cached.Keys) //TODO -- make this better, its just ok for now { ix++; if (ix == target) { rem = cur; } } this.cached.Remove(rem); } return(r); } } return(null); }