/// <summary>
        ///
        /// </summary>
        private void DeleteListViewItem()
        {
            if (this.lvReply.SelectedItems.Count > 0)
            {
                ListViewItem lvi   = this.lvReply.SelectedItems[0];
                int          index = lvi.Index;
                ReplyItem    item  = (ReplyItem)lvi.Tag;

                string msg = Strings.AreYouSureDelete;
                if (NUnit.UiKit.UserMessage.Ask(msg) == DialogResult.Yes)
                {
                    this._replyCollection.Remove(item);
                    lvi.Remove();

                    if (this.lvReply.Items.Count > 0)
                    {
                        if (index >= this.lvReply.Items.Count)
                        {
                            index = this.lvReply.Items.Count - 1;
                        }
                        this.lvReply.SelectedIndices.Clear();
                        this.lvReply.SelectedIndices.Add(index);
                    }
                }
            }
            else
            {
                NUnit.UiKit.UserMessage.DisplayFailure(Strings.SelectListViewItemFirst);
            }
        }
        void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            ListViewItem lvi = e.Item;
            ReplyItem    asi = lvi.Tag as ReplyItem;

            asi.Enabled = lvi.Checked;
        }
        public void ReplyHandlingTest()
        {
            var text = "hello";
            IConversationContext context = new ConversationContext
            {
                Entry = new Entry
                {
                    Message = new Messaging
                    {
                        Message = new EntryMessage
                        {
                            Text = text
                        }
                    }
                },
                Route = new Route()
            };
            var replyItem = new ReplyItem {
                ReplyType = "raw", Reply = new ReplyMessage()
            };

            this.replyConfigurationMock.Setup(x => x.FetchReplyItem(It.IsAny <IConversationContext>())).Returns(Task.FromResult(replyItem));

            this.replyHandler.InvokeAsync(context).Wait();

            this.replyConfigurationMock.Verify(x => x.FetchReplyItem(context), Times.Exactly(1));
            this.replyFactroyMock.Verify(x => x.CreateReplyAsync(context, replyItem), Times.Exactly(1));
        }
        public void ReplyHandlingTest()
        {
            var text = "hello";
            IConversationContext context = new ConversationContext
            {
                Entry = new Entry
                {
                    Message = new Messaging
                    {
                        Message = new EntryMessage
                        {
                            Text = text
                        }
                    }
                },
                Route = new Route()
            };
            var replyItem = new ReplyItem {
                ReplyType = "raw", Reply = new ReplyMessage()
            };

            this.genericExpressionFactoryMock.Setup(x => x.Create(It.Is <string>(s => s == "raw"), builderFactory, context, It.IsAny <string>())).
            Returns(Task.FromResult(new ReplyMessage
            {
                Text = text
            }));

            this.replyFactory.CreateReplyAsync(context, replyItem).Wait();
            var reply = this.replyFactory.CreateReplyAsync(context, replyItem).Result;

            Assert.True(reply.Message.Text == text);
            this.genericExpressionFactoryMock.VerifyAll();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmReplyItem f = new frmReplyItem();

            if (f.ShowDialog() == DialogResult.OK)
            {
                ReplyItem ri = f.ReplyItem;
                this._replyCollection.Add(ri);
                this.AddReplyItemToListView(ri);
                this.lvReply.SelectedIndices.Add(this.lvReply.Items.Count - 1);
            }
        }
        private static IFramework AddBotAction(this IFramework framework, Type replyActionType, string[] routes, bool isDefault, bool isGlobalCommand)
        {
            var replyId   = replyActionType.FullName;
            var replyItem = new ReplyItem
            {
                Routes          = routes,
                ReplyId         = replyId,
                ReplyType       = replyId,
                IsDefault       = isDefault,
                IsGlobalCommand = isGlobalCommand
            };

            framework.AddService(s => s.Service(typeof(ReplyItem)).As(replyItem).Keyed(replyId).Lifetime(Lifetime.Singleton));
            return(AddBotAction(framework, replyActionType, replyId));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="i"></param>
        private void AddReplyItemToListView(ReplyItem ri)
        {
            ListViewItem lvi = new ListViewItem(ri.Name);

            string[] subItems = new string[]
            {
                ri.ReceivedPattern,
                HexStringConverter.Default.ConvertToObject(ri.ReplyBytes).ToString(),
                ri.Description
            };

            lvi.SubItems.AddRange(subItems);
            lvi.Checked = ri.Enabled;
            lvi.Tag     = ri;
            this.lvReply.Items.Add(lvi);
        }
Exemple #8
0
        public void AddConfiguration(ReplyItem replyItem)
        {
            if (!replyItems.ToList().Any(x => x.ReplyId == replyItem.ReplyId))
            {
                replyItems.Add(replyItem);

                replyItem.Routes.ToList().ForEach(x =>
                                                  routingTable.Add(new Route
                {
                    RouteId         = replyItem.ReplyId,
                    RouteText       = x,
                    IsDefault       = replyItem.IsDefault,
                    IsGlobalCommand = replyItem.IsGlobalCommand
                }));
            }
        }
Exemple #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public ReplyCollection Build(string filename)
        {
            ReplyCollection r   = new ReplyCollection();
            XmlDocument     doc = new XmlDocument();

            doc.Load(filename);
            XmlNode root = doc.SelectSingleNode("root");

            foreach (XmlNode n in root.ChildNodes)
            {
                XmlElement e    = n as XmlElement;
                ReplyItem  item = Build(e);
                r.Add(item);
            }
            return(r);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnModify_Click(object sender, EventArgs e)
        {
            if (this.lvReply.SelectedItems.Count > 0)
            {
                ListViewItem lvi = this.lvReply.SelectedItems[0];
                ReplyItem    ri  = lvi.Tag as ReplyItem;

                frmReplyItem f = new frmReplyItem(ri);
                if (f.ShowDialog() == DialogResult.OK)
                {
                    lvi.SubItems[0].Text = ri.Name;
                    lvi.SubItems[1].Text = ri.ReceivedPattern;
                    lvi.SubItems[2].Text = HexStringConverter.Default.ConvertToObject(ri.ReplyBytes).ToString();
                    lvi.SubItems[3].Text = ri.Description;
                }
            }
            else
            {
                NUnit.UiKit.UserMessage.DisplayFailure(Strings.SelectListViewItemFirst);
            }
        }
        public frmReplyItem(ReplyItem replyItem)
        {
            if (replyItem == null)
            {
                throw new ArgumentNullException("replyItem");
            }

            InitializeComponent();
            this.ReplyItem = replyItem;
            this.IsEdit    = true;

            this.txtName.Text        = this.ReplyItem.Name;
            this.txtReceived.Text    = this.ReplyItem.ReceivedPattern;
            this.txtReply.Text       = HexStringConverter.Default.ConvertToObject(this.ReplyItem.ReplyBytes).ToString();
            this.txtDescription.Text = this.ReplyItem.Description;

            string s = string.Format(
                "{0} - {1}",
                this.Text,
                Strings.Edit);
        }
Exemple #12
0
        public async Task <Reply> CreateReplyAsync(IConversationContext conversationContext, ReplyItem replyItem)
        {
            var replyItemText = replyItem.Reply?.ToString();
            var message       = await(Task <ReplyMessage>) this.genericExpressionFactory.Create(replyItem.ReplyType, replyBuilders, conversationContext, replyItemText);

            return(new Reply
            {
                Recipient = new Recipient {
                    Id = conversationContext?.Entry?.Message?.Sender?.Id
                },
                NotificationType = replyItem.NotificationType,
                SenderAction = replyItem.SenderAction,
                Message = message
            });
        }