Пример #1
0
        /// <summary>
        ///     File Make upper case Name.
        /// </summary>
        /// <param name="songTitle">File path.</param>
        /// <exception cref="FileNotFoundException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        public string FileMakeUpperCaseName(string songTitle)
        {
            try
            {
                MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name;

                songTitle = songTitle.Trim();

                if (string.IsNullOrEmpty(songTitle))
                {
                    throw new ArgumentNullException();
                }

                var    parentDirPath = new FileInfo(songTitle).DirectoryName;
                var    origFileName  = Path.GetFileName(songTitle);
                var    newFileName   = origFileName.ToUpperInvariant();
                string newDirPath;

                var comp = string.Compare(origFileName, newFileName, StringComparison.CurrentCultureIgnoreCase);

                if (comp == 0)
                {
                    OriginalDirectoryFilePathsCollection.AddItem(songTitle);
                    OriginalDirectoryFileNamesCollection.AddItem(origFileName);

                    newDirPath = Path.Combine(parentDirPath, newFileName);
                    NewDirectoryFilePathsCollection.AddItem(newDirPath);
                    NewDirectoryFileNameCollection.AddItem(newFileName);
                }
                else
                {
                    newDirPath = string.Empty;
                }

                return(newDirPath);
            }
            catch (ArgumentNullException ex)
            {
                MyMessages.ErrorMessage = "The file path is not valid.";
                MyMessages.BuildErrorString(MyMessages.NameOfClass, MyMessages.NameOfMethod, MyMessages.ErrorMessage,
                                            ex.Message);
                return(string.Empty);
            }
            catch (ArgumentException ex)
            {
                MyMessages.ErrorMessage = "The file path is not valid.";
                MyMessages.BuildErrorString(MyMessages.NameOfClass, MyMessages.NameOfMethod, MyMessages.ErrorMessage,
                                            ex.Message);
                return(string.Empty);
            }
            catch (FileNotFoundException ex)
            {
                MyMessages.ErrorMessage = "The file path is not valid.";
                MyMessages.BuildErrorString(MyMessages.NameOfClass, MyMessages.NameOfMethod, MyMessages.ErrorMessage,
                                            ex.Message);
                return(string.Empty);
            }
        }
Пример #2
0
        /// <summary>
        ///     Create Make Proper name from current directory name.
        /// </summary>
        /// <returns>
        ///     <c>true</c>, if make proper case name was directory, <c>false</c> otherwise.
        /// </returns>
        /// <param name="dirName">Directory path.</param>
        /// <exception cref="DirectoryNotFoundException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        public string DirectoryMakeProperCaseName(string dirName)
        {
            try
            {
                MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name;

                dirName = dirName.Trim();

                if (string.IsNullOrEmpty(dirName))
                {
                    throw new ArgumentNullException();
                }

                string newDirPath;
                var    parentDirName = new DirectoryInfo(dirName).Parent.FullName;
                var    origDirName   = new DirectoryInfo(dirName).Name;
                var    newDirName    = string.Empty;

                var myTI = new CultureInfo("en-US", false).TextInfo;

                var newLowerCase = myTI.ToLower(origDirName);

                newDirName = myTI.ToTitleCase(newLowerCase);

                var comp = string.Compare(origDirName, newDirName, StringComparison.CurrentCultureIgnoreCase);
                if (comp == 0)
                {
                    OriginalDirectoryFilePathsCollection.AddItem(dirName);
                    OriginalDirectoryFileNamesCollection.AddItem(origDirName);

                    newDirPath = Path.Combine(parentDirName, newDirName);
                    SongRecordProperties.NewDirectoryPath = newDirPath;
                    NewDirectoryFilePathsCollection.AddItem(newDirPath);
                    NewDirectoryFileNameCollection.AddItem(newDirName);
                }
                else
                {
                    newDirPath = string.Empty;
                }

                return(newDirPath);
            }
            catch (ArgumentNullException ex)
            {
                MyMessages.ErrorMessage = "The directory path is not valid.";
                MyMessages.BuildErrorString(MyMessages.NameOfClass, MyMessages.NameOfMethod, MyMessages.ErrorMessage,
                                            ex.Message);
                return(string.Empty);
            }
            catch (ArgumentException ex)
            {
                MyMessages.ErrorMessage = "The directory path is not valid.";
                MyMessages.BuildErrorString(MyMessages.NameOfClass, MyMessages.NameOfMethod, MyMessages.ErrorMessage,
                                            ex.Message);
                return(string.Empty);
            }
            catch (DirectoryNotFoundException ex)
            {
                MyMessages.ErrorMessage = "The directory path is not valid.";
                MyMessages.BuildErrorString(MyMessages.NameOfClass, MyMessages.NameOfMethod, MyMessages.ErrorMessage,
                                            ex.Message);
                return(string.Empty);
            }
        }