Beispiel #1
0
        // =============================================================================================================
        // public method (パブリックメソッド)
        // =============================================================================================================
        #region "public method"

        /// ------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// ■DeleteBackupOverFile (Delete log files and retain specified number of log files)
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// Ver.01.00.00.000  2013-04-11  (TSDV)hung.trinhhong  Create
        /// Ver.01.01.00.000  2013-06-07  (TSDV)hung.trinhhong  Update Specification change
        /// Ver.01.01.00.001  2013-06-11  (TSDV)hung.trinhhong  Update Bug when create system semaphore
        /// Ver.01.01.00.002  2013-06-12  (TSDV)hung.trinhhong  Update Confirm rule for naming semaphore
        /// </history>
        /// ------------------------------------------------------------------------------------------------------------
        public void DeleteBackupOverFile()
        {
            // Create semaphore for delete
            string semaphoreForDeleteString = "SemaphoreForDelete";

            try
            {
                // Try to reference to exist system semaphore
                m_SemaphoreForDelete = Semaphore.OpenExisting(semaphoreForDeleteString);
            }
            catch
            {
                // Create new semaphore
                m_SemaphoreForDelete = CreateSemaphore(semaphoreForDeleteString);
            }

            try
            {
                m_SemaphoreForDelete.WaitOne();

                // Get subfolder list in m_savePath
                string[] allSubFolders = DirectoryOperator.GetDirectories(m_SavePath);
                if (allSubFolders.Length > m_KeepDays)
                {
                    int numberDeleteFolders = allSubFolders.Length - m_KeepDays;
                    for (int topIndex = 0; topIndex < numberDeleteFolders; topIndex++)
                    {
                        DirectoryOperator.Delete(allSubFolders[topIndex], true);
                    }
                }
            }
            catch
            {
                if (m_ExceptionHandling == ExceptionHandling.Throw)
                {
                    throw;
                }
                else
                {
                    // skip exception
                }
            }
            finally
            {
                m_SemaphoreForDelete.Release();
            }
        }
Beispiel #2
0
        /// <summary>
        /// delete unrelated hbv cached files
        /// </summary>
        private void CleanUnUsedHbvCache()
        {
            var rootInfo = new DirectoryInfo(Constant.CacheDir);
            var dirList  = rootInfo.EnumerateDirectories();

            foreach (DirectoryInfo dir in dirList)
            {
                var target = new DirectoryOperator(dir.FullName);
                var found  = false;
                foreach (var file  in this._appData.RecentFiles)
                {
                    if (file.CacheDir == target.Name)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    target.Delete();
                }
            }
        }