コード例 #1
0
        public void AddMessageTest()
        {
            // No messages yet
            _manager.Count.Should().Be(0);
            _tempData.Should().NotContainKey(typeof(MessageManager).FullName);

            _manager.Add(new FlashMessage(Toastr.INFO, "A message"));

            _manager.Count.Should().Be(1);
            _tempData.Should().ContainKey(typeof(MessageManager).FullName);
        }
コード例 #2
0
ファイル: Conversations.cs プロジェクト: Squiggle/Ri0t
        public void TooManyPossibleLocationsPromptsForConfirmation()
        {
            var convo = new MessageManager(ManyResultsGeomock().Object).GetConversation(MyNumber);
            convo.Add("It's all kicking off in Hyde Park!");

            var nextMessage = convo.GetNext();
            Assert.AreEqual("Did you mean Hyde Park, London or Hyde Park, Leeds?", nextMessage);
        }
コード例 #3
0
        public ActionResult AddNewMessage(Message message, string button)
        {
            string           sender     = (string)Session["WriterMail"];
            ValidationResult validation = messageValidator.Validate(message);

            if (button == "draft")
            {
                validation = messageValidator.Validate(message);
                if (validation.IsValid)
                {
                    message.SenderMail  = sender;
                    message.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                    message.IsDraft     = true;
                    messageManager.Add(message);
                    return(RedirectToAction("Draft"));
                }
                else
                {
                    foreach (var item in validation.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }

            else if (button == "send")
            {
                validation = messageValidator.Validate(message);
                if (validation.IsValid)
                {
                    message.SenderMail  = sender;
                    message.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                    message.IsDraft     = false;
                    messageManager.Add(message);
                    return(RedirectToAction("Sendbox"));
                }
                else
                {
                    foreach (var item in validation.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }
            return(View(message));
        }
コード例 #4
0
ファイル: Conversations.cs プロジェクト: Squiggle/Ri0t
        public void NoGeodataInFirstMessagePromptsForMoreInfo()
        {
            var convo = new MessageManager(NoResultsGeomock().Object).GetConversation(MyNumber);
            convo.Add("Hey there");

            var nextMessage = convo.GetNext();
            Assert.AreEqual("Could you tell me where that's happening?", nextMessage);
        }
コード例 #5
0
        public ActionResult NewMessage(Message message, string button)
        {
            string           userEmail = (string)Session["WriterMail"];
            ValidationResult results   = messageValidator.Validate(message);

            if (button == "draft")
            {
                results = messageValidator.Validate(message);
                if (results.IsValid)
                {
                    message.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                    message.SenderMail  = userEmail;
                    message.isDraft     = true;
                    _messageManager.Add(message);
                    return(RedirectToAction("Draft"));
                }
                else
                {
                    foreach (var item in results.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }
            else if (button == "save")
            {
                results = messageValidator.Validate(message);
                if (results.IsValid)
                {
                    message.MessageDate = DateTime.Now;
                    message.SenderMail  = userEmail;
                    message.isDraft     = false;
                    _messageManager.Add(message);
                    return(RedirectToAction("SendBox"));
                }
                else
                {
                    foreach (var item in results.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }
            return(View());
        }
コード例 #6
0
        [HttpPost] //Burası refaktor edilecek şuanlık bu şekide..
        public ActionResult NewMessage(Message message, string parameter)
        {
            ValidationResult results = messageValidator.Validate(message);

            if (parameter == "send")
            {
                if (results.IsValid)
                {
                    message.SenderMail  = "*****@*****.**";
                    message.IsDraft     = false;
                    message.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                    messageManager.Add(message);
                    return(RedirectToAction("Sendbox"));
                }
                else
                {
                    foreach (var item in results.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }

            else if (parameter == "draft")
            {
                if (results.IsValid)
                {
                    message.SenderMail  = "*****@*****.**";
                    message.IsDraft     = true;
                    message.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                    messageManager.Add(message);
                    return(RedirectToAction("Draft"));
                }
                else
                {
                    foreach (var item in results.Errors)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                }
            }

            return(View());
        }
コード例 #7
0
        private void AddFlashMessages(int number)
        {
            if (number <= 0) return;

            var manager = new MessageManager(_htmlHelper.ViewContext.TempData);

            while (number-- >= 0)
            {
                manager.Add(new FlashMessage(Toastr.INFO, $"Message {number}"));
            }
        }
コード例 #8
0
        private void AddFlashMessages(int number)
        {
            if (number <= 0)
            {
                return;
            }

            var manager = new MessageManager(_htmlHelper.ViewContext.TempData);

            while (number-- >= 0)
            {
                manager.Add(new FlashMessage(Toastr.INFO, $"Message {number}"));
            }
        }
コード例 #9
0
ファイル: TreeNode.cs プロジェクト: 6gales/NetworkProgramming
        void AnswerMessage(MessageManager manager, Message message, IPEndPoint sender)
        {
            switch (message.Type)
            {
            case ContentType.ConnectionRequest:                     //accept connection
                if (!_childs.Contains(sender))
                {
                    _childs.Add(sender);
                    manager.Add(sender);

                    if (_childsReserve != null)
                    {
                        manager.SendToOne(new ReserveNodeMessage(_name, _childsReserve), sender);
                    }
                    else
                    {
                        //if node has no parent, elect first child as reserve node
                        _childsReserve = _childs.First();
                    }
                }
                goto default;

            case ContentType.ReceptionConfirmation:
                Guid confirmedID = ((ConfirmationMessage)message).ConfirmedGuid;
                manager.MessageConfirmed(sender, confirmedID);
                break;

            case ContentType.Data:                     //send to all, if received first time
                if (!_messageHistory.Contains(message.GuidProperty))
                {
                    _messageHistory.Add(message.GuidProperty);
                    Console.WriteLine("@{0}: {1}", message.Name, ((DataMessage)message).Data);
                    manager.SendToAllExclude(message, sender);
                }
                goto default;

            case ContentType.ReserveNode:                     //update reserve node
                _reserveNode = ((ReserveNodeMessage)message).ReserveNode.GetIPEndPoint();
                goto default;

            default:
                manager.ConfirmReception(message.GuidProperty, sender);
                break;
            }
        }
コード例 #10
0
        public ActionResult NewMessage(Message p)
        {
            ValidationResult validationResult = messageValidator.Validate(p);

            if (validationResult.IsValid)
            {
                p.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString());
                messageManager.Add(p);
                return(RedirectToAction("Sendbox"));
            }
            else
            {
                foreach (var item in validationResult.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View());
        }
コード例 #11
0
        public ActionResult Compose(Message message)
        {
            ValidationResult result = msgval.Validate(message);

            if (result.IsValid)
            {
                message.MessageDate = DateTime.Now;
                _msgman.Add(message);
                return(RedirectToAction("SendBox"));
            }
            else
            {
                foreach (var item in result.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View());
        }
コード例 #12
0
        public async Task <IActionResult> Add(Message model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                ModelState.AddModelError("", "Błąd dodawania wiadomości");
                return(View(model));
            }

            model.User = user;

            await _messageManager.Add(model);

            return(RedirectToAction("Index"));
        }
コード例 #13
0
        public ActionResult NewMessage(Message message)
        {
            string sender = (string)Session["WriterMail"];

            ValidationResult results = messageValidator.Validate(message);

            if (results.IsValid)
            {
                message.SenderMail  = sender;
                message.MessageDate = DateTime.Parse(DateTime.Now.ToShortDateString().ToString());
                messageManager.Add(message);
                return(RedirectToAction("SendBox"));
            }
            else
            {
                foreach (var item in results.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View());
        }
コード例 #14
0
        /// <summary>
        /// Finds local bluetooth device, discover other devices in neighborhood
        /// and tries pairing with first device found
        /// </summary>
        private async void Connect()
        {
            BluetoothEx.DeviceManager dm = new BluetoothEx.DeviceManager();
            MessageManager            mm = new MessageManager(this.TBMessages, this.progressBar1);

            try
            {
                this.BtnConnect.Enabled = false;

                var radio = dm.GetPrimaryDevice();
                if (radio == null)
                {
                    MessageBox.Show("Bluetooh device not found");
                    return;
                }

                // this device
                mm.Add("Status", radio.HardwareStatus.ToString());
                var mac = radio.LocalAddress;
                mm.Add("Mac", mac.ToString());

                #region Discovery

                // discover devices using non blocking call
                AddBeforeMessage(mm, "Discovering devices...");

                List <BluetoothDeviceInfo> radios = await dm.DiscoverAll();

                // show result
                mm.EndProgress();
                mm.Add($"Found {radios.Count} device(s)");
                radios.ForEach(r => mm.Add(r.DeviceName, r.DeviceAddress.ToString()));
                #endregion

                #region Pairing
                // attempt pairing with first device in the list
                if (radios.Count > 0)
                {
                    BluetoothDeviceInfo btInfo = radios[0];
                    BluetoothAddress    addr   = new BluetoothAddress(btInfo.DeviceAddress.ToByteArray());

                    AddBeforeMessage(mm, $"Initiating pairing with {btInfo.DeviceName}...");

                    // perform pairing task
                    var paired = await dm.PairDevice(addr);

                    mm.EndProgress();
                    var successPrefix = paired ? "" : "un";
                    mm.Add($"Pairing was {successPrefix}successful.");
                }
                else
                {
                    mm.Add($"Pairing was skipped.");
                }
                #endregion
            }
            catch (Exception)
            {
            }
            finally
            {
                this.BtnConnect.Enabled = true;
            }
        }
コード例 #15
0
        /// <summary>
        /// Adds a Toastr notification of the specified severity to be displayed on page load.
        /// </summary>
        /// <param name="controller">The controller to extend.</param>
        /// <param name="severity">The message severity.</param>
        /// <param name="title">The message title.</param>
        /// <param name="message">The message text.</param>
        /// <param name="options">The message options.</param>
        public static void Flash(this Controller controller, Toastr severity, string title, string message, object options)
        {
            var messages = new MessageManager(controller.TempData);

            messages.Add(new FlashMessage(severity, title, message, options));
        }
コード例 #16
0
        /// <summary>
        /// Adds a Toastr notification of the specified severity to be displayed on page load.
        /// </summary>
        /// <param name="controller">The controller to extend.</param>
        /// <param name="severity">The message severity.</param>
        /// <param name="message">The message text.</param>
        public static void Flash(this Controller controller, Toastr severity, string message)
        {
            var messages = new MessageManager(controller.TempData);

            messages.Add(new FlashMessage(severity, message));
        }
コード例 #17
0
 /// <summary>
 /// 接收消息事件处理方法
 /// </summary>
 /// <param name="sender">触发事件对象</param>
 /// <param name="e">参数</param>
 private void ReceiveEvent(object sender, ProtocalData e)
 {
     msgManager.Add(e);
 }
コード例 #18
0
 /// <summary>
 /// Adds a Toastr notification of the specified severity to be displayed on page load.
 /// </summary>
 /// <param name="controller">The controller to extend.</param>
 /// <param name="severity">The message severity.</param>
 /// <param name="message">The message text.</param>
 public static void Flash(this Controller controller, Toastr severity, string message)
 {
     var messages = new MessageManager(controller.TempData);
     messages.Add(new FlashMessage(severity, message));
 }
コード例 #19
0
 /// <summary>
 /// Adds a Toastr notification of the specified severity to be displayed on page load.
 /// </summary>
 /// <param name="controller">The controller to extend.</param>
 /// <param name="severity">The message severity.</param>
 /// <param name="title">The message title.</param>
 /// <param name="message">The message text.</param>
 /// <param name="options">The message options.</param>
 public static void Flash(this Controller controller, Toastr severity, string title, string message, object options)
 {
     var messages = new MessageManager(controller.TempData);
     messages.Add(new FlashMessage(severity, title, message, options));
 }
コード例 #20
0
 public void Post([FromBody] Message value)
 {
     _repo.Add(value);
 }