public void CanSerialise()
 {
     var dataToSerialise = new TypeVisualiserLayoutFile();
     var dataContents = (VisualisableTypeSubjectData)carData.ExtractPersistentData();
     dataToSerialise.Subject = dataContents;
     var subject = new ModelSerialiser();
     subject.Serialise("TypeVisualiserTest.tvd", dataToSerialise);
 }
        public void SanityCheck4()
        {
            var dataToSerialise = new TypeVisualiserLayoutFile();
            var dataContents = new VisualisableTypeSubjectData
            {
                Associations = new[] { new FieldAssociationData(), new StaticAssociationData(), new ConsumeAssociationData() }
            };
            dataToSerialise.Subject = dataContents;

            var serialiser = new XmlSerializer(typeof(TypeVisualiserLayoutFile));
            using (var writer = new XmlTextWriter("SanityTest.xml", Encoding.UTF8))
            {
                serialiser.Serialize(writer, dataToSerialise);
            }
        }
示例#3
0
        private void OnLoadDiagramExecute()
        {
            this.diagramFile = this.fileManager.LoadDiagram();
            if (this.diagramFile == null)
            {
                // Cancel clicked by user
                return;
            }

            SetLoadingStatus(true);
            Task<IVisualisableTypeWithAssociations> task = this.fileManager.LoadFromDiagramFileAsync(this.diagramFile);
            if (task == null)
            {
                SetLoadingStatus(false);
                return;
            }

            if (task.IsCompleted)
            {
                OnTypeFinishedLoadingFromFile(task.Result);
            } else
            {
                task.ContinueWith(finishedTask => OnTypeFinishedLoadingFromFile(finishedTask.Result));
            }

            HideTrivialTypes = this.diagramFile.HideTrivialTypes;
        }
示例#4
0
        private void OnDiagramFinishedLoadingFromFile(object sender, EventArgs e)
        {
            var diagram = sender as Diagram;
            if (diagram == null)
            {
                return;
            }

            diagram.Controller.DiagramLoaded -= OnDiagramFinishedLoadingFromFile;
            if (diagram.Id != CurrentView.Id)
            {
                return;
            }

            OnZoomToFitExecute();
            CurrentView.Controller.LoadDiagramDataFromFile(this.diagramFile);
            this.diagramFile = null;
            SetLoadingStatus(false);
        }
        private static VisualisableTypeData FindTypeInFile(TypeVisualiserLayoutFile data, string id)
        {
            if (data.Subject.Id == id)
            {
                return data.Subject;
            }

            if (data.Subject.Parent != null && data.Subject.Parent.AssociatedTo.Id == id)
            {
                return data.Subject;
            }

            AssociationData type = data.Subject.Associations.FirstOrDefault(x => x.AssociatedTo.Id == id);
            if (type != null)
            {
                return type.AssociatedTo;
            }

            type = data.Subject.Implements.FirstOrDefault(x => x.AssociatedTo.Id == id);
            if (type != null)
            {
                return type.AssociatedTo;
            }

            return null;
        }
        public IPersistentFileData GatherPersistentData()
        {
            var canvasLayoutData = new CanvasLayoutData();
            foreach (DiagramElement element in DiagramElements)
            {
                if (Attribute.GetCustomAttribute(element.DiagramContent.GetType(), typeof(PersistentAttribute)) == null)
                {
                    // Only Diagram Content that is decorated with Persistent will get saved into the Layout collection.
                    continue;
                }

                var layoutData = new TypeLayoutData { ContentType = element.DiagramContent.GetType().FullName, TopLeft = element.TopLeft, Id = element.DiagramContent.Id, Visible = element.Show, };
                var diagramContent = element.DiagramContent as AnnotationData;
                if (diagramContent != null)
                {
                    layoutData.Data = diagramContent.Text;
                }

                canvasLayoutData.Types.Add(layoutData);
            }

            var saveData = new TypeVisualiserLayoutFile
                {
                    CanvasLayout = canvasLayoutData,
                    Subject = (VisualisableTypeSubjectData)Subject.ExtractPersistentData(),
                    AssemblyFullName = Subject.AssemblyFullName,
                    AssemblyFileName = Subject.AssemblyFileName,
                    FileVersion = GetType().Assembly.GetName().Version.ToString(),
                };
            saveData.AssemblyFileName = saveData.Subject.AssemblyFileName ?? GetType().Assembly.Location;
            return saveData;
        }
示例#7
0
        public Task<IVisualisableTypeWithAssociations> LoadFromDiagramFileAsync(TypeVisualiserLayoutFile layout)
        {
            if (layout == null)
            {
                throw new ArgumentNullResourceException("layout", Resources.General_Given_Parameter_Cannot_Be_Null);
            }

            return Task.Factory.StartNew(() => this.ModelBuilder.BuildSubject(layout.AssemblyFileName, layout.Subject.FullName, 0), TaskCreationOptions.LongRunning);
        }