Example #1
0
            public IDataSource Parse(JobParser parser, ParseState state)
            {
                var connectionString = state.TryGet("connection", ExperienceExtractorWebApiConfig.XdbConnectionString, true);

                if (!connectionString.StartsWith("mongodb://"))
                {
                    var connection = ConfigurationManager.ConnectionStrings[connectionString];
                    if (connection == null)
                    {
                        throw state.AttributeError("Connection string '{0}' not found", connectionString);
                    }
                    connectionString = connection.ConnectionString;
                }

                var source = new MongoDbVisitAggregationContextSource(new MongoDbDriver(connectionString), ExperienceExtractorWebApiConfig.JobExecutionSettings.LoadThreads);

                //source.SecondaryLookup = state.TryGet("SecondaryLookup", false);

                var index = state.TryGet <string>("index");

                if (!string.IsNullOrEmpty(index))
                {
                    source.CursorInitializing += (sender, cursor) =>
                    {
                        if (index == "$natural")
                        {
                            cursor.SetSortOrder(SortBy.Ascending("$natural"));
                        }
                        else
                        {
                            cursor.SetHint(index);
                        }
                    };
                }

                var fields = state.TryGet("fields", new string[0]);

                if (fields.Length > 0)
                {
                    source.CursorInitializing += (sender, cursor) => cursor.SetFields(fields);
                }


                foreach (var filter in state.SelectMany("Filters"))
                {
                    source.Filters.Add(parser.ParseDataFilter(filter));
                }

                return(source);
            }