Exemple #1
0
        public void SendEventTileNotification(EventTileModel etm)
        {
            var content = new TileBindingContentAdaptive();
            TileGroup firstGroup = new TileGroup();

            TileSubgroup sgroup = new TileSubgroup();
            sgroup.Weight = 22;
            TileImage imgOrganizer = new TileImage();
            var uriImageOrganizer = etm.OrganizerImageAbsoluteUri;

            if (string.IsNullOrEmpty(uriImageOrganizer))
                uriImageOrganizer = unknownPersonImageUri.AbsoluteUri;

            imgOrganizer.Source = new TileImageSource(uriImageOrganizer);
            sgroup.Children.Add(imgOrganizer);
            firstGroup.Children.Add(sgroup);

            sgroup = new TileSubgroup();
            TileText organizerName = new TileText();
            organizerName.Text = etm.OrganizerName;
            sgroup.Children.Add(organizerName);
            TileText timeEvent = new TileText();
            timeEvent.Text = etm.TimeDelta;
            timeEvent.Style = TileTextStyle.CaptionSubtle;
            sgroup.Children.Add(timeEvent);
            TileText eventBdy = new TileText();
            eventBdy.Text = etm.Subject;
            sgroup.Children.Add(eventBdy);
            firstGroup.Children.Add(sgroup);

            content.Children.Add(firstGroup);

            foreach (var driveItem in etm.Items.Take(2))
            {

                TileGroup secondGroup = new TileGroup();
                sgroup = new TileSubgroup();
                TileImage imgExt = new TileImage();
                imgExt.Source = new TileImageSource(driveItem.IconAbsoluteUri);
                sgroup.Children.Add(imgExt);
                sgroup.Weight = 5;
                secondGroup.Children.Add(sgroup);
                sgroup = new TileSubgroup();
                TileText tt = new TileText();
                tt.Text = driveItem.Title;
                sgroup.Children.Add(tt);
                secondGroup.Children.Add(sgroup);
                content.Children.Add(secondGroup);

            }
            TileContent tileContent = new TileContent()
            {
                Visual = new TileVisual()
                {
                    TileWide = new TileBinding()
                    {
                        Content = content
                    },
                    TileMedium = new TileBinding()
                    {
                        Content = content
                    },
                }
            };
            try
            {
                var tileContentxml = tileContent.ToString();
                TileNotification notification = new TileNotification(tileContent.GetXml());
                TileUpdateManager.CreateTileUpdaterForApplication().Update(notification);

            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemple #2
0
        /// <summary>
        /// Makes sure the main app tile is an icon tile type
        /// </summary>
        public void UpdateMainTile(int unreadCount)
        {
            // Setup the main tile as iconic for small and medium
            TileContent content = new TileContent()
            {
                Visual = new TileVisual()
                {
                    TileSmall = new TileBinding()
                    {
                        Content = new TileBindingContentIconic()
                        {
                            Icon = new TileImageSource("ms-appx:///Assets/AppAssets/IconicTiles/Iconic144.png"),
                        }
                    },
                    TileMedium = new TileBinding()
                    {
                        Content = new TileBindingContentIconic()
                        {
                            Icon = new TileImageSource("ms-appx:///Assets/AppAssets/IconicTiles/Iconic200.png"),
                        }
                    },                    
                }
            };

            // If the user is signed in we will do more for large and wide.
            if(m_baconMan.UserMan.IsUserSignedIn && m_baconMan.UserMan.CurrentUser != null && !String.IsNullOrWhiteSpace(m_baconMan.UserMan.CurrentUser.Name))
            {
                content.Visual.TileWide = new TileBinding()
                {
                    Content = new TileBindingContentAdaptive()
                    {
                        Children =
                        {
                            new TileText()
                            {
                                Text = m_baconMan.UserMan.CurrentUser.Name,
                                Style = TileTextStyle.Caption
                            },
                            new TileText()
                            {
                                Text = String.Format("{0:N0}", m_baconMan.UserMan.CurrentUser.CommentKarma) + " comment karma",
                                Style = TileTextStyle.CaptionSubtle
                            },
                            new TileText()
                            {
                                Text = String.Format("{0:N0}", m_baconMan.UserMan.CurrentUser.LinkKarma) + " link karma",
                                Style = TileTextStyle.CaptionSubtle
                            },                           
                        }
                    },
                };

                // If we have messages replace the user name with the message string.
                if (unreadCount != 0)
                {
                    TileText unreadCountText = new TileText()
                    {
                        Text = unreadCount + " Unread Inbox Message" + (unreadCount == 1 ? "" : "s"),
                        Style = TileTextStyle.Body
                    };
                    ((TileBindingContentAdaptive)content.Visual.TileWide.Content).Children[0] = unreadCountText;
                }

                // Also set the cake day if it is today
                DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime userCreationTime = origin.AddSeconds(m_baconMan.UserMan.CurrentUser.CreatedUtc).ToLocalTime();
                TimeSpan elapsed = DateTime.Now - userCreationTime;
                double fullYears = Math.Floor((elapsed.TotalDays / 365));
                int daysUntil = (int)(elapsed.TotalDays - (fullYears * 365));

                if(daysUntil == 0)
                {
                    // Make the text
                    TileText cakeDayText = new TileText()
                    {
                        Text = "Today is your cake day!",
                        Style = TileTextStyle.Body
                    };
                    ((TileBindingContentAdaptive)content.Visual.TileWide.Content).Children[0] = cakeDayText;
                }
            }  

            // Set large to the be same as wide.
            content.Visual.TileLarge = content.Visual.TileWide;

            // Update the tile
            TileUpdateManager.CreateTileUpdaterForApplication().Update(new TileNotification(content.GetXml()));

            // Update the badge
            BadgeNumericNotificationContent badgeContent = new BadgeNumericNotificationContent();
            badgeContent.Number = (uint)unreadCount;
            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(new BadgeNotification(badgeContent.GetXml()));
        }
Exemple #3
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral _defferal = taskInstance.GetDeferral();
            var appdata = ApplicationData.Current.LocalSettings;
            if (!(bool) (appdata.Values["TileUpdates"] ?? false) && !(bool) (appdata.Values["UseToasts"] ?? false)) // if task isn't needed, kill it
            {
                _defferal.Complete();
                return;
            }

            PasswordVault vault = new PasswordVault();
            PasswordCredential cred;
            try
            {
                cred = vault.FindAllByResource("MYUW").First(); // Make sure this matches CredResName
            }
            catch
            {
                _defferal.Complete();
                return;
            }

            var connector = new MUConnector(cred);
            if (await connector.Login())
            {
                
                //double lastValue = (float)(appdata.Values["LastValue"] ?? -1); //shit's stored as a float...  avoids invalid cast

                float lastValue = -1;

                if (appdata.Values.ContainsKey("LastValue"))
                {
                    float? lv = appdata.Values["LastValue"] as float?; // stupid workarounds for float precision
                    lastValue = lv.Value;
                }
                var hfs = await connector.GetHfsData();
                var term = await connector.GetTermInfo();

                double average = hfs.resident_dining.balance / term.AdjustedDaysRemaining(LoadSavedDates());

                if ((bool)(appdata.Values["TileUpdates"] ?? false))
                {
                    var bindingContent = new TileBindingContentAdaptive();
                    var medBindingContent = new TileBindingContentAdaptive();
                    var items = bindingContent.Children;
                    var medItems = medBindingContent.Children;

                    medItems.Add(new TileText()
                    {
                        Text = $"{hfs.resident_dining.balance:C} remaining",
                        Style = TileTextStyle.Body
                    });

                    items.Add(new TileText()
                    {
                        Text = $"{hfs.resident_dining.balance:C} remaining",
                        Style = TileTextStyle.Subtitle
                    });

                    var line2 = new TileText()
                    {
                        Text = $"{term.AdjustedDaysRemaining(LoadSavedDates())} days",
                        Style = TileTextStyle.Caption
                    };

                    var line3 = new TileText()
                    {            
                        Text = $"${average:0.00} per day",
                        Style = TileTextStyle.Caption
                    };

                    items.Add(line2);
                    items.Add(line3);
                    medItems.Add(line2);
                    medItems.Add(line3);

                    var tileBinding = new TileBinding()
                    {
                        Content = bindingContent,
                        DisplayName = "FoodTile",
                        Branding = TileBranding.NameAndLogo
                    };

                    var medTileBinding = new TileBinding()
                    {
                        Content = medBindingContent,
                        DisplayName = "FoodTile",
                        Branding = TileBranding.NameAndLogo
                    };

                    var content = new TileContent()
                    {
                        Visual = new TileVisual
                        {
                            TileMedium = medTileBinding,
                            TileWide = tileBinding,
                            TileLarge = tileBinding
                        }
                    };

                    var note = new TileNotification(content.GetXml());
                    var updater = TileUpdateManager.CreateTileUpdaterForApplication();

                    updater.Update(note);
                }

                if (hfs.resident_dining.balance != lastValue)
                {
                    if ((bool)(appdata.Values["UseToasts"] ?? false))
                    {
                        var toastContent = new ToastContent()
                        {
                            Visual = new ToastVisual()
                            {
                                TitleText = new ToastText()
                                {
                                    Text = $"Dining Balance ${hfs.resident_dining.balance:0.00}"
                                },
                                BodyTextLine1 = new ToastText()
                                {
                                    Text = $"New daily average ${average:0.00}"
                                },
                                BodyTextLine2 = new ToastText()
                                {
                                    Text = $"{term.AdjustedDaysRemaining(LoadSavedDates())} days remaining in quarter"
                                }
                            }
                        };

                        var note = ToastNotificationManager.CreateToastNotifier();
                        var toast = new ToastNotification(toastContent.GetXml());
                        note.Show(toast);
                    }
                    appdata.Values["LastValue"] = hfs.resident_dining.balance;
                }
            }
            connector.Dispose();
            _defferal.Complete();
        }
 private static void AssertAdaptiveText(string expectedTextXml, TileText text)
 {
     AssertBindingMedium("<binding template='TileMedium'>" + expectedTextXml + "</binding>", new TileBinding()
     {
         Content = new TileBindingContentAdaptive()
         {
             Children =
             {
                 text
             }
         }
     });
 }