Ejemplo n.º 1
0
        /// <summary>
        /// Create An iFolder Entry
        /// </summary>
        /// <param name="c"></param>
        /// <param name="parent"></param>
        /// <param name="type"></param>
        /// <param name="entryName"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        internal static Node CreateEntry(Collection c, Node parent,
                                         iFolderEntryType type, string entryName, out string path, bool DontCheckPolicies)
        {
            Node result = null;

            // NOTE: a new entry off the iFolder is not allowed, it must be off the root directory node or lower
            if ((parent == null) || (c.ID.Equals(parent.ID)))
            {
                throw new EntryDoesNotExistException(parent.ID);
            }

            // NOTE: only directories can have children
            if (!parent.IsBaseType(NodeTypes.DirNodeType))
            {
                throw new DirectoryEntryRequiredException(parent.ID);
            }

            // check the name
            CheckName(entryName);

            // create new path
            DirNode parentDirNode = (DirNode)parent;

            path = parentDirNode.GetFullPath(c);
            path = System.IO.Path.Combine(path, entryName);

            // check for existing entry (case insensitive test)
            if (SyncFile.DoesNodeExist(c, parentDirNode, entryName))
            {
                throw new EntryAlreadyExistException(entryName);
            }

            // directory
            if (type == iFolderEntryType.Directory)
            {
                result = new DirNode(c, parentDirNode, entryName);
            }
            // file
            else
            {
                if (DontCheckPolicies == false)
                {
                    // check file type policy
                    FileTypeFilter filter = FileTypeFilter.Get(c);
                    if (!filter.Allowed(entryName))
                    {
                        throw new FileTypeException(entryName);
                    }
                }

                result = new FileNode(c, parentDirNode, entryName);
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks for a name conflict.
        /// </summary>
        /// <returns>True if conflict.</returns>
        protected bool CheckForNameConflict()
        {
            if (!NameConflict)
            {
                // Look up the FsPath property (StoreFileNodes don't have this property set).
                Property property = node.Properties.GetSingleProperty(PropertyTags.FileSystemPath);
                if (property != null)
                {
                    string  path = property.Value.ToString();
                    ICSList nodeList;
                    nodeList = collection.Search(PropertyTags.FileSystemPath, path, SearchOp.Equal);
                    foreach (ShallowNode sn in nodeList)
                    {
                        FileNode localFileNode = new FileNode(collection.GetNodeByID(sn.ID));
                        // Set name conflict true if both file doesn't match
                        if (sn.ID != node.ID && String.Compare(new FileNode(node).GetRelativePath(), localFileNode.GetRelativePath(), false) != 0)
                        {
                            conflictingNode = collection.GetNodeByID(sn.ID);
                            nameConflict    = true;
                            break;
                        }
                    }
                    // Now make sure we don't have any illegal characters.
                    if (!IsNameValid(path))
                    {
                        nameConflict = true;
                    }

                    if (nameConflict)
                    {
                        node = Conflict.CreateNameConflict(collection, node) as BaseFileNode;
                        file = Conflict.GetFileConflictPath(collection, node);
                        if (conflictingNode != null)
                        {
                            string   cnPath;
                            FileNode tmpFn = conflictingNode as FileNode;
                            DirNode  tmpDn = conflictingNode as DirNode;
                            if (tmpFn != null)
                            {
                                cnPath = tmpFn.GetFullPath(collection);
                            }
                            else
                            {
                                cnPath = tmpDn.GetFullPath(collection);
                            }
                            conflictingNode = Conflict.CreateNameConflict(collection, conflictingNode, cnPath);
                            Conflict.LinkConflictingNodes(conflictingNode, node);
                        }
                    }
                }
            }
            return(nameConflict);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="c">The iFolder Collection</param>
        /// <param name="accessID">The Access User ID</param>
        protected iFolderDetails(Collection c, string accessID)
            : base(c, accessID)
        {
            this.FileCount      = c.GetNodesByType(NodeTypes.FileNodeType).Count;
            this.DirectoryCount = c.GetNodesByType(NodeTypes.DirNodeType).Count;

            // paths
            this.ManagedPath = c.ManagedPath;

            DirNode dirNode = c.GetRootDirectory();

            if (dirNode != null)
            {
                this.UnManagedPath = dirNode.GetFullPath(c);
            }
        }
Ejemplo n.º 4
0
        //---------------------------------------------------------------------------
        /// <summary>
        /// resolve file name conflict and commit
        /// </summary>
        public void Resolve(string newNodeName)
        {
            if (!SyncFile.IsNameValid(newNodeName))
            {
                throw new MalformedException(newNodeName);
            }
            FileNode fn = node as FileNode;

            if (fn != null)
            {
                DirNode parent = fn.GetParent(collection);
                if (newNodeName == node.Name)
                {
                    Log.log.Debug("Resolving the name conflict >>>>> name: {0}  newName: {1}", node.Name, newNodeName);
                    // We are resolving to the same name.
                    if (Path.GetDirectoryName(FileNameConflictPath) != Path.GetDirectoryName(NonconflictedPath))
                    {
                        // This file is in the conflict bin and has been sync-ed from the server.  We do not need
                        // To push it back up.  Set internal.
                        node.Properties.State = PropertyList.PropertyListState.Internal;
                        try
                        {
                            File.Move(FileNameConflictPath, NonconflictedPath);
                        }
                        catch (IOException)
                        {
                            // The file exists it must have been modified locally create a node conflict.
                            File.Move(FileNameConflictPath, GetUpdateConflictPath(collection, fn));
                            fn = (FileNode)RemoveNameConflict(collection, fn);
                            collection.Commit(fn);
                            Node serverNode = collection.GetNodeByID(fn.ID);
                            // Now commit the node to update the file (size and dates);
                            fn.UpdateFileInfo(collection);
                            collection.Commit(fn);
                            // Create the node conflict.
                            fn = (FileNode)collection.CreateCollision(serverNode, false);
                            collection.Commit(fn);
                            return;
                        }
                    }
                }
                else
                {
                    Log.log.Debug("Resolving the name conflict >>>>> name: {0}  newName: {1}", node.Name, newNodeName);

                    if (SyncFile.DoesNodeExist(collection, parent, newNodeName))
                    {
                        throw new ExistsException(newNodeName);
                    }
                    //TODO: what if move succeeds but node rename or commit fails?
                    File.Move(FileNameConflictPath, Path.Combine(Path.GetDirectoryName(NonconflictedPath), newNodeName));
                    string relativePath = fn.GetRelativePath();
                    relativePath = relativePath.Remove(relativePath.Length - node.Name.Length, node.Name.Length) + newNodeName;
                    node.Properties.ModifyNodeProperty(new Property(PropertyTags.FileSystemPath, Syntax.String, relativePath));
                    node.Name = newNodeName;
                }
                node = RemoveNameConflict(collection, node);
                collection.Commit(node);
            }
            else
            {
                DirNode dn = node as DirNode;
                if (dn != null)
                {
                    DirNode parent = dn.GetParent(collection);
                    string  oldname, newname;
                    oldname = FileNameConflictPath;
                    newname = Path.Combine(Path.GetDirectoryName(dn.GetFullPath(collection)), newNodeName);
                    if (newNodeName != node.Name)
                    {
                        if (SyncFile.DoesNodeExist(collection, parent, newNodeName))
                        {
                            throw new ExistsException(newNodeName);
                        }
                        if (Directory.Exists(oldname))
                        {
                            Directory.Move(oldname, newname);
                        }
                        else
                        {
                            Directory.CreateDirectory(newname);
                        }
                        string oldRelativePath = dn.GetRelativePath();
                        string relativePath    = oldRelativePath.Remove(oldRelativePath.Length - node.Name.Length, node.Name.Length) + newNodeName;
                        node.Properties.ModifyNodeProperty(new Property(PropertyTags.FileSystemPath, Syntax.String, relativePath));
                        node.Name = newNodeName;
                        node      = RemoveNameConflict(collection, node);
                        collection.Commit(node);
                        FileWatcher.RenameDirsChildren(collection, dn, oldRelativePath);
                    }
                    else
                    {
                        // The name did not change.
                        if (Directory.Exists(oldname))
                        {
                            Directory.Move(oldname, newname);
                        }
                        else
                        {
                            Directory.CreateDirectory(newname);
                        }
                        node = RemoveNameConflict(collection, node);
                        collection.Commit(node);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Delete An iFolder Entry
        /// </summary>
        /// <param name="ifolderID">The ID of the iFolder.</param>
        /// <param name="entryID">The ID of the Entry.</param>
        /// <param name="accessID">The Access User ID.</param>
        public static void DeleteEntry(string ifolderID, string entryID, string accessID)
        {
            Store store = Store.GetStore();

            Collection c = store.GetCollectionByID(ifolderID);

            if (c == null)
            {
                throw new iFolderDoesNotExistException(ifolderID);
            }

            // impersonate
            iFolder.Impersonate(c, accessID);

            Node n = c.GetNodeByID(entryID);

            if (n == null)
            {
                throw new EntryDoesNotExistException(entryID);
            }

            // directory
            if (n.IsBaseType(NodeTypes.DirNodeType))
            {
                DirNode dn = (DirNode)n;

                if (dn.IsRoot)
                {
                    throw new DirectoryEntryRequiredException(entryID);
                }

                string path = dn.GetFullPath(c);

                if (Directory.Exists(path))
                {
                    Directory.Delete(path, true);
                }

                // delete recursivley
                c.Commit(c.Delete(dn, PropertyTags.Parent));
            }

            // file
            else if (n.IsBaseType(NodeTypes.FileNodeType))
            {
                FileNode fn = (FileNode)n;

                string path = fn.GetFullPath(c);

                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                c.Commit(c.Delete(fn));
            }

            // not an entry
            else
            {
                throw new EntryDoesNotExistException(entryID);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Constructor
        /// </summary>
        public iFolderWeb(Collection collection)
        {
            Member tmpMember = null;

            this.DomainID         = collection.Domain;
            this.ID               = collection.ID;
            this.CollectionID     = collection.ID;
            this.LocalIncarnation = collection.LocalIncarnation;
            DirNode dirNode = collection.GetRootDirectory();

            if (dirNode != null)
            {
                this.UnManagedPath = dirNode.GetFullPath(collection);
            }
            else
            {
                this.UnManagedPath = "";
            }
            this.ManagedPath       = collection.ManagedPath;
            this.MasterIncarnation = collection.MasterIncarnation;
            this.Name = collection.Name;
            tmpMember = collection.Owner;

            if (tmpMember != null)
            {
                this.OwnerID = tmpMember.UserID;
                Domain domain       = Store.GetStore().GetDomain(this.DomainID);
                Member domainMember = domain.GetMemberByID(this.OwnerID);
                string fullName     = domainMember.FN;
                this.Owner = (fullName != null) ? fullName : tmpMember.Name;
                this.EffectiveSyncInterval = tmpMember.EffectiveSyncPolicy(collection);
            }
            else
            {
                this.Owner   = "Not available";
                this.OwnerID = "0";
            }

            this.SyncInterval =
                Simias.Policy.SyncInterval.GetInterval(collection);
            this.Synchronizable  = collection.Synchronizable;
            this.Type            = iFolderType;
            this.Description     = "";
            this.IsSubscription  = false;
            this.EnumeratedState = -1;

            // There is no longer a WorkGroup domain ... for now return false. We
            // probably need to change this to return a type instead.
            this.IsWorkgroup  = false;
            this.HasConflicts = collection.HasCollisions();

            tmpMember = collection.GetCurrentMember();

            this.CurrentUserID     = tmpMember.UserID;
            this.CurrentUserRights = tmpMember.Rights.ToString();
            int EffectiveSync = tmpMember.EffectiveSyncPolicy(collection);

            if (EffectiveSync > 0)
            {
                this.EffectiveSyncInterval = EffectiveSync;
                //Simias.Policy.SyncInterval.Set(collection, EffectiveSync);
            }

            DateTime lastSyncTime = Simias.Sync.SyncClient.GetLastSyncTime(collection.ID);

            if (collection.Role.Equals(SyncRoles.Master))
            {
                this.LastSyncTime = string.Empty;
                this.State        = "Local";
            }
            else if (lastSyncTime.Equals(DateTime.MinValue))
            {
                this.LastSyncTime = string.Empty;
                this.State        = "WaitSync";
            }
            else
            {
                this.LastSyncTime = lastSyncTime.ToString();
                this.State        = collection.IsProxy ? "WaitSync" : "Local";
            }

            this.Role = collection.Role.ToString();
            this.ssl  = collection.SSL;
            if (collection.EncryptionAlgorithm == null || collection.EncryptionAlgorithm == "")
            {
                this.encryptionAlgorithm = "";
            }
            else
            {
                this.encryptionAlgorithm = collection.EncryptionAlgorithm;
            }
            this.MigratediFolder = collection.MigratediFolder;
            ICSList memberList;

            memberList = collection.GetMemberList();
            if (memberList.Count > 1)
            {
                this.shared = true;
            }
            else
            {
                this.shared = false;
            }
            this.iFolderSize = collection.StorageSize;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="collection">Collcetion</param>
        public iFolderWeb(Collection collection, int infoToFetch)
        {
            Member tmpMember = null;

            //base information that is mandatory
            this.DomainID         = collection.Domain;
            this.ID               = collection.ID;
            this.CollectionID     = collection.ID;
            this.LocalIncarnation = collection.LocalIncarnation;

            //infoToFetch is a bitmap, for now using it as a boolean
            if (infoToFetch > 0)
            {
                DirNode dirNode = collection.GetRootDirectory();
                if (dirNode != null)
                {
                    this.UnManagedPath = dirNode.GetFullPath(collection);
                }
                else
                {
                    this.UnManagedPath = "";
                }
                this.ManagedPath       = collection.ManagedPath;
                this.MasterIncarnation = collection.MasterIncarnation;
                this.Name = collection.Name;
                DateTime lastSyncTime = Simias.Sync.SyncClient.GetLastSyncTime(collection.ID);
                if (collection.Role.Equals(SyncRoles.Master))
                {
                    this.LastSyncTime = string.Empty;
                    this.State        = "Local";
                }
                else if (lastSyncTime.Equals(DateTime.MinValue))
                {
                    this.LastSyncTime = string.Empty;
                    this.State        = "WaitSync";
                }
                else
                {
                    this.LastSyncTime = lastSyncTime.ToString();
                    this.State        = collection.IsProxy ? "WaitSync" : "Local";
                }
                this.HasConflicts = collection.HasCollisions();

                tmpMember = collection.GetCurrentMember();

                this.CurrentUserID     = tmpMember.UserID;
                this.CurrentUserRights = tmpMember.Rights.ToString();

                this.Role = collection.Role.ToString();
                this.ssl  = collection.SSL;
                if (collection.EncryptionAlgorithm == null || collection.EncryptionAlgorithm == "")
                {
                    this.encryptionAlgorithm = "";
                }
                else
                {
                    this.encryptionAlgorithm = collection.EncryptionAlgorithm;
                }

                this.MigratediFolder = collection.MigratediFolder;

                tmpMember = collection.Owner;
                if (tmpMember != null)
                {
                    this.Owner   = tmpMember.Name;
                    this.OwnerID = tmpMember.UserID;
                    this.EffectiveSyncInterval = tmpMember.EffectiveSyncPolicy(collection);
                }
                else
                {
                    this.Owner   = "Not available";
                    this.OwnerID = "0";
                }

                ICSList memberList;

                memberList = collection.GetMemberList();
                if (memberList.Count > 1)
                {
                    this.shared = true;
                }
                else
                {
                    this.shared = false;
                }
                this.iFolderSize = collection.StorageSize;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Generates a report
        /// </summary>
        public void GenerateReport()
        {
            bool         hadException = false;
            const double MB           = 1024 * 1024;
            ReportConfig config       = GetReportConfiguration();

            string reportPath = null;

            if (config.IsiFolder)
            {
                DirNode dirNode = reportCollection.GetRootDirectory();
                reportPath = dirNode.GetFullPath(reportCollection);
            }
            else
            {
                reportPath = ReportPath;
            }

            string fileName = String.Format("ifolder-{0}-{1}.csv",
                                            Environment.MachineName,
                                            currentReportTime.ToString("yyyyMMdd-HHmmss"));

            string filePath = Path.Combine(reportPath, fileName);

            log.Debug("Report file name = {0}", filePath);
            StreamWriter file = File.CreateText(filePath);

            try
            {
                Domain domain = store.GetDomain(store.DefaultDomain);

                // headers
                WriteHeaderRow(file, columns);

                // list iFolders
                ICSList ifolders = store.GetCollectionsByType("iFolder");

                foreach (ShallowNode sn in ifolders)
                {
                    object[] cells = new object[count];

                    Collection ifolder = store.GetCollectionByID(sn.ID);
                    Member     owner   = domain.GetMemberByID(ifolder.Owner.UserID);

                    // cells
                    if (cli != null)
                    {
                        cells[(int)ColumnID.ReportTime]     = currentReportTime.ToString(cli);
                        cells[(int)ColumnID.OwnerLastLogin] = owner.Properties.GetSingleProperty("LastLogin").ToString(cli);
                        cells[(int)ColumnID.LastSyncTime]   = ifolder.Properties.GetSingleProperty("LastModified").ToString(cli);
                    }
                    else
                    {
                        cells[(int)ColumnID.ReportTime]     = currentReportTime.ToString("F");
                        cells[(int)ColumnID.OwnerLastLogin] = owner.Properties.GetSingleProperty("LastLogin").ToString("F");
                        cells[(int)ColumnID.LastSyncTime]   = ifolder.Properties.GetSingleProperty("LastModified").ToString("F");
                    }
                    cells[( int )ColumnID.iFolderSystem]  = domain.Name;
                    cells[( int )ColumnID.iFolderServer]  = Environment.MachineName;
                    cells[( int )ColumnID.iFolderID]      = ifolder.ID;
                    cells[( int )ColumnID.iFolderName]    = ifolder.Name;
                    cells[( int )ColumnID.iFolderSize]    = ifolder.StorageSize / MB;
                    cells[( int )ColumnID.iFolderPath]    = ifolder.UnmanagedPath;
                    cells[( int )ColumnID.iFolderQuota]   = DiskSpaceQuota.GetLimit(ifolder) / MB;
                    cells[( int )ColumnID.MemberCount]    = ifolder.GetMemberList().Count;
                    cells[( int )ColumnID.FileCount]      = ifolder.GetNodesByType(NodeTypes.FileNodeType).Count;
                    cells[( int )ColumnID.DirectoryCount] = ifolder.GetNodesByType(NodeTypes.DirNodeType).Count;
                    cells[( int )ColumnID.OwnerID]        = owner.UserID;
                    cells[( int )ColumnID.OwnerName]      = owner.FN;
                    cells[( int )ColumnID.OwnerCN]        = owner.Name;
                    cells[( int )ColumnID.OwnerDN]        = owner.Properties.GetSingleProperty("DN");
                    cells[( int )ColumnID.OwnerQuota]     = DiskSpaceQuota.Get(owner).Limit / MB;
                    cells[( int )ColumnID.OwnerDisabled]  = domain.IsLoginDisabled(owner.UserID);
                    cells[( int )ColumnID.PreviousOwner]  = ifolder.PreviousOwner;
                    cells[( int )ColumnID.OrphanedOwner]  = ifolder.Properties.GetSingleProperty("OrphanedOwner");

                    WriteRow(file, columns, cells);
                }
            }
            catch (Exception ex)
            {
                hadException = true;
                file.WriteLine();
                file.WriteLine();
                file.WriteLine(ex);
                file.WriteLine(ex.StackTrace);
            }
            finally
            {
                file.Close();

                if (hadException == false)
                {
                    // If this is an iFolder create the file node for the report file.
                    if (config.IsiFolder)
                    {
                        CreateFileNode(fileName);
                    }

                    // Set the time of the last successful report.
                    SetLastReportTime(currentReportTime);
                }
            }
        }