Beispiel #1
0
        static public void runMonitorExe(object obj)
        {
            int    exitCode = -1;
            string args     = (string)obj;

            if (string.IsNullOrEmpty(args))
            {
                args = "-start-service";
            }

            new Thread(() => { runMonitorService(); }).Start();
            do
            {
                try
                {
                    string exeFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MonitoriDevice.exe");
                    //string args = "-start-service";
                    if (System.IO.File.Exists(exeFilename))
                    {
                        Program.logIt(string.Format("[runEXE]: {0} arg={1}", exeFilename, args));
                        System.Diagnostics.Process p = new System.Diagnostics.Process();
                        p.StartInfo.FileName       = exeFilename;
                        p.StartInfo.Arguments      = args;
                        p.StartInfo.CreateNoWindow = true;
                        p.StartInfo.WindowStyle    = System.Diagnostics.ProcessWindowStyle.Hidden;

                        p.StartInfo.UseShellExecute        = false;
                        p.StartInfo.RedirectStandardOutput = true;
                        p.OutputDataReceived += (sender, e) =>
                        {
                            if (!string.IsNullOrEmpty(e.Data))
                            {
                                Regex regexAdd    = new Regex(@"iDeviceAdd=(.*?)$");
                                Regex regexRemove = new Regex(@"iDeviceRemove=(.*?)$");
                                Match matchAdd    = regexAdd.Match(e.Data);
                                if (matchAdd.Success)
                                {
                                    string udid = matchAdd.Groups[1].Value;
                                    if (!ListDeviceInfo.ContainsKey(udid))
                                    {
                                        Util.ListDeviceInfo.TryAdd(udid, new ConcurrentDictionary <string, string>(StringComparer.OrdinalIgnoreCase));
                                        //ThreadPool.QueueUserWorkItem(new WaitCallback(GetDeviceInfo), udid);
                                        ThreadPool.QueueUserWorkItem(new WaitCallback(Util.GetBatteryMaxCapacity), udid);
                                    }
                                }
                                else
                                {
                                    Match matchRemove = regexRemove.Match(e.Data);
                                    if (matchRemove.Success)
                                    {
                                        string udid = matchRemove.Groups[1].Value;
                                        if (ListDeviceInfo.ContainsKey(udid))
                                        {
                                            ConcurrentDictionary <String, String> ddd;
                                            ListDeviceInfo.TryRemove(udid, out ddd);
                                            Program.logIt("Removed Device");
                                        }
                                    }
                                }
                            }
                        };
                        p.Start();
                        p.BeginOutputReadLine();
                        JobManagement.Job job = new JobManagement.Job();
                        job.AddProcess(p.Handle);
                        p.WaitForExit();

                        exitCode = p.ExitCode;
                        Program.logIt(string.Format("[runEXE]: exit code={0}", exitCode));
                        Thread.Sleep(3000);
                    }
                    else
                    {
                        exitCode = 2;
                    }
                }
                catch (Exception) { }
            } while (!bExit);
        }
        public static uint HandleDataErrorCount = 0; //This variable is used to rate limit the amount of errors that are recorded from the HandleDataError function

        public static void InitJobManagement()
        {
            job = new JobManagement.Job();
        }