Inheritance: IDisposable
Ejemplo n.º 1
0
 public void Dispose()
 {
     if (watcher != null)
     {
         watcher.Dispose();
         watcher = null;
     }
 }
Ejemplo n.º 2
0
            private void _Attach(Process p)
            {
                if (this.Process != null)
                {
                    if (watcher != null)
                    {
                        watcher.Dispose();
                        watcher = null;
                    }
                    else
                    {
                        this.Process.Exited -= p_Exited;
                    }
                }

                bool hasExited = false;
                bool hasStarted = false;

                try
                {
                    hasExited = p.HasExited;
                    hasStarted = true;
                }
                catch { }

                this.Process = p;

                if (!hasExited)
                {
                    bool supportsEvents = false;

                    if (!p.EnableRaisingEvents)
                    {
                        //try setting the value as the current user, then the user running the process
                        //the current user will be able to set another user's process if this process is still the owner (ownership is lost when this process is closed)
                        try
                        {
                            p.EnableRaisingEvents = true;
                            supportsEvents = true;
                        }
                        catch
                        {
                            if (!Util.Users.IsCurrentUser(account.Settings.WindowsAccount))
                            {
                                string username = Util.Users.GetUserName(account.Settings.WindowsAccount);

                                try
                                {
                                    using (Security.Impersonation.Impersonate(username, Security.Credentials.GetPassword(username)))
                                    {
                                        p.EnableRaisingEvents = true;
                                        supportsEvents = true;
                                    }
                                }
                                catch { }
                            }
                        }
                    }
                    else
                        supportsEvents = true;

                    if (supportsEvents)
                    {
                        p.Exited += p_Exited;
                    }
                    else
                    {
                        watcher = new ProcessWatcher(p);
                        watcher.Exited += p_Exited;
                    }

                    if (hasStarted && p.HasExited)
                    {
                        this.HasMutex = false;
                    }
                    else
                    {
                        this.HasMutex = true;
                    }
                }
                else
                {
                    this.HasMutex = false;

                    p_Exited(p, null);
                }

                if (hasStarted)
                {
                    lock (activeProcesses)
                    {
                        if (!p.HasExited)
                        {
                            activeProcesses.Add(p.Id, this);
                        }
                    }
                }
            }
Ejemplo n.º 3
0
        protected override void OnExecute()
        {
            var            dte = Package.GetDTE();
            SolutionBuild2 sb  = (SolutionBuild2)dte.Solution.SolutionBuild;

            // get the name of the active project
            string startupProjectUniqueName = (string)((Array)sb.StartupProjects).GetValue(0);

            var results = new List <Project>();

            foreach (EnvDTE.Project project in dte.Solution.Projects)
            {
                GetAllProjectsFromProject(project, results);
            }

            results.ToDebugPrint();

            // find the start up project
            var startupProject = results.Where(x => !string.IsNullOrEmpty(x.Name) && string.Equals(x.UniqueName, startupProjectUniqueName));

            if (!startupProject.Any())
            {
                // no startup project found
                return;
            }

            // try to figure out the build outputs of the project
            var outputGroups = startupProject.First().ConfigurationManager.ActiveConfiguration.OutputGroups.OfType <EnvDTE.OutputGroup>();
            var builtGroup   = outputGroups.First(x => x.CanonicalName == "Built");

            var fileUrls    = ((object[])builtGroup.FileURLs).OfType <string>();
            var executables = fileUrls.Where(x => x.EndsWith(".exe", StringComparison.OrdinalIgnoreCase));

            if (!executables.Any())
            {
                return;
            }

            string activeProjectExePath = new Uri(executables.First(), UriKind.Absolute).LocalPath;
            string activeExePath        = Path.GetFileName(activeProjectExePath);

            CleanupProcWatcher();

            _procWatcher = new ProcessWatcher(activeExePath);
            _procWatcher.ProcessCreated += ProcWatcher_ProcessCreated;
            _procWatcher.ProcessDeleted += ProcWatcher_ProcessDeleted;
            _procWatcher.Start();

            dte.ExecuteCommand("Debug.StartWithoutDebugging");

            // this will get all the build output paths for the active project
            var outputFolders = new List <string>();

            foreach (var strUri in fileUrls)
            {
                var uri        = new Uri(strUri, UriKind.Absolute);
                var filePath   = uri.LocalPath;
                var folderPath = Path.GetDirectoryName(filePath);
                outputFolders.Add(folderPath.ToLower());
            }
        }
Ejemplo n.º 4
0
 public MainWindow()
 {
     _watcher = new ProcessWatcher(this);
     InitializeComponent();
     LanguageManager.Setup(toolStripLanguages);
 }
            private void _Attach(Process p)
            {
                if (this.Process != null)
                {
                    try
                    {
                        int pid = this.Process.Id;
                        lock (activeProcesses)
                        {
                            activeProcesses.Remove(pid);
                        }
                    }
                    catch (Exception e)
                    {
                        Util.Logging.Log(e);
                    }

                    if (watcher != null)
                    {
                        watcher.Dispose();
                        watcher = null;
                    }
                    else
                    {
                        this.Process.Exited -= p_Exited;
                    }
                }

                bool hasExited  = false;
                bool hasStarted = false;

                try
                {
                    hasStarted = p.Id > 0;
                    hasExited  = p.HasExited;
                }
                catch (Exception ex)
                {
                    Util.Logging.Log(ex);
                }

                this.Process = p;

                if (!hasExited)
                {
                    bool supportsEvents = false;

                    if (!p.EnableRaisingEvents)
                    {
                        //try setting the value as the current user, then the user running the process
                        //the current user will be able to set another user's process if this process is still the owner (ownership is lost when this process is closed)
                        try
                        {
                            p.EnableRaisingEvents = true;
                            supportsEvents        = true;
                        }
                        catch (Exception e)
                        {
                            Util.Logging.Log(e);

                            if (!Util.Users.IsCurrentUser(account.Settings.WindowsAccount))
                            {
                                string username = Util.Users.GetUserName(account.Settings.WindowsAccount);

                                try
                                {
                                    using (Security.Impersonation.Impersonate(username, Security.Credentials.GetPassword(username)))
                                    {
                                        p.EnableRaisingEvents = true;
                                        supportsEvents        = true;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Util.Logging.Log(ex);
                                }
                            }
                        }
                    }
                    else
                    {
                        supportsEvents = true;
                    }

                    if (supportsEvents)
                    {
                        p.Exited += p_Exited;
                    }
                    else
                    {
                        watcher         = new ProcessWatcher(p);
                        watcher.Exited += p_Exited;
                    }

                    if (hasStarted && p.HasExited)
                    {
                        this.HasMutex = false;
                    }
                    else
                    {
                        this.HasMutex = true;
                    }
                }
                else
                {
                    this.HasMutex = false;

                    p_Exited(p, null);
                }

                if (hasStarted)
                {
                    lock (activeProcesses)
                    {
                        if (!p.HasExited)
                        {
                            activeProcesses.Add(p.Id, this);

                            if (ProcessActive != null)
                            {
                                ProcessActive(p, this.account);
                            }
                        }
                    }
                }
            }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultOpenVRManager"/> class.
 /// </summary>
 public DefaultOpenVRManager()
 {
     _runtimeWatcher = ProcessWatcherFactory.GetInstance().CreateProcessWatcher(Runtime.VRMonitorFileName);
 }
        public void Run()
        {
            ProcessWatcher procWatcher = new ProcessWatcher();

            procWatcher.Start();
        }
Ejemplo n.º 8
0
 public static extern int EnumWindows(EnumWindowsDelegate CallBack, 
   ProcessWatcher processWatcher);
Ejemplo n.º 9
0
 /// <summary>
 /// Factory method for creating a new instance of ProcessWatcherCheckResult.
 /// </summary>
 /// <param name="watcher">Instance of ProcessWatcher.</param>
 /// <param name="isValid">Flag determining whether the performed check was valid.</param>
 /// <param name="processInfo">Details of the process.</param>
 /// <param name="description">Custom description of the performed check.</param>
 /// <returns>Instance of ProcessWatcherCheckResult.</returns>
 public static ProcessWatcherCheckResult Create(ProcessWatcher watcher, bool isValid,
                                                ProcessInfo processInfo, string description = "")
 => new ProcessWatcherCheckResult(watcher, isValid, description, processInfo);
Ejemplo n.º 10
0
 protected ProcessWatcherCheckResult(ProcessWatcher watcher, bool isValid, string description,
                                     ProcessInfo processInfo)
     : base(watcher, isValid, description)
 {
     ProcessInfo = processInfo;
 }
Ejemplo n.º 11
0
 public MainWindow()
 {
     _watcher = new ProcessWatcher(this);
     InitializeComponent();
 }
Ejemplo n.º 12
0
        public void Autoexecutescripts()
        {
            try
            {
                //if (username != null)
                //{
                string[] filelist = Directory.GetFiles(Program.ScriptsFolder);
                scarabler.GetExeCutingApplicationVersion(Assembly.LoadFile(Application.ExecutablePath));


                if (filelist != null)
                {
                    // ScrablerCore.cp.ReferencedAssemblies.Add(Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("\\")) + "\\AxInterop.MOZILLACONTROLLib.dll");
                    // ScrablerCore.cp.ReferencedAssemblies.Add(Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("\\")) + "\\Interop.MOZILLACONTROLLib.dll");
                    //  ScrablerCore.cp.ReferencedAssemblies.Add(Application.ExecutablePath);
                    ScrablerCore.cp.ReferencedAssemblies.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace(@"file:\", "") + "\\Scrabler.dll");
                    //ScrablerCore.definedConstants = definedConstants;
                    //   ScrablerCore.definedValues = definedValues;
                    //Interop.MOZILLACONTROLLib.dll

                    foreach (string file in filelist)
                    {
                        //if ((file != null) && (file.EndsWith("scrf") == true))
                        //{

                        //    int i;
                        //    // ProcessHost prohost = new ProcessHost();
                        //    scarabler.ReadScript(file);


                        //}
                        //if ((file != null) && (file.EndsWith("cs") == true))
                        //{

                        //    int i;
                        //    scarabler.ReadScriptInLightMode(file);


                        //}
                        //if ((file != null) && (file.EndsWith(Scrabler.ScrablerV2.scriptext) == true))
                        //{
                        //    scr2.ReadScript2(file);
                        //}
                        //  MessageBox.Show(file);

                        //char[] pass = password.ToCharArray();
                        //fixed (char* pchar= pass)
                        //{

                        //Core core = new Core();



                        //core.Executescript(file);

                        ProcessStartInfo inf = new ProcessStartInfo();
                        inf.CreateNoWindow = true;
                        inf.Arguments      = "-af" + " \"" + file + "\"";



                        inf.FileName = Path.Combine(Application.StartupPath, "ScriptRunner.exe");
                        Process pr = new Process();
                        pr.StartInfo = inf;

                        // pr.Start();
                        this.aproc.Add(pr);
                        ProcessWatcher prwtch = new ProcessWatcher(pr);
                        prwtch.MaxAllowedBytes = maxmemoryperapp;
                        prwtch.Start();
                        this.procwatcher.Add(prwtch);

                        //  }
                    }
                    //autoastart.scrf
                }



                //}
            }
            catch (Exception ex)
            {
                Program.errorreporting(ex);
            }
        }
Ejemplo n.º 13
0
        static string ExecCmd(string m, Dictionary <string, string> a)
        {
            try
            {
                //ProcessWatcher.OnStop();
                switch (m)
                {
                case "startall":
                    ProcessWatcher.OnStop();

                    efwplusHttpManager.StartHttp();
                    MongodbManager.StartDB();
                    NginxManager.StartWeb();

                    efwplusBaseManager.StartBase();
                    efwplusRouteManager.StartRoute();
                    efwplusWebAPIManager.StartAPI();

                    ProcessWatcher.OnStart();
                    break;

                case "quitall":
                    ProcessWatcher.OnStop();

                    efwplusHttpManager.StopHttp();
                    efwplusBaseManager.StopBase();
                    efwplusRouteManager.StopRoute();
                    efwplusWebAPIManager.StopAPI();
                    MongodbManager.StopDB();
                    NginxManager.StopWeb();
                    break;

                case "exit":
                    ProcessWatcher.OnStop();

                    efwplusHttpManager.StopHttp();
                    efwplusBaseManager.StopBase();
                    efwplusRouteManager.StopRoute();
                    efwplusWebAPIManager.StopAPI();
                    MongodbManager.StopDB();
                    NginxManager.StopWeb();
                    Process.GetCurrentProcess().Kill();
                    break;

                case "restart":
                    ProcessWatcher.OnStop();

                    efwplusBaseManager.StopBase();
                    efwplusRouteManager.StopRoute();
                    efwplusWebAPIManager.StopAPI();
                    MongodbManager.StopDB();
                    NginxManager.StopWeb();

                    Application.Restart();
                    Process.GetCurrentProcess().Kill();
                    //MongodbManager.StartDB();
                    //NginxManager.StartWeb();

                    //efwplusBaseManager.StartBase();
                    //efwplusRouteManager.StartRoute();
                    //efwplusWebAPIManager.StartAPI();

                    break;

                case "restartbase":
                    efwplusBaseManager.StopBase();
                    efwplusBaseManager.StartBase();
                    break;

                case "restartroute":
                    efwplusRouteManager.StopRoute();
                    efwplusRouteManager.StartRoute();
                    break;

                case "restartwebapi":
                    efwplusWebAPIManager.StopAPI();
                    efwplusWebAPIManager.StartAPI();
                    break;

                case "restartmongodb":
                    MongodbManager.StopDB();
                    MongodbManager.StartDB();
                    break;

                case "restartnginx":
                    NginxManager.StopWeb();
                    NginxManager.StartWeb();
                    break;

                case "upgradeplugin":                                                               //升级插件
                    if (EFWCoreLib.CoreFrame.Init.HostSettingConfig.GetValue("autoupdater") == "1") //是否启动自动升级程序
                    {
                        showmsg("准备升级插件...");
                        ExecCmd("quitall", null);
                        try
                        {
                            efwplusHosting.UpgradeProgram.SetUpPluginUpgrade();
                        }
                        catch (Exception err)
                        {
                            showmsg("升级插件失败!" + err.Message + err.StackTrace);
                            showmsg("程序服务未启动.");
                            //Process.GetCurrentProcess().Kill();
                            //host.RunState = HostState.NoOpen;
                        }

                        showmsg("升级插件完成,正在启动服务...");
                        ExecCmd("startall", null);
                    }
                    else
                    {
                        showmsg("自动升级插件没有开启!");
                    }
                    break;
                }
                //ProcessWatcher.OnStart();
                return("succeed");
            }
            catch (Exception e)
            {
                showmsg(e.Message + e.StackTrace);
                return(e.Message);
            }
        }