private void BuildDirNode(CloudFileDirectory cloudDir, DirNode dirNode)
        {
            cloudDir.FetchAttributes(options: HelperConst.DefaultFileOptions);
            dirNode.LastWriteTime = cloudDir.Properties.LastWriteTime;
            dirNode.CreationTime  = cloudDir.Properties.CreationTime;
            dirNode.SMBAttributes = cloudDir.Properties.NtfsAttributes;

            if (cloudDir.Metadata.Count > 0)
            {
                dirNode.Metadata = new Dictionary <string, string>(cloudDir.Metadata);
            }

            foreach (IListFileItem item in cloudDir.ListFilesAndDirectories(HelperConst.DefaultFileOptions))
            {
                CloudFile          cloudFile   = item as CloudFile;
                CloudFileDirectory subCloudDir = item as CloudFileDirectory;

                if (cloudFile != null)
                {
                    // Cannot fetch attributes while listing, so do it for each cloud file.
                    cloudFile.FetchAttributes(options: HelperConst.DefaultFileOptions);

                    FileNode fileNode = new FileNode(cloudFile.Name);
                    this.BuildFileNode(cloudFile, fileNode);
                    dirNode.AddFileNode(fileNode);
                }
                else if (subCloudDir != null)
                {
                    DirNode subDirNode = new DirNode(subCloudDir.Name);
                    this.BuildDirNode(subCloudDir, subDirNode);
                    dirNode.AddDirNode(subDirNode);
                }
            }
        }
Esempio n. 2
0
        private void GenerateDir(DirNode dirNode, CloudFileDirectory cloudFileDir, string parentPath)
        {
            string dirPath = Path.Combine(parentPath, dirNode.Name);

            DMLibDataHelper.CreateLocalDirIfNotExists(dirPath);
            cloudFileDir.CreateIfNotExists(HelperConst.DefaultFileOptions);

            if (null != cloudFileDir.Parent)
            {
                if (null != dirNode.SMBAttributes)
                {
                    cloudFileDir.Properties.NtfsAttributes = dirNode.SMBAttributes;
                }

                if (dirNode.CreationTime.HasValue)
                {
                    cloudFileDir.Properties.CreationTime = dirNode.CreationTime;
                }
                if (dirNode.LastWriteTime.HasValue)
                {
                    cloudFileDir.Properties.LastWriteTime = dirNode.LastWriteTime;
                }
                if (null != dirNode.PortableSDDL)
                {
                    cloudFileDir.FilePermission = dirNode.PortableSDDL;
                }
                cloudFileDir.SetProperties(HelperConst.DefaultFileOptions);

                cloudFileDir.FetchAttributes(null, HelperConst.DefaultFileOptions);

                dirNode.CreationTime  = cloudFileDir.Properties.CreationTime;
                dirNode.LastWriteTime = cloudFileDir.Properties.LastWriteTime;

                if ((null != dirNode.Metadata) &&
                    (dirNode.Metadata.Count > 0))
                {
                    cloudFileDir.Metadata.Clear();

                    foreach (var keyValuePair in dirNode.Metadata)
                    {
                        cloudFileDir.Metadata.Add(keyValuePair);
                    }

                    cloudFileDir.SetMetadata(null, HelperConst.DefaultFileOptions);
                }
            }

            foreach (var subDir in dirNode.DirNodes)
            {
                CloudFileDirectory subCloudFileDir = cloudFileDir.GetDirectoryReference(subDir.Name);
                this.GenerateDir(subDir, subCloudFileDir, dirPath);
            }

            foreach (var file in dirNode.FileNodes)
            {
                CloudFile cloudFile = cloudFileDir.GetFileReference(file.Name);
                this.GenerateFile(file, cloudFile, dirPath);
            }
        }
        public static FileSystemEntry CreateDictionaryEntry(CloudFileDirectory directory)
        {
            directory.FetchAttributes();
            DictionaryEntry retDictionary = new DictionaryEntry();

            retDictionary.ETag       = directory.Properties.ETag;
            retDictionary.Name       = directory.Name;
            retDictionary.LastAccess = directory.Properties.LastModified.HasValue
                                ? directory.Properties.LastModified.Value.UtcDateTime
                                : (DateTime?)null;
            return(retDictionary);
        }
Esempio n. 4
0
        public void GetDocumentFolders(IDocumentFolderService service, IDocumentFileService fileService, DocumentFolderViewModel dir, bool recursive = false)
        {
            if (CancelOperation)
            {
                return;
            }

            if (dir != null)
            {
                CloudFileDirectory dirPath = GetDirectory(dir.Path);
                if (dirPath != null && dirPath.Exists())
                {
                    currentlyIndexedNumber++;
                    IndexingDirectoryChanged?.Invoke(dir.Path, currentlyIndexedNumber);

                    if (dir.Id < 1)
                    {
                        var response = service.Create(dir);
                        if (response.Success)
                        {
                            dir.Id = response?.DocumentFolder?.Id ?? 0;
                        }
                        else
                        {
                            dir.Id = -1;
                        }
                    }
                    if (dir.Id > 0)
                    {
                        dirPath.FetchAttributes();
                        var subFilesAndDirectories = dirPath.ListFilesAndDirectories();

                        var subFiles = subFilesAndDirectories.OfType <CloudFile>()
                                       .Select(x => new DocumentFileViewModel()
                        {
                            Identifier     = Guid.NewGuid(),
                            DocumentFolder = dir,
                            Name           = x.Name,
                            Path           = x.Uri.LocalPath,

                            Company = new ServiceInterfaces.ViewModels.Common.Companies.CompanyViewModel()
                            {
                                Id = MainWindow.CurrentCompanyId
                            },
                            CreatedBy = new ServiceInterfaces.ViewModels.Common.Identity.UserViewModel()
                            {
                                Id = MainWindow.CurrentUserId
                            }
                        })
                                       .ToList();
                        subFiles.ForEach(x => GetDocumentAttributes(x));

                        var fileResponse = fileService.SubmitList(subFiles);



                        var subDirectories = subFilesAndDirectories.OfType <CloudFileDirectory>()
                                             .Select(x => new DocumentFolderViewModel()
                        {
                            Path    = x.Uri.LocalPath, Name = x.Name, Identifier = Guid.NewGuid(), ParentFolder = dir,
                            Company = new ServiceInterfaces.ViewModels.Common.Companies.CompanyViewModel()
                            {
                                Id = MainWindow.CurrentCompanyId
                            },
                            CreatedBy = new ServiceInterfaces.ViewModels.Common.Identity.UserViewModel()
                            {
                                Id = MainWindow.CurrentUserId
                            }
                        })
                                             .ToList();

                        var response = service.SubmitList(subDirectories);
                        if (response.Success)
                        {
                            dir.SubDirectories = new ObservableCollection <DocumentFolderViewModel>(response?.DocumentFolders ?? new List <DocumentFolderViewModel>());

                            if (recursive)
                            {
                                foreach (var item in dir.SubDirectories)
                                {
                                    if (CancelOperation)
                                    {
                                        return;
                                    }

                                    GetDocumentFolders(service, fileService, item, recursive);
                                }
                            }
                        }
                    }
                }
            }
        }