예제 #1
0
파일: Dir.cs 프로젝트: mcskik/Utilities
        /// <summary>
        /// Append directory level information into the specified DataTable.
        /// </summary>
        /// <param name="qualifier">Top level directory.</param>
        /// <param name="dirs">Work in progress collection of directories.</param>
        /// <param name="estimate">Number of directory entries found. Used for future estimating.</param>
        public void DirLevel(string qualifier, string directory, ref List <string> dirs, ref long estimate)
        {
            string spec;
            string path;
            string name;

            path = directory;
            if (directory.Length > qualifier.Length)
            {
                directory = directory.Substring(qualifier.Length);
            }
            else
            {
                directory = string.Empty;
            }
            try
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(path);
                directoryInfo.Refresh();
                if (DirectoryExclusionsHelper.AllowDirectory(path))
                {
                    DirectoryInfo[] directoryInfoArray = directoryInfo.GetDirectories();
                    for (int row = 0; row < directoryInfoArray.Length; row++)
                    {
                        try
                        {
                            name = directoryInfoArray[row].Name;
                            spec = path + Path.DirectorySeparatorChar.ToString() + name;
                            if (DirectoryExclusionsHelper.AllowDirectory(spec))
                            {
                                if (directoryInfoArray[row].Exists)
                                {
                                    dirs.Add(spec);
                                    DirectoryEntry entry = new DirectoryEntry();
                                    entry.StdHlq        = qualifier.Trim();
                                    entry.StdDir        = directory.Trim();
                                    entry.StdFile       = name.Trim();
                                    entry.StdSize       = 0;
                                    entry.StdDate       = System.DateTime.Parse("01/01/2000");
                                    entry.StdType       = "dir";
                                    entry.CtlComparison = string.Empty;
                                    directoryListing.Add(entry);
                                    estimate += entry.StdSize;
                                    SignalUpdateProgress("DirList");
                                }
                            }
                        }
                        catch (OleDbException oExceptionA)
                        {
                            System.Diagnostics.Debug.WriteLine(oExceptionA.Errors[0].Message);
                        }
                        if (action == "Cancel")
                        {
                            break;
                        }
                    }
                    FileInfo[] fileInfoArray = directoryInfo.GetFiles();
                    for (int row = 0; row < fileInfoArray.Length; row++)
                    {
                        try
                        {
                            name = fileInfoArray[row].Name;
                            spec = path + Path.DirectorySeparatorChar.ToString() + name;
                            if (fileInfoArray[row].Exists)
                            {
                                string ext = Path.GetExtension(spec);
                                if (ext.StartsWith("."))
                                {
                                    if (ext.Length > 1)
                                    {
                                        ext = ext.Substring(1);
                                    }
                                    else
                                    {
                                        ext = string.Empty;
                                    }
                                }
                                if (MonitoredTypesHelper.AllowFile(spec, true))
                                {
                                    DirectoryEntry entry = new DirectoryEntry();
                                    entry.StdHlq        = qualifier.Trim();
                                    entry.StdDir        = directory.Trim();
                                    entry.StdFile       = name.Trim();
                                    entry.StdSize       = fileInfoArray[row].Length;
                                    entry.StdDate       = fileInfoArray[row].LastWriteTime;
                                    entry.StdType       = ext;
                                    entry.CtlComparison = string.Empty;
                                    directoryListing.Add(entry);
                                    estimate += entry.StdSize;
                                    SignalUpdateProgress("DirList");
                                }
                            }
                        }
                        catch (OleDbException exceptionB)
                        {
                            System.Diagnostics.Debug.WriteLine(exceptionB.Errors[0].Message);
                        }
                        if (action == "Cancel")
                        {
                            break;
                        }
                    }
                }
            }
            catch (DirectoryNotFoundException oExceptionNF)
            {
                System.Diagnostics.Debug.WriteLine(oExceptionNF.Message);
            }
            finally
            {
            }
        }
예제 #2
0
 private void XEditLayouts(DirectoryInfo targetDirectory)
 {
     if (DirectoryExclusionsHelper.AllowDirectory(targetDirectory.FullName))
     {
         _log.WriteLn();
         _log.WriteTimedMsg("000", "I", String.Format(@"Global Change Layout Directory : ""{0}""", targetDirectory.ToString()));
         foreach (FileInfo fi in targetDirectory.GetFiles())
         {
             if (_action != "Cancel")
             {
                 string targetFileName = string.Empty;
                 try
                 {
                     targetFileName = fi.Name;
                     try
                     {
                         string fileSpec = fi.FullName;
                         EditLayoutFile(fileSpec);
                     }
                     catch (Exception ex)
                     {
                         _log.WriteLn();
                         _log.WriteTimedMsg("000", "E", String.Format(@"{0} - Error : {1}{2}", targetFileName, Environment.NewLine, ex.Message));
                         _log.WriteLn();
                     }
                 }
                 catch (Exception ex2)
                 {
                     _log.WriteLn();
                     _log.WriteTimedMsg("000", "E", String.Format(@"{0} - Target File (Name too long) Error : {1}{2}", targetFileName, Environment.NewLine, ex2.Message));
                     _log.WriteLn();
                 }
             }
         }
         foreach (DirectoryInfo di in targetDirectory.GetDirectories())
         {
             if (_action != "Cancel")
             {
                 try
                 {
                     if (DirectoryExclusionsHelper.AllowDirectory(di.FullName))
                     {
                         XEditLayouts(di);
                     }
                 }
                 catch (Exception ex)
                 {
                     _log.WriteLn();
                     _log.WriteTimedMsg("000", "E", String.Format(@"{0} - Target Directory (Name too long) Error : {1}{2}", di.Name, Environment.NewLine, ex.Message));
                     _log.WriteLn();
                 }
             }
         }
     }
     //Check if user has chosen to cancel run.
     if (_action == "Cancel")
     {
         _log.WriteTimedMsg("000", "I", String.Format(@"XEditLayouts cancelled"));
         return;
     }
 }
예제 #3
0
        /// <summary>
        /// Append directory level information into the specified DataTable.
        /// </summary>
        /// <param name="qualifier">Top level directory.</param>
        /// <param name="dirs">Work in progress collection of directories.</param>
        /// <param name="estimate">Number of directory entries found. Used for future estimating.</param>
        public void DirLevel(string qualifier, string directory, ref List <string> dirs, ref long estimate)
        {
            string spec;
            string path;
            string name;

            path = directory;
            if (directory.Length > qualifier.Length)
            {
                directory = directory.Substring(qualifier.Length);
            }
            else
            {
                directory = string.Empty;
            }
            try
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(path);
                directoryInfo.Refresh();
                if (DirectoryExclusionsHelper.AllowDirectory(path))
                {
                    DirectoryInfo[] directoryInfoArray = directoryInfo.GetDirectories();
                    for (int row = 0; row < directoryInfoArray.Length; row++)
                    {
                        try
                        {
                            name = directoryInfoArray[row].Name;
                            spec = path + Path.DirectorySeparatorChar.ToString() + name;
                            if (DirectoryExclusionsHelper.AllowDirectory(spec))
                            {
                                if (directoryInfoArray[row].Exists)
                                {
                                    dirs.Add(spec);
                                    AdvancedDirectoryEntry entry = new AdvancedDirectoryEntry();
                                    entry.StdHlq     = qualifier.Trim();
                                    entry.StdDir     = directory.Trim();
                                    entry.StdFile    = name.Trim();
                                    entry.StdSize    = 0;
                                    entry.StdDate    = System.DateTime.Parse("01/01/2000");
                                    entry.SourceDate = entry.StdDate;
                                    entry.TargetDate = entry.StdDate;
                                    entry.SourceFile = entry.StdFile;
                                    entry.TargetFile = entry.StdFile;
                                    entry.StdType    = "dir";
                                    string matchAfter = string.Empty;
                                    entry.FolderGroup = GetFolderGroup(spec, ref matchAfter);
                                    string matchSpec = GetMatchPart(spec, matchAfter);
                                    entry.FolderGroupMatchPath     = matchSpec;
                                    entry.FolderGroupMatchStem     = matchSpec;
                                    entry.FolderGroupMatchFileSpec = matchSpec;
                                    entry.FolderGroupFullPath      = spec;
                                    entry.FolderGroupFullStem      = spec;
                                    entry.FolderGroupFullFileSpec  = spec;
                                    entry.CtlComparison            = string.Empty;
                                    directoryListing.Add(entry);
                                    estimate += entry.StdSize;
                                    SignalUpdateProgress("DirList", entry.StdSize);
                                }
                            }
                        }
                        catch (OleDbException oExceptionA)
                        {
                            System.Diagnostics.Debug.WriteLine(oExceptionA.Errors[0].Message);
                        }
                        if (Interrupt.Reason == "Cancel")
                        {
                            break;
                        }
                    }
                    FileInfo[] fileInfoArray = directoryInfo.GetFiles();
                    for (int row = 0; row < fileInfoArray.Length; row++)
                    {
                        try
                        {
                            name = fileInfoArray[row].Name;
                            spec = path + Path.DirectorySeparatorChar.ToString() + name;
                            if (fileInfoArray[row].Exists)
                            {
                                string fullExt = Path.GetExtension(spec);
                                string ext     = fullExt;
                                if (ext.StartsWith("."))
                                {
                                    if (ext.Length > 1)
                                    {
                                        ext = ext.Substring(1);
                                    }
                                    else
                                    {
                                        ext = string.Empty;
                                    }
                                }
                                if (MonitoredTypesHelper.AllowFile(spec, monitoredTypesOnly))
                                {
                                    AdvancedDirectoryEntry entry = new AdvancedDirectoryEntry();
                                    entry.StdHlq     = qualifier.Trim();
                                    entry.StdDir     = directory.Trim();
                                    entry.StdFile    = name.Trim();
                                    entry.StdSize    = fileInfoArray[row].Length;
                                    entry.StdDate    = fileInfoArray[row].LastWriteTime;
                                    entry.SourceDate = entry.StdDate;
                                    entry.TargetDate = entry.StdDate;
                                    entry.SourceFile = entry.StdFile;
                                    entry.TargetFile = entry.StdFile;
                                    entry.StdType    = ext;
                                    string matchAfter = string.Empty;
                                    entry.FolderGroup          = GetFolderGroup(spec, ref matchAfter);
                                    entry.FolderGroupMatchPath = GetMatchPart(fileInfoArray[row].DirectoryName, matchAfter);
                                    string matchSpec = GetMatchPart(spec, matchAfter);
                                    string matchStem = RemoveExt(matchSpec, fullExt);
                                    entry.FolderGroupMatchStem     = matchStem;
                                    entry.FolderGroupMatchFileSpec = matchSpec;
                                    entry.FolderGroupFullPath      = fileInfoArray[row].DirectoryName;
                                    entry.FolderGroupFullStem      = RemoveExt(spec, fullExt);
                                    entry.FolderGroupFullFileSpec  = spec;
                                    entry.CtlComparison            = string.Empty;
                                    directoryListing.Add(entry);
                                    estimate += entry.StdSize;
                                    SignalUpdateProgress("DirList", entry.StdSize);
                                }
                            }
                        }
                        catch (OleDbException exceptionB)
                        {
                            System.Diagnostics.Debug.WriteLine(exceptionB.Errors[0].Message);
                        }
                        if (Interrupt.Reason == "Cancel")
                        {
                            break;
                        }
                    }
                }
            }
            catch (DirectoryNotFoundException oExceptionNF)
            {
                System.Diagnostics.Debug.WriteLine(oExceptionNF.Message);
            }
            finally
            {
            }
        }
예제 #4
0
 private void XCopyModels(DirectoryInfo sourceDirectory, DirectoryInfo targetDirectory)
 {
     if (DirectoryExclusionsHelper.AllowDirectory(sourceDirectory.FullName))
     {
         if (!Directory.Exists(targetDirectory.FullName))
         {
             Directory.CreateDirectory(targetDirectory.FullName);
         }
         _log.WriteLn();
         _log.WriteTimedMsg("000", "I", String.Format(@"Copy From : ""{0}""", sourceDirectory.ToString()));
         _log.WriteTimedMsg("000", "I", String.Format(@"Copy To   : ""{0}""", targetDirectory.ToString()));
         foreach (FileInfo fi in sourceDirectory.GetFiles())
         {
             if (true)
             {
                 if (_action != "Cancel")
                 {
                     string sourceFileName  = fi.Name;
                     string sourceClassName = fi.Name;
                     string ext             = fi.Extension;
                     int    pos             = sourceClassName.LastIndexOf(ext);
                     if (pos != -1)
                     {
                         sourceClassName = sourceClassName.Substring(0, pos);
                     }
                     string targetClassName = sourceClassName + MODEL_CLASS_SUFFIX;
                     string targetFileName  = targetClassName + ext;
                     _apiToModelClassNameMapping.Add(sourceClassName, targetClassName);
                     try
                     {
                         string   targetFile     = System.IO.Path.Combine(targetDirectory.ToString(), targetFileName);
                         FileInfo targetFileInfo = new FileInfo(targetFile);
                         if (true)
                         {
                             try
                             {
                                 if (targetFileInfo.Exists)
                                 {
                                     targetFileInfo.IsReadOnly = false;
                                 }
                                 fi.CopyTo(System.IO.Path.Combine(targetDirectory.ToString(), targetFileName), true);
                                 targetFileInfo = new FileInfo(targetFile);
                                 if (targetFileInfo.Exists)
                                 {
                                     targetFileInfo.IsReadOnly = false;
                                 }
                                 _log.WriteTimedMsg("000", "I", String.Format(@"{0} - Copied", targetFileName));
                             }
                             catch (Exception ex)
                             {
                                 _log.WriteLn();
                                 _log.WriteTimedMsg("000", "E", String.Format(@"{0} - Error : {1}{2}", targetFileName, Environment.NewLine, ex.Message));
                                 _log.WriteLn();
                             }
                         }
                     }
                     catch (Exception ex2)
                     {
                         _log.WriteLn();
                         _log.WriteTimedMsg("000", "E", String.Format(@"{0} - Target File (Name too long) Error : {1}{2}", targetFileName, Environment.NewLine, ex2.Message));
                         _log.WriteLn();
                     }
                 }
             }
         }
         foreach (DirectoryInfo di in sourceDirectory.GetDirectories())
         {
             if (_action != "Cancel")
             {
                 try
                 {
                     if (DirectoryExclusionsHelper.AllowDirectory(di.FullName))
                     {
                         DirectoryInfo targetDirectoryInfo = targetDirectory.CreateSubdirectory(di.Name);
                         XCopyModels(di, targetDirectoryInfo);
                     }
                 }
                 catch (Exception ex)
                 {
                     _log.WriteLn();
                     _log.WriteTimedMsg("000", "E", String.Format(@"{0} - Target Directory (Name too long) Error : {1}{2}", di.Name, Environment.NewLine, ex.Message));
                     _log.WriteLn();
                 }
             }
         }
     }
     //Check if user has chosen to cancel run.
     if (_action == "Cancel")
     {
         _log.WriteTimedMsg("000", "I", String.Format(@"XCopyModels cancelled"));
         return;
     }
 }
예제 #5
0
 private void XEditAll(DirectoryInfo sourceDirectory)
 {
     if (DirectoryExclusionsHelper.AllowDirectory(sourceDirectory.FullName))
     {
         _foldersSearchedCount++;
         //_log.WriteLn();
         //_log.WriteTimedMsg("000", "I", String.Format(@"Global Change All Folders : {0}", sourceDirectory.ToString()));
         int currentFilesChanged = _filesChangedCount;
         foreach (FileInfo fi in sourceDirectory.GetFiles())
         {
             if (_action != "Cancel")
             {
                 string sourceFileName = string.Empty;
                 try
                 {
                     sourceFileName = fi.Name;
                     try
                     {
                         string fileSpec = fi.FullName;
                         if (IsTextFile(fileSpec))
                         {
                             int currentLinesChanged = _linesChangedCount;
                             EditTextFile(fileSpec);
                             if (_linesChangedCount > currentLinesChanged)
                             {
                                 _filesChangedCount++;
                             }
                         }
                     }
                     catch (Exception ex)
                     {
                         _log.WriteLn();
                         _log.WriteTimedMsg("000", "E", String.Format(@"{0} - Error : {1}{2}", sourceFileName, Environment.NewLine, ex.Message));
                         _log.WriteLn();
                     }
                 }
                 catch (Exception ex2)
                 {
                     _log.WriteLn();
                     _log.WriteTimedMsg("000", "E", String.Format(@"{0} - Source File (Name too long) Error : {1}{2}", sourceFileName, Environment.NewLine, ex2.Message));
                     _log.WriteLn();
                 }
             }
         }
         if (_filesChangedCount > currentFilesChanged)
         {
             _foldersChangedCount++;
         }
         foreach (DirectoryInfo di in sourceDirectory.GetDirectories())
         {
             if (_action != "Cancel")
             {
                 try
                 {
                     if (DirectoryExclusionsHelper.AllowDirectory(di.FullName))
                     {
                         XEditAll(di);
                     }
                 }
                 catch (Exception ex)
                 {
                     _log.WriteLn();
                     _log.WriteTimedMsg("000", "E", String.Format(@"{0} - Source Directory (Name too long) Error : {1}{2}", di.Name, Environment.NewLine, ex.Message));
                     _log.WriteLn();
                 }
             }
         }
     }
     //Check if user has chosen to cancel run.
     if (_action == "Cancel")
     {
         _log.WriteTimedMsg("000", "I", String.Format(@"XEditAll cancelled"));
         return;
     }
 }
예제 #6
0
        private void XCopyAll(DirectoryInfo sourceDirectory)
        {
            CurrentPath = sourceDirectory.FullName;
            string        targetDir       = DeriveFullTargetDirectory(sourceDirectory.FullName);
            DirectoryInfo targetDirectory = new DirectoryInfo(targetDir);

            if (!Directory.Exists(targetDirectory.FullName))
            {
                Directory.CreateDirectory(targetDirectory.FullName);
            }
            if (DirectoryExclusionsHelper.AllowDirectory(sourceDirectory.FullName))
            {
                _log.WriteLn();
                string symbolicTargetDirectory = ExtractSymbolicTarget(targetDir);
                _log.WriteTimedMsg("000", "I", String.Format(@"{0} : Copy Directory To : ""{1}""", symbolicTargetDirectory, targetDirectory.ToString()));
                _directoriesCopiedCount++;
                foreach (FileInfo fi in sourceDirectory.GetFiles())
                {
                    if (_action != "Cancel")
                    {
                        string sourceFileSpec = fi.FullName;
                        CurrentPath = sourceFileSpec;
                        string sourceFileName = fi.Name;
                        string targetFileSpec = DeriveFullTargetFile(sourceFileSpec);
                        if (targetFileSpec != sourceFileSpec)
                        {
                            try
                            {
                                try
                                {
                                    if (File.Exists(targetFileSpec))
                                    {
                                        FileInfo targetFileInfo = new FileInfo(targetFileSpec);
                                        if (targetFileInfo.Exists)
                                        {
                                            targetFileInfo.IsReadOnly = false;
                                        }
                                    }
                                    FileHelper.PathCheck(targetFileSpec);
                                    fi.CopyTo(targetFileSpec, true);
                                    if (File.Exists(targetFileSpec))
                                    {
                                        FileInfo targetFileInfo = new FileInfo(targetFileSpec);
                                        if (targetFileInfo.Exists)
                                        {
                                            targetFileInfo.IsReadOnly = false;
                                        }
                                    }
                                    string symbolicTargetFileSpec = ExtractSymbolicTarget(targetFileSpec);
                                    _log.WriteTimedMsg("000", "I", String.Format(@"{0} : File Copied To : {1}", symbolicTargetFileSpec, targetFileSpec));
                                    _filesCopiedCount++;
                                }
                                catch (Exception ex)
                                {
                                    _log.WriteLn();
                                    _log.WriteTimedMsg("000", "E", String.Format(@"{0} - File Copy Error : {1}{2}", targetFileSpec, Environment.NewLine, ex.Message));
                                    _log.WriteLn();
                                }
                            }
                            catch (Exception ex)
                            {
                                _log.WriteLn();
                                _log.WriteTimedMsg("000", "E", String.Format(@"{0} - Error : {1}{2}", sourceFileSpec, Environment.NewLine, ex.Message));
                                _log.WriteLn();
                            }
                        }
                    }
                }
                foreach (DirectoryInfo di in sourceDirectory.GetDirectories())
                {
                    if (_action != "Cancel")
                    {
                        try
                        {
                            if (DirectoryExclusionsHelper.AllowDirectory(di.FullName))
                            {
                                XCopyAll(di);
                            }
                        }
                        catch (Exception ex)
                        {
                            _log.WriteLn();
                            _log.WriteTimedMsg("000", "E", String.Format(@"{0} - Target Directory (Name too long) Error : {1}{2}", di.Name, Environment.NewLine, ex.Message));
                            _log.WriteLn();
                        }
                    }
                }
            }
            //Check if user has chosen to cancel run.
            if (_action == "Cancel")
            {
                _log.WriteTimedMsg("000", "I", String.Format(@"XCopyAll cancelled"));
                return;
            }
        }