Exemplo n.º 1
0
        public void Execute(NavigateCommand command)
        {
            IGraphData graph  = null;
            GraphNode  filter = null;

            // IDiagramNodeItem item = null;
            IGraphFilter[] filterPath = null;

            //if(!string.IsNullOrEmpty(command.ItemId))
            //     item = Repository.GetById<IDiagramNodeItem>(command.ItemId);
            // if (!string.IsNullOrEmpty(command.FilterId))
            filter = Repository.GetById <GraphNode>(command.FilterId);
            // if (!string.IsNullOrEmpty(command.GraphId))
            graph = Repository.GetById <IGraphData>(command.GraphId);
            //if (!string.IsNullOrEmpty(command.Workspaceid))


//            if (item == null && graph != null)
//            {
//                workspace = workspace ?? WorkspaceService.Workspaces.FirstOrDefault(p => p.Graphs.Any(x => x.Identifier == graph.Identifier));
//                filter = filter ?? graph.RootFilter as GraphNode;
//            }
//            else if(item != null)
//            {
//                graph = graph ?? item.Graph;
//                workspace = workspace ?? WorkspaceService.Workspaces.FirstOrDefault(p => p.Graphs.Any(x => x.Identifier == graph.Identifier));
//                if(item.Node != null) filter = filter ?? item.Node;
//            }
//            else if(filter == null)
//            {
//                throw new Exception("Cannot navigate: Invalid address");
//            }

//            if (workspace == null || filter == null || graph == null)
//            {
//                var ws = workspace == null ? "UnknownWorkspace" : workspace.Name;
//                var gp = graph == null ? "UnknownGraph" : graph.Name;
//                var f = filter == null ? "UnknownFilter" : filter.Name;
//                Signal<INotify>(_ => _.Notify(string.Format("Invalid Address: {0}/{1}/{2}", ws, gp, f), NotificationIcon.Error));
//
//                return;
//            };

            //Open Workspace

            if (WorkspaceService.CurrentWorkspace.Identifier != command.Workspaceid)
            {
                var workspace = Repository.GetById <Workspace>(command.Workspaceid);
                WorkspaceService.Execute(new OpenWorkspaceCommand()
                {
                    Workspace = workspace
                });
            }


            if (WorkspaceService.CurrentWorkspace.CurrentGraphId != command.GraphId)
            {
                WorkspaceService.CurrentWorkspace.CurrentGraphId = command.GraphId;
            }


//            filterPath = filter.FilterPath().ToArray();
//            graph.PopToFilter(graph.RootFilter);
//            foreach (var f in filterPath)
//            {
//                if (f == graph.RootFilter) continue;
//                graph.PushFilter(f);
//            }
//            if(filter != graph.RootFilter && !filterPath.Contains(filter)) graph.PushFilter(filter);

            filterPath = filter.FilterPath().ToArray();
            graph.PopToFilter(graph.RootFilter);
            foreach (var item in filterPath)
            {
                if (item == graph.RootFilter)
                {
                    continue;
                }
                graph.PushFilter(item);
            }
            if (filterPath.LastOrDefault() != filter)
            {
                graph.PushFilter(filter);
            }

            Execute(new ScrollGraphCommand()
            {
                Position = command.Scroll
            });
        }