void dbManager_CancelStore(object sender, CancelStoreEventArgs e)
 {
     try
     {
         ValidateLicense(e);
     }
     catch {}
 }
        private void ValidateLicense(CancelStoreEventArgs e)
        {
            if (_License == null)
            {
                e.Cancel        = true;
                e.CancelMessage = "No valid license provided.";
            }
            else
            {
                if (_AccessAgent != null)
                {
                    string instance = string.Empty;
                    int    count;
                    MatchingParameterCollection mpc = new MatchingParameterCollection()
                    {
                        { new MatchingParameterList() }
                    };

                    if (_FeatureStudyCount != null)
                    {
                        instance = e.DataSet.GetValue <string>(DicomTag.StudyInstanceUID, string.Empty);
                        if (!_AccessAgent.IsStudyExists(instance))
                        {
                            count = _AccessAgent.FindStudiesCount(mpc);
                            if (_FeatureStudyCount.Counter > 0 && (count + 1) > _FeatureStudyCount.Counter)
                            {
                                e.Cancel        = true;
                                e.CancelMessage = string.Format("Max study limit reached, Study ({0}) not stored.  The license is restricted to storing {1} {2}.", instance, count, count == 1 ? "study" : "studies");
                                return;
                            }
                        }
                    }

                    if (_FeatureSeriesCount != null)
                    {
                        instance = e.DataSet.GetValue <string>(DicomTag.SeriesInstanceUID, string.Empty);
                        if (!_AccessAgent.IsSeriesExists(instance))
                        {
                            count = _AccessAgent.FindSeriesCount(mpc);
                            if (_FeatureSeriesCount.Counter > 0 && (count + 1) > _FeatureSeriesCount.Counter)
                            {
                                e.Cancel        = true;
                                e.CancelMessage = string.Format("Max series limit reached, Series ({0}) not stored.  The license is restricted to storing {1} series.", instance, count);
                                return;
                            }
                        }
                    }
                }
            }
        }