Ejemplo n.º 1
0
        private void ConnectToService(bool canThrow = true)
        {
            string uri = string.Format("ipc://{0}/{1}", "FlowTomator.Service", nameof(FlowTomatorService));

            try
            {
                Service = (FlowTomatorService)Activator.GetObject(typeof(FlowTomatorService), uri);
                Service.ToString();

                if (!Program.Parameters.ContainsKey("quiet"))
                {
                    Icon.ShowBalloonTip(4000, "FlowTomator", "Connected to FlowTomator service", ToolTipIcon.Info);
                }

                Service.Notification += notificationReceiver.OnNotification;
                notificationReceiver.Notification += Service_Notification;
            }
            catch (Exception e)
            {
                Service = null;

                if (canThrow && Debugger.IsAttached)
                {
                    Debugger.Break();
                }
                else if (!Program.Parameters.ContainsKey("quiet"))
                {
                    Icon.ShowBalloonTip(4000, "FlowTomator", "Could not connect to FlowTomator service. " + e.Message, ToolTipIcon.Error);
                }
            }
        }
Ejemplo n.º 2
0
 private void UninstallServiceButton_Click(object sender, EventArgs e)
 {
     if (FlowTomatorService.Installed)
     {
         FlowTomatorService.Uninstall();
     }
 }
Ejemplo n.º 3
0
        private void ConnectToService(bool canThrow = true)
        {
            string uri = string.Format("ipc://{0}/{1}", "FlowTomator.Service", nameof(FlowTomatorService));

            try
            {
                Service = (FlowTomatorService)Activator.GetObject(typeof(FlowTomatorService), uri);
                Service.ToString();

                if (!Program.Parameters.ContainsKey("quiet"))
                    Icon.ShowBalloonTip(4000, "FlowTomator", "Connected to FlowTomator service", ToolTipIcon.Info);

                Service.Notification += notificationReceiver.OnNotification;
                notificationReceiver.Notification += Service_Notification;
            }
            catch (Exception e)
            {
                Service = null;

                if (canThrow && Debugger.IsAttached)
                    Debugger.Break();
                else if (!Program.Parameters.ContainsKey("quiet"))
                    Icon.ShowBalloonTip(4000, "FlowTomator", "Could not connect to FlowTomator service. " + e.Message, ToolTipIcon.Error);
            }
        }
Ejemplo n.º 4
0
 private void InstallServiceButton_Click(object sender, EventArgs e)
 {
     if (!FlowTomatorService.Installed)
     {
         FlowTomatorService.Install();
         StartServiceButton_Click(sender, e);
     }
 }
Ejemplo n.º 5
0
        private void StopService()
        {
            if (!FlowTomatorService.Installed)
            {
                if (!Program.Parameters.ContainsKey("quiet"))
                {
                    Icon.ShowBalloonTip(5000, "FlowTomator", "FlowTomator service is not installed on this computer", ToolTipIcon.Error);
                }

                return;
            }

            FlowTomatorService.Stop();

            startServiceButton.Enabled = true;
            stopServiceButton.Enabled  = false;
        }
Ejemplo n.º 6
0
 private void StopServiceButton_Click(object sender, EventArgs e)
 {
     Task.Run(() => StopService())
     .ContinueWith(t => Service = null);
 }
Ejemplo n.º 7
0
        private void Menu_Popup(object sender, EventArgs e)
        {
            try
            {
                if (Service != null)
                {
                    Service.ToString();
                }
            }
            catch (Exception ex)
            {
                Service = null;
            }

            if (Service == null && FlowTomatorService.Running)
            {
                ConnectToService(false);
            }

            Menu.MenuItems.Clear();

            if (Service != null)
            {
                FlowEnvironment[] flows = Service.Flows.ToArray();
                if (flows.Length > 0)
                {
                    foreach (FlowEnvironment flow in flows)
                    {
                        string path = flow.File.FullName;
                        string file = flow.File.Name;

                        Menu.MenuItems.Add(new MenuItem(file, new[]
                        {
                            new MenuItem("Start", (a, b) => StartFlowButton_Click(flow, b))
                            {
                                Enabled = !flow.Running
                            },
                            new MenuItem("Stop", (a, b) => StopFlowButton_Click(flow, b))
                            {
                                Enabled = flow.Running
                            },
                            new MenuItem("Reload", (a, b) => ReloadFlowButton_Click(flow, b)),
                            new MenuItem("-"),
                            new MenuItem("Edit", (a, b) => EditFlowButton_Click(flow, b)),
                            new MenuItem("Remove", (a, b) => RemoveFlowButton_Click(flow, b)),
                        }));
                    }

                    Menu.MenuItems.Add("-");
                }

                Menu.MenuItems.AddRange(new[]
                {
                    new MenuItem("Load flow ...", LoadFlowButton_Click),
                    new MenuItem("-")
                });
            }

            if (!FlowTomatorService.Installed)
            {
                Menu.MenuItems.AddRange(new[]
                {
                    new MenuItem("Install service", InstallServiceButton_Click)
                });
            }
            else
            {
                Menu.MenuItems.AddRange(new[]
                {
                    new MenuItem("Service", new[]
                    {
                        new MenuItem("Start", StartServiceButton_Click)
                        {
                            Enabled = !FlowTomatorService.Running
                        },
                        new MenuItem("Stop", StopServiceButton_Click)
                        {
                            Enabled = FlowTomatorService.Running
                        },
                        new MenuItem("-"),
                        new MenuItem("Uninstall", UninstallServiceButton_Click)
                        {
                            Enabled = !FlowTomatorService.Running
                        },
                        new MenuItem("-"),
                        new MenuItem("Settings", new[]
                        {
                            new MenuItem("Open log", OpenLogButton_Click)
                        }),
                    })
                });
            }

            Menu.MenuItems.AddRange(new[]
            {
                new MenuItem("Exit", ExitButton_Click)
            });
        }
Ejemplo n.º 8
0
        public static void Main(string[] args)
        {
            if (!Environment.UserInteractive || Environment.OSVersion.Platform == PlatformID.Unix)
            {
                ServiceBase.Run(new FlowTomatorService());
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Parameters = Environment.GetCommandLineArgs()
                         .Where(p => p.StartsWith("/"))
                         .Select(p => p.TrimStart('/'))
                         .Select(p => new { Parameter = p.Trim(), Separator = p.Trim().IndexOf(':') })
                         .ToDictionary(p => p.Separator == -1 ? p.Parameter.ToLower() : p.Parameter.Substring(0, p.Separator).ToLower(), p => p.Separator == -1 ? null : p.Parameter.Substring(p.Separator + 1));

            // Quick flag to stop the service
            if (Parameters.ContainsKey("stop"))
            {
                ServiceController service = ServiceController.GetServices().SingleOrDefault(s => s.ServiceName == Program.ServiceName);
                if (service == null)
                {
                    return;
                }

                if (service.Status != ServiceControllerStatus.Stopped && service.Status != ServiceControllerStatus.StopPending)
                {
                    service.Stop();
                }

                return;
            }

            // Install service if needed
            if (Parameters.ContainsKey("reinstall"))
            {
                if (FlowTomatorService.Installed)
                {
                    try
                    {
                        FlowTomatorService.Uninstall();
                    }
                    catch (Exception e)
                    {
                        if (Debugger.IsAttached)
                        {
                            throw;
                        }
                        else
                        {
                            MessageBox.Show("Could not uninstall FlowTomator service. " + e.Message);
                        }
                    }

                    Thread.Sleep(1000);
                }

                try
                {
                    FlowTomatorService.Install();
                }
                catch (Exception e)
                {
                    if (Debugger.IsAttached)
                    {
                        throw;
                    }
                    else
                    {
                        MessageBox.Show("Could not install FlowTomator service. " + e.Message);
                    }
                }
            }
            else if (Parameters.ContainsKey("install"))
            {
                if (!FlowTomatorService.Installed)
                {
                    try
                    {
                        FlowTomatorService.Install();
                    }
                    catch (Exception e)
                    {
                        if (Debugger.IsAttached)
                        {
                            throw;
                        }
                        else
                        {
                            MessageBox.Show("Could not install FlowTomator service. " + e.Message);
                        }
                    }
                }
            }

            // Start FlowTomator service UI
            Application.Run(new FlowTomatorApplication());
        }
Ejemplo n.º 9
0
 private void StopServiceButton_Click(object sender, EventArgs e)
 {
     Task.Run(() => StopService())
         .ContinueWith(t => Service = null);
 }
Ejemplo n.º 10
0
        private void Menu_Popup(object sender, EventArgs e)
        {
            try
            {
                if (Service != null)
                    Service.ToString();
            }
            catch (Exception ex)
            {
                Service = null;
            }

            if (Service == null && FlowTomatorService.Running)
                ConnectToService(false);

            Menu.MenuItems.Clear();

            if (Service != null)
            {
                FlowEnvironment[] flows = Service.Flows.ToArray();
                if (flows.Length > 0)
                {
                    foreach (FlowEnvironment flow in flows)
                    {
                        string path = flow.File.FullName;
                        string file = flow.File.Name;

                        Menu.MenuItems.Add(new MenuItem(file, new[]
                        {
                            new MenuItem("Start", (a, b) => StartFlowButton_Click(flow, b))  { Enabled = !flow.Running },
                            new MenuItem("Stop", (a, b) => StopFlowButton_Click(flow, b)) { Enabled = flow.Running },
                            new MenuItem("Reload", (a, b) => ReloadFlowButton_Click(flow, b)),
                            new MenuItem("-"),
                            new MenuItem("Edit", (a, b) => EditFlowButton_Click(flow, b)),
                            new MenuItem("Remove", (a, b) => RemoveFlowButton_Click(flow, b)),
                        }));
                    }

                    Menu.MenuItems.Add("-");
                }

                Menu.MenuItems.AddRange(new[]
                {
                    new MenuItem("Load flow ...", LoadFlowButton_Click),
                    new MenuItem("-")
                });
            }

            if (!FlowTomatorService.Installed)
            {
                Menu.MenuItems.AddRange(new[]
                {
                    new MenuItem("Install service", InstallServiceButton_Click)
                });
            }
            else
            {
                Menu.MenuItems.AddRange(new[]
                {
                    new MenuItem("Service", new[]
                    {
                        new MenuItem("Start", StartServiceButton_Click) { Enabled = !FlowTomatorService.Running },
                        new MenuItem("Stop", StopServiceButton_Click) { Enabled = FlowTomatorService.Running },
                        new MenuItem("-"),
                        new MenuItem("Uninstall", UninstallServiceButton_Click) { Enabled = !FlowTomatorService.Running },
                        new MenuItem("-"),
                        new MenuItem("Settings", new[]
                        {
                            new MenuItem("Open log", OpenLogButton_Click)
                        }),
                    })
                });
            }

            Menu.MenuItems.AddRange(new[]
            {
                new MenuItem("Exit", ExitButton_Click)
            });
        }