Exemplo n.º 1
0
        /// <summary>
        /// Handles showing the MOTD if necessary.
        /// </summary>
        /// <param name="e"></param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            MessageOfTheDay motd = ViewModel.RequestMotd();

            if (motd.ShouldDisplay)
            {
                ContentDialog motdDialog = new ContentDialog
                {
                    Title = motd.Title,

                    Content = motd.Body,

                    PrimaryButtonText      = motd.DismissText,
                    IsPrimaryButtonEnabled = true,
                    PrimaryButtonCommand   = new TypedCommand <ContentDialog>(d => d.Hide()),
                };

                motdDialog.PrimaryButtonCommandParameter = motdDialog;
                motdDialog.Style = (Style)Resources["ScrollableContentDialogStyle"];

                await motdDialog.ShowAsync();
            }
        }
        public void TestShowMessage()
        {
            MessageOfTheDay message = new MessageOfTheDay();

            Assert.Equal("If debugging is the process of removing software bugs, " +
                         "then programming must be the process of putting them in.\n" +
                         "\tBy \"Edsger Dijkstra\"", message.ShowMessage());
        }
Exemplo n.º 3
0
        public async void CheckForUpdates()
        {
            // Don't check from the background
            if (m_baconMan.IsBackgroundTask)
            {
                return;
            }

            // Check if we should update
            TimeSpan timeSinceLastUpdate = DateTime.Now - LastUpdate;

            if (timeSinceLastUpdate.TotalHours > c_minHoursBetweenCheck)
            {
                // Get the new message
                MessageOfTheDay newMotd = await GetNewMessage();

                // Make sure everything went well
                if (newMotd != null)
                {
                    // Check for an update
                    if (LastMotd == null || !newMotd.UniqueId.Equals(LastMotd.UniqueId))
                    {
                        // Get the current package version.
                        PackageVersion curVer = Package.Current.Id.Version;

                        // There is an update! If we have a version number in the MOTD make sure we are >= the min.
                        if ((newMotd.MinVerMajor == 0) ||
                            (curVer.Major >= newMotd.MinVerMajor && curVer.Minor >= newMotd.MinVerMinor && curVer.Build >= newMotd.MinVerBuild && curVer.Revision >= newMotd.MinVerRev))
                        {
                            // Make sure we have been opened enough.
                            if (m_baconMan.UiSettingsMan.AppOpenedCount > newMotd.MinOpenTimes)
                            {
                                if (!newMotd.isIngore)
                                {
                                    // Show the message!
                                    // We need to loop because sometimes we can get the message faster than the UI is even ready.
                                    // When the UI isn't ready the function will return false. So just sleep until we can show it.
                                    bool showSuccess = false;
                                    while (!showSuccess)
                                    {
                                        showSuccess = m_baconMan.ShowMessageOfTheDay(newMotd.Title, newMotd.MarkdownContent);

                                        if (!showSuccess)
                                        {
                                            await Task.Delay(500);
                                        }
                                    }
                                }

                                // Update the message and last updated time
                                LastUpdate = DateTime.Now;
                                LastMotd   = newMotd;
                            }
                        }
                    }
                }
            }
        }
        private string ParseMessage(string s)
        {
            var motd = MessageOfTheDay.GetDashes();

            return(s
                   .Replace("<br>", motd)
                   .Replace("!", "\\!")
                   .Replace(".", "\\.")
                   .Replace("(", "\\(")
                   .Replace(")", "\\)")
                   .Replace("-", "\\-"));
        }
Exemplo n.º 5
0
        public async void GetMessageByDayRepository_WrongInput_ShouldReturnNull()
        {
            //Given
            var             iEDaysRepository = _helpers.GenerateFakeEDaysRepository();
            MessageOfTheDay returnValue      = null;

            var model = _helpers.CreateMessageOfTheDayList()
                        .Where(d => d.Day == "monday")
                        .FirstOrDefault();
            var c = A.CallTo(() => iEDaysRepository.GetMessageByDay("SomeData")).Returns(returnValue);

            //When
            var response = await iEDaysRepository.GetMessageByDay("SomeData");

            //Then
            Assert.Null(response);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Loads class from a dictionary object (provided by JSON)
        /// </summary>
        /// <param name="obj">A dictionary object</param>
        /// <exception cref="eduJSON.InvalidParameterTypeException">Incorrect parameter <paramref name="obj"/> type</exception>
        public void Load(object obj)
        {
            if (obj is List <object> obj2)
            {
                Clear();

                // Parse all mesages listed. Don't do it in parallel to preserve the sort order.
                foreach (var el in obj2)
                {
                    var el2 = (Dictionary <string, object>)el;

                    // Parse message type.
                    Message message = null;
                    if (eduJSON.Parser.GetValue(el2, "type", out string type))
                    {
                        switch (type.ToLower())
                        {
                        case "motd": message = new MessageOfTheDay(); break;

                        case "maintenance": message = new MessageMaintenance(); break;

                        default: message = new MessageNotification(); break;     // Assume notification type on all other values.
                        }
                    }
                    else
                    {
                        message = new MessageNotification();
                    }

                    // Load and add message.
                    message.Load(el);
                    Add(message);
                }
            }
            else
            {
                throw new eduJSON.InvalidParameterTypeException(nameof(obj), typeof(List <object>), obj.GetType());
            }
        }
Exemplo n.º 7
0
        public void WriteTo(NetBinaryWriter writer)
        {
            bool isBeta = IsBeta;

            void WriteField(string value, bool delimit = true)
            {
                writer.WriteRaw(value);
                if (delimit)
                {
                    writer.Write((short)(isBeta ? '§' : 0)); // null char delimeter
                }
            }

            writer.Write((byte)0xff);
            writer.Write((short)0); // reserved space for message length

            long startPos = writer.Position;

            if (!isBeta)
            {
                WriteField("§1");
                WriteField(ProtocolVersion.ToString());
                WriteField(MinecraftVersion.ToString());
            }
            WriteField(MessageOfTheDay.ToString());
            WriteField(CurrentPlayerCount.ToString());
            WriteField(MaxPlayers.ToString(), delimit: false);

            int byteLength          = (int)(writer.Position - startPos);
            int reservedSpaceOffset = (int)(startPos - sizeof(short));

            long endPosition = writer.Position;

            writer.Seek(reservedSpaceOffset, SeekOrigin.Begin);
            writer.Write((short)(byteLength / sizeof(char)));

            writer.Seek((int)endPosition, SeekOrigin.Begin);
        }
Exemplo n.º 8
0
        public async Task CheckForUpdates()
        {
            // Don't check from the background
            if (m_baconMan.IsBackgroundTask)
            {
                return;
            }

            // The current app version.
            PackageVersion curAppVersion = Package.Current.Id.Version;

            // Check if the current version of the app is larger than the version we
            // last checked on. (meaning we were updated)
            bool forceUpdateDueAppVersion = false;

            if (LastVersionCheckedOn == null || LastVersionCheckedOn.Major < curAppVersion.Major || LastVersionCheckedOn.Minor < curAppVersion.Minor || LastVersionCheckedOn.Build < curAppVersion.Build || LastVersionCheckedOn.Revision < curAppVersion.Revision)
            {
                forceUpdateDueAppVersion = true;
            }

            // Check if we should update
            TimeSpan timeSinceLastUpdate = DateTime.Now - LastUpdate;

            if (timeSinceLastUpdate.TotalHours > c_minHoursBetweenCheck || forceUpdateDueAppVersion)
            {
                // Get the new message
                MessageOfTheDay newMotd = await GetNewMessage();

                // Make sure everything went well
                if (newMotd != null)
                {
                    // Since we successfully got a MOTD update the last update time
                    // and app version.
                    LastUpdate           = DateTime.Now;
                    LastVersionCheckedOn = new AppVersion()
                    {
                        Major    = curAppVersion.Major,
                        Minor    = curAppVersion.Minor,
                        Build    = curAppVersion.Build,
                        Revision = curAppVersion.Revision
                    };

                    // Check for a difference
                    if (LastMotd == null || !newMotd.UniqueId.Equals(LastMotd.UniqueId))
                    {
                        // There is an update! If we have a version number in the MOTD make sure we are >= the min.
                        if ((newMotd.MinVerMajor == 0) ||
                            (curAppVersion.Major >= newMotd.MinVerMajor && curAppVersion.Minor >= newMotd.MinVerMinor && curAppVersion.Build >= newMotd.MinVerBuild && curAppVersion.Revision >= newMotd.MinVerRev))
                        {
                            // Make sure we have been opened enough.
                            if (m_baconMan.UiSettingsMan.AppOpenedCount > newMotd.MinOpenTimes)
                            {
                                if (!newMotd.isIgnore)
                                {
                                    // Show the message!
                                    // We need to loop because sometimes we can get the message faster than the UI is even ready.
                                    // When the UI isn't ready the function will return false. So just sleep until we can show it.
                                    bool showSuccess = false;
                                    while (!showSuccess)
                                    {
                                        showSuccess = m_baconMan.ShowMessageOfTheDay(newMotd.Title, newMotd.MarkdownContent);

                                        if (!showSuccess)
                                        {
                                            await Task.Delay(500);
                                        }
                                    }
                                }

                                // Update that we have processed this newest MOTD.
                                LastMotd = newMotd;
                            }
                        }
                    }
                }
            }
        }