public static void Run() { try { if (ProgramRoutines.IsParameterSet(CommandLineParameters.WINDOWLESS)) { Cliver.Bot.Program.Run(); return; } LogMessage.Output2Console = false; Cliver.Bot.Program.Initialize(); if (Bot.Properties.App.Default.SingleProcessOnly) { ProcessRoutines.RunSingleProcessOnly(); } Application.Run(MainForm.This); } catch (Exception e) { LogMessage.Exit(e); } }
protected override void Loaded() { if (string.IsNullOrWhiteSpace(InputFolder)) { InputFolder = ProgramRoutines.GetAppDirectory(); } }
public static void Run() { try { LogMessage.DisableStumblingDialogs = ProgramRoutines.IsParameterSet(CommandLineParameters.AUTOMATIC); Log.MODE = Log.Mode.ONLY_LOG; LogMessage.Output2Console = true; ProcessRoutines.RunSingleProcessOnly(); LogMessage.Inform(MessageMark.STARTED + " \r\nCommand line: " + string.Join("|", Environment.GetCommandLineArgs()) + " \r\nRunning as:" + System.Security.Principal.WindowsIdentity.GetCurrent().Name); Assembly service_assembly = Assembly.GetEntryAssembly(); List <Type> service_types = (from t in service_assembly.GetExportedTypes() where t.IsSubclassOf(typeof(Service)) select t).ToList(); if (service_types.Count < 1) { LogMessage.Exit("Could not find Service implementation in the entry assembly: " + service_assembly.FullName); } if (service_types.Count > 1) { LogMessage.Exit("Found more than one Service implementations in the entry assembly: " + service_assembly.FullName); } Service service = (Service)Activator.CreateInstance(service_types[0]); service.Do(); service.complete(); } catch (Exception e) { LogMessage.Exit(e); } }
public static void RunMeInSingleProcessOnly(Action <string> exitingMessage) { string appName = ProgramRoutines.GetAppName(); bool createdNew; MutexSecurity mutexSecurity = new MutexSecurity(); mutexSecurity.AddAccessRule(new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.Synchronize | MutexRights.Modify, AccessControlType.Allow)); for (int i = 0; i < 2; i++) { try { GLOBAL_SINGLE_PROCESS_MUTEX = new Mutex(false, @"Global\CLIVERSOFT_" + appName + @"_SINGLE_PROCESS", out createdNew, mutexSecurity); break; } catch (Exception e) {//An “access denied” while creating a new Mutex can happen in the following situation: //a.Process A running as an administrator creates a named mutex. //b.Process B running as a normal user attempts to access the mutex which fails with “access denied” since only Administrators can access the mutex. if (i == 0) { Thread.Sleep(1000);//wait for some time while contending, if the other instance of the program is still in progress of shutting down. continue; } exitingMessage?.Invoke(Log.GetExceptionMessage(e) + "\r\n\r\nExiting..."); Environment.Exit(0); } } if (GLOBAL_SINGLE_PROCESS_MUTEX.WaitOne(1000, false))//wait for some time while contending, if the other instance of the program is still in progress of shutting down. { return; } exitingMessage?.Invoke(appName + " is already running, so this instance will exit."); Environment.Exit(0); }
public static void Main(string[] args) { try { //Wpf.Message.ResourceDictionaryPath = "assembly=" + System.Reflection.Assembly.GetEntryAssembly().EscapedCodeBase + ";resources/style.xaml"; //Uri u = new System.Uri("/" + PathRoutines.GetFileNameFromPath(System.Reflection.Assembly.GetEntryAssembly().EscapedCodeBase) + ";component/resources/style.xaml", System.UriKind.Relative); //System.Windows.ResourceDictionary rd = new System.Windows.ResourceDictionary(); //System.Windows.Application.LoadComponent(rd, u); //Wpf.Message.ResourceDictionary = rd; //System.Windows.Resources.StreamResourceInfo info = System.Windows.Application.GetContentStream(u); //System.Windows.Markup.XamlReader reader = new System.Windows.Markup.XamlReader(); //Wpf.Message.ResourceDictionary = (System.Windows.ResourceDictionary)reader.LoadAsync(info.Stream); Log.Main.Inform("Version: " + AssemblyRoutines.GetAppVersion()); string user = ProcessRoutines.GetProcessUserName(); string m = "User: "******" (as administrator)"; } Log.Main.Inform(m); ProcessRoutines.RunSingleProcessOnly(); if (ProgramRoutines.IsParameterSet <CommandLineParameters>(CommandLineParameters.INITIAL_CONFIGURATION)) { Message.Inform("Please configure service in the next window."); SettingsWindow.OpenDialog(); return; } #if !test Application.Run(SysTray.This); #else UiApiClient.testCreateInstanceContext(); SettingsWindow.Open(); Application.Run(SysTray.This); //UiApiClient.testSubscribe(); //UiApiClient.testSubscribe(); //Thread.Sleep(1000); //UiApiClient.testCloseInstanceContext(); //UiApiClient.testCreateInstanceContext(); //UiApiClient.testSubscribe(); //UiApiClient.testSubscribe(); //for (; ; ) //{ // System.Threading.Thread.Sleep(10000); //} #endif } catch (Exception e) { LogMessage.Error(e); } finally { Exit(); } }
internal MainForm() { InitializeComponent(); this.Text = Cliver.Bot.Program.Title; if (ProgramRoutines.IsParameterSet(CommandLineParameters.CONFIGURE)) { this.buttonStart.Enabled = false; } ProgressBarInputItemQueueName = Session.GetFirstDeclaredInputItemType().Name; Session.Closing += Session_Closing; InputItemQueue.Progress += new InputItemQueue.OnProgress(Session_InputItemQueueProgress); }
static Program() { Cliver.Bot.Program.Initialize(); if (ProgramRoutines.IsParameterSet(CommandLineParameters.CONFIGURE)) { Mode = ProgramMode.CONFIGURE; return; } if (ProgramRoutines.IsParameterSet(CommandLineParameters.WINDOWLESS)) { Mode = ProgramMode.WINDOWLESS; return; } if (ProgramRoutines.IsParameterSet(CommandLineParameters.AUTOMATIC)) { Mode = ProgramMode.AUTOMATIC; return; } Mode = ProgramMode.DIALOG; }
public static InfoWindow Create(string text, string image_url, string action_name, Action action, string sound_file = null, Brush box_brush = null, Brush button_brush = null) { return(Create(ProgramRoutines.GetAppName(), text, image_url, action_name, action, sound_file, box_brush, button_brush)); }