private string ReadProperties(IModelElement element, ISchemaElement schema) { var elem = ReadNextElement(); if (elem == "properties") { while ((elem = ReadNextElement()) == "property") { var name = ReadAttribute("name"); var prop = schema.GetProperty(name); if (prop == null) { throw new XmlSerializationException(String.Format("Unknow value property {1} for element {1}", name, element.Id)); } var vElem = ReadNextElement(); if (vElem != "value") { throw new XmlSerializationException(String.Format("Value expected for property {1} of element {1}", name, element.Id)); } _reader.Read(); var val = PlatformServices.Current.ObjectSerializer.Deserialize(_reader.Value, null); var cmd = new Hyperstore.Modeling.Commands.ChangePropertyValueCommand(element, prop, prop.PropertySchema.Deserialize(new SerializationContext(prop, val))); Session.Current.Execute(cmd); } } return(elem); }
///------------------------------------------------------------------------------------------------- /// <summary> /// Creates the index. /// </summary> /// <exception cref="NotSupportedException"> /// Thrown when the requested operation is not supported. /// </exception> /// <exception cref="Exception"> /// Thrown when an exception error condition occurs. /// </exception> /// <exception cref="DuplicateIndexException"> /// Thrown when a Duplicate Index error condition occurs. /// </exception> /// <param name="metaclass"> /// The metaclass. /// </param> /// <param name="name"> /// The name. /// </param> /// <param name="unique"> /// true to unique. /// </param> /// <param name="propertyNames"> /// List of names of the properties. /// </param> /// <returns> /// The new index. /// </returns> ///------------------------------------------------------------------------------------------------- public IIndex CreateIndex(ISchemaElement metaclass, string name, bool unique, params string[] propertyNames) { Contract.Requires(metaclass, "metaclass"); Contract.Requires(propertyNames.Length > 0, "propertyName"); if (propertyNames.Length > 1) { throw new NotSupportedException(); } var property = metaclass.GetProperty(propertyNames[0]); if (property == null) { throw new Hyperstore.Modeling.Metadata.PropertyDefinitionException(string.Format(ExceptionMessages.PropertyNameNotValidForMetaclassFormat, metaclass.Name)); } Conventions.CheckValidName(name); IndexDefinition def; _sync.EnterWriteLock(); try { if (IndexExists(name)) { throw new DuplicateIndexException(string.Format(ExceptionMessages.DuplicateIndexFormat, name)); } List <IndexDefinition> list = null; if (!_indexByMetaClass.TryGetValue(metaclass.Id, out list)) { list = new List <IndexDefinition>(); _indexByMetaClass.Add(metaclass.Id, list); } def = new IndexDefinition(_graph, name, metaclass, unique, propertyNames); list.Add(def); _indexByNames.TryAdd(name, def); } finally { _sync.ExitWriteLock(); } // Build index if (_graph.DomainModel != null) { foreach (var mel in _graph.GetElements(metaclass)) { def.Index.Add(mel.Id, mel.GetPropertyValue(property).Value); } } return(def.Index); }