public IEnumerable <RedditAnswer> ParseThing(Thing objThing, PortalKeeperContext <ScheduleEvent> actionContext) //where TEngineEvent : IConvertible
        {
            var toReturn = new List <RedditAnswer>();


            if (EnableAllUsers || SimpleOrExpression <String> .GetValues(CommandUsers.ToArray(), actionContext, actionContext).Contains(objThing.AuthorName))
            {
                var parentsParsed = false;
                var message       = ParseThingVariables(objThing, actionContext, "", 0);

                foreach (var objRegex in BuiltRegexes)
                {
                    var objMatch = objRegex.Match(message);
                    if (objMatch.Success)
                    {
                        var previousAnswer = GetExistingAnswer(objThing);
                        // We only proceed with messages we have not answered yet
                        if (previousAnswer == null)
                        {
                            if (ParsingDepth > 0)
                            {
                                if (!parentsParsed)
                                {
                                    ParseThingVariables(objThing.ParentThing, actionContext, "Parent", ParsingDepth - 1);
                                    parentsParsed = true;
                                }
                            }
                            foreach (string groupName in objRegex.GetGroupNames())
                            {
                                actionContext.SetVar(groupName, objMatch.Groups[groupName].Value);
                            }

                            foreach (var objRedditAction in RedditAnswers)
                            {
                                if (objRedditAction.IsMatch(actionContext))
                                {
                                    toReturn.Add(objRedditAction);
                                }
                            }
                        }
                        else
                        {
                            //var candidateThings = previousAnswer.Children;
                            //foreach (var candidateThing in candidateThings)
                            //{
                            //    foreach (var command in NextCommands)
                            //    {
                            //       toReturn = toReturn | command.ParseThing(candidateThing, actionContext);
                            //    }
                            //}
                        }

                        return(toReturn);
                    }
                }
            }

            return(toReturn);
        }
        public virtual CreateHttpResponseInfo ProcessInternal(PortalKeeperContext <SimpleEngineEvent> actionContext, WebMethod verb)
        {
            actionContext.SetVar("HttpVerb", verb);
            this.SelectedAction.ProcessRules(actionContext, SimpleEngineEvent.Run, true, true);
            var response = actionContext.GetResponse();

            if (response == null && this.SelectedAction.DefaultResponse.Enabled)
            {
                response = this.SelectedAction.DefaultResponse.Entity;
            }

            return(response);
        }
        private string ParseThingVariables(Thing objThing, PortalKeeperContext <ScheduleEvent> actionContext, string prefix, int depth)
        {
            string toReturn = "";

            if (objThing != null && depth >= 0)
            {
                actionContext.SetVar(prefix + "Thing", objThing);
                actionContext.SetVar(prefix + "AuthorName", objThing.AuthorName);
                switch (objThing.Kind)
                {
                case "Comment":
                    var objComment = (Comment)objThing;

                    actionContext.SetVar(prefix + "Comment", objComment);
                    toReturn = objComment.Body;
                    actionContext.SetVar(prefix + "Message", objComment.Body);

                    break;

                case "PrivateMessage":
                    var pm = (PrivateMessage)objThing;
                    actionContext.SetVar(prefix + "PrivateMessage", pm);
                    toReturn = pm.Body;
                    actionContext.SetVar(prefix + "Message", pm.Body);
                    break;

                case "Post":
                    var objPost = (Post)objThing;
                    actionContext.SetVar(prefix + "Post", objPost);
                    toReturn = objPost.SelfText;
                    actionContext.SetVar(prefix + "Message", objPost.SelfText);
                    break;
                }
                if (depth > 0)
                {
                    ParseThingVariables(objThing.ParentThing, actionContext, "Parent" + prefix, depth - 1);
                }
            }
            return(toReturn);
        }
Exemple #4
0
 public static void SetResponse(this PortalKeeperContext <SimpleEngineEvent> context, CreateHttpResponseInfo objresponse)
 {
     context.SetVar("Response", objresponse);
 }