Update cvsbulk import to support mailbox plans

This commit is contained in:
Virtuworks 2013-01-18 18:47:19 -05:00
parent 62d638ea7b
commit 96ca6053b6

View file

@ -92,7 +92,10 @@ namespace WebsitePanel.Import.CsvBulk
private int PagerIndex = -1;
private int WebPageIndex = -1;
private int NotesIndex = -1;
private int PlanIndex = -1;
private int defaultPlanId = -1;
private Dictionary<string, int> planName2Id = new Dictionary<string,int>();
public ExchangeImport()
{
@ -184,6 +187,8 @@ namespace WebsitePanel.Import.CsvBulk
}
index = 0;
GetMailboxPlans(orgId);
using (StreamReader sr = new StreamReader(inputFile))
{
string line;
@ -210,6 +215,22 @@ namespace WebsitePanel.Import.CsvBulk
}
}
private void GetMailboxPlans(int orgId)
{
ExchangeMailboxPlan[] plans = ES.Services.ExchangeServer.GetExchangeMailboxPlans(orgId);
foreach (ExchangeMailboxPlan plan in plans)
{
if (!planName2Id.ContainsKey(plan.MailboxPlan))
{
planName2Id.Add(plan.MailboxPlan, plan.MailboxPlanId);
}
if (plan.IsDefault)
{
defaultPlanId = plan.MailboxPlanId;
}
}
}
private void ShowSummary()
{
Log.WriteLine(string.Format("{0} line(s) processed", index));
@ -286,7 +307,9 @@ namespace WebsitePanel.Import.CsvBulk
WebPageIndex = i;
else if (StringEquals(cells[i], "Notes"))
NotesIndex = i;
}
else if (StringEquals(cells[i], "Mailbox Plan"))
PlanIndex = i;
}
return true;
}
//check csv structure
@ -430,6 +453,29 @@ namespace WebsitePanel.Import.CsvBulk
string webPage = cells[WebPageIndex];
string notes = cells[NotesIndex];
int planId;
// do we have plan-column?
if (PlanIndex > -1)
{
string planName = cells[PlanIndex];
if (!planName2Id.TryGetValue(planName, out planId))
{
Log.WriteInfo(String.Format("Warning at line {0}: Plan named {1} does not exist!", index + 1, planName));
// fall back to default plan
planId = defaultPlanId;
}
}
// or not?
else
{
// fall back to default plan
planId = defaultPlanId;
}
if (planId < 0)
{
Log.WriteError(string.Format("Error at line {0}: No valid plan name and/or no valid default plan", index + 1));
return false;
}
@ -480,7 +526,7 @@ namespace WebsitePanel.Import.CsvBulk
//create mailbox using web service
if (!CreateMailbox(index, orgId, displayName, emailAddress, password, firstName, middleName, lastName,
address, city, state, zip, country, jobTitle, company, department, office,
businessPhone, fax, homePhone, mobilePhone, pager, webPage, notes))
businessPhone, fax, homePhone, mobilePhone, pager, webPage, notes, planId))
{
return false;
}
@ -517,7 +563,7 @@ namespace WebsitePanel.Import.CsvBulk
/// </summary>
private bool CreateMailbox(int index, int orgId, string displayName, string emailAddress, string password, string firstName, string middleName, string lastName,
string address, string city, string state, string zip, string country, string jobTitle, string company, string department, string office,
string businessPhone, string fax, string homePhone, string mobilePhone, string pager, string webPage, string notes)
string businessPhone, string fax, string homePhone, string mobilePhone, string pager, string webPage, string notes, int planId)
{
bool ret = false;
try
@ -528,7 +574,7 @@ namespace WebsitePanel.Import.CsvBulk
//create mailbox
//ES.Services.ExchangeServer.
string accountName = string.Empty;
int accountId = ES.Services.ExchangeServer.CreateMailbox(orgId, 0, ExchangeAccountType.Mailbox, accountName, displayName, name, domain, password, false, string.Empty, 0, string.Empty);
int accountId = ES.Services.ExchangeServer.CreateMailbox(orgId, 0, ExchangeAccountType.Mailbox, accountName, displayName, name, domain, password, false, string.Empty, planId, string.Empty);
if (accountId < 0)
{
string errorMessage = GetErrorMessage(accountId);
@ -557,7 +603,6 @@ namespace WebsitePanel.Import.CsvBulk
mailbox.WebPage = webPage;
mailbox.Notes = notes;
//update mailbox
/*
ES.Services.ExchangeServer.SetMailboxGeneralSettings(orgId, accountId, mailbox.DisplayName,