Exemple #1
0
        public event EventHandler CanExecuteChanged; // Event that can be raised when the executability of the command changes. When this event is raised, the Viewer will invoke the CanExecute method, allowing the add-in to update the state of the tool's button on the toolbar.
        //if (CanExecuteChanged != null){CanExecuteChanged(this, EventArgs.Empty);}

        #endregion ICommand members


        #region Event Handlers
        /// <summary>
        /// Handle successful query task and create FeatureLayer from related table/FC
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void QueryTask_ExecuteRelationshipQueryCompleted(object sender, RelationshipEventArgs e)
        {
            // queryResult used once the results layer is initialized
            queryResult = e.Result;

            // Create a new url for the related table using the querytaskUrl and the RelatedTableId.
            string resultsUrl = relatesLayer.lyrUrl;
            var    lastSlash  = resultsUrl.LastIndexOf("/");         // -1?

            resultsUrl = string.Format("{0}/{1}", resultsUrl.Substring(0, lastSlash), relationInfo.tableId);
            log(string.Format("QueryTask_ExecuteRelationshipQueryCompleted, resultsUrl='{0}'", resultsUrl));

            // Create a FeatureLayer for the results based on the url of the related records.
            var resFL = new FeatureLayer()
            {
                Url = resultsUrl
            };

            resFL.OutFields.Add("*");

            // Initialize the resultsLayer to populate layer metadata (LayerInfo) so the OID field can be retrieved.
            resFL.Initialized += resultsLayer_Initialized;
            resFL.Initialize();
            resultsLayer = new mwb02.AddIns.VLayer(resFL);

            log(string.Format("QueryTask_ExecuteRelationshipQueryCompleted, completed, wait for resultsLayer_Initialized"));
        }         // private void QueryTask_ExecuteRelationshipQueryCompleted(object sender, RelationshipEventArgs e)
        /// <summary>
        /// Handle successful query task and create FeatureLayer from related table/FC
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void QueryTask_ExecuteRelationshipQueryCompleted(
            object sender, RelationshipEventArgs e)
        {
            // queryResult used once the results layer is initialized
            queryResult = e.Result;

            // Create a new url for the related table using the querytaskUrl and the RelatedTableId.
            string resultsUrl = relatesLayer.Url;

            string[] splitResultUrl = resultsUrl.Split('/');
            resultsUrl = resultsUrl.Replace(splitResultUrl.Last <string>(), "");
            resultsUrl = resultsUrl.Insert(resultsUrl.Length, relationInfo.tableId.ToString());
            log(string.Format("QueryTask_ExecuteRelationshipQueryCompleted, resultsUrl='{0}'", resultsUrl));

            // Create a FeatureLayer for the results based on the url of the related records.
            resultsLayer = new FeatureLayer()
            {
                Url = resultsUrl
            };
            resultsLayer.OutFields.Add("*");

            // Initialize the resultsLayer to populate layer metadata (LayerInfo) so the OID field can be retrieved.
            resultsLayer.Initialized += resultsLayer_Initialized;
            resultsLayer.Initialize();

            log(string.Format("QueryTask_ExecuteRelationshipQueryCompleted, completed, wait for resultsLayer_Initialized"));
        } // private void QueryTask_ExecuteRelationshipQueryCompleted(object sender, RelationshipEventArgs e)
        /// <summary>
        /// Handle successful query task and initializes the results layer
        /// </summary>
        private void QueryTask_ExecuteRelationshipQueryCompleted(object sender, RelationshipEventArgs e)
        {
            // Unhook the queryTask.ExecuteRelationshipQueryCompleted
            queryTask.ExecuteRelationshipQueryCompleted -= QueryTask_ExecuteRelationshipQueryCompleted;

            // queryResult used once the results layer is initialized
            queryResult = e.Result;

            if (queryResult.RelatedRecordsGroup.Count > 0)
            {
                string relatedTableID = SelectedRelationship.RelatedTableId.ToString();

                if (relatedTableID == null)
                {
                    relatedTableID = relatesLayer.LayerInfo.Relationships.First().RelatedTableId.ToString();
                }

                // Determine the url for the related table and use to populate the Url property of the new resultsLayer.
                string resultsUrl = relatesLayer.Url;

                resultsUrl = resultsUrl.Substring(0, resultsUrl.LastIndexOf('/') + 1);
                resultsUrl = resultsUrl.Insert(resultsUrl.Length, relatedTableID);


                // Create a FeatureLayer for the results based on the url of the related records. At this point, the feature layer will
                // retrieve all the graphics/info from the layer. In the resultsLayer_Initialized, we trim that down based on the Object id field.
                resultsLayer = new FeatureLayer()
                {
                    Url      = resultsUrl,
                    ProxyUrl = relatesLayer.ProxyUrl
                };

                resultsLayer.OutFields.Add("*");

                // Initialize the resultsLayer to populate layer metadata (LayerInfo) so the OID field can be retrieved.
                resultsLayer.Initialized          += resultsLayer_Initialized;
                resultsLayer.InitializationFailed += resultsLayer_InitializationFailed;
                resultsLayer.UpdateCompleted      += resultsLayer_UpdateCompleted;

                resultsLayer.Initialize();
            }
            else
            {
                Grid infoWindowGrid = Utils.FindChildOfType <Grid>(popupWindow, 3);
                infoWindowGrid.Children.Remove(indicator);

                infoWindowGrid.Children.Add(NoRecordsFoundView);

                ((DelegateCommand)CloseNoRecordsView).RaiseCanExecuteChanged();
            }
        }
Exemple #4
0
        void QueryTask_ExecuteRelationshipQueryCompleted(object sender, RelationshipEventArgs e)
        {
            RelationshipResult pr = e.Result;

            if (pr.RelatedRecordsGroup.Count == 0)
            {
                RelatedRowsDataGrid.ItemsSource = null;
            }
            else
            {
                foreach (var pair in pr.RelatedRecordsGroup)
                {
                    RelatedRowsDataGrid.ItemsSource = pair.Value;
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="relationshipAttributes">fields that are declared on the application schema containing '.' </param>
        /// <param name="entityMetadata"></param>
        /// <returns></returns>
        public static RelationshipResult HandleRelationshipFields(IEnumerable <String> relationshipAttributes,
                                                                  EntityMetadata entityMetadata)
        {
            var result     = new RelationshipResult();
            var attributes = relationshipAttributes as string[] ?? relationshipAttributes.ToArray();

            if (!attributes.Any())
            {
                return(result);
            }

            var innerFields       = new Dictionary <string, HashSet <string> >();
            var usedRelationships = new List <EntityAssociation>();

            foreach (var attribute in attributes)
            {
                var indexOf   = attribute.IndexOf(".", System.StringComparison.InvariantCulture);
                var qualifier = attribute.Substring(0, indexOf);
                qualifier = qualifier.EndsWith("_") ? qualifier : qualifier + "_";
                //                if (qualifier.LastIndexOf("_", StringComparison.Ordinal) !=
                //                    qualifier.IndexOf("_", StringComparison.Ordinal)) {
                //if we have more then 1 _ it means that this is non a direct relationship...
                //so we need to add Inner Sliced Data to perform a nested join, besisdes of the "used relationship"
                // ex: location_shipto_.address1 or location_billto_.address2
                PopulateInnerFieldsEntry(entityMetadata, attribute, usedRelationships, innerFields);
                //                    result.InnerEntityMetadatas.Add(BuildInnerSliced());
                //                } else {
                //                    //otherwise, just add as a simple relationship
                //                    //ex: asset_.description on application sr
                //                    var sliced =SlicedEntityAssociation.GetInstance(entityMetadata.Associations.First(a => a.Qualifier == qualifier));
                //                    usedRelationships.Add(sliced);
                //                }
            }
            foreach (var innerFieldEntry in innerFields)
            {
                result.InnerEntityMetadatas.Add(BuildInnerSliced(entityMetadata, innerFieldEntry));
            }

            result.DirectRelationships = usedRelationships;
            return(result);
        }
        /// <summary>
        /// Handle successful query task and initializes the results layer
        /// </summary>
        private void QueryTask_ExecuteRelationshipQueryCompleted(object sender, RelationshipEventArgs e)
        {
            // Unhook the queryTask.ExecuteRelationshipQueryCompleted
            queryTask.ExecuteRelationshipQueryCompleted -= QueryTask_ExecuteRelationshipQueryCompleted;

            // queryResult used once the results layer is initialized
            queryResult = e.Result;

            if (queryResult.RelatedRecordsGroup.Count > 0)
            {

                string relatedTableID = SelectedRelationship.RelatedTableId.ToString();

                if (relatedTableID == null)
                {
                    relatedTableID = relatesLayer.LayerInfo.Relationships.First().RelatedTableId.ToString();
                }

                // Determine the url for the related table and use to populate the Url property of the new resultsLayer.
                string resultsUrl = relatesLayer.Url;

                resultsUrl = resultsUrl.Substring(0, resultsUrl.LastIndexOf('/') + 1);
                resultsUrl = resultsUrl.Insert(resultsUrl.Length, relatedTableID);


                // Create a FeatureLayer for the results based on the url of the related records. At this point, the feature layer will
                // retrieve all the graphics/info from the layer. In the resultsLayer_Initialized, we trim that down based on the Object id field.
                resultsLayer = new FeatureLayer()
                {
                    Url = resultsUrl,
                    ProxyUrl = relatesLayer.ProxyUrl
                };

                resultsLayer.OutFields.Add("*");

                // Initialize the resultsLayer to populate layer metadata (LayerInfo) so the OID field can be retrieved.
                resultsLayer.Initialized += resultsLayer_Initialized;
                resultsLayer.InitializationFailed += resultsLayer_InitializationFailed;
                resultsLayer.UpdateCompleted += resultsLayer_UpdateCompleted;

                resultsLayer.Initialize();

            }
            else
            {
                Grid infoWindowGrid = Utils.FindChildOfType<Grid>(popupWindow, 3);
                infoWindowGrid.Children.Remove(indicator);

                infoWindowGrid.Children.Add(NoRecordsFoundView);

                ((DelegateCommand)CloseNoRecordsView).RaiseCanExecuteChanged();
            }
        }