Пример #1
0
        /// <summary>
        /// Creates a sample schema, populates it with sample data, and saves it to an XML file
        /// </summary>
        /// <param name="schemaComplexity">The example schema to create</param>
        private void CreateSetSave(SampleSchemaComplexity schemaComplexity)
        {
            //Get read-write access levels and schema and application Ids from the active dialog
            AccessLevel read;
            AccessLevel write;

            GetUIAccessLevels(out read, out write);
            if (!ValidateGuids())
            {
                TaskDialog.Show("ExtensibleStorage Manager", "Invalid Schema or ApplicationId Guid.");
                return;
            }

            //Get a pathname for an XML file from the user.
            Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
            sfd.DefaultExt       = ".xml";
            sfd.Filter           = "SchemaWrapper Xml files (*.xml)|*.xml";
            sfd.InitialDirectory = GetStartingXmlPath();

            sfd.FileName = this.m_textBox_SchemaName.Text + "_" + this.m_textBox_SchemaVendorId.Text + "___" + this.m_textBox_SchemaId.Text.Substring(31) + ".xml";

            Nullable <bool> result = sfd.ShowDialog();

            if ((result.HasValue) && (result == true))
            {
                try
                {
                    //Create a new sample SchemaWrapper, schema, and Entity and store it in the current document's ProjectInformation element.
                    m_SchemaWrapper = StorageCommand.CreateSetAndExport(m_Document.ProjectInformation, sfd.FileName, new Guid(this.m_textBox_SchemaId.Text), read, write, this.m_textBox_SchemaVendorId.Text, this.m_textBox_SchemaApplicationId.Text, this.m_textBox_SchemaName.Text, this.m_textBox_SchemaDocumentation.Text, schemaComplexity);
                }
                catch (Exception ex)
                {
                    TaskDialog.Show("ExtensibleStorage Manager", "Could not Create Schema.  " + ex.ToString());
                    return;
                }


                UpdateUI();

                //Display the schema fields and sample data we just created in a dialog.
                ExtensibleStorageManager.UIData dataDialog = new ExtensibleStorageManager.UIData();
                string schemaData = this.m_SchemaWrapper.ToString();
                string entityData = this.m_SchemaWrapper.GetSchemaEntityData(m_Document.ProjectInformation.GetEntity(m_SchemaWrapper.GetSchema()));
                string allData    = "Schema: " + Environment.NewLine + schemaData + Environment.NewLine + Environment.NewLine + "Entity" + Environment.NewLine + entityData;
                dataDialog.SetData(allData);
                dataDialog.ShowDialog();
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a sample schema, populates it with sample data, and saves it to an XML file
        /// </summary>
        /// <param name="schemaComplexity">The example schema to create</param>
        private void CreateSetSave(SampleSchemaComplexity schemaComplexity)
        {
            //Get read-write access levels and schema and application Ids from the active dialog
             AccessLevel read;
             AccessLevel write;
             GetUIAccessLevels(out read, out write);
             if (!ValidateGuids())
             {
            TaskDialog.Show("ExtensibleStorage Manager", "Invalid Schema or ApplicationId Guid.");
            return;
             }

             //Get a pathname for an XML file from the user.
             Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
             sfd.DefaultExt = ".xml";
             sfd.Filter = "SchemaWrapper Xml files (*.xml)|*.xml";
             sfd.InitialDirectory = GetStartingXmlPath();

             sfd.FileName = this.m_textBox_SchemaName.Text + "_" + this.m_textBox_SchemaVendorId.Text + "___" + this.m_textBox_SchemaId.Text.Substring(31) + ".xml";

             Nullable<bool> result = sfd.ShowDialog();

             if ((result.HasValue) && (result == true))
             {
            try
            {
               //Create a new sample SchemaWrapper, schema, and Entity and store it in the current document's ProjectInformation element.
               m_SchemaWrapper = StorageCommand.CreateSetAndExport(m_Document.ProjectInformation, sfd.FileName, new Guid(this.m_textBox_SchemaId.Text), read, write, this.m_textBox_SchemaVendorId.Text, this.m_textBox_SchemaApplicationId.Text, this.m_textBox_SchemaName.Text, this.m_textBox_SchemaDocumentation.Text, schemaComplexity);
            }
            catch (Exception ex)
            {
               TaskDialog.Show("ExtensibleStorage Manager", "Could not Create Schema.  " + ex.ToString());
               return;
            }

            UpdateUI();

            //Display the schema fields and sample data we just created in a dialog.
            ExtensibleStorageManager.UIData dataDialog = new ExtensibleStorageManager.UIData();
            string schemaData = this.m_SchemaWrapper.ToString();
            string entityData = this.m_SchemaWrapper.GetSchemaEntityData(m_Document.ProjectInformation.GetEntity(m_SchemaWrapper.GetSchema()));
            string allData = "Schema: " + Environment.NewLine + schemaData + Environment.NewLine + Environment.NewLine + "Entity" + Environment.NewLine + entityData;
            dataDialog.SetData(allData);
            dataDialog.ShowDialog();
             }
        }
Пример #3
0
        /// <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
        }
Пример #4
0
        /// <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
        }