Exemplo n.º 1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            AssemblyTraceEvent.Tracer.TraceEvent(TraceEventType.Verbose, 39, "Starting application.");
            string _commandLine = Environment.CommandLine;

#if DEBUG
            if (_commandLine.ToLower().Contains("debugstop"))
            {
                MessageBox.Show("Attach debug point");
            }
#endif
            bool _isDebugRun = _commandLine.ToLower().Contains(m_InstallLicenseDebugerArgument);
            if (IsFirstRun() || _isDebugRun)
            {
                try
                {
                    AssemblyTraceEvent.Tracer.TraceEvent(TraceEventType.Verbose, 49, $"Installing license because IsFirstRun={IsFirstRun()}, and debug={_isDebugRun}.");
                    LibInstaller.InstallLicense(false);
                }
                catch (Exception _ex)
                {
                    string _message = $"Installing license has failed, reason: {_ex.Message}: {_ex.StackTrace}.";
                    AssemblyTraceEvent.Tracer.TraceEvent(TraceEventType.Error, 55, _message);
                    MessageBox.Show(_message, "License Installation error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            try
            {
                SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
                if (!SecurityManager.IsGranted(permission))
                {
                    string msg = "";
                    msg += "This application requires permission to access unmanaged code ";
                    msg += "in order to connect to COM-DA servers directly.\r\n\r\n";
                    msg += "Connections to XML-DA servers will not be affected.";
                    MessageBox.Show(msg, "CAS OPCViewer Data Access Client");
                }
                MainFormV2008 mainForm;
                string[]      args = GetArguments();
                if (args == null || args.Length < 2 || string.IsNullOrEmpty(args[1]) || args[1].Contains(m_InstallLicenseDebugerArgument) || args[1].Contains("http://"))
                {
                    mainForm = new MainFormV2008();
                }
                else
                {
                    mainForm = new MainFormV2008(args[1]); //args[ 0 ] - is application file name , args[ 1 ] - is first argument
                }
                if (ApplicationDeployment.IsNetworkDeployed)
                {
                    mainForm.DoNotShowUnlockCodeToolStrip();
                }
                Application.Run(mainForm);
            }
            catch (Exception e)
            {
                string _message = $"An unexpected exception occurred. Application exiting with error:\r\n\r\n {e.Message}";
                AssemblyTraceEvent.Tracer.TraceEvent(TraceEventType.Error, 84, _message);
                MessageBox.Show(_message, "OPCViewer - Data Access Client", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        internal static void DoApplicationRun(Action <Form> applicationRun)
        {
            MainFormV2008 _mainForm = new MainFormV2008();

            applicationRun(_mainForm);
        }