/// <summary> /// Creates an instance of the class using the specified <see cref="IUID" />. /// </summary> /// <typeparam name="TValue">The type of the value.</typeparam> /// <param name="source">The UID.</param> /// <returns> /// The class for the GUID; otherwise null. /// </returns> public static TValue Create <TValue>(this IUID source) where TValue : class { if (source == null) { return(default(TValue)); } // When the type could be located and matches the given type. Type t = Type.GetTypeFromCLSID(new Guid(source.Value.ToString())); if (t == null) { return(default(TValue)); } object o = Activator.CreateInstance(t); return(o as TValue); }
/// <summary> /// Gets the name of the component. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="uid">The uid.</param> /// <returns> /// Returns a <see cref="string" /> representing the name of the component. /// </returns> /// <remarks> /// Defaults to the name specified on the <see cref="IMMExtObject" /> /// interface. /// </remarks> private string GetComponentName <T>(IUID uid) { object component; try { component = uid.Create <T>(); } catch (Exception) { return("UNREGISTERED PROGRAM"); } if (component is IMMSpecialAUStrategy) { return(((IMMSpecialAUStrategy)component).Name); } if (component is IMMSpecialAUStrategyEx) { return(((IMMSpecialAUStrategyEx)component).Name); } if (component is IMMAbandonAUStrategy) { return(((IMMAbandonAUStrategy)component).Name); } if (component is IMMAttrAUStrategy) { return(((IMMAttrAUStrategy)component).Name); } if (component is IMMRelationshipAUStrategy) { return(((IMMRelationshipAUStrategy)component).Name); } if (component is IMMExtObject) { return(((IMMExtObject)component).Name); } return("UNREGISTERED PROGRAM"); }
/// <summary> /// 创建注记层 /// </summary> /// <param name="strFeaClsName">注记层名称</param> /// <param name="destDataset">待创建的注记层所在的featuredataset</param> /// <param name="ipInputFields">注记层字段</param> public static IFeatureClass CreateAnnotation(IFeatureClass pInputCls, IFeatureDataset destDataset, IFields ipInputFields) { try { //要素类标识信息 IObjectClassDescription ipObjectClassDesc = new AnnotationFeatureClassDescription(); IFeatureClassDescription ipFeatClassDesc = (IFeatureClassDescription)ipObjectClassDesc; IAnnoClass pAnnoClass = pInputCls.Extension as IAnnoClass; double scale = pAnnoClass.ReferenceScale; IUID ipCLSID = ipObjectClassDesc.InstanceCLSID; ipCLSID.Value = "esriCore.AnnotationFeature"; IUID ipExtCLSID = ipObjectClassDesc.ClassExtensionCLSID; ipExtCLSID.Value = "esriCore.AnnotationFeatureClassExtension"; //IField ipField; IFields ipFields = ipObjectClassDesc.RequiredFields; IFieldsEdit ipFieldsEdit = (IFieldsEdit)ipFields; int numFields = ipInputFields.FieldCount; esriFieldType type; for (int i = 0; i < numFields; i++) { IField ipField = ipInputFields.get_Field(i); type = ipField.Type; if (type != esriFieldType.esriFieldTypeOID && type != esriFieldType.esriFieldTypeGeometry) { string fldName = ipField.Name; int fldIndex = ipFields.FindField(fldName); if (fldIndex == -1) { ipFieldsEdit.AddField(ipField); } } } //工作空间 IWorkspace ipWorkspace = destDataset.Workspace; IFeatureWorkspaceAnno ipFeatureWorkspaceAnno = (IFeatureWorkspaceAnno)ipWorkspace; //显示比例 IGraphicsLayerScale ipGraphicsLayerScale = new GraphicsLayerScaleClass(); ipGraphicsLayerScale.ReferenceScale = scale; ipGraphicsLayerScale.Units = pAnnoClass.ReferenceScaleUnits; //符号信息 //' set up symbol collection ISymbolCollection pSymbolColl = new SymbolCollectionClass(); ITextSymbol myTxtSym = new TextSymbolClass(); //Set the font for myTxtSym stdole.IFontDisp myFont = new stdole.StdFontClass() as stdole.IFontDisp; IFont pFt = (IFont)myFont; pFt.Name = "Courier New"; myTxtSym.Font = myFont; // Set the Color for myTxtSym to be Dark Red IRgbColor myColor = new RgbColorClass(); myColor.Red = 150; myColor.Green = 0; myColor.Blue = 0; myTxtSym.Color = myColor; // Set other properties for myTxtSym myTxtSym.Angle = 0; myTxtSym.RightToLeft = false; myTxtSym.VerticalAlignment = esriTextVerticalAlignment.esriTVABaseline; myTxtSym.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull; myTxtSym.Size = 9; ISymbol pSymbol = (ISymbol)myTxtSym; pSymbolColl.set_Symbol(0, pSymbol); //set up the annotation labeling properties including the expression IAnnotateLayerProperties pAnnoProps = new LabelEngineLayerPropertiesClass(); pAnnoProps.FeatureLinked = true; pAnnoProps.AddUnplacedToGraphicsContainer = false; pAnnoProps.CreateUnplacedElements = true; pAnnoProps.DisplayAnnotation = true; pAnnoProps.UseOutput = true; ILabelEngineLayerProperties pLELayerProps = (ILabelEngineLayerProperties)pAnnoProps; IAnnotationExpressionEngine aAnnoVBScriptEngine = new AnnotationVBScriptEngineClass(); pLELayerProps.ExpressionParser = aAnnoVBScriptEngine; pLELayerProps.Expression = "[DESCRIPTION]"; pLELayerProps.IsExpressionSimple = true; pLELayerProps.Offset = 0; pLELayerProps.SymbolID = 0; pLELayerProps.Symbol = myTxtSym; IAnnotateLayerTransformationProperties pATP = (IAnnotateLayerTransformationProperties)pAnnoProps; double dRefScale = ipGraphicsLayerScale.ReferenceScale; pATP.ReferenceScale = dRefScale; pATP.Units = esriUnits.esriMeters; pATP.ScaleRatio = 1; IAnnotateLayerPropertiesCollection pAnnoPropsColl = new AnnotateLayerPropertiesCollectionClass(); pAnnoPropsColl.Add(pAnnoProps); //' use the AnnotationFeatureClassDescription co - class to get the list of required fields and the default name of the shape field IObjectClassDescription pOCDesc = new AnnotationFeatureClassDescriptionClass(); IFeatureClassDescription pFDesc = (IFeatureClassDescription)pOCDesc; IFields pReqFields = pOCDesc.RequiredFields; IUID pInstCLSID = pOCDesc.InstanceCLSID; IUID pExtCLSID = pOCDesc.ClassExtensionCLSID; string bsShapeFieldName = pFDesc.ShapeFieldName; IDataset pDs = (IDataset)pInputCls; //创建 string bstName = ipFeatClassDesc.ShapeFieldName; IFeatureClass pOutFcls = ipFeatureWorkspaceAnno.CreateAnnotationClass(pDs.Name, ipFields, pOCDesc.InstanceCLSID, pOCDesc.ClassExtensionCLSID, pInputCls.ShapeFieldName, "", destDataset, null, pAnnoPropsColl, ipGraphicsLayerScale, pSymbolColl, true); return(pOutFcls); } catch (Exception exp) { Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString()); return(null); } return(null); }
/// <summary> /// Indicates if the value is not equal to any of the given args. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="value"></param> /// <param name="args">An array of values that the value will be checked against.</param> /// <returns>true if the value is not equal to any of the given args.</returns> public static bool IsNotIn(this IUID value, params IUID[] args) => args.All(arg => !arg.Id.Equals(value.Id));
private void MenuItem_Activate(object sender, EventArgs e) { try { // // Error List Context Menu // if (sender == this.menuButtonItemScroll) { // Can only zoom to one item if (this.listViewErrorList.SelectedItems.Count != 1) { return; } // Get EsriTable containing the error ListViewItemError item = (ListViewItemError)this.listViewErrorList.SelectedItems[0]; EsriTable table = null; if (item.Error is ErrorTable) { ErrorTable errorTable = (ErrorTable)item.Error; table = errorTable.Table; } else if (item.Error is ErrorTableRow) { ErrorTableRow errorTableRow = (ErrorTableRow)item.Error; EsriTableRow esriTableRow = (EsriTableRow)errorTableRow.TableRow; table = (EsriTable)esriTableRow.Table; } else if (item.Error is ErrorObject) { ErrorObject errorObject = (ErrorObject)item.Error; table = errorObject.Table; } if (table == null) { return; } // Get Containing Model EsriModel model = (EsriModel)table.Container; // Scroll to Table model.ScrollToElement(table); // Flash Table table.Flash(); } else if (sender == this.menuButtonItemSelect) { // Can only zoom to one item if (this.listViewErrorList.SelectedItems.Count == 0) { return; } foreach (ListViewItemError item in this.listViewErrorList.SelectedItems) { EsriModel model = null; if (item.Error is ErrorTable) { ErrorTable errorTable = (ErrorTable)item.Error; EsriTable table = errorTable.Table; model = (EsriModel)table.Container; } else if (item.Error is ErrorTableRow) { ErrorTableRow errorTableRow = (ErrorTableRow)item.Error; EsriTableRow esriTableRow = (EsriTableRow)errorTableRow.TableRow; EsriTable table = (EsriTable)esriTableRow.Table; model = (EsriModel)table.Container; } else if (item.Error is ErrorObject) { ErrorObject errorObject = (ErrorObject)item.Error; EsriTable table = errorObject.Table; model = (EsriModel)table.Container; } if (model == null) { continue; } // Clear Model Selection model.SelectElements(false); } // foreach (ListViewItemError item in this.listViewErrorList.SelectedItems) { // Get Table EsriTable table = null; if (item.Error is ErrorTable) { ErrorTable errorTable = (ErrorTable)item.Error; table = errorTable.Table; } else if (item.Error is ErrorTableRow) { ErrorTableRow errorTableRow = (ErrorTableRow)item.Error; EsriTableRow esriTableRow = (EsriTableRow)errorTableRow.TableRow; table = (EsriTable)esriTableRow.Table; } else if (item.Error is ErrorObject) { ErrorObject errorObject = (ErrorObject)item.Error; table = errorObject.Table; } if (table == null) { continue; } // Flash Table table.Selected = true; } } else if (sender == this.menuButtonItemFlashError) { // Can only zoom to one item if (this.listViewErrorList.SelectedItems.Count == 0) { return; } // foreach (ListViewItemError item in this.listViewErrorList.SelectedItems) { // Get Table EsriTable table = null; if (item.Error is ErrorTable) { ErrorTable errorTable = (ErrorTable)item.Error; table = errorTable.Table; } else if (item.Error is ErrorTableRow) { ErrorTableRow errorTableRow = (ErrorTableRow)item.Error; EsriTableRow esriTableRow = (EsriTableRow)errorTableRow.TableRow; table = (EsriTable)esriTableRow.Table; } else if (item.Error is ErrorObject) { ErrorObject errorObject = (ErrorObject)item.Error; table = errorObject.Table; } if (table == null) { continue; } // Flash Table table.Flash(); } } else if (sender == this.menuButtonItemClearError) { // Remove Selected Items foreach (ListViewItemError item in this.listViewErrorList.SelectedItems) { if (this.m_errors.Contains(item.Error)) { this.m_errors.Remove(item.Error); } } // Refresh Error List this.RefreshErrorList(); } else if (sender == menuButtonItemClearAllErrors) { // Remove All Errors this.m_errors.Clear(); // Refresh Error List this.RefreshErrorList(); } // // Validator Dropdown Menu // else if (sender == this.menuButtonItemPGdb) { WorkspaceValidator.Default.Validator = new PersonalGeodatabaseValidator(); } else if (sender == this.menuButtonItemFGdb) { WorkspaceValidator.Default.Validator = new FileGeodatabaseValidator(); } else if (sender == this.menuButtonItemSelectGeodatabase) { // Create GxObjectFilter for GxDialog IGxObjectFilter gxObjectFilter = new GxFilterWorkspacesClass(); // Create GxDialog IGxDialog gxDialog = new GxDialogClass(); gxDialog.AllowMultiSelect = false; gxDialog.ButtonCaption = Resources.TEXT_SELECT; gxDialog.ObjectFilter = gxObjectFilter; gxDialog.RememberLocation = true; gxDialog.Title = Resources.TEXT_SELECT_EXISTING_GEODATABASE; // Declare Enumerator to hold selected objects IEnumGxObject enumGxObject = null; // Open Dialog if (!gxDialog.DoModalOpen(0, out enumGxObject)) { return; } if (enumGxObject == null) { return; } // Get Selected Object (if any) IGxObject gxObject = enumGxObject.Next(); if (gxObject == null) { return; } if (!gxObject.IsValid) { return; } // Get GxDatabase if (!(gxObject is IGxDatabase)) { return; } IGxDatabase gxDatabase = (IGxDatabase)gxObject; // Get Workspace IWorkspace workspace = gxDatabase.Workspace; if (workspace == null) { return; } // Get Workspace Factory IWorkspaceFactory workspaceFactory = workspace.WorkspaceFactory; if (workspaceFactory == null) { return; } // Get Workspace Factory ID IUID uid = workspaceFactory.GetClassID(); string guid = uid.Value.ToString().ToUpper(); switch (guid) { case EsriRegistry.GEODATABASE_PERSONAL: WorkspaceValidator.Default.Validator = new PersonalGeodatabaseValidator(workspace); break; case EsriRegistry.GEODATABASE_FILE: WorkspaceValidator.Default.Validator = new FileGeodatabaseValidator(workspace); break; case EsriRegistry.GEODATABASE_SDE: WorkspaceValidator.Default.Validator = new SdeValidator(workspace); break; default: break; } } else if ((sender is MenuButtonItem) && (((MenuButtonItem)sender).Parent == this.menuButtonItemSdeConnection)) { MenuButtonItem item = (MenuButtonItem)sender; if (item.Tag == null) { return; } WorkspaceValidator.Default.Validator = new SdeValidator(item.Tag.ToString()); } } catch (Exception ex) { ExceptionDialog.HandleException(ex); } }
/// <summary> /// Initializes a new instance of the <see cref="GPAutoValue{TValue}" /> class. /// </summary> /// <param name="uid">The uid.</param> public GPAutoValue(IUID uid) { this.UID = uid; this.Value = uid.Create <TValue>(); }
private static void ReadMsgValues(GdbObjectMsg gdbObjectMsg, GdbRow intoResult, ITable table) { if (gdbObjectMsg.Values.Count == 0) { return; } Assert.AreEqual(table.Fields.FieldCount, gdbObjectMsg.Values.Count, "GdbObject message values do not correspond to table schema"); for (var index = 0; index < gdbObjectMsg.Values.Count; index++) { AttributeValue attributeValue = gdbObjectMsg.Values[index]; switch (attributeValue.ValueCase) { case AttributeValue.ValueOneofCase.None: break; case AttributeValue.ValueOneofCase.DbNull: intoResult.set_Value(index, DBNull.Value); break; case AttributeValue.ValueOneofCase.ShortIntValue: intoResult.set_Value(index, attributeValue.ShortIntValue); break; case AttributeValue.ValueOneofCase.LongIntValue: intoResult.set_Value(index, attributeValue.LongIntValue); break; case AttributeValue.ValueOneofCase.FloatValue: intoResult.set_Value(index, attributeValue.FloatValue); break; case AttributeValue.ValueOneofCase.DoubleValue: intoResult.set_Value(index, attributeValue.DoubleValue); break; case AttributeValue.ValueOneofCase.StringValue: intoResult.set_Value(index, attributeValue.StringValue); break; case AttributeValue.ValueOneofCase.DateTimeTicksValue: intoResult.set_Value( index, new DateTime(attributeValue.DateTimeTicksValue)); break; case AttributeValue.ValueOneofCase.UuidValue: var guid = new Guid(attributeValue.UuidValue.Value.ToByteArray()); IUID uid = UIDUtils.CreateUID(guid); intoResult.set_Value(index, uid); break; case AttributeValue.ValueOneofCase.BlobValue: intoResult.set_Value(index, attributeValue.BlobValue); break; default: if (table.Fields.Field[index].Type == esriFieldType.esriFieldTypeGeometry) { // Leave empty, it is already assigned to the Shape property break; } throw new ArgumentOutOfRangeException(); } } }