Esempio n. 1
0
        static void Main(string[] args)
        {
            Application.SetCompatibleTextRenderingDefault(false);
            using (ChannelFactory <ISpoti15WCF> spotFactory = new ChannelFactory <ISpoti15WCF>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/Spoti15WCF")))
            {
                try
                {
                    ISpoti15WCF iface = spotFactory.CreateChannel();
                    iface.Shutdown();
                    spotFactory.Close();

                    System.Threading.Thread.Sleep(1000);
                }
                catch
                {
                    spotFactory.Abort();
                    spotFactory.Close();
                }
            }

            host = new ServiceHost(typeof(Spoti15WcfImpl), new Uri[] { new Uri("net.pipe://localhost") });
            host.AddServiceEndpoint(typeof(ISpoti15WCF), new NetNamedPipeBinding(), "Spoti15WCF");
            host.Open();

            if (args.Length == 0 || args[0] != "-autostart")
            {
                Properties.Settings.Default.HideIcon = false;
                Properties.Settings.Default.Save();
            }

            ContextMenu cm = new ContextMenu();
            MenuItem    menu;

            menu        = new MenuItem();
            menu.Text   = "&Hide tray icon";
            menu.Click += HideClick;
            cm.MenuItems.Add(menu);

            menu         = new MenuItem();
            menu.Checked = Autostart.IsEnabled();
            menu.Text    = "&Autostart";
            menu.Click  += AutostartClick;
            cm.MenuItems.Add(menu);
            autostartItem = menu;

            cm.MenuItems.Add("-");

            menu        = new MenuItem();
            menu.Text   = "E&xit";
            menu.Click += ExitClick;
            cm.MenuItems.Add(menu);

            notico             = new NotifyIcon();
            notico.Text        = "Spoti15";
            notico.Icon        = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
            notico.ContextMenu = cm;
            notico.Visible     = !Properties.Settings.Default.HideIcon;

            Spoti15 spoti15 = new Spoti15();

            Application.Run();

            GC.KeepAlive(spoti15);
            host.Close();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            using (ChannelFactory<ISpoti15WCF> spotFactory = new ChannelFactory<ISpoti15WCF>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/Spoti15WCF")))
            {
                try
                {
                    ISpoti15WCF iface = spotFactory.CreateChannel();
                    iface.Shutdown();
                    spotFactory.Close();

                    System.Threading.Thread.Sleep(1000);
                }
                catch
                {
                    spotFactory.Abort();
                    spotFactory.Close();
                }
            }

            host = new ServiceHost(typeof(Spoti15WcfImpl), new Uri[] { new Uri("net.pipe://localhost") });
            host.AddServiceEndpoint(typeof(ISpoti15WCF), new NetNamedPipeBinding(), "Spoti15WCF");
            host.Open();

            if (args.Length == 0 || args[0] != "-autostart")
            {
                Properties.Settings.Default.HideIcon = false;
                Properties.Settings.Default.Save();
            }

            ContextMenu cm = new ContextMenu();
            MenuItem menu;

            menu = new MenuItem();
            menu.Text = "&Hide tray icon";
            menu.Click += HideClick;
            cm.MenuItems.Add(menu);

            menu = new MenuItem();
            menu.Checked = Autostart.IsEnabled();
            menu.Text = "&Autostart";
            menu.Click += AutostartClick;
            cm.MenuItems.Add(menu);
            autostartItem = menu;

            cm.MenuItems.Add("-");

            menu = new MenuItem();
            menu.Text = "E&xit";
            menu.Click += ExitClick;
            cm.MenuItems.Add(menu);

            notico = new NotifyIcon();
            notico.Text = "Spoti15";
            notico.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
            notico.ContextMenu = cm;
            notico.Visible = !Properties.Settings.Default.HideIcon;

            Spoti15 spoti15 = new Spoti15();

            Application.Run();

            GC.KeepAlive(spoti15);
            host.Close();
        }