Esempio n. 1
0
        private Action <bool> GetDiagramPostEditCallback(ObservableDiagram od)
        {
            ObservableDiagram originalObservableDiagram = od;
            Diagram           originalDiagram           = od.Diagram;

            return((changed) =>
            {
                if (changed)
                {
                    if (Collection.Contains(originalDiagram))
                    {
                        // We edited an existing diagram, so we need to replace the pre-edited Diagram still in the library
                        // with the newly minted Diagram from the editor
                        Collection.Replace(originalDiagram, originalObservableDiagram.Diagram);
                    }
                    else
                    {
                        // This was a new diagram, so we need to add it to the library collection
                        Collection.Add(originalObservableDiagram.Diagram);
                        // Then add it to the list of visible diagrams
                        Diagrams.Add(originalObservableDiagram);
                    }

                    // Now we need to refresh the individual image
                    originalObservableDiagram.Refresh();

                    // Now that the internal Diagram has changed, we need to rebuild the callback so that the new Diagram is
                    // cached correctly for any future calls to edit this od
                    originalObservableDiagram.PostEditCallback = GetDiagramPostEditCallback(originalObservableDiagram);
                }
            });
        }
Esempio n. 2
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method updates the view model data and sends update command back
        /// to the solution builder.</summary>
        ///--------------------------------------------------------------------------------
        protected override void OnUpdate()
        {
            // send update for any updated children
            foreach (DiagramViewModel item in Diagrams)
            {
                if (item.IsEdited == true)
                {
                    item.Update();
                }
            }
            // send update for any new children
            foreach (DiagramViewModel item in ItemsToAdd.OfType <DiagramViewModel>())
            {
                item.Update();
                Diagrams.Add(item);
            }
            ItemsToAdd.Clear();

            // send delete for any deleted children
            foreach (DiagramViewModel item in ItemsToDelete.OfType <DiagramViewModel>())
            {
                item.Delete();
                Diagrams.Remove(item);
            }
            ItemsToDelete.Clear();

            // reset modified for children
            foreach (DiagramViewModel item in Diagrams)
            {
                item.ResetModified(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Adds a diagram to the project.
        /// </summary>
        /// <param name="diagram">The diagram to add.</param>
        public virtual void AddDiagram(DiagramModel diagram)
        {
            if (Diagrams.Contains(diagram))
            {
                return;
            }

            Diagrams.Add(diagram);
        }
Esempio n. 4
0
        public async void LoadDiagram()
        {
            try
            {
                installedLocation = await installedLocation.CreateFolderAsync("Syncfusion", CreationCollisionOption.OpenIfExists);

                //IReadOnlyList<StorageFile> files = await installedLocation.GetFilesAsync();
                StorageFile indexFile             = null;
                IReadOnlyList <StorageFile> files = await installedLocation.GetFilesAsync();

                indexFile = files.Where(f => f.Name == "index.xml").FirstOrDefault();
                if (indexFile != null)
                {
                    XmlSerializer   deSerializer = new XmlSerializer(typeof(List <FileInfo>), new Type[] { typeof(FileInfo) });
                    List <FileInfo> fileIndex    = null;
                    using (Stream stream = await indexFile.OpenStreamForReadAsync())
                    {
                        fileIndex = deSerializer.Deserialize(stream) as List <FileInfo>;
                    }

                    foreach (FileInfo fileInfo in fileIndex.OrderBy(e => e.Index))
                    {
                        if (!files.Any(f => f.Name == fileInfo.FileName))
                        {
                            continue;
                        }
                        StorageFile file = await installedLocation.GetFileAsync(fileInfo.FileName);

                        DiagramVM newdiagram = GetNewDiagramVM(file, true);
                        newdiagram.IsSelected = fileInfo.Selected;
                        newdiagram.Title      = fileInfo.Title;
                        Diagrams.Add(newdiagram);

                        //FileItem item = new FileItem();
                        //item.Name = file.DisplayName;
                        //item.Load = this.Load;
                        //BasicProperties properties = await file.GetBasicPropertiesAsync();
                        //item.LastUpdated = properties.DateModified;
                        //items.Add(item);
                    }
                }
            }
            catch
            {
            }
            if (Diagrams.Count == 0)
            {
                OnNewCommand(null);
            }
            //else
            //{
            //    SelectedDiagram = Diagrams[0];
            //}
        }
Esempio n. 5
0
        public virtual void AddDiagram(DiagramModel diagram)
        {
            if (Diagrams.Contains(diagram))
            {
                return;
            }

            Diagrams.Add(diagram);
            ProjectChanged();
            TriggerProjectChangeWhenDiagramChanges(diagram);
        }
Esempio n. 6
0
        public async void OnNewCommand(object param)
        {
            StorageFile s         = null;
            string      parameter = Guid.NewGuid().ToString("N");

            //if (EnsureUnsnapped())
            {
                s = await installedLocation.CreateFileAsync(parameter + ".xml", CreationCollisionOption.FailIfExists);
            }
            if (s != null)
            {
                DiagramVM newDiagram = GetNewDiagramVM(s, false);
                Diagrams.Add(newDiagram);
                SelectedDiagram = newDiagram;
            }
            await SaveFileIndex();
        }
Esempio n. 7
0
        public async void OnDuplicateCommand(object param)
        {
            StorageFile s          = null;
            DiagramVM   newDiagram = null;
            //Task task = null;
            string parameter = Guid.NewGuid().ToString("N");

            //if (EnsureUnsnapped())
            {
                s = await installedLocation.CreateFileAsync(parameter + ".mock", CreationCollisionOption.FailIfExists);
            }
            if (s != null)
            {
                IGraphInfo graph = SelectedDiagram.Info as IGraphInfo;
                PageVM     page  = SelectedDiagram.PageSettings as PageVM;
                if (graph != null && SelectedDiagram.ScrollSettings.ScrollInfo != null)
                {
                    page.HOffset = SelectedDiagram.ScrollSettings.ScrollInfo.HorizontalOffset;
                    page.VOffset = SelectedDiagram.ScrollSettings.ScrollInfo.VerticalOffset;
                    page.Scale   = SelectedDiagram.ScrollSettings.ScrollInfo.CurrentZoom;
                    using (Stream stream = await s.OpenStreamForWriteAsync())
                    {
                        graph.Save(stream);
                    }
                    newDiagram = new DiagramVM(s, true);

                    Diagrams.Add(newDiagram);
                    SelectedDiagram             = newDiagram;
                    newDiagram.EditTile         = true;
                    newDiagram.PropertyChanged += (diagram, e) =>
                    {
                        DiagramVM sender = diagram as DiagramVM;
                        if (e.PropertyName == "IsSelected")
                        {
                            if (sender.IsSelected == true)
                            {
                                this.SelectedDiagram = sender;
                            }
                        }
                    };
                    await SaveFileIndex();
                }
            }
        }
 ///--------------------------------------------------------------------------------
 /// <summary>This method loads Diagrams into the view model.</summary>
 ///
 /// <param name="entities">The solution entities that could be added to the diagram.</param>
 /// <param name="solution">The associated solution.</param>
 /// <param name="loadChildren">Flag indicating whether to perform a deeper load.</param>
 ///--------------------------------------------------------------------------------
 public void LoadDiagrams(EnterpriseDataObjectList <EntityViewModel> entities, Solution solution, bool loadChildren = true)
 {
     // attach the items
     Items.Clear();
     if (Diagrams == null)
     {
         Diagrams = new EnterpriseDataObjectList <DiagramViewModel>();
     }
     if (loadChildren == true)
     {
         foreach (Diagram item in solution.DiagramList)
         {
             DiagramViewModel itemView = new DiagramViewModel(item, entities, solution);
             itemView.Updated += new EventHandler(Children_Updated);
             Diagrams.Add(itemView);
             Items.Add(itemView);
         }
     }
 }
Esempio n. 9
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method applies diagram updates.</summary>
        ///--------------------------------------------------------------------------------
        public void ProcessEditDiagramPerformed(DiagramEventArgs data)
        {
            try
            {
                bool isItemMatch = false;
                if (data != null && data.Diagram != null)
                {
                    foreach (DiagramViewModel item in Diagrams)
                    {
                        if (item.Diagram.DiagramID == data.Diagram.DiagramID)
                        {
                            isItemMatch = true;
                            item.Diagram.TransformDataFromObject(data.Diagram, null, false);
                            item.OnUpdated(item, null);
                            item.ShowInTreeView();
                            break;
                        }
                    }
                    if (isItemMatch == false)
                    {
                        // add new Diagram
                        data.Diagram.Solution = Solution;

                        #region protected
                        DiagramViewModel newItem = new DiagramViewModel(data.Diagram, Entities, Solution);
                        #endregion protected

                        newItem.Updated += new EventHandler(Children_Updated);
                        Diagrams.Add(newItem);
                        Solution.DiagramList.Add(newItem.Diagram);
                        Items.Add(newItem);
                        OnUpdated(this, null);
                        newItem.ShowInTreeView();
                    }
                }
            }
            catch (Exception ex)
            {
                ShowIssue(ex.Message + ex.StackTrace);
            }
        }
Esempio n. 10
0
        private void DrawDiagrams()  // Построение и отрисовка диаграм
        {
            Diagrams.Clear();

            var Xdiagrams = SelectedTask
                            .Element("diagrams");

            if (Xdiagrams == null)
            {
                ButtonDiagramsVisibility = Visibility.Collapsed;
                return;
            }

            var diagrams = Xdiagrams.
                           Descendants("diagram")
                           .Select(i => new
            {
                x = int.Parse(i.Element("x").Attribute("column").Value),
                y = int.Parse(i.Element("y").Attribute("column").Value),
            })
                           .ToArray();

            foreach (var diagram in diagrams)
            {
                if (diagram.x > DataTable.First().Count || diagram.y > DataTable.First().Count || diagram.x < 0 || diagram.y < 0)
                {
                    throw new XMLValidationException("Diagram value is bigger than length if the table or less than 0");
                }

                StackPanel spA = ParseToStackPanel(DataTable[0][diagram.x].Text);
                StackPanel spB = ParseToStackPanel(DataTable[0][diagram.y].Text);

                Diagram d = new Diagram(diagram.x, diagram.y, spA, spB);
                Diagrams.Add(d);
            }

            ButtonDiagramsVisibility = Diagrams.Count > 0 ? Visibility.Visible : Visibility.Collapsed;
            UpdateDiagrams();
        }
Esempio n. 11
0
 private void TypesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     foreach (var newItem in e.NewItems)
     {
         Type type = newItem as Type;
         if (type.GetInterface(typeof(IDiagram).FullName, false) != null)
         {
             IDiagram diagram = (IDiagram)Activator.CreateInstance(type);
             if (!Diagrams.Any(item => item.GetType() == type))
             {
                 Diagrams.Add(diagram);
                 if (SelectedDiagram == null)
                 {
                     SelectedDiagram = diagram;
                 }
             }
         }
         else if (type.IsSubclassOf(typeof(ObjectType)))
         {
             AddSelectedDiagramType(type);
         }
     }
 }
        /// <summary>
        /// Traverses Depth-First through the bpmn XML file, collecting and linking all Elements.
        /// </summary>
        /// <param name="xNode">The XML node to start with</param>
        /// <param name="parent">The parent <see cref="BpmnElement"/></param>
        /// <param name="callingElements">A list to add all <see cref="BpmnElement"/> with a valid 'CalledElement' or 'Process' property.</param>
        private void RecursiveElements(XElement xNode, BpmnElement parent, ICollection <BpmnElement> callingElements)
        {
            var element = new BpmnElement(xNode);

            if (element.CalledElement != null)
            {
                callingElements.Add(element);
            }
            else if (element.Process != null)
            {
                callingElements.Add(element);
            }

            // Only xml nodes with an id can be bpmn elements
            if (element.Id != null)
            {
                try {
                    Elements.Add(element.Id, element);
                    // some tools prefix the ids with a namespace prefix but don't use this namespace to reference it
                    // so if the id contains a prefix, it is mapped with and without it
                    var prefix = xNode.GetPrefixOfNamespace(xNode.Name.Namespace);
                    if (prefix != null)
                    {
                        Elements.Add(prefix + ":" + element.Id, element);
                    }
                } catch (ArgumentException) {
                    Messages.Add("Error while trying to add second Element with the same id: " + element.Id);
                }
            }

            // Double-link bpmn element to the given parent element
            if (parent != null)
            {
                parent.AddChild(element);
            }
            element.Parent = parent;

            // Call all xml children
            foreach (var xChild in xNode.Elements())
            {
                var nameSpace = xChild.Name.Namespace;
                var localName = xChild.Name.LocalName;
                if (nameSpace.Equals(BpmnNM.Bpmn))
                {
                    // Add all bpmn elements to the dictionary
                    RecursiveElements(xChild, element, callingElements);
                }
                else if (nameSpace.Equals(BpmnNM.BpmnDi))
                {
                    // Parse a diagram as whole
                    if (localName == BpmnDiConstants.BpmnDiagramElement)
                    {
                        var diagram = BuildDiagram(xChild);
                        if (diagram.Plane != null)
                        {
                            Diagrams.Add(diagram);
                        }
                        else
                        {
                            Messages.Add("The plane for diagram + " + diagram.Id + " was not correctly parsed.");
                        }
                    }
                }
                else
                {
                    element.ForeignChildren.Add(xChild);
                }
            }
        }