Esempio n. 1
0
 public void Execute(IJobExecutionContext context)
 {
     try
     {
         using (CloudPanelDbContext db = new CloudPanelDbContext(Config.ServiceSettings.SqlConnectionString))
         {
             using (ExchActions powershell = new ExchActions())
             {
                 List <StatMailboxDatabaseSizes> mailboxDatabases = powershell.Get_MailboxDatabaseSizes();
                 db.StatMailboxDatabaseSizes.InsertAllOnSubmit(mailboxDatabases);
                 db.SubmitChanges();
             }
         }
     }
     catch (Exception ex)
     {
         CPService.LogError("Failed to retrieve mailbox database sizes: " + ex.ToString());
     }
 }
        public void Execute(IJobExecutionContext context)
        {
            try
            {
                using (CloudPanelDbContext db = new CloudPanelDbContext(Config.ServiceSettings.SqlConnectionString))
                {
                    // Get a list of ALL companies
                    IEnumerable <Companies> companies = db.Companies.Where(x => x.IsReseller != true);

                    // Set our date and time when we started this task
                    DateTime now = DateTime.Now;

                    // Go through all companies getting the latest values
                    foreach (Companies company in companies)
                    {
                        IEnumerable <Users> users   = db.Users.Where(x => x.CompanyCode == company.CompanyCode);
                        IEnumerable <int>   userIds = users.Select(x => x.ID);

                        int citrixUsers = db.CitrixUserToDesktopGroup.Where(x => userIds.Contains(x.UserRefDesktopGroupId))
                                          .Select(x => x.UserRefDesktopGroupId)
                                          .Distinct()
                                          .Count();

                        Statistics newStatistic = new Statistics();
                        newStatistic.UserCount    = users.Count();
                        newStatistic.MailboxCount = users.Where(a => a.MailboxPlan > 0).Count();
                        newStatistic.CitrixCount  = citrixUsers;
                        newStatistic.ResellerCode = company.ResellerCode;
                        newStatistic.CompanyCode  = company.CompanyCode;
                        newStatistic.Retrieved    = now;

                        db.Statistics.InsertOnSubmit(newStatistic);
                    }

                    // Save changes to the database
                    db.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                CPService.LogError("Error getting history statistics: " + ex.ToString());
            }
        }
Esempio n. 3
0
        public void Execute(IJobExecutionContext context)
        {
            if (Config.ServiceSettings.ExchangeVersion > 2010)
            {
                try
                {
                    using (CloudPanelDbContext db = new CloudPanelDbContext(Config.ServiceSettings.SqlConnectionString))
                    {
                        // Find users with missing Exchange Guid that are Exchange enabled
                        IEnumerable <Users> users = db.Users.Where(x => x.MailboxPlan > 0).Where(x => x.ExchangeGuid == Guid.Empty);

                        if (users != null)
                        {
                            using (ExchActions exchTasks = new ExchActions())
                            {
                                foreach (Users user in users)
                                {
                                    try
                                    {
                                        Guid exchangeGuid = exchTasks.Get_ExchangeGuid(user.UserPrincipalName);
                                        user.ExchangeGuid = exchangeGuid;
                                    }
                                    catch (Exception ex)
                                    {
                                        CPService.LogError("Error retrieving Exchange GUID for " + user.UserPrincipalName + ": " + ex.ToString());
                                    }
                                }

                                db.SubmitChanges();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    CPService.LogError("Error finding missing ExchangeGuid values: " + ex.ToString());
                }
            }
        }
Esempio n. 4
0
        public void Execute(IJobExecutionContext context)
        {
            int processedCount = 0, failedCount = 0;

            try
            {
                using (ExchActions powershell = new ExchActions())
                {
                    // Our timestamps to look for
                    DateTime startTime = DateTime.Now.AddHours(-24);
                    DateTime endTime   = DateTime.Now;

                    // Get the sent and received logs for the past 24 hours from Exchange
                    List <MessageTrackingLog> sentLogs     = powershell.Get_TotalSentMessages(startTime, endTime);
                    List <MessageTrackingLog> receivedLogs = powershell.Get_TotalReceivedMessages(startTime, endTime);

                    // Initialize our database
                    using (CloudPanelDbContext db = new CloudPanelDbContext(Config.ServiceSettings.SqlConnectionString))
                    {
                        // Find a list of ALL mailbox users
                        IQueryable <Users> allMailboxes = db.Users.Where(x => x.MailboxPlan > 0);

                        // Look through each mailbox adding the message tracking information
                        foreach (Users user in allMailboxes)
                        {
                            try
                            {
                                IEnumerable <MessageTrackingLog> totalSentLogs     = sentLogs.Where(a => a.Users.Contains(user.Email, StringComparer.OrdinalIgnoreCase));
                                IEnumerable <MessageTrackingLog> totalReceivedLogs = receivedLogs.Where(a => a.Users.Contains(user.Email, StringComparer.OrdinalIgnoreCase));

                                int totalSentLogsCount     = totalSentLogs.Count();
                                int totalReceivedLogsCount = totalReceivedLogs.Count();

                                StatMessageTrackingCounts newCount = new StatMessageTrackingCounts();
                                newCount.UserID             = user.ID;
                                newCount.Start              = startTime;
                                newCount.End                = endTime;
                                newCount.TotalSent          = totalSentLogsCount;
                                newCount.TotalReceived      = totalReceivedLogsCount;
                                newCount.TotalBytesSent     = totalSentLogsCount > 0 ? totalSentLogs.Select(a => a.TotalBytes).Sum() : 0;
                                newCount.TotalBytesReceived = totalReceivedLogsCount > 0 ? totalReceivedLogs.Select(a => a.TotalBytes).Sum() : 0;

                                db.StatMessageTrackingCounts.InsertOnSubmit(newCount);
                                processedCount++;
                            }
                            catch (Exception ex)
                            {
                                CPService.LogError("Error getting total messages for " + user.Email + ": " + ex.ToString());
                                failedCount++;
                            }
                        }

                        // Save to database
                        db.SubmitChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                CPService.LogError("Failed to retrieve message logs: {0}: " + ex.ToString());
            }
        }
        public void Execute(IJobExecutionContext context)
        {
            try
            {
                using (CloudPanelDbContext db = new CloudPanelDbContext(Config.ServiceSettings.SqlConnectionString))
                {
                    // Get a list of all users with mailboxes
                    IEnumerable <Users> mailboxes = db.Users.Where(x => x.MailboxPlan > 0);
                    IEnumerable <Users> archives  = mailboxes.Where(x => x.ArchivePlan > 0);
                    if (mailboxes != null)
                    {
                        using (ExchActions powershell = new ExchActions())
                        {
                            // Process mailbox sizes
                            foreach (Users user in mailboxes)
                            {
                                try
                                {
                                    StatMailboxSizes size = powershell.Get_MailboxSize(user.UserGuid, false);
                                    size.UserGuid          = user.UserGuid;
                                    size.UserPrincipalName = user.UserPrincipalName;

                                    db.StatMailboxSizes.InsertOnSubmit(size);
                                }
                                catch (Exception ex)
                                {
                                    CPService.LogError("Error getting mailbox size for " + user.UserPrincipalName + ": " + ex.ToString());
                                }
                            }

                            // Process archive sizes
                            foreach (Users user in archives)
                            {
                                try
                                {
                                    StatMailboxSizes size = powershell.Get_MailboxSize(user.UserGuid, true);
                                    size.UserGuid          = user.UserGuid;
                                    size.UserPrincipalName = user.UserPrincipalName;

                                    db.StatMailboxArchiveSizes.InsertOnSubmit(new StatMailboxArchiveSizes()
                                    {
                                        UserGuid                    = size.UserGuid,
                                        UserPrincipalName           = size.UserPrincipalName,
                                        MailboxDatabase             = size.MailboxDatabase,
                                        TotalItemSize               = size.TotalItemSize,
                                        TotalItemSizeInBytes        = size.TotalItemSizeInBytes,
                                        TotalDeletedItemSize        = size.TotalDeletedItemSize,
                                        TotalDeletedItemSizeInBytes = size.TotalDeletedItemSizeInBytes,
                                        ItemCount                   = size.ItemCount,
                                        DeletedItemCount            = size.DeletedItemCount,
                                        Retrieved                   = size.Retrieved
                                    });
                                }
                                catch (Exception ex)
                                {
                                    CPService.LogError("Error getting archive mailbox size for " + user.UserPrincipalName + ": " + ex.ToString());
                                }
                            }

                            // Save the database changes now
                            db.SubmitChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CPService.LogError("Failed to retrieve mailbox and archive sizes: " + ex.ToString());
            }
        }