/// <summary>
        /// Shows the toast notification.
        /// </summary>
        public async Task Show()
        {
            var builder = new ToastContentBuilder();

            if (AppLogoOverride != null)
            {
                var uri = AppLogoOverride.GetSourceUri() ?? await AppLogoOverride.GetFileUriAsync().ConfigureAwait(false);

                builder.AddAppLogoOverride(uri);
            }

            // Title and Message are required.
            builder.AddText(Title, hintMaxLines: 1)
            .AddText(Message);

            builder.SetToastDuration(ToastDuration == ToastDuration.Short ? UwpNot.ToastDuration.Short : UwpNot.ToastDuration.Long);

            _tcs = new TaskCompletionSource <object>();

            builder.Show(t =>
            {
                TypedEventHandler <Windows.UI.Notifications.ToastNotification, ToastDismissedEventArgs> handler = (sender, args) => { };
                handler = (sender, args) =>
                {
                    sender.Dismissed -= handler;
                    _tcs.SetResult(null);
                };
                t.Dismissed += handler;
            });

            await _tcs.Task;
        }
Exemple #2
0
        public void SetToastDurationTest_WithCustomToastDuration_ReturnSelfWithCustomToastDurationSet()
        {
            // Arrange
            ToastDuration testToastDuration = ToastDuration.Long;

            // Act
            ToastContentBuilder builder          = new ToastContentBuilder();
            ToastContentBuilder anotherReference = builder.SetToastDuration(testToastDuration);

            // Assert
            Assert.AreSame(builder, anotherReference);
            Assert.AreEqual(testToastDuration, builder.Content.Duration);
        }
Exemple #3
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();
        }