private void PopulateCompletionData(IList <ICompletionData> data, IntellisenseMetadataTypes metadataType, DaxLineState state)
        {
            // exit early if the Metadata is not cached
            if (!MetadataIsCached)
            {
                return;
            }

            var tmpData = new List <ICompletionData>();

            Log.Debug("{class} {method} Type: {metadataType}  Table: {table} Column: {column}", "DaxIntellisenseProvider", "PopulateCompletionData", metadataType.ToString(), state == null ? "-" : state.TableName, state == null ? "-": state.ColumnName);
            if (metadataType.HasFlag(IntellisenseMetadataTypes.Tables) ||
                metadataType.HasFlag(IntellisenseMetadataTypes.Columns) ||
                metadataType.HasFlag(IntellisenseMetadataTypes.Measures))
            {
                //var tabs = Document.Connection.Database.Models[Document.MetadataPane.SelectedModelName].Tables;
                var tabs = Model.Tables;
                foreach (var tab in tabs)
                {
                    // add tables
                    if (metadataType.HasFlag(IntellisenseMetadataTypes.Tables))
                    {
                        tmpData.Add(new DaxCompletionData(this, tab, _daxState));
                    }

                    // add columns or measures
                    if ((metadataType.HasFlag(IntellisenseMetadataTypes.Columns) &&
                         (string.IsNullOrWhiteSpace(_daxState.TableName)) || (tab.Name.Equals(_daxState.TableName, StringComparison.CurrentCultureIgnoreCase))) ||
                        metadataType.HasFlag(IntellisenseMetadataTypes.Measures))
                    {
                        foreach (var col in tab.Columns)
                        {
                            if ((col.ColumnType == ADOTabularColumnType.Column && metadataType.HasFlag(IntellisenseMetadataTypes.Columns)) ||
                                col.ColumnType == ADOTabularColumnType.Measure && metadataType.HasFlag(IntellisenseMetadataTypes.Measures))
                            {
                                tmpData.Add(new DaxCompletionData(this, col, _daxState));
                            }
                        }
                    }
                }
            }

            // add functions
            if (metadataType.HasFlag(IntellisenseMetadataTypes.Functions))
            {
                foreach (var funcGrp in Document.Connection.FunctionGroups)
                {
                    foreach (var func in funcGrp.Functions)
                    {
                        tmpData.Add(new DaxCompletionData(this, func));
                    }
                }
            }

            if (metadataType.HasFlag(IntellisenseMetadataTypes.DMV))
            {
                foreach (var dmv in Document.Connection.DynamicManagementViews)
                {
                    tmpData.Add(new DaxCompletionData(this, dmv));
                }
            }

            // add keywords
            if (metadataType.HasFlag(IntellisenseMetadataTypes.Keywords))
            {
                tmpData.Add(new DaxCompletionData(this, "EVALUATE", 200.0));
                tmpData.Add(new DaxCompletionData(this, "MEASURE", 200.0));
                tmpData.Add(new DaxCompletionData(this, "DEFINE", 200.0));
                tmpData.Add(new DaxCompletionData(this, "ORDER BY", 200.0));
                tmpData.Add(new DaxCompletionData(this, "ASC", 200.0));
                tmpData.Add(new DaxCompletionData(this, "DESC", 200.0));
                tmpData.Add(new DaxCompletionData(this, "SELECT", 200.0));
                tmpData.Add(new DaxCompletionData(this, "FROM", 200.0));
                tmpData.Add(new DaxCompletionData(this, "WHERE", 200.0));
                tmpData.Add(new DaxCompletionData(this, "$SYSTEM", 200.0));
            }
            foreach (var itm in tmpData.OrderBy(x => x.Content.ToString()))
            {
                data.Add(itm);
            }
        }
        private void PopulateCompletionData(IList<ICompletionData> data, IntellisenseMetadataTypes metadataType, string tableName)
        {
            var tmpData = new List<ICompletionData>();

            if (metadataType.HasFlag(IntellisenseMetadataTypes.Tables)
                || metadataType.HasFlag(IntellisenseMetadataTypes.Columns)
                || metadataType.HasFlag(IntellisenseMetadataTypes.Measures))
            {
                foreach (var tab in Document.Connection.Database.Models[Document.MetadataPane.SelectedModelName].Tables)
                {
                    // add tables
                    if (metadataType.HasFlag(IntellisenseMetadataTypes.Tables))
                            tmpData.Add( new DaxCompletionData(tab));

                    // add columns or measures
                    if ((metadataType.HasFlag(IntellisenseMetadataTypes.Columns)
                        && ( string.IsNullOrWhiteSpace(tableName)) || (tab.Name.Equals(tableName, StringComparison.CurrentCultureIgnoreCase)))
                        || metadataType.HasFlag(IntellisenseMetadataTypes.Measures))
                    {
                        foreach (var col in tab.Columns)
                        {
                            if ((col.ColumnType == ADOTabularColumnType.Column && metadataType.HasFlag(IntellisenseMetadataTypes.Columns))
                                || col.ColumnType == ADOTabularColumnType.Measure && metadataType.HasFlag(IntellisenseMetadataTypes.Measures))
                            {

                                tmpData.Add(new DaxCompletionData(col));
                            }
                        }
                    }
                }
            }

            // add functions
            if (metadataType.HasFlag(IntellisenseMetadataTypes.Functions))
            {
                foreach (var funcGrp in Document.Connection.FunctionGroups)
                {
                    foreach (var func in funcGrp.Functions)
                    {
                        tmpData.Add( new DaxCompletionData(func));
                    }
                }
            }

            if (metadataType.HasFlag(IntellisenseMetadataTypes.DMV))
            {
                foreach (var dmv in Document.Connection.DynamicManagementViews)
                {
                    tmpData.Add(new DaxCompletionData(dmv));
                }
            }

            // add keywords
            if (metadataType.HasFlag(IntellisenseMetadataTypes.Keywords))
            {
                tmpData.Add(new DaxCompletionData("EVALUATE", 200.0));
                tmpData.Add(new DaxCompletionData("MEASURE", 200.0));
                tmpData.Add(new DaxCompletionData("DEFINE", 200.0));
                tmpData.Add(new DaxCompletionData("ORDER BY", 200.0));
                tmpData.Add(new DaxCompletionData("ASC", 200.0));
                tmpData.Add(new DaxCompletionData("DESC", 200.0));
                tmpData.Add(new DaxCompletionData("SELECT", 200.0));
                tmpData.Add(new DaxCompletionData("FROM", 200.0));
                tmpData.Add(new DaxCompletionData("WHERE", 200.0));
                tmpData.Add(new DaxCompletionData("$SYSTEM", 200.0));
            }
            foreach(var itm in tmpData.OrderBy(x => x.Content.ToString()))
            {
                data.Add(itm);
            }
        }
 private void PopulateCompletionData(IList <ICompletionData> data, IntellisenseMetadataTypes metadataType)
 {
     PopulateCompletionData(data, metadataType, null);
 }
 private void PopulateCompletionData(IList<ICompletionData> data, IntellisenseMetadataTypes metadataType)
 {
     PopulateCompletionData(data, metadataType,"");
 }