Example #1
0
        /// <summary>
        /// Used by a trigger to save the content of the [XML param file](https://www.microfocus.com/documentation/accurev/72/WebHelp/wwhelp/wwhimpl/js/html/wwhelp.htm#href=AccuRev_Admin/trig_param_file.html)
        /// passed to it by AccuRev to <tt>\%LOCALAPPDATA\%\\AcTools\\Param\\<trigger-command-principal-timestamp\>.xml</tt>.
        /// </summary>
        /// <param name="xmlFile">XML param file sent to the trigger by AccuRev.</param>
        /// <param name="pfcopy">[ParamFileCopy](@ref AcUtils#ParamFileCopy) enum to indicate in what manner to handle the XML param file passed by AccuRev.</param>
        /// <param name="trigger">Name of this trigger.</param>
        /// <param name="prncpl">Principal name of the user who issued the command.</param>
        /// <param name="command">AccuRev command issued.</param>
        /// <returns>\e true if operation ran successfully, \e false on error.</returns>
        /// <exception cref="Exception">caught and [logged](@ref AcUtils#AcDebug#initAcLogging)
        /// in <tt>\%LOCALAPPDATA\%\\AcTools\\Logs\\<trig_name\>-YYYY-MM-DD.log</tt> on failure to handle a range of exceptions.</exception>
        /*! \sa paramFileCopy(ParamFileCopy, string, string, string) */
        public static bool paramFileCopy(string xmlFile, ParamFileCopy pfcopy, string trigger, string prncpl, string command)
        {
            bool ret = true; // assume success

            try
            {
                if (pfcopy != ParamFileCopy.NoParamFileCopy)
                {
                    if (
                        (pfcopy == ParamFileCopy.CopyParmFileTrigTarget &&
                         entryInTrigTargetsFile(trigger, prncpl)) ||
                        (pfcopy == ParamFileCopy.CopyParmFileContinue) ||
                        (pfcopy == ParamFileCopy.CopyParmFileExitSuccess) ||
                        (pfcopy == ParamFileCopy.CopyParmFileExitFailure)
                        )
                    {
                        string localappdata = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                        string paramFolder  = Path.Combine(localappdata, "AcTools\\Param");
                        if (!Directory.Exists(paramFolder))
                        {
                            Directory.CreateDirectory(paramFolder);
                        }
                        FileInfo fileInfoXml = new FileInfo(xmlFile);
                        string   pFile;
                        if (String.IsNullOrEmpty(command))
                        {
                            // command is null in the case of server_post_promote
                            pFile = String.Format(@"{0}\{1}-{2}-{3}.xml",
                                                  paramFolder, trigger, prncpl, getStamp());
                        }
                        else
                        {
                            pFile = String.Format(@"{0}\{1}-{2}-{3}-{4}.xml",
                                                  paramFolder, trigger, command, prncpl, getStamp());
                        }

                        fileInfoXml.CopyTo(pFile, true);
                        if (pfcopy == ParamFileCopy.CopyParmFileExitSuccess)
                        {
                            Environment.Exit(0);
                        }
                        else if (pfcopy == ParamFileCopy.CopyParmFileExitFailure)
                        {
                            Environment.Exit(1);
                        }
                    }
                }
            }

            catch (Exception ecx)
            {
                Log($"Exception caught and logged in AcDebug.paramFileCopy(string, ParamFileCopy, string, string, string){Environment.NewLine}{ecx.Message}");
                ret = false;
            }

            return(ret);
        }
Example #2
0
        /// <summary>
        /// Used by the <a href="https://www.microfocus.com/documentation/accurev/72/WebHelp/wwhelp/wwhimpl/js/html/wwhelp.htm#href=AccuRev_Admin/user_auth.html">server_auth_trig</a>
        /// to save the content of the [XML param data](https://www.microfocus.com/documentation/accurev/72/WebHelp/wwhelp/wwhimpl/js/html/wwhelp.htm#href=AccuRev_Admin/trig_param_file.html)
        /// passed to it by AccuRev to <tt>\%LOCALAPPDATA\%\\AcTools\\Param\\server_auth_trig-principal-timestamp.xml</tt>.
        /// </summary>
        /// <remarks>
        /// Overloaded version used by the <a href="https://www.microfocus.com/documentation/accurev/72/WebHelp/wwhelp/wwhimpl/js/html/wwhelp.htm#href=AccuRev_Admin/user_auth.html">server_auth_trig</a>
        /// since the [XML param data](https://www.microfocus.com/documentation/accurev/72/WebHelp/wwhelp/wwhimpl/js/html/wwhelp.htm#href=AccuRev_Admin/trig_param_file.html)
        /// is sent, for security reasons, via STDIN and not in a file.
        /// </remarks>
        /// <param name="pfcopy">[ParamFileCopy](@ref AcUtils#ParamFileCopy) enum to indicate in what manner to handle the XML param data passed by AccuRev.</param>
        /// <param name="xml">String containing the XML param data.</param>
        /// <param name="trigger">Name of the trigger (\e server_auth_trig until something changes).</param>
        /// <param name="prncpl">Principal name of the user who issued the command.</param>
        /// <returns>\e true if operation ran successfully, \e false on error.</returns>
        /// <exception cref="Exception">caught and [logged](@ref AcUtils#AcDebug#initAcLogging)
        /// in <tt>\%LOCALAPPDATA\%\\AcTools\\Logs\\server_auth_trig-YYYY-MM-DD.log</tt> on failure to handle a range of exceptions.</exception>
        /*! \sa paramFileCopy(string, ParamFileCopy, string, string, string) */
        public static bool paramFileCopy(ParamFileCopy pfcopy, string xml, string trigger, string prncpl)
        {
            bool ret = true; // assume success

            try
            {
                if (pfcopy != ParamFileCopy.NoParamFileCopy)
                {
                    if (
                        (pfcopy == ParamFileCopy.CopyParmFileTrigTarget &&
                         entryInTrigTargetsFile(trigger, prncpl)) ||
                        (pfcopy == ParamFileCopy.CopyParmFileContinue) ||
                        (pfcopy == ParamFileCopy.CopyParmFileExitSuccess) ||
                        (pfcopy == ParamFileCopy.CopyParmFileExitFailure)
                        )
                    {
                        string localappdata = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                        string paramFolder  = Path.Combine(localappdata, "AcTools\\Param");
                        if (!Directory.Exists(paramFolder))
                        {
                            Directory.CreateDirectory(paramFolder);
                        }
                        string pFile = String.Format(@"{0}\{1}-{2}-{3}.xml",
                                                     paramFolder, trigger, prncpl, getStamp());
                        createParamFile(pFile, xml);
                        if (pfcopy == ParamFileCopy.CopyParmFileExitSuccess)
                        {
                            Environment.Exit(0);
                        }
                        else if (pfcopy == ParamFileCopy.CopyParmFileExitFailure)
                        {
                            Environment.Exit(1);
                        }
                    }
                }
            }

            catch (Exception ecx)
            {
                Log($"Exception caught and logged in AcDebug.paramFileCopy(ParamFileCopy, string, string, string){Environment.NewLine}{ecx.Message}");
                ret = false;
            }

            return(ret);
        }