示例#1
0
        public static bool Run(int buildUserAssnId, string workingDirectory)
        {
            AutoCheck autoCheck = new AutoCheck();

            autoCheck.Init(buildUserAssnId, workingDirectory);
            autoCheck.RetrieveElements();
            autoCheck.RunService();
            autoCheck.StoreResult();
            autoCheck.Cleanup();
            return(autoCheck.checkSuccessful);
        }
示例#2
0
        // validates, processes directions inside XML Message; returns true if ok to remove msg from queue
        internal bool ProcessMessage(string message, string label)
        {
            // always return true because always want to remove message from queue in this implementation
            try
            {
                // raise error if no label or message
                label   = label.Trim();
                message = message.Trim();
                if (label.Equals(String.Empty))
                {
                    SharedSupport.HandleError(new System.Exception(SharedSupport.GetLocalizedString("ServerAction_MissingLabel")));
                }
                if (message.Equals(String.Empty))
                {
                    SharedSupport.HandleError(new System.Exception(SharedSupport.GetLocalizedString("ServerAction_MissingBody")));
                }

                // xml object declarations
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(message);                   //load the string as xml
                XPathNavigator nav = ((IXPathNavigable)doc).CreateNavigator();

                // misc vars
                bool   bCheckRequested  = false;                // track if check requested
                bool   bBuildSuccessful = false;                // track if build successful
                int    buildUserAssnId  = 0;                    // build userAssignmentId
                int    checkUserAssnId  = 0;                    // check userAssignmentId
                string buildResults     = string.Empty;         // results of the build
                string checkResults     = string.Empty;         // results of the check
                string workingDirectory = string.Empty;         // working directory

                //-------------------------------------------------------------------------------------------------------------
                // evaluate label, parse xml message; extract instructions
                //-------------------------------------------------------------------------------------------------------------

                switch (label)
                {
                ////////////////////////////////////////////////////////////////
                // This is a submit action
                ////////////////////////////////////////////////////////////////
                case Constants.AM_SUBMIT_ACTION:

                    // select the serverActions
                    XPathNodeIterator serverActionsIterator = nav.Select("serverActions/serverAction");

                    // retrieve all serverAction actions from xml
                    while (serverActionsIterator.MoveNext())
                    {
                        // perform the appropriate action evaluating the serverAction attribute
                        string actionCommand = serverActionsIterator.Current.GetAttribute("name", doc.NamespaceURI).ToString().Trim();
                        switch (actionCommand)
                        {
                        //////////////////////////////////////////////////////////////
                        // AutoBuild
                        /////////////////////////////////////////////////////////////
                        case Constants.AM_BUILD:
                            // grab the userAssignmentId from the xml
                            buildUserAssnId = Convert.ToInt32(serverActionsIterator.Current.Value.ToString());

                            /////////////////////////////////////////////////
                            // extensibility: add custom parameters here
                            /////////////////////////////////////////////////
                            break;

                        /////////////////////////////////////////////////////////////
                        // AutoCheck
                        /////////////////////////////////////////////////////////////
                        case Constants.AM_CHECK:
                            // set check flag
                            bCheckRequested = true;

                            // grab the userAssignmentId from the xml
                            checkUserAssnId = Convert.ToInt32(serverActionsIterator.Current.Value.ToString());

                            /////////////////////////////////////////////////
                            // extensibility: add custom parameters here
                            /////////////////////////////////////////////////
                            break;

                        /////////////////////////////////////////////////
                        // extensibility: add future submit actions here
                        /////////////////////////////////////////////////
                        // 1. load all actions from ServerActions table
                        // 2. loop actions; do any match xml serverAction element?
                        // 3. if so, retrieve parameters from ServerActions
                        // 4. make 'late bound' call to proper class, method
                        /////////////////////////////////////////////////

                        default:
                            break;
                        }
                    }

                    break;

                /////////////////////////////////////////////////
                // extensibility: add future actions here
                /////////////////////////////////////////////////

                default:
                    throw new System.NotImplementedException(SharedSupport.GetLocalizedString("ServerAction_ActionNotImplemented"));
                }

                //-------------------------------------------------------------------------------------------------------------
                // execute instructions from xml message in proper order
                //-------------------------------------------------------------------------------------------------------------
                // perform prep work, execute build, record results; returns true if successful
                // we always do the build: necessary for check and expected by custom actions

                // set the working directory
                workingDirectory = getUserWorkingDirectory();

                ////////////////////////////////////////////
                // Perform AutoBuild
                ////////////////////////////////////////////

                // check to make sure we have a valid userAssignmentId
                if (buildUserAssnId == 0)
                {
                    if (checkUserAssnId == 0)
                    {
                        // raise error
                        SharedSupport.HandleError(new System.Exception(SharedSupport.GetLocalizedString("ServerAction_MissingUserAssignmentElement")));
                    }
                    else
                    {
                        // set the buildUserAssnId = check
                        buildUserAssnId = checkUserAssnId;
                    }
                }

                // raise error if no buildUserAssnId
                if (buildUserAssnId <= 0)
                {
                    SharedSupport.HandleError(new System.Exception(SharedSupport.GetLocalizedString("ServerAction_MissingUserAssignmentElement")));
                }

                // raise error if build disabled on the server
                if (!Convert.ToBoolean(SharedSupport.GetSetting(Constants.AUTOBUILD_SETTING)))
                {
                    SharedSupport.HandleError(new System.Exception(SharedSupport.GetLocalizedString("ServerAction_BuildDisabled")));
                }

                // delete any previous user assignment detail records for this userassignment and detail type
                deleteUserAssignmentDetails(buildUserAssnId, Constants.AUTO_COMPILE_DETAILTYPE);

                bBuildSuccessful = AutoBuild.Run(buildUserAssnId, workingDirectory);

                // was check requested?
                if (bCheckRequested)
                {
                    ////////////////////////////////////////////
                    // Perform AutoCheck
                    ////////////////////////////////////////////

                    // raise error if no checkUserAssnId
                    if (checkUserAssnId <= 0)
                    {
                        SharedSupport.HandleError(new System.Exception(SharedSupport.GetLocalizedString("ServerAction_MissingUserAssignmentElement")));
                    }

                    // check that checkUserAssnId = buildUserAssnId;
                    if (checkUserAssnId != buildUserAssnId)
                    {
                        // raise error
                        SharedSupport.HandleError(new System.Exception(SharedSupport.GetLocalizedString("ServerAction_DifferentUserAssignmentIDs")));
                    }
                    else
                    {
                        // did the build execute ok if it was requested?
                        if (bBuildSuccessful)
                        {
                            // raise error if check disabled on the server
                            if (!Convert.ToBoolean(SharedSupport.GetSetting(Constants.AUTOCHECK_SETTING)))
                            {
                                SharedSupport.HandleError(new System.Exception(SharedSupport.GetLocalizedString("ServerAction_CheckDisabled")));
                            }

                            AutoCheck.Run(buildUserAssnId, workingDirectory);
                        }
                    }
                }
                ////////////////////////////////////////////
                // extensibility: CUSTOM ACTIONS
                ////////////////////////////////////////////
            }
            catch (System.Exception ex)
            {
                SharedSupport.LogMessage(ex.Message + " " + SharedSupport.GetLocalizedString("ServerAction_GeneralProcessError") + " " + label + " " + SharedSupport.GetLocalizedString("ServerAction_GeneralProcessErrorBody") + " " + message + " ", SharedSupport.GetLocalizedString("ServerAction_MethodName"), System.Diagnostics.EventLogEntryType.Warning);
            }

            // returning true here ensures message is removed from the queue
            return(true);
        }