/// <summary>
        /// Join an enumeration of elements to the pipeline
        /// </summary>
        /// <typeparam name="T">type of elements to join</typeparam>
        /// <param name="observed">observed operation</param>
        /// <param name="activator">join parameters</param>
        /// <returns>resulting operation</returns>
        public static JoinOperation <T> Join <T>(this IObservableOperation observed, JoinActivator <T> activator)
        {
            var op = new JoinOperation <T>(activator);

            observed.Subscribe(op);
            return(op);
        }
Beispiel #2
0
        public void test_THAT_join_operation_with_foreign_and_primary_list_IS_converted_to_expression_correctly()
        {
            var        op1  = new FieldRefOperand("CityName", (new[] { new KeyValuePair <string, string>(Attributes.List, "Customers"), new KeyValuePair <string, string>(Attributes.RefType, "Id") }).ToList());
            var        op2  = new FieldRefOperand("Id", (new[] { new KeyValuePair <string, string>(Attributes.List, "CustomerCities") }).ToList());
            var        op   = new JoinOperation(null, op1, op2, JoinType.Inner);
            Expression expr = op.ToExpression();

            Assert.That(expr.ToString(), Is.EqualTo("x.get_Item(\"CityName\").PrimaryList(\"Customers\").ForeignList(\"CustomerCities\")"));
        }
        public void test_THAT_join_operation_IS_rendered_to_caml_properly()
        {
            var f = MockRepository.GenerateStub <FieldRefOperand>("");
            var v = MockRepository.GenerateStub <IntegerValueOperand>(1);

            f.Stub(o => o.ToCaml()).Return(new XElement("fieldRefOperandStub"));
            v.Stub(o => o.ToCaml()).Return(new XElement("valueOperandStub"));
            var op = new JoinOperation(new OperationResultBuilder(), f, v, JoinType.Inner);

            string caml = op.ToResult().ToString();

            string expected =
                "<Join Type=\"INNER\" ListAlias=\"\">" +
                "  <Eq>" +
                "    <fieldRefOperandStub />" +
                "    <valueOperandStub />" +
                "  </Eq>" +
                "</Join>";

            Assert.That(caml, Is.EqualTo(expected).Using(new CamlComparer()));
        }
Beispiel #4
0
        //private void ReflectionLaziness()
        //{
        //    Actions = new Dictionary<string, Action>();
        //    var operators = Assembly.GetExecutingAssembly().GetTypes()
        //        .Where(t => t.IsClass && t.GetInterface("IOperator") != null);

        //    foreach (var item in operators)
        //    {
        //        object obj = Activator.CreateInstance(item);

        //        var methods = item.GetMethods();
        //        foreach (var method in methods)
        //        {
        //            method.
        //            Actions.Add(method.Name, )
        //        }
        //    }
        //}

        private void ManualWithNimbleText()
        {
            Aggregation   Aggregation   = new Aggregation();
            Concatenation Concatenation = new Concatenation();
            Conversion    Conversion    = new Conversion();
            Element       Element       = new Element();
            Equal         Equal         = new Equal();
            Filter        Filter        = new Filter();
            Generate      Generate      = new Generate();
            Group         Group         = new Group();
            JoinOperation JoinOperation = new JoinOperation();
            Partition     Partition     = new Partition();
            Projection    Projection    = new Projection();
            Quantifier    Quantifier    = new Quantifier();
            Set           Set           = new Set();
            Sorting       Sorting       = new Sorting();

            Actions = new Dictionary <string, Action>();

            Actions.Add("OrderBy", Sorting.OrderBy);
            Actions.Add("OrderByDescending", Sorting.OrderByDescending);
            Actions.Add("ThenBy", Sorting.ThenBy);
            Actions.Add("ThenByDescending", Sorting.ThenByDescending);
            Actions.Add("Reverse", Sorting.Reverse);
            Actions.Add("Where", Filter.Where);
            Actions.Add("OfType", Filter.OfType);
            Actions.Add("Join", JoinOperation.Join);
            Actions.Add("GroupJoin", JoinOperation.GroupJoin);
            Actions.Add("SequenceEqual", Equal.SequenceEqual);
            Actions.Add("Concat", Concatenation.Concat);
            Actions.Add("GroupBy", Group.GroupBy);
            Actions.Add("ToLookup", Group.ToLookup);
            Actions.Add("DefaultIfEmpty", Generate.DefaultIfEmpty);
            Actions.Add("Empty", Generate.Empty);
            Actions.Add("Range", Generate.Range);
            Actions.Add("Repeat", Generate.Repeat);
            Actions.Add("Select", Projection.Select);
            Actions.Add("SelectMany", Projection.SelectMany);
            Actions.Add("All", Quantifier.All);
            Actions.Add("Any", Quantifier.Any);
            Actions.Add("Contains", Quantifier.Contains);
            Actions.Add("Distinct", Set.Distinct);
            Actions.Add("Except", Set.Except);
            Actions.Add("Intersect", Set.Intersect);
            Actions.Add("Union", Set.Union);
            Actions.Add("Skip", Partition.Skip);
            Actions.Add("SkipWhile", Partition.SkipWhile);
            Actions.Add("Take", Partition.Take);
            Actions.Add("TakeWhile", Partition.TakeWhile);
            Actions.Add("ElementAt", Element.ElementAt);
            Actions.Add("ElementAtOrDefault", Element.ElementAtOrDefault);
            Actions.Add("First", Element.First);
            Actions.Add("FirstOrDefault", Element.FirstOrDefault);
            Actions.Add("Last", Element.Last);
            Actions.Add("LastOrDefault", Element.LastOrDefault);
            Actions.Add("Single", Element.Single);
            Actions.Add("SingleOrDefault", Element.SingleOrDefault);
            Actions.Add("AsEnumerable", Conversion.AsEnumerable);
            Actions.Add("AsQueryable", Conversion.AsQueryable);
            Actions.Add("Cast", Conversion.Cast);
            Actions.Add("ToArray", Conversion.ToArray);
            Actions.Add("ToDictionary", Conversion.ToDictionary);
            Actions.Add("ToList", Conversion.ToList);
            Actions.Add("Aggregate", Aggregation.Aggregate);
            Actions.Add("Average", Aggregation.Average);
            Actions.Add("Count", Aggregation.Count);
            Actions.Add("LongCount", Aggregation.LongCount);
            Actions.Add("Max", Aggregation.Max);
            Actions.Add("Min", Aggregation.Min);
            Actions.Add("Sum", Aggregation.Sum);
        }
Beispiel #5
0
 internal Join(Table parentTable, SelectQueryBuilder joinQuery, JoinOperation joinOperator)
 {
     ParentTable    = parentTable;
     JoinOperator   = joinOperator;
     this.joinQuery = joinQuery;
 }
Beispiel #6
0
 internal Join(Table parentTable, string tableName, JoinOperation joinOperator)
 {
     ParentTable  = parentTable;
     JoinOperator = joinOperator;
     JoinTable    = tableName;
 }
        /// <summary>
        ///     Joins attributes from one feature to another based on the spatial relationship. The target features and the joined
        ///     attributes from the join features are written to the output feature class.
        /// </summary>
        /// <param name="source">
        ///     The source features and the attributes from the joined features are transferred to the output
        ///     feature class. However, a subset of attributes can be defined in the field map parameter.
        /// </param>
        /// <param name="join">The attributes from the join features are joined to the attributes of the source features.</param>
        /// <param name="tableName">A new feature class containing the attributes of the target and join features.</param>
        /// <param name="operation">
        ///     Determines how joins between the target features and join features will be handled in the
        ///     output feature class if multiple join features are found that have the same spatial relationship with a single
        ///     target feature.
        /// </param>
        /// <param name="isOuterJoin">
        ///     if set to <c>true</c> if all target features will be maintained in the output feature class
        ///     (known as outer join), or only those that have the specified spatial relationship with the join features (inner
        ///     join).
        /// </param>
        /// <param name="option">Defines the criteria used to match rows.</param>
        /// <param name="caseFields">The attribute fields will be in the output feature class.</param>
        /// <param name="searchRadius">
        ///     Join features within this distance of a target feature will be considered for the spatial
        ///     join.
        /// </param>
        /// <param name="trackCancel">The track cancel.</param>
        /// <param name="eventHandler">The event handler.</param>
        /// <returns>Returns a <see cref="IFeatureClass" /> representing the feature class of the joined data.</returns>
        public static IFeatureClass Join(this IFeatureClass source, IFeatureClass join, string tableName, JoinOperation operation, bool isOuterJoin, SpatialOperation option, string[] caseFields, double searchRadius, ITrackCancel trackCancel, IGeoProcessorEvents eventHandler)
        {
            IGpFieldMappingsObject fieldMappings = new GpFieldMappingsObjectClass();

            fieldMappings.AddTable(source.GetAbsolutePath());
            fieldMappings.AddTable(join.GetAbsolutePath());

            int[] caseIndexes = caseFields.Select(fieldMappings.FindFieldMapIndex).ToArray();

            for (int i = fieldMappings.FieldCount - 1; i >= 0; i--)
            {
                if (caseIndexes.Contains(i))
                {
                    continue;
                }

                fieldMappings.RemoveFieldMap(i);
            }

            return(source.Join(join, tableName, operation, isOuterJoin, option, fieldMappings, searchRadius, trackCancel, eventHandler));
        }
        /// <summary>
        ///     Joins attributes from one feature to another based on the spatial relationship. The target features and the joined
        ///     attributes from the join features are written to the output feature class.
        /// </summary>
        /// <param name="source">
        ///     The source features and the attributes from the joined features are transferred to the output
        ///     feature class. However, a subset of attributes can be defined in the field map parameter.
        /// </param>
        /// <param name="join">The attributes from the join features are joined to the attributes of the source features.</param>
        /// <param name="tableName">A new feature class containing the attributes of the target and join features.</param>
        /// <param name="operation">
        ///     Determines how joins between the target features and join features will be handled in the
        ///     output feature class if multiple join features are found that have the same spatial relationship with a single
        ///     target feature.
        /// </param>
        /// <param name="isOuterJoin">
        ///     if set to <c>true</c> if all target features will be maintained in the output feature class
        ///     (known as outer join), or only those that have the specified spatial relationship with the join features (inner
        ///     join).
        /// </param>
        /// <param name="option">Defines the criteria used to match rows.</param>
        /// <param name="fieldMappings">The attribute fields will be in the output feature class.</param>
        /// <param name="searchRadius">
        ///     Join features within this distance of a target feature will be considered for the spatial
        ///     join.
        /// </param>
        /// <param name="trackCancel">The track cancel.</param>
        /// <param name="eventHandler">The event handler.</param>
        /// <returns>Returns a <see cref="IFeatureClass" /> representing the feature class of the joined data.</returns>
        public static IFeatureClass Join(this IFeatureClass source, IFeatureClass join, string tableName, JoinOperation operation, bool isOuterJoin, SpatialOperation option, IGpFieldMappingsObject fieldMappings, double searchRadius, ITrackCancel trackCancel, IGeoProcessorEvents eventHandler)
        {
            var ds = (IDataset)source;

            SpatialJoin gp = new SpatialJoin();

            gp.join_operation = operation.ToDescription();
            gp.join_type      = isOuterJoin ? "KEEP_ALL" : "KEEP_COMMON";
            gp.match_option   = option.ToDescription();
            gp.field_mapping  = fieldMappings;
            gp.search_radius  = searchRadius;

            gp.target_features   = source;
            gp.join_features     = join;
            gp.out_feature_class = ds.Workspace.GetAbsolutePath(tableName);

            if (gp.Run(trackCancel, eventHandler) == esriJobStatus.esriJobSucceeded)
            {
                return(ds.Workspace.GetFeatureClass(tableName));
            }

            return(null);
        }