Exemple #1
0
        /// <summary>
        /// Needs to accept args in the following format:
        ///    {$iUserID} {$iProjectID} {$iFileID} {$iRow} {$iColumn}
        /// Example PHP command:
        ///    $sCommand = "mono /QuantConnect.Server.Autocomplete.worker/bin/QuantConnect.Server.Autocomplete.worker.exe {$iUserID} {$iProjectID} {$iFileID} {$iRow} {$iColumn}";
        ///
        /// Output should be a JSON-formatted object in the following form:
        ///    { autocomplete: [ ... ] }
        ///
        /// Input format:
        ///    UserId  ProjectId  SessionId  FileId  RowNumber  ColumnNumber
        /// Note:  RowNumber and ColumnNumber apply to the location within the file specified by FileId.
        /// Input Example:
        ///    478 125 MyArbitrarySessionIdThatCouldBeHelpfulForCachingSerializedProjectInfo 263 9 1
        ///  > Interpretation of above example:
        ///    User=Paul(478)  Project=paul-project(125)  SessionId  File=Main.cs(263)  Row=9  Column=1
        ///
        /// An example url:
        ///    http://autocomplete.quantconnect.com/api.php?sAction=autocomplete&iUserID=478&iProjectID=125&iFileID=263&iRow=10&iColumn=123
        /// </summary>
        /// <param name="args"></param>
        static void CommandLineAutocompleteMain(string[] args)
        {
            var sb = new StringBuilder("QuantConnect.Server.Autocomplete.worker args: ");

            for (int i = 0; i < args.Length; i++)
            {
                sb.AppendFormat("{0} ", args[i]);
            }
            Log.Trace(sb.ToString());


            int    userId = 0, projectId = 0, fileId = 0, line = 0, column = 0;
            string sessionId = "";

            if (args.Length < 6 ||
                !Int32.TryParse(args[0].Trim('\''), out userId) ||
                !Int32.TryParse(args[1].Trim('\''), out projectId) ||
                // session ID doesn't need processing
                !Int32.TryParse(args[3].Trim('\''), out fileId) ||
                !Int32.TryParse(args[4].Trim('\''), out line) ||
                !Int32.TryParse(args[5].Trim('\''), out column))
            {
                WriteResponse(NO_RESULTS_RESPONSE);
                return;
            }

            try
            {
                var request = new FileOperationRequest()
                {
                    UserId       = userId,
                    ProjectId    = projectId,
                    FileId       = fileId,
                    CompleteCode = new FileCodeCompletionRequest()
                    {
                        AutoComplete = true,
                        LineNumber   = line,
                        ColumnNumber = column,
                        CtrlSpace    = true // always true for now
                    },
                    Parse = new FileParseRequest()
                            //SyncContent = new FileSyncContentRequest()
                };

                FileOperationResponse response = AutocompleteServiceUtil.DoAutoComplete(request);

                string completionJson = JsonConvert.SerializeObject(response);
                //string jsonResponse = string.Format("{{ \"autocomplete\": {0} }}", completionJson);
                WriteResponse(completionJson);
            }
            catch (Exception ex)
            {
                WriteResponse(ex.ToString());
                Log.Error(ex.ToString());
            }
        }
Exemple #2
0
            public object Any(AutoCompleteRequest request)
            {
                try
                {
                    var sb = new StringBuilder("autocomplete args: ");
                    sb.AppendFormat(" [UserId:{0}]", request.UserId);
                    sb.AppendFormat(" [ProjectId:{0}]", request.ProjectId);
                    sb.AppendFormat(" [FileId:{0}]", request.FileId);
                    sb.AppendFormat(" [Line:{0}]", request.Line);
                    sb.AppendFormat(" [Column:{0}]", request.Column);
                    log.Info(sb.ToString());

                    var fileRequest = new FileOperationRequest()
                    {
                        UserId       = request.UserId,
                        ProjectId    = request.ProjectId,
                        FileId       = request.FileId,
                        CompleteCode = new FileCodeCompletionRequest()
                        {
                            AutoComplete = true,
                            LineNumber   = request.Line,
                            ColumnNumber = request.Column,
                            CtrlSpace    = true // always true for now
                        },
                        Parse = new FileParseRequest()
                    };

                    FileOperationResponse response = AutocompleteServiceUtil.DoAutoComplete(fileRequest);

                    return(response);
                }
                catch (Exception ex)
                {
                    log.Error(ex.ToString(), ex);

                    return(new ApiError()
                    {
                        FullName = ex.GetType().FullName,
                        Message = ex.Message,
                        StackTrace = ex.StackTrace
                    });
                }
            }