Esempio n. 1
0
        private void optimizeDatabase(object state) {
            TrackerDatabaseSizeItem trackerDatabaseSizeItem = (TrackerDatabaseSizeItem)state;
            try {
                Query query = new Query(database);
                TrackerDatabaseSize trackerDatabaseSize = query.getDatabaseSize(trackerDatabaseSizeItem.Name);
                trackerDatabaseSizeItem.TrackerDatabaseSize = trackerDatabaseSize;
                trackerDatabaseSizeItem.Status = MaintenanceServerStatus.DONE;
                trackerDatabaseSizeItem.DateTimeUpdated = DateTime.Now;


            } catch (Exception exception) {
                MaintenanceServerLog maintenanceServerLog = new MaintenanceServerLog();
                maintenanceServerLog.Status = MaintenanceServerStatus.ERROR;
                maintenanceServerLog.Description = exception.Message;
                log(maintenanceServerLog);


                trackerDatabaseSizeItem.DateTimeUpdated = DateTime.Now;
                trackerDatabaseSizeItem.Status = MaintenanceServerStatus.ERROR;
            } finally {
                threadProperties.CurrentThreadCount++;
                if (threadProperties.CurrentThreadCount == threadProperties.MaxThreadCount) {
                    MaintenanceServerLog maintenanceServerLog = new MaintenanceServerLog();
                    maintenanceServerLog.Status = MaintenanceServerStatus.DONE;
                    maintenanceServerLog.Description = "Optimizing " + threadProperties.CurrentThreadCount + " databases are done.";
                    log(maintenanceServerLog);
                }
                Dispatcher.Invoke(new Action(() => {
                    dataGrid.Items.Refresh();
                }));
            }
        }
Esempio n. 2
0
        private void log(MaintenanceServerLog maintenanceServerLog) {
            lock (maintenanceServerLog) {
                maintenanceServerLog.Sequence = ++logCounter;
                maintenanceServerLog.DateTime = DateTime.Now;

                Dispatcher.Invoke(new Action(() => {
                    listViewStatus.Items.Add(maintenanceServerLog);
                    listViewStatus.ScrollIntoView(maintenanceServerLog);
                }));
            }
        }
Esempio n. 3
0
        private void run(object state) {
            try {


                while (serverStatus == ServerStatus.RUN) {

                    TimeSpan timeSpan = DateTime.Now.Subtract(dateTimeLastTime);
                    if (timeSpan.Minutes > 3) {
                        MaintenanceServerLog maintenanceServerLogStart = new MaintenanceServerLog();
                        maintenanceServerLogStart.Description = "Starting Maintenance Server.";
                        maintenanceServerLogStart.Status = MaintenanceServerStatus.SUCCESS;
                        log(maintenanceServerLogStart);

                        dateTimeLastTime = DateTime.Now;

                        if (dataGrid == null) {
                            continue;
                        }

                        MaintenanceServerLog maintenanceServerLog = new MaintenanceServerLog();
                        maintenanceServerLog.Status = MaintenanceServerStatus.RUNNING;
                        maintenanceServerLog.Description = "Starting to optimize " + dataGrid.Items.Count.ToString() + " databases.";
                        log(maintenanceServerLog);

                        threadProperties.MaxThreadCount = dataGrid.Items.Count;
                        foreach (TrackerDatabaseSizeItem trackerDatabaseSizeItem in dataGrid.Items) {

                            ThreadPool.QueueUserWorkItem(new WaitCallback(optimizeDatabase), trackerDatabaseSizeItem);

                        }

                       
                    }

                }

                MaintenanceServerLog maintenanceServerStop = new MaintenanceServerLog();
                maintenanceServerStop.Description = "Stopping Maintenance Server.";
                maintenanceServerStop.Status = MaintenanceServerStatus.SUCCESS;
                log(maintenanceServerStop);
            } catch (Exception exception) {
                MaintenanceServerLog maintenanceServerLog = new MaintenanceServerLog();
                maintenanceServerLog.Status = MaintenanceServerStatus.ERROR;
                maintenanceServerLog.Description = exception.Message;
                log(maintenanceServerLog);
            }
        }