public TaxonomyTerms(ClientContext ctx, string TermSetId, Guid AnchorId)
        {
            bool IsRootTerm = false;

            LogHelper.Log("Inside TaxonomyTerms termsetid:" + TermSetId);
            CurrentContext   = ctx;
            _TermsDictionary = new Dictionary <TermKey, string>();
            var _taxSession = TaxonomySession.GetTaxonomySession(CurrentContext);

            var _termStore = _taxSession.GetDefaultSiteCollectionTermStore();

            var            _termSet        = _termStore.GetTermSet(new Guid(TermSetId));
            TermCollection _termCollection = null;


            if (AnchorId == Guid.Empty)
            {
                CustomPropertyMatchInformation match = new CustomPropertyMatchInformation(ctx);
                match.CustomPropertyName  = Constants.AutoTaggable;
                match.CustomPropertyValue = "1";
                match.TrimUnavailable     = true;
                match.StringMatchOption   = StringMatchOption.ExactMatch;
                _termCollection           = _termSet.GetTermsWithCustomProperty(match);
                CurrentContext.Load(_termCollection,
                                    terms => terms.Include(
                                        tt => tt.Id, tt => tt.Labels), terms => terms.Include(tt => tt.CustomProperties));
                IsRootTerm = true;
            }
            else
            {
                //No way to match a property when taking terms of a term. The CustomPropertyMatch...only works when
                //getting terms from a _termSet. Tried to deal with LoadQuery but no way to query terms based on their properties
                var _targetTerm = _termSet.GetTerm(AnchorId);
                _termCollection = _targetTerm.Terms;
                CurrentContext.Load(_termCollection,
                                    terms => terms.Include(
                                        tt => tt.Id, tt => tt.Labels,
                                        tt => tt.CustomProperties,
                                        tt => tt.Terms, tt => tt.Terms.Include(ttt => ttt.Labels)));
            }
            if (keywords == null || (DateTime.Now - LastRefreshedKeywords).Minutes > Constants.KeywordIntervalRefresh)
            {
                lock (locker)
                {
                    if (keywords == null || (DateTime.Now - LastRefreshedKeywords).Minutes > Constants.KeywordIntervalRefresh)
                    {
                        keywords = _taxSession.GetDefaultKeywordsTermStore().KeywordsTermSet.GetAllTerms();
                        ctx.Load(keywords);
                        CurrentContext.ExecuteQuery();
                        LastRefreshedKeywords = DateTime.Now;
                        LogHelper.Log("Refreshed the keyword list", LogSeverity.Error);
                    }
                }
            }
            else
            {
                CurrentContext.ExecuteQuery();
            }

            LogHelper.Log("Inside TaxonomyTerms " + _termCollection.Count);
            AddTerms(_termCollection, IsRootTerm);
        }
        public TaxonomyTerms(ClientContext ctx, string TermSetId,Guid AnchorId)
        {
            
            bool IsRootTerm = false;
            LogHelper.Log("Inside TaxonomyTerms termsetid:" + TermSetId);
            CurrentContext = ctx;
            _TermsDictionary = new Dictionary<TermKey, string>();
            var _taxSession = TaxonomySession.GetTaxonomySession(CurrentContext);
            
            var _termStore = _taxSession.GetDefaultSiteCollectionTermStore();
            
            var _termSet = _termStore.GetTermSet(new Guid(TermSetId));
            TermCollection _termCollection=null;

            
            if(AnchorId == Guid.Empty)
            {
                CustomPropertyMatchInformation match = new CustomPropertyMatchInformation(ctx);
                match.CustomPropertyName = Constants.AutoTaggable;
                match.CustomPropertyValue = "1";
                match.TrimUnavailable = true;
                match.StringMatchOption = StringMatchOption.ExactMatch;
                _termCollection = _termSet.GetTermsWithCustomProperty(match);
                CurrentContext.Load(_termCollection,
                terms => terms.Include(
                     tt => tt.Id, tt => tt.Labels), terms => terms.Include(tt => tt.CustomProperties));
                IsRootTerm = true;
            }
            else
            {
                //No way to match a property when taking terms of a term. The CustomPropertyMatch...only works when
                //getting terms from a _termSet. Tried to deal with LoadQuery but no way to query terms based on their properties
                var _targetTerm = _termSet.GetTerm(AnchorId);
                _termCollection = _targetTerm.Terms;
                CurrentContext.Load(_termCollection,
                terms => terms.Include(
                     tt => tt.Id, tt => tt.Labels,
                     tt => tt.CustomProperties,
                     tt=>tt.Terms,tt=>tt.Terms.Include(ttt=>ttt.Labels)));
            }
            if (keywords == null || (DateTime.Now - LastRefreshedKeywords).Minutes > Constants.KeywordIntervalRefresh)
            {
                lock (locker)
                {
                    if (keywords == null || (DateTime.Now - LastRefreshedKeywords).Minutes > Constants.KeywordIntervalRefresh)
                    {
                        keywords = _taxSession.GetDefaultKeywordsTermStore().KeywordsTermSet.GetAllTerms();
                        ctx.Load(keywords);
                        CurrentContext.ExecuteQuery();
                        LastRefreshedKeywords = DateTime.Now;
                        LogHelper.Log("Refreshed the keyword list",LogSeverity.Error);
                    }
                }
            }
            else
            {
                CurrentContext.ExecuteQuery();
            }
            
            LogHelper.Log("Inside TaxonomyTerms " + _termCollection.Count);
            AddTerms(_termCollection, IsRootTerm);
        }