private void OnLoaded(object sender, RoutedEventArgs e) { //Get references to window, screen, toastNotification and mainViewModel window = Window.GetWindow(this); screen = window.GetScreen(); toastNotification = VisualAndLogicalTreeHelper.FindLogicalChildren<ToastNotification>(this).First(); var mainViewModel = DataContext as MainViewModel; //Handle ToastNotification event mainViewModel.ToastNotification += (o, args) => { SetSizeAndPosition(); Title = args.Title; Content = args.Content; NotificationType = args.NotificationType; Action closePopup = () => { if (IsOpen) { IsOpen = false; if (args.Callback != null) { args.Callback(); } } }; AnimateTarget(args.Content, toastNotification, closePopup); IsOpen = true; }; }
private void WriteToastOptions(JsonWriter writer, ToastNotification option) { writer .StartObject() .WriteProperty("notificationtype", "toast") .WriteProperty("text1", option.Text1, true) .WriteProperty("text2", option.Text2, true) .WriteProperty("navigatepath", option.Path, true) .EndObject(); }
public void ShowToastNotification(ToastNotification toastNotification) { ToastNotificationManager.CreateToastNotifier().Show(toastNotification); }
/// <summary> /// Notify /// </summary> private void AddMessageForNotifications() { var inventories = _inventoryService.GetQuantityInventories(); foreach (var inventory in inventories) { var toastNotification = new ToastNotification { ID = inventory.ProductID, Header = inventory.ProductID, Body = "Sản phẩm: "+inventory.ProductID, Body2 = "Tồn số lượng là: " + inventory.QuantityInventory, Template = ToastNotificationTemplate.ImageAndText04, //Image = Resources.umc, Duration = ToastNotificationDuration.Default, Sound = ToastNotificationSound.SMS }; toastNotificationsManager1.Notifications.Add(toastNotification); toastNotificationsManager1.ShowNotification(toastNotification); } }
private void toastBtn_Click(object sender, RoutedEventArgs e) { ToastContent content = new ToastContent() { Launch = "app-defined-string",// pass parameter. Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "Sample" }, new AdaptiveText() { Text = "This is a simple toast notification example" } } }, }, Audio = new ToastAudio() { Src = new Uri("ms-winsoundevent:Notification.Reminder") }, Actions = new ToastActionsCustom() { Buttons = { new ToastButton("See event", "see"), new ToastButton("Ignore", "cancel") }, Inputs = { new ToastSelectionBox("interest") { DefaultSelectionBoxItemId = "2", Items = { new ToastSelectionBoxItem("1", "Interesting"), new ToastSelectionBoxItem("2", "Not sure"), new ToastSelectionBoxItem("3", "Giving it a miss") } }, new ToastTextBox("comments") { PlaceholderContent = "Type other thoughts" } } }, }; var notification = new ToastNotification(content.GetXml()); notification.ExpirationTime = DateTimeOffset.UtcNow.AddMinutes(10); ToastNotificationManager.CreateToastNotifier().Show(notification); }
public void Begin() { List <string> history = new List <string>(); Genome bestGenomeEver = null; console.WriteLn("Starting Genetic Algorithm", true); for (int r = 0; r < TetrisSettings.Runs; r++) { List <string> hist = new List <string>(); double bestRunScore = 0; int evals = 0, g = 0; // Create the population population.Clear(); Parallel.For(0, GASettings.InitialPopulation, i => { population.Add(new Genome()); //console.WriteLn((++evals).ToString() + "," + population.Last().GetFitness().Item1); //history.Add((++evals).ToString() + "," + population.Last().GetFitness().Item1); }); evals += GASettings.InitialPopulation; console.WriteLn("\nAll Genomes Initialized\n"); hist.Add(evals.ToString() + "," + Select(GASettings.SelectionMethods.ABSOLUTE, true).GetFitness().Item1.ToString()); //for (int g = 0; g < GASettings.Generations; g++) { bool run = true; while (run) { g++; Genome genome1 = Select(true); Genome genome2 = Select(true); while (genome1 == genome2) { genome2 = Select(true); } Tuple <Genome, Genome> noobs = Crossover(genome1, genome2); evals += 2; population.Add(noobs.Item1); population.Add(noobs.Item2); if (g % GASettings.AddEvery == 0) { population.Add(new Genome()); evals++; } while (population.Count > GASettings.MaxPopulation) { population.Remove(Select(false)); } if (TetrisSettings.LimitEvals) { Tuple <double, double> eh = Select(GASettings.SelectionMethods.ABSOLUTE).GetFitness(); console.WriteLn(evals.ToString() + "," + eh.Item1.ToString()); hist.Add(evals.ToString() + "," + eh.Item1.ToString()); this.console.UpdateLn(evals.ToString() + "/" + TetrisSettings.Evals.ToString() + " | " + eh.Item1.ToString(), !TetrisSettings.Verbose); } else { console.WriteLn(Select(GASettings.SelectionMethods.ABSOLUTE).GetScore() + ", " + Select(GASettings.SelectionMethods.ABSOLUTE).GetFitness().Item2); } if ((TetrisSettings.LimitEvals && evals >= TetrisSettings.Evals) || (!TetrisSettings.LimitEvals && g >= GASettings.Generations)) { run = false; break; } } console.WriteLn("Done\n"); foreach (Genome indiv in this.population) { console.WriteLn(indiv.GetScore().ToString()); } console.WriteLn(""); Genome best = Select(GASettings.SelectionMethods.ABSOLUTE); Tuple <double, double> score = best.Evaluate(true); if (score.Item1 > bestRunScore) { bestRunScore = score.Item1; history = hist; bestGenomeEver = best; } scores[r] = score; console.WriteLn(score.Item1.ToString(), true); //File.WriteAllText(TetrisSettings.SavePath, Select(GASettings.SelectionMethods.ABSOLUTE, true).ToString()); console.WriteLn("Weights"); console.WriteLn(best.ToString()); } this.console.WriteLn("\n", true); foreach (string h in history) { this.console.WriteLn(h, true); } this.console.WriteLn("", true); this.console.WriteLn(bestGenomeEver.ToString(), true); ToastVisual visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "Your Majesty" }, new AdaptiveText() { Text = "It is done" } } } }; ToastContent toastContent = new ToastContent() { Visual = visual }; var toast = new ToastNotification(toastContent.GetXml()); ToastNotificationManager.CreateToastNotifier().Show(toast); console.WriteLn("Jobs Done", true); }
public async Task Send(Notification notification) { if (notification.Id == 0) { notification.Id = this.settings.IncrementValue("NotificationId"); } if (notification.ScheduleDate != null) { await this.repository.Set(notification.Id.ToString(), notification); return; } var toastContent = new ToastContent { Duration = notification.Windows.UseLongDuration ? ToastDuration.Long : ToastDuration.Short, Launch = notification.Payload, ActivationType = ToastActivationType.Background, //ActivationType = ToastActivationType.Foreground, Visual = new ToastVisual { BindingGeneric = new ToastBindingGeneric { Children = { new AdaptiveText { Text = notification.Title }, new AdaptiveText { Text = notification.Message } } } } }; if (!notification.Category.IsEmpty()) { var category = this.registeredCategories.FirstOrDefault(x => x.Identifier.Equals(notification.Category)); var nativeActions = new ToastActionsCustom(); foreach (var action in category.Actions) { switch (action.ActionType) { case NotificationActionType.OpenApp: nativeActions.Buttons.Add(new ToastButton(action.Title, action.Identifier) { //ActivationType = ToastActivationType.Foreground ActivationType = ToastActivationType.Background }); break; case NotificationActionType.None: case NotificationActionType.Destructive: nativeActions.Buttons.Add(new ToastButton(action.Title, action.Identifier) { ActivationType = ToastActivationType.Background }); break; case NotificationActionType.TextReply: nativeActions.Inputs.Add(new ToastTextBox(action.Identifier) { Title = notification.Title //DefaultInput = "", //PlaceholderContent = "" }); break; } } toastContent.Actions = nativeActions; } if (!Notification.CustomSoundFilePath.IsEmpty()) { toastContent.Audio = new ToastAudio { Src = new Uri(Notification.CustomSoundFilePath) } } ; var native = new ToastNotification(toastContent.GetXml()); this.toastNotifier.Show(native); if (notification.BadgeCount != null) { this.Badge = notification.BadgeCount.Value; } await this.services.SafeResolveAndExecute <INotificationDelegate>(x => x.OnReceived(notification)); }
/// <summary> /// 发送通知 /// </summary> protected static void ShowToast(XmlDocument xml) { ToastNotification toast = new ToastNotification(xml); DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }
private static void ShowReminderToast(Reminder reminder) { var toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = reminder.Title }, new AdaptiveText() { Text = reminder.Description } } } }, Actions = new ToastActionsCustom() { Inputs = { new ToastSelectionBox("snoozeTimes") { Title = "Snooze for", Items = { new ToastSelectionBoxItem("5", "5 Minutes"), new ToastSelectionBoxItem("10", "10 Minutes"), new ToastSelectionBoxItem("15", "15 Minutes"), new ToastSelectionBoxItem("30", "30 Minutes") }, DefaultSelectionBoxItemId = "5" } }, Buttons = { new ToastButtonSnooze() { SelectionBoxId = "snoozeTimes" }, new ToastButtonDismiss("Dismiss") } }, //Audio = new ToastAudio() //{ // Src = new Uri("ms-winsoundevent:Notification.Looping.Alarm"), // Loop = true //}, Scenario = ToastScenario.Reminder }; // Create the toast notification var toastNotif = new ToastNotification(toastContent.GetXml()); // And send the notification ToastNotificationManager.CreateToastNotifier().Show(toastNotif); }