Example #1
0
        /// <summary>
        /// Gets a list of intervals and sets the values in memory from the xml file
        /// </summary>
        public static void GetIntervalsFromConfig()
        {
            try
            {
                var _assembly = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
                var path      = string.Format("{0}\\{1}", System.IO.Path.GetDirectoryName(_assembly), "config\\settings.xml");

                var xDoc = XDocument.Load(path);
                var x    = from s in xDoc.Elements("cloudpanel") select s;

                // Active Directory
                ad_GetDisabledUsers = ConvertStringIntervalToInteger(ref x, "ActiveDirectory", "GetDisabledUsers");
                ad_GetLockedUsers   = ConvertStringIntervalToInteger(ref x, "ActiveDirectory", "GetLockedUsers");

                // Exchange
                exch_GetMailboxSizes         = ConvertStringIntervalToInteger(ref x, "Exchange", "GetMailboxSizes");
                exch_GetMailboxDatabaseSizes = ConvertStringIntervalToInteger(ref x, "Exchange", "GetMailboxDatabaseSizes");
                exch_GetMessageTrackingLogs  = ConvertStringIntervalToInteger(ref x, "Exchange", "GetMessageTrackingLogs");

                // Database
                db_FindMissingData       = ConvertStringIntervalToInteger(ref x, "Database", "FindMissingData");
                db_UpdateDatabaseHistory = ConvertStringIntervalToInteger(ref x, "Database", "UpdateDatabaseHistory");
            }
            catch (Exception ex)
            {
                CPService.LogError("Error retrieving intervals from config file: " + ex.ToString());
            }
        }
Example #2
0
        public void Execute(IJobExecutionContext context)
        {
            // Get a list of all locked out users
            List <Users> users = ADActions.GetLockedUsers();

            if (users != null)
            {
                try
                {
                    using (SqlConnection sql = new SqlConnection(Config.ServiceSettings.SqlConnectionString))
                    {
                        sql.Open();

                        using (SqlCommand cmd = new SqlCommand("UPDATE Users SET IsLockedOut=@IsLockedOut WHERE UserPrincipalName=@UserPrincipalName", sql))
                        {
                            users.ForEach(x =>
                            {
                                if (!string.IsNullOrEmpty(x.UserPrincipalName))
                                {
                                    cmd.Parameters.Clear();
                                    cmd.Parameters.AddWithValue("IsLockedOut", x.IsLockedOut ?? false);
                                    cmd.Parameters.AddWithValue("UserPrincipalName", x.UserPrincipalName);

                                    cmd.ExecuteNonQuery();
                                }
                            });
                        }
                    }
                }
                catch (Exception ex)
                {
                    CPService.LogError("Error processing locked users: " + ex.ToString());
                }
            }
        }
Example #3
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());
            }
        }
Example #5
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());
                }
            }
        }
Example #6
0
        /// <summary>
        /// Reads the settings from the Xml file and stores in memory
        /// </summary>
        public static void ReadSettings()
        {
            try
            {
                var xDoc = XDocument.Load(Settings.Default.SettingsPath);
                var x    = from s in xDoc.Elements("cloudpanel") select s;

                // Get salt key first for decryption
                SaltKey   = x.Descendants("Settings").Elements("SaltKey").FirstOrDefault().Value;
                Username  = x.Descendants("Settings").Elements("Username").FirstOrDefault().Value;
                Password  = x.Descendants("Settings").Elements("Password").FirstOrDefault().Value;
                PrimaryDC = x.Descendants("Settings").Elements("PrimaryDC").FirstOrDefault().Value;

                SqlConnectionString = x.Descendants("Settings").Elements("Database").FirstOrDefault().Value;

                ExchangeServer     = x.Descendants("Exchange").Elements("ExchangeServer").FirstOrDefault().Value;
                ExchangeVersion    = int.Parse(x.Descendants("Exchange").Elements("ExchangeVersion").FirstOrDefault().Value);
                ExchangeConnection = x.Descendants("Exchange").Elements("ExchangeConnection").FirstOrDefault().Value;
            }
            catch (Exception ex)
            {
                CPService.LogError("Error reading settings: " + ex.ToString());
            }
        }
Example #7
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());
            }
        }