예제 #1
0
        public static void SynchronizeFolder( int PortalId, string physicalPath, string relativePath, bool isRecursive, bool syncFiles, bool forceFolderSync )
        {
            FolderController objFolderController = new FolderController();
            int FolderId = 0;
            bool isInSync = true;

            // synchronize folder collection
            if( forceFolderSync == true & relativePath == "" )
            {
                RemoveOrphanedFolders( PortalId );
            }

            //Attempt to get the folder
            FolderInfo folder = (FolderInfo)( CBO.FillObject( DataProvider.Instance().GetFolder( PortalId, relativePath ), typeof( FolderInfo ) ) );

            DirectoryInfo dirInfo = new DirectoryInfo( physicalPath );
            if( dirInfo.Exists )
            {
                // check to see if the folder exists in the db
                if( folder == null )
                {
                    // check if folder contains files or subfolders
                    if( dirInfo.GetFileSystemInfos( "*" ).Length != 0 )
                    {
                        //Add Folder to database
                        FolderId = AddFolder( PortalId, relativePath, (int)FolderController.StorageLocationTypes.InsecureFileSystem );
                        folder = objFolderController.GetFolderInfo( PortalId, FolderId );
                        isInSync = false;
                    }
                }
                else
                {
                    //Check whether existing folder is in sync by comparing LastWriteTime of the physical folder with the LastUpdated value in the database
                    //*NOTE: dirInfo.LastWriteTime is updated when files are added to or deleted from a directory - but NOT when existing files are overwritten ( this is a known Windows Operating System issue )
                    isInSync = ( dirInfo.LastWriteTime.ToString( "yyyyMMddhhmmss" ) == folder.LastUpdated.ToString( "yyyyMMddhhmmss" ) );
                }

                if( folder != null )
                {
                    if( syncFiles == true & ( isInSync == false || forceFolderSync == true ) )
                    {
                        //Get Physical Files in this Folder and sync them
                        string[] strFiles = Directory.GetFiles( physicalPath );
                        foreach( string strFileName in strFiles )
                        {
                            //Add the File if it doesn't exist, Update it if the file size has changed
                            AddFile( strFileName, PortalId, false, folder.FolderID );
                        }

                        //Removed orphaned files
                        RemoveOrphanedFiles( folder, PortalId );

                        //Update the folder with the LastWriteTime of the directory
                        folder.LastUpdated = dirInfo.LastWriteTime;
                        objFolderController.UpdateFolder( folder );
                    }

                    //Get Physical Sub Folders (and synchronize recursively)
                    if( isRecursive )
                    {
                        string[] strFolders = Directory.GetDirectories( physicalPath );
                        foreach( string strFolder in strFolders )
                        {
                            DirectoryInfo dir = new DirectoryInfo( strFolder );
                            string relPath = Null.NullString;
                            if( relativePath == "" )
                            {
                                relPath = dir.Name + "/";
                            }
                            else
                            {
                                relPath = relativePath;
                                if( !( relativePath.EndsWith( "/" ) ) )
                                {
                                    relPath = relPath + "/";
                                }
                                relPath = relPath + dir.Name + "/";
                            }
                            SynchronizeFolder( PortalId, strFolder, relPath, true, syncFiles, forceFolderSync );
                        }
                    }
                }
            }
            else // physical folder does not exist on file system
            {
                if( folder != null )
                {
                    // folder exists in DB
                    if( folder.StorageLocation != (int)FolderController.StorageLocationTypes.DatabaseSecure )
                    {
                        // remove files and folder from DB
                        RemoveOrphanedFiles( folder, PortalId );
                        objFolderController.DeleteFolder( PortalId, relativePath.Replace( "\\", "/" ) );
                    }
                }
            }
        }
예제 #2
0
 public static void RemoveOrphanedFolders( int PortalId )
 {
     bool blnInvalidateCache = false;
     FolderController objFolderController = new FolderController();
     ArrayList arrFolders = GetFolders( PortalId );
     foreach( FolderInfo objFolder in arrFolders )
     {
         if( objFolder.StorageLocation != (int)FolderController.StorageLocationTypes.DatabaseSecure )
         {
             if( Directory.Exists( objFolder.PhysicalPath ) == false )
             {
                 RemoveOrphanedFiles( objFolder, PortalId );
                 objFolderController.DeleteFolder( PortalId, objFolder.FolderPath );
                 blnInvalidateCache = true;
             }
         }
     }
     if( blnInvalidateCache )
     {
         DataCache.RemoveCache( "Folders:" + PortalId.ToString() );
     }
 }
예제 #3
0
        /// <summary>
        /// Deletes a folder
        /// </summary>
        /// <param name="PortalId">The Id of the Portal</param>
        /// <param name="folder">The Directory Info object to delete</param>
        /// <param name="folderName">The Name of the folder relative to the Root of the Portal</param>
        /// <remarks>
        /// </remarks>
        public static void DeleteFolder( int PortalId, DirectoryInfo folder, string folderName )
        {
            //Delete Folder
            folder.Delete( false );

            //Remove Folder from DataBase
            FolderController objFolderController = new FolderController();
            objFolderController.DeleteFolder( PortalId, folderName.Replace( "\\", "/" ) );
        }