Mailboxplan Policy adjusted. Restamp and stamp buttons moved to grid. Only

two options:
a) Restamp mailboxes with the selected plan assigned and enforce
mailbox settings as such
b) stamp not assigned mailboxes with the selected plan.
This commit is contained in:
robvde 2012-08-06 19:03:38 +04:00
parent 4552d47fc4
commit 0475288ebd
4 changed files with 87 additions and 206 deletions

View file

@ -216,14 +216,14 @@
<data name="btnAddMailboxPlanToOrganizations.Text" xml:space="preserve">
<value>Add Mailbox Plans Template to All Tenants</value>
</data>
<data name="btnMatchMailboxPlanToUser.Text" xml:space="preserve">
<value>Match Mailbox Plan to User</value>
<data name="btnStampUnassigned.Text" xml:space="preserve">
<value>Stamp unassigned mailboxes</value>
</data>
<data name="secTools.Text" xml:space="preserve">
<value>Tools</value>
</data>
<data name="btnStamp.Text" xml:space="preserve">
<value>Restamp all mailboxes</value>
<value>Restamp mailboxes</value>
</data>
<data name="btnUpdateMailboxPlan.Text" xml:space="preserve">
<value>Update Mailbox Plan</value>

View file

@ -33,6 +33,21 @@
meta:resourcekey="cmdDelete" OnClientClick="return confirm('Are you sure you want to delete selected mailbox plan?')"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnStamp" runat="server" meta:resourcekey="btnStamp"
Text="Restamp all mailboxes with this plan" CssClass="Button1" CommandName="RestampItem" CommandArgument='<%# Eval("MailboxPlanId") %>' OnClientClick="if (confirm('Restamp mailboxes with this plan.\n\nAre you sure you want to restamp the mailboxes ?')) ShowProgressDialog('Stamping mailboxes, this might take a while ...'); else return false;"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnStampUnassigned" runat="server" meta:resourcekey="btnStampUnassigned"
Text="Stamp unassigned mailboxes" CssClass="Button1"
CommandName="StampUnassigned" CommandArgument='<%# Eval("MailboxPlanId") %>'
OnClientClick="if (confirm('Stamp unassigned mailboxes with this mailbox plan.\n\nAre you sure you want to continue with this ?')) ShowProgressDialog('Applying mailbox plans, this might take a while ...'); else return false;" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
@ -192,29 +207,5 @@
<br />
<wsp:CollapsiblePanel id="secTools" runat="server" TargetControlID="Tools" meta:resourcekey="secTools" Text="Tools">
</wsp:CollapsiblePanel>
<asp:Panel ID="Tools" runat="server" Height="0" style="overflow:hidden;">
<table>
<tr>
<td>
<asp:Button ID="btnStamp" runat="server" meta:resourcekey="btnStamp"
Text="Restamp all mailboxes" CssClass="Button1" OnClick="btnStampClick" OnClientClick="if (confirm('Restamp mailboxes with these plans. \nAre you sure you want to restamp the mailbox plans ?')) ShowProgressDialog('Stamping mailboxes, this might take a while ...'); else return false;"/>
</td>
<td>
<asp:TextBox ID="txtStatus" runat="server" CssClass="TextBox400" MaxLength="128" ReadOnly="true"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnMatchMailboxPlanToUser" runat="server" meta:resourcekey="btnMatchMailboxPlanToUser"
Text="Match Plan to User" CssClass="Button1"
OnClientClick="if (confirm('Mail enabled users with no mailbox plan assigned will get a matching mailbox plan applied.\nMatching takes place on mailbox size and the MAPI properties.\n\nAre you sure you want to continue with this ?')) ShowProgressDialog('Applying mailbox plans, this might take a while ...'); else return false;"
onclick="btnMatchMailboxPlanToUser_Click" />
</td>
</tr>
</table>
<br />
</asp:Panel>
<asp:TextBox ID="txtStatus" runat="server" CssClass="TextBox400" MaxLength="128" ReadOnly="true"></asp:TextBox>

View file

@ -275,6 +275,13 @@ namespace WebsitePanel.Portal
btnUpdateMailboxPlan.Enabled = (string.IsNullOrEmpty(txtMailboxPlan.Text)) ? false : true;
break;
case "RestampItem":
RestampMailboxes(mailboxPlanId);
break;
case "StampUnassigned":
StampUnAssigned(mailboxPlanId);
break;
}
}
@ -407,139 +414,12 @@ namespace WebsitePanel.Portal
return result;
}
protected void btnMatchMailboxPlanToUser_Click(object sender, EventArgs e)
{
MatchMailboxPlanToUser("serverAdmin");
}
private void MatchMailboxPlanToUser(string serverAdmin)
{
UserInfo ServerAdminInfo = ES.Services.Users.GetUserByUsername(serverAdmin);
if (ServerAdminInfo == null) return;
UserInfo[] UsersInfo = ES.Services.Users.GetUsers(ServerAdminInfo.UserId, true);
try
{
foreach (UserInfo ui in UsersInfo)
{
PackageInfo[] Packages = ES.Services.Packages.GetPackages(ui.UserId);
if ((Packages != null) & (Packages.GetLength(0) > 0))
{
foreach (PackageInfo Package in Packages)
{
Providers.HostedSolution.Organization[] orgs = null;
orgs = ES.Services.ExchangeServer.GetExchangeOrganizations(Package.PackageId, false);
if ((orgs != null) & (orgs.GetLength(0) > 0))
{
foreach (Organization org in orgs)
{
if (!string.IsNullOrEmpty(org.GlobalAddressList))
{
ExchangeMailboxPlan[] plans = ES.Services.ExchangeServer.GetExchangeMailboxPlans(org.Id);
ExchangeAccount[] mailboxes = ES.Services.ExchangeServer.GetAccounts(org.Id, ExchangeAccountType.Mailbox);
ExchangeAccount[] rooms = ES.Services.ExchangeServer.GetAccounts(org.Id, ExchangeAccountType.Room);
ExchangeAccount[] equipment = ES.Services.ExchangeServer.GetAccounts(org.Id, ExchangeAccountType.Equipment);
MatchExchangeAccountToPlan(org.Id, mailboxes, plans);
MatchExchangeAccountToPlan(org.Id, rooms, plans);
MatchExchangeAccountToPlan(org.Id, equipment, plans);
}
}
}
}
}
}
messageBox.ShowSuccessMessage("EXCHANGE_MATCHPLANS");
}
catch (Exception ex)
{
messageBox.ShowErrorMessage("EXCHANGE_MATCHPLANS", ex);
}
}
private void MatchExchangeAccountToPlan(int itemId, ExchangeAccount[] mailboxes, ExchangeMailboxPlan[] plans)
{
foreach (ExchangeAccount a in mailboxes)
{
if (string.IsNullOrEmpty(a.MailboxPlan))
{
ExchangeMailbox mailbox = ES.Services.ExchangeServer.GetMailboxAdvancedSettings(itemId, a.AccountId);
if (mailbox != null)
{
List<ExchangeMailboxPlan> pl = new List<ExchangeMailboxPlan>();
//sort a list of similar MAPI
foreach (ExchangeMailboxPlan p in plans)
{
if (p.EnableMAPI == mailbox.EnableMAPI)
pl.Add(p);
}
//remove plans smaller than mailbox size
ExchangeMailboxPlan p3 = null;
foreach (ExchangeMailboxPlan p2 in pl)
{
if ((p2.MailboxSizeMB == -1) & (mailbox.ProhibitSendReceiveKB == -1))
{
p3 = p2;
break;
}
if (p2.MailboxSizeMB >= (mailbox.ProhibitSendReceiveKB / 1024))
{
if (p3 == null)
p3 = p2;
else
if ((p2.MailboxSizeMB) <= p3.MailboxSizeMB)
p3 = p2;
}
}
// no matching plan, just match on size
if (p3 == null)
{
foreach (ExchangeMailboxPlan p in plans)
{
if ((p.MailboxSizeMB == -1) & (mailbox.ProhibitSendReceiveKB == -1))
{
p3 = p;
break;
}
if (p.MailboxSizeMB >= (mailbox.ProhibitSendReceiveKB / 1024))
{
if (p3 == null)
p3 = p;
else
if ((p.MailboxSizeMB) <= p3.MailboxSizeMB)
p3 = p;
}
}
}
if (p3 != null)
ES.Services.ExchangeServer.SetExchangeMailboxPlan(itemId, a.AccountId, p3.MailboxPlanId);
}
}
}
}
protected void txtMailboxPlan_TextChanged(object sender, EventArgs e)
{
btnUpdateMailboxPlan.Enabled = (string.IsNullOrEmpty(txtMailboxPlan.Text)) ? false : true;
}
protected void btnStampClick(object sender, EventArgs e)
private void RestampMailboxes(int mailboxPlanId)
{
txtStatus.Visible = true;
@ -563,23 +443,18 @@ namespace WebsitePanel.Portal
if ((orgs != null) & (orgs.GetLength(0) > 0))
{
ExchangeMailboxPlan[] list = ES.Services.ExchangeServer.GetExchangeMailboxPlans(orgs[0].Id);
ExchangeAccount[] Accounts = ES.Services.ExchangeServer.GetExchangeAccountByMailboxPlanId(0, mailboxPlanId);
foreach (ExchangeMailboxPlan p in list)
foreach (ExchangeAccount a in Accounts)
{
ExchangeAccount[] Accounts = ES.Services.ExchangeServer.GetExchangeAccountByMailboxPlanId(0, p.MailboxPlanId);
foreach (ExchangeAccount a in Accounts)
txtStatus.Text = "Completed";
int result = ES.Services.ExchangeServer.SetExchangeMailboxPlan(a.ItemId, a.AccountId, mailboxPlanId);
if (result < 0)
{
txtStatus.Text = "Completed";
int result = ES.Services.ExchangeServer.SetExchangeMailboxPlan(a.ItemId, a.AccountId, p.MailboxPlanId);
if (result < 0)
{
BindMailboxPlans();
txtStatus.Text = "Error: " + a.AccountName;
messageBox.ShowErrorMessage("EXCHANGE_STAMPMAILBOXES");
return;
}
BindMailboxPlans();
txtStatus.Text = "Error: " + a.AccountName;
messageBox.ShowErrorMessage("EXCHANGE_STAMPMAILBOXES");
return;
}
}
}
@ -595,5 +470,56 @@ namespace WebsitePanel.Portal
}
private void StampUnAssigned(int mailboxPlanId)
{
txtStatus.Visible = true;
try
{
Providers.HostedSolution.Organization[] orgs = null;
if (PanelSecurity.SelectedUserId != 1)
{
PackageInfo[] Packages = ES.Services.Packages.GetPackages(PanelSecurity.SelectedUserId);
if ((Packages != null) & (Packages.GetLength(0) > 0))
{
orgs = ES.Services.ExchangeServer.GetExchangeOrganizations(Packages[0].PackageId, false);
}
}
else
{
orgs = ES.Services.ExchangeServer.GetExchangeOrganizations(1, false);
}
if ((orgs != null) & (orgs.GetLength(0) > 0))
{
ExchangeAccount[] Accounts = ES.Services.ExchangeServer.GetExchangeAccountByMailboxPlanId(PanelRequest.ItemID, -1);
foreach (ExchangeAccount a in Accounts)
{
txtStatus.Text = "Completed";
int result = ES.Services.ExchangeServer.SetExchangeMailboxPlan(PanelRequest.ItemID, a.AccountId, mailboxPlanId);
if (result < 0)
{
BindMailboxPlans();
txtStatus.Text = "Error: " + a.AccountName;
messageBox.ShowErrorMessage("EXCHANGE_FAILED_TO_STAMP");
return;
}
}
}
messageBox.ShowSuccessMessage("EXCHANGE_STAMPMAILBOXES");
}
catch (Exception ex)
{
messageBox.ShowErrorMessage("EXCHANGE_FAILED_TO_STAMP", ex);
}
BindMailboxPlans();
}
}
}

View file

@ -372,33 +372,6 @@ namespace WebsitePanel.Portal {
/// </remarks>
protected global::System.Web.UI.WebControls.Button btnUpdateMailboxPlan;
/// <summary>
/// secTools control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::WebsitePanel.Portal.CollapsiblePanel secTools;
/// <summary>
/// Tools control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Panel Tools;
/// <summary>
/// btnStamp control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Button btnStamp;
/// <summary>
/// txtStatus control.
/// </summary>
@ -407,14 +380,5 @@ namespace WebsitePanel.Portal {
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.TextBox txtStatus;
/// <summary>
/// btnMatchMailboxPlanToUser control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Button btnMatchMailboxPlanToUser;
}
}