/// <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>Dispatches InputForm data received by after a "Submitted" or "Canceled" event.</summary> /// <param name="inputForm">Reference to the input form.</param> /// <param name="wasSubmitted">Set true if the OK button was clicked. Set false if canceled.</param> private void HandleFormInput(InputForm inputForm, bool wasSubmitted) { // Validate argument. if (inputForm == null) { return; } // Close the input form and remove our event handlers from it. // This will remove all references to this form, allowing it to be garbage collected. fCoronaPanel.Children.Remove(inputForm); inputForm.Submitted -= OnFormInputSubmitted; inputForm.Canceled -= OnFormInputCanceled; // Dispatch an event to Corona about the received input form data. if (fCoronaRuntimeEnvironment != null) { // Create a custom Corona event named "userLoggedIn" with the following properties. // This will be converted into a Lua "event" table once dispatched by Corona. var eventProperties = CoronaLabs.Corona.WinRT.CoronaLuaEventProperties.CreateWithName("onLoginInfo"); eventProperties.Set("submitted", wasSubmitted); if (wasSubmitted) { eventProperties.Set("username", inputForm.Username); eventProperties.Set("password", inputForm.Password); } // Dispatch the event to Lua. var eventArgs = new CoronaLabs.Corona.WinRT.CoronaLuaEventArgs(eventProperties); fCoronaRuntimeEnvironment.DispatchEvent(eventArgs); } }
/// <summary> /// Invoked when a message is received /// </summary> /// <param name="device">The ProximityDevice object that received the message.</param> /// <param name="message">The message that was received.</param> private void messageReceived(ProximityDevice device, ProximityMessage message) { // This will be converted into a Lua "event" table once dispatched by Corona. var eventProperties = CoronaLabs.Corona.WinRT.CoronaLuaEventProperties.CreateWithName("messageReceived"); eventProperties.Set("message", message.DataAsString); // Dispatch the event to Lua. var eventArgs = new CoronaLabs.Corona.WinRT.CoronaLuaEventArgs(eventProperties); var result = coronaEventArgs.CoronaRuntimeEnvironment.DispatchEvent(eventArgs); }
/// <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")); }