/// <summary> /// Get an iFolder Entry /// </summary> /// <param name="c">The Collection Object</param> /// <param name="n">The Node Object</param> /// <returns>An iFolderEntry Object</returns> private static iFolderEntry GetEntry(Collection c, Node n) { iFolderEntry entry = new iFolderEntry(); entry.ID = n.ID; entry.Name = n.Name; entry.iFolderID = c.ID; try { entry.ParentID = (n.Properties.GetSingleProperty(PropertyTags.Parent).Value as Relationship).NodeID; } catch { // ignore } // file node if (n.IsBaseType(NodeTypes.FileNodeType)) { FileNode fileNode = (FileNode)FileNode.NodeFactory(c, n); entry.Path = fileNode.GetRelativePath(); entry.LastModified = fileNode.LastWriteTime; entry.Size = fileNode.Length; } // dir node else if (n.IsBaseType(NodeTypes.DirNodeType)) { DirNode dirNode = (DirNode)DirNode.NodeFactory(c, n); entry.Path = dirNode.GetRelativePath(); entry.LastModified = dirNode.CreationTime; entry.IsDirectory = true; entry.IsRoot = dirNode.IsRoot; entry.HasChildren = dirNode.HasChildren(c); entry.Size = (long)dirNode.GetSize(c); } // bad node else { throw new EntryDoesNotExistException(n.ID); } return(entry); }
public virtual iFolderEntry GetEntryByPath(string ifolderID, string entryPath) { iFolderEntry result = null; try { result = iFolderEntry.GetEntryByPath(ifolderID, entryPath, GetAccessID()); } catch (Exception e) { SmartException.Throw(e); } return(result); }
public virtual iFolderEntry CreateEntry(string ifolderID, string parentID, iFolderEntryType type, string entryName) { iFolderEntry result = null; try { result = iFolderEntry.CreateEntry(ifolderID, parentID, type, entryName, GetAccessID()); } catch (Exception e) { SmartException.Throw(e); } return(result); }
/// <summary> /// Creates the fileNode for given directory /// </summary> /// <param name="source">directory info</param> /// <param name="ifolderID">ifolder id</param> /// <param name="parentID">parent id</param> /// <param name="entryName">entry name for ifolder</param> /// <returns>true if successful</returns> public static bool CreateFileNodesForDirectory(DirectoryInfo source, string ifolderID, string parentID, string entryName) { log.Debug("Creating nodes for directory: {0}", source.Name); Store store = Store.GetStore(); // collection Collection c = store.GetCollectionByID(ifolderID); if (c == null) { throw new iFolderDoesNotExistException(ifolderID); } Node n = iFolderEntry.GetEntryByPath(c, entryName); if (n == null) { throw new Exception(string.Format("Node entry for {0} does not exist", source.FullName)); } if (ifolderID == parentID) { iFolderEntry entry = iFolderEntry.GetEntry(c, c.GetRootDirectory()); if (entry == null) { throw new Exception(string.Format("Node entry for {0} does not exist", parentID)); } parentID = entry.ID; } Node parent = c.GetNodeByID(parentID); string path; FileInfo[] files = source.GetFiles(); iFolderEntryType type; foreach (FileInfo file in files) { log.Debug("CreateEntry for file name: {0}", file.Name); string tempEntryPath = entryName + "/" + file.Name; Node n1 = iFolderEntry.GetEntryByPath(c, tempEntryPath); if (n1 != null) { continue; } type = iFolderEntryType.File; try { Node entry = CreateEntry(c, parent, type, file.Name, out path, true); // update (entry as FileNode).UpdateFileInfo(c); c.Commit(entry); // Create Hashmap also... if (c.EncryptionAlgorithm == null || c.EncryptionAlgorithm == "") { // Upload hashmap for unencrypted iFolders.. FileNode node = new FileNode(entry); HashMap map = new HashMap(c, (BaseFileNode)node); map.CreateHashMapFile(); } } catch (Exception e) { log.Debug("Exception In creating file entry for: {0}. Exception: {1}--{2}", file.FullName, e.Message, e.StackTrace); } } DirectoryInfo[] dirs = source.GetDirectories(); foreach (DirectoryInfo dir in dirs) { string tempEntryPath = entryName + "/" + dir.Name; Node entry = iFolderEntry.GetEntryByPath(c, tempEntryPath); if (entry == null) { try { entry = CreateEntry(c, parent, iFolderEntryType.Directory, dir.Name, out path); // create directory and node // DirectoryInfo info = Directory.CreateDirectory(path); // update (entry as DirNode).CreationTime = dir.CreationTime; c.Commit(entry); CreateFileNodesForDirectory(dir, ifolderID, entry.ID, (entry as DirNode).GetRelativePath()); } catch (Exception ex) { log.Debug("Exception in creating dir entry for: {0}", ex.Message); /* * if (Directory.Exists(path)) * { * Directory.Delete(path); * } * throw; */ } } else { CreateFileNodesForDirectory(dir, ifolderID, entry.ID, (entry as DirNode).GetRelativePath()); } } return(true); }