コード例 #1
0
        //用配置信息去同步自启动
        private static void SyncAutoStartState()
        {
            var fact = AutoStarter.IsRegistered(Constants.Identifier, Application.ExecutablePath);
            var conf = config.Get <bool>(ConfigKeys.AutoStart);

            if (fact == conf && !isFirstRun)
            {
                return;
            }

            try
            {
                //可能被杀毒软件阻止
                if (conf)
                {
                    AutoStarter.Register(Constants.Identifier, Application.ExecutablePath);
                }
                else
                {
                    AutoStarter.Unregister(Constants.Identifier);
                }
            }
            catch (Exception)
            {
#if DEBUG
                throw;
#endif
            }
        }
コード例 #2
0
 public void SetUp()
 {
     token    = new CancellationTokenSource();
     instance = CreateInstance();
     instance.RegisterCommand <BlockingCommand, ConfigOne>("One");
     instance.RegisterCommand <SampleCommandTwo, ConfigTwo>("Two");
 }
コード例 #3
0
        public static async Task Main(string[] args)
        {
            NLog.LogManager.LoadConfiguration("nlog.config");
            var starter = new AutoStarter(ApplicationLogging.LoggerFactory, "IB Utility", args);

            starter.LoggerFactory.AddNLog();
            starter.RegisterCommand <HistoricCommand, HistoricConfig>("history");
            starter.RegisterCommand <RealtimeCommand, RealtimeConfig>("realtime");
            starter.RegisterCommand <NewsCommand, NewsConfig>("news");
            await new SyncExecutor(starter).Execute().ConfigureAwait(false);
            NLog.LogManager.Shutdown();
        }
コード例 #4
0
ファイル: Settings.cs プロジェクト: lkd70/ReLAUNCH
 private void chkStartWithWindows_CheckedChanged(object sender, EventArgs e)
 {
     if (AutoStarter.IsAutoStartEnabled != chkStartWithWindows.Checked)
     {
         if (AutoStarter.IsAutoStartEnabled)
         {
             AutoStarter.UnSetAutoStart();
         }
         else
         {
             AutoStarter.SetAutoStart();
         }
     }
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: AndMu/Wikiled.FreeAgent
        static async Task Main(string[] args)
        {
            NLog.LogManager.LoadConfiguration("nlog.config");
            starter = new AutoStarter(ApplicationLogging.LoggerFactory, "FreeAgent App", args);
            starter.LoggerFactory.AddNLog();
            starter.RegisterCommand <DownloadCommand, DownloadConfig>("download");
            source = new CancellationTokenSource();
            task   = starter.StartAsync(source.Token);
            System.Console.WriteLine("Please press CTRL+C to break...");
            System.Console.CancelKeyPress += ConsoleOnCancelKeyPress;
            await starter.Status.LastOrDefaultAsync();

            System.Console.WriteLine("Exiting...");
        }
コード例 #6
0
        static async Task Main(string[] args)
        {
            NLog.LogManager.LoadConfiguration("nlog.config");
            starter = new AutoStarter(ApplicationLogging.LoggerFactory, "Instagram Bot", args);
            starter.LoggerFactory.AddNLog();
            starter.RegisterCommand <DiscoveryCommand, BasicConfig>("discovery");
            starter.RegisterCommand <EnrichCommand, EnrichConfig>("enrich");
            starter.RegisterCommand <RemoveFollowersCommand, RemoveFollowConfig>("remove");
            source = new CancellationTokenSource();
            task   = starter.StartAsync(source.Token);
            System.Console.WriteLine("Please press CTRL+C to break...");
            System.Console.CancelKeyPress += ConsoleOnCancelKeyPress;
            await starter.Status.LastOrDefaultAsync();

            System.Console.WriteLine("Exiting...");
        }
コード例 #7
0
        public static async Task Main(string[] args)
        {
            NLog.LogManager.LoadConfiguration("nlog.config");
            starter = new AutoStarter(ApplicationLogging.LoggerFactory, "Sentiment analysis", args);
            starter.LoggerFactory.AddNLog();
            starter.RegisterCommand <TestingCommand, TestingConfig>("test");
            starter.RegisterCommand <TrainCommand, TrainingConfig>("train");
            starter.RegisterCommand <BoostrapCommand, BootsrapConfig>("boot");

            var configuration = new ConfigurationHandler();
            var resourcesPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), configuration.GetConfiguration("Resources"));

            if (Directory.Exists(resourcesPath))
            {
                log.LogInformation("Resources folder {0} found.", resourcesPath);
            }
            else
            {
                var  dataDownloader = new DataDownloader(ApplicationLogging.LoggerFactory);
                Task download       = dataDownloader.DownloadFile(new Uri(configuration.GetConfiguration("dataset")), resourcesPath);
                await download.ConfigureAwait(false);
            }


#if NET472
            var fPreviousExecutionState = NativeMethods.SetThreadExecutionState(NativeMethods.ES_CONTINUOUS | NativeMethods.ES_SYSTEM_REQUIRED);
            if (fPreviousExecutionState == 0)
            {
                log.LogError("SetThreadExecutionState failed.");
                return;
            }
#endif
            try
            {
                source = new CancellationTokenSource();
                task   = starter.StartAsync(source.Token);
                System.Console.WriteLine("Please press CTRL+C to break...");
                System.Console.CancelKeyPress += ConsoleOnCancelKeyPress;
                await starter.Status.LastOrDefaultAsync();

                System.Console.WriteLine("Exiting...");
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
            }
        }
コード例 #8
0
        public static async Task Main(string[] args)
        {
            NLog.LogManager.LoadConfiguration("NLog.config");
            var starter = new AutoStarter(ApplicationLogging.LoggerFactory, "Market Utility", args);

            starter.LoggerFactory.AddNLog();
            starter.RegisterCommand <TwitterBotCommand, TwitterBotConfig>("bot");
            starter.RegisterCommand <GeneratePredictionCommand, GeneratePredictionConfig>("generate");

            var hostBuilder = new HostBuilder()
                              .ConfigureServices((hostContext, services) =>
            {
                services.AddSingleton <IHostedService>(serviceProvider => starter);
            });

            await hostBuilder.RunConsoleAsync();
        }
コード例 #9
0
        public static async Task Main(string[] args)
        {
            NLog.LogManager.LoadConfiguration("nlog.config");
            ApplicationLogging.LoggerFactory = LoggerFactory.Create(builder =>
            {
                builder.SetMinimumLevel(LogLevel.Trace);
                builder.AddNLog();
            });

            var starter = new AutoStarter(ApplicationLogging.LoggerFactory, "IB Utility", args);

            starter.RegisterCommand <OptionHistoryCommand, OptionsHistoricConfig>("options");
            starter.RegisterCommand <HistoricCommand, HistoricConfig>("history");
            starter.RegisterCommand <RealtimeCommand, RealtimeConfig>("realtime");
            starter.RegisterCommand <NewsCommand, NewsConfig>("news");
            await new SyncExecutor(starter).Execute().ConfigureAwait(false);
            NLog.LogManager.Shutdown();
        }
コード例 #10
0
        public static async Task Main(string[] args)
        {
            NLog.LogManager.LoadConfiguration("nlog.config");
            starter = new AutoStarter(ApplicationLogging.LoggerFactory, "Twitter Bot", args);
            starter.LoggerFactory.AddNLog();
            starter.RegisterCommand <DiscoveryCommand, DiscoveryConfig>("Discovery");
            starter.RegisterCommand <EnrichCommand, EnrichConfig>("Enrich");
            starter.RegisterCommand <DownloadMessagesCommand, DownloadMessagesConfig>("DownloadMessages");
            starter.RegisterCommand <TwitterLoadCommand, TwitterLoadConfig>("load");
            starter.RegisterCommand <TwitterMonitorCommand, TwitterMonitorConfig>("monitor");
            starter.RegisterCommand <TestPublishCommand, TestPublishConfig>("publish");

            source = new CancellationTokenSource();
            task   = starter.StartAsync(source.Token);
            System.Console.WriteLine("Please press CTRL+C to break...");
            System.Console.CancelKeyPress += ConsoleOnCancelKeyPress;
            await starter.Status.LastOrDefaultAsync();

            System.Console.WriteLine("Exiting...");
        }
コード例 #11
0
ファイル: Options_Mdi.cs プロジェクト: webesen/Muhasebe
        private void Save_Button_Click(object sender, EventArgs e)
        {
            if (this.Startup_Check.Checked)
            {
                if (AutoStarter.IsAutoStartEnabled)
                {
                    AutoStarter.UnSetAutoStart();
                }

                AutoStarter.SetAutoStart();
            }
            else
            {
                AutoStarter.UnSetAutoStart();
            }

            if (this.ShowStats_Check.Checked)
            {
                GuiManipulator.CanShowStatistics = true;
            }
            else
            {
                GuiManipulator.CanShowStatistics = false;
            }

            Properties.Settings.Default.AlertForLowAmountItems = this.AlertForAmount_Check.Checked;
            Properties.Settings.Default.LowAmountTheresold     = Convert.ToInt32(this.LowAmountTheresold_Num.Value);
            Properties.Settings.Default.LowAmountAlertColor    = this.LowAmountColor_Preview_Label.BackColor;

            Properties.Settings.Default.AlertForUnpricedItems = this.AlertForUnpriced_Check.Checked;
            Properties.Settings.Default.UnpricedAlertColor    = this.Unpriced_Color_Preview_Label.BackColor;

            Properties.Settings.Default.PlaySoundOnScanned = this.Sound_Check.Checked;
            Properties.Settings.Default.SoundFileLocation  = (this.Sound_Combo.SelectedItem as SoundEntity).FilePath;

            Properties.Settings.Default.Save();

            this.Close();
        }
コード例 #12
0
        public static async Task Main(string[] args)
        {
            NLog.LogManager.LoadConfiguration("nlog.config");
            ApplicationLogging.LoggerFactory = LoggerFactory.Create(builder =>
            {
                builder.SetMinimumLevel(LogLevel.Trace);
                builder.AddNLog();
            });

            starter = new AutoStarter(ApplicationLogging.LoggerFactory, "Sentiment analysis", args);
            starter.RegisterCommand <TestingCommand, TestingConfig>("test");
            starter.RegisterCommand <TrainCommand, TrainingConfig>("train");
            starter.RegisterCommand <BoostrapCommand, BootsrapConfig>("boot");

            starter.Init = async provider =>
            {
                var downloader = provider.GetRequiredService <ConfigDownloader <ILexiconConfig> >();
                await downloader.Download(item => item.Model).ConfigureAwait(false);

                await downloader.Download(item => item.Lexicons, always : true).ConfigureAwait(false);
            };

            try
            {
                source = new CancellationTokenSource();
                task   = starter.StartAsync(source.Token);
                System.Console.WriteLine("Please press CTRL+C to break...");
                System.Console.CancelKeyPress += ConsoleOnCancelKeyPress;
                await starter.Status.LastOrDefaultAsync();

                System.Console.WriteLine("Exiting...");
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
            }
        }
コード例 #13
0
        private void MenuItemAutoStartClick(object sender, EventArgs e)
        {
            string keyName          = AssemblyUtils.AssemblyProductName;
            string assemblyLocation = AssemblyUtils.AssemblyLocation;
            bool   autoStartEnabled = AutoStarter.IsAutoStartByRegisterEnabled(keyName, assemblyLocation);

            if (autoStartEnabled)
            {
                AutoStarter.UnsetAutoStartByRegister(keyName);
                if (Environment.OSVersion.Version.Major >= 6)
                {
                    AutoStarter.UnsetAutoStartByScheduler(keyName);
                }
            }
            else
            {
                AutoStarter.SetAutoStartByRegister(keyName, assemblyLocation);
                if (Environment.OSVersion.Version.Major >= 6)
                {
                    AutoStarter.SetAutoStartByScheduler(keyName, assemblyLocation);
                }
            }
            ((ToolStripMenuItem)sender).Checked = !autoStartEnabled;
        }
コード例 #14
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var settingsFileName = Path.Combine(AssemblyUtils.AssemblyDirectory, "SmartSystemMenu.xml");

            if (File.Exists(settingsFileName))
            {
                _settings = SmartSystemMenuSettings.Read(settingsFileName);
            }
#if WIN32
            if (Environment.Is64BitOperatingSystem)
            {
                string resourceName  = "SmartSystemMenu.SmartSystemMenu64.exe";
                string fileName      = "SmartSystemMenu64.exe";
                string directoryName = Path.GetDirectoryName(AssemblyUtils.AssemblyLocation);
                string filePath      = Path.Combine(directoryName, fileName);
                try
                {
                    if (!File.Exists(filePath))
                    {
                        AssemblyUtils.ExtractFileFromAssembly(resourceName, filePath);
                    }
                    _64BitProcess = Process.Start(filePath);
                }
                catch
                {
                    string message = string.Format("Failed to load {0} process!", fileName);
                    MessageBox.Show(message, AssemblyUtils.AssemblyTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Close();
                    return;
                }
            }
            _systemTrayMenu = new SystemTrayMenu();
            _systemTrayMenu.MenuItemAutoStart.Click  += MenuItemAutoStartClick;
            _systemTrayMenu.MenuItemSettings.Click   += MenuItemSettingsClick;
            _systemTrayMenu.MenuItemAbout.Click      += MenuItemAboutClick;
            _systemTrayMenu.MenuItemExit.Click       += MenuItemExitClick;
            _systemTrayMenu.MenuItemAutoStart.Checked = AutoStarter.IsAutoStartByRegisterEnabled(AssemblyUtils.AssemblyProductName, AssemblyUtils.AssemblyLocation);
#endif
            _windows = EnumWindows.EnumAllWindows(_settings.MenuItems, new string[] { SHELL_WINDOW_NAME }).ToList();

            foreach (var window in _windows)
            {
                var processName = "";

                try
                {
                    processName = Path.GetFileName(window.Process.GetMainModuleFileName());
                }
                catch
                {
                }

                if (string.IsNullOrEmpty(processName) || _settings.ProcessExclusions.Contains(processName.ToLower()))
                {
                    continue;
                }

                window.Menu.Create();
                int menuItemId = window.ProcessPriority.GetMenuItemId();
                window.Menu.CheckMenuItem(menuItemId, true);
                window.Menu.SetMenuItemText(SystemMenu.SC_ALIGN_MONITOR, "Select Monitor: " + Screen.AllScreens.ToList().FindIndex(s => s.Primary));
                if (window.AlwaysOnTop)
                {
                    window.Menu.CheckMenuItem(SystemMenu.SC_TOPMOST, true);
                }
            }

            _getMsgHook         = new GetMsgHook(Handle, SystemMenu.SC_DRAG_BY_MOUSE);
            _getMsgHook.GetMsg += WindowGetMsg;
            _getMsgHook.Start();

            _shellHook = new ShellHook(Handle, SystemMenu.SC_DRAG_BY_MOUSE);
            _shellHook.WindowCreated   += WindowCreated;
            _shellHook.WindowDestroyed += WindowDestroyed;
            _shellHook.Start();

            _cbtHook = new CBTHook(Handle, SystemMenu.SC_DRAG_BY_MOUSE);
            _cbtHook.WindowCreated   += WindowCreated;
            _cbtHook.WindowDestroyed += WindowDestroyed;
            _cbtHook.MoveSize        += WindowMoveSize;
            _cbtHook.MinMax          += WindowMinMax;
            _cbtHook.Start();

            _mouseHook = new MouseHook(Handle, SystemMenu.SC_DRAG_BY_MOUSE);
            _mouseHook.Start();

            Hide();
        }
コード例 #15
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

#if WIN32
            if (Environment.Is64BitOperatingSystem)
            {
                var resourceName  = "SmartSystemMenu.SmartSystemMenu64.exe";
                var fileName      = "SmartSystemMenu64.exe";
                var directoryName = Path.GetDirectoryName(AssemblyUtils.AssemblyLocation);
                var filePath      = Path.Combine(directoryName, fileName);
                try
                {
                    if (!File.Exists(filePath))
                    {
                        AssemblyUtils.ExtractFileFromAssembly(resourceName, filePath);
                    }
                    _64BitProcess = Process.Start(filePath);
                }
                catch
                {
                    string message = string.Format("Failed to load {0} process!", fileName);
                    MessageBox.Show(message, AssemblyUtils.AssemblyTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Close();
                    return;
                }
            }

            if (_settings.ShowSystemTrayIcon)
            {
                _systemTrayMenu = new SystemTrayMenu(_settings.Language);
                _systemTrayMenu.MenuItemAutoStartClick += MenuItemAutoStartClick;
                _systemTrayMenu.MenuItemSettingsClick  += MenuItemSettingsClick;
                _systemTrayMenu.MenuItemAboutClick     += MenuItemAboutClick;
                _systemTrayMenu.MenuItemExitClick      += MenuItemExitClick;
                _systemTrayMenu.Create();
                _systemTrayMenu.CheckMenuItemAutoStart(AutoStarter.IsAutoStartByRegisterEnabled(AssemblyUtils.AssemblyProductName, AssemblyUtils.AssemblyLocation));
            }

            var moduleName = Process.GetCurrentProcess().MainModule.ModuleName;

            _hotKeyHook         = new HotKeyHook();
            _hotKeyHook.Hooked += HotKeyHooked;
            if (_settings.MenuItems.Items.Flatten(x => x.Items).Any(x => x.Type == MenuItemType.Item && x.Key3 != VirtualKey.None && x.Show) || _settings.MenuItems.WindowSizeItems.Any(x => x.Key3 != VirtualKey.None))
            {
                _hotKeyHook.Start(moduleName, _settings.MenuItems);
            }

            _hotKeyMouseHook         = new HotKeys.MouseHook();
            _hotKeyMouseHook.Hooked += HotKeyMouseHooked;
            if (_settings.Closer.MouseButton != MouseButton.None)
            {
                _hotKeyMouseHook.Start(moduleName, _settings.Closer.Key1, _settings.Closer.Key2, _settings.Closer.MouseButton);
            }
#endif
            _windows = EnumWindows.EnumAllWindows(_settings, _windowSettings, new string[] { SHELL_WINDOW_NAME }).ToList();

            foreach (var window in _windows)
            {
                var processPath = window.Process?.GetMainModuleFileName() ?? string.Empty;
                var fileName    = Path.GetFileName(processPath);
                if (!string.IsNullOrEmpty(fileName) && _settings.ProcessExclusions.Contains(fileName.ToLower()))
                {
                    continue;
                }

                var isAdded = window.Menu.Create();
                if (isAdded)
                {
                    window.Menu.CheckMenuItem(window.ProcessPriority.GetMenuItemId(), true);
                    if (window.AlwaysOnTop)
                    {
                        window.Menu.CheckMenuItem(MenuItemId.SC_TOPMOST, true);
                    }

                    if (window.IsExToolWindow)
                    {
                        window.Menu.CheckMenuItem(MenuItemId.SC_HIDE_FOR_ALT_TAB, true);
                    }

                    var windowClassName = window.GetClassName();
                    var states          = _windowSettings.Find(windowClassName, processPath);
                    if (states.Any())
                    {
                        window.ApplyState(states[0], _settings.SaveSelectedItems, _settings.MenuItems.WindowSizeItems);
                        window.Menu.CheckMenuItem(MenuItemId.SC_SAVE_SELECTED_ITEMS, true);
                    }
                }
            }

            _callWndProcHook              = new CallWndProcHook(Handle, MenuItemId.SC_DRAG_BY_MOUSE);
            _callWndProcHook.CallWndProc += WindowProc;
            _callWndProcHook.Start();

            _getMsgHook         = new GetMsgHook(Handle, MenuItemId.SC_DRAG_BY_MOUSE);
            _getMsgHook.GetMsg += WindowGetMsg;
            _getMsgHook.Start();

            _shellHook = new ShellHook(Handle, MenuItemId.SC_DRAG_BY_MOUSE);
            _shellHook.WindowCreated   += WindowCreated;
            _shellHook.WindowDestroyed += WindowDestroyed;
            _shellHook.Start();

            _cbtHook = new CBTHook(Handle, MenuItemId.SC_DRAG_BY_MOUSE);
            _cbtHook.WindowCreated   += WindowCreated;
            _cbtHook.WindowDestroyed += WindowDestroyed;
            _cbtHook.MoveSize        += WindowMoveSize;
            _cbtHook.MinMax          += WindowMinMax;
            _cbtHook.Start();


            _mouseHook = new Hooks.MouseHook(Handle, MenuItemId.SC_DRAG_BY_MOUSE);
            var dragByMouseItemName = MenuItemId.GetName(MenuItemId.SC_DRAG_BY_MOUSE);
            if (_settings.MenuItems.Items.Flatten(x => x.Items).Any(x => x.Type == MenuItemType.Item && x.Name == dragByMouseItemName && x.Show))
            {
                _mouseHook.Start();
            }

            Hide();
        }