public async Task <IHttpActionResult> GetProjectWorkSpaces()
        {
            var projectMasterRepository = new ProjectMasterRepository(new AppDbContext());
            var projects = await projectMasterRepository.GetAllItems();

            return(Ok(projects));
        }
Exemple #2
0
        public async Task <HttpResponseMessage> StartProcessUbProject(int projectId)
        {
            using (_codeVortoService = new CodeVortoService())
            {
                var projectMasterRepository = new ProjectMasterRepository(new AppDbContext());
                var projectDetails          = projectMasterRepository.GetItem(projectId);
                if (projectDetails == null)
                {
                    return(new HttpResponseMessage(HttpStatusCode.BadRequest)
                    {
                        Content = new StringContent("Project not found: " + projectId)
                    });
                }
                var entensionList =
                    await _codeVortoService.FileTypeExtensionRepository.GetAllListItems(
                        p => p.LanguageId == projectDetails.LanguageId).ConfigureAwait(true);

                var strExtensions = new List <string>();
                strExtensions.AddRange(entensionList.Select(extension => extension.FileExtension));
                var lstFileMasters = new List <FileMaster>();
                var projectPath    = projectDetails.PhysicalPath;
                var solutionId     = projectDetails.SolutionId;
                var directoryList  = new List <string> {
                    projectPath
                };
                var ignoredFile =
                    await projectMasterRepository.GetAllIgnoredFiles <IgnoreFiles>(projectDetails.LanguageId)
                    .ConfigureAwait(false);

                var regexPattern = new Regex(@"RECEIVE\s+MAP|SEND\s+MAP");
                foreach (var directory in directoryList)
                {
                    try
                    {
                        var allFiles = Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories)
                                       .Where(s => strExtensions.Any(s.EndsWith));
                        var enumerator = allFiles.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            var currentFile = enumerator.Current;
                            if (ignoredFile.Any(f => f.FileName == Path.GetFileName(currentFile)))
                            {
                                continue;
                            }
                            if (currentFile == null)
                            {
                                continue;
                            }
                            var fileLines = File.ReadAllLines(currentFile).ToList();
                            var exist     = fileLines.Any(f => regexPattern.IsMatch(f));
                            var fileType  = exist ? "Online" : "Batch";
                            var lineCount = fileLines.Count(line => !string.IsNullOrWhiteSpace(line));
                            var fileName  = Path.GetFileName(currentFile);
                            if (string.IsNullOrEmpty(fileName))
                            {
                                continue;
                            }
                            var extension   = Path.GetExtension(currentFile);
                            var extensionId =
                                entensionList.First(e => e.FileExtension == extension).FileTypeExtensionId;
                            var fileMaster = new FileMaster
                            {
                                FileId              = 0,
                                FileName            = fileName,
                                FilePath            = currentFile,
                                FileTypeExtensionId = extensionId,
                                ProjectId           = projectId,
                                SolutionId          = solutionId,
                                DoneParsing         = 0,
                                LinesCount          = lineCount,
                                FileType            = fileType
                            };
                            lstFileMasters.Add(fileMaster);
                        }
                        enumerator.Dispose();
                        await
                        _codeVortoService.FileMasterRepository.BulkInsert(lstFileMasters).ConfigureAwait(false);
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception.InnerException);
                        return(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                        {
                            Content =
                                new ObjectContent(typeof(Exception), exception.InnerException,
                                                  new JsonMediaTypeFormatter())
                        });
                    }
                }

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent("Cobol processing is done")
                });
            }
        }