Beispiel #1
0
        public async Task <Response> doModelHttpRequest(ICommandObject cmdObject, ECmdObjType cmdType)
        {
            ServerResponse response = await this.bridge.makeHttPostRequest(cmdObject, cmdType);

            Collection <DataItemUpdate> updates = new Collection <DataItemUpdate>();

            foreach (ModelUpdate modelUpdate in response.modelUpdates)
            {
                updates.Add(this.makeDataItemUpdate(modelUpdate));
            }

            this.updateItems(updates);
            //Accept and implement any changes to the model received

            return(response.errorResponse);
        }
Beispiel #2
0
        public async Task <ServerResponse> makeHttPostRequest(ICommandObject commandObject, ECmdObjType cmdObjType)
        {
            string responseContent;



            HttpClient client = new HttpClient();


            try {
                string jsonString = JsonConvert.SerializeObject(commandObject);


                string cmdObjTypePair = "cmdObjType=" + cmdObjType;

                HttpRequestMessage requestMessage = constructRequest(
                    "http://127.0.0.1:32767/ajax.ashx",
                    "POST",
                    jsonString,
                    cmdObjTypePair
                    );



                Task <HttpResponseMessage> getResponseStringTask = client.SendAsync(requestMessage);

                //Task<HttpResponseMessage> getResponseStringTask = client.PostAsync("http://127.0.0.1:32767/ajax.ashx", content);
                HttpResponseMessage urlContents = await getResponseStringTask;

                //string herd = urlContents.Headers["Test"];

                responseContent = await urlContents.Content.ReadAsStringAsync();
            } catch (Exception e) {
                ServerResponse errorResponse = new ServerResponse();

                Response error = new Response(ResponseState.error, e.Message);

                errorResponse.errorResponse = error;

                return(errorResponse);
            }


            ServerResponse response = JsonConvert.DeserializeObject <ServerResponse>(responseContent);

            return(response);
        }
Beispiel #3
0
 //コマンドオブジェクトを実行する
 public void Update()
 {
     while (true)
     {
         if (runningCommandObject != null)
         {
             runningCommandObject.Run();
         }
         else if (runningCommandObject == null)
         {
             if (commandObjectQueue.TryDequeue(out runningCommandObject))
             {
                 runningCommandObject.Run();
             }
         }
         if (runningCommandObject == null || runningCommandObject.IsFinished == false)
         {
             return;
         }
         runningCommandObject = null;
     }
 }
Beispiel #4
0
 //コマンドを登録する
 public Task <T> Run(ICommandObject <T> commandObject)
 {
     commandObjectQueue.Enqueue(commandObject);
     return(Task.Run(commandObject.WaitFinished));
 }
 internal ParsingResult(ICommandObject commandObject, IEnumerable <ValidationResult> validationResults, CommandParsingResultCode parsingResultCode)
 {
     CommandObject     = commandObject;
     ValidationResults = validationResults ?? Enumerable.Empty <ValidationResult>();
     ParsingResultCode = parsingResultCode;
 }
 public Task <Void> AddActionCommandObject(ICommandObject <Void> commandObject)
 {
     return(actionCommandObjectQueue.Run(commandObject));
 }
 //タイルタイプ取得系のコマンドを登録する
 public Task <TileType> AddTileTypeGetCommandObject(ICommandObject <TileType> commandObject)
 => tileTypeGetCommandObjectQueue.Run(commandObject);
 //角度取得系のコマンドを登録する
 public Task <float> AddRadGetCommandObject(ICommandObject <float> commandObject)
 => radGetCommandObjectQueue.Run(commandObject);
 //座標取得系のコマンドを登録する
 public Task <GridPosition> AddPosGetCommandObject(ICommandObject <GridPosition> commandObject)
 => posGetCommandObjectQueue.Run(commandObject);
 //移動系のコマンドを登録する
 public Task <Void> AddMoveTypeCommandObject(ICommandObject <Void> commandObject)
 => moveTypeCommandObjectQueue.Run(commandObject);
Beispiel #11
0
        public static List <ICommand> GetCommands(string str, KScriptContainer container, KScriptBaseObject baseObj)
        {
            //Count all open brackets, when finding close bracket, length of string to array

            Stack <ICommand> commands = new Stack <ICommand>();

            List <ICommand> All_Commands = new List <ICommand>();

            char[] str_cmds = str.ToCharArray();

            ICommandObject bracket      = new ICommandObject(str, container, baseObj);
            ParamTracker   paramTracker = new ParamTracker();

            HashSet <char> allowedChars = new HashSet <char>(new[] { '(', ')', char.Parse("'") });
            List <char>    stack        = new List <char>(str.Where(allowedChars.Contains));

            int index = -1;

            bool ignore = false, encountered_cmd = false;

            for (int i = 0; i < str_cmds.Length; i++)
            {
                if (str_cmds[i].Equals('@') && !ignore)
                {
                    encountered_cmd = true;
                }

                if (encountered_cmd)
                {
                    paramTracker.Track(str_cmds[i], i);
                }


                if (str_cmds[i].Equals(char.Parse("'")) && encountered_cmd)
                {
                    ignore = !ignore;
                }

                if (str_cmds[i].Equals('@') && !ignore && encountered_cmd)
                {
                    bracket = new ICommandObject(str, container, baseObj);
                    bracket.IndexProperties.Start = i;
                    bracket.Index = ++index;
                    commands.Push(bracket);
                    continue;
                }
                else if (str_cmds[i].Equals('$') && !ignore && encountered_cmd)
                {
                    //ignore = !ignore;
                }
                else if (str_cmds[i].Equals('(') && !ignore && encountered_cmd)
                {
                    if (commands.Peek().IsCommandObject)
                    {
                        commands.Peek().GetCommandObject().EndNameIndex = i;
                    }
                    continue;
                }
                else if (str_cmds[i].Equals(',') && !ignore && encountered_cmd && commands.Count > 0)
                {
                    if (commands.Any())
                    {
                        ICommand cmd = commands.Peek();

                        if (cmd.IsCommandObject)
                        {
                            if (paramTracker.HasParams)
                            {
                                IValue variable = new IValue(paramTracker.GetIndexPair(), container);
                                cmd.GetCommandObject().Children.Enqueue(variable);
                            }
                        }
                    }
                }
                else if (str_cmds[i].Equals(')') && !ignore && encountered_cmd && commands.Count > 0)
                {
                    if (!commands.Any())
                    {
                        All_Commands.Add(bracket);
                        continue;
                    }

                    ICommand cmd = commands.Pop();
                    cmd.IndexProperties.End = i;

                    if (paramTracker.HasParams)
                    {
                        if (cmd.IsCommandObject)
                        {
                            if (cmd.GetCommandObject().InnerCommand.Length > 0)
                            {
                                IValue variable = new IValue(paramTracker.GetIndexPair(), container);
                                cmd.GetCommandObject().Children.Enqueue(variable);
                            }
                        }
                        else
                        {
                            IValue variable = new IValue(paramTracker.GetIndexPair(), container);
                            cmd.GetCommandObject().Children.Enqueue(variable);
                        }
                    }

                    if (commands.Count == 0)
                    {
                        All_Commands.Add(cmd);
                    }

                    if (commands.Count > 0 && commands.Peek().IsCommandObject&& !commands.Peek().GetCommandObject().IsClosed)
                    {
                        commands.Peek().GetCommandObject().Children.Enqueue(cmd);
                        continue;
                    }

                    All_Commands.Add(cmd);
                    continue;
                }
            }

            if (!(stack.Count % 2 == 0) && encountered_cmd)
            {
                throw new KScriptExceptions.KScriptException("KScript Command is incorrectly formatted - check brackets match and that all (') symbols are surrounding strings." +
                                                             "\nError occurs when parsing string: \n" + "----------------------------------------------------\n" + str);
            }

            return(All_Commands);
        }