/// <summary>
 /// Register process for command.
 /// </summary>
 /// <typeparam name="TCommand"></typeparam>
 /// <param name="process"></param>
 public void RegisterProcess <TCommand>([NotNull] SingleProcess <TCommand> process) where TCommand : ACommand
 {
     if (process == null)
     {
         throw new ArgumentNullException(nameof(process));
     }
     typeProcesses.Add(typeof(TCommand), (command, input) => process((TCommand)command, input));
 }
Example #2
0
 public void KillProcess(SingleProcess process)
 {
     try
     {
         process.Process.Kill();
         ProcessList.Remove(process);
     }
     catch (Win32Exception e) { Console.WriteLine(e.Message); }
 }
Example #3
0
 public ModuleListViewModel(SingleProcess process)
 {
     ProcessLabel = $"Process: {process.Id} {process.Name}";
     _modulesList = new ObservableCollection <SingleModule>();
     foreach (ProcessModule processModule in process.ModuleList)
     {
         ModuleList.Add(new SingleModule(processModule));
     }
 }
Example #4
0
 public ThreadListViewModel(SingleProcess process)
 {
     ProcessLabel = $"Process: {process.Id} {process.Name}";
     _threadList  = new ObservableCollection <SingleThread>();
     foreach (ProcessThread processThread in process.ThreadList)
     {
         ThreadList.Add(new SingleThread(processThread, process.Accessible));
     }
 }
        public ShowModulesWindow(ref SingleProcess proc)
        {
            InitializeComponent();
            ShowModulesViewModel vm = new ShowModulesViewModel(ref proc);

            DataContext = vm;
            if (vm.CloseAction == null)
            {
                vm.CloseAction = new Action(this.Close);
            }
        }
        public async Task RunAsync_StartsTask()
        {
            // arrange
            var func = A.Fake <Func <CancellationToken, Task> >();
            var sut  = new SingleProcess(func);

            // act
            await sut.RunAsync(CancellationToken.None);

            // assert
            A.CallTo(func).MustHaveHappenedOnceExactly();
        }
        public void RunAsync_TaskThrows_Throws()
        {
            // arrange
            var expectedException = new Exception("I'm failing You, I'm so sorry.");

            Task Func(CancellationToken token) => Task.FromException(expectedException);

            var sut = new SingleProcess(Func);

            // act + assert
            sut.Invoking(async x => await x.RunAsync(CancellationToken.None))
            .Should().Throw <Exception>().Where(ex => ex == expectedException);
        }
Example #8
0
        internal ShowThreadsViewModel(ref SingleProcess process)
        {
            Threads = new ObservableCollection <SingleThread>();
            ObservableCollection <SingleThread> tmp = new ObservableCollection <SingleThread>();

            ProcessName = process.Name;
            int id = process.ID;

            foreach (ProcessThread thread in process.ThreadsCollection)
            {
                tmp.Add(new SingleThread(thread));
            }
            Threads = tmp;
        }
Example #9
0
        internal ShowModulesViewModel(ref SingleProcess process)
        {
            Modules = new ObservableCollection <SingleModule>();
            ObservableCollection <SingleModule> tmp = new ObservableCollection <SingleModule>();

            ProcessName = process.Name;
            int id = process.ID;

            foreach (ProcessModule module in process.Modules)
            {
                tmp.Add(new SingleModule(module));
            }
            Modules = tmp;
        }
Example #10
0
 static void Main(string[] args)
 {
     Console.WriteLine($"[NDaemon.Client ({AppGuid})] started.");
     using (SingleProcess singleProcess = new SingleProcess(AppGuid))
     {
         if (singleProcess.OtherProcessRunning)
         {
             Console.WriteLine($"[NDaemon.Client ({AppGuid})] found other process.");
             return;
         }
         Console.WriteLine($"[NDaemon.Client ({AppGuid})] Single instance of the client started.");
         Console.Write("To exit from program, press <Enter>.");
         Console.ReadLine();
     }
     Console.WriteLine($"[NDaemon.Client ({AppGuid})] finished.");
 }
Example #11
0
 public void OpenFolder(SingleProcess process)
 {
     Process.Start("explorer.exe", $"/select, \"{process.Path}\"");
 }
Example #12
0
        static void Main()
        {
            try
            {
                string[] args = Environment.GetCommandLineArgs().Skip(1).ToArray();

                if (args.Length == 2 && args[0] == "--reg-file-assoc")
                {
                    if (args[1] == "audio")
                    {
                        FileAssociation.Register(App.AudioTypes);
                    }
                    if (args[1] == "video")
                    {
                        FileAssociation.Register(App.VideoTypes);
                    }
                    if (args[1] == "unreg")
                    {
                        FileAssociation.Unregister();
                    }
                    return;
                }

                App.Init();
                Mutex mutex = new Mutex(true, "mpvnetProcessInstance", out bool isFirst);

                if ((App.ProcessInstance == "single" || App.ProcessInstance == "queue") && !isFirst)
                {
                    List <string> files = new List <string>();

                    foreach (string arg in args)
                    {
                        if (!arg.StartsWith("--") && (File.Exists(arg) || arg == "-" || arg.StartsWith("http")))
                        {
                            files.Add(arg);
                        }
                    }

                    if (files.Count > 0)
                    {
                        RegHelp.SetObject(App.RegPath, "ShellFiles", files.ToArray());
                    }

                    RegHelp.SetObject(App.RegPath, "ProcessInstanceMode", App.ProcessInstance);

                    foreach (Process process in Process.GetProcessesByName("mpvnet"))
                    {
                        try {
                            SingleProcess.AllowSetForegroundWindow(process.Id);
                            Native.SendMessage(process.MainWindowHandle, SingleProcess.Message, IntPtr.Zero, IntPtr.Zero);
                        } catch {}
                    }

                    mutex.Dispose();
                    return;
                }

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());
                mutex.Dispose();
            }
            catch (Exception ex)
            {
                Msg.ShowException(ex);
            }
        }
 /// <summary>
 /// Get registered process for type.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="process"></param>
 /// <returns></returns>
 public bool TryGetProcess(Type type, out SingleProcess <ACommand> process)
 {
     return(typeProcesses.TryGetValue(type, out process));
 }
Example #14
0
 internal static void DeleteProcess(ref SingleProcess p)
 {
     _processList.Remove(p);
 }