Пример #1
0
        public void CheckNullAreEqual()
        {
            var fic = new FileInfoComparer();

            Assert.IsTrue(
                fic.Equals(null, null));
        }
Пример #2
0
        public void CheckNonNullAreEqual()
        {
            var fic = new FileInfoComparer();

            Assert.IsFalse(
                fic.Equals(null, new FileInfo("c:\\dir\\file.txt")));
        }
Пример #3
0
        public static void WarnFiles(IEnumerable <FileInfo> diffList, IEnumerable <FileInfo> baseList)
        {
            FileInfoComparer fileInfoComparer = new FileInfoComparer();
            var onlyInBaseList = baseList.Except(diffList, fileInfoComparer);
            var onlyInDiffList = diffList.Except(baseList, fileInfoComparer);

            //  Go through the files and flag anything not in both lists.

            var onlyInBaseCount = onlyInBaseList.Count();

            if (onlyInBaseCount > 0)
            {
                Console.WriteLine("Warning: {0} files in base but not in diff.", onlyInBaseCount);
                Console.WriteLine("\nOnly in base files:");
                foreach (var file in onlyInBaseList)
                {
                    Console.WriteLine(file.path);
                }
            }

            var onlyInDiffCount = onlyInDiffList.Count();

            if (onlyInDiffCount > 0)
            {
                Console.WriteLine("Warning: {0} files in diff but not in base.", onlyInDiffCount);
                Console.WriteLine("\nOnly in diff files:");
                foreach (var file in onlyInDiffList)
                {
                    Console.WriteLine(file.path);
                }
            }
        }
Пример #4
0
        public void CheckAreEqual(string lhs, string rhs)
        {
            var fic = new FileInfoComparer();

            Assert.IsTrue(
                fic.Equals(new FileInfo(lhs), new FileInfo(rhs)));
        }
        public List<FileCompareInfo> GetDuplicateFiles(string sourceLocation, string comparisonLocation)
        {
            if (!Directory.Exists(sourceLocation))
            {
                throw new Exception(string.Format("Source Location doesnt exist: {0}", sourceLocation));
            }

            if (!Directory.Exists(comparisonLocation))
            {
                throw new Exception(string.Format("Comparison Location doesnt exist: {0}", comparisonLocation));
            }

            DirectoryInfo sourceDirectory = new DirectoryInfo(sourceLocation);
            DirectoryInfo comparisonDirectory = new DirectoryInfo(comparisonLocation);

            string[] extensions = new[] { ".jpg", ".bmp", ".jpeg" };

            IEnumerable<System.IO.FileInfo> sourceFiles = sourceDirectory.EnumerateFiles("*.*", System.IO.SearchOption.TopDirectoryOnly)
                                                            .Where(f => extensions.Contains(f.Extension, StringComparer.OrdinalIgnoreCase));

            IEnumerable<System.IO.FileInfo> comparisonLocationFiles = comparisonDirectory.EnumerateFiles("*.*", System.IO.SearchOption.TopDirectoryOnly)
                                                            .Where(f => extensions.Contains(f.Extension, StringComparer.OrdinalIgnoreCase));


            FileInfoComparer fileCompare = new FileInfoComparer();

            var distinctFiles = sourceFiles.Intersect(comparisonLocationFiles, fileCompare)
                .Select(t => new FileCompareInfo()
                {
                    DuplicateFileInfo = t
                }
                );

            return distinctFiles.ToList();
        }
Пример #6
0
        public void HashCodeCaseInsensitive()
        {
            const string name     = "c:\\hello\\world\\blah.txt";
            var          fic      = new FileInfoComparer();
            var          expected = fic.GetHashCode(new FileInfo(name));

            Assert.AreEqual(expected, fic.GetHashCode(new FileInfo(name.ToUpper())));
        }
Пример #7
0
        public void DictionaryKeys()
        {
            const string name = "c:\\test.txt";

            var fic  = new FileInfoComparer();
            var dict = new Dictionary <FileInfo, object>(fic);
            var info = new FileInfo(name);

            dict[info] = null;
            Assert.IsTrue(dict.ContainsKey(info));
            Assert.IsTrue(dict.ContainsKey(new FileInfo(name)));
        }
Пример #8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        public FolderComparer(string source, string destination)
        {
            if ( !(Directory.Exists (source) && Directory.Exists (destination))) throw new DirectoryNotFoundException();
            this.source = source;
            this.destination = destination;

            this.sourceDirectoryInfos = GetDirectoryInfos(this.source);
            this.destinationDirectoryInfos = GetDirectoryInfos(this.destination);

            this.sourceFileInfos = GetFileInfos(this.source);
            this.destinationFileInfos = GetFileInfos(this.destination);

            this.fileInfoComparer = new FileInfoComparer(source, destination);
            this.directoryInforComparer = new DirectoryInfoComparer(source, destination);
        }
Пример #9
0
        /// <summary>
        /// Get the relative complement
        /// Return the list of elements that are in B but not in A
        /// </summary>
        /// <param name="fisA"></param>
        /// <param name="fisB"></param>
        /// <returns></returns>
        public static IList <FileInfo> RelativeComplement(IList <FileInfo> fisA, IList <FileInfo> fisB)
        {
            // if they are both empty then the complement is nothing.
            if (null == fisA && null == fisB)
            {
                return(new List <FileInfo>());
            }

            // if we have a null A then everything in B is the relative
            // complement as they never intercet.
            if (null == fisA || !fisA.Any())
            {
                return(Distinct(fisB ?? new List <FileInfo>()));
            }

            // If B is empty then it will never intercet with A
            // so there is no complement values.
            if (null == fisB || !fisB.Any())
            {
                return(new List <FileInfo>());
            }

            // we can now go around B and find all the ones that are _not_ in A
            // A = {2,3,4}
            // B = {3,4,5}
            // RC = {5}
            var fc = new FileInfoComparer();
            var fisRelativeComplement = new HashSet <FileInfo>(fc);

            // convert to a hashSet, it is a lot faster than a List<>.Contains( ... ) ...
            // even if all we are doing is converting it back to a lis.t
            var dicA = new HashSet <FileInfo>(fisA, fc);

            foreach (var fi in fisB)
            {
                if (dicA.Contains(fi))
                {
                    continue;
                }
                fisRelativeComplement.Add(fi);
            }

            // convert it to a list
            // we know it is Distinct as it is a HashSet<>()
            return(fisRelativeComplement.ToList());
        }
Пример #10
0
        private void CompareFiles(IEnumerable<System.IO.FileInfo> files)
        {
            FileInfoComparer fileCompare = new FileInfoComparer();

            var trList = files.GroupBy(x => x, fileCompare)
            .Select(x => new FileTreeInfo()
            {
                DuplicateCount = x.Count(),
                ChildFiles = x.Select(y => y).ToList(),
                FileInfo = x.Key,
            })
            .Where(x => x.DuplicateCount > 1);

            // Flatten the list so the view can diplay it however it wants.
            var trListA = trList
                        .SelectMany(x => x.ChildFiles)
                        .Select(y => y);

            DirectoryInfoComparer dirCompare = new DirectoryInfoComparer();

            this.treeList = trListA.ToList();
        }
Пример #11
0
 public void FullNameIsProperlyChanged(string lhs, string rhs)
 {
     Assert.AreEqual(
         FileInfoComparer.FullName(new FileInfo(lhs)), rhs);
 }
Пример #12
0
 public void FullNameCaseAreKept(string given, string expected)
 {
     Assert.AreEqual(expected, FileInfoComparer.FullName(new FileInfo(given)));
 }
Пример #13
0
 public void FulleNameCannotBeNull()
 {
     Assert.Throws <ArgumentNullException>(() => FileInfoComparer.FullName(null));
 }
Пример #14
0
        public static void ListFiles()
        {
            try
            { //Get index of robot/field files from server
                WebClient webClient = new WebClient
                {
                    BaseAddress = "http://bxd.autodesk.com/Downloadables/"
                };
                List <FileInfo> webFiles = new List <FileInfo>();
                using (var reader = XmlReader.Create(webClient.OpenRead("FieldRobotIndex.xml")))
                {
                    while (reader.Read())
                    {
                        switch (reader.NodeType)
                        {
                        default:
                            break;

                        case XmlNodeType.Element:
                            FileInfo fileInfo = new FileInfo();

                            if (reader.Name == "fileList")
                            {
                                break;
                            }
                            else if (reader.Name == "field")
                            {
                                fileInfo.type = FileType.FIELD;
                            }
                            else if (reader.Name == "robot")
                            {
                                fileInfo.type = FileType.ROBOT;
                            }
                            else     //For if we ever decide to add more assets. This prevents breaking backwards compatability
                            {
                                fileInfo.type = FileType.OTHER;
                                break;
                            }

                            reader.MoveToFirstAttribute();
                            if (reader.Name == "path")
                            {
                                fileInfo.path = reader.Value;
                            }
                            reader.MoveToNextAttribute();
                            if (reader.Name == "name")
                            {
                                fileInfo.name = reader.Value;
                            }
                            webFiles.Add(fileInfo);
                            break;
                        }
                    }
                }

                //Get index of local robot/field files
                List <FileInfo> localFiles = new List <FileInfo>();
                foreach (string fieldFolder in Directory.EnumerateDirectories(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\synthesis\fields"))
                {
                    if (File.Exists(fieldFolder + @"\definition.bxdf"))
                    {
                        localFiles.Add(new FileInfo
                        {
                            type = FileType.FIELD,
                            name = fieldFolder.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries).Last()
                        });
                    }
                }
                foreach (string robotFolder in Directory.EnumerateDirectories(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\synthesis\robots"))
                {
                    if (File.Exists(robotFolder + @"\skeleton.bxdj"))
                    {
                        localFiles.Add(new FileInfo
                        {
                            type = FileType.ROBOT,
                            name = Path.GetDirectoryName(robotFolder)
                        });
                    }
                }

                var             fileInfoComparer = new FileInfoComparer();
                List <FileInfo> getQueue         = new List <FileInfo>();
                foreach (FileInfo file in webFiles)
                {
                    if ((file.type == FileType.ROBOT && File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Synthesis\Robots\" + file.name + @"\skeleton.bxdj")) ||
                        (file.type == FileType.FIELD && File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Synthesis\Fields\" + file.name + @"\definition.bxdf")))
                    {
                        Debug.WriteLine("{0} {1} checked out successfully.", (file.type == FileType.FIELD) ? "Field " : "Robot ", file.name);
                    }
                    else
                    {
                        Debug.WriteLine("{0} {1} not found. Adding to update queue.", (file.type == FileType.FIELD) ? "Field" : "Robot", file.name);
                        getQueue.Add(file);
                    }
                }

                int robotCount = getQueue.Count(x => x.type == FileType.ROBOT);
                int fieldCount = getQueue.Count(x => x.type == FileType.FIELD);


                if (robotCount != 0 || fieldCount != 0)
                {
                    if (System.Windows.Forms.MessageBox.Show(string.Format("{0}{1}{2} {3} available for you to download. Would you like to download {4} now?",
                                                                           (robotCount != 0) ? string.Format("{0} {1}", robotCount, (robotCount == 1) ? "robot" : "robots") : "",
                                                                           (fieldCount != 0 && robotCount != 0) ? " and " : "",
                                                                           (fieldCount != 0) ? string.Format("{0} {1}", fieldCount, (fieldCount == 1) ? "field" : "fields") : "",
                                                                           (fieldCount + robotCount > 1) ? "are" : "is",
                                                                           (fieldCount + robotCount > 1) ? "them" : "it"), "New Fields/Robots",
                                                             System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                    {
                        AquireFilesForm aquireFilesForm = new AquireFilesForm(getQueue, webClient);
                        aquireFilesForm.ShowDialog();
                    }
                }
            }
            catch { }
        }