Beispiel #1
0
 private void UpdateItem()
 {
     leftStack.Children.Clear();
     rightStack.Children.Clear();
     foreach (Item item in CurrentSource.Items)
     {
         if (item.IsOut)
         {
             var outItem = new SourceItemControl {
                 DataContext = item
             };
             outItem.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right;
             outItem.Selected     += outItem_Selected;
             outItem.TryConnected += outItem_TryConnected;
             rightStack.Children.Add(outItem);
         }
         else
         {
             var inItem = new SourceItemControl {
                 DataContext = item
             };
             inItem.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;
             inItem.Selected     += inItem_Selected;
             inItem.TryConnected += inItem_TryConnected;
             leftStack.Children.Add(inItem);
         }
     }
     inItems  = null;
     outItems = null;
 }
Beispiel #2
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;
            }
        }
Beispiel #3
0
 protected virtual void OnTryConnected(SourceItemControl itemControl)
 {
     TryConnected?.Invoke(itemControl, new EventArgs());
 }
Beispiel #4
0
 protected virtual void OnInItemSelected(SourceItemControl itemControl)
 {
     InItemSelected?.Invoke(itemControl, new EventArgs());
 }