Esempio n. 1
0
        static void Main(string[] args)
        {
            Application.SetCompatibleTextRenderingDefault(false);
            Application.EnableVisualStyles();

            //MMessageBox.Show("holder", Application.ProductName);

            service = new FPService.FPService();

            //appApi = new ApiManager(args);
            /*
            if (!SecureLib.SetGetState(string.Empty))
            {
                Registration reg = new Registration();
                reg.ShowDialog();
                reg.Dispose();
                Environment.Exit(Environment.ExitCode);
            }
            */
            // in futrue move this to mdcore lib
            /* test
            if (MainArgs.ContainsKey("-c") && MainArgs["-c"] != null)
                AppConfig.LoadData(MainArgs["-c"].ToString());
            else
                AppConfig.LoadData();
            test */
            AppConfig.LoadData();
            winapi.WApi.OutputDebugString("after AppConfig.LoadData()");

            CoreLib.VerifyAllFolders();
            winapi.WApi.OutputDebugString("after CoreLib.VerifyAllFolders()");

            CoreLib.WriteLog(new Exception("It is not an error. This message used for tracking of app's startup only."), "AppStartup (Main)");

            //one copy
            System.Threading.Mutex myMutex = null;
            try
            {
                myMutex = System.Threading.Mutex.OpenExisting("PayDeskMutex");
                winapi.WApi.OutputDebugString("mutex received");
            }
            catch { }

            try
            {
                if (myMutex != null && AppConfig.APP_AllowOneCopy)
                {
                    MMessageBox.Show("Вже запущена одна копія програми", Application.ProductName);
                    Environment.Exit(0);
                }
                else
                    myMutex = new System.Threading.Mutex(true, "PayDeskMutex");
            }
            catch (Exception ex)
            {
                winapi.WApi.OutputDebugString(ex.Message);
            }

            bool active = true;
            do
            {
                active = true;

                uiWndStartupDialog entry = new uiWndStartupDialog();
                active = entry.ShowDialog() == DialogResult.OK;
                entry.Dispose();

                if (!active)
                    break;

                winapi.WApi.OutputDebugString("before main action switcher");
                switch (CoreLib.Authorize(entry.Password, entry.Login))
                {
                    case "service":
                        {
                            winapi.WApi.OutputDebugString("before service windoow");
                            uiWndService serv = new uiWndService();
                            serv.ShowDialog();
                            serv.Dispose();
                            break;
                        }
                    case "main":
                        {
                            winapi.WApi.OutputDebugString("before main windoow");
                            uiWndMain main = null;
                            try
                            {
                                main = new uiWndMain();
                                if (main.ShowDialog() != DialogResult.Retry)
                                    active = false;
                            }
                            catch(Exception ex)
                            {
                                CoreLib.WriteLog(ex, "AppStartup inside switcher (Main)");

                            }
                            finally
                            {
                                if (main != null)
                                    main.Dispose();
                            }
                            /*
                            if (Program.MainArgs.ContainsKey("-c") && Program.MainArgs["-c"] != null)
                                AppConfig.SaveData(Program.MainArgs["-c"].ToString());
                            else*/
                            AppConfig.SaveData();
                            winapi.WApi.OutputDebugString("after saving configuration");
                            break;
                        }
                    default: { break; }
                }

            } while (active);

            CoreLib.WriteLog(new Exception("It is not an error. This message used for tracking of app's exit only."), "AppStartup (Main)");
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Application.SetCompatibleTextRenderingDefault(false);
            Application.EnableVisualStyles();

            // get arguments
            Hashtable hargs = new Hashtable();
            components.Components.ArgumentParser.Com_ArgumentParser.TransformArguments(hargs, args);

            // load xml settings
            ApplicationConfiguration.CustomConfigurationMethod = CustomConfigurationSettingsContext;
            ApplicationConfiguration.Instance.LoadConfigurationData();

            // load bin settings
            driver.Config.ConfigManager.getInstance();
            if (!driver.Config.ConfigManager.LoadConfiguration())
                return;

            // mode only
            try
            {
                CoreLib.WriteLog(new Exception("Starting service mode for " + hargs["mode"]), "AppStartup (Main)");

                if (hargs.ContainsKey("mode"))
                {
                    // admin verification

                    DialogResult rez = DialogResult.None;
                    PayDesk.Components.UI.uiWndAdmin admin = new uiWndAdmin(FormStartPosition.CenterScreen);
                    rez = admin.ShowDialog();

                    // mode selector with admin
                    if (rez == DialogResult.OK)
                        switch (hargs["mode"].ToString())
                        {
                            case "settings":
                                {
                                    PayDesk.Components.UI.uiWndSettings wnd = new PayDesk.Components.UI.uiWndSettings();
                                    wnd.ShowDialog();
                                    break;
                                }
                            case "printer":
                                {
                                    PayDesk.Components.UI.uiWndPrinting wnd = new PayDesk.Components.UI.uiWndPrinting();
                                    wnd.ShowDialog();
                                    break;
                                }
                            case "billmanager":
                                {
                                    PayDesk.Components.UI.wndBills.uiWndBillManagercs wnd = new PayDesk.Components.UI.wndBills.uiWndBillManagercs();
                                    wnd.ShowDialog();
                                    break;
                                }
                        }

                    admin.Dispose();

                    return;
                }

            }
            catch { }

            ApplicationName = string.Empty;
            //if (args.Length != 0 && args[0] != null && args[0] != string.Empty)
            try
            {
                if (hargs.ContainsKey("app") && hargs["app"].ToString().Length != 0)
                    ApplicationName = args[0];
            }
            catch { }

            //axCfg = ApplicationConfiguration. ("display", @"default/config", (ApplicationName == "" ? "" : ApplicationName + @"/config"), (Program.ApplicationName != string.Empty));

            //MessageBox.Show("wait");

            //appApi = new ApiManager(args);
            /*
            if (!SecureLib.SetGetState(string.Empty))
            {
                Registration reg = new Registration();
                reg.ShowDialog();
                reg.Dispose();
                Environment.Exit(Environment.ExitCode);
            }
            */
            // in futrue move this to mdcore lib
            /* test
            if (MainArgs.ContainsKey("-c") && MainArgs["-c"] != null)
                AppConfig.LoadData(MainArgs["-c"].ToString());
            else
                AppConfig.LoadData();
            test */
            // [a] // AppConfig.LoadData();

            FileMgrLib.VerifyAllFolders();
            CoreLib.WriteLog(new Exception("It is not an error. This message used for tracking of app's startup only."), "AppStartup (Main)");

            // [a] // plugs = new PluginModule.Plugins(AppConfig.Path_Plugins);
            plugs = new Com_PluginManager(driver.Config.ConfigManager.Instance.CommonConfiguration.Path_Plugins);

            //one copy
            System.Threading.Mutex myMutex = null;
            try
            {
                myMutex = System.Threading.Mutex.OpenExisting("PayDeskMutex");
            }
            catch { }
            if (myMutex != null && driver.Config.ConfigManager.Instance.CommonConfiguration.APP_AllowOneCopy)
            {
                MMessageBox.Show("Вже запущена одна копія програми", Application.ProductName);
                Environment.Exit(0);
            }
            else
                myMutex = new System.Threading.Mutex(true, "PayDeskMutex");

            bool active = true;
            do
            {
                active = true;

                uiWndStartupDialog entry = new uiWndStartupDialog();
                active = entry.ShowDialog() == DialogResult.OK;
                entry.Dispose();

                if (!active)
                    break;

                switch (SecureLib.Authorize(entry.Password, entry.Login))
                {
                    case "service":
                        {
                            uiWndService serv = new uiWndService();
                            serv.ShowDialog();
                            serv.Dispose();
                            break;
                        }
                    case "main":
                        {
                            uiWndMain main = new uiWndMain();
                            if (main.ShowDialog() != DialogResult.Retry)
                                active = false;
                            main.Dispose();/*
                            if (Program.MainArgs.ContainsKey("-c") && Program.MainArgs["-c"] != null)
                                AppConfig.SaveData(Program.MainArgs["-c"].ToString());
                            else*/
                            driver.Config.ConfigManager.SaveConfiguration();
                            break;
                        }
                    default: { break; }
                }

            } while (active);

            CoreLib.WriteLog(new Exception("It is not an error. This message used for tracking of app's exit only."), "AppStartup (Main)");

            System.Diagnostics.Process[] prc = System.Diagnostics.Process.GetProcessesByName("vk");
            foreach (System.Diagnostics.Process p in prc)
                p.Kill();
        }