/// <summary> /// Creates a new sample Schema, creates an instance of that Schema (an Entity) in the given element, /// sets data on that element's entity, and exports the schema to a given XML file. /// </summary> /// <returns>A new SchemaWrapper</returns> public static SchemaWrapperTools.SchemaWrapper CreateSetAndExport(Element storageElement, string xmlPathOut, Guid schemaId, AccessLevel readAccess, AccessLevel writeAccess, string vendorId, string applicationId, string name, string documentation, SampleSchemaComplexity schemaComplexity) { #region Start a new transaction, and create a new Schema if (Schema.Lookup(schemaId) != null) { throw new Exception("A Schema with this Guid already exists in this document -- another one cannot be created."); } Transaction storageWrite = new Transaction(storageElement.Document, "storageWrite"); storageWrite.Start(); //Create a new schema. SchemaWrapperTools.SchemaWrapper mySchemaWrapper = SchemaWrapperTools.SchemaWrapper.NewSchema(schemaId, readAccess, writeAccess, vendorId, applicationId, name, documentation); mySchemaWrapper.SetXmlPath(xmlPathOut); #endregion Entity storageElementEntityWrite = null; //Create some sample schema fields. There are two sample schemas hard coded here, "simple" and "complex." switch (schemaComplexity) { case SampleSchemaComplexity.SimpleExample: SimpleSchemaAndData(mySchemaWrapper, out storageElementEntityWrite); break; case SampleSchemaComplexity.ComplexExample: ComplexSchemaAndData(mySchemaWrapper, storageElement, xmlPathOut, schemaId, readAccess, writeAccess, vendorId, applicationId, name, documentation, out storageElementEntityWrite); break; } #region Store the main entity in an element, save the Serializeable SchemaWrapper to xml, and finish the transaction storageElement.SetEntity(storageElementEntityWrite); TransactionStatus storageResult = storageWrite.Commit(); if (storageResult != TransactionStatus.Committed) { throw new Exception("Error storing Schema. Transaction status: " + storageResult.ToString()); } else { mySchemaWrapper.ToXml(xmlPathOut); return(mySchemaWrapper); } #endregion }
/// <summary> /// Given an xml path containing serialized schema data, create a new Schema and SchemaWrapper /// </summary> public static void ImportSchemaFromXml(string path, out SchemaWrapperTools.SchemaWrapper sWrapper) { sWrapper = SchemaWrapperTools.SchemaWrapper.FromXml(path); sWrapper.SetXmlPath(path); }