Beispiel #1
0
        public async Task ExecuteAsync(MessageOption messageOption, ISonicIngestConnection sonicIngestConnection)
        {
            List <long> Users;

            if (GroupUser.TryGetValue(messageOption.UserId, out Users))
            {
                try {
                    foreach (var e in Users)
                    {
                        var i = 0;
                        foreach (var s in SplitWords(messageOption.Content))
                        {
                            if (!string.IsNullOrEmpty(s))
                            {
                                var tmp = i++.ToString();
                                await sonicIngestConnection.PushAsync(e.ToString(), Env.SonicCollection, $"{messageOption.ChatId}:{messageOption.MessageId}:{tmp}", s);
                            }
                        }
                    }
                } catch (AssertionException exception) {
                    await Send.Log($"{messageOption.ChatId}:{messageOption.MessageId}\n{messageOption.Content}");

                    await Send.Log(exception.ToString());

                    Console.Error.WriteLine(exception);
                }

                //await Cache.SetAsync(
                //    $"{messageOption.ChatId}:{messageOption.MessageId}",
                //    Encoding.UTF8.GetBytes(messageOption.Content.Replace("\n", " ")),
                //    new DistributedCacheEntryOptions { });
            }
        }
Beispiel #2
0
        /// <summary>
        /// 子控件事件回调处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="ms"></param>
        protected virtual object ChileEventCallBack(Object sender, MouseState ms, XObjectData data = null)
        {
            switch (ms)
            {
            case MouseState.XUpdatePropertyData:
                XAribute bute = sender as XAribute;
                if (bute != null)
                {
                    //更新数据
                    bute.ProjectUseClassType = ProjectUseClassType;
                }
                break;

            case MouseState.XUpdateTreeViewData:
                PicTabPage page = sender as PicTabPage;
                if (page != null && (data.data as PicFunctionTabPage) != null)
                {
                    MessageOption option = XObject.MessageOptionTypeMapping(data.additional_Information.ToString());
                    if (option == MessageOption.Add)
                    {
                        ///更新函数
                        AddPicFunctionToPicData(page, data.data as PicFunctionTabPage);
                    }
                    else if (option == MessageOption.Update)
                    {
                        UpdatePicFunctionToPicData(page, data.data as PicFunctionTabPage);
                    }
                }
                break;
            }
            return(null);
        }
        public async Task <ActionResult <MessageOption> > UpdateOption(int id, MessageOption option)
        {
            if (!AuthenticateEditor())
            {
                return(Unauthorized("Sorry you don't have the permission to create or edit is resource"));
            }
            if (id != option.Id)
            {
                return(BadRequest());
            }
            _context.Entry(option).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!await OptionExists(id))
                {
                    return(NotFound());
                }
                throw;
            }

            return(option);
        }
Beispiel #4
0
 private static async Task OnDismiss(MessageOption option)
 {
     if (option.OnDismiss != null)
     {
         await option.OnDismiss();
     }
 }
Beispiel #5
0
        public MessageHost(MessageOption messageOption, ILoggerFactory loggerFactory)
        {
            messageOption.VerifyNotNull(nameof(messageOption));
            loggerFactory.VerifyNotNull(nameof(loggerFactory));

            _messageOption = messageOption;
            _loggerFactory = loggerFactory;
        }
Beispiel #6
0
        public static void Verify(this MessageOption subject)
        {
            subject.VerifyNotNull(nameof(subject));

            subject.Nodes
            .VerifyNotNull(nameof(subject.Nodes))
            .VerifyAssert(x => x.Count > 0, "Nodes are empty");

            subject.Nodes.ForEach(x => x.Verify());
        }
Beispiel #7
0
        public ICheckLogic <T> Fails(string error, MessageOption noCheckedBlock)
        {
            this.failed = true;
            if (!this.IsNegated)
            {
                this.lastError = error;
                this.options   = this.options | noCheckedBlock;
            }

            return(this);
        }
Beispiel #8
0
        public ICheckLogic <T> Fail(string error, MessageOption options)
        {
            this.failed = true;
            if (this.IsNegated)
            {
                return(this);
            }

            this.lastError = error;
            this.options  |= options;
            return(this);
        }
Beispiel #9
0
        public ICheckLogic <T> Negates(string message, MessageOption option)
        {
            if (this.negatedFailed)
            {
                return(this);
            }

            this.negatedError  = message;
            this.negatedFailed = true;
            this.negatedOption = option;
            return(this);
        }
Beispiel #10
0
        private static IEnumerable <string> GetMessageOptions(SupportedLanguage userPreferedLangue, Message messageToSend, MessageOption extraMessageOptions)
        {
            MessageOption combinedOptions = MessageOption.CombineOptions(messageToSend?.Options, extraMessageOptions);

            switch (userPreferedLangue)
            {
            case SupportedLanguage.English:
                return(combinedOptions?.English);

            case SupportedLanguage.Arabic:
                return(combinedOptions?.Arabic);

            default:
                return(combinedOptions?.English);
            }
        }
        public async Task <ActionResult <MessageOption> > CreateOption(MessageOption option)
        {
            if (!AuthenticateEditor())
            {
                return(Unauthorized("Sorry you don't have the permission to create or edit is resource"));
            }
            if (option == null || await OptionExists(option.Id))
            {
                return(BadRequest());
            }

            _context.MessageOptions.Add(option);
            await _context.SaveChangesAsync();

            return(option);
        }
Beispiel #12
0
        public ICheckLogic <T> OnNegateWhen(Func <T, bool> predicate, string error, MessageOption negatedOptions)
        {
            if (this.negatedFailed || this.parentNegatedFailed)
            {
                return(this);
            }

            if (predicate(this.fluentSut.Value))
            {
                this.negatedFailed = true;
                this.negatedError  = error;
                this.negatedOption = negatedOptions;
            }

            return(this);
        }
Beispiel #13
0
        public ICheckLogic <T> NegatesIf(Func <T, bool> predicate, string error, MessageOption option)
        {
            if (this.negatedFailed)
            {
                return(this);
            }

            if (predicate(this.value))
            {
                this.negatedFailed = true;
                this.negatedError  = error;
                this.negatedOption = option;
            }

            return(this);
        }
Beispiel #14
0
        public ICheckLogic <T> FailsIf(Func <T, bool> predicate, Func <T, ICheckLogic <T>, string> errorBuilder,
                                       MessageOption noCheckedBlock)
        {
            if (this.failed)
            {
                return(this);
            }

            this.failed = predicate(this.value);
            if (!this.failed || this.IsNegated)
            {
                return(this);
            }

            this.lastError = errorBuilder(this.value, this);
            this.options   = this.options | noCheckedBlock;
            return(this);
        }
        public override async Task StartAsync(ITurnContext turnContext, CancellationToken cancellationToken)
        {
            var formRepresentation = new string[]
            {
                this.ConversationData.ServiceBookingForm.ToLocalizedStrings(this.UserProfile.PreferredLanguage.Value)
            };

            var formValuesStringRepresentation = new MessageOption()
            {
                English = formRepresentation,
                Arabic  = formRepresentation
            };

            await ConversationUtils.SendMessageBasedOnUserPreferredLanguage(
                Constants.Confirmation.ConfirmationMessage,
                this.UserProfile,
                turnContext,
                cancellationToken,
                formattingValues : formValuesStringRepresentation);

            ConversationData.SetWaitingForUserInputFlag(true);
        }
Beispiel #16
0
        private static void InitializeMessage(
            IMessageActivity proactiveMessageActivity,
            SupportedLanguage userPreferedLangue,
            Message messageToSend,
            MessageOption messgeFormattingOptions = null,
            MessageOption ExtraMessageOptions     = null)
        {
            proactiveMessageActivity.Text = GetMessageString(userPreferedLangue, messageToSend, messgeFormattingOptions);
            var messageOptions = GetMessageOptions(userPreferedLangue, messageToSend, ExtraMessageOptions);

            if (messageOptions != null && messageOptions.Any())
            {
                proactiveMessageActivity.SuggestedActions = new SuggestedActions()
                {
                    Actions = messageOptions
                              .Select(option => new CardAction()
                    {
                        Title = option, Type = ActionTypes.ImBack, Value = option
                    })
                              .ToList()
                };
            }
        }
Beispiel #17
0
        /// <summary>
        /// 创建一个函数
        /// </summary>
        /// <param name="Title">函数的名字</param>
        public bool CreatePicFunctionPage(string Title)
        {
            foreach (PicFunctionTabPage fun in ListFunction)
            {
                if (fun.Title == Title)
                {
                    return(false);
                }
            }
            PicFunctionTabPage function = new PicFunctionTabPage(1, this.CallBackFunction, Title);
            ///给函数里面的函数代码创建数据
            ObservableCollection <MyXTreeItem> funcitondata = new ObservableCollection <MyXTreeItem>();

            foreach (MyXTreeItem item in PopContentCode.MyData)
            {
                funcitondata.Add(item);
            }
            ///函数属性更新事件
            function.XAributeChangeMessage = (tcp) =>
            {
                XObjectData tcpmessagedata = new XObjectData(tcp);
                tcpmessagedata.additional_Information = MessageOption.Update.ToString();
                ///消息回调
                MessageUpdateCall(this, MouseState.XUpdateTreeViewData, tcpmessagedata);
            };
            ///绑定数据
            function.PopContentCode.MyData = funcitondata;
            ListFunction.Add(function);
            ///通知更新数据
            MessageOption option      = MessageOption.Add;
            XObjectData   messagedata = new XObjectData(function);

            messagedata.additional_Information = option.ToString();
            MessageUpdateCall(this, MouseState.XUpdateTreeViewData, messagedata);
            return(true);
        }
Beispiel #18
0
    // Load all messages and decisions from the current passage
    public void UpdatePassage(Chat chat)
    {
        if (chat.story)
        {
            foreach (string message in chat.story.GetMessages())
            {
                SendMessage(chat, message);
            }

            // Reset all decisions
            ChatApp.ClearDialogueOptions(chat);

            Decision[] newDecisions = chat.story.GetDecisions();
            foreach (Decision d in newDecisions)
            {
                MessageOption option = ScriptableObject.CreateInstance <MessageOption>();
                option.name    = chat.story.currentPassage.ToString();
                option.chat    = chat;
                option.message = d.message;
                option.id      = d.link;
                ChatApp.AddDialogueOption(option);
            }
        }
    }
Beispiel #19
0
 public ICheckLogic <T> DefineExpectedType(System.Type expectedInstanteType)
 {
     this.expectedKind = ValueKind.Type;
     this.options     |= MessageOption.WithType;
     return(this.DefineExpectedValue(expectedInstanteType, string.Empty, "different from"));
 }
Beispiel #20
0
 /// <summary>
 /// Failing condition
 /// </summary>
 /// <param name="logic"></param>
 /// <param name="predicate">Predicate, returns true if test fails.</param>
 /// <param name="error">Error message on failure</param>
 /// <param name="newOptions"></param>
 /// <returns>Continuation object.</returns>
 public static ICheckLogic <T> FailWhen <T>(this ICheckLogic <T> logic, Func <T, bool> predicate, string error, MessageOption newOptions = MessageOption.None)
 {
     return(logic.Analyze((sut2, test) =>
     {
         if (predicate(sut2))
         {
             test.Fail(error, newOptions);
         }
     }));
 }
Beispiel #21
0
 /// <summary>
 /// Error message for negated checks.
 /// </summary>
 /// <param name="logic">check</param>
 /// <param name="message">Message template to use when check succeeds.</param>
 /// <param name="option"></param>
 /// <typeparam name="T">type of the checked object</typeparam>
 /// <returns>Continuation object.</returns>
 public static ICheckLogic <T> OnNegate <T>(this ICheckLogic <T> logic, string message, MessageOption option = MessageOption.None)
 {
     return(logic.OnNegateWhen(_ => true, message, option));
 }
Beispiel #22
0
 public ICheckLogic <T> DefineExpectedType(System.Type expectedInstanceType)
 {
     this.expectedKind = ValueKind.Type;
     this.options     |= MessageOption.WithType;
     return(this.DefineExpectedValue(new TypeOfInstanceValue(expectedInstanceType), string.Empty, this.doNotNeedNegatedMessage ? "":"different from"));
 }
Beispiel #23
0
 public ICheckLogic <T> FailsIf(Func <T, bool> predicate, string error, MessageOption options)
 {
     return(this.FailsIf(predicate, (x, y) => error, options));
 }
Beispiel #24
0
        public async Task ExecuteAsync(MessageOption messageOption)
        {
            using (var sonicIngestConnection = NSonicFactory.Ingest(Env.SonicHostname, Env.SonicPort, Env.SonicSecret)) {
                await sonicIngestConnection.ConnectAsync();

                var UserIfExists = from s in context.Users
                                   where s.UserId.Equals(messageOption.UserId) && s.GroupId.Equals(messageOption.ChatId)
                                   select s;
                if (UserIfExists.Any())
                {
                }
                else
                {
                    await context.Users.AddAsync(new User()
                    {
                        GroupId = messageOption.ChatId, UserId = messageOption.UserId
                    });
                }

                await context.Messages.AddAsync(new Message()
                {
                    GroupId = messageOption.ChatId, MessageId = messageOption.MessageId, Content = messageOption.Content
                });

                await context.SaveChangesAsync();

                var UsersQuery = from s in context.Users
                                 where s.GroupId.Equals(messageOption.ChatId)
                                 select s.UserId;

                var Users = UsersQuery.ToList();
                Users.Add(messageOption.ChatId);


                try {
                    foreach (var e in Users)
                    {
                        var i = 0;
                        foreach (var s in SplitWords(messageOption.Content))
                        {
                            if (!string.IsNullOrEmpty(s))
                            {
                                var tmp = i++.ToString();
                                await sonicIngestConnection.PushAsync(e.ToString(), Env.SonicCollection, $"{messageOption.ChatId}:{messageOption.MessageId}:{tmp}", s);
                            }
                        }
                    }
                } catch (AssertionException exception) {
                    await Send.Log($"{messageOption.ChatId}:{messageOption.MessageId}\n{messageOption.Content}");

                    await Send.Log(exception.ToString());

                    Console.Error.WriteLine(exception);
                }

                await Cache.SetAsync(
                    $"{messageOption.ChatId}:{messageOption.MessageId}",
                    Encoding.UTF8.GetBytes(messageOption.Content.Replace("\n", " ")),
                    new DistributedCacheEntryOptions { });
            }
        }
Beispiel #25
0
 public static MessageEngine MessageEngineWithOption(MessageOption messageOption) => androidJavaClass.CallStaticAsWrapper <MessageEngine>("getMessageEngine", AndroidContext.ApplicationContext, messageOption);
Beispiel #26
0
        public static async Task SendMessageBasedOnUserPreferredLanguage(
            Message message,
            UserData userProfile,
            ITurnContext turnContext,
            CancellationToken cancellationToken,
            MessageOption extraOptions     = null,
            MessageOption formattingValues = null)
        {
            var allOptions = MessageOption.CombineOptions(message.Options, extraOptions);

            if (message.IsLanguageIndependent || userProfile.PreferredLanguage == null)
            {
                var options     = allOptions?.CombineLanguagesOptions();
                var messageText = message.English;
                if (formattingValues?.English != null && formattingValues.English.Any())
                {
                    messageText = string.Format(messageText, formattingValues.English);
                }

                if (options != null && options.Count() > 0)
                {
                    await SendMessageWithOptions(messageText, turnContext, cancellationToken, options);
                }
                else
                {
                    await SendMessage(messageText, turnContext, cancellationToken);
                }
            }
            else if (userProfile.PreferredLanguage.Value == SupportedLanguage.Arabic)
            {
                var messageText = message.Arabic;
                if (formattingValues?.Arabic != null && formattingValues.Arabic.Any())
                {
                    messageText = string.Format(messageText, formattingValues.Arabic);
                }

                if (allOptions?.Arabic != null && allOptions.Arabic.Count() > 0)
                {
                    await SendMessageWithOptions(messageText, turnContext, cancellationToken, allOptions.Arabic);
                }
                else
                {
                    await SendMessage(messageText, turnContext, cancellationToken);
                }
            }
            else if (userProfile.PreferredLanguage.Value == SupportedLanguage.English)
            {
                var messageText = message.English;
                if (formattingValues?.English != null && formattingValues.English.Any())
                {
                    messageText = string.Format(messageText, formattingValues.English);
                }

                if (allOptions?.English != null && allOptions.English.Count() > 0)
                {
                    await SendMessageWithOptions(messageText, turnContext, cancellationToken, allOptions.English);
                }
                else
                {
                    await SendMessage(messageText, turnContext, cancellationToken);
                }
            }
            else
            {
                // TODO:- Telemtry for invalid state
            }
        }
Beispiel #27
0
 public static extern int zmq_msg_get(this message msg, MessageOption option);
Beispiel #28
0
        private static string GetMessageString(SupportedLanguage userPreferedLangue, Message messageToSend, MessageOption messgeOptions)
        {
            switch (userPreferedLangue)
            {
            case SupportedLanguage.English:
                return(GetMessageString(messageToSend.English, messgeOptions?.English));

            case SupportedLanguage.Arabic:
                return(GetMessageString(messageToSend.Arabic, messgeOptions?.Arabic));

            default:
                return(GetMessageString(messageToSend.English, messgeOptions?.English));
            }
        }
Beispiel #29
0
 public static extern Result zmq_msg_set(this message msg, MessageOption option, int optval);
Beispiel #30
0
 public ICheckLogic <T> ExpectingType(System.Type expectedType, string expectedLabel, string negatedExpLabel)
 {
     this.expectedKind = ValueKind.Type;
     this.options     |= MessageOption.WithType;
     return(this.Expecting(expectedType, expectedLabel, negatedExpLabel));
 }