/// <summary> Loads, displays, saves and returns an alias configuration. </summary>
        /// <remarks> Any changes to the alias list are saved even if the form is cancelled. </remarks>
        public static AliasConfiguration Execute()
        {
            AliasConfiguration configuration = AliasManager.LoadConfiguration();

            Execute(configuration);
            return(configuration);
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            WinForms.Application.SetUnhandledExceptionMode(WinForms.UnhandledExceptionMode.CatchException, true);
            WinForms.Application.EnableVisualStyles();

            WinForms.Application.ThreadException += new ThreadExceptionEventHandler(ThreadException);
            try
            {
                // Parse the command line
                string alias         = String.Empty;
                string applicationID = String.Empty;
                string userID        = String.Empty;
                int    i             = 0;
                while (i < args.Length)
                {
                    switch (args[i].ToLower())
                    {
                    case AliasParameter:
                        alias = args[i + 1];
                        i++;
                        break;

                    case ApplicationParameter:
                        applicationID = args[i + 1];
                        i++;
                        break;

                    case UserParameter:
                        userID = args[i + 1];
                        i++;
                        break;

                    default:
                        throw new ClientException(ClientException.Codes.InvalidCommandLine, args[i]);
                    }
                    i++;
                }

                AliasConfiguration configuration;
                if (alias == String.Empty)
                {
                    configuration = ServerConnectForm.Execute();
                }
                else
                {
                    configuration = AliasManager.LoadConfiguration();
                    configuration.DefaultAliasName = alias;
                }

                if (userID != String.Empty)
                {
                    configuration.Aliases[configuration.DefaultAliasName].SessionInfo.UserID = userID;
                }

                using (DataSession dataSession = new DataSession())
                {
                    dataSession.Alias = configuration.Aliases[configuration.DefaultAliasName];
                    dataSession.SessionInfo.Environment = "WindowsClient";
                    dataSession.Active = true;

                    if (applicationID == String.Empty)
                    {
                        using (DAE.Client.DataView view = new DAE.Client.DataView())
                        {
                            view.Session     = dataSession;
                            view.Expression  = ApplicationListExpression;
                            view.OrderString = ApplicationListOrder;
                            view.IsReadOnly  = true;
                            view.Open();

                            // Count the number of applications
                            System.Collections.IEnumerator enumValue = view.GetEnumerator();                                     // use explicit enumerator to avoid foreach unused var warning
                            int count = 0;
                            while (enumValue.MoveNext())
                            {
                                count++;
                            }

                            // Prompt the user for the application if there is not exactly one row
                            if (count != 1)
                            {
                                view.First();
                                ApplicationListForm.Execute(view);
                            }

                            applicationID = view.Fields["ID"].AsString;
                        }
                    }

                    Session session = new Session(dataSession, false);                     // Pass false because the DataSession will be disposed by the using block
                    session.Start(session.SetApplication(applicationID));                  // This call will dispose the session.
                }
            }
            catch (AbortException)
            {
                // Do nothing (ignore abort)
            }
            catch (Exception exception)
            {
                Windows.Session.HandleException(exception);
            }
        }