From 11c78bb5ebec5dc14d4f1f943e5b032cb4be77c9 Mon Sep 17 00:00:00 2001 From: dev_amdtel Date: Wed, 17 Dec 2014 19:43:58 +0400 Subject: [PATCH] wsp-10284 Enterprise solution report --- .../HostedSolution/ReportController.cs | 58 +++++++++++++++++-- .../SchedulerTasks/HostedSolutionReport.cs | 50 ++++++++++++++-- .../Scheduling/Scheduler.cs | 4 +- .../SchedulerService.cs | 19 ++++-- 4 files changed, 112 insertions(+), 19 deletions(-) diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/HostedSolution/ReportController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/HostedSolution/ReportController.cs index fab50dff..ecf6ebdc 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/HostedSolution/ReportController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/HostedSolution/ReportController.cs @@ -278,11 +278,16 @@ 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) @@ -473,7 +500,8 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution TaskManager.WriteError(ex); } } - + + 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 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 { @@ -596,11 +630,14 @@ namespace WebsitePanel.EnterpriseServer.Code.HostedSolution TaskManager.WriteError(ex); } } - + + 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 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); @@ -631,11 +671,16 @@ 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; } diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/SchedulerTasks/HostedSolutionReport.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/SchedulerTasks/HostedSolutionReport.cs index e0209bc1..e7f82265 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/SchedulerTasks/HostedSolutionReport.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/SchedulerTasks/HostedSolutionReport.cs @@ -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 attacments = new List(); 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); @@ -116,9 +136,29 @@ namespace WebsitePanel.EnterpriseServer string body = user.HtmlMail ? settings["HtmlBody"] : settings["TextBody"]; bool isHtml = user.HtmlMail; - MailPriority priority = MailPriority.Normal; + MailPriority priority = MailPriority.Normal; + + TaskManager.WriteParameter("from", from); + TaskManager.WriteParameter("email", email); + TaskManager.WriteParameter("subject", subject); + TaskManager.WriteParameter("body", body); + - MailHelper.SendMessage(from, email, cc, subject, body, priority, isHtml, attacments.ToArray()); + 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"); + } } diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Scheduling/Scheduler.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Scheduling/Scheduler.cs index 6773f712..d3a65dd4 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Scheduling/Scheduler.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Scheduling/Scheduler.cs @@ -45,7 +45,7 @@ namespace WebsitePanel.EnterpriseServer public static SchedulerJob nextSchedule = null; public static void Start() - { + { ScheduleTasks(); } @@ -73,7 +73,7 @@ namespace WebsitePanel.EnterpriseServer private static void RunManualTasks() { - var tasks = TaskController.GetProcessTasks(BackgroundTaskStatus.Stopping); + var tasks = TaskController.GetProcessTasks(BackgroundTaskStatus.Stopping); foreach (var task in tasks) { diff --git a/WebsitePanel/Sources/WebsitePanel.SchedulerService/SchedulerService.cs b/WebsitePanel/Sources/WebsitePanel.SchedulerService/SchedulerService.cs index 2f017c19..92d0128a 100644 --- a/WebsitePanel/Sources/WebsitePanel.SchedulerService/SchedulerService.cs +++ b/WebsitePanel/Sources/WebsitePanel.SchedulerService/SchedulerService.cs @@ -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; - Scheduler.Start(); - _isRuninng = false; + try + { + Scheduler.Start(); + } + finally + { + Monitor.Exit(_isRuninng); + } + } #endregion