/// <summary>
        /// This method deletes folders according to the parameters
        /// </summary>
        /// <param name="operation">parameters for FolderDelete</param>
        /// <returns>true if processed successfully, false otherwise</returns>
        private bool FolderDelete(MailSimOperationsFolderDelete operation)
        {
            int  iterations = GetIterationCount(operation.Count);
            bool random     = false;

            // gets the Outlook folder
            IMailFolder folder = olMailStore.GetDefaultFolder(operation.FolderPath);

            if (folder == null)
            {
                Log.Out(Log.Severity.Error, operation.OperationName, "Unable to retrieve folder {0}",
                        operation.FolderPath);
                return(false);
            }

            var subFolders = GetMatchingSubFolders(operation.OperationName, folder, operation.FolderName).ToList();

            if (subFolders.Count == 0)
            {
                Log.Out(Log.Severity.Error, operation.OperationName, "There is no matching folder to delete in folder {0}",
                        folder.Name);
                return(false);
            }

            // randomly generate the number of folder to delete if Count is not specified
            if (iterations == 0)
            {
                random     = true;
                iterations = randomNum.Next(1, subFolders.Count + 1);
                Log.Out(Log.Severity.Info, operation.OperationName, "Randomly deleting {0} folders", iterations);
            }
            else if (iterations > subFolders.Count)
            {
                Log.Out(Log.Severity.Warning, operation.OperationName, "Only {0} folders available, adjusting delete from {1} folders to {0}",
                        subFolders.Count, iterations);
                iterations = subFolders.Count;
            }

            int indexToDelete;

            for (int count = 1; count <= iterations; count++)
            {
                Log.Out(Log.Severity.Info, operation.OperationName, "Starting iteration {0}", count);

                indexToDelete = random ? randomNum.Next(0, subFolders.Count) : subFolders.Count - 1;

                // deletes the folder and remove it from the saved list
                Log.Out(Log.Severity.Info, operation.OperationName, "Deleting folder: {0}", subFolders[indexToDelete].Name);
                subFolders[indexToDelete].Delete();
                subFolders.RemoveAt(indexToDelete);

                SleepOrStop(operation.OperationName, operation.Sleep);
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// This method deletes folders according to the parameters
        /// </summary>
        /// <param name="operation">parameters for FolderDelete</param>
        /// <returns>true if processed successfully, false otherwise</returns>
        private bool FolderDelete(MailSimOperationsFolderDelete operation)
        {
            int iterations = GetIterationCount(operation.Count);
            bool random = false;

            // gets the Outlook folder
            IMailFolder folder = olMailStore.GetDefaultFolder(operation.FolderPath);
            if (folder == null)
            {
                Log.Out(Log.Severity.Error, operation.OperationName, "Unable to retrieve folder {0}",
                    operation.FolderPath);
                return false;
            }

            var subFolders = GetMatchingSubFolders(operation.OperationName, folder, operation.FolderName).ToList();
            if (subFolders.Count == 0)
            {
                Log.Out(Log.Severity.Error, operation.OperationName, "There is no matching folder to delete in folder {0}",
                    folder.Name);
                return false;
            }

            // randomly generate the number of folder to delete if Count is not specified
            if (iterations == 0)
            {
                random = true;
                iterations = randomNum.Next(1, subFolders.Count + 1);
                Log.Out(Log.Severity.Info, operation.OperationName, "Randomly deleting {0} folders", iterations);
            }
            else if (iterations > subFolders.Count)
            {
                Log.Out(Log.Severity.Warning, operation.OperationName, "Only {0} folders available, adjusting delete from {1} folders to {0}",
                    subFolders.Count, iterations);
                iterations = subFolders.Count;
            }

            int indexToDelete;
            for (int count = 1; count <= iterations; count++)
            {
                Log.Out(Log.Severity.Info, operation.OperationName, "Starting iteration {0}", count);

                indexToDelete = random ? randomNum.Next(0, subFolders.Count) : subFolders.Count - 1;

                // deletes the folder and remove it from the saved list
                Log.Out(Log.Severity.Info, operation.OperationName, "Deleting folder: {0}", subFolders[indexToDelete].Name);
                subFolders[indexToDelete].Delete();
                subFolders.RemoveAt(indexToDelete);

                SleepOrStop(operation.OperationName, operation.Sleep);
            }

            return true;
        }