private bool GetTestFiles()
        {
            bool ret = true;
            mTestFiles = FileItems.GetFileItems(testDirInfo);
            if (ret && mTestFiles == null)
            {
                ret = false;
                msg = "files collections is null";
            }
            if (ret && !File.Exists(mTestFiles.FileItemsfile))
            {
                ret = false;
                msg = "Meta File does not exist";
            }

            const int expectedFileCount = 2;
            if (ret && expectedFileCount != mTestFiles.FileItemList.Count)
            {
                ret = false;
                msg = string.Format("Actual file count ({0}) does not match expected ({1})",
                mTestFiles.FileItemList.Count, expectedFileCount);
            }

            return ret;
        }
Esempio n. 2
0
        private static string GetFullCommand(FileItems fileItems, string command, string parameter)
        {
            StringBuilder sb = new StringBuilder();

            DirectoryInfo sourceDirectoryInfo = new DirectoryInfo(fileItems.PathToDirectory);
            string targetDirFullPath = Path.Combine(parameter, sourceDirectoryInfo.Name);
            sb.AppendLine(String.Format("mkdir {0}", targetDirFullPath));
            string targetFileFormat = GetTargetFileFormat();

            foreach (FileItem fi in fileItems.FileItemList)
            {
                string sourceFilePath = Path.Combine(sourceDirectoryInfo.FullName, fi.Name);
                string targetFilePath = Path.Combine(targetDirFullPath, fi.CustomToString(targetFileFormat));

                sb.AppendLine(string.Format(@"{0} {3}{1}{3} {3}{2}{3}", command, sourceFilePath, targetFilePath, '"'));
            }
            return sb.ToString();
        }
Esempio n. 3
0
 private static void IncludeNewFileItems(FileItems newFileItems)
 {
     bool itemsListFoundInGroupLists = false;
     foreach (FileItems fileItems in mFileItemsList)
     {
         if (fileItems.PathToDirectory == newFileItems.PathToDirectory)
         {
             itemsListFoundInGroupLists = true;
             foreach (var newFileItem in newFileItems.FileItemList)
             {
                 if (!fileItems.CurrentListContainsFileHash(newFileItem.MD5Hash))
                 {
                     fileItems.FileItemList.Add(newFileItem);
                 }
             }
         }
     }
     if (!itemsListFoundInGroupLists)
     {
         newFileItems.FileItemsfile = Path.Combine(mGroupDirInfo.FullName, newFileItems.DirInfo.Name + "_metadata.xml");
         newFileItems.SaveToFile();
         mFileItemsList.Add(newFileItems);
     }
 }
Esempio n. 4
0
        public static FileItems GetFileItems(DirectoryInfo dirInfo, string pattern = null, DirectoryInfo altDirInfo = null)
        {
            string dirMetaFile;
            string metaFileName = string.Format("{0}_metadata.xml", dirInfo.Name);
            dirMetaFile = altDirInfo == null ?
                      Path.Combine(dirInfo.FullName, metaFileName)
                    : Path.Combine(altDirInfo.FullName, metaFileName);

            Console.WriteLine("Looking for {0}", dirMetaFile);
            FileItems fileItems;
            if (!File.Exists(dirMetaFile))
            {
                fileItems = new FileItems()
                {
                    PathToDirectory = dirInfo.FullName,
                    FileItemsfile = dirMetaFile,
                    DirInfo = dirInfo
                };

                var files = string.IsNullOrEmpty(pattern) ? dirInfo.GetFiles() : dirInfo.GetFiles(pattern);
                foreach (var file in files)
                {
                    fileItems.FileItemList.Add(new FileItem
                    {
                        Name = file.Name,
                        Size = file.Length,
                        MD5Hash = GetChecksum(file)
                    });
                }
                fileItems.SaveToFile();
                fileItems.NewMetaFileCreated = true;
            }
            else
            {
                fileItems = new FileItems();
                fileItems.DirInfo = dirInfo;
                FileItems fileItemsRead = FileItems.ReadMetadataFile(dirMetaFile);
                Regex filter = String.IsNullOrEmpty(pattern) ? null : new Regex(pattern);

                foreach (var el in fileItemsRead.FileItemList)
                {
                    if (filter == null || filter.IsMatch(el.Name))
                    {
                        fileItems.FileItemList.Add(el);
                        fileItems.PathToDirectory = dirInfo.FullName;
                    }
                }
                fileItems.NewMetaFileCreated = false;
            }
            return fileItems;
        }