示例#1
0
 public TaskManager(RepeatClient client)
 {
     this.client   = client;
     this.compiler = new CSCompiler(".");
     actions       = new Dictionary <string, UserDefinedAction>();
     emptyAction   = new EmptyAction("");
 }
示例#2
0
 private JObject GenerateTaskReply(string id, UserDefinedAction task)
 {
     return(new JObject(
                new JProperty("id", id),
                new JProperty("file_name", task.FileName)
                ));
 }
示例#3
0
        private JObject CreateTask(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return(GenerateReply(FAILURE, "File " + filePath + " does not exist."));
            }
            else
            {
                string sourceCode = FileUtility.ReadFile(filePath);
                if (sourceCode == null)
                {
                    return(GenerateReply(FAILURE, "Unreadable file " + filePath));
                }

                UserDefinedAction action = null;
                try {
                    action = compiler.Compile(sourceCode);
                } catch (Exception e) {
                    logger.Warn("Unable to compile source code\n" + e.StackTrace);
                }
                if (action == null)
                {
                    return(GenerateReply(FAILURE, "Cannot compile file " + filePath));
                }
                else
                {
                    string newId = System.Guid.NewGuid().ToString();
                    actions[newId]  = action;
                    action.FileName = filePath;
                    logger.Info("Successfully compiled source code.");
                    return(GenerateReply(SUCCESS, GenerateTaskReply(newId, action)));
                }
            }
        }