public void TestLogErrorFromResources1()
 {
     RunAndCheckTaskLoggingHelper(
         (tlh) => tlh.LogErrorFromResources("MessageResource1", "foo"),
         (l) => Assert.IsTrue(l.CheckFullLog("Message from resources with arg 'foo'") == 0, "Message not found")
         );
 }
Exemplo n.º 2
0
        /// <summary>
        /// A method that will validate the integer type arguments
        /// If the min or max is set, and the value a property is set to is not within
        /// the range, the build fails
        /// </summary>
        /// <param name="switchName"></param>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <param name="value"></param>
        /// <returns>The valid integer passed converted to a string form</returns>
        protected bool ValidateInteger(string switchName, int min, int max, int value)
        {
            if (value < min || value > max)
            {
                logPrivate.LogErrorFromResources("ArgumentOutOfRange", switchName, value);
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks if the file path is valid.
        /// </summary>
        /// <param name="fileName">
        /// The filename to check.
        /// </param>
        /// <param name="log">
        /// The <see cref="TaskLoggingHelper"/> to use for logging errors.
        /// </param>
        /// <returns>
        /// True if valid, false otherwise.
        /// </returns>
        internal static Boolean CheckFilePath(String fileName,
                                              TaskLoggingHelper log)
        {
            Boolean retValue = true;
            String  errMsg   = String.Empty;

            try
            {
                errMsg = Path.GetDirectoryName(fileName);
            }
            catch (ArgumentException exAE)
            {
                errMsg   = exAE.Message;
                retValue = false;
            }
            catch (PathTooLongException exPTLE)
            {
                errMsg   = exPTLE.Message;
                retValue = false;
            }
            if (false == retValue)
            {
                log.LogErrorFromResources("InvalidPathChars", errMsg);
            }
            return(retValue);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a directory, but reports errors to the log if fails.
        /// </summary>
        /// <param name="path">
        /// The path to create.
        /// </param>
        /// <param name="log">
        /// The <see cref="TaskLoggingHelper"/> to use for logging errors.
        /// </param>
        /// <returns>
        /// True if valid, false otherwise.
        /// </returns>
        internal static Boolean SafeCreateDirectory(String path,
                                                    TaskLoggingHelper log)
        {
            Boolean retValue = true;
            String  errMsg   = String.Empty;

            if (false == Directory.Exists(path))
            {
                try
                {
                    Directory.CreateDirectory(path);
                }
                catch (UnauthorizedAccessException exUAE)
                {
                    errMsg   = exUAE.Message;
                    retValue = false;
                }
                catch (ArgumentNullException exANE)
                {
                    errMsg   = exANE.Message;
                    retValue = false;
                }
                catch (ArgumentException exAE)
                {
                    errMsg   = exAE.Message;
                    retValue = false;
                }
                catch (PathTooLongException exPTLE)
                {
                    errMsg   = exPTLE.Message;
                    retValue = false;
                }
                catch (DirectoryNotFoundException exDNFE)
                {
                    errMsg   = exDNFE.Message;
                    retValue = false;
                }
                catch (IOException exIO)
                {
                    errMsg   = exIO.Message;
                    retValue = false;
                }
                catch (NotSupportedException exNSE)
                {
                    errMsg   = exNSE.Message;
                    retValue = false;
                }
            }
            if (false == retValue)
            {
                // Let the user know.
                log.LogErrorFromResources("DirectoryCreationError", errMsg);
            }
            return(retValue);
        }
 public void TestLogErrorFromResourcesNullMessage2()
 {
     tlh = new TaskLoggingHelper(task);
     tlh.LogErrorFromResources(null, null, null, null, 0, 0, 0, 0, null);
 }