public void ScheduleMessageTest() { CreateMessageTest(); var result = client.BroadcastMessageAsync(message, NotificationTypes.Regular, DateTime.UtcNow.AddMinutes(5)).Result; broadcast = result; Trace.WriteLine($"Broadcast Id: {result.Id}"); }
public async Task <bool> CancelScheduledBroadcast(BroadcastResult broadcast) { string apiUri = $"https://graph.facebook.com/v{ApiVersion}/{broadcast.Id}?access_token={PageToken}"; CancelContainer container = new CancelContainer(); var result = await PostAsync <CancelResult>(container, apiUri); return(result.Result); }
/// <summary> /// This method will call the broadcast method, and then decide whether we have got any valid repsonses. It will keep broadcasting until we find an arduino. /// </summary> private async void ScanForDevices() { // We can jump back to here when we need to rescan for arduinos. This stop us having to do recursion and then filling up lots of memory top_of_function: // We have started sending statusLabel.Text = "Sending..."; // Create the socket. We will use this to bradcast the discovery packet Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp) { // If this isn't set then we get an access denied exception EnableBroadcast = true }; // Broadcast the packet and get the result var tuple = await Broadcast(socket); BroadcastResult status = tuple.Item1; UdpReceiveResult response = tuple.Item2; // Holds the amount of times we have pinged the network byte pingCount = 1; pingCountLabel.Text = "1 ping"; // If we got a network unreachable then the user isn't connected if (status == BroadcastResult.NetworkUnreachable) { CreateRetryButton(); statusLabel.Text = "Couldn't find any devices because the network is unreachable. Please connect to a WiFi network or hotspot and try again. Note: using mobile data will not work."; // We dont need to rescan so we can exit the function return; } // If it timed out we need to ping the network again. while (status == BroadcastResult.TimedOut) { tuple = await Broadcast(socket); status = tuple.Item1; response = tuple.Item2; pingCount++; pingCountLabel.Text = $"{pingCount} pings"; // If we have pinged 3 times then we really can't find the arduino so we gotta stop if (pingCount == 3) { statusLabel.Text = "No devices found. If the gas sensor's green light is on, then please connect to your 2.4GHz network and try again"; CreateRetryButton(); // We dont need to rescan so we can exit the function return; } } bool needPassword = false; if (Encoding.ASCII.GetString(response.Buffer).EndsWith("np")) { nameEntry.IsVisible = true; passwordEntry.IsVisible = true; goButton.IsVisible = true; needPassword = true; } // Otherwise, we have received the data. Notify the app. statusLabel.Text = "Connected to the arduino"; // Start the tcp loop as a task. This will run it in the background withput interupting/blocking the main UI thread await Task.Run(() => { // When the function exits it will be because of a connection failure. TCPLoop(response.RemoteEndPoint.Address.ToString(), needPassword); // Give the arduino a bit of time to sort its problems out Task.Delay(2000); }); Console.WriteLine("Down here"); // We want the function to rescan for any arduinos goto top_of_function; }