Example #1
0
        /// <summary>
        /// read a list of path + files in source ini path
        /// </summary>
        private Dictionary <DirectoryInfo, List <FileInfo> > GetLocalFiles()
        {
            _logger.Write(string.Format("Scanning {0}...", _ini.SourcePath));

            var filesInPath = DirectoryExtension.GetFilesByExt(_ini.SourcePath, _ini.SearchPattern, ',');
            var sourceFiles = filesInPath.OrderBy(p => p)
                              .GroupBy(p => Path.GetDirectoryName(p))
                              .ToDictionary(p => new DirectoryInfo(p.Key), p => p.Select(f => new FileInfo(f)).ToList());

            var lengthSum = filesInPath.Sum(p => new FileInfo(p).Length);

            _logger.Write(string.Format("{0} folders, {1} files, {2}", sourceFiles.Count, filesInPath.Count, lengthSum.ToFileSize()));

            return(sourceFiles);
        }
Example #2
0
        //private object FindCreateMegaRoot(IEnumerable<INode> nodes, string v)
        //{
        //    GetPathTokens();

        //    return null;
        //}

        //private static IEnumerable<string> SplitSubPaths(string fullPath)
        //{
        //    var paths = (fullPath ?? string.Empty).Split(Path.DirectorySeparatorChar).Where(p => !string.IsNullOrWhiteSpace(p));
        //    return paths;
        //}


        //private void BuildNodeTree(IEnumerable<INode> nodes)
        //{

        //    INode root = nodes.Single(x => x.Type == NodeType.Root);



        //}



        //public void Sync(IEnumerable<INode> nodes, string megaRoot, string localRoot)
        //{
        //    FindMegaFolder(nodes, megaRoot);

        //}

        //private INode FindMegaFolder(IEnumerable<INode> nodes, string folderName)
        //{
        //    string parentId =  nodes.FirstOrDefault(x => x.Type == NodeType.Root)?.Id ;
        //    var tokens = folderName.Split('\\');
        //    for (int i = 0; i < tokens.Length; i++)
        //    {
        //        var folderNode = FindMegaFolder(nodes, tokens[i], parentId);
        //        if (folderNode == null)
        //            return null;
        //        if (i == (tokens.Length - 1))
        //            return folderNode;

        //        parentId = folderNode.Id;

        //    }
        //    return null;
        //}

        //private INode FindMegaFolder(IEnumerable<INode> nodes, string folderName, string parentId)
        //{
        //    return nodes.FirstOrDefault(p => p.Type == NodeType.Directory && p.ParentId == parentId && p.Name == folderName);
        //}



        /// <summary>
        /// read a list of path + files in source ini path
        /// </summary>
        private Dictionary <DirectoryInfo, List <FileInfo> > GetLocalFiles(string root)
        {
            //   _logger.Write(string.Format("Scanning {0}...", _ini.SourcePath));

            //var srcPath = @"D:\tmp\mega-photos-test";

            var filesInPath = DirectoryExtension.GetFilesByExt(root, "jpg", ',');
            var sourceFiles = filesInPath.OrderBy(p => p)
                              .GroupBy(p => Path.GetDirectoryName(p))
                              .ToDictionary(p => new DirectoryInfo(p.Key), p => p.Select(f => new FileInfo(f)).ToList());

            var lengthSum = filesInPath.Sum(p => new FileInfo(p).Length);

            // _logger.Write(string.Format("{0} folders, {1} files, {2}", sourceFiles.Count, filesInPath.Count, lengthSum.ToFileSize()));

            return(sourceFiles);
        }