Ejemplo n.º 1
0
        // For any folder name in the list , create them as a node and append them to the folder node
        private void AddFolderToChild(List<string> folderName, FolderCompareObject folder, int counter, int length)
        {
            for (int i = 0; i < folderName.Count; i++)
            {
                BaseCompareObject o = folder.GetChild(folderName[i]);
                FolderCompareObject fco;

                if (o == null)
                    fco = new FolderCompareObject(folderName[i], length, folder);
                else
                    fco = (FolderCompareObject)o;

                fco.MetaExists[counter] = true;

                if (o == null)
                    folder.AddChild(fco);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes and adds folders to the tree.
        /// </summary>
        /// <param name="folder"><see cref="FolderCompareObject"/> to process and add folders to.</param>
        /// <param name="numOfPaths">The total number of sync folders.</param>
        /// <param name="f">The <see cref="DirectoryInfo"/> to process and get folders from.</param>
        /// <param name="index">The index indicating which sync folder it belongs to.</param>
        private void ProcessFolders(FolderCompareObject folder, int numOfPaths, DirectoryInfo f, int index)
        {
            try
            {
                DirectoryInfo[] infos = f.GetDirectories();

                foreach (DirectoryInfo info in infos)
                {
                    if (_filterChain.ApplyFilter(_filter, info.FullName))
                    {
                        if (_progress != null)
                        {
                            _progress.Message = info.FullName;
                            _progress.Update();
                        }

                        BaseCompareObject o = folder.GetChild(info.Name); // Gets a child with the same name.
                        FolderCompareObject fco;
                        bool conflict = false;

                        if (o == null) // If o is null, create a new folder compare object.
                            fco = new FolderCompareObject(info.Name, numOfPaths, folder);
                        // Create a new folder compare object
                        else
                        {
                            try
                            {
                                fco = (FolderCompareObject)o; // Cast o to a FolderCompareObject.
                            }
                            catch (InvalidCastException) // Happens when a file has the same name as the folder.
                            {
                                for (int i = 0; i < numOfPaths; i++)
                                {
                                    if (o.Exists[i])
                                        _typeConflicts.Add(Path.Combine(o.GetSmartParentPath(i), o.Name));
                                }
                                folder.RemoveChild(info.Name); //Remove file object
                                fco = new FolderCompareObject(info.Name, numOfPaths, folder);
                                // Create a new folder compare object
                                conflict = true;
                                ServiceLocator.GetLogger(ServiceLocator.USER_LOG).Write(
                                    new LogData(LogEventType.FSCHANGE_CONFLICT,
                                                "Conflicted file detected " + info.FullName));
                            }
                        }

                        fco.CreationTimeUtc[index] = info.CreationTimeUtc.Ticks;
                        fco.Exists[index] = true;

                        if (o == null || conflict)
                            folder.AddChild(fco); // Add the newly created FolderCompareObject to this current folder
                    }
                }
            }
            catch (UnauthorizedAccessException e)
            {
                ServiceLocator.GetLogger(ServiceLocator.DEBUG_LOG).Write(e);
                ServiceLocator.GetLogger(ServiceLocator.USER_LOG).Write(new LogData(LogEventType.UNKNOWN, "Error retrieving contents of folder due to unauthorized access."));
            }
            catch (DirectoryNotFoundException e)
            {
                ServiceLocator.GetLogger(ServiceLocator.DEBUG_LOG).Write(e);
                ServiceLocator.GetLogger(ServiceLocator.USER_LOG).Write(new LogData(LogEventType.UNKNOWN, "Error retrieving contents of folder due to directory not being found."));
            }
        }
Ejemplo n.º 3
0
        // For any XMLCompareObjects in the list , create them as a node and append them to the folder node
        private void AddFileToChild(List<XMLCompareObject> xmlFileList, FolderCompareObject folder, int counter, int length)
        {
            for (int i = 0; i < xmlFileList.Count; i++)
            {
                BaseCompareObject o = folder.GetChild(xmlFileList[i].Name);
                FileCompareObject fco;

                if (o == null)
                    fco = new FileCompareObject(xmlFileList[i].Name, length, folder);
                else
                    fco = (FileCompareObject)o;

                fco.MetaCreationTimeUtc[counter] = xmlFileList[i].CreatedTimeUtc;
                fco.MetaHash[counter] = xmlFileList[i].Hash;
                fco.MetaLastWriteTimeUtc[counter] = xmlFileList[i].LastModifiedTimeUtc;
                fco.MetaLength[counter] = xmlFileList[i].Size;
                fco.MetaUpdated[counter] = xmlFileList[i].LastUpdatedTimeUtc;
                fco.MetaExists[counter] = true;

                if (o == null)
                    folder.AddChild(fco);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Processes and adds files to the tree.
        /// </summary>
        /// <param name="folder"><see cref="FolderCompareObject"/> to process and add files to.</param>
        /// <param name="numOfPaths">The total number of sync folders.</param>
        /// <param name="f">The <see cref="DirectoryInfo"/> to process and get files from.</param>
        /// <param name="index">The index indicating which sync folder it belongs to.</param>
        private void ProcessFiles(FolderCompareObject folder, int numOfPaths, DirectoryInfo f, int index)
        {
            try
            {
                FileInfo[] fileInfos = f.GetFiles();

                foreach (FileInfo info in fileInfos)
                {
                    if (_filterChain.ApplyFilter(_filter, info.FullName))
                    {
                        if (_progress != null)
                        {
                            _progress.Message = info.FullName;
                            _progress.Update();
                        }

                        BaseCompareObject o = folder.GetChild(info.Name); // Gets a child with the same name.
                        FileCompareObject fco = null;
                        bool conflict = false;

                        if (o == null) // If o is null, create a new file compare object
                            fco = new FileCompareObject(info.Name, numOfPaths, folder);
                        else
                        {
                            try
                            {
                                fco = (FileCompareObject)o; // Case o to a FileCompareObject is o is not null
                            }
                            catch (InvalidCastException)
                            // If invalid cast, it means there is a FolderCompareObject with the exact same name.
                            {
                                _typeConflicts.Add(info.FullName); // Add to to conflicts
                                conflict = true;
                                ServiceLocator.GetLogger(ServiceLocator.USER_LOG).Write(
                                    new LogData(LogEventType.FSCHANGE_CONFLICT,
                                                "Conflicted file detected " + info.FullName));
                            }
                        }

                        if (!conflict)
                        {
                            fco.CreationTimeUtc[index] = info.CreationTimeUtc.Ticks;
                            fco.LastWriteTimeUtc[index] = info.LastWriteTimeUtc.Ticks;
                            fco.Length[index] = info.Length;
                            fco.Exists[index] = true;

                            if (o == null)
                                folder.AddChild(fco); // Add the newly created FileCompareObject to this current folder
                        }
                    }
                }
            }
            catch (UnauthorizedAccessException e)
            {
                ServiceLocator.GetLogger(ServiceLocator.DEBUG_LOG).Write(e);
                ServiceLocator.GetLogger(ServiceLocator.USER_LOG).Write(new LogData(LogEventType.UNKNOWN, "Error retrieving contents of folder due to unauthorized access."));
            }
            catch (DirectoryNotFoundException e)
            {
                ServiceLocator.GetLogger(ServiceLocator.DEBUG_LOG).Write(e);
                ServiceLocator.GetLogger(ServiceLocator.USER_LOG).Write(new LogData(LogEventType.UNKNOWN, "Error retrieving contents of folder due to directory not being found."));
            }
        }