public void CreateSession()
    {
        CreateFrontend();

        // StartSession will call ARRService_OnSessionStarted once the session becomes available
        arrService.StartSession(new RenderingSessionCreationParams(VMSize, MaxLeaseTimeHours, MaxLeaseTimeMinutes));
    }
Ejemplo n.º 2
0
    // start a new session or use an existing one, connect to it and then load the model
    public async void AutoStartSessionAsync()
    {
        try
        {
            CreateFrontend();

            RenderingSessionProperties props = default(RenderingSessionProperties);
            bool   hasSessionId = !string.IsNullOrEmpty(SessionId);
            string sessionId    = SessionId;

            if (hasSessionId)
            {
                try
                {
                    props = await arrService.OpenSession(SessionId);
                }
                catch (RRSessionException sessionException)
                {
                    LogMessage($"Error opening session: {sessionException.Context.ErrorMessage}", true);
                }
                catch (RRException generalException)
                {
                    LogMessage($"General error opening session: {generalException.ErrorCode}", true);
                }
                finally
                {
                    SessionId = null;
                }
            }

            if (props.Status != RenderingSessionStatus.Ready)
            {
                if (hasSessionId)
                {
                    LogMessage($"Session ID: {sessionId} is in state: {props.Status}. Starting a new session.");
                }

                props = await arrService.StartSession(new RenderingSessionCreationOptions(VMSize, (int)MaxLeaseTimeHours, (int)MaxLeaseTimeMinutes));

                if (props.Status != RenderingSessionStatus.Ready)
                {
                    LogMessage($"Session creation failed. Session status: {props.Status}.", true);
                    return;
                }
            }

            SessionId = arrService.CurrentActiveSession.SessionUuid;

            if (!enabled)
            {
                return;
            }
        }
        catch (RRSessionException sessionException)
        {
            LogMessage($"Error creating session: {sessionException.Context.ErrorMessage}", true);
        }
        catch (RRException generalException)
        {
            LogMessage($"General error creating session: {generalException.ErrorCode}", true);
        }

        ConnectAndLoadModel();
    }