예제 #1
0
        public static PurgeCommand ConstructIntervalCommand(PurgeCommandScope scope, UserTrashBin trashBin, int dayInterval, int hourInterval, int minInterval)
        {
            PurgeCommand cmd = new PurgeCommand(scope, PurgeCommandType.INTERVAL, dayInterval, hourInterval, minInterval);

            cmd.AddUserTrash(trashBin);

            return(cmd);
        }
예제 #2
0
		public void AddCommand(PurgeCommand cmd)
		{
			if (cmd != null)
			{
				if (this.commandList == null)
					this.commandList = new ArrayList();

				this.commandList.Add(cmd);
			}
		}
예제 #3
0
        public static PurgeCommand ConstructAgeCommand(PurgeCommandScope scope, ArrayList trashBins, int dayInterval, int hourInterval, int minInterval)
        {
            PurgeCommand cmd = new PurgeCommand(scope, PurgeCommandType.AGE, dayInterval, hourInterval, minInterval);

            foreach (UserTrashBin trashBin in trashBins)
            {
                cmd.AddUserTrash(trashBin);
            }

            return(cmd);
        }
예제 #4
0
        public static PurgeCommand ConstructMegsCommand(PurgeCommandScope scope, ArrayList trashBins, int megLimit)
        {
            PurgeCommand cmd = new PurgeCommand(scope, PurgeCommandType.MEGS, megLimit);

            foreach (UserTrashBin trashBin in trashBins)
            {
                cmd.AddUserTrash(trashBin);
            }

            return(cmd);
        }
예제 #5
0
        // ---------------------------------------------------
        // performs purge - if purge scope is overriden, returns false; otherwise performs purge and returns true
        public bool ExecutePurge(PurgeCommand cmd)
        {
            if (!DosUtils.DirectoryExistFast(this.trashPath))
            {
                //MessageBox.Show("Rejected purge of \n\n\t" + this.trashPath + "\n\t(COMMAND: " + cmd.ToString() + ")" + "\n\n because dir does not exist");
                if (this.logActions)
                {
                    Utils.AppendLineToFile(this.logFilename, DateTime.Now.ToString() + ":\tUserTrashBin: Rejected purge of '" + this.trashPath + "' from command { " + cmd.ToString() + " } because the specified directory does not exist");
                }

                return(false);
            }

            if (cmd.Type != PurgeCommandType.FORCE)
            {
                if (cmd.Scope == PurgeCommandScope.GLOBAL && this.overridesGlobal)
                {
                    //MessageBox.Show("Rejected purge of \n\n\t" + this.trashPath + "\n\t(COMMAND: " + cmd.ToString() + ")" + "\n\n because it overrides global commands");
                    if (this.logActions)
                    {
                        Utils.AppendLineToFile(this.logFilename, DateTime.Now.ToString() + ":\tUserTrashBin: Rejected purge of '" + this.trashPath + "' from command { " + cmd.ToString() + " } because it overrides global commands");
                    }

                    return(false);                              // don't purge if we override global commands
                }

                if (cmd.Scope == PurgeCommandScope.PROJECT && this.overridesProject)
                {
                    //MessageBox.Show("Rejected purge of \n\n\t" + this.trashPath + "\n\t(COMMAND: " + cmd.ToString() + ")" + "\n\n because it overrides project commands");
                    if (this.logActions)
                    {
                        Utils.AppendLineToFile(this.logFilename, DateTime.Now.ToString() + ":\tUserTrashBin: Rejected purge of '" + this.trashPath + "' from command { " + cmd.ToString() + " } because it overrides project commands");
                    }

                    return(false);                              // don't purge if we override project commands
                }
            }


            // execute purge
            if (cmd.Type == PurgeCommandType.FORCE || cmd.Type == PurgeCommandType.INTERVAL)
            {
                try
                {
                    Directory.Delete(this.trashPath, true);
                    Directory.CreateDirectory(this.trashPath);

                    this.lastPurged = DateTime.Now;

                    //MessageBox.Show("Purged \n\n\t" + this.trashPath + "\n\t(COMMAND: " + cmd.ToString() + ")" + "\n\nat " + this.lastPurged.ToString(), "Purged");
                    if (this.logActions)
                    {
                        Utils.AppendLineToFile(this.logFilename, DateTime.Now.ToString() + ":\tUserTrashBin: Purged '" + this.trashPath + "' from command { " + cmd.ToString() + " }");
                    }
                }
                catch (Exception e)
                {
                    //MessageBox.Show("Failed purge of \n\n\t" + this.trashPath + "\n\t(COMMAND: " + cmd.ToString() + ")" + "\n\nat " + this.lastPurged.ToString() + " due to an exception:\n\n" + e.Message + "\n" + e.StackTrace, "Exception");
                    if (this.logActions)
                    {
                        Utils.AppendLineToFile(this.logFilename, DateTime.Now.ToString() + ":\tUserTrashBin: Failed purge of '" + this.trashPath + "' from command { " + cmd.ToString() + " } due to an exception:\n\n" + e.Message + "\n" + e.StackTrace);
                    }
                }
            }
            else if (cmd.Type == PurgeCommandType.AGE)
            {
                ArrayList filelist = DeleteFilesByAge(this.trashPath, cmd.DayInterval, cmd.HourInterval, cmd.MinInterval, true);
                //string msg = "";
                //foreach (string file in filelist)
                //	msg += "\t" + file + "\n";
                //MessageBox.Show("Age Purge of " + this.trashPath + " resulted in the following actions:\n\n" + msg);
                if (this.logActions)
                {
                    Utils.AppendLineToFile(this.logFilename, DateTime.Now.ToString() + ":\tUserTrashBin: Age-purge of '" + this.trashPath + "' from command { " + cmd.ToString() + " } resulted in the following actions:");
                    foreach (string file in filelist)
                    {
                        Utils.AppendLineToFile(this.logFilename, "\t\t\t\t" + file);
                    }
                }
            }
            else if (cmd.Type == PurgeCommandType.MEGS)
            {
                if (DirSizeInMegs(this.trashPath) > (float)cmd.MegsLimit)
                {
                    // purge it baby
                    try
                    {
                        Directory.Delete(this.trashPath, true);
                        Directory.CreateDirectory(this.trashPath);

                        this.lastPurged = DateTime.Now;

                        //MessageBox.Show("Purged (MEGS) \n\n\t" + this.trashPath + "\n\t(COMMAND: " + cmd.ToString() + ")" + "\n\nat " + this.lastPurged.ToString(), "Purged");
                        if (this.logActions)
                        {
                            Utils.AppendLineToFile(this.logFilename, DateTime.Now.ToString() + ":\tUserTrashBin: Megs-purged '" + this.trashPath + "' from command { " + cmd.ToString() + " }");
                        }
                    }
                    catch (Exception e)
                    {
                        //MessageBox.Show("Failed purge (MEGS) of \n\n\t" + this.trashPath + "\n\t(COMMAND: " + cmd.ToString() + ")" + "\n\nat " + this.lastPurged.ToString() + " due to an exception:\n\n" + e.Message + "\n" + e.StackTrace, "Exception");
                        if (this.logActions)
                        {
                            Utils.AppendLineToFile(this.logFilename, DateTime.Now.ToString() + ":\tUserTrashBin: Failed megs-purge of '" + this.trashPath + "' from command { " + cmd.ToString() + " } due to an exception:\n\n" + e.Message + "\n" + e.StackTrace);
                        }
                    }
                }
            }

            return(true);
        }