An example usage to get you started:
This exports all projects and keeps the last 3 days, add it to a
schedule and you're all done:
I Havn't included the Helper classes but you can just put your own
code in.
using System;
using System.Collections.Generic;
using System.Text;
using Sbc.Helper;
using System.IO;
using System.Configuration;
using RustyLogic.RedDotNet;
namespace RustyLogic.RedDotDailyExport
{
class Program
{
static void Main(string[] args)
{
ConfigHelper.Encrypt(false);
string username =
ConfigurationManager.AppSettings["username"];
string password =
ConfigurationManager.AppSettings["password"];
string exportPath =
ConfigurationManager.AppSettings["exportPath"];
string emailTo =
ConfigurationManager.AppSettings["emailTo"];
string emailFrom =
ConfigurationManager.AppSettings["emailFrom"];
string serverName =
ConfigurationManager.AppSettings["serverName"];
EmailHelper emailHelper = new EmailHelper("localhost");
Session.Login(username, password);
try
{
User exportUser = null;
foreach (User user in User.List())
{
if (user.Name == username)
{
exportUser = user;
break;
}
}
Server server = null;
foreach (Server cmsServer in Server.List())
{
if (cmsServer.Name == serverName)
{
server = cmsServer;
}
}
List<Project> projects = Project.List();
DirectoryInfo exportDir = new
DirectoryInfo(exportPath);
foreach (Project project in projects)
{
project.Select();
try
{
// Clear out some publishing logs or the
export may fail.
project.DeletePublishingLogs(3);
project.Export(exportDir, true, true, true,
true, server, server, true, exportUser, project.Name + " export job
completed", project.Name + " export job completed on " + server.Name +
" as " + exportUser.Name);
}
catch (Exception ex)
{
emailHelper.Send(emailFrom, emailTo, "Export
Failed", ex.Message + ex.StackTrace + ex.Data);
}
}
PurgeDirectory(exportPath, new TimeSpan(48, 0, 0));
}
catch (Exception ex)
{
emailHelper.Send(emailFrom, emailTo, "Export Failed",
ex.Message + ex.StackTrace + ex.Data);
}
finally
{
Session.Logout();
}
}
public static void PurgeDirectory(string rootDirectory,
TimeSpan maximumAge)
{
DirectoryInfo root = new DirectoryInfo(rootDirectory);
DirectoryInfo[] directories = root.GetDirectories();
foreach (DirectoryInfo dir in directories)
{
TimeSpan directoryAge =
DateTime.Now.Subtract(dir.CreationTime);
if (directoryAge.CompareTo(maximumAge) > 0)
{
dir.Delete(true);
> > >
http://groups.google.co.uk/group/RedDot-CMS-Users/web/RustyLogic.zip?...Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -