コード例 #1
0
        public string Analyze(out bool allDisconnected, out string[] screenFiles)
        {
            string message = string.Empty;

            screenFiles = null;

            // Get Progress "main.exe"
            Process[] proArr = Process.GetProcessesByName(ProcessName);
            if (proArr == null || proArr.Length == 0)
            {
                message         = "奇迹进程找不到了.";
                allDisconnected = true;
            }
            else
            {
                allDisconnected = true;
                var pids = from process in proArr select process.Id;

                using (NetworkPerformanceReporter perfReporter = new NetworkPerformanceReporter(pids.ToArray()))
                {
                    Console.WriteLine("Capturing network and analyze.");
                    perfReporter.Initialize();
                    Thread.Sleep(TraceDurationInMins * 1000 * 60); // Wait for tracing
                    perfReporter.Stop();
                    var perfDatas = perfReporter.GetNetworkPerformanceData();

                    int index = 1;

                    foreach (var perf in perfDatas)
                    {
                        bool online = false;
                        message += "MU_" + perf.Key + ":";
                        message += GetStatus(perf.Value, out online);
                        if (online)
                        {
                            allDisconnected = false;
                        }
                        Console.WriteLine("{2}, Send:{0} B/sec, Recv:{1} B/sec", perf.Value.BytesSent, perf.Value.BytesReceived, perf.Key);
                        index++;
                    }
                }

                if (TakeScreenshot)
                {
                    List <string> files = new List <string>();
                    foreach (var muProcess in proArr)
                    {
                        string muScreenFile = string.Format(
                            CultureInfo.InvariantCulture,
                            "{0}\\MU_{1}.jpg",
                            Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                            muProcess.Id);
                        MuHelper.CaptureProcess(muProcess, muScreenFile);
                        files.Add(muScreenFile);
                    }
                    screenFiles = files.ToArray();
                }
            }
            return(message);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: TianSanxia/MuAssist
        static void Main(string[] args)
        {
            email    = ConfigurationManager.AppSettings["EmailAddress"];
            emailPwd = ConfigurationManager.AppSettings["EmailPassword"];
            var emailParts = email.Split('@');

            if (emailParts.Length != 2)
            {
                Console.WriteLine("Invalid email address!");
                return;
            }

            if (MuHelper.GetSMTPServerFromType(emailParts[1]) == null)
            {
                Console.WriteLine("The email type is not supported!");
                return;
            }

            captureIntervalInMins = int.Parse(ConfigurationManager.AppSettings["CheckIntervalInMins"]);

            if (captureIntervalInMins < 1)
            {
                captureIntervalInMins = 1;
            }

            ShutdownOnDisconnected = bool.Parse(ConfigurationManager.AppSettings["ShutdownOnDisconnected"]);

            //That's it! Save the image in the directory and this will work like charm.
            try
            {
                fileFullName = string.Format(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
                                             @"\" + MuHelper.ScreenshotFile);
            }
            catch (Exception er)
            {
                Console.WriteLine("Sorry, there was an error: " + er.Message);
            }


            // timer, exception, emails, analisis
            SetTimer();

            while (true)
            {
                Console.Write("Input 'X' to exit:");
                string input = Console.ReadLine();
                if (input.Equals("x", StringComparison.InvariantCultureIgnoreCase))
                {
                    return;
                }
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: TianSanxia/MuAssist
        private static void OnTimedEvent(Object source, ElapsedEventArgs e)
        {
            Console.WriteLine("Triggered on {0}", DateTime.Now.ToString("u"));
            try
            {
                bool             allDisconnected = false;
                string[]         screenFiles;
                MuNetworkMonitor networkMonitor = new MuNetworkMonitor(true);
                string           status         = networkMonitor.Analyze(out allDisconnected, out screenFiles);
                string           error          = string.Empty;

                if (ShutdownOnDisconnected & allDisconnected)
                {
                    status += " 即将关机!";
                }
                Console.WriteLine(status);


                //bool bScreen = MuHelper.TakeScreenshot(fileFullName, out error);

                string sendError;
                if (!MuHelper.SendEmail(
                        email,
                        emailPwd,
                        status,
                        status,
                        screenFiles,
                        out sendError))
                {
                    Console.WriteLine(sendError);
                }
                else
                if (ShutdownOnDisconnected & allDisconnected)
                {
                    Console.WriteLine("Shutdown this computer...");
                    MuHelper.ShutdownComputer();
                }
            }
            catch (Exception ex)
            {
                MuHelper.ReportError(email, emailPwd, ex.Message + "\n" + ex.StackTrace);
            }
        }