/// <summary>
        /// Sets the appearance of this row to match a process condition.
        /// </summary>
        /// <param name="condition">The condition to evaluate and display.</param>
        internal void SetCondition(ProcessCondition condition)
        {
            var   status = condition.EvaluateCondition();
            Color itemColor;

            if (status != lastStatus)
            {
                switch (status)
                {
                case ProcessCondition.Status.Warning:
                    itemColor = ConditionListSideScreen.warningColor;
                    break;

                case ProcessCondition.Status.Ready:
                    itemColor = ConditionListSideScreen.readyColor;
                    break;

                case ProcessCondition.Status.Failure:
                default:
                    itemColor = ConditionListSideScreen.failedColor;
                    break;
                }
                text.color = itemColor;
                box.color  = itemColor;
                check.SetActive(status == ProcessCondition.Status.Ready);
                lastStatus = status;
            }
            SetTitle(condition.GetStatusMessage(status), condition.GetStatusTooltip(
                         status));
        }
示例#2
0
        public async Task TestStatusChangesWithNotificator()
        {
            id = Guid.NewGuid().ToString();

            ProcessCondition processCondition = new ProcessCondition
            {
                Language       = LANG,
                Id             = id,
                WorkingDirPath = WorkingDirPathsHelper.CppSuccess()
            };

            await processManager.ProcessTask(processCondition);

            List <bool> statuses = new List <bool>
            {
                buildStatuses[0] == BuildStatus.WaitingToBuild,
                buildStatuses[1] == BuildStatus.BuildStarting,
                buildStatuses[2] == BuildStatus.Preparing,
                buildStatuses[3] == BuildStatus.BuildSystemTest,
                buildStatuses[4] == BuildStatus.Building,
                buildStatuses[5] == BuildStatus.ProcessingBuildingArtifacts,
                buildStatuses[6] == BuildStatus.Execution,
                buildStatuses[7] == BuildStatus.ProcessingExecutionArtifacts,
                buildStatuses[8] == BuildStatus.Complete
            };

            Assert.IsNotNull(actualProcessResult);
            Assert.AreEqual(id, actualProcessResult.Condition.Id);
            Assert.AreEqual(ProcessState.Completed, actualProcessResult.State);
            Assert.AreEqual(BuildStatus.Complete, actualProcessResult.Status);
            Assert.AreEqual(true, statuses.All(x => x == true));
        }
        public ProcessConditionViewModel(ProcessCondition condition) : base(condition)
        {
            Option = new OptionViewModel(condition, nameof(condition.Option));
            Text   = new TextViewModel(condition);

            Attach(Option);
            Attach(Text);
        }
示例#4
0
        public async Task TestDeletingWithNotificator()
        {
            FilesHelper.CreateJunkFiles(WorkingDirPathsHelper.CommonNoOutput());

            id = Guid.NewGuid().ToString();

            ProcessCondition processCondition = new ProcessCondition
            {
                Language       = LANG,
                Id             = id,
                WorkingDirPath = WorkingDirPathsHelper.CommonNoOutput()
            };

            await processManager.ProcessTask(processCondition);

            Assert.IsTrue(FilesHelper.JunkFilesDeleted(WorkingDirPathsHelper.CommonNoOutput()));
        }
示例#5
0
        public async Task TestSuccessScenarioWithNotificator()
        {
            id = Guid.NewGuid().ToString();

            ProcessCondition processCondition = new ProcessCondition
            {
                Language       = LANG,
                Id             = id,
                WorkingDirPath = WorkingDirPathsHelper.JavaSuccess()
            };

            await processManager.ProcessTask(processCondition);

            Assert.IsNotNull(actualProcessResult);
            Assert.AreEqual(id, actualProcessResult.Condition.Id);
            Assert.AreEqual(ProcessState.Completed, actualProcessResult.State);
            Assert.AreEqual(BuildStatus.Complete, actualProcessResult.Status);
        }
示例#6
0
        public async Task TestTimeoutScenarioWithNotificator()
        {
            id = Guid.NewGuid().ToString();

            ProcessCondition processCondition = new ProcessCondition
            {
                Language       = SupportedLanguage.CPP,
                Id             = id,
                WorkingDirPath = WorkingDirPathsHelper.CppTimeouted()
            };

            await processManager.ProcessTask(processCondition);

            Assert.IsNotNull(actualProcessResult);
            Assert.AreEqual(id, actualProcessResult.Condition.Id);
            Assert.AreEqual(ProcessState.Error, actualProcessResult.State);
            Assert.AreEqual(BuildStatus.Execution, actualProcessResult.Status);
            Assert.IsInstanceOfType(actualProcessResult.Error, typeof(ProcessExecutionTimeouted));
        }
示例#7
0
        public async Task TestNoWorkDirNotSpecifiedWithNotificator()
        {
            id = Guid.NewGuid().ToString();

            ProcessCondition processCondition = new ProcessCondition
            {
                Language       = LANG,
                Id             = id,
                WorkingDirPath = ""
            };

            await processManager.ProcessTask(processCondition);

            Assert.IsNotNull(actualProcessResult);
            Assert.AreEqual(id, actualProcessResult.Condition.Id);
            Assert.AreEqual(ProcessState.Error, actualProcessResult.State);
            Assert.AreEqual(BuildStatus.Preparing, actualProcessResult.Status);
            Assert.IsInstanceOfType(actualProcessResult.Error, typeof(WorkingDirNotSpecified));
        }
示例#8
0
        public async Task TestRuntimeErrorScenarioWithNotificator()
        {
            id = Guid.NewGuid().ToString();

            ProcessCondition processCondition = new ProcessCondition
            {
                Language       = LANG,
                Id             = id,
                WorkingDirPath = WorkingDirPathsHelper.CRuntimeError()
            };

            await processManager.ProcessTask(processCondition);

            Assert.IsNotNull(actualProcessResult);
            Assert.AreEqual(id, actualProcessResult.Condition.Id);
            Assert.AreEqual(ProcessState.Error, actualProcessResult.State);
            Assert.AreEqual(BuildStatus.ProcessingExecutionArtifacts, actualProcessResult.Status);
            Assert.IsInstanceOfType(actualProcessResult.Error, typeof(OutputFileNotFound));
        }
示例#9
0
        public async Task TestOutOfMemoryScenarioWithNotificator()
        {
            id = Guid.NewGuid().ToString();

            ProcessCondition processCondition = new ProcessCondition
            {
                Language       = LANG,
                Id             = id,
                WorkingDirPath = WorkingDirPathsHelper.JavaOutOfMemory()
            };

            await processManager.ProcessTask(processCondition);

            Assert.IsNotNull(actualProcessResult);
            Assert.AreEqual(id, actualProcessResult.Condition.Id);
            Assert.AreEqual(ProcessState.Error, actualProcessResult.State);
            Assert.AreEqual(BuildStatus.Execution, actualProcessResult.Status);
            Assert.IsInstanceOfType(actualProcessResult.Error, typeof(ExecutionFailed));
        }
示例#10
0
            private string[] ExtractConsecutiveWords(List <string> words, ProcessCondition condition)
            {
                int indexOfFirstTag = Int32.MinValue;

                for (int i = 0; i < words.Count; i++)
                {
                    string word = words[i];

                    if (!condition(word))
                    {
                        indexOfFirstTag = i;
                        break;
                    }
                }

                if (indexOfFirstTag != Int32.MinValue)
                {
                    // var items = words.Where((s, pos) => pos >= 0 && pos < indexOfFirstTag).ToArray();
                    List <string> items = new List <string>();
                    for (int pos = 0; pos < indexOfFirstTag; pos++)
                    {
                        items.Add(words[pos]);
                    }

                    if (indexOfFirstTag > 0)
                    {
                        words.RemoveRange(0, indexOfFirstTag);
                    }
                    return(items.ToArray());
                }
                else
                {
                    // var items = words.Where((s, pos) => pos >= 0 && pos <= words.Count).ToArray();
                    List <string> items = new List <string>();
                    for (int pos = 0; pos < words.Count; pos++)
                    {
                        items.Add(words[pos]);
                    }

                    words.RemoveRange(0, words.Count);
                    return(items.ToArray());
                }
            }
        public async Task TestSuccessScenarioWithRetriver()
        {
            id = Guid.NewGuid().ToString();

            ProcessCondition processCondition = new ProcessCondition
            {
                Language       = LANG,
                Id             = id,
                WorkingDirPath = WorkingDirPathsHelper.CSharpSuccess()
            };

            await processManager.ProcessTask(processCondition);

            ProcessResult processResult = processManager.RetrieveProcessResult(id);

            Assert.IsNotNull(processResult);
            Assert.AreEqual(id, processResult.Condition.Id);
            Assert.AreEqual(ProcessState.Completed, processResult.State);
            Assert.AreEqual(BuildStatus.Complete, processResult.Status);
        }
示例#12
0
        public async Task TestNoSrcWithNotificator()
        {
            id = Guid.NewGuid().ToString();

            ProcessCondition processCondition = new ProcessCondition
            {
                Language       = LANG,
                Id             = id,
                WorkingDirPath = WorkingDirPathsHelper.CommonNoSrc()
            };

            await processManager.ProcessTask(processCondition);

            Assert.IsNotNull(actualProcessResult);
            Assert.AreEqual(id, actualProcessResult.Condition.Id);
            Assert.AreEqual(ProcessState.Error, actualProcessResult.State);
            Assert.AreEqual(BuildStatus.Preparing, actualProcessResult.Status);
            Assert.IsInstanceOfType(actualProcessResult.Error, typeof(InputFilesNotFound));
            Assert.AreEqual(InputFilesNotFound.InputFile.Src, (actualProcessResult.Error as InputFilesNotFound).FileType);
        }
示例#13
0
        public async Task TestCompileErrorScenarioWithRetriever()
        {
            id = Guid.NewGuid().ToString();

            ProcessCondition processCondition = new ProcessCondition
            {
                Language       = LANG,
                Id             = id,
                WorkingDirPath = WorkingDirPathsHelper.JavaCompileError()
            };

            await processManager.ProcessTask(processCondition);

            ProcessResult processResult = processManager.RetrieveProcessResult(id);

            Assert.IsNotNull(processResult);
            Assert.AreEqual(id, processResult.Condition.Id);
            Assert.AreEqual(ProcessState.Error, processResult.State);
            Assert.AreEqual(BuildStatus.Building, processResult.Status);
            Assert.IsInstanceOfType(processResult.Error, typeof(BuildFailed));
        }
示例#14
0
        public async Task TestRuntimeErrorScenarioWithRetriever()
        {
            id = Guid.NewGuid().ToString();

            ProcessCondition processCondition = new ProcessCondition
            {
                Language       = SupportedLanguage.CPP,
                Id             = id,
                WorkingDirPath = WorkingDirPathsHelper.CppRuntimeError()
            };

            await processManager.ProcessTask(processCondition);

            ProcessResult processResult = processManager.RetrieveProcessResult(id);

            Assert.IsNotNull(processResult);
            Assert.AreEqual(id, processResult.Condition.Id);
            Assert.AreEqual(ProcessState.Error, processResult.State);
            Assert.AreEqual(BuildStatus.Execution, processResult.Status);
            Assert.IsInstanceOfType(processResult.Error, typeof(ExecutionFailed));
        }
        public async Task TestCopyingSrcWithNotificator()
        {
            id = Guid.NewGuid().ToString();

            ProcessCondition processCondition = new ProcessCondition
            {
                Language       = LANG,
                Id             = id,
                WorkingDirPath = WorkingDirPathsHelper.CSharpSuccess()
            };

            await processManager.ProcessTask(processCondition);

            string outputContent = FilesHelper.ReadOutputFileContent(actualProcessResult?.OutputFilePath);

            Assert.IsNotNull(actualProcessResult);
            Assert.AreEqual(id, actualProcessResult.Condition.Id);
            Assert.AreEqual(ProcessState.Completed, actualProcessResult.State);
            Assert.AreEqual(BuildStatus.Complete, actualProcessResult.Status);
            Assert.AreEqual(OUTPUT_FILE_CONTENT, outputContent);
        }
        public async Task TestOutOfMemoryScenarioWithNotificator()
        {
            id = Guid.NewGuid().ToString();

            ProcessCondition processCondition = new ProcessCondition
            {
                Language       = LANG,
                Id             = id,
                WorkingDirPath = WorkingDirPathsHelper.CSharpOutOfMemory()
            };

            await processManager.ProcessTask(processCondition);

            Assert.IsNotNull(actualProcessResult);
            Assert.AreEqual(id, actualProcessResult.Condition.Id);
            Assert.AreEqual(ProcessState.Error, actualProcessResult.State);
            Assert.AreEqual(BuildStatus.Execution, actualProcessResult.Status);

            // Depends on free memory CLR may throw OOF exception or may execute process till it exceeded timeout. Booth type of errors are correct
            bool errorCorrect = actualProcessResult.Error.GetType() == typeof(ProcessExecutionTimeouted) ||
                                actualProcessResult.Error.GetType() == typeof(ExecutionFailed);

            Assert.AreEqual(true, errorCorrect);
        }
        public void TestBuildingSeveralProcesses()
        {
            idCSharp = Guid.NewGuid().ToString();
            ProcessCondition csharpCondition = new ProcessCondition
            {
                Id             = idCSharp,
                Language       = SupportedLanguage.CSharp,
                WorkingDirPath = WorkingDirPathsHelper.CSharpTimeouted()
            };

            idCPP = Guid.NewGuid().ToString();
            ProcessCondition cppCondition = new ProcessCondition
            {
                Id             = idCPP,
                Language       = SupportedLanguage.CPP,
                WorkingDirPath = WorkingDirPathsHelper.CppCompileError()
            };

            idJava = Guid.NewGuid().ToString();
            ProcessCondition javaCondition = new ProcessCondition
            {
                Id             = idJava,
                Language       = SupportedLanguage.Java,
                WorkingDirPath = WorkingDirPathsHelper.JavaSuccess()
            };

            processManager.ProcessTask(csharpCondition);

            Thread.Sleep(1500);

            processManager.ProcessTask(cppCondition);
            processManager.ProcessTask(javaCondition);

            // use timer to guaranteed exit the loop
            Stopwatch stopwatch       = new Stopwatch();
            int       stopwathTimeout = 50; // 50 sec

            while (stopwatch.Elapsed.TotalSeconds <= stopwathTimeout)
            {
                if (AllProcessCompleted())
                {
                    break;
                }
            }

            if (!AllProcessCompleted())
            {
                Assert.Fail("Execution stoped by timeout. Some or all procees did not completed. Execution stoped");
                CleanUp();
            }

            Assert.IsNotNull(processResultCSharp);
            Assert.AreEqual(idCSharp, processResultCSharp.Condition.Id);
            Assert.AreEqual(ProcessState.Error, processResultCSharp.State);
            Assert.AreEqual(BuildStatus.Execution, processResultCSharp.Status);
            Assert.IsInstanceOfType(processResultCSharp.Error, typeof(ProcessExecutionTimeouted));

            Assert.IsNotNull(processResultCPP);
            Assert.AreEqual(idCPP, processResultCPP.Condition.Id);
            Assert.AreEqual(ProcessState.Error, processResultCPP.State);
            Assert.AreEqual(BuildStatus.Building, processResultCPP.Status);
            Assert.IsInstanceOfType(processResultCPP.Error, typeof(BuildFailed));

            Assert.IsNotNull(processResultJava);
            Assert.AreEqual(idJava, processResultJava.Condition.Id);
            Assert.AreEqual(ProcessState.Completed, processResultJava.State);
            Assert.AreEqual(BuildStatus.Complete, processResultJava.Status);
        }
        public async Task <IActionResult> OnPostSubmit(int?id)
        {
            if (!id.HasValue)
            {
                return(NotFound());
            }

            var task = taskRepository.GetTask(id.Value);

            if (task == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var selectedFileExt = InputViewModel.SrcFilePath.Split('.').Last();
                var validSrcExt     = GetFileExt(InputViewModel.LangCode);

                if (validSrcExt != selectedFileExt)
                {
                    ModelState.AddModelError("", "Select file with correct extension!");
                    return(OnGet(id));
                }

                var    userId   = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                var    assignee = task.Assignees.FirstOrDefault(x => x.User.Id == userId);
                string workDir  = "";

                // upload src to user work dir
                if (!string.IsNullOrEmpty(assignee.WorkDir))
                {
                    workDir = assignee.WorkDir;
                }
                else
                {
                    var tournament = tournamentRepository.GetTournamentByTask(task.TournamentTaskId);
                    workDir = storageManager.GetWorkDir(userId, tournament.TournamentId.ToString(), task.TournamentTaskId.ToString());

                    assignee.WorkDir = workDir;
                    taskRepository.Update(task);
                }

                var srcFilePath = storageManager.CreateSrcFile(workDir, validSrcExt);
                using (var stream = new FileStream(srcFilePath, FileMode.Create))
                {
                    await InputViewModel.SrcFile.CopyToAsync(stream);
                }

                var inputFilePath = storageManager.CreateInputFileInWorkDir(workDir);
                storageManager.CopyInputFileToWorkDir(task.InputFilePath, inputFilePath);

                var lang = SupportedProgrammingLanguage.Map(InputViewModel.LangCode, out bool langParseSuccess);

                if (!langParseSuccess)
                {
                    ModelState.AddModelError("", "Smth went wrong");
                    return(OnGet(id));
                }

                string processConditionId = Guid.NewGuid().ToString();
                assignee.ProcessResultId = processConditionId;
                taskRepository.Update(task);

                ProcessCondition processCondition = new ProcessCondition
                {
                    Id             = processConditionId,
                    WorkingDirPath = workDir,
                    Language       = lang
                };

                await processManager.ProcessTask(processCondition);

                var result = processManager.RetrieveProcessResult(processConditionId);
                ProcessResult(result, task, assignee);
            }

            return(OnGet(id));
        }
示例#19
0
        public static void Main(string[] args)
        {
            try
            {
                var result = new List <string>();

                const string transactionSource = @"C:\Users\tgravran\Documents\visual studio 2015\Projects\SolutionStockExplorer\stock.console\data_total.csv";
                const string resultFile        = @"C:\Users\tgravran\Documents\visual studio 2015\Projects\SolutionStockExplorer\stock.console\resultFile.csv";

                IDataLoader         loader  = new DataLoader.DataLoader(transactionSource);
                ITransactionFactory factory = new TransactionFactory();

                decimal amountIncrement = (decimal)1000;
                decimal amountMin       = (decimal)1000;
                decimal amountMax       = (decimal)30000;

                decimal highPriceMin       = (decimal)0;
                decimal highPriceMax       = (decimal)2;
                decimal highPriceIncrement = (decimal)0.1;

                decimal lowPriceMin       = (decimal)0;
                decimal lowPriceMax       = (decimal)2;
                decimal lowPriceIncrement = (decimal)0.1;

                double totalCount = Convert.ToDouble((amountMax - amountMin) / amountIncrement * ((highPriceMax - highPriceMin) / highPriceIncrement) * ((lowPriceMax - lowPriceMin) / lowPriceIncrement));

                var tasks = new List <Task>();

                //for (var initialAmount = amountMin; initialAmount < amountMax; initialAmount += amountIncrement)
                //    for (var highPrice = highPriceMin; highPrice < highPriceMax; highPrice += highPriceIncrement)
                //        for (var lowPrice = lowPriceMin; lowPrice < lowPriceMax; lowPrice += lowPriceIncrement)
                //        {
                //            var c = new ProcessCondition()
                //            {
                //                HighPrice = highPrice,
                //                LowPrice = lowPrice,
                //                InitialAmount = initialAmount
                //            };

                //            var t = Task.Run(() =>
                //            {
                //                var processor = new TransactionProcessor(c);

                //                var enumerator = loader.Read();

                //                while (enumerator.MoveNext())
                //                    processor.Process(processor.Vault, enumerator.Current);

                //                result.Add(string.Format("{0},{1},{2},{3},{4},{5}", c.InitialAmount, c.HighPrice, c.LowPrice, processor.Vault.GetMargin(), processor.Vault.GetTotalBankFees(), processor.Vault.GetTransactionCount()));
                //                Console.WriteLine("{0},{1},{2},{3},{4},{5}", c.InitialAmount, c.HighPrice, c.LowPrice, processor.Vault.GetMargin(), processor.Vault.GetTotalBankFees(), processor.Vault.GetTransactionCount());
                //            });

                //            tasks.Add(t);
                //        }

                var c = new ProcessCondition()
                {
                    HighPrice     = (decimal)1.8,
                    LowPrice      = (decimal)0.2,
                    InitialAmount = (decimal)3000
                };

                var t = Task.Run(() =>
                {
                    IStockTradingStrategy strategy = new StandardStockStrategy(ComputeTransactionFee);

                    var processor  = new TransactionProcessor(ComputeTransactionFee, strategy, factory, c);
                    var enumerator = loader.Read();

                    while (enumerator.MoveNext())
                    {
                        processor.Process(enumerator.Current);
                    }

                    result.Add(string.Format("{0},{1},{2},{3},{4},{5},{6}", c.InitialAmount, c.HighPrice, c.LowPrice, processor.Vault.GetMargin(), processor.Vault.GetTotalBankFees(), processor.Vault.GetTransactionCount(), processor.Vault.Money));
                    Console.WriteLine("{0},{1},{2},{3},{4},{5},{6}", c.InitialAmount, c.HighPrice, c.LowPrice, processor.Vault.GetMargin(), processor.Vault.GetTotalBankFees(), processor.Vault.GetTransactionCount(), processor.Vault.Money);
                });

                tasks.Add(t);

                Task.WaitAll(tasks.ToArray());

                if (File.Exists(resultFile))
                {
                    File.Delete(resultFile);
                }

                //Insert Header
                result.Insert(0, string.Format("{0},{1},{2},{3},{4},{5},{6}", "InitialAmount", "High", "Low", "Margin", "BankFees", "TransactionCount", "Money"));

                //Write to file
                File.AppendAllLines(resultFile, result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Console.WriteLine("Process Over");
            Console.ReadKey();
        }