Example #1
0
        public void BeginLogin()
        {
            Status = ConnectStatus.Connecting;

            Session.Invoke <LoginResult>
            (
                () =>
            {
                var dataSession =
                    new DataSession()
                {
                    Alias =
                        new ConnectionAlias()
                    {
                        HostName     = _hostName,
                        InstanceName = _instanceName
                    }
                };
                dataSession.Alias.SessionInfo.UserID      = _userName;
                dataSession.Alias.SessionInfo.Password    = _password == null ? "" : _password;
                dataSession.Alias.SessionInfo.Environment = "SilverlightClient";
                dataSession.Open();
                try
                {
                    var applicationRows = new List <object[]>();
                    using (var applications = dataSession.OpenReadOnlyDataView(".Frontend.Applications"))
                    {
                        foreach (DAE.Runtime.Data.Row row in applications)
                        {
                            applicationRows.Add((object[])((NativeRow)row.AsNative).Values.Clone());
                        }
                    }
                    return(new LoginResult()
                    {
                        Applications = applicationRows, DataSession = dataSession
                    });
                }
                catch
                {
                    dataSession.Dispose();
                    throw;
                }
            },
                (Exception AException) =>
            {
                Status    = ConnectStatus.Login;
                Exception = AException;
            },
                (LoginResult AResult) =>
            {
                DataSession  = AResult.DataSession;
                Applications = AResult.Applications;

                // If there is only 1 application, skip to login
                if (Applications.Count == 1)
                {
                    ApplicationID = (string)Applications[0][0];
                    BeginStartApplication();
                }
                else
                {
                    Status = ConnectStatus.SelectApplication;
                }
            }
            );
        }