private int _SaveFolders(DataContext context, string fullPath, FileSystemFolder fileSystemFolder) { var folders = Directory.GetDirectories(fullPath); var changed = 0; foreach (var path in folders) { var dbPath = GetFolderName(path); var dbFolder = context.FileSystemFolders.FirstOrDefault(f => f.Path == dbPath); if (dbFolder == null) { dbFolder = new FileSystemFolder { Path = dbPath, ParentId = fileSystemFolder.Id, Parent = fileSystemFolder }; context.FileSystemFolders.Add(dbFolder); changed++; } changed += _SaveFolders(context, path, dbFolder); } return(changed); }
public void SaveAllFolders() { using (var context = GetNewDataContext()) { var folders = Directory.GetDirectories(PhotosLocation); var changes = 0; foreach (var path in folders) { var dbPath = GetFolderName(path); var dbFolder = context.FileSystemFolders.FirstOrDefault(f => f.ParentId == null && f.Path == dbPath); if (dbFolder == null) { dbFolder = new FileSystemFolder { Path = dbPath, ParentId = null }; context.FileSystemFolders.Add(dbFolder); changes++; } changes += _SaveFolders(context, path, dbFolder); } context.SaveChanges(); } }
private static async Task <IFolder> DownloadFolderDecider(string[] fileTypes) { string downloadPath = System.IO.Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath, "Roamit"); System.IO.Directory.CreateDirectory(downloadPath); //Make sure download folder exists. IFolder downloadFolder = new FileSystemFolder(downloadPath); return(downloadFolder); }
public void SetCurrentDirectory(string path) { var folder = GetFolder(path); if (folder == null) { throw new InvalidOperationException($"Path not found: {path}"); } CurrentFolder = folder; }
public static FileSystemFolderDto ToFolderDto(this FileSystemFolder folder) { var bits = folder.Path.Split('\\', StringSplitOptions.RemoveEmptyEntries).ToList(); return(new FileSystemFolderDto { Id = folder.Id, Path = folder.Path, Name = bits.Last() }); }
void Start() { im = GetComponent <Image>(); foreach (Transform go in children.transform) { FileSystemFolder folderChild = go.GetComponentInChildren <FileSystemFolder>(); if (folderChild != null) { folder.Add(folderChild); } } }
public FileSystemEntry(string name, FileSystemFolder parent) { if (HasParent && String.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } if (HasParent && parent == null) { throw new ArgumentNullException(nameof(parent)); } Name = name; Parent = parent; LastWriteTimeUtc = DateTime.UtcNow; }
protected void AddFolder(FileSystemFolder folder) { // Split the folder up into it component parts List <string> pathParts = Utility.ListFromString(folder.FullPath, '\\', false); string folderSoFar = ""; // Try and find each part of the folder path and add any not defined FileSystemFolder currentFolder = null; foreach (string part in pathParts) { if (folderSoFar != "") { folderSoFar += @"\"; } folderSoFar += part; // Does this folder exist in our list FileSystemFolder parentFolder = _usbAuditFile.AuditedFolders.FindFolderByPath(folderSoFar); // No - OK well add it as a child of the last folder we did find or at the top level otherwise if (parentFolder == null) { if (folder.FullPath == folderSoFar) { parentFolder = folder; } else { parentFolder = new FileSystemFolder(); parentFolder.FullPath = folderSoFar; } // Now add this folder to its parent if (currentFolder == null) { _usbAuditFile.AuditedFolders.Add(parentFolder); } else { currentFolder.FoldersList.Add(parentFolder); } } currentFolder = parentFolder; } }
/// <summary> /// Recursively process a file system folder /// </summary> /// <param name="line"></param> /// <param name="?"></param> protected void ProcessFileRead(string line, FileSystemFolder currentFolder) { try { // BUG WORKAROUND // Owing to a bug in the way in which the file is written we end up with individual files being // concatenated so we will try and split the line on '0;' as this terminates each file // There are 5 entries for each file and we must split up by stepping through the line as we // cannot just replace ';0' with some other separator as it may appear validly within the line List <string> listParts = Utility.ListFromString(line, ';', true); // If we have more than 5 parts then we are only interested in the last 5 int startIndex = 0; if (listParts.Count > 5) { startIndex = listParts.Count - 5; } // Create the file system file object and set the file name FileSystemFile newFile = new FileSystemFile(); if (startIndex == 0) { newFile.Name = listParts[startIndex]; } else { newFile.Name = listParts[startIndex].Substring(1); } // get the last modified date - if this throws an exceptionwe ignore it string date = listParts[startIndex + 1]; string time = listParts[startIndex + 2]; time = time.Replace('-', ':'); string datetime = date + " " + time; newFile.ModifiedDateTime = Convert.ToDateTime(datetime); // Last File Size newFile.Size = Convert.ToInt32(listParts[startIndex + 3]); // Add the file to the folder currentFolder.FilesList.Add(newFile); } catch (Exception) { } }
public FileSystemFolder CreateFolder(string name) { if (String.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } if (Files.ContainsKey(name)) { throw new InvalidOperationException($"File already exists: {name}"); } if (Folders.ContainsKey(name)) { throw new InvalidOperationException($"Folder already exists: {name}"); } var folder = new FileSystemFolder(name, this); Folders.Add(name, folder); return(folder); }
public FileSystemFolder GetFolder(string path) { var pathArray = GetFullPathArray(path); if (!pathArray.Any()) { return(this); } FileSystemFolder folder = this; foreach (var item in pathArray) { if (!folder.Folders.TryGetValue(item, out folder)) { return(null); } } return(folder); }
/// <summary> /// Callde when we are displaying FileSystem Information /// </summary> /// <param name="displayedNode"></param> protected void DisplayFileSystem(UltraTreeNode displayedNode) { DataColumn objectColumn = new DataColumn("DataObject", typeof(object)); DataColumn itemColumn = new DataColumn("Name", typeof(string)); auditDataSet.Tables[0].Columns.AddRange(new System.Data.DataColumn[] { objectColumn, itemColumn }); // First ensure that the tree is expanded foreach (UltraTreeNode node in displayedNode.Nodes) { auditDataSet.Tables[0].Rows.Add(new object[] { node, node.Text }); } // That does it for the folders but we may also have some files. To get these we need the FileSystemFolder // object which we are displaying - luckily unless we are at the very top level this is passed as the tag of the node if (displayedNode.Tag is FileSystemFolder) { FileSystemFolder displayedFolder = displayedNode.Tag as FileSystemFolder; foreach (FileSystemFile file in displayedFolder.FilesList) { auditDataSet.Tables[0].Rows.Add(new object[] { file, file.Name }); } } }
public void VerifyDatabaseHashes() { var syncFileList = this.testWrapper.SyncFileList; var syncSourcePath = (this.testWrapper.SourceAdapter as WindowsFileSystemAdapter).Config.RootDirectory; var syncDestinationPath = (this.testWrapper.DestinationAdapter as WindowsFileSystemAdapter).Config.RootDirectory; Dictionary <string, string[]> itemIds = new Dictionary <string, string[]>(syncFileList.Count); foreach (string syncFile in syncFileList) { if (syncFile.Contains(".")) { string srcId = FileSystemFolder.GetUniqueIdForFileSystemInfo( new FileInfo(Path.Combine(syncSourcePath, syncFile))); string destId = FileSystemFolder.GetUniqueIdForFileSystemInfo( new FileInfo(Path.Combine(syncDestinationPath, syncFile))); itemIds.Add(syncFile, new[] { srcId, destId }); } else { string srcId = FileSystemFolder.GetUniqueIdForFileSystemInfo( new DirectoryInfo(Path.Combine(syncSourcePath, syncFile))); string destId = FileSystemFolder.GetUniqueIdForFileSystemInfo( new DirectoryInfo(Path.Combine(syncDestinationPath, syncFile))); itemIds.Add(syncFile, new[] { srcId, destId }); } } using (var db = this.testWrapper.Relationship.GetDatabase()) { var entries = db.Entries.Include(e => e.AdapterEntries).ToList(); Logger.Info( "Source adapter has Id={0}, Dest adapter has Id={1}", this.testWrapper.Relationship.Configuration.SourceAdapterId, this.testWrapper.Relationship.Configuration.DestinationAdapterId); foreach (SyncEntry entry in entries.Where(e => e.ParentId != null)) { if (entry.State.HasFlag(SyncEntryState.IsDeleted)) { continue; } string relativePath = entry.GetRelativePath(db, "\\"); Logger.Info("Entry Id={0}, Path={1}, Type={2}", entry.Id, relativePath, entry.Type); string[] dbIds = new string[2]; int at = 0; foreach (SyncEntryAdapterData adapterEntry in entry.AdapterEntries.OrderBy(e => e.AdapterId)) { dbIds[at] = adapterEntry.AdapterEntryId; at++; } string[] Ids; if (itemIds.TryGetValue(relativePath, out Ids)) { bool srcOk = string.Equals(Ids[0], dbIds[0]); bool destOk = string.Equals(Ids[1], dbIds[1]); Logger.Info(" Source Hash: {0} Dest Hash: {1}", srcOk ? "[OK]" : Ids[0] + " <> " + dbIds[0], destOk ? "[OK]" : Ids[1] + " <> " + dbIds[1]); Assert.IsTrue(srcOk, "Source hashes do not match!"); Assert.IsTrue(destOk, "Destination hashes do not match!"); } else { Assert.Fail("Did not find item " + relativePath); } //string fullDestPath = Path.Combine(syncDestinationPath, relativePath); } } }
public FileSystemFile(string name, FileSystemFolder parent) : base(name, parent) { }
public void SaveFileSystemFolder(FileSystemFolder FileSystemFolder) { throw new Exception("SaveFileSystemFolder is not implemented!"); }
public void DeleteFileSystemFolder(FileSystemFolder FileSystemFolder) { throw new Exception("DeleteFileSystemFolder is not implemented!"); }
public LyncAuditFile(string audFile) { _usbAuditFile = new AuditDataFile(); _usbAuditFile.FileName = audFile; _fileName = Path.GetFileName(audFile); // Open and try and read the AUD file IniFile usbIniFile = new IniFile(); usbIniFile.Read(audFile); // Now we need to take this file apart and create an ADF file from the pieces usbIniFile.SetSection(SECTION_ASSET); // Check the scanner name - this MUST contain the text 'USB' or 'PDA' to be valid string scannerType = usbIniFile.GetString(KEY_SCANNER, ""); if (scannerType.Contains("USB")) { _usbAuditFile.CreatedBy = AuditDataFile.CREATEDBY.usbscanner; } else if (scannerType.Contains("PDA")) { _usbAuditFile.CreatedBy = AuditDataFile.CREATEDBY.mdascanner; } else { return; } // Name of Asset _usbAuditFile.AssetName = usbIniFile.GetString(KEY_NAME, ""); _usbAuditFile.ParentAssetName = usbIniFile.GetString(KEY_PARENT, ""); _usbAuditFile.AuditDate = usbIniFile.GetTime(KEY_DATE, DateTime.Now, false); _usbAuditFile.Category = usbIniFile.GetString(KEY_CATEGORY, "Disk Drive"); _usbAuditFile.AgentVersion = usbIniFile.GetString(KEY_SCANNER, "LyncUSB"); // The following fields do not seem to be uploaded by AuditWizard string busType = usbIniFile.GetString(KEY_BUSTYPE, ""); string hostName = usbIniFile.GetString(KEY_HOSTPC, ""); string numberOfDrives = usbIniFile.GetString(KEY_NUMBEROFDRIVES, "1"); // We MAY have a hardware section which again we can convert into AuditedItems hopefully if (usbIniFile.FindSection(SECTION_HARDWARE) != -1) { List <string> listHardwareKeys = new List <string>(); usbIniFile.EnumerateKeys(SECTION_HARDWARE, listHardwareKeys); // Loop through the keys returned foreach (string key in listHardwareKeys) { string value = usbIniFile.GetString(SECTION_HARDWARE, key, ""); // The key is formatted as a comma separated list - the last item is the field name int delimiter = key.LastIndexOf(';'); string category = "Hardware|" + key.Substring(0, delimiter); category = category.Replace(';', '|'); string field = key.Substring(delimiter + 1); // Now create an AuditedDataItem for this field and add to the file AuditedItem item = new AuditedItem(category, field, value, "", AuditedItem.eDATATYPE.text, false); _usbAuditFile.AuditedItems.Add(item); } } // We may additionally have an SWA file for this asset - if so we should load its data into the // audit data file which we are generating also. string swaFileName = Path.Combine(Path.GetDirectoryName(audFile), Path.GetFileNameWithoutExtension(audFile)); swaFileName += ".swa"; if (!File.Exists(swaFileName)) { return; } // The SWA file is a simple text file with lines either containing a folder or file specification // Unfortunately the folders are in reverse order to that which we would expect so we need to tempoarily // store them in a list and then construct the container and build from the bottom up List <FileSystemFolder> listFolders = new List <FileSystemFolder>(); FileSystemFolder currentFolder = null; string line; System.IO.StreamReader file = new System.IO.StreamReader(swaFileName); while ((line = file.ReadLine()) != null) { if (line.Contains(";")) { ProcessFileRead(line, currentFolder); } else { currentFolder = new FileSystemFolder(); currentFolder.FullPath = line; listFolders.Add(currentFolder); } } // Close the file again file.Close(); // Now we need to post-process the folders list so that we can upload it as a contiguous, heirarchial // list of folders - not as easy as it sounds as the Lync files may have missing nodes in the tree PostProcessFolders(listFolders); }