Beispiel #1
0
    // Start is called before the first frame update
    void Start()
    {
        UpdateConsole("Init Oculus Platform SDK...");
        Core.AsyncInitialize().OnComplete(message => {
            if (message.IsError)
            {
                // Init failed, nothing will work
                UpdateConsole(message.GetError().Message);
            }
            else
            {
                /**
                 * Get the deeplink message when the app starts up
                 */
                UpdateConsole("Init complete!\n" + GetAppLaunchDetails());

                /**
                 * Get and cache the Logged in User ID for future queries
                 */
                Users.GetLoggedInUser().OnComplete(OnLoggedInUser);

                /**
                 * Get the list of destinations defined for this app from the developer portal
                 */
                RichPresence.GetDestinations().OnComplete(OnGetDestinations);

                /**
                 * Listen for future deeplink message changes that might come in
                 */
                ApplicationLifecycle.SetLaunchIntentChangedNotificationCallback(OnLaunchIntentChangeNotif);
            }
        });
    }
Beispiel #2
0
    public async Task Restart()
    {
        _logger.LogInformation("Shutdown triggered by 'restart' command. Application will shut down in 10 seconds ...");
        await RespondAsync("Shutting down in 10 seconds. Restart will be performed automatically.");

        _ = Task.Run(async() =>
        {
            await Task.Delay(TimeSpan.FromSeconds(10));
            ApplicationLifecycle.End();
        }).ConfigureAwait(false);
    }
Beispiel #3
0
 public void Launch_WithSampleAppPresent_CorrectOutput()
 {
     Task.Run(async() =>
     {
         await Task.Delay(3000);
         ApplicationLifecycle.Shutdown();
     });
     Lifecycle.Program.Main(new[] { "." });
     _consoleOutputCollector.Output.Should().Contain("OnStart called");
     _consoleOutputCollector.Output.Should().Contain("OnStop called");
 }
 protected override void OnInstall()
 {
     CreateHook("advapi32.dll", "StartServiceCtrlDispatcherW", new StartServiceCtrlDispatcherDelegate(StartServiceCtrlDispatcherHook));
     CreateHook("advapi32.dll", "RegisterServiceCtrlHandlerExW", new RegisterServiceCtrlHandlerExDelegate(RegisterServiceCtrlHandlerExHook));
     CreateHook("advapi32.dll", "SetServiceStatus", new SetServiceStatusDelegate(SetServiceStatusHook));
     ApplicationLifecycle.RegisterForGracefulShutdown(async() =>
     {
         Console.WriteLine("Starting graceful shutdown of services");
         await Task.WhenAll(_serviceCommands.Select(x =>
                                                    Task.Run(() => x.Value.CommandControlDelegate(5, 0, IntPtr.Zero, IntPtr.Zero))));
     });
 }
Beispiel #5
0
        public void Launch_WithMultipleAppsPresent_SelectsCorrectEntrypoint()
        {
            var otherExeName = "ZampleServices.exe";

            File.Copy("SampleServices.exe", otherExeName, true);
            Environment.SetEnvironmentVariable("WINDOWS_SERVICE_EXE", otherExeName);

            Task.Run(async() =>
            {
                await Task.Delay(3000);
                ApplicationLifecycle.Shutdown();
            });
            Lifecycle.Program.Main(new[] { "." });
            _consoleOutputCollector.Output.Should().Contain($"{otherExeName} as the service entry point executable");
        }
    void InitCallback(Message <PlatformInitialize> msg)
    {
        if (msg.IsError)
        {
            TerminateWithError(msg);
            return;
        }

        LaunchDetails launchDetails = ApplicationLifecycle.GetLaunchDetails();

        SocialPlatformManager.LogOutput("App launched with LaunchType " + launchDetails.LaunchType);

        // First thing we should do is perform an entitlement check to make sure
        // we successfully connected to the Oculus Platform Service.
        Entitlements.IsUserEntitledToApplication().OnComplete(IsEntitledCallback);
    }
Beispiel #7
0
    /**
     * Getting the deeplink information off the app launch details. When a user requests
     * to travel to a destination from outside your app, their request will be found here
     * Get the info to bring the user to the expected destination.
     */
    string GetAppLaunchDetails()
    {
        var launchDetails = ApplicationLifecycle.GetLaunchDetails();

        // The other users this user expect to see after traveling to the destination
        // If there is conflicting data between the inputted users and destination,
        // favor using the users.
        // For example, if user A & destination 1 was passed in, but user A is now
        // in destination 2, it is better to bring the current user to destination 2
        // if possible.
        var users      = launchDetails.UsersOptional;
        var usersCount = (users != null) ? users.Count : 0;

        // The deeplink message, this should give enough info on how to go the
        // destination in the app.
        var deeplinkMessage = launchDetails.DeeplinkMessage;

        // The API Name of the destination. You can set the user to this after
        // navigating to the app
        var destinationApiName = launchDetails.DestinationApiName;

        TrackingID = !string.IsNullOrEmpty(launchDetails.TrackingID) ? launchDetails.TrackingID : "FakeTrackingID";

        var detailsString = "-Deeplink Message:\n" + deeplinkMessage + "\n-Api Name:\n" + destinationApiName + "\n-Users:\n";

        if (usersCount > 0)
        {
            foreach (var user in users)
            {
                detailsString += user.OculusID + "\n";
            }
        }
        else
        {
            detailsString += "null\n";
        }
        detailsString += "\n";
        return(detailsString);
    }
Beispiel #8
0
    private async Task DisconnectedHandler()
    {
        const int delayInSeconds = 30;

        _logger.LogWarning("Bot disconnected. Checking for connection status in {DelayInSeconds} seconds.", delayInSeconds);

        // The Discord connection might get lost, but should reconnect automatically.
        // In rare cases, the reconnect doesn't work and the bot will just idle.
        // Therefore, after a disconnect, we grant the connection 30 seconds to recover.
        await Task.Delay(TimeSpan.FromSeconds(delayInSeconds));

        if (_discordAccess.IsConnected)
        {
            _logger.LogInformation("Bot re-connected successfully.");
            return;
        }
        // If it doesn't recover during this period of time, we'll kill the process.
        _logger.LogWarning("Failed to recover connection to Discord. Killing the process.");
        // Give the logger some time to log the message
        await Task.Delay(TimeSpan.FromSeconds(5));

        // Finally kill the process to start over
        ApplicationLifecycle.End();
    }
 public void Shutdown()
 {
     try
     {
         this.tracer.Debug("Calling custom OnShutdown procedure");
         this.OnShutdown();
     }
     catch (Exception ex)
     {
         this.tracer.Debug("Custom OnShutdown procedure failed");
         if (!this.HandleBootstrappingException(ex))
         {
             throw;
         }
     }
     finally
     {
         applicationLifecycle = ApplicationLifecycle.Uninitialized;
         if (this.simpleIoc != null)
         {
             this.simpleIoc.Reset();
             this.simpleIoc = null;
         }
     }
 }
 private void InternalOnStartup()
 {
     try
     {
         this.tracer.Debug("Calling custom OnStartup procedure");
         this.OnStartup();
         applicationLifecycle = ApplicationLifecycle.Running;
     }
     catch (Exception ex)
     {
         if (!this.HandleBootstrappingException(ex))
         {
             throw new BootstrappingException("Bootstrapping failed during custom OnStratup sequence.", ex);
         }
     }
 }
 public void Sleep()
 {
     applicationLifecycle = ApplicationLifecycle.Sleep;
 }
Beispiel #12
0
    /**
     * Setting the rich presence
     */
    void SetPresence()
    {
        var options = new RichPresenceOptions();

        // Only Destination API Name is required
        options.SetApiName(DestinationAPINames[DestinationIndex]);

        // Override the deeplink message if you like, otherwise it will use the one found in the destination
        if (!string.IsNullOrEmpty(DeeplinkMessageOverride))
        {
            options.SetDeeplinkMessageOverride(DeeplinkMessageOverride);
        }

        if (!string.IsNullOrEmpty(InstanceID))
        {
            options.SetInstanceId(InstanceID);
        }

        // Set is Joinable to let other players deeplink and join this user via the presence
        options.SetIsJoinable(IsJoinable);

        // Set if the user is idle
        options.SetIsIdle(IsIdle);

        // Used when displaying the current to max capacity on the user's presence
        options.SetCurrentCapacity(CurrentCapacity);
        options.SetMaxCapacity(MaxCapacity);

        // Used to display how long since this start / when will this end
        options.SetStartTime(StartTime);
        options.SetEndTime(EndTime);

        // Used to display extra info like the capacity, start/end times, or looking for a match
        options.SetExtraContext(ExtraContext);
        UpdateConsole("Setting Rich Presence to " + DestinationAPINames[DestinationIndex] + " ...");

        // Here we are setting the rich presence then fetching it after we successfully set it
        RichPresence.Set(options).OnComplete(message => {
            if (message.IsError)
            {
                UpdateConsole(message.GetError().Message);
                ApplicationLifecycle.LogDeeplinkResult(TrackingID, LaunchResult.FailedOtherReason);
            }
            else
            {
                ApplicationLifecycle.LogDeeplinkResult(TrackingID, LaunchResult.Success);
                // Note that Users.GetLoggedInUser() does not do a server fetch and will
                // not get an updated presence status
                Users.Get(LoggedInUserID).OnComplete(message2 =>
                {
                    if (message2.IsError)
                    {
                        UpdateConsole("Success! But rich presence is unknown!");
                    }
                    else
                    {
                        UpdateConsole("Rich Presence set to:\n" + message2.Data.Presence + "\n" + message2.Data.PresenceDeeplinkMessage + "\n" + message2.Data.PresenceDestinationApiName);
                    }
                });
            }
        });
    }