private string GetPropertyType(MetadataProperty property) { if (property.PropertyType.IsMultipleType) { return("object"); } else if (property.PropertyType.IsUuid) { return("Guid"); } else if (property.PropertyType.CanBeString) { return("string"); } else if (property.PropertyType.CanBeNumeric) { return("decimal"); } else if (property.PropertyType.CanBeBoolean) { return("bool"); } else if (property.PropertyType.CanBeDateTime) { return("DateTime"); } else if (property.PropertyType.CanBeReference) { return("Guid"); } return("object"); }
private void Build_SelectBatch_Script(string targetTable) { StringBuilder script = new StringBuilder(); script.AppendLine("SELECT"); for (int i = 0; i < _catalog.Properties.Count; i++) { MetadataProperty property = _catalog.Properties[i]; string propertyName = GetPropertyName(property); if (string.IsNullOrEmpty(propertyName)) { continue; } script.Append($"\t[{propertyName}]"); if (i != (_catalog.Properties.Count - 1)) { script.Append(","); } script.AppendLine(); } script.AppendLine("FROM"); script.AppendLine($"\t[{targetTable}]"); script.AppendLine("WHERE"); script.Append("\t[RowNumber] BETWEEN @RowNumber1 AND @RowNumber2;"); _sql_script_SelectBatch = script.ToString(); }
private void MoveMetadataDown() { int currentIndex = this.TilesetMetadata.Value.CurrentPosition; MetadataProperty currentItem = this.TilesetMetadata.Value.CurrentItem as MetadataProperty; MetadataType currentItemType = currentItem.Type; int propertyIndex = 0; int statisticIndex = this.MetadataList.Count(p => p.Type == MetadataType.Property) + propertyIndex; int customIndex = this.MetadataList.Count(p => p.Type == MetadataType.Statistic) + statisticIndex; int highestIndex = 0; switch (currentItemType) { case MetadataType.Property: highestIndex = statisticIndex - 1; break; case MetadataType.Statistic: highestIndex = customIndex - 1; break; case MetadataType.Custom: highestIndex = this.MetadataList.Count - 1; break; default: break; } if (currentIndex < highestIndex) { this.MetadataList.Move(currentIndex, currentIndex + 1); this.TilesetMetadata.Value.Refresh(); } }
public IProperty GetDefinition(PropertyDefinitionHandle handle) { if (handle.IsNil) { return(null); } if (propertyDefs == null) { return(new MetadataProperty(this, handle)); } int row = MetadataTokens.GetRowNumber(handle); Debug.Assert(row != 0); if (row >= methodDefs.Length) { HandleOutOfRange(handle); } var property = LazyInit.VolatileRead(ref propertyDefs[row]); if (property != null) { return(property); } property = new MetadataProperty(this, handle); return(LazyInit.GetOrSet(ref propertyDefs[row], property)); }
// POST api/Metadata public HttpResponseMessage SaveMetadataProperty(MetadataProperty metadataproperty) { var db = ServicesContext.Current; HttpResponseMessage response = null; if (ModelState.IsValid) { if (metadataproperty.Id == 0) { db.MetadataProperty.Add(metadataproperty); response = Request.CreateResponse(HttpStatusCode.Created, metadataproperty); } else { db.Entry(metadataproperty).State = EntityState.Modified; response = Request.CreateResponse(HttpStatusCode.OK, metadataproperty); } } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } db.SaveChanges(); return(response); }
public HttpResponseMessage DeleteMetadataProperty(JObject jsonData) { var db = ServicesContext.Current; dynamic json = jsonData; int PropertyId = json.Id.ToObject <int>(); MetadataProperty metadataproperty = db.MetadataProperty.Find(PropertyId); if (metadataproperty == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } db.MetadataProperty.Remove(metadataproperty); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK, metadataproperty)); }
private void InsertPropertyField(ApplicationObject metaObject, SqlFieldInfo fieldInfo) { IApplicationObjectFactory factory = MetadataManager.GetFactory(metaObject.GetType()); if (factory == null) { return; } string propertyName = factory.PropertyFactory.GetPropertyName(fieldInfo); if (string.IsNullOrEmpty(propertyName)) { propertyName = fieldInfo.COLUMN_NAME; } // Проверка нужна для свойств, имеющих составной тип данных MetadataProperty property = metaObject.Properties.Where(p => p.Name == propertyName).FirstOrDefault(); if (property == null) { property = factory.PropertyFactory.CreateProperty(metaObject, propertyName, fieldInfo); metaObject.Properties.Add(property); } else if (property.Fields.Where(f => f.Name == fieldInfo.COLUMN_NAME).FirstOrDefault() != null) { return; // поле добавлять не надо } property.Fields.Add(factory.PropertyFactory.CreateField(fieldInfo)); }
public void CloneWithDefiningQuery_does_not_creat_schema_and_table_extended_attributes_if_they_are_null() { var property = EdmProperty.CreatePrimitive( "Id", ProviderManifest.GetStoreTypes().Single(t => t.PrimitiveTypeKind == PrimitiveTypeKind.Int32)); var customMetadataProperty = MetadataProperty.Create( "http://tempUri:myProperty", TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)), "value"); var entityType = EntityType.Create("EntityType", "MyModel", DataSpace.SSpace, new[] { "Id" }, new[] { property }, null); var entitySet = EntitySet.Create("EntityTypeSet", null, null, null, entityType, new[] { customMetadataProperty }); var clonedEntitySet = EntitySetDefiningQueryConverter.CloneWithDefiningQuery(entitySet, "definingQuery"); Assert.Null(clonedEntitySet.Schema); Assert.Null(clonedEntitySet.Table); Assert.False(entitySet.MetadataProperties.Any(p => p.Name.EndsWith(StoreSchemaAttributeNamespace + ":Schema"))); Assert.False(entitySet.MetadataProperties.Any(p => p.Name.EndsWith(StoreSchemaAttributeNamespace + ":Name"))); }
private string GetPropertyName(MetadataProperty property) { if (property.Name == "Ссылка") { return("Ref"); } else if (property.Name == "ВерсияДанных") { return(string.Empty); } else if (property.Name == "ПометкаУдаления") { return("DeletionMark"); } else if (property.Name == "Дата") { return("Date"); } else if (property.Name == "Номер") { return("Number"); } else if (property.Name == "Проведён") { return("Posted"); } else if (property.Name == "ПериодНомера") { return(string.Empty); } return(property.Name); }
public static void ShowFields(MetadataProperty property) { foreach (DatabaseField field in property.Fields) { Console.WriteLine(" - " + field.Name + " (" + field.TypeName + ")"); } }
internal static MetadataProperty CreateMetadataPropertyFromXmlElement( string xmlNamespaceUri, string elementName, XElement value) { return(MetadataProperty.CreateAnnotation(xmlNamespaceUri + ":" + elementName, (object)value)); }
// PUT api/Metadata/5 public HttpResponseMessage PutMetadataProperty(int id, MetadataProperty metadataproperty) { var db = ServicesContext.Current; if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != metadataproperty.Id) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } db.Entry(metadataproperty).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
private static EntityType CreateEntityTypeWithExtendedProperty(XNamespace copyToSSDLNamespace, string copyToSSDLValue) { var extendedPropertyContents = new XElement( (XNamespace)"http://myExtendedProperties" + "MyProp", new XAttribute( (XNamespace)"http://myExtendedProperties" + "MyAttribute", "MyValue"), new XAttribute( copyToSSDLNamespace + "CopyToSSDL", copyToSSDLValue)); var extendedPropertyMetadataProperty = MetadataProperty.Create( "http://myExtendedProperties:MyProp", TypeUsage.CreateStringTypeUsage( PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String), true, false), extendedPropertyContents ); return(EntityType.Create( "TestEntityType", "Model1", DataSpace.CSpace, new[] { "Id" }, new[] { EdmProperty.CreatePrimitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)) }, new[] { extendedPropertyMetadataProperty })); }
public void CollectStoreModelErrors_returns_errors_on_model_items() { var edmSchemaError = new EdmSchemaError("msg", 42, EdmSchemaErrorSeverity.Error); var errorMetadataProperty = MetadataProperty.Create( MetadataItemHelper.SchemaErrorsMetadataPropertyName, TypeUsage.CreateDefaultTypeUsage( PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String).GetCollectionType()), new List <EdmSchemaError> { edmSchemaError }); var entityType = EntityType.Create( "foo", "bar", DataSpace.SSpace, new string[0], new EdmMember[0], new[] { errorMetadataProperty }); var model = new EdmModel(DataSpace.SSpace); model.AddItem(entityType); var schemaErrors = ModelGenerator.CollectStoreModelErrors(model); Assert.NotNull(schemaErrors); Assert.Equal(1, schemaErrors.Count); Assert.Same(edmSchemaError, schemaErrors.Single()); }
public static bool IsControlledVocabulary(this MetadataProperty metadataProperty, out string range) { range = metadataProperty.Properties.GetValueOrNull(Constants.Shacl.Range, true); if (string.IsNullOrWhiteSpace(range) || range == Constants.Identifier.Type) { return(false); } string hasPid = metadataProperty.Properties.GetValueOrNull(Constants.EnterpriseCore.PidUri, true); if (hasPid == Constants.Resource.MainDistribution || hasPid == Constants.Resource.Distribution || hasPid == Constants.Resource.BaseUri || hasPid == Constants.RDF.Type || hasPid == Constants.Resource.HasHistoricVersion || hasPid == Constants.Resource.HasLaterVersion || hasPid == Constants.Resource.MetadataGraphConfiguration) { return(false); } var groupKey = metadataProperty.GetMetadataPropertyGroup()?.Key; if (groupKey == Constants.Resource.Groups.LinkTypes) { return(false); } return(metadataProperty.Properties.GetValueOrNull(Constants.Shacl.NodeKind, true) == Constants.Shacl.NodeKinds.IRI); }
/// <summary> /// Given a resource type, generates the HasStreamAttribute for it /// </summary> /// <param name="entityType">Entity type for which HasStreamAttribute discovery is happening</param> /// <param name="typeDecl">Type declaration to add the attributes to</param> private void EmitStreamAttributesForEntityType(EntityType entityType, CodeTypeDeclaration typeDecl) { IEnumerable <MetadataProperty> hasStreamMetadataProperties = entityType.MetadataProperties.Where(mp => mp.PropertyKind == PropertyKind.Extended && mp.Name == System.Data.Services.XmlConstants.DataWebMetadataNamespace + ":" + System.Data.Services.XmlConstants.DataWebAccessHasStreamAttribute); MetadataProperty hasStreamMetadataProperty = null; foreach (MetadataProperty p in hasStreamMetadataProperties) { if (hasStreamMetadataProperty != null) { throw new InvalidOperationException( Strings.ObjectContext_MultipleValuesForSameExtendedAttributeType( System.Data.Services.XmlConstants.DataWebAccessHasStreamAttribute, entityType.Name)); } hasStreamMetadataProperty = p; } if (hasStreamMetadataProperty == null) { return; } if (!String.Equals(Convert.ToString(hasStreamMetadataProperty.Value, CultureInfo.InvariantCulture), System.Data.Services.XmlConstants.DataWebAccessDefaultStreamPropertyValue, StringComparison.Ordinal)) { return; } CodeAttributeDeclaration attribute = new CodeAttributeDeclaration( TypeReference.FromString( Utils.WebFrameworkCommonNamespace + "." + "HasStreamAttribute", true)); typeDecl.CustomAttributes.Add(attribute); }
public EntityTypeBuilder WithMetadataProperty <T>(string name, object value) { this.metadataProperties.Add( MetadataProperty.Create(name, this.typeUsageFactory.Create <T>(), value)); return(this); }
public override Region GetOrGenerate(MetadataProperty property) { if (property is MetadataSpecProperty specProp) { var exRegion = this.FirstOrDefault(a => a.SpecificationId == specProp.Id); if (exRegion != null) { return(exRegion); } var reg = Emulation.Regions.FirstOrDefault(a => a.Id == specProp.Id || a.Name == specProp.Id); if (reg != null) { exRegion = this.FirstOrDefault(a => a.SpecificationId == reg.Id); if (exRegion != null) { return(exRegion); } else { return(new Region(reg.Name) { SpecificationId = reg.Id }); } } return(null); } else { return(base.GetOrGenerate(property)); } }
public override Platform GetOrGenerate(MetadataProperty property) { if (property is MetadataSpecProperty specProp) { var exPlat = this.FirstOrDefault(a => a.SpecificationId == specProp.Id); if (exPlat != null) { return(exPlat); } var plat = Emulation.Platforms.FirstOrDefault(a => a.Id == specProp.Id || a.Name == specProp.Id); if (plat != null) { exPlat = this.FirstOrDefault(a => a.SpecificationId == plat.Id); if (exPlat != null) { return(exPlat); } else { return(new Platform(plat.Name) { SpecificationId = plat.Id }); } } return(null); } else { return(base.GetOrGenerate(property)); } }
public void RemoveCustomProperty(MetadataProperty property) { if (property.Type == MetadataType.Custom) { this.MetadataList.Remove(property); } }
/// <summary> /// Reads Id3 metadata directly in MP3 format /// </summary> public static void ReadId3MetadataDirectly() { //ExStart:ReadId3MetadataInMp3Directly // init Mp3Format class Mp3Format mp3Format = new Mp3Format(Common.MapSourceFilePath(filePath)); // read album in ID3 v1 MetadataProperty album = mp3Format[MetadataKey.Id3v1.Album]; Console.WriteLine(album); // read title in ID3 v2 MetadataProperty title = mp3Format[MetadataKey.Id3v2.Title]; Console.WriteLine(title); // create custom ID3v2 key // TCOP is used for 'Copyright' property according to the ID3 specification MetadataKey copyrightKey = new MetadataKey(MetadataType.Id3v2, "TCOP"); // read copyright property MetadataProperty copyright = mp3Format[copyrightKey]; Console.WriteLine(copyright); //ExEnd:ReadId3MetadataInMp3Directly }
internal override void Load( DataObject obj, object value, object exValue, LoadContext loadContext) { MetadataProperty property = this.Association.Property; if (obj.IsPropertyModified(property)) { return; } value = DataProperty.EscapeFromDBNull(value); exValue = DataProperty.EscapeFromDBNull(exValue); obj.LoadPropertyValue(property, value, exValue, loadContext); DataId id = new DataId((string)value); if (!id.IsEmpty) { MetadataAssociationRef metadataAssociationRef = this.Association.Selector == null ? this.Refs[0] : this.Refs.FindBySelectorValue(exValue); if (metadataAssociationRef != null) { ObjectListLoaderByIds refLoader = this.RefLoaders[metadataAssociationRef.Index]; if (refLoader != null && refLoader.ObjectLoader.Count > 0) { refLoader.Add(id); } } } }
/// <summary> /// Determines if the specified EdmMember is a concurrency timestamp. /// </summary> /// <remarks>Since EF doesn't expose "timestamp" as a first class /// concept, we use the below criteria to infer this for ourselves. /// </remarks> /// <param name="member">The member to check.</param> /// <returns>True or false.</returns> public static bool IsConcurrencyTimestamp(EdmMember member) { Facet facet = member.TypeUsage.Facets.SingleOrDefault(p => p.Name == "ConcurrencyMode"); if (facet == null || facet.Value == null || (ConcurrencyMode)facet.Value != ConcurrencyMode.Fixed) { return(false); } facet = member.TypeUsage.Facets.SingleOrDefault(p => p.Name == "FixedLength"); if (facet == null || facet.Value == null || !((bool)facet.Value)) { return(false); } facet = member.TypeUsage.Facets.SingleOrDefault(p => p.Name == "MaxLength"); if (facet == null || facet.Value == null || (int)facet.Value != 8) { return(false); } MetadataProperty md = ObjectContextUtilities.GetStoreGeneratedPattern(member); if (md == null || facet.Value == null || (string)md.Value != "Computed") { return(false); } return(true); }
private string GetPropertyName(MetadataProperty property) { if (property.Name == "Ссылка") { return("Ref"); } else if (property.Name == "ВерсияДанных") { return(string.Empty); } else if (property.Name == "Предопределённый") { return(string.Empty); } else if (property.Name == "ПометкаУдаления") { return("DeletionMark"); } else if (property.Name == "Владелец") { return("Owner"); } else if (property.Name == "Код") { return("Code"); } else if (property.Name == "Наименование") { return("Description"); } return(property.Name); }
internal MetadataProperty CreateMetadataPropertyFromXmlAttribute( string xmlNamespaceUri, string attributeName, string value) { var serializer = _resolver.GetService <Func <IMetadataAnnotationSerializer> >(attributeName); var parsedValue = serializer == null ? value : serializer().Deserialize(attributeName, value); return(MetadataProperty.CreateAnnotation(xmlNamespaceUri + ":" + attributeName, parsedValue)); }
public static string GetSoftDeleteColumnName(EdmType type) { MetadataProperty annotation = type.MetadataProperties .Where(p => p.Name.EndsWith("customannotation:SoftDeleteColumnName")) .SingleOrDefault(); return(annotation == null ? null : (string)annotation.Value); }
public static string GetTenantColumnName(EdmType type) { MetadataProperty annotation = type.MetadataProperties.SingleOrDefault( p => p.Name.EndsWith(string.Format("customannotation:{0}", TenantAnnotation))); return(annotation == null ? null : (string)annotation.Value); }
internal MetadataProperty CreateMetadataPropertyFromXmlAttribute( string xmlNamespaceUri, string artifactName, string value) { var name = xmlNamespaceUri + ":" + artifactName; var serializer = _resolver.GetService <IMetadataAnnotationSerializer>(name); var parsedValue = serializer == null ? value : serializer.DeserializeValue(name, value); return(MetadataProperty.CreateAnnotation(name, parsedValue)); }
public void AddNewCustomProperty() { int customCount = this.MetadataList.Count(p => p.Type == MetadataType.Custom); string customName = string.Format("Custom #{0}", customCount); MetadataProperty property = new MetadataProperty(customName, "", MetadataType.Custom); this.Item.CustomProperties.Add(property); this.MetadataList.Add(property); }
private void AddCustomProperty() { int customCount = this.MetadataList.Count(p => p.Type == MetadataType.Custom); string customName = string.Format("Custom #{0}", customCount); MetadataProperty property = new MetadataProperty(customName, "", MetadataType.Custom); this.TilesetModel.Value.CustomProperties.Add(property); this.MetadataList.Add(property); }