public void ExpressionEditor_GoToDefinition()
        {
            // Navigate to symbol under cursor
            var obj           = ExpressionEditor_Current as IDaxDependantObject;
            var dependsOnList = DependsOnList.GetDependencies(obj, UI.ExpressionEditor.Text, CurrentDaxProperty);

            var dest = dependsOnList.GetObjectAt(CurrentDaxProperty, UI.ExpressionEditor.SelectionStart);

            if (dest == null)
            {
                var token = ExpressionParser.GetTokenAtPos(currentTokens, UI.ExpressionEditor.SelectionStart);
                if (token != null)
                {
                    if (token.Channel == DAXLexer.KEYWORD_CHANNEL)
                    {
                        Process.Start(string.Format(DAX_GUIDE_URL, token.Text.ToLowerInvariant()));
                    }
                }
                else
                {
                    UI.StatusLabel.Text = "Cannot navigate to symbol under cursor.";
                }
            }
            else
            {
                Goto(dest);
            }
        }
Exemple #2
0
        private void ExpressionEditor_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F12)
            {
                // Navigate to symbol under cursor
                var obj           = ExpressionEditor_Current as IDaxDependantObject;
                var dependsOnList = DependsOnList.GetDependencies(obj, UI.ExpressionEditor.Text, CurrentDaxProperty);

                var dest = dependsOnList.GetObjectAt(CurrentDaxProperty, UI.ExpressionEditor.SelectionStart);
                if (dest == null)
                {
                    UI.StatusLabel.Text = "Cannot navigate to symbol under cursor.";
                }
                else
                {
                    Goto(dest);
                }
            }
        }
        private static List <BuildAction> ReadActions(string InputPath)
        {
            XmlDocument File = new XmlDocument();

            File.Load(InputPath);

            XmlNode RootNode = File.FirstChild;

            if (RootNode == null || RootNode.Name != "BuildSet")
            {
                throw new Exception("Incorrect node at root of graph; expected 'BuildSet'");
            }

            XmlNode EnvironmentsNode = RootNode.SelectSingleNode("Environments");

            if (EnvironmentsNode == null)
            {
                throw new Exception("Missing Environments node under root in XML document");
            }

            // Get the current environment variables
            Dictionary <string, string> CurrentEnvironment = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase);

            foreach (System.Collections.DictionaryEntry Entry in Environment.GetEnvironmentVariables())
            {
                CurrentEnvironment[Entry.Key.ToString()] = Entry.Value.ToString();
            }

            // Read the tool environment
            Dictionary <string, XmlNode> NameToTool = new Dictionary <string, XmlNode>();
            Dictionary <string, IReadOnlyDictionary <string, string> > NameToEnvironment = new Dictionary <string, IReadOnlyDictionary <string, string> >();

            for (XmlNode EnvironmentNode = EnvironmentsNode.FirstChild; EnvironmentNode != null; EnvironmentNode = EnvironmentNode.NextSibling)
            {
                if (EnvironmentNode.Name == "Environment")
                {
                    // Read the tools nodes
                    XmlNode ToolsNode = EnvironmentNode.SelectSingleNode("Tools");
                    if (ToolsNode != null)
                    {
                        for (XmlNode ToolNode = ToolsNode.FirstChild; ToolNode != null; ToolNode = ToolNode.NextSibling)
                        {
                            if (ToolNode.Name == "Tool")
                            {
                                XmlNode Name = ToolNode.Attributes.GetNamedItem("Name");
                                if (Name != null)
                                {
                                    NameToTool.Add(Name.Value, ToolNode);
                                }
                            }
                        }
                    }

                    // Read the environment variables for this environment. Each environment has its own set of variables
                    XmlNode VariablesNode = EnvironmentNode.SelectSingleNode("Variables");
                    if (VariablesNode != null)
                    {
                        XmlNode Name = EnvironmentNode.Attributes.GetNamedItem("Name");
                        if (Name != null)
                        {
                            Dictionary <string, string> NamedEnvironment = new Dictionary <string, string>(CurrentEnvironment, StringComparer.InvariantCultureIgnoreCase);
                            for (XmlNode VariableNode = VariablesNode.FirstChild; VariableNode != null; VariableNode = VariableNode.NextSibling)
                            {
                                if (VariableNode.Name == "Variable")
                                {
                                    XmlNode VariableName = VariableNode.Attributes.GetNamedItem("Name");
                                    if (VariableName != null)
                                    {
                                        NamedEnvironment[VariableName.Value] = VariableNode.Attributes.GetNamedItem("Value").Value;
                                    }
                                }
                            }
                            NameToEnvironment[Name.Value] = NamedEnvironment;
                        }
                    }
                }
            }

            // Read all the tasks for each project, and convert them into actions
            List <BuildAction> Actions = new List <BuildAction>();

            for (XmlNode ProjectNode = RootNode.FirstChild; ProjectNode != null; ProjectNode = ProjectNode.NextSibling)
            {
                if (ProjectNode.Name == "Project")
                {
                    int SortIndex = 0;
                    Dictionary <string, BuildAction> NameToAction = new Dictionary <string, BuildAction>();
                    for (XmlNode TaskNode = ProjectNode.FirstChild; TaskNode != null; TaskNode = TaskNode.NextSibling)
                    {
                        if (TaskNode.Name == "Task")
                        {
                            XmlNode ToolNode;
                            if (NameToTool.TryGetValue(TaskNode.Attributes.GetNamedItem("Tool").Value, out ToolNode))
                            {
                                BuildAction Action = FindOrAddAction(NameToAction, TaskNode.Attributes.GetNamedItem("Name").Value, Actions);
                                Action.SortIndex = ++SortIndex;
                                TryGetAttribute(TaskNode, "Caption", out Action.Caption);

                                TryGetAttribute(ToolNode, "GroupPrefix", out Action.GroupPrefix);
                                TryGetAttribute(ToolNode, "OutputPrefix", out Action.OutputPrefix);
                                TryGetAttribute(ToolNode, "Path", out Action.ToolPath);
                                TryGetAttribute(ToolNode, "WorkingDir", out Action.WorkingDirectory);

                                string EnvironmentName;
                                if (!TryGetAttribute(ProjectNode, "Env", out EnvironmentName))
                                {
                                    Action.Environment = CurrentEnvironment;
                                }
                                else if (!NameToEnvironment.TryGetValue(EnvironmentName, out Action.Environment))
                                {
                                    throw new Exception(String.Format("Couldn't find environment '{0}'", EnvironmentName));
                                }

                                if (TryGetAttribute(ToolNode, "Params", out Action.ToolArguments))
                                {
                                    Action.ToolArguments = ExpandEnvironmentVariables(Action.ToolArguments, Action.Environment);
                                }

                                string SkipIfProjectFailed;
                                if (TryGetAttribute(TaskNode, "SkipIfProjectFailed", out SkipIfProjectFailed) && SkipIfProjectFailed == "True")
                                {
                                    Action.bSkipIfProjectFailed = true;
                                }

                                string DependsOnList;
                                if (TryGetAttribute(TaskNode, "DependsOn", out DependsOnList))
                                {
                                    foreach (string DependsOn in DependsOnList.Split(';'))
                                    {
                                        BuildAction DependsOnAction = FindOrAddAction(NameToAction, DependsOn, Actions);
                                        if (!Action.Dependencies.Contains(DependsOnAction))
                                        {
                                            Action.Dependencies.Add(DependsOnAction);
                                        }
                                        if (!DependsOnAction.Dependants.Contains(Action))
                                        {
                                            DependsOnAction.Dependants.Add(Action);
                                        }
                                    }
                                }

                                HashSet <BuildAction> VisitedActions = new HashSet <BuildAction>();
                                RecursiveIncDependents(Action, VisitedActions);

                                Action.MissingDependencyCount = Action.Dependencies.Count;
                            }
                        }
                    }

                    // Make sure there have been no actions added which were referenced but never declared
                    foreach (KeyValuePair <string, BuildAction> Pair in NameToAction)
                    {
                        if (Pair.Value.SortIndex == -1)
                        {
                            throw new Exception(String.Format("Action {0} was referenced but never declared", Pair.Key));
                        }
                    }
                }
            }
            return(Actions);
        }