Example #1
0
 private void AddToCanvasImpl(ScopeControl parent, FlowAreaControl flowAreaControl)
 {
     flowAreaControl.AddScopeImpl(ScopeControl, parent);
     foreach (ScopeNode next in nexts)
     {
         next.AddToCanvasImpl(ScopeControl, flowAreaControl);
     }
 }
Example #2
0
        public void RemoveScope(ScopeControl scopeControl)
        {
            if (!childScopes.Contains(scopeControl))
            {
                return;
            }

            scopeControl.CurrentPositionable.PropertyChanged -= CurrentPositionable_PropertyChanged;
            scopeControl.CurrentPositionable.SizeChanged     -= CurrentPositionable_SizeChanged;
            childScopes.Remove(scopeControl);
            UpdateSize();
        }
Example #3
0
        public void AddScope(ScopeControl scopeControl)
        {
            if (childScopes.Contains(scopeControl))
            {
                return;
            }

            scopeControl.CurrentPositionable.PropertyChanged += CurrentPositionable_PropertyChanged;
            scopeControl.CurrentPositionable.SizeChanged     += CurrentPositionable_SizeChanged;
            childScopes.Add(scopeControl);
            UpdateSize();
        }
Example #4
0
        public void Load(Stream stream, out string[] errorList, Action <float> progressCallback)
        {
            var errors = new List <string>();

            Clear();
            try
            {
                Utility.IsLoading = true;
                var document = new XmlDocument();
                document.Load(stream);
                var collapseList = new Dictionary <Source, Source>();
                var sourceDicts  = new Dictionary <int, SourceControl>();
                var nodes        = SelectSingleNodeChildren(document, "Sources");
                int iter         = 0;
                foreach (XmlNode node in nodes)
                {
                    try
                    {
                        var source = SelectionSerializer.DeserializeSource(node, OnGetSource);
                        if (source == null)
                        {
                            throw new Exception(String.Format("Invalid FullName. FullName:{0}", node.Attributes["FullName"].Value));
                        }
                        var temp    = CreateSource(source);
                        var control = AddSourceAtImpl(temp);
                        sourceDicts.Add(source.Id, control);
                        collapseList.Add(control.CurrentSource, source);
                        if (source.Comment != null)
                        {
                            var command = new AddBoundCommentBommand(this, control);
                            command.CommentControl.CurrentComment.Text = source.Comment.Text;
                            commandManager.AddCommand(command);
                        }
                    }
                    catch (Exception e)
                    {
                        errors.Add(e.Message);
                    }
                    iter++;
                    progressCallback?.Invoke((float)iter / nodes.Count);
                }
                foreach (XmlNode node in SelectSingleNodeChildren(document, "//Flows"))
                {
                    try
                    {
                        var           connectionInfo = SelectionSerializer.DeserializeFlow(node);
                        SourceControl src = sourceDicts[connectionInfo.SrcId], dest = sourceDicts[connectionInfo.DestId];
                        if (src != null && dest != null)
                        {
                            SourceItemControl srcItem  = src.GetItemControlByName(connectionInfo.SrcName, true),
                                              destItem = dest.GetItemControlByName(connectionInfo.DestName, false);
                            if (srcItem != null && destItem != null)
                            {
                                var command = new AddFlowCommand(this, new ArrowControl(), srcItem, destItem);
                                commandManager.AddCommand(command);
                            }
                            else
                            {
                                var message = String.Format("SrcItem or DestItem is null. SrcID:{0}, DestID:{1}, SrcName:{2}, DestName:{3}",
                                                            connectionInfo.SrcId, connectionInfo.DestId,
                                                            connectionInfo.SrcName, connectionInfo.DestName);
                                throw new Exception(message);
                            }
                        }
                        else
                        {
                            var message = String.Format("SrcControl or DestControl is null. SrcID:{0}, DestID:{1}, SrcName:{2}, DestName:{3}",
                                                        connectionInfo.SrcId, connectionInfo.DestId,
                                                        connectionInfo.SrcName, connectionInfo.DestName);
                            throw new Exception(message);
                        }
                    }
                    catch (Exception e)
                    {
                        errors.Add(e.Message);
                    }
                }
                foreach (KeyValuePair <Source, Source> pair in collapseList)
                {
                    pair.Key.IsCollapsed = pair.Value.IsCollapsed;
                }
                foreach (XmlNode node in SelectSingleNodeChildren(document, "//Comments"))
                {
                    var comment        = SelectionSerializer.DeserializeComment(node);
                    var commentControl = AddCommentAtImpl(comment.Position.X, comment.Position.Y);
                    commentControl.CurrentComment.Text    = comment.Text;
                    commentControl.CurrentComment.ScopeId = comment.ScopeId;
                }

                var parentScopeIdList = new Dictionary <ScopeControl, int>();
                var addedScopes       = new List <ScopeControl>();
                foreach (XmlNode node in SelectSingleNodeChildren(document, "//Scopes"))
                {
                    var          scope        = SelectionSerializer.DeserializeScope(node);
                    ScopeControl scopeControl = null;
                    if (scope.ParentScopeId < 0)
                    {
                        scopeControl = AddScopeAtImpl(scope.Position, scope.Color, scope.Id, null);
                        addedScopes.Add(scopeControl);
                    }
                    else
                    {
                        scopeControl = CreateScopeControl(scope.Position, scope.Color, scope.Id);
                        parentScopeIdList.Add(scopeControl, scope.ParentScopeId);
                    }
                }
                SolveScopeDependencyAndAdd(parentScopeIdList, addedScopes.ToArray());
                foreach (SourceControl source in GetAllSourceControls())
                {
                    try
                    {
                        if (source.CurrentSource.ScopeId < 0)
                        {
                            continue;
                        }
                        var scope = GetScopeById(source.CurrentSource.ScopeId);
                        if (scope == null)
                        {
                            throw new Exception(String.Format("Scope Not Found:Scope ID:{0}, SourceID:{1}",
                                                              source.CurrentSource.ScopeId, source.CurrentSource.Id));
                        }
                        var command = new AddSelectableToScopeCommand(this, scope, source);
                        commandManager.AddCommand(command);
                    }
                    catch (Exception e)
                    {
                        errors.Add(e.Message);
                    }
                }
                foreach (CommentControl comment in GetAllCommentControls())
                {
                    try
                    {
                        if (comment.CurrentComment.ScopeId < 0)
                        {
                            continue;
                        }
                        var scope = GetScopeById(comment.CurrentComment.ScopeId);
                        if (scope == null)
                        {
                            throw new Exception(String.Format("Scope Not Found:Scope ID:{0}", comment.CurrentComment.ScopeId));
                        }
                        var command = new AddSelectableToScopeCommand(this, scope, comment);
                        commandManager.AddCommand(command);
                    }
                    catch (Exception e)
                    {
                        errors.Add(e.Message);
                    }
                }
            }
            finally
            {
                commandManager.Clear();
                UpdateMaxId();
                errorList         = errors.ToArray();
                Utility.IsLoading = false;
            }
        }
Example #5
0
 public bool ContainsScope(ScopeControl scopeControl)
 {
     return(childScopes.Contains(scopeControl));
 }