/// <summary> /// Called when the CoronaRuntimeEnvironment is terminating /// during a Lua "applicationExit" system event. /// </summary> /// <param name="sender">The CoronaRuntime object that raised this event.</param> /// <param name="e">Event arguments providing the CoronaRuntimeEnvironment that is being terminated.</param> private void OnCoronaRuntimeExiting( object sender, CoronaLabs.Corona.WinRT.CoronaRuntimeEventArgs e) { // Give up our reference to the Corona runtime since it is not running anymore. // This also allows it to be garbage collected. fCoronaRuntimeEnvironment = null; }
/// <summary>Called by Lua when it is requesting a login popup to be shown.</summary> /// <param name="sender">The CoronaRuntimeEnvironment that dispatched this event.</param> /// <param name="e">Provides the Lua vent table's fields/properties.</param> /// <returns>Returns a boxed object to Lua.</returns> private CoronaLabs.Corona.WinRT.ICoronaBoxedData OnRequestingLogin( CoronaLabs.Corona.WinRT.CoronaRuntimeEnvironment sender, CoronaLabs.Corona.WinRT.CoronaLuaEventArgs e) { // Fetch the "event.loginName" property, if provided. string username = string.Empty; var boxedUsername = e.Properties.Get("username") as CoronaLabs.Corona.WinRT.CoronaBoxedString; if (boxedUsername != null) { username = boxedUsername.ToString(); } // Display your login popup here using the "loginName" fetched up above. var inputForm = new InputForm(); inputForm.Username = username; inputForm.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; inputForm.VerticalAlignment = System.Windows.VerticalAlignment.Center; inputForm.Submitted += OnFormInputSubmitted; inputForm.Canceled += OnFormInputCanceled; fCoronaPanel.Children.Add(inputForm); // This returns nil to Lua. return(null); }
/// <summary> /// Called when a new CoronaRuntimeEnvironment has been created/loaded, /// but before the "main.lua" has been executed. /// </summary> /// <param name="sender">The CoronaRuntime object that raised this event.</param> /// <param name="e">Event arguments providing the CoronaRuntimeEnvironment that has been created/loaded.</param> private void OnCoronaRuntimeLoaded( object sender, CoronaLabs.Corona.WinRT.CoronaRuntimeEventArgs e) { // Keep a reference to the Corona runtime environment. // It's needed so that your login window's results can be dispatched to Corona. fCoronaRuntimeEnvironment = e.CoronaRuntimeEnvironment; fCoronaRuntimeEnvironment.AddEventListener("requestingLogin", OnRequestingLogin); }
/// <summary> /// When the app is started, start listening for other devices. /// </summary> /// <param name="sender">The CoronaRuntimeEnvironment that dispatched the event.</param> /// <param name="e">Provides the Lua event table's fields/properties.</param> private CoronaLabs.Corona.WinRT.ICoronaBoxedData OnStartSubscribeAndPublish( CoronaLabs.Corona.WinRT.CoronaRuntimeEnvironment sender, CoronaLabs.Corona.WinRT.CoronaLuaEventArgs e) { string str = ""; // Fetch the "event.message" property. var boxedMessage = e.Properties.Get("message") as CoronaLabs.Corona.WinRT.CoronaBoxedString; if (boxedMessage == null) { // A "message" property was not provided or it was not of type string. // Return an error message to Lua describing what went wrong. return(CoronaLabs.Corona.WinRT.CoronaBoxedString.From("'event.message' is a required field.")); } if (_subscribedMessageID == -1) { _subscribedMessageID = _proximityDevice.SubscribeForMessage("Windows.ProximityDemo", messageReceived); str += "Subscribed"; } else { str += "Already Subscribed"; } //Stop Publishing the current message. if (_publishedMessageID != -1) { _proximityDevice.StopPublishingMessage(_publishedMessageID); } string msg = boxedMessage.ToString(); if (msg.Length > 0) { _publishedMessageID = _proximityDevice.PublishMessage("Windows.ProximityDemo", msg); str += " - Published"; } else { str += " - Error Length 0"; } // Return a success message to Lua. return(CoronaLabs.Corona.WinRT.CoronaBoxedString.From("Started Proximity: " + str)); }
/// <summary> /// When the stop subscribing button is pressed, stop listening for other devices. /// </summary> /// <param name="sender">The CoronaRuntimeEnvironment that dispatched the event.</param> /// <param name="e">Provides the Lua event table's fields/properties.</param> private CoronaLabs.Corona.WinRT.ICoronaBoxedData OnStopSubscribeAndPublish( CoronaLabs.Corona.WinRT.CoronaRuntimeEnvironment sender, CoronaLabs.Corona.WinRT.CoronaLuaEventArgs e) { if (_subscribedMessageID != -1) { _proximityDevice.StopSubscribingForMessage(_subscribedMessageID); _subscribedMessageID = -1; } if (_publishedMessageID != -1) { _proximityDevice.StopPublishingMessage(_publishedMessageID); _publishedMessageID = -1; } // Return a success message to Lua. return(CoronaLabs.Corona.WinRT.CoronaBoxedString.From("Stopped subscribing and publishing")); }