Exemplo n.º 1
0
        private void CreateToastButton_Click(object sender, EventArgs e)
        {
            var actionButton = new ToastButton();

            actionButton.AddArgument("action", "buttonAction");
            actionButton.SetContent("Action Button");

            var dismissButton = new ToastButton();

            dismissButton.SetContent("Dismiss Button");
            dismissButton.SetDismissActivation();

            var toast = new ToastContentBuilder();

            toast.AddAttributionText("Attribute Text");
            toast.AddText("Title");
            toast.AddText("Text 1");
            toast.AddText("Text 2");
            toast.AddButton(actionButton);
            toast.AddButton(dismissButton);
            toast.Show(toast =>
            {
                toast.ExpirationTime = DateTime.Now.AddSeconds(5);
                toast.Priority       = Windows.UI.Notifications.ToastNotificationPriority.High;
            });
        }
Exemplo n.º 2
0
        public void AddAttributionTextTest_WithSimpleText_ReturnSelfWithCustomAttributionTextAdded()
        {
            // Arrange
            string testAttributionText = "Test Attribution Text";

            // Act
            ToastContentBuilder builder          = new ToastContentBuilder();
            ToastContentBuilder anotherReference = builder.AddAttributionText(testAttributionText);

            // Assert
            Assert.AreSame(builder, anotherReference);
            Assert.AreEqual(testAttributionText, builder.Content.Visual.BindingGeneric.Attribution.Text);
        }
Exemplo n.º 3
0
        public void Show(NotificationData data)
        {
            var toast = new ToastContentBuilder().SetToastScenario(ToastScenario.Default)
                        .AddText(RemoveInvalidXmlChars(data.Title), AdaptiveTextStyle.Title)
                        .AddText(RemoveInvalidXmlChars(data.Content));

            if (!string.IsNullOrEmpty(data.Image))
            {
                toast.AddAppLogoOverride(new Uri(data.Image));
            }

            if (!string.IsNullOrEmpty(data.Attribution))
            {
                toast.AddAttributionText(RemoveInvalidXmlChars(data.Attribution));
            }
            var result = toast.Content;

            ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(result.GetXml()));
        }
Exemplo n.º 4
0
        private void OnRafflesWon(object sender, RafflesWonArgs e)
        {
            bool enableToast = Properties.UserConfig.Default.ToastNotifications;

            if (enableToast)
            {
                string logo = Files.LogoFile;
                if (!File.Exists(logo))
                {
                    using (var http = new HttpClient())
                    {
                        string url  = string.Format("https://scrap.tf/apple-touch-icon.png?{0}", Guid.NewGuid());
                        byte[] data = http.GetByteArrayAsync(url).Result;
                        File.WriteAllBytes(logo, data);
                    }
                }

                string message    = e.Message;
                var    viewButton = new ToastButton();
                viewButton.AddArgument("action", "viewRafflesWonPage");
                viewButton.SetContent("View Won Raffles");

                var dismissButton = new ToastButton();
                dismissButton.SetContent("Dismiss");
                dismissButton.SetDismissActivation();

                var toast = new ToastContentBuilder();
                toast.AddAppLogoOverride(new Uri(logo), ToastGenericAppLogoCrop.Circle, null, false);
                toast.AddAttributionText(string.Format("Scraps {0}", Common.Constants.Version.Full));
                toast.AddText("Items Need Withdrawing");
                toast.AddText(message);
                toast.AddButton(viewButton);
                toast.AddButton(dismissButton);
                toast.Show();
            }
        }
Exemplo n.º 5
0
 public IUwpExtension AddAttributionText(string text, string?language = null)
 {
     tbc.AddAttributionText(text, language);
     return(this);
 }
Exemplo n.º 6
0
        public void checkChanges()
        {
            bool   blPaused       = NotificationsPaused();
            string strDocsChanged = "";

            tmrCheck.Stop();
            log("Checking changes", 5);
            if (credential == null)
            {
                getCredentials();
            }

            // Create Drive API service.
            var service = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            // List files.
            FilesResource.ListRequest listRequest = service.Files.List();
            listRequest.Fields = "nextPageToken, files(id, name, lastModifyingUser(displayName), modifiedTime, parents, trashed, webViewLink)";

            var response = listRequest.Execute();
            IList <Google.Apis.Drive.v3.Data.File> files = response.Files;

            Console.WriteLine("Files:");

            //List<ToastContentBuilder> lstToasts = new List<ToastContentBuilder>();
            string strDocChangeKey = "";

            if (files != null && files.Count > 0)
            {
                foreach (var file in files)
                {
                    FileState fileState = null;
                    if (driveState.FileStates.ContainsKey(file.Id))
                    {
                        fileState = driveState.FileStates[file.Id];
                    }

                    // Determine if we know who last edited the file
                    string lastEditBy = "Unknown";
                    if (file.LastModifyingUser != null && file.LastModifyingUser.DisplayName != null)
                    {
                        lastEditBy = file.LastModifyingUser.DisplayName;
                    }

                    bool blnShowToast = (fileState == null || file.ModifiedTime > fileState.lastEditWhen.AddSeconds(Properties.Settings.Default.CheckSeconds * 5) || fileState.lastEditBy != lastEditBy);
                    updateFileState(file);

                    if (file.ModifiedTime > datLast && !excludedFiles.ContainsKey(file.Id) && Properties.Settings.Default.MyName != lastEditBy)
                    {
                        // If this is a new file or the file hasn't been edited in a while or the file has been edited by someone new then notify
                        if (blnShowToast && !blPaused)
                        {
                            // Build the basic toast config
                            ToastContentBuilder tst = new ToastContentBuilder()
                                                      .AddArgument("action", "viewFile")
                                                      .AddArgument("fileId", file.Id)
                                                      .AddArgument("url", file.WebViewLink)
                                                      .AddText(file.Name);

                            // Set the toast duration based on settings.
                            if (Properties.Settings.Default.LongNotification)
                            {
                                tst = tst.SetToastDuration(ToastDuration.Long);
                            }
                            else
                            {
                                tst = tst.SetToastDuration(ToastDuration.Short);
                            }

                            // Try and set the EditBy and modified time.
                            try
                            {
                                tst = tst.AddCustomTimeStamp((DateTime)file.ModifiedTime);
                                if (file.ModifiedTime.Value.Date == DateTime.Now.Date)
                                {
                                    tst = tst.AddAttributionText(lastEditBy + " @ " + string.Format("{0:HH:mm}", file.ModifiedTime.Value));
                                }
                                else
                                {
                                    tst = tst.AddAttributionText(lastEditBy + " @ " + string.Format("{0:HH:mm dd/MM/yyyy}", file.ModifiedTime.Value));
                                }
                            }
                            catch (Exception)
                            {
                                // We failed so just set the EditBy
                                tst = tst.AddAttributionText(lastEditBy);
                            }

                            // Display the toast
                            tst.Show();
                        }
                        //lstToasts.Add(tst);

                        strDocChangeKey += file.Name + "|" + lastEditBy + "|";
                        if (file.Name.Length > 35)
                        {
                            strDocsChanged += file.Name.Substring(0, 34) + Environment.NewLine;
                        }
                        else
                        {
                            strDocsChanged += file.Name + Environment.NewLine;
                        }
                        setIcon("red");
                    }
                    log(file.Name, 10);
                }
            }
            else
            {
                log("No files found.", 10);
            }
            if (strDocChangeKey != "")
            {
                if (Properties.Settings.Default.WindowsNotifications && strDocChangeKey != strLastTip)
                {
                    strLastTip = strDocChangeKey;
                    //foreach (ToastContentBuilder tst in lstToasts)
                    //{
                    //    tst.Show();
                    //}
                }
                if (strDocsChanged.Length > 64)
                {
                    nfyIcon.Text = strDocsChanged.Substring(0, 63);
                }
                else
                {
                    nfyIcon.Text = strDocsChanged;
                }
            }
            else
            {
                strLastTip   = "";
                nfyIcon.Text = "No changes";
            }
            saveState();
            showFiles();
            tmrCheck.Interval = Properties.Settings.Default.CheckSeconds * 1000;
            tmrCheck.Start();
        }