示例#1
0
        /// <summary>
        /// Create or update the tool in the build tools collection.
        /// </summary>
        /// <returns></returns>
        private bool SaveTool()
        {
            _displayNameTextBox.BackColor = Color.Empty;
            _toolPathTextBox.BackColor    = Color.Empty;

            string id =
                (_toolId != null) ? _toolId : Guid.NewGuid().ToString();

            string documentTypeString =
                _documentTypeComboBox.SelectedItem as string;

            string displayName    = _displayNameTextBox.Text.Trim();
            string toolAction     = _actionComboBox.SelectedItem as string;
            string toolPath       = _toolPathTextBox.Text.Trim();
            string toolArgs       = _toolArgsTextBox.Text.Trim();
            string userArgs       = _userArgsTextBox.Text.Trim();
            string lineParserName = String.Empty;

            if (_parserComboBox.SelectedIndex > 0)
            {
                lineParserName = _parserComboBox.SelectedItem as string;
            }

            id = MakeSafeForSerialization(id);
            documentTypeString = MakeSafeForSerialization(documentTypeString);
            displayName        = MakeSafeForSerialization(displayName);
            toolAction         = MakeSafeForSerialization(toolAction);
            toolPath           = MakeSafeForSerialization(toolPath);
            toolArgs           = MakeSafeForSerialization(toolArgs);
            userArgs           = MakeSafeForSerialization(userArgs);
            lineParserName     = MakeSafeForSerialization(lineParserName);

            bool validated = true;

            if (displayName == String.Empty)
            {
                validated = false;
                _displayNameTextBox.BackColor = Color.Yellow;
            }

            if (toolPath == String.Empty)
            {
                validated = false;
                _toolPathTextBox.BackColor = Color.Yellow;
            }

            if (!validated)
            {
                return(false);
            }

            DocumentType documentType = new DocumentType(documentTypeString);
            BuildTool    tool         = new BuildTool(id, documentType, displayName);

            tool.Action       = toolAction;
            tool.Path         = toolPath;
            tool.Args         = toolArgs;
            tool.UserArgs     = userArgs;
            tool.BuildCommand =
                _buildToolManager.GetBuildCommand(documentType, toolAction);
            tool.LineParserName = lineParserName;
            tool.LineParser     =
                _buildToolManager.GetLineParser(tool.LineParserName);

            _buildTools.AddTool(tool);

            return(true);
        }