DotNetNuke Scheduler

Code


public class ArchiveEventLog : DotNetNuke.Services.Scheduling.SchedulerClient
{
    
public ArchiveEventLog(DotNetNuke.Services.Scheduling.ScheduleHistoryItem objScheduleHistoryItem) : base()
    {
            
//REQUIRED
        this.ScheduleHistoryItem = objScheduleHistoryItem;
    }
    
public override void DoWork()
    {
        
try {
            
//notification that the event is progressing
            
//this is optional
            this.Progressing();
            
//OPTIONAL
            
//get the directory that logs are written to
            string LogDirectory = null;
            LogDirectory 
= Common.Globals.HostMapPath + "Logs\\";
           
            
//create a folder with today's date
            string FolderName = null;
            FolderName 
= LogDirectory + Now.Month.ToString + "-" + Now.Day.ToString + "-" + Now.Year.ToString + "\\";
            
if (!IO.Directory.Exists(FolderName)) {
                IO.Directory.CreateDirectory(FolderName);
            }
           
            
//get the files in the log directory
            string[] s = null;
            s 
= IO.Directory.GetFiles(LogDirectory);
            
//loop through the files
            int i = 0;
            
for (i = 0; i <= s.Length - 1; i++) {
                IO.FileInfo OldFileInfo 
= new IO.FileInfo(s(i));
                
//move all files to the new folder except the file
                
//used to store pending log notifications
                if (OldFileInfo.Name != "PendingLogNotifications.xml.resources") {
                    
string NewFileName = null;
                    NewFileName 
= FolderName + OldFileInfo.Name;
                    
//check to see if the new file already exists
                    if (IO.File.Exists(NewFileName)) {
                        
string errMessage = null;
                        errMessage 
= "An error occurred archiving " + "log file to " + NewFileName + ". The file already exists.";
                        LogException(
new BasePortalException(errMessage));
                    }
                    
else {
                        IO.File.Move(OldFileInfo.FullName, NewFileName);
                            
//OPTIONAL
                        this.ScheduleHistoryItem.AddLogNote("Moved " + OldFileInfo.FullName + " to " + FolderName + OldFileInfo.Name + ".");
                       
                    }
                }
            }
           
                
//REQUIRED
            this.ScheduleHistoryItem.Succeeded = true;
        }
        
catch (Exception exc) {
           
            
//REQUIRED
           
            
this.ScheduleHistoryItem.Succeeded = false;
            
//REQUIRED
           
            
this.ScheduleHistoryItem.AddLogNote(string.Format("Archiving log files failed.", exc.ToString));
            
//OPTIONAL
           
            
//notification that we have errored
            this.Errored(exc);
            
//REQUIRED
           
            
//log the exception
                
//OPTIONAL
            LogException(exc);
        }
    }
}

posted @ 2009-04-16 19:32  无尽思绪  阅读(328)  评论(0编辑  收藏  举报