This commit is contained in:
Virtuworks 2014-12-17 11:54:51 -05:00
commit cfa335ba42
4 changed files with 112 additions and 19 deletions

View file

@ -279,10 +279,15 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
private static void PopulateOrganizationData(Organization org, EnterpriseSolutionStatisticsReport report, string topReseller)
{
TaskManager.Write("Stat populate organization data "+org.Name);
if (report.ExchangeReport != null)
{
try
{
TaskManager.Write("Populate exchange report items");
PopulateExchangeReportItems(org, report, topReseller);
}
catch(Exception ex)
@ -295,6 +300,8 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
{
try
{
TaskManager.Write("Populate populate CRM report items");
PopulateCRMReportItems(org, report, topReseller);
}
catch(Exception ex)
@ -307,6 +314,8 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
{
try
{
TaskManager.Write("Populate SharePoint item ");
PopulateSharePointItem(org, report, topReseller);
}
catch(Exception ex)
@ -319,6 +328,8 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
{
try
{
TaskManager.Write("Populate Lync report items");
PopulateLyncReportItems(org, report, topReseller);
}
catch (Exception ex)
@ -331,6 +342,8 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
{
try
{
TaskManager.Write("Populate Organization statistics report");
PopulateOrganizationStatisticsReport(org, report, topReseller);
}
catch(Exception ex)
@ -339,7 +352,7 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
}
}
TaskManager.Write("End populate organization data " + org.Name);
}
private static int GetExchangeServiceID(int packageId)
@ -408,6 +421,8 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
private static void PopulateExchangeReportItems(Organization org, EnterpriseSolutionStatisticsReport report, string topReseller)
{
TaskManager.Write("Exchange Report Items " + org.Name);
//Check if exchange organization
if (string.IsNullOrEmpty(org.GlobalAddressList))
return;
@ -420,10 +435,14 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
}
catch (Exception ex)
{
TaskManager.WriteError(ex);
throw new ApplicationException(
string.Format("Could not get mailboxes for current organization {0}", org.Id), ex);
}
TaskManager.WriteParameter("mailboxes.Count", mailboxes.Count);
try
{
int exchangeServiceId = GetExchangeServiceID(org.PackageId);
@ -431,6 +450,8 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
}
catch(Exception ex)
{
TaskManager.WriteError(ex);
throw new ApplicationException(
string.Format("Could not get exchange server. PackageId: {0}", org.PackageId), ex);
}
@ -440,6 +461,8 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
{
try
{
TaskManager.WriteParameter("mailbox", mailbox.UserPrincipalName);
stats = null;
try
{
@ -448,6 +471,8 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
}
catch (Exception ex)
{
TaskManager.WriteError(ex);
TaskManager.WriteError(ex, "Could not get mailbox statistics. AccountName: {0}",
mailbox.UserPrincipalName);
}
@ -466,6 +491,8 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
stats.BlackberryEnabled = BlackBerryController.CheckBlackBerryUserExists(mailbox.AccountId);
report.ExchangeReport.Items.Add(stats);
TaskManager.Write("Items.Add");
}
}
catch(Exception ex)
@ -474,6 +501,7 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
}
}
TaskManager.Write("End Populate Exchange Report Items " + org.Name);
}
@ -547,6 +575,8 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
private static void PopulateSpaceData(int packageId, EnterpriseSolutionStatisticsReport report, string topReseller)
{
TaskManager.Write("Populate SpaceData " + packageId);
List<Organization> organizations;
try
@ -570,10 +600,14 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
TaskManager.WriteError(ex);
}
}
TaskManager.Write("End Populate SpaceData " + packageId);
}
private static void PopulateUserData(UserInfo user, EnterpriseSolutionStatisticsReport report, string topReseller)
{
TaskManager.Write("Populate UserData " + user.Username);
DataSet ds;
try
{
@ -597,10 +631,13 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
}
}
TaskManager.Write("End Populate UserData " + user.Username);
}
private static void GetUsersData(EnterpriseSolutionStatisticsReport report, int userId, bool generateExchangeReport, bool generateSharePointReport, bool generateCRMReport, bool generateOrganizationReport, bool generateLyncReport, string topReseller)
{
TaskManager.Write("Get UsersData " + userId);
List<UserInfo> users;
try
{
@ -611,9 +648,12 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
throw new ApplicationException("Cannot get users for report", ex);
}
TaskManager.WriteParameter("users.Count", users.Count);
foreach (UserInfo user in users)
{
TaskManager.WriteParameter("User", user.Username);
try
{
PopulateUserData(user, report, topReseller);
@ -632,10 +672,15 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
TaskManager.WriteError(ex);
}
}
TaskManager.Write("End get UsersData " + userId);
}
public static EnterpriseSolutionStatisticsReport GetEnterpriseSolutionStatisticsReport(int userId, bool generateExchangeReport, bool generateSharePointReport, bool generateCRMReport, bool generateOrganizationReport, bool generateLyncReport)
{
TaskManager.Write("Get enterprise solution statistics report " + userId);
EnterpriseSolutionStatisticsReport report = new EnterpriseSolutionStatisticsReport();
if (generateExchangeReport || generateOrganizationReport)
@ -647,7 +692,6 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
if (generateLyncReport || generateOrganizationReport)
report.LyncReport = new LyncStatisticsReport();
if (generateCRMReport || generateOrganizationReport)
report.CRMReport = new CRMStatisticsReport();
@ -664,6 +708,8 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution
TaskManager.WriteError(ex, "Cannot get enterprise solution statistics report");
}
TaskManager.Write("End get enterprise solution statistics report " + userId);
return report;
}

View file

@ -32,6 +32,7 @@ using System.IO;
using System.Net.Mail;
using System.Net.Mime;
using System.Text;
using WebsitePanel.EnterpriseServer;
using WebsitePanel.EnterpriseServer.Code.HostedSolution;
using WebsitePanel.Providers.HostedSolution;
@ -51,6 +52,8 @@ namespace WebsitePanel.EnterpriseServer
{
try
{
TaskManager.Write("Start HostedSolutionReportTask");
BackgroundTask topTask = TaskManager.TopTask;
bool isExchange = Utils.ParseBool(topTask.GetParamValue(EXCHANGE_REPORT), false);
@ -61,23 +64,41 @@ namespace WebsitePanel.EnterpriseServer
string email = topTask.GetParamValue(EMAIL).ToString();
TaskManager.WriteParameter("isExchange",isExchange);
TaskManager.WriteParameter("isSharePoint",isSharePoint);
TaskManager.WriteParameter("isLync", isLync);
TaskManager.WriteParameter("isCRM", isCRM);
TaskManager.WriteParameter("isOrganization", isOrganization);
TaskManager.WriteParameter("email", email);
UserInfo user = PackageController.GetPackageOwner(topTask.PackageId);
TaskManager.WriteParameter("user", user.Username);
EnterpriseSolutionStatisticsReport report =
ReportController.GetEnterpriseSolutionStatisticsReport(user.UserId, isExchange, isSharePoint, isCRM,
isOrganization, isLync);
TaskManager.WriteParameter("report.ExchangeReport.Items.Count", report.ExchangeReport.Items.Count);
TaskManager.WriteParameter("report.SharePointReport.Items.Count", report.SharePointReport.Items.Count);
TaskManager.WriteParameter("report.CRMReport.Items.Count", report.CRMReport.Items.Count);
TaskManager.WriteParameter("report.OrganizationReport.Items.Count", report.OrganizationReport.Items.Count);
TaskManager.WriteParameter("report.LyncReport.Items.Count", report.LyncReport.Items.Count);
SendMessage(user, email, isExchange && report.ExchangeReport != null ? report.ExchangeReport.ToCSV() : string.Empty,
isSharePoint && report.SharePointReport != null ? report.SharePointReport.ToCSV() : string.Empty,
isCRM && report.CRMReport != null ? report.CRMReport.ToCSV() : string.Empty,
isOrganization && report.OrganizationReport != null ? report.OrganizationReport.ToCSV() : string.Empty,
isLync && report.LyncReport != null ? report.LyncReport.ToCSV() : string.Empty);
}
catch(Exception ex)
{
TaskManager.WriteError(ex);
}
TaskManager.Write("End HostedSolutionReportTask");
}
@ -97,6 +118,8 @@ namespace WebsitePanel.EnterpriseServer
private void SendMessage(UserInfo user,string email, string exchange_csv, string sharepoint_csv, string crm_csv, string organization_csv, string lync_csv)
{
TaskManager.Write("SendMessage");
List<Attachment> attacments = new List<Attachment>();
PrepareAttament("exchange.csv", exchange_csv, attacments);
PrepareAttament("sharepoint.csv", sharepoint_csv, attacments);
@ -104,9 +127,6 @@ namespace WebsitePanel.EnterpriseServer
PrepareAttament("crm.csv", crm_csv, attacments);
PrepareAttament("organization.csv", organization_csv, attacments);
// get letter settings
UserSettings settings = UserController.GetUserSettings(user.UserId, UserSettings.HOSTED_SOLUTION_REPORT);
@ -118,7 +138,27 @@ namespace WebsitePanel.EnterpriseServer
MailPriority priority = MailPriority.Normal;
MailHelper.SendMessage(from, email, cc, subject, body, priority, isHtml, attacments.ToArray());
TaskManager.WriteParameter("from", from);
TaskManager.WriteParameter("email", email);
TaskManager.WriteParameter("subject", subject);
TaskManager.WriteParameter("body", body);
int res = MailHelper.SendMessage(from, email, cc, subject, body, priority, isHtml, attacments.ToArray());
if (res==0)
{
TaskManager.Write("SendMessage OK");
}
else
{
TaskManager.WriteError("SendMessage error ", "error code", res.ToString());
}
TaskManager.WriteParameter("", res);
TaskManager.Write("End SendMessage");
}
}

View file

@ -35,15 +35,16 @@ namespace WebsitePanel.SchedulerService
public partial class SchedulerService : ServiceBase
{
private Timer _Timer;
private static bool _isRuninng;
private static object _isRuninng;
#region Construcor
public SchedulerService()
{
_isRuninng = new object();
InitializeComponent();
_Timer = new Timer(Process, null, 5000, 5000);
_isRuninng = false;
}
#endregion
@ -57,12 +58,18 @@ namespace WebsitePanel.SchedulerService
protected static void Process(object callback)
{
//check running service
if (_isRuninng)
if (!Monitor.TryEnter(_isRuninng))
return;
_isRuninng = true;
try
{
Scheduler.Start();
_isRuninng = false;
}
finally
{
Monitor.Exit(_isRuninng);
}
}
#endregion