Beispiel #1
0
        static void Main(string[] args)
        {
            try
            {
                // enable styles, faster text rendering and protect the current process
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                ProcessSecurity.ProtectCurrentProcessFromTerminate();

                // parse the args
                var showSecurityDialog = false;
                var overrideConfig     = (string)null;
                foreach (var arg in args)
                {
                    if (arg.Equals(ParamShowSecurityDialog, StringComparison.OrdinalIgnoreCase))
                    {
                        if (!showSecurityDialog)
                        {
                            showSecurityDialog = true;
                            continue;
                        }
                    }
                    else if (arg.StartsWith(ParamOverrideConfig, StringComparison.OrdinalIgnoreCase))
                    {
                        if (overrideConfig == null)
                        {
                            overrideConfig = arg.Substring(ParamOverrideConfig.Length);
                            continue;
                        }
                    }
                    MessageBox.Show(string.Format("{0} [{1}] [{2}<path>]\n\n\n\n{1}\t\tDisplays the security dialog.\n\n{2}\tUse an alternative app config file.", Environment.GetCommandLineArgs()[0], ParamShowSecurityDialog, ParamOverrideConfig), "Usage", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                // set the config file and show the security dialog if requested
                if (overrideConfig != null)
                {
                    ((AppDomainSetup)typeof(AppDomain).GetProperty("FusionStore", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(AppDomain.CurrentDomain, null)).ConfigurationFile = overrideConfig;
                }
                configFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
                if (showSecurityDialog)
                {
                    Security.ShowEditDialog();
                    return;
                }

                // create the rdp session
                var session = new RDPSessionClass();
                session.OnError += OnSessionError;
                session.Open();
                try
                {
                    // create the web service host and run the app
                    var host = new WebServiceHost(new Service(session));
                    host.Open();
                    try { Application.Run(); }
                    finally { host.Close(); }
                }
                finally { session.Close(); }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, e.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.ExitCode = Marshal.GetHRForException(e);
            }
        }