private void SelectedWellsTreeView_OnSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { if (e.RemovedItems.Count > 0) { Graphic g = e.RemovedItems[0] as Graphic; g.UnSelect(); g.SetZIndex(0); } if (e.AddedItems.Count > 0) { Graphic g = e.AddedItems[0] as Graphic; g.Select(); g.SetZIndex(1); //Relationship query RelationshipParameter relationshipParameters = new RelationshipParameter() { ObjectIds = new int[] { Convert.ToInt32(g.Attributes[SelectedWellsTreeView.Tag as string]) }, OutFields = new string[] { "OBJECTID, API_NUMBER, ELEVATION, FORMATION, TOP" }, RelationshipId = 3, OutSpatialReference = MyMap.SpatialReference }; queryTask.ExecuteRelationshipQueryAsync(relationshipParameters); } }
// Query for rows related to the selected well in the wells list view private async void WellsGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (e.AddedItems != null && e.AddedItems.Count > 0) { QueryTask queryTask = new QueryTask(new Uri("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer/0")); //Relationship query var objectIds = e.AddedItems.OfType <Graphic>() .Select(g => Convert.ToInt64(g.Attributes["OBJECTID"])); RelationshipParameter parameters = new RelationshipParameter(new List <long>(objectIds), 3) { OutSpatialReference = mapView.SpatialReference }; parameters.OutFields.AddRange(new string[] { "OBJECTID, API_NUMBER, ELEVATION, FORMATION, TOP" }); var result = await queryTask.ExecuteRelationshipQueryAsync(parameters); relationshipsGrid.ItemsSource = result.RelatedRecordGroups.FirstOrDefault().Value; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Query Related Tables"); } }
private void SelectedWellsTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { if (e.OldValue != null) { Graphic g = e.OldValue as Graphic; g.UnSelect(); g.SetZIndex(0); } if (e.NewValue != null) { Graphic g = e.NewValue as Graphic; g.Select(); g.SetZIndex(1); //Relationship query RelationshipParameter relationshipParameters = new RelationshipParameter() { ObjectIds = new int[] { Convert.ToInt32(g.Attributes[SelectedWellsTreeView.Tag as string]) }, OutFields = new string[] { "OBJECTID, API_NUMBER, ELEVATION, FORMATION, TOP" }, RelationshipId = 3, OutSpatialReference = MyMap.SpatialReference }; queryTask.ExecuteRelationshipQueryAsync(relationshipParameters); } }
// Query for rows related to the selected well in the wells list view private async void WellsGrid_SelectionChanged(object sender, Windows.UI.Xaml.Controls.SelectionChangedEventArgs e) { try { if (e.AddedItems != null && e.AddedItems.Count > 0) { QueryTask queryTask = new QueryTask(new Uri("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer/0")); //Relationship query var objectIds = e.AddedItems.OfType<Graphic>() .Select(g => Convert.ToInt64(g.Attributes["OBJECTID"])); RelationshipParameter parameters = new RelationshipParameter(new List<long>(objectIds), 3) { OutSpatialReference = mapView.SpatialReference }; parameters.OutFields.AddRange(new string[] { "OBJECTID, API_NUMBER, ELEVATION, FORMATION, TOP" }); var result = await queryTask.ExecuteRelationshipQueryAsync(parameters); relationshipsGrid.ItemsSource = result.RelatedRecordGroups.FirstOrDefault().Value; } } catch (Exception ex) { var _ = new MessageDialog(ex.Message, "Sample Error").ShowAsync(); } }
void ISoapTransactionLinkExecutor.ExecuteBulkTransactions(Guid sessionId, Service.TransactionalMappingToolServiceClient serviceProxy, ref Service.OPS bulkOperations) { SessionId = sessionId; ServiceProxy = serviceProxy; ResponseParameter = new Service.MP(); ResponseParameter.I = Guid.NewGuid(); ResponseParameter.S = sessionId; ResponseParameter.V = Guid.Empty; ResponseParameter.D = true; ResponseParameter.T = Service.MapParameterType.Node; Service.BMA metadataBulkOperation = new Service.BMA(); metadataBulkOperation.I = TransactionLinkId; metadataBulkOperation.D = DomainParameter.GetParameterValue(sessionId); metadataBulkOperation.RM = RootMapParameter.GetParameterValue(sessionId); metadataBulkOperation.N = NodeParameter.GetParameterValue(sessionId); metadataBulkOperation.R = RelationshipParameter.GetParameterValue(sessionId); metadataBulkOperation.DT = MapManager.ConnectionTypes.ConvertProxyToService(ConnectionType); metadataBulkOperation.T = MapManager.MetadataTypes.ConvertProxyToService(MetadataType); metadataBulkOperation.MN = Name; metadataBulkOperation.MV = Value; metadataBulkOperation.RI = ResponseParameter.I; bulkOperations.O.Add(metadataBulkOperation); ISoapTransactionLinkExecutor executor = _firstLink as ISoapTransactionLinkExecutor; if (executor == null) { DebugLogger.Instance.LogMsg("Exception: This is not a supported type of link. This link does not implement ISoapTransactionLinkExecutor."); throw new NotSupportedException("This is not a supported type of link. This link does not implement ISoapTransactionLinkExecutor."); } if (bulkOperations.O.Count < 200) { if (!_onCompletedBound) { executor.TransactionFailed += OnTransactionFailed; executor.TransactionCompleted += OnTransactionCompleted; _onCompletedBound = true; } DebugLogger.Instance.LogMsg("Executing add metadata transaction. Name - '{0}'; Value - '{1}';", Name, Value); executor.ExecuteBulkTransactions(SessionId, ServiceProxy, ref bulkOperations); } else { ServiceProxy.BOCCompleted += new EventHandler <Service.BOCCompletedEventArgs>(OnSubmitBulkOperationCompleted); ServiceProxy.SubmitBulkOperationsAsync(System.Windows.Browser.HtmlPage.Document.DocumentUri.ToString(), SessionId, bulkOperations, this); } }
private async Task RunRelationshipQuery(IEnumerable<long> objectIds) { QueryTask queryTask = new QueryTask(new Uri("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer/0")); //Relationship query RelationshipParameter parameters = new RelationshipParameter(new List<long>(objectIds), 3) { OutSpatialReference = mapView1.SpatialReference }; parameters.OutFields.AddRange(new string[] { "OBJECTID, API_NUMBER, ELEVATION, FORMATION, TOP" }); var result = await queryTask.ExecuteRelationshipQueryAsync(parameters); RelationshipResultsGrid.ItemsSource = result.RelatedRecordGroups.FirstOrDefault().Value; }
private async Task RunRelationshipQuery(IEnumerable <long> objectIds) { QueryTask queryTask = new QueryTask(new Uri("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer/0")); //Relationship query RelationshipParameter parameters = new RelationshipParameter(new List <long>(objectIds), 3) { OutSpatialReference = mapView1.SpatialReference }; parameters.OutFields.AddRange(new string[] { "OBJECTID, API_NUMBER, ELEVATION, FORMATION, TOP" }); var result = await queryTask.ExecuteRelationshipQueryAsync(parameters); RelationshipResultsGrid.ItemsSource = result.RelatedRecordGroups.FirstOrDefault().Value; }
void ISoapTransactionLinkExecutor.ExecuteBulkTransactions(Guid sessionId, TransactionalMappingToolServiceClient serviceProxy, ref Service.OPS bulkOperations) { SessionId = sessionId; ServiceProxy = serviceProxy; ResponseParameter = new Service.MP(); ResponseParameter.I = Guid.NewGuid(); ResponseParameter.S = sessionId; ResponseParameter.V = Guid.Empty; ResponseParameter.D = true; ResponseParameter.T = Service.MapParameterType.Node; Service.BRD relationshipBulkOperation = new Service.BRD(); relationshipBulkOperation.I = TransactionLinkId; relationshipBulkOperation.D = DomainParameter.GetParameterValue(sessionId); relationshipBulkOperation.R = RelationshipParameter.GetParameterValue(SessionId); relationshipBulkOperation.RI = ResponseParameter.I; bulkOperations.O.Add(relationshipBulkOperation); ISoapTransactionLinkExecutor executor = _firstLink as ISoapTransactionLinkExecutor; if (executor == null) { DebugLogger.Instance.LogMsg("Exception: This is not a supported type of link. This link does not implement ISoapTransactionLinkExecutor."); throw new NotSupportedException("This is not a supported type of link. This link does not implement ISoapTransactionLinkExecutor."); } if (bulkOperations.O.Count < 200) { if (!_onCompletedBound) { executor.TransactionFailed += OnTransactionFailed; executor.TransactionCompleted += OnTransactionCompleted; _onCompletedBound = true; } DebugLogger.Instance.LogMsg("Executing delete relationship transaction. ClientId - '{0}';", Relationship.ClientId); executor.ExecuteBulkTransactions(SessionId, ServiceProxy, ref bulkOperations); } else { ServiceProxy.BOCCompleted += new EventHandler <BOCCompletedEventArgs>(OnSubmitBulkOperationCompleted); ServiceProxy.SubmitBulkOperationsAsync(CallingUrl.Url, SessionId, bulkOperations, this); } }
// Query for well tops related to wells with the passed-in object ID private async Task <RelationshipResult> doRelationshipQuery(int oid) { QueryTask queryTask = new QueryTask(new Uri("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer/0")); // Initialize relationship parameters RelationshipParameter parameters = new RelationshipParameter(new long[] { oid }, 3) { OutSpatialReference = m_mapView.SpatialReference, OutFields = new OutFields(new string[] { "OBJECTID, API_NUMBER, FORMATION, TOP" }) }; try { // Do the relationship query and return the result return(await queryTask.ExecuteRelationshipQueryAsync(parameters)); } catch { return(null); } }
void ISoapTransactionLinkExecutor.ExecuteTransaction(Guid sessionId, Service.TransactionalMappingToolServiceClient serviceProxy) { SessionId = sessionId; ServiceProxy = serviceProxy; ServiceProxy.MACompleted += OnAddMetadataCompleted; ServiceProxy.MAAsync(System.Windows.Browser.HtmlPage.Document.DocumentUri.ToString(), SessionId, DomainParameter.GetParameterValue(sessionId), RootMapParameter.GetParameterValue(sessionId), NodeParameter.GetParameterValue(sessionId), RelationshipParameter.GetParameterValue(sessionId), MapManager.ConnectionTypes.ConvertProxyToService(ConnectionType), MapManager.MetadataTypes.ConvertProxyToService(MetadataType), Name, Value, this); }
void ISoapTransactionLinkExecutor.ExecuteTransaction(Guid sessionId, TransactionalMappingToolServiceClient serviceProxy) { SessionId = sessionId; ServiceProxy = serviceProxy; ServiceProxy.MACompleted += OnAddMetadataCompleted; ServiceProxy.MAAsync(CallingUrl.Url, SessionId, DomainParameter.GetParameterValue(sessionId), RootMapParameter.GetParameterValue(sessionId), NodeParameter.GetParameterValue(sessionId), RelationshipParameter.GetParameterValue(sessionId), MapManager.ConnectionTypes.ConvertProxyToService(ConnectionType), MapManager.MetadataTypes.ConvertProxyToService(MetadataType), Name, Value, this); }
void ISoapTransactionLinkExecutor.ExecuteTransaction(Guid sessionId, TransactionalMappingToolServiceClient serviceProxy) { SessionId = sessionId; ServiceProxy = serviceProxy; ServiceProxy.RDCompleted += OnDeleteRelationshipCompleted; ServiceProxy.RDAsync(CallingUrl.Url, SessionId, DomainParameter.GetParameterValue(SessionId), RelationshipParameter.GetParameterValue(SessionId), this); }
/// <summary> /// Performs the relationship query. /// </summary> /// <remarks>Called from the doQuery method.</remarks> private void QueryRelationship() { // Set the popupWindow and subscribe to changes on the popupWindow.IsOpen property popupWindow = PopupInfo.Container as InfoWindow; // Set the attribute grid container and subscripbe to changes on the Visibility property attributeGridContainer = MapApplication.Current.FindObjectInLayout(CONTAINER_NAME) as FrameworkElement; ExtensionMethods.Properties.NotifyOnDependencyPropertyChanged("Visibility", attributeGridContainer, OnDataGridVisibilityChanged); // Listen for selection of a different layer in the map contents. MapApplication.Current.SelectedLayerChanged += Current_SelectedLayerChanged; // Listen for a change in the selected index of the PopupInfo (indicating the popup item has changed). PopupInfo.PropertyChanged += PopupInfo_PropertyChanged; // Locate the grid inside the popup window and remove the RelationshipView. This was initially inserted if // multiple relationships for a feature were detected. Grid infoWindowGrid = Utils.FindChildOfType <Grid>(popupWindow, 3); infoWindowGrid.Children.Remove(RelationshipView); // Set the relationshipID for the QueryTask. int relationshipID = SelectedRelationship.Id; // Get the feature and layer info from the pop-up. The PopupItem property of OnClickPopupInfo // provides information about the item currently shown in the pop-up. Graphic inputFeature = PopupInfo.PopupItem.Graphic; relatesLayer = PopupInfo.PopupItem.Layer as FeatureLayer; // The layer to get related records for. This is used to get the RelationshipID and Query url. // Get the name of the ObjectID field. objectIDField = relatesLayer.LayerInfo.ObjectIdField; // Input parameters for QueryTask RelationshipParameter relationshipParameters = new RelationshipParameter() { ObjectIds = new int[] { (int)inputFeature.Attributes[objectIDField] }, OutFields = new string[] { "*" }, // Return all fields ReturnGeometry = true, // Return the geometry so that features can be displayed on the map if applicable RelationshipId = relationshipID, // Obtain the desired RelationshipID from the Service Details page. Here it takes the first relationship it finds if there is more than one. OutSpatialReference = map.SpatialReference }; // Specify the Feature Service url for the QueryTask. queryTask.Url = relatesLayer.Url; queryTask.ProxyURL = relatesLayer.ProxyUrl; // Events for the successful completion of the RelationshipQuery and for if the Query fails queryTask.ExecuteRelationshipQueryCompleted += QueryTask_ExecuteRelationshipQueryCompleted; queryTask.Failed += QueryTask_Failed; // Execute the Query Task with specified parameters queryTask.ExecuteRelationshipQueryAsync(relationshipParameters); // Create the BusyIndicator and insert into the grid of the popup window. indicator = new BusyIndicator(); indicator.BusyContent = Strings.RetrievingRecords; if (infoWindowGrid != null) { infoWindowGrid.Children.Add(indicator); indicator.IsBusy = true; } }
private void SelectedWellsTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e) { if (e.OldValue != null) { Graphic g = e.OldValue as Graphic; g.UnSelect(); g.SetZIndex(0); } if (e.NewValue != null) { Graphic g = e.NewValue as Graphic; g.Select(); g.SetZIndex(1); //Relationship query RelationshipParameter relationshipParameters = new RelationshipParameter() { ObjectIds = new int[] {Convert.ToInt32(g.Attributes[SelectedWellsTreeView.Tag as string])}, OutFields = new string[] { "OBJECTID, API_NUMBER, ELEVATION, FORMATION, TOP" }, RelationshipId = 3, OutSpatialReference = MyMap.SpatialReference }; queryTask.ExecuteRelationshipQueryAsync(relationshipParameters); } }
void ISoapTransactionLinkExecutor.ExecuteTransaction(Guid sessionId, TransactionalMappingToolServiceClient serviceProxy) { TransactionStatus = ServerStatus.SendingTransaction; SessionId = sessionId; ServiceProxy = serviceProxy; Dictionary <Service.DT, Service.MP> nodeConnections = new Dictionary <Service.DT, Service.MP>(); foreach (KeyValuePair <Service.DT, SoapTransactionLinkParameter> keyValuePair in TransactionLinkConnections) { Service.DT descriptorType = keyValuePair.Key; Service.MP parameter = keyValuePair.Value.GetParameterValue(sessionId); nodeConnections[descriptorType] = parameter; } /// TODO: This may need to be changed so that this update transaction link is called if the NodeType on the INode object is assigned. Need to consider what is the best method. Relationship.RelationshipType = RelationshipType; foreach (KeyValuePair <ConnectionType, INode> connectionPairs in ProxyNodeConnections) { Relationship.Nodes.UpdateConnection(connectionPairs.Key, connectionPairs.Value); } ServiceProxy.RUCompleted += OnUpdateRelationshipCompleted; ServiceProxy.RUAsync(CallingUrl.Url, sessionId, DomainParameter.GetParameterValue(SessionId), RelationshipParameter.GetParameterValue(SessionId), nodeConnections, MapManager.RelationshipTypes.ConvertProxyToService(RelationshipType), this); }
} // countRelatedRecords /// <summary> /// ask related records from server for each relatioin, one relation at a time /// </summary> /// <param name="vfl"></param> /// <param name="feature"></param> private void askServerForRelatedRecs(mwb02.AddIns.VLayer vfl, ESRI.ArcGIS.Client.Graphic feature) { var fl = vfl.lyr as FeatureLayer; var rels = fl.LayerInfo.Relationships; // Get the name of the ObjectID field. var oidFieldname = vfl.getOIDFieldnameOrAlias(); // get key value int objIdValue = vfl.getOID(feature); log(string.Format("askServerForRelatedRecs, ready for ask, {0}/{1}", vfl.lyrUrl, objIdValue)); //for each relation if (vfl.relations == null) { vfl.initRelations(); } foreach (var rel in rels) { var relinfo = vfl.getRelation(rel); if (relinfo == null) { throw new Exception(string.Format("askServerForRelatedRecs, stored relinfo is null, make it; {0}/{1}, rel {2}", vfl.lyrUrl, objIdValue, rel.Name)); } log(string.Format("askServerForRelatedRecs, have relinfo {0}/{1}, rel {2}", vfl.lyrUrl, objIdValue, relinfo.name)); if (relinfo.linkedRecords == null) { log(string.Format("askServerForRelatedRecs, create linkedRecords dict {0}/{1}, rel {2}", vfl.lyrUrl, objIdValue, relinfo.name)); relinfo.linkedRecords = new Dictionary <int, IEnumerable <Graphic> >(); } IEnumerable <Graphic> recs; if (relinfo.linkedRecords.TryGetValue(objIdValue, out recs)) { log(string.Format("askServerForRelatedRecs, have relrecs for feature already, skip; {0}/{1}, rel {2}, count {3}", vfl.lyrUrl, objIdValue, relinfo.name, recs == null ? 0 : recs.Count())); continue; // goto next relation } log(string.Format("askServerForRelatedRecs, haven't relrecs for feature, get it! {0}/{1}, rel {2}", vfl.lyrUrl, objIdValue, relinfo.name)); // get data from server. then store it var qt = new QueryTask(); // callbacks qt.Failed += (sender, eventargs) => { this.isBusy = false; log(string.Format("askServerForRelatedRecs, QueryTask.Failed! {0}/{1}, rel {2}", vfl.lyrUrl, objIdValue, relinfo.name)); relinfo.linkedRecords.Add(objIdValue, null); if (CanExecuteChanged != null) { CanExecuteChanged(this, EventArgs.Empty); } }; // qt.failed qt.ExecuteRelationshipQueryCompleted += (sender, eventargs) => { this.isBusy = false; log(string.Format("askServerForRelatedRecs, QueryTask.Completed, {0}/{1}, rel {2}", vfl.lyrUrl, objIdValue, relinfo.name)); var qres = eventargs.Result; recs = null; foreach (var records in qres.RelatedRecordsGroup) { var graphics = records.Value; if (recs == null) { recs = graphics; } else { recs = recs.Concat(graphics); } } log(string.Format("askServerForRelatedRecs, QueryTask.Completed, {0}/{1}, rel {2}, recs {3}", vfl.lyrUrl, objIdValue, relinfo.name, recs == null ? 0 : recs.Count())); // store data, repeat for next relation relinfo.linkedRecords.Add(objIdValue, recs); if (CanExecuteChanged != null) { CanExecuteChanged(this, EventArgs.Empty); } }; // qt.ExecuteRelationshipQueryCompleted // Input parameters for QueryTask if (!qt.IsBusy) { RelationshipParameter relationshipParameters = new RelationshipParameter() { ObjectIds = new int[] { objIdValue }, OutFields = new string[] { "*" }, // Return all fields ReturnGeometry = true, // Return the geometry so that features can be displayed on the map if applicable RelationshipId = relinfo.id, // Obtain the desired RelationshipID from the Service Details page. Here it takes the first relationship it finds if there is more than one. OutSpatialReference = MapApplication.Current.Map.SpatialReference }; qt.Url = fl.Url; this.isBusy = true; log(string.Format("askServerForRelatedRecs, QueryTask.Execute, {0}/{1}, rel {2}", vfl.lyrUrl, objIdValue, relinfo.name)); qt.ExecuteRelationshipQueryAsync(relationshipParameters); return; } } // for each relation } // private void askServerForRelatedRecs(mwb02.AddIns.VLayer vfl, ESRI.ArcGIS.Client.Graphic feature)
} // public void Execute(object parameter) /// <summary> /// Executes the relationship query against the layer. /// </summary> /// <param name="parameter">The OnClickPopupInfo from the layer.</param> public void doExecute(object parameter) { // The plan is: // Get the featurelayer and clicked feature from the pop-up. // The PopupItem property of OnClickPopupInfo provides information about the item currently shown in the pop-up. // Then get feature ID value and put it into ExecuteRelationshipQueryAsync task. // Then get related records ID's and create FeatureLayer from related table/feature class, filtered by that ID's. // Then show grid for that layer. popupInfo = parameter as OnClickPopupInfo; inputFeature = popupInfo.PopupItem.Graphic; var lyr = new mwb02.AddIns.VLayer(popupInfo.PopupItem.Layer); // print layer info to console log(string.Format("Execute, layer type '{0}', popupInd '{1}', popupDescr '{2}', lyrID '{3}', lyrName '{4}', title '{5}'", popupInfo.PopupItem.Layer.GetType(), // 'ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer' popupInfo.SelectedIndex, popupInfo.SelectionDescription, popupInfo.PopupItem.LayerId, popupInfo.PopupItem.LayerName, popupInfo.PopupItem.Title)); // SelectedIndex - index 0-n for found features. // SelectionDescription - note about current record for user, '2 from 2' for example. // lyrID '0' - sublayer id for ArcGISDynamicMapServiceLayer // lyrName 'Аэродромы и вертодромы' - sublayer name for ArcGISDynamicMapServiceLayer log(string.Format("Execute, lyrType '{0}', lyrUrl '{1}'", lyr.lyrType, lyr.lyrUrl)); // layer type 'ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer', popupInd '0', popupDescr '1 из 2', lyrID '0', lyrName 'Wells', title 'UNKNOWN' // lyrType 'ArcGISDynamicMapServiceLayer', lyrUrl 'http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer' log(string.Format("Execute, inputFeature.Attributes.Count '{0}'", inputFeature.Attributes.Count)); // we need FeatureLayer if (lyr.lyrType == "FeatureLayer") { relatesLayer = lyr; // The layer to get related records for. This is used to get the RelationshipID and Query url. } else if (lyr.lyrType == "ArcGISDynamicMapServiceLayer") { var rLyr = getSubLayer(lyr, popupInfo.PopupItem.LayerId) as FeatureLayer; if (relatesLayer != null && relatesLayer.lyrUrl == rLyr.Url) { ; // we here after relatesLayer.Initialized } else // init new FeatureLayer { relatesLayer = new mwb02.AddIns.VLayer(rLyr); relatesLayer.lyr.Initialized += (a, b) => { if (relatesLayer.lyr.InitializationFailure == null) { var info = (relatesLayer.lyr as FeatureLayer).LayerInfo; log(string.Format("Execute, relatesLayer.InitializationFailure == null, info '{0}'", info)); Execute(parameter); } }; // callback relatesLayer.lyr.Initialize(); log(string.Format("Execute, relatesLayer.Initialize called, wait...")); return; } // init new FeatureLayer } // if(lyr.lyrType == "ArcGISDynamicMapServiceLayer") else { throw new Exception("Тип слоя должен быть или FeatureLayer или ArcGISDynamicMapServiceLayer"); } // we have inited FeatureLayer now if (relatesLayer.getFL().LayerInfo == null) { throw new Exception(string.Format("Execute, relatesLayer.LayerInfo == null")); } var clickedLayer = relatesLayer; var storedFL = this.flList[clickedLayer.lyrUrl]; // check FeatureLayer info log(string.Format("Execute, relatesLayer lyrType '{0}', lyrUrl '{1}'", clickedLayer.lyrType, clickedLayer.lyrUrl)); // get relationship id var rels = relatesLayer.getFL().LayerInfo.Relationships; log(string.Format("Execute, getrelid.1, rels.count '{0}'", rels.Count())); if (rels.Count() <= 0) { log(string.Format("Execute, relationships.count <= 0")); throw new Exception(string.Format("У выбранного слоя нет связей с другими таблицами")); } else if (rels.Count() > 1) { log(string.Format("Execute, relationships.count > 1")); if (relationsListForm.relationsList.Count > 0) { // continue after user input relationInfo = relationsListForm.listBox1.SelectedItem as mwb02.AddIns.VRelationInfo; relationsListForm.relationsList.Clear(); } // user select relID already else { // new query relationInfo = null; foreach (var r in rels) { var ri = storedFL.getRelation(r); if (ri == null) { ri = new mwb02.AddIns.VRelationInfo(r); } ri.oid = clickedLayer.getOID(inputFeature); if (ri.oid == -1) { log(string.Format("featurelayer.getOID returns invalid OID; {0}", clickedLayer.lyrUrl)); continue; } relationsListForm.relationsList.Add(ri); } relationsListForm.listBox1.SelectedItem = relationsListForm.relationsList.First(); MapApplication.Current.ShowWindow("Relations", relationsListForm, false, // ismodal (sender, canceleventargs) => { log("relationsListForm onhidINGhandler"); }, // onhidinghandler (sender, eventargs) => { log("relationsListForm onhidEhandler"); //if(relationsListForm.listBox1.SelectedItem != null) Execute(parameter); }, // onhidehandler WindowType.Floating ); return; // wait for user input } // new query } // rels.count > 1 else // rels.count == 1 { log(string.Format("Execute, relationships.count = 1")); relationInfo = new mwb02.AddIns.VRelationInfo(rels.First()); } // ok, we get relation info now if (relationInfo == null) { throw new Exception("Не указана связанная таблица"); } log(string.Format("Execute, getrelid.2, relationshipID '{0}', rels.count '{1}'", relationInfo.id, rels.Count())); // Get the name of the ObjectID field. objectID = clickedLayer.getOIDFieldnameOrAlias(); // get key value int objIdValue = clickedLayer.getOID(inputFeature); if (objIdValue == -1) { // Attributes key = 'Object ID' but ObjectIdField = 'OBJECTID' var ks = string.Join(", ", inputFeature.Attributes.Keys); // inputFeature.AttributesKeys='Object ID, Shape, Field KID, var vs = string.Join(", ", inputFeature.Attributes.Values); log(string.Format("Execute, inputFeature.AttributesKeys='{0}', values='{1}'", ks, vs)); throw new Exception(string.Format("Поле OBJECTID не содержит целого числа")); } log(string.Format("Execute, objIdValue.int='{0}'", objIdValue)); // Input parameters for QueryTask RelationshipParameter relationshipParameters = new RelationshipParameter() { ObjectIds = new int[] { objIdValue }, OutFields = new string[] { "*" }, // Return all fields ReturnGeometry = true, // Return the geometry so that features can be displayed on the map if applicable RelationshipId = relationInfo.id, // Obtain the desired RelationshipID from the Service Details page. Here it takes the first relationship it finds if there is more than one. OutSpatialReference = MapApplication.Current.Map.SpatialReference }; log(string.Format("Execute, relationshipParameters set")); // Specify the Feature Service url for the QueryTask. if (queryTask.IsBusy) { throw new Exception("Выполняется предыдущий запрос, попробуйте позже"); } queryTask.Url = relatesLayer.lyrUrl; // Execute the Query Task with specified parameters queryTask.ExecuteRelationshipQueryAsync(relationshipParameters); // Find the attribute grid in the Pop-up and insert the BusyIndicator attributeGrid = Utils.FindChildOfType <Grid>(popupInfo.AttributeContainer, 3); indicator = new BusyIndicator(); if (attributeGrid != null) { // Add the Busy Indicator attributeGrid.Children.Add(indicator); indicator.IsBusy = true; } log(string.Format("Execute, completed, wait for QueryTask_ExecuteRelationshipQueryCompleted")); } // public void doExecute(object parameter)
void ISoapTransactionLinkExecutor.ExecuteBulkTransactions(Guid sessionId, TransactionalMappingToolServiceClient serviceProxy, ref Service.OPS bulkOperations) { TransactionStatus = ServerStatus.SendingTransaction; SessionId = sessionId; ServiceProxy = serviceProxy; Dictionary <Service.DT, Service.MP> nodeConnections = new Dictionary <Service.DT, Service.MP>(); foreach (KeyValuePair <Service.DT, SoapTransactionLinkParameter> keyValuePair in TransactionLinkConnections) { Service.DT descriptorType = keyValuePair.Key; Service.MP parameter = keyValuePair.Value.GetParameterValue(sessionId); nodeConnections[descriptorType] = parameter; } /// TODO: This may need to be changed so that this update transaction link is called if the NodeType on the INode object is assigned. Need to consider what is the best method. Relationship.RelationshipType = RelationshipType; foreach (KeyValuePair <ConnectionType, INode> connectionPairs in ProxyNodeConnections) { Relationship.Nodes.UpdateConnection(connectionPairs.Key, connectionPairs.Value); } ResponseParameter = new Service.MP(); ResponseParameter.I = Guid.NewGuid(); ResponseParameter.S = sessionId; ResponseParameter.V = Guid.Empty; ResponseParameter.D = true; ResponseParameter.T = Service.MapParameterType.Node; Service.BRU relationshipBulkOperation = new Service.BRU(); relationshipBulkOperation.I = TransactionLinkId; relationshipBulkOperation.D = DomainParameter.GetParameterValue(sessionId); relationshipBulkOperation.R = RelationshipParameter.GetParameterValue(SessionId); relationshipBulkOperation.N = nodeConnections; relationshipBulkOperation.T = MapManager.RelationshipTypes.ConvertProxyToService(RelationshipType); relationshipBulkOperation.RI = ResponseParameter.I; bulkOperations.O.Add(relationshipBulkOperation); ISoapTransactionLinkExecutor executor = _firstLink as ISoapTransactionLinkExecutor; if (executor == null) { DebugLogger.Instance.LogMsg("Exception: This is not a supported type of link. This link does not implement ISoapTransactionLinkExecutor."); throw new NotSupportedException("This is not a supported type of link. This link does not implement ISoapTransactionLinkExecutor."); } if (bulkOperations.O.Count < 200) { TransactionStatus = ServerStatus.TransactionReceived; if (!_onCompletedBound) { executor.TransactionFailed += OnTransactionFailed; executor.TransactionCompleted += OnTransactionCompleted; _onCompletedBound = true; } TransactionStatus = ServerStatus.TransactionExecuting; DebugLogger.Instance.LogMsg("Executing update relationship transaction. ClientId - '{0}';", Relationship.ClientId); executor.ExecuteBulkTransactions(SessionId, ServiceProxy, ref bulkOperations); } else { ServiceProxy.BOCCompleted += new EventHandler <BOCCompletedEventArgs>(OnSubmitBulkOperationCompleted); ServiceProxy.SubmitBulkOperationsAsync(CallingUrl.Url, SessionId, bulkOperations, this); } }
// Query for well tops related to wells with the passed-in object ID private async Task<RelationshipResult> doRelationshipQuery(int oid) { QueryTask queryTask = new QueryTask(new Uri("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer/0")); // Initialize relationship parameters RelationshipParameter parameters = new RelationshipParameter(new long[] { oid }, 3) { OutSpatialReference = m_mapView.SpatialReference, OutFields = new OutFields(new string[] { "OBJECTID, API_NUMBER, FORMATION, TOP" }) }; try { // Do the relationship query and return the result return await queryTask.ExecuteRelationshipQueryAsync(parameters); } catch { return null; } }
} // public void Execute(object parameter) /// <summary> /// Executes the relationship query against the layer. /// </summary> /// <param name="parameter">The OnClickPopupInfo from the layer.</param> public void doExecute(object parameter) { // The plan is: // Get the featurelayer and clicked feature from the pop-up. // The PopupItem property of OnClickPopupInfo provides information // about the item currently shown in the pop-up. // Then get feature ID value and put it into ExecuteRelationshipQueryAsync task. // Then get related records ID's and create FeatureLayer from // related table/feature class, filtered by that ID's. // Then show grid for that layer. popupInfo = parameter as OnClickPopupInfo; inputFeature = popupInfo.PopupItem.Graphic; var lyr = new VUtils.ArcGIS.SLViewer.VLayer(popupInfo.PopupItem.Layer); // print layer info to console log(string.Format( "Execute, layer type '{0}', popupInd '{1}', popupDescr '{2}', lyrID '{3}', lyrName '{4}', title '{5}'", popupInfo.PopupItem.Layer.GetType(), popupInfo.SelectedIndex, popupInfo.SelectionDescription, popupInfo.PopupItem.LayerId, popupInfo.PopupItem.LayerName, popupInfo.PopupItem.Title)); log(string.Format("Execute, lyrType '{0}', lyrUrl '{1}'", lyr.lyrType, lyr.lyrUrl)); log(string.Format("Execute, inputFeature.Attributes.Count '{0}'", inputFeature.Attributes.Count)); // we need FeatureLayer if (lyr.lyrType == "FeatureLayer") { // The layer to get related records for. // This is used to get the RelationshipID and Query url. relatesLayer = lyr.lyr as FeatureLayer; } else if (lyr.lyrType == "ArcGISDynamicMapServiceLayer") { var rLyr = getSubLayer(lyr, popupInfo.PopupItem.LayerId) as FeatureLayer; if (relatesLayer != null && relatesLayer.Url == rLyr.Url) { // we're here after relatesLayer.Initialized ; } else { // init new FeatureLayer relatesLayer = rLyr; relatesLayer.Initialized += (a, b) => { if (relatesLayer.InitializationFailure == null) { var info = relatesLayer.LayerInfo; log(string.Format( "Execute, relatesLayer.InitializationFailure == null, info '{0}'", info)); Execute(parameter); } }; // callback relatesLayer.Initialize(); log(string.Format("Execute, relatesLayer.Initialize called, wait...")); return; } // init new FeatureLayer } // if(lyr.lyrType == "ArcGISDynamicMapServiceLayer") else { throw new Exception("Layer type must be FeatureLayer or ArcGISDynamicMapServiceLayer"); } // we have inited FeatureLayer now if (relatesLayer.LayerInfo == null) { throw new Exception(string.Format("Execute, relatesLayer.LayerInfo == null")); } var clickedLayer = new VUtils.ArcGIS.SLViewer.VLayer(relatesLayer); // check FeatureLayer info log(string.Format( "Execute, relatesLayer lyrType '{0}', lyrUrl '{1}'", clickedLayer.lyrType, clickedLayer.lyrUrl)); // get relationship id var rels = relatesLayer.LayerInfo.Relationships; if (rels.Count() <= 0) { log(string.Format("Execute, relationships.count <= 0")); throw new Exception(string.Format("Layer have not relations")); } else if (rels.Count() > 1) { log(string.Format("Execute, relationships.count > 1")); if (relationsListForm.listBox1.Items.Count > 0) { // continue after user input // user selected relID already relationInfo = new VUtils.ArcGIS.SLViewer.VRelationInfo( relationsListForm.listBox1.SelectedItem as string); relationsListForm.listBox1.Items.Clear(); } else { // new query foreach (var r in rels) { var ri = new VUtils.ArcGIS.SLViewer.VRelationInfo(r); relationsListForm.listBox1.Items.Add(ri.descr); } relationsListForm.listBox1.SelectedItem = relationsListForm.listBox1.Items.First(); MapApplication.Current.ShowWindow("Relations", relationsListForm, false, // ismodal (sender, canceleventargs) => { log("relationsListForm onhidINGhandler"); }, // onhidinghandler (sender, eventargs) => { log("relationsListForm onhidEhandler"); if (relationsListForm.listBox1.SelectedItem != null) { Execute(parameter); } }, // onhidehandler WindowType.Floating ); return; // wait for user input } // new query } // rels.count > 1 else // rels.count == 1 { log(string.Format("Execute, relationships.count = 1")); relationInfo = new VUtils.ArcGIS.SLViewer.VRelationInfo(rels.First()); } // ok, we get relation info now log(string.Format( "Execute, getrelid, relationshipID '{0}', rels.count '{1}'", relationInfo.id, rels.Count())); // Get the name of the ObjectID field. objectID = relatesLayer.LayerInfo.ObjectIdField; string objectIDAlias = clickedLayer.getFieldAlias(objectID); log(string.Format("Execute, objectID '{0}', alias '{1}'", objectID, objectIDAlias)); if (objectIDAlias != "") { objectID = objectIDAlias; // because of bug? in Graphic.Attributes[fieldname] } // get key value Object v = null; v = inputFeature.Attributes[objectID]; log(string.Format("Execute, objIdValue.str='{0}'", v)); int objIdValue = -1; try { objIdValue = Int32.Parse(string.Format("{0}", v)); } catch (Exception ex) { // fieldname = 'OBJECTID' but alias = 'Object ID' var ks = string.Join(", ", inputFeature.Attributes.Keys); var vs = string.Join(", ", inputFeature.Attributes.Values); log(string.Format("Execute, inputFeature.AttributesKeys='{0}', values='{1}'", ks, vs)); throw new Exception(string.Format("OBJECTID is not an integer")); } log(string.Format("Execute, objIdValue.int='{0}'", objIdValue)); // Input parameters for QueryTask RelationshipParameter relationshipParameters = new RelationshipParameter() { ObjectIds = new int[] { objIdValue }, OutFields = new string[] { "*" }, // Return all fields ReturnGeometry = true, // Return the geometry // so that features can be displayed on the map if applicable RelationshipId = relationInfo.id, // Obtain the desired RelationshipID // from the Service Details page. Here it takes the first relationship // it finds if there is more than one. OutSpatialReference = MapApplication.Current.Map.SpatialReference }; // Specify the Feature Service url for the QueryTask. queryTask.Url = relatesLayer.Url; // Execute the Query Task with specified parameters queryTask.ExecuteRelationshipQueryAsync(relationshipParameters); // Find the attribute grid in the Pop-up and insert the BusyIndicator attributeGrid = Utils.FindChildOfType <Grid>(popupInfo.AttributeContainer, 3); indicator = new BusyIndicator(); if (attributeGrid != null) { // Add the Busy Indicator attributeGrid.Children.Add(indicator); indicator.IsBusy = true; } log(string.Format("Execute, completed, wait for QueryTask_ExecuteRelationshipQueryCompleted")); } // public void doExecute(object parameter)
/// <summary> /// Performs the relationship query. /// </summary> /// <remarks>Called from the doQuery method.</remarks> private void QueryRelationship() { // Set the popupWindow and subscribe to changes on the popupWindow.IsOpen property popupWindow = PopupInfo.Container as InfoWindow; // Set the attribute grid container and subscripbe to changes on the Visibility property attributeGridContainer = MapApplication.Current.FindObjectInLayout(CONTAINER_NAME) as FrameworkElement; ExtensionMethods.Properties.NotifyOnDependencyPropertyChanged("Visibility", attributeGridContainer, OnDataGridVisibilityChanged); // Listen for selection of a different layer in the map contents. MapApplication.Current.SelectedLayerChanged += Current_SelectedLayerChanged; // Listen for a change in the selected index of the PopupInfo (indicating the popup item has changed). PopupInfo.PropertyChanged += PopupInfo_PropertyChanged; // Locate the grid inside the popup window and remove the RelationshipView. This was initially inserted if // multiple relationships for a feature were detected. Grid infoWindowGrid = Utils.FindChildOfType<Grid>(popupWindow, 3); infoWindowGrid.Children.Remove(RelationshipView); // Set the relationshipID for the QueryTask. int relationshipID = SelectedRelationship.Id; // Get the feature and layer info from the pop-up. The PopupItem property of OnClickPopupInfo // provides information about the item currently shown in the pop-up. Graphic inputFeature = PopupInfo.PopupItem.Graphic; relatesLayer = PopupInfo.PopupItem.Layer as FeatureLayer; // The layer to get related records for. This is used to get the RelationshipID and Query url. // Get the name of the ObjectID field. objectIDField = relatesLayer.LayerInfo.ObjectIdField; // Input parameters for QueryTask RelationshipParameter relationshipParameters = new RelationshipParameter() { ObjectIds = new int[] { (int)inputFeature.Attributes[objectIDField] }, OutFields = new string[] { "*" }, // Return all fields ReturnGeometry = true, // Return the geometry so that features can be displayed on the map if applicable RelationshipId = relationshipID, // Obtain the desired RelationshipID from the Service Details page. Here it takes the first relationship it finds if there is more than one. OutSpatialReference = map.SpatialReference }; // Specify the Feature Service url for the QueryTask. queryTask.Url = relatesLayer.Url; queryTask.ProxyURL = relatesLayer.ProxyUrl; // Events for the successful completion of the RelationshipQuery and for if the Query fails queryTask.ExecuteRelationshipQueryCompleted += QueryTask_ExecuteRelationshipQueryCompleted; queryTask.Failed += QueryTask_Failed; // Execute the Query Task with specified parameters queryTask.ExecuteRelationshipQueryAsync(relationshipParameters); // Create the BusyIndicator and insert into the grid of the popup window. indicator = new BusyIndicator(); indicator.BusyContent = Strings.RetrievingRecords; if (infoWindowGrid != null) { infoWindowGrid.Children.Add(indicator); indicator.IsBusy = true; } }
void ISoapTransactionLinkExecutor.ExecuteTransaction(Guid sessionId, Service.TransactionalMappingToolServiceClient serviceProxy) { SessionId = sessionId; ServiceProxy = serviceProxy; ServiceProxy.RDCompleted += OnDeleteRelationshipCompleted; ServiceProxy.RDAsync(System.Windows.Browser.HtmlPage.Document.DocumentUri.ToString(), SessionId, DomainParameter.GetParameterValue(SessionId), RelationshipParameter.GetParameterValue(SessionId), this); }