コード例 #1
0
 public SchemaReader([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
 {
     this.serviceProvider = serviceProvider;
     var componentModel = this.serviceProvider.GetService<SComponentModel, IComponentModel>();
     this.serializerLocator = new StandardSerializerLocator(componentModel.DefaultExportProvider);
     this.extensionLocator = new StandardExtensionLocator(componentModel.DefaultExportProvider);
 }
コード例 #2
0
        public SchemaReader([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider;
            var componentModel = this.serviceProvider.GetService <SComponentModel, IComponentModel>();

            this.serializerLocator = new StandardSerializerLocator(componentModel.DefaultExportProvider);
            this.extensionLocator  = new StandardExtensionLocator(componentModel.DefaultExportProvider);
        }
コード例 #3
0
        private ModelElement LoadPartition(Partition partition, string modelFile)
        {
            if (string.IsNullOrEmpty(modelFile) || !File.Exists(modelFile))
            {
                base.ModelBus.LogError(ErrorCategory.Error, Microsoft.VisualStudio.TextTemplating.Modeling.ModelBusExceptionMessages.GetInvalidModelFilePath(modelFile));
                return(null);
            }
            ISerializerLocator serializerLocator = this.CreateSerializerLocator();

            if (serializerLocator == null)
            {
                base.ModelBus.LogError(ErrorCategory.Error, Microsoft.VisualStudio.TextTemplating.Modeling.ModelBusExceptionMessages.GetErrorLocateSerializer(modelFile));
                return(null);
            }
            IDomainModelSerializer serializerFromFileName = serializerLocator.GetSerializerFromFileName(modelFile);

            if (serializerFromFileName == null)
            {
                base.ModelBus.LogError(ErrorCategory.Error, Microsoft.VisualStudio.TextTemplating.Modeling.ModelBusExceptionMessages.GetErrorLocateSerializer(modelFile));
                return(null);
            }
            Type domainModelType = serializerFromFileName.DomainModelType;

            if (!(from i in partition.DomainDataDirectory.DomainModels select i.ImplementationType).Any <Type>(t => object.Equals(t, domainModelType)))
            {
                partition.Store.LoadDomainModels(new Type[] { domainModelType });
            }
            SerializationResult serializationResult = new SerializationResult();
            ModelElement        element             = null;

            using (Transaction transaction = partition.Store.TransactionManager.BeginTransaction("Load model", true))
            {
                element = serializerFromFileName.LoadModel(serializationResult, partition, modelFile, serializerLocator);
                if (!serializationResult.Failed)
                {
                    transaction.Commit();
                }
            }
            if (!serializationResult.Failed && (element != null))
            {
                return(element);
            }
            base.ModelBus.LogError(ErrorCategory.Error, Microsoft.VisualStudio.TextTemplating.Modeling.ModelBusExceptionMessages.GetErrorLoadFailed(modelFile));
            if (serializationResult.Failed)
            {
                foreach (SerializationMessage message in serializationResult)
                {
                    base.ModelBus.LogError(FromKind(message.Kind), message.Message);
                }
            }
            return(null);
        }
 internal override EntityDesignerViewModel LoadModelAndDiagram(
     SerializationResult serializationResult, Partition modelPartition, string modelFileName, Partition diagramPartition,
     string diagramFileName, ISchemaResolver schemaResolver, ValidationController validationController,
     ISerializerLocator serializerLocator)
 {
     EntityDesignerViewModel evm = null;
     using (new VsUtils.HourglassHelper())
     {
         evm = LoadModel(serializationResult, modelPartition, modelFileName, schemaResolver, validationController, serializerLocator);
         var diagram = CreateDiagramHelper(diagramPartition, evm);
     }
     return evm;
 }
コード例 #5
0
        internal override EntityDesignerViewModel LoadModelAndDiagram(
            SerializationResult serializationResult, Partition modelPartition, string modelFileName, Partition diagramPartition,
            string diagramFileName, ISchemaResolver schemaResolver, ValidationController validationController,
            ISerializerLocator serializerLocator)
        {
            EntityDesignerViewModel evm = null;

            using (new VsUtils.HourglassHelper())
            {
                evm = LoadModel(serializationResult, modelPartition, modelFileName, schemaResolver, validationController, serializerLocator);
                var diagram = CreateDiagramHelper(diagramPartition, evm);
            }
            return(evm);
        }
コード例 #6
0
        internal override EntityDesignerViewModel LoadModel(
            SerializationResult serializationResult, Partition partition, string fileName, ISchemaResolver schemaResolver,
            ValidationController validationController, ISerializerLocator serializerLocator)
        {
            var docData = VSHelpers.GetDocData(PackageManager.Package, fileName) as IEntityDesignDocData;

            docData.CreateAndLoadBuffer();

            EntityDesignerViewModel evm = null;

            var serializationContext = new SerializationContext(GetDirectory(partition.Store), fileName, serializationResult);
            var transactionContext   = new TransactionContext();

            transactionContext.Add(SerializationContext.TransactionContextKey, serializationContext);

            using (var t = partition.Store.TransactionManager.BeginTransaction("Load Model from " + fileName, true, transactionContext))
            {
                var uri     = Tools.XmlDesignerBase.Base.Util.Utils.FileName2Uri(fileName);
                var context = PackageManager.Package.DocumentFrameMgr.EditingContextManager.GetNewOrExistingContext(uri);
                evm =
                    ModelTranslatorContextItem.GetEntityModelTranslator(context).TranslateModelToDslModel(null, partition) as
                    EntityDesignerViewModel;

                if (evm == null)
                {
                    serializationResult.Failed = true;
                }
                else
                {
                    if (t.IsActive)
                    {
                        t.Commit();
                    }
                }
            }

            // Validate imported model
            if (!serializationResult.Failed &&
                (validationController != null))
            {
                validationController.Validate(partition, ValidationCategories.Load);
            }
            return(evm);
        }
        internal override EntityDesignerViewModel LoadModel(
            SerializationResult serializationResult, Partition partition, string fileName, ISchemaResolver schemaResolver,
            ValidationController validationController, ISerializerLocator serializerLocator)
        {
            var docData = VSHelpers.GetDocData(PackageManager.Package, fileName) as IEntityDesignDocData;
            docData.CreateAndLoadBuffer();

            EntityDesignerViewModel evm = null;

            var serializationContext = new SerializationContext(GetDirectory(partition.Store), fileName, serializationResult);
            var transactionContext = new TransactionContext();
            transactionContext.Add(SerializationContext.TransactionContextKey, serializationContext);

            using (var t = partition.Store.TransactionManager.BeginTransaction("Load Model from " + fileName, true, transactionContext))
            {
                var uri = Tools.XmlDesignerBase.Base.Util.Utils.FileName2Uri(fileName);
                var context = PackageManager.Package.DocumentFrameMgr.EditingContextManager.GetNewOrExistingContext(uri);
                evm =
                    ModelTranslatorContextItem.GetEntityModelTranslator(context).TranslateModelToDslModel(null, partition) as
                    EntityDesignerViewModel;

                if (evm == null)
                {
                    serializationResult.Failed = true;
                }
                else
                {
                    if (t.IsActive)
                    {
                        t.Commit();
                    }
                }
            }

            // Validate imported model
            if (!serializationResult.Failed
                && (validationController != null))
            {
                validationController.Validate(partition, ValidationCategories.Load);
            }
            return evm;
        }
コード例 #8
0
        public override ServiceContractModel LoadModelAndDiagram(
            SerializationResult serializationResult,
            Partition modelPartition,
            string modelFileName,
            Partition diagramPartition,
            string diagramFileName,
            ISchemaResolver schemaResolver,
            ValidationController validationController,
            ISerializerLocator serializerLocator)
        {
            ISchemaResolver resolver = new CustomModelingSchemaResolver(schemaResolver, "GeneratedCode\\ServiceContractSchema.xsd");

            return(base.LoadModelAndDiagram(
                       serializationResult,
                       modelPartition,
                       modelFileName,
                       diagramPartition,
                       diagramFileName,
                       resolver,
                       validationController,
                       serializerLocator));
        }
コード例 #9
0
        public override HostDesignerModel LoadModelAndDiagram(
            SerializationResult serializationResult, 
            Partition modelPartition, 
            string modelFileName, 
            Partition diagramPartition, 
            string diagramFileName, 
            ISchemaResolver schemaResolver, 
            ValidationController validationController, 
            ISerializerLocator serializerLocator)
        {
            ISchemaResolver resolver = new CustomModelingSchemaResolver(schemaResolver, "GeneratedCode\\HostDesignerSchema.xsd");

            return base.LoadModelAndDiagram(
                serializationResult,
                modelPartition,
                modelFileName,
                diagramPartition,
                diagramFileName,
                resolver,
                validationController,
                serializerLocator);
        }
コード例 #10
0
        public override ModelRoot LoadModel(SerializationResult serializationResult, Partition partition, string location, ISchemaResolver schemaResolver, ValidationController validationController, ISerializerLocator serializerLocator, Stream stream)
        {
            #region Check Parameters

            if (serializationResult == null)
            {
                throw new ArgumentNullException(nameof(serializationResult));
            }

            if (partition == null)
            {
                throw new ArgumentNullException(nameof(partition));
            }

            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            #endregion

            // Prior to v1.2.6.3, the XML format was a bit different.
            // To maintain backward compatability, we're going to check the format and morph it if needed.
            // The verified (or changed) stream is them passed down for further processing in the base class

            Stream workingStream = stream;
            workingStream = ModelMigration.To_1_2_6_11(workingStream);

            if (workingStream == null)
            {
                throw new FileFormatException();
            }

            workingStream.Seek(0, SeekOrigin.Begin);
            return(base.LoadModel(serializationResult, partition, location, schemaResolver, validationController, serializerLocator, workingStream));
        }
コード例 #11
0
 public override MetaModel LoadModel(SerializationResult serializationResult, Store store, string fileName, ISchemaResolver schemaResolver, DslValidation.ValidationController validationController, ISerializerLocator serializerLocator)
 {
     return LoadModel(serializationResult, store.DefaultPartition, fileName, schemaResolver, validationController, serializerLocator, true, true);
 }
コード例 #12
0
 public Application(ISerializerLocator serializerLocator)
 {
     this.serializerLocator = serializerLocator;
 }