示例#1
0
        /// <summary>
        /// Sends the GhostCast Server window state in an e-mail to the supplied address.
        /// </summary>
        /// <param name="emailAddress">The address to send the session details.</param>
        /// <param name="session">The GhostCast Server session details object.</param>
        public static void SendAlertEmail(string emailAddress, GhostCastSession session)
        {
            string subject = String.Format("GhostBuster: {0} {1}", session.SessionName, "Possible Error");
            if (session.Status == "Transfer Complete")
            {
                subject = String.Format("GhostBuster: {0} {1}", session.SessionName, session.Status);
            }

            Attachment attachment = null;
            try
            {
                string logFile = Path.Combine(AgentSettings.SessionLogPath, session.SessionName + AgentSettings.ConsoleLogFileSuffix);
                if (File.Exists(logFile))
                {
                    attachment = new Attachment(logFile);
                }
            }
            catch (Exception)
            {
                Log.Write("Error: Unable to add the log file as an attachment for the e-mail alert.");
            }

            SendAlertEmail(emailAddress, subject, session.ToString(), attachment);
        }
        /// <summary>
        /// Scrapes the passed GhostCast session getting control values.
        /// </summary>
        /// <param name="ghostCastWindow">The GhostCast Session to retrieve values from.</param>
        /// <returns>A populated GhostCastSession object.</returns>
        private GhostCastSession ScrapeGhostCastSession(AutomationElement ghostCastWindow)
        {
            GhostCastSession gcs = new GhostCastSession();

            // Check for the GhostCast Server dialog message 'Transfer Complete'.
            bool dialogBox = false;
            string dialogMessage = String.Empty;
            AutomationElement dialogMessageAe = ghostCastWindow.FindFirst(TreeScope.Descendants,
                new PropertyCondition(AutomationElement.AutomationIdProperty, ControlId.DialogMessage));
            if (dialogMessageAe != null)
            {
                dialogBox = true;
                dialogMessage = dialogMessageAe.Current.Name;
            }

            AutomationElementCollection controls = ghostCastWindow.FindAll(TreeScope.Descendants,
            new NotCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text)));

            gcs.Title = ghostCastWindow.Current.Name;
            gcs.ProcessId = ghostCastWindow.Current.ProcessId;
            //Parallel.ForEach(AEHelper.GetAllGhostCastServerWindows(), control =>
            foreach (AutomationElement control in controls)
            {
                switch (control.Current.AutomationId)
                {
                    case ControlId.AutoStartClientCountEdit:
                        {
                            gcs.AutoStartClientCount = AEHelper.GetEditContent(control);
                            break;
                        }
                    case ControlId.AutoStartTimeEdit:
                        {
                            gcs.AutoStartTime = AEHelper.GetEditContent(control);
                            break;
                        }
                    case ControlId.AutoStartTimeoutEdit:
                        {
                            gcs.AutoStartTimeout = AEHelper.GetEditContent(control);
                            break;
                        }
                    case ControlId.CommandLineEdit:
                        {
                            gcs.CommandLine = AEHelper.GetEditContent(control);
                            break;
                        }
                    case ControlId.ConnectedClientsDataGrid:
                        {
                            DataTable dt = AEHelper.GetDataGridContent(control);
                            List<ConnectedClient> clients = new List<ConnectedClient>();
                            foreach (DataRow dr in dt.Rows)
                            {
                                ConnectedClient cc = new ConnectedClient();
                                cc.IP = (string)dr[0];
                                cc.MAC = (string)dr[1];
                                cc.Mode = (string)dr[2];
                                cc.Status = (string)dr[3];
                                clients.Add(cc);
                            }
                            gcs.ConnectedClientList = clients;
                            break;
                        }
                    case ControlId.ConnectedClientsEdit:
                        {
                            gcs.ConnectedClients = AEHelper.GetEditContent(control);
                            break;
                        }
                    case ControlId.CreateImageRadioButton:
                        {
                            if (AEHelper.GetRadioButtonCheckState(control))
                            {
                                gcs.SessionType = "Create Image";
                            }
                            else
                            {
                                gcs.SessionType = "Restore Image";
                            }
                            break;
                        }
                    case ControlId.DiskNoSpinner:
                        {
                            gcs.DiskNumber = AEHelper.GetSpinnerContent(control);
                            break;
                        }
                    case ControlId.FailedClientsEdit:
                        {
                            gcs.FailedClients = AEHelper.GetEditContent(control);
                            break;
                        }
                    case ControlId.ImageFileEdit:
                        {
                            gcs.GhostImageFile = AEHelper.GetEditContent(control);
                            break;
                        }
                    case ControlId.MBRemainingEdit:
                        {
                            gcs.MBRemaining = AEHelper.GetEditContent(control);
                            break;
                        }
                    case ControlId.MBTransmittedEdit:
                        {
                            gcs.MBTransmitted = AEHelper.GetEditContent(control);
                            break;
                        }
                    case ControlId.PartitionDetailsComboBox:
                        {
                            gcs.PartitionDetails = AEHelper.GetComboBoxContent(control);
                            break;
                        }
                    case ControlId.PartitionNoSpinner:
                        {
                            gcs.PartitionNumber = AEHelper.GetSpinnerContent(control);
                            break;
                        }
                    case ControlId.PercentCompleteEdit:
                        {
                            gcs.PercentComplete = AEHelper.GetEditContent(control);
                            break;
                        }
                    case ControlId.SessionNameEdit:
                        {
                            gcs.SessionName = AEHelper.GetEditContent(control);
                            break;
                        }
                    case ControlId.SessionStatus:
                        {
                            if (dialogBox)
                            {
                                gcs.Status = dialogMessage;
                            }
                            else
                            {
                                gcs.Status = control.Current.Name;
                            }
                            break;
                        }
                    case ControlId.SpeedMBminEdit:
                        {
                            gcs.Speed = AEHelper.GetEditContent(control);
                            break;
                        }
                    case ControlId.TimeElapsedEdit:
                        {
                            gcs.TimeElapsed = AEHelper.GetEditContent(control);
                            break;
                        }
                    case ControlId.TimeRemainingEdit:
                        {
                            gcs.TimeRemaining = AEHelper.GetEditContent(control);
                            break;
                        }
                } // switch
            } // foreach control

            return gcs;
        }