Exemplo n.º 1
0
        /// <summary>
        /// Creates a new view digram for the pattern model.
        /// </summary>
        /// <param name="patternModel">The pattern model</param>
        /// <param name="docData">The document window data</param>
        /// <returns></returns>
        public static Guid CreateNewViewDiagram(PatternModelSchema patternModel, ModelingDocData docData)
        {
            Guard.NotNull(() => patternModel, patternModel);
            Guard.NotNull(() => docData, docData);

            // Create a new diagram file
            var docView = docData.DocViews.FirstOrDefault() as SingleDiagramDocView;
            PatternModelSchemaDiagram diagram = null;

            patternModel.Store.TransactionManager.DoWithinTransaction(() =>
            {
                diagram = PatternModelSerializationHelper.CreatePatternModelSchemaDiagram(
                    new SerializationResult(),
                    patternModel.Store.DefaultPartition,
                    patternModel.Store.GetRootElement(),
                    string.Empty);
            });
            if (diagram != null)
            {
                SetCurrentDiagram(docView, diagram, patternModel.Pattern);

                FixUpDiagram(patternModel, patternModel.Pattern, diagram.Id.ToString(),
                             PresentationViewsSubject.GetPresentation(patternModel.Pattern).OfType <ShapeElement>());

                return(diagram.Id);
            }

            return(Guid.Empty);
        }
Exemplo n.º 2
0
        internal PatternModelSchema LoadModelAndDiagrams(
            DslModeling.SerializationResult serializationResult,
            DslModeling.Partition modelPartition,
            string modelFileName,
            DslModeling.Partition diagramPartition,
            IEnumerable <string> diagramFileNames,
            DslModeling.ISchemaResolver schemaResolver,
            ValidationController validationController,
            DslModeling.ISerializerLocator serializerLocator)
        {
            Guard.NotNull(() => serializationResult, serializationResult);
            Guard.NotNull(() => modelPartition, modelPartition);
            Guard.NotNullOrEmpty(() => modelFileName, modelFileName);
            Guard.NotNull(() => diagramPartition, diagramPartition);
            Guard.NotNull(() => diagramFileNames, diagramFileNames);
            Guard.NotNull(() => schemaResolver, schemaResolver);
            Guard.NotNull(() => serializerLocator, serializerLocator);

            PatternModelSchema modelRoot;

            if (!diagramPartition.Store.TransactionActive)
            {
                throw new InvalidOperationException(PatternModelDomainModel.SingletonResourceManager.GetString("MissingTransaction"));
            }

            modelRoot = this.LoadModel(serializationResult, modelPartition, modelFileName, schemaResolver, validationController, serializerLocator);

            if (serializationResult.Failed)
            {
                // don't try to deserialize diagram data if model load failed.
                return(modelRoot);
            }

            var directory         = this.GetDirectory(diagramPartition.Store);
            var diagramSerializer = directory.GetSerializer(PatternModelSchemaDiagram.DomainClassId);
            var views             = modelRoot.Store.ElementDirectory.AllElements.OfType <ViewSchema>().ToList();

            foreach (var view in views)
            {
                var diagramFileName = diagramFileNames.FirstOrDefault(file => Path.GetFileNameWithoutExtension(file).Contains(view.DiagramId));

                if (diagramFileName == null)
                {
                    PatternModelSerializationHelper.CreatePatternModelSchemaDiagram(serializationResult, diagramPartition, modelRoot, view.DiagramId);
                }
                else
                {
                    this.LoadDiagram(serializationResult, diagramPartition, modelRoot, directory, diagramSerializer, diagramFileName, schemaResolver, validationController);
                }
            }

            // Set tracking properties
            ResetTrackingProperties(modelPartition.Store);

            return(modelRoot);
        }
Exemplo n.º 3
0
        public void Clone()
        {
            tracer.Info(string.Format(CultureInfo.InvariantCulture, Properties.Resources.PatternModelCloner_PatternModelCloning, this.SourcePatternModel.Id));

            tracer.Info(Properties.Resources.PatternModelCloner_EstablishingPatternModelInheritance);

            this.TargetPatternModel.Store.TransactionManager.DoWithinTransaction(
                () => this.TargetPatternModel.BaseVersion = this.SourceVersion.ToString());

            if (this.SourcePatternModel.Pattern != null)
            {
                var serializationResult = new SerializationResult();

                this.TargetPatternModel.Store.TransactionManager.DoWithinTransaction(() =>
                {
                    tracer.Info(Properties.Resources.PatternModelCloner_CloningViews);

                    foreach (var view in this.SourcePatternModel.Pattern.Views)
                    {
                        tracer.Info(string.Format(CultureInfo.InvariantCulture, Properties.Resources.PatternModelCloner_CloningView, view.Name));

                        PatternModelSerializationHelper.CreatePatternModelSchemaDiagram(
                            serializationResult,
                            this.TargetPatternModel.Store.GetDefaultDiagramPartition(),
                            this.TargetPatternModel,
                            view.DiagramId);
                    }
                });

                if (this.SourcePatternModel.Pattern != null)
                {
                    tracer.Info(Properties.Resources.PatternModelCloner_CloningProduct);

                    CopyElementGraph(this.TargetPatternModel.Store, this.TargetPatternModel, this.SourcePatternModel.Pattern);
                }

                tracer.Info(Properties.Resources.PatternModelCloner_EstablishingElementInheritance);

                this.SetNamedElementBaseIdentifiers();
            }
            else
            {
                tracer.Warn(Properties.Resources.PatternModelCloner_PatternSchemaNotFound);
            }
        }