Beispiel #1
0
        public MainForm(DataManager manager)
        {
            this.manager = manager;

            InitializeComponent();
            ResetLanguage();

            ReloadList();

            if (ListBoxItems.Items.Count > 0)
                ListBoxItems.SetSelected(0, true);
        }
Beispiel #2
0
		static void WinFormApp(Arguments arg) {
            InitServices();

			var welcome = new WelcomeController(new ViewFactory());
            welcome.TryShow();

			var manager = new DataManager();

			try {
				manager.StartDelayedLoading();
				manager.LoadProfiles();
			}
			catch (Exception e) {
				MessageBox.Show(e.Message, ClientServiceLocator.GetService<ILanguage>().GetText("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
				UseTrace(e);
			}

            var frm = new MainForm(manager);

			try {
				new MainController(frm, manager);
				if (arg.Minimalize) {
					frm.GoToTray();
					Application.Run();
					manager.SaveSettings();
				}
				else if (arg.ConsoleMode) {
					ApplyProfile(manager, arg.Profiles[0]);
				}
				else {
					Application.Run(frm);
					manager.SaveSettings();
				}

			}
			catch (Exception e) {
				using (var form = new ExceptionForm(e.Message + "\n\n" + e.StackTrace)) {
					form.FormBorderStyle = FormBorderStyle.FixedDialog;
					form.StartPosition = FormStartPosition.CenterScreen;
					form.ShowDialog();
				}
				UseTrace(e);
			}
			finally {
				manager.Dispose();
				frm.Dispose();
				Properties.Settings.Default.Save();
			}
            
        }
Beispiel #3
0
    	private static void ApplyProfile(DataManager manager, string profile) {
			using (var tmpForm = new Form() { TopMost = true }) {
				if (manager.RequestApply(profile)) {

					MessageBox.Show(tmpForm, ClientServiceLocator.GetService<ILanguage>().GetText("ProfileApplied"),
					                ClientServiceLocator.GetService<ILanguage>().GetText("Succes"), MessageBoxButtons.OK,
					                MessageBoxIcon.Information);
				}
				else {
					MessageBox.Show(tmpForm, ClientServiceLocator.GetService<ILanguage>().GetText("CannotApply"),
					                ClientServiceLocator.GetService<ILanguage>().GetText("Error"), MessageBoxButtons.OK,
					                MessageBoxIcon.Error);
				}
			}
    	}
Beispiel #4
0
 private static int ConsoleApp(Arguments arg)
 {
     var manager = new DataManager();
     try {
         manager.LoadProfiles();
     }
     catch (Exception e) {
         Console.WriteLine("Error: " + e.Message);
         manager.Dispose();
         return 1;
     }
     bool result = true;
     foreach (ConsoleActions act in arg.Actions) {
         switch (act) {
             case ConsoleActions.UseProfile:
                 foreach (string profile in arg.Profiles) {
                     bool r = false;
                     try {
                         r = manager.Apply(profile);
                     }
                     catch(Exception e) {
                         Trace.WriteLine(e.Message);
                         Trace.WriteLine(e.StackTrace);
                         r = false;
                     }
                     result &= r;
                     if (r)
                         Console.WriteLine(profile + ": OK");
                     else
                         Console.WriteLine(profile + ": FAILED");
                 }
                 break;
         }
     }
     manager.Dispose();
     return result ? 0 : 1;
 }