Example #1
0
        public async Task <Result> HandleAsync(AddDocumentToSourceStoreCommand command,
                                               CancellationToken cancellationToken)
        {
            Console.WriteLine($"[AddDocumentToSourceStoreCommandHandler] received command {command}");

            await UpdateFileStatus(command, OperationStatus.NotInitialized);

            var result = PythonRunner.Run(
                _scriptsConfiguration.UploadSource,
                $"{command.UserId} {command.FileId} Repository  {command.File.FileName} {command.File.Content}"
                );

            Console.WriteLine(result);
            if (result.TrimEnd().Split("\n").Last() == "-1")
            {
                Console.WriteLine($"[AddDocumentToSourceStoreCommandHandler] Upload failed for file {command.FileId}");
                await UpdateFileStatus(command, OperationStatus.Failed);

                return(Result.Fail($"Upload failed for file {command.FileId}"));
            }
            Console.WriteLine($"[AddDocumentToSourceStoreCommandHandler] upload successful");
            await UpdateFileStatus(command, OperationStatus.Complete);

            return(Guid.NewGuid().ToSuccessfulResult());
        }
Example #2
0
        public async Task <KeyValuePair <bool, List <Mark> > > GetSecondMiddlePrediction(string groupCourseId)
        {
            var result = await Task.Run <bool>(() => PythonRunner.Run(OperationNames.PredictForSecondMiddle, groupCourseId));

            if (!result)
            {
                return(new KeyValuePair <bool, List <Mark> >(false, null));
            }

            var secondMiddle = (await lessonRepository.GetByGroupCourse(groupCourseId)).FirstOrDefault(l => l.LessonType == LessonType.SecondMiddle);

            var predictedMiddleMarks = await markRepository.GetPredictedMarksByLesson(secondMiddle.Id, (int)secondMiddle.LessonType);

            return(new KeyValuePair <bool, List <Mark> >(true, predictedMiddleMarks));
        }
Example #3
0
        private double getAnalysisResult(AnalyzeDocumentCommand command)
        {
            var scriptResult = PythonRunner.Run(
                _scriptsConfiguration.PerformAnalysis,
                command.FileId.ToString()
                );

            Console.WriteLine(scriptResult);
            var last = scriptResult.TrimEnd().Split("\n").Last();

            if (double.TryParse(last, out var result))
            {
                return(result);
            }
            throw new NotSupportedException(scriptResult);
        }
Example #4
0
        internal static byte[] ProcessRequestedFile(HttpRequestHeader requestHeader, Settings settings, out bool doesItApply, HttpRespondHeader resh)
        {
            doesItApply = false;
            if (requestHeader.AbsoluteFilePath.EndsWith(".py"))
            {
                // .Net's IronBython Powerfull Engine

                return(PythonRunner.Run(requestHeader, resh)); //System.IO.File.ReadAllBytes(requestHeader.AbsoluteFilePath);
            }
            else if (requestHeader.AbsoluteFilePath.EndsWith(".py3"))
            {
                // Python's C-based Engine
                return(ProcessPython3Script(requestHeader, settings));
            }
            else if (requestHeader.AbsoluteFilePath.EndsWith(".jss"))
            {
                return(ChakraCoreObject.RunScript(requestHeader.AbsoluteFilePath, requestHeader, resh));
            }
            else if (requestHeader.AbsoluteFilePath.EndsWith(".exe"))
            {
                // Native request processing app
                return(RunNativeRequestProcessorApp(requestHeader, settings));
            }
            else
            {
                // Just read bytes and pass out
                doesItApply = true;
                int count = 0;
RE_TRY:
                if (count > 10)
                {
                    return(null);
                }
                byte[] b;
                try { b = System.IO.File.ReadAllBytes(requestHeader.AbsoluteFilePath); }
                catch { count++; System.Threading.Thread.Sleep(50); goto RE_TRY; }
                return(b);
            }
        }
Example #5
0
        public async Task <Result> HandleAsync(AddDocumentToAnalysisCommand command, CancellationToken cancellationToken)
        {
            Console.WriteLine($"[AddDocumentToAnalysisCommandHandler] received command {command}");
            await UpdateFileStatus(command, OperationStatus.NotInitialized);

            var result = PythonRunner.Run(
                _scriptsConfiguration.UploadAnalysis,
                $"{command.UserId} {command.FileId} Repository  {command.FileToVerify.FileName} {command.FileToVerify.Content}"
                );

            Console.WriteLine(result);
            if (result.TrimEnd().Split("\n").Last() == "-1")
            {
                Console.WriteLine($"[AddDocumentToAnalysisCommandHandler] upload failed {command}");
                await UpdateFileStatus(command, OperationStatus.Failed);

                return(Result.Fail($"Upload of file {command.FileId} failed"));
            }
            Console.WriteLine($"[AddDocumentToAnalysisCommandHandler] upload successful");
            //INFO: The file should be persisted with key of toAnalysisCommand.TaskId
            await UpdateFileStatus(command, OperationStatus.NotStarted);

            return(Result.Success());
        }