private async Task <List <StatementReferenceMaster> > GetMethodBlock(int stmtId)
        {
            using (_codeVortoService = new CodeVortoService())
            {
                object[] parameters =
                {
                    new MySqlParameter("@stmtId", MySqlDbType.Int32)
                    {
                        Value = stmtId
                    },
                    new MySqlParameter("@startBaseCommandId", MySqlDbType.Int32)
                    {
                        Value = 8
                    },
                    new MySqlParameter("@endBaseCommandId", MySqlDbType.Int32)
                    {
                        Value = 9
                    }
                };
                var workflowRef = await _codeVortoService.StatementReferenceMasterRepository
                                  .ExecuteStoreProcedure <StatementReferenceMaster>("SpGetAnyGenericBlock", parameters)
                                  .ConfigureAwait(false);

                var settings = new JsonSerializerSettings
                {
                    ContractResolver           = new ReferenceLoopResolver <StatementReferenceMaster>(),
                    PreserveReferencesHandling = PreserveReferencesHandling.None,
                    ReferenceLoopHandling      = ReferenceLoopHandling.Ignore,
                    Formatting = Formatting.Indented
                };
                var json     = JsonConvert.SerializeObject(workflowRef, settings);
                var listData = JsonConvert.DeserializeObject <List <StatementReferenceMaster> >(json);
                return(listData);
            }
        }
 private List <StatementReferenceMaster> GetAllMethodsForClass(string className)
 {
     using (ICodeVortoService codeVortoService = new CodeVortoService())
     {
         object[] parametersExp =
         {
             new MySqlParameter("@delim", MySqlDbType.VarChar)
             {
                 Value = ","
             },
             new MySqlParameter("@className", MySqlDbType.VarChar)
             {
                 Value = className
             }
         };
         var callExtExpandedCode = codeVortoService.StatementReferenceMasterRepository
                                   .ExecuteStoreProcedure <StatementReferenceMaster>("SpGetAllMethodsForClass", parametersExp)
                                   .ContinueWith(t => t.Result).Result;
         return(callExtExpandedCode);
     }
 }
        public async void StartingPoints(int projectId)
        {
            // Action Workflows data...
            using (ICodeVortoService codeVortoService = new CodeVortoService())
            {
                var projectMaster = new GeneralRepository <ProjectMaster>(new AppDbContext());
                Expression <Func <ProjectMaster, bool> > expression = e => e.ProjectId == projectId;
                var projectMasterData = await projectMaster.GetItem <ProjectMaster>(expression, projectId);

                int projectType = projectMasterData.ProjectConfigType;
                if (projectType == 3)
                {
                    var projectConfig     = new GeneralRepository <ProjectConfigMaster>(new AppDbContext());
                    var projectConfigData = projectConfig.GetItem(projectType);
                    if (projectConfigData.ConfigFileId == projectType)
                    {
                        // Means the project type is windows application and we need to read starting point from that
                        // files respective code behind file...
                        string configFileName = projectConfigData.ToString();
                        if (!string.IsNullOrEmpty(configFileName))
                        {
                            var allConfigFiles =
                                await codeVortoService.FileMasterRepository.GetAllItems(
                                    f => f.FilePath.EndsWith(configFileName) && f.ProjectId == projectId);

                            foreach (var cFile in allConfigFiles)
                            {
                                var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(cFile.FilePath);
                                if (fileNameWithoutExtension != null)
                                {
                                    string className     = fileNameWithoutExtension.Split('.')[0];
                                    var    genericBlocks = GetAllMethodsForClass(className);
                                    foreach (var statement in genericBlocks)
                                    {
                                        ActionWorkflows actionWorkflow = new ActionWorkflows
                                        {
                                            ActionWorkflowId  = 0,
                                            CreatedBy         = 1,
                                            EndPointOrService = "Service",
                                            MethodStatementId = statement.StatementId,
                                            OriginFileName    =
                                                Path.GetFileName(
                                                    cFile.FilePath),
                                            OriginFilePath =
                                                cFile.FilePath,
                                            ProjectId          = projectId,
                                            OriginEventMethod  = statement.MethodName,
                                            OriginObject       = className,
                                            WorkflowName       = statement.OriginalStatement,
                                            ServiceBaseAddress = null,
                                            ServiceContract    = null
                                        };
                                        await codeVortoService.ActionWorkflowsRepository.AddNewItem(actionWorkflow);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    var allConfigFiles =
                        await codeVortoService.FileMasterRepository.GetAllItems(
                            f => f.FilePath.EndsWith(".config") && f.ProjectId == projectId);

                    foreach (var configFile in allConfigFiles)
                    {
                        if (configFile.FileName == "Web.config")
                        {
                            continue;
                        }
                        var filePaths =
                            await codeVortoService.FileMasterRepository.GetAllItems(f => f.ProjectId == projectId);

                        var         fileMaster = filePaths as FileMaster[] ?? filePaths.ToArray();
                        XmlDocument xmlDoc     = new XmlDocument();
                        //xmlDoc.Load(@"D:\NjSoft\CodeVorto\KDOTTRS\TRSWcfService\app.config");
                        xmlDoc.Load(configFile.FilePath);
                        List <string> startListNames = new List <string>();
                        List <string> sContracts     = new List <string>();
                        List <string> sAddress       = new List <string>();
                        Dictionary <string, string> otherEntryPoints = new Dictionary <string, string>();

                        foreach (XmlNode serviceModel in xmlDoc.GetElementsByTagName("client"))
                        {
                            foreach (XmlNode node in serviceModel)
                            {
                                string startPoint  = node.Attributes["name"].Value;
                                string baseAddress = node.Attributes["address"].Value;
                                otherEntryPoints.Add(startPoint, baseAddress);
                            }
                        }

                        foreach (XmlNode childNodes in xmlDoc.GetElementsByTagName("services"))
                        {
                            foreach (XmlNode node in childNodes)
                            {
                                startListNames.Add(node.Attributes["name"].Value);
                                XmlNode firstNd = node.FirstChild;
                                XmlNode lastNd  = node.LastChild.FirstChild.ChildNodes[0];
                                sContracts.Add(firstNd.Attributes["contract"].Value);
                                sAddress.Add(lastNd.Attributes["baseAddress"].Value);
                            }
                        }
                        foreach (var sPoint in otherEntryPoints)
                        {
                            var actionWorkflow = new ActionWorkflows
                            {
                                ActionWorkflowId   = 0,
                                CreatedBy          = 1,
                                EndPointOrService  = null,
                                ProjectId          = projectId,
                                WorkflowName       = sPoint.Key,
                                ServiceBaseAddress = sPoint.Value,
                                OriginFileName     = Path.GetFileName(
                                    fileMaster.ToList().Find(f => f.FileId == configFile.FileId).FilePath)
                            };
                            await codeVortoService.ActionWorkflowsRepository.AddNewItem(actionWorkflow);
                        }
                        int listPosition = 0;
                        foreach (var clsName in startListNames)
                        {
                            object[] parameters =
                            {
                                new MySqlParameter("@clsName", MySqlDbType.VarChar)
                                {
                                    Value = clsName.Split('.').Last()
                                }
                            };
                            var allMethodStatements = await codeVortoService.StatementReferenceMasterRepository
                                                      .ExecuteStoreProcedure <StatementReferenceMaster>("SpGetClassMethods", parameters);

                            foreach (var statement in allMethodStatements)
                            {
                                //if (statement.OriginalStatement.StartsWith("Private")) continue;

                                ActionWorkflows actionWorkflow = new ActionWorkflows
                                {
                                    ActionWorkflowId  = 0,
                                    CreatedBy         = 1,
                                    EndPointOrService = "Service",
                                    MethodStatementId = statement.StatementId,
                                    OriginFileName    =
                                        Path.GetFileName(
                                            fileMaster.ToList().Find(f => f.FileId == statement.FileId).FilePath),
                                    OriginFilePath =
                                        fileMaster.ToList().Find(f => f.FileId == statement.FileId).FilePath,
                                    ProjectId          = projectId,
                                    OriginEventMethod  = statement.MethodName,
                                    OriginObject       = clsName,
                                    WorkflowName       = statement.OriginalStatement,
                                    ServiceBaseAddress = sAddress.ElementAt(listPosition),
                                    ServiceContract    = sContracts.ElementAt(listPosition)
                                };
                                await codeVortoService.ActionWorkflowsRepository.AddNewItem(actionWorkflow);
                            }
                            listPosition++;
                        }
                    }
                }
            }
        }
        public async Task <IHttpActionResult> ProcessActionWorkflowDetails(int projectId)
        {
            using (_codeVortoService = new CodeVortoService())
            {
                var allActionWorkFlows = await _codeVortoService.ActionWorkflowsRepository
                                         .GetAllListItems(a => a.ProjectId == projectId).ConfigureAwait(false);

                var projectDetails = _codeVortoService.ProjectMasterRepository.GetItem(projectId);
                int solutionId     = projectDetails.SolutionId ?? 0;

                object[] parameters =
                {
                    new MySqlParameter("@prjId", MySqlDbType.Int32)
                    {
                        Value = projectId
                    }
                };
                var allClassNameDeclared =
                    await _codeVortoService.StatementReferenceMasterRepository
                    .ExecuteStoreProcedure <StatementReferenceMaster>("SpGetAllStatementForWorkFlowProcess", parameters)
                    .ConfigureAwait(false);

                var fileMasterData = await _codeVortoService.FileMasterRepository
                                     .GetAllListItems(f => f.SolutionId == solutionId && f.ProjectId == projectDetails.ProjectId)
                                     .ConfigureAwait(false);

                int graphId       = 0;
                int childsGraphId = 0;

                Console.WriteLine("=============================================================");
                Console.WriteLine("Total Action Workflows to process: " + allActionWorkFlows.Count);
                Console.WriteLine("=============================================================");
                foreach (var actionWorkflow in allActionWorkFlows)
                {
                    graphId++;
                    Console.WriteLine("Action Workflows Remaining: " + (allActionWorkFlows.Count - graphId));
                    Console.WriteLine("=============================================================");

                    childsGraphId++;
                    Thread.Sleep(100);
                    int fileMenuId = actionWorkflow.FileMenuId;
                    if (actionWorkflow.FileId == 0)
                    {
                        var emptyActionDetails = GiveMeActionWorkFlowDetail(allActionWorkFlows, allClassNameDeclared,
                                                                            actionWorkflow, graphId, projectId, 0);
                        emptyActionDetails.GraphId    = "EmptyGraph_" + graphId;
                        emptyActionDetails.ParentId   = "-1";
                        emptyActionDetails.ObjectType = "Menu";
                        emptyActionDetails.FileMenuId = fileMenuId;
                        await _codeVortoService.ActionWorkflowDetailsRepository.AddNewItem(emptyActionDetails)
                        .ConfigureAwait(false);

                        Thread.Sleep(10);
                        continue;
                    }
                    int fileId         = actionWorkflow.FileId;
                    var currentJclFile = fileMasterData.First(f => f.FileId == fileId);
                    // main workflow
                    var aDetails = GiveMeActionWorkFlowDetail(allActionWorkFlows, allClassNameDeclared, actionWorkflow,
                                                              graphId, projectId, 1);
                    aDetails.GraphId      = "Graph_" + graphId;
                    aDetails.ParentId     = "-1";
                    aDetails.ObjectType   = "JCL"; // objectType;
                    aDetails.WorkflowName = !string.IsNullOrEmpty(actionWorkflow.OriginEventMethod)
                        ? actionWorkflow.OriginEventMethod
                        : actionWorkflow.WorkflowName;
                    aDetails.FileMenuId = fileMenuId;
                    await _codeVortoService.ActionWorkflowDetailsRepository.AddNewItem(aDetails).ConfigureAwait(false);

                    Thread.Sleep(100);

                    // main jcl
                    string disabled   = string.Empty;
                    var    jclGraphId = "JclGraphId_" + graphId;
                    string btnStyle   = "style='margin-top :5px;height: 31px;'";

                    var allCallExt = allClassNameDeclared
                                     .Where(s => s.FileId == currentJclFile.FileId && s.BaseCommandId == 6)
                                     .OrderBy(s => s.StatementId).ToList();

                    foreach (var file in allCallExt)
                    {
                        Thread.Sleep(500);
                        if (fileMasterData.All(f => f.FileId != file.FileId))
                        {
                            continue;
                        }
                        if (file.ReferenceFileId == 0)
                        {
                            continue;
                        }
                        var fileMaster = fileMasterData.First(f => f.FileId == file.ReferenceFileId);
                        if (fileMaster == null)
                        {
                            continue;
                        }

                        var fileStatements1 = File.ReadAllLines(fileMaster.FilePath).ToList();
                        fileStatements1.RemoveAll(s => s.Length <= 0);
                        fileStatements1 = fileStatements1.Select(s => s.Trim()).ToList();
                        var fileBusinessName1 = fileStatements1.First().TrimStart('/').Trim('*').StartsWith("PA ")
                            ? fileStatements1.First().TrimStart('/').Trim('*').Replace("PA ", "").Trim()
                            : fileStatements1.First().TrimStart('/').Trim('*').Trim();

                        if (fileMaster.FileTypeExtensionId == 8)
                        {
                            // add new actionWorkflowDetails...
                            string pageUrl1 = "customview.html?prjId=" + projectId + "&fileId=" +
                                              fileMaster.FileId + "";
                            var view1 = "<a " + disabled + " href=javascript:window.open('" + pageUrl1 + "')>" +
                                        "<button " + btnStyle + " " + disabled +
                                        " class='btn btn-mint'>View</button>";

                            string objectType       = fileMaster.FileTypeExtensionReference.FileTypeName;
                            var    workflowDetails1 = new ActionWorkflowDetails
                            {
                                DecisionCount    = 0,   //decisionCount,
                                ExtrernalCalls   = "-", // callExternal > 0 ? "Yes" : "No",
                                InternalCalls    = "-", // callInternal > 0 ? "Yes" : "No",
                                View             = view1,
                                OriginObject     = Path.GetFileNameWithoutExtension(fileMaster.FilePath),
                                WorkflowName     = fileBusinessName1, // Path.GetFileNameWithoutExtension(fileMaster.FilePath),
                                ProjectName      = fileMaster.ProjectMaster.ProjectName,
                                ActionWorkflowId = 0,
                                ShortDetails     = "0",
                                ParentId         = aDetails.GraphId,
                                GraphId          = "ProgramGraphId_" + graphId + fileMaster.FileId,
                                ProjectId        = projectId,
                                ObjectType       = objectType,
                                FileMenuId       = fileMenuId
                            };
                            // Console.WriteLine("Program");
                            await _codeVortoService.ActionWorkflowDetailsRepository.AddNewItem(workflowDetails1)
                            .ConfigureAwait(false);

                            Thread.Sleep(1000);

                            childsGraphId = await FaktJclToProgramChaCode(fileMaster, fileMasterData, allClassNameDeclared,
                                                                          workflowDetails1.GraphId, childsGraphId, fileMenuId).ConfigureAwait(false);

                            childsGraphId = childsGraphId + 1;

                            continue;
                        } // Program
                        if (fileMaster.FileTypeExtensionId == 6)
                        {
                            // add new actionWorkflowDetails...
                            string objectType     = fileMaster.FileTypeExtensionReference.FileTypeName;
                            string jclFileGraphId = "NewJclGraph_" + graphId + fileMaster.FileId;
                            string pageUrl1       = "customview.html?prjId=" + projectId + "&fileId=" +
                                                    fileMaster.FileId + "";
                            var view1 = "<a " + disabled + " href=javascript:window.open('" + pageUrl1 + "')>" +
                                        "<button " + btnStyle + " " + disabled +
                                        " class='btn btn-mint'>View</button>";

                            var workflowDetails1 = new ActionWorkflowDetails
                            {
                                DecisionCount    = 0,   //decisionCount,
                                ExtrernalCalls   = "-", // callExternal > 0 ? "Yes" : "No",
                                InternalCalls    = "-", // callInternal > 0 ? "Yes" : "No",
                                View             = view1,
                                OriginObject     = Path.GetFileNameWithoutExtension(fileMaster.FilePath),
                                WorkflowName     = fileBusinessName1, // Path.GetFileNameWithoutExtension(fileMaster.FilePath),
                                ProjectName      = fileMaster.ProjectMaster.ProjectName,
                                ActionWorkflowId = 0,
                                ShortDetails     = "0",
                                ParentId         = jclGraphId,
                                GraphId          = jclFileGraphId,
                                ProjectId        = projectId,
                                ObjectType       = objectType,
                                FileMenuId       = fileMenuId
                            };
                            // Console.WriteLine("JCL");
                            await _codeVortoService.ActionWorkflowDetailsRepository.AddNewItem(workflowDetails1)
                            .ConfigureAwait(false);

                            if (fileMaster.FileId == file.FileId)
                            {
                                continue;
                            }

                            Thread.Sleep(600);
                            childsGraphId = await FaktJclToProgramChaCode(fileMaster, fileMasterData, allClassNameDeclared,
                                                                          jclFileGraphId, childsGraphId, fileMenuId).ConfigureAwait(false);

                            childsGraphId = childsGraphId + 1;
                        } // JCL
                    }
                }

                return(Ok("All action workflow details processed successfully."));
            }
        }
        private async Task <int> FaktJclToProgramChaCode(FileMaster fileMaster, List <FileMaster> fileMasterData,
                                                         List <StatementReferenceMaster> allClassNameDeclared, string parentId, int childsGraphId, int fileMenuId)
        {
            using (_codeVortoService = new CodeVortoService())
            {
                var allCallExt = await _codeVortoService.StatementReferenceMasterRepository
                                 .GetAllListItems(s => s.FileId == fileMaster.FileId && s.BaseCommandId == 6 && s.ReferenceFileId != 0)
                                 .ConfigureAwait(false);

                allCallExt = allCallExt.OrderBy(s => s.StatementId).ToList();
                string btnStyle   = "style='margin-top :5px;height: 31px;'";
                var    allClasses = (from a in allCallExt
                                     where !string.IsNullOrEmpty(a.ClassCalled)
                                     select a.ClassCalled).ToList();

                foreach (var aClass in allClasses)
                {
                    Thread.Sleep(100);
                    var allFiles = (from s in allClassNameDeclared
                                    where aClass == s.ClassNameDeclared
                                    select s).ToList();

                    foreach (var file in allFiles)
                    {
                        Thread.Sleep(200);
                        if (fileMasterData.All(f => f.FileId != file.FileId))
                        {
                            continue;
                        }
                        var thisFileMaster = fileMasterData.First(f => f.FileId == file.FileId);

                        var fileStatements1 = File.ReadAllLines(thisFileMaster.FilePath).ToList();
                        fileStatements1.RemoveAll(s => s.Length <= 0);
                        fileStatements1 = fileStatements1.Select(s => s.Trim()).ToList();
                        var fileBusinessName1 = fileStatements1.First().TrimStart('/').Trim('*').StartsWith("PA ")
                            ? fileStatements1.First().TrimStart('/').Trim('*').Replace("PA ", "").Trim()
                            : fileStatements1.First().TrimStart('/').Trim('*').Trim();

                        if (thisFileMaster.FileTypeExtensionId == 8)
                        {
                            // add new actionWorkflowDetails...
                            string pilluChaGraphId = "PgmGraphId_" + ++childsGraphId + thisFileMaster.FileId;
                            string pageUrl1        = "customview.html?prjId=" + thisFileMaster.ProjectId + "&fileId=" +
                                                     thisFileMaster.FileId + "";
                            var view1 = "<a href=javascript:window.open('" + pageUrl1 + "')>" +
                                        "<button " + btnStyle + " class='btn btn-mint'>View</button>";
                            string objectType       = fileMaster.FileTypeExtensionReference.FileTypeName;
                            var    workflowDetails1 = new ActionWorkflowDetails
                            {
                                DecisionCount    = 0,
                                ExtrernalCalls   = "No",
                                InternalCalls    = "No",
                                View             = view1,
                                OriginObject     = Path.GetFileNameWithoutExtension(thisFileMaster.FilePath),
                                WorkflowName     = fileBusinessName1, // Path.GetFileNameWithoutExtension(thisFileMaster.FilePath),
                                ProjectName      = thisFileMaster.ProjectMaster.ProjectName,
                                ActionWorkflowId = 0,
                                ShortDetails     = "0",
                                ParentId         = parentId,
                                GraphId          = pilluChaGraphId,
                                ProjectId        = thisFileMaster.ProjectId,
                                ObjectType       = objectType,
                                FileMenuId       = fileMenuId
                            };
                            // Console.WriteLine("Program");
                            await _codeVortoService.ActionWorkflowDetailsRepository.AddNewItem(workflowDetails1)
                            .ConfigureAwait(false);

                            Thread.Sleep(200);
                            continue;
                        } // Proc
                        if (thisFileMaster.FileTypeExtensionId == 19)
                        {
                            // add new actionWorkflowDetails...
                            string jclFileGraphId = "PilluJclGraph_" + ++childsGraphId + thisFileMaster.FileId;
                            string pageUrl1       = "customview.html?prjId=" + thisFileMaster.ProjectId + "&fileId=" +
                                                    thisFileMaster.FileId + "";
                            var view1 = "<a  href=javascript:window.open('" + pageUrl1 + "')>" +
                                        "<button " + btnStyle + " class='btn btn-mint'>View</button>";
                            string objectType       = thisFileMaster.FileTypeExtensionReference.FileTypeName;
                            var    workflowDetails1 = new ActionWorkflowDetails
                            {
                                DecisionCount    = 0,
                                ExtrernalCalls   = "No",
                                InternalCalls    = "No",
                                View             = view1,
                                OriginObject     = Path.GetFileNameWithoutExtension(thisFileMaster.FilePath),
                                WorkflowName     = fileBusinessName1, // Path.GetFileNameWithoutExtension(thisFileMaster.FilePath),
                                ProjectName      = thisFileMaster.ProjectMaster.ProjectName,
                                ActionWorkflowId = 0,
                                ShortDetails     = "0",
                                ParentId         = parentId,
                                GraphId          = jclFileGraphId,
                                ProjectId        = thisFileMaster.ProjectId,
                                ObjectType       = objectType,
                                FileMenuId       = fileMenuId
                            };
                            // Console.WriteLine("JCL");
                            await _codeVortoService.ActionWorkflowDetailsRepository.AddNewItem(workflowDetails1)
                            .ConfigureAwait(false);

                            // if (thisFileMaster.FileId == file.FileId) break;

                            Thread.Sleep(500);
                            await FaktJclToProgramChaCode(thisFileMaster, fileMasterData, allClassNameDeclared,
                                                          jclFileGraphId, childsGraphId, fileMenuId);

                            Console.WriteLine("InputLib");
                        } // InputLib
                        if (thisFileMaster.FileTypeExtensionId == 6)
                        {
                            // add new actionWorkflowDetails...
                            string jclFileGraphId = "PilluJclGraph_" + ++childsGraphId + thisFileMaster.FileId;
                            string pageUrl1       = "customview.html?prjId=" + thisFileMaster.ProjectId + "&fileId=" +
                                                    thisFileMaster.FileId + "";
                            var view1 = "<a  href=javascript:window.open('" + pageUrl1 + "')>" +
                                        "<button " + btnStyle + " class='btn btn-mint'>View</button>";
                            string objectType       = thisFileMaster.FileTypeExtensionReference.FileTypeName;
                            var    workflowDetails1 = new ActionWorkflowDetails
                            {
                                DecisionCount    = 0,
                                ExtrernalCalls   = "No",
                                InternalCalls    = "No",
                                View             = view1,
                                OriginObject     = Path.GetFileNameWithoutExtension(thisFileMaster.FilePath),
                                WorkflowName     = fileBusinessName1, // Path.GetFileNameWithoutExtension(thisFileMaster.FilePath),
                                ProjectName      = thisFileMaster.ProjectMaster.ProjectName,
                                ActionWorkflowId = 0,
                                ShortDetails     = "0",
                                ParentId         = parentId,
                                GraphId          = jclFileGraphId,
                                ProjectId        = thisFileMaster.ProjectId,
                                ObjectType       = objectType,
                                FileMenuId       = fileMenuId
                            };
                            // Console.WriteLine("JCL");
                            await _codeVortoService.ActionWorkflowDetailsRepository.AddNewItem(workflowDetails1)
                            .ConfigureAwait(false);

                            if (thisFileMaster.FileId == file.FileId)
                            {
                                break;
                            }

                            Thread.Sleep(500);
                            await FaktJclToProgramChaCode(thisFileMaster, fileMasterData, allClassNameDeclared,
                                                          jclFileGraphId, childsGraphId, fileMenuId);

                            Console.WriteLine("Cobol / Program");
                        } // Cobol / Program
                    }
                }
                return(childsGraphId);
            }
        }
        public async Task <IHttpActionResult> ProcessAllActioWorkflows(int projectId, FileMaster fileMaster)
        {
            using (_codeVortoService = new CodeVortoService())
            {
                #region Added the Action workflow table

                if (string.IsNullOrEmpty(fileMaster.FileName) || fileMaster.FileId == 0)
                {
                    return(Ok("Action Workflows processed successfully"));
                }
                // Action Workflows data...
                var projectMaster = _codeVortoService.ProjectMasterRepository.GetItem(projectId);
                var projectType   = projectMaster.ProjectConfigType;
                if (projectType != 4)
                {
                    return(Ok("Action Workflows processed successfully"));
                }
                var projectCongfig    = new GeneralRepository <ProjectConfigMaster>(new AppDbContext());
                var projectConfigData = projectCongfig.GetItem(projectType);
                if (projectConfigData.ConfigFileId != projectType)
                {
                    return(Ok("Process completed successfully"));
                }
                try
                {
                    var allProcessedWorkflows = await _codeVortoService.ActionWorkflowsRepository
                                                .GetAllListItems(r => r.ProjectId == projectId && r.Processed == 1);

                    object[] param =
                    {
                        new MySqlParameter("@pjId", MySqlDbType.Int32)
                        {
                            Value = projectId
                        },
                        new MySqlParameter("@fileId", MySqlDbType.Int32)
                        {
                            Value = fileMaster.FileId
                        }
                    };

                    var genericBlocks =
                        await
                        _codeVortoService.StatementReferenceMasterRepository
                        .ExecuteStoreProcedure <StatementReferenceMaster>("SpGetMethodData", param);

                    foreach (var statement in genericBlocks)
                    {
                        if (allProcessedWorkflows.Any(s => statement.StatementId == s.MethodStatementId))
                        {
                            continue;
                        }

                        var actionWorkflow = new ActionWorkflows
                        {
                            ActionWorkflowId  = 0,
                            CreatedBy         = 1,
                            EndPointOrService = "Batch",
                            MethodStatementId = statement.StatementId,
                            OriginFileName    = Path.GetFileName(fileMaster.FilePath),
                            OriginFilePath    = fileMaster.FilePath,
                            ProjectId         = projectId,
                            OriginObject      = projectMaster.ProjectName + fileMaster.FilePath.Replace(".jcl", "")
                                                .Replace(projectMaster.PhysicalPath, "").Trim().Replace("\\", "."),
                            WorkflowName         = statement.OriginalStatement,
                            ServiceBaseAddress   = null,
                            ServiceContract      = null,
                            WorkflowBusinessName = statement.BusinessName,
                            IsDeleted            = 0,
                            ReasonAboutDisable   = null,
                            Processed            = 0,
                            FileId = statement.FileId
                        };
                        await
                        _codeVortoService.ActionWorkflowsRepository.AddNewItem(actionWorkflow)
                        .ConfigureAwait(false);
                    }
                }

                catch (Exception exception)
                {
                    Console.WriteLine(exception.InnerException);
                }
                return(Ok("Action Workflows processed successfully"));

                #endregion
            }
        }
        public async Task <IHttpActionResult> GetWorkFlowWorkSpaceParallel(int projectId, int stmtId)
        {
            using (_codeVortoService = new CodeVortoService())
            {
                var stringBuilder = new StringBuilder();
                stringBuilder.AppendLine("====================================");
                Console.WriteLine("===========================================");
                stringBuilder.AppendLine("\n" + " Started GetWorkFlowWorkSpaceParallel for projectId: " + projectId +
                                         " and StatementId: " + stmtId);
                Console.WriteLine("Started GetWorkFlowWorkSpaceParallel for projectId: " + projectId +
                                  " and StatementId: " + stmtId);
                #region Start pre-process

                var lstTreeView = new List <TreeView>();
                var secondTab   = new List <TreeView>();

                var startClasses = await _codeVortoService.ActionWorkflowsRepository
                                   .GetAllListItems(p => p.MethodStatementId != 0 &&
                                                    p.ProjectId == projectId && p.Processed == 0).ConfigureAwait(false);

                var actionWorkflows = (from s in startClasses where s.MethodStatementId == stmtId select s).ToList().First();
                if (actionWorkflows.FileId == 0)
                {
                    return(Ok("Action Workflow processed successfully."));
                }

                stringBuilder.AppendLine("=====================================================");
                stringBuilder.AppendLine("\n" + "Called stored procedure: SpBaseStatementMaster : " + projectId + "," + actionWorkflows);

                string sqlQuery = " SELECT * from statementreferencemaster " +
                                  " Where FileId = " + actionWorkflows.FileId + " AND BaseCommandId = 19;";
                var baseStatementMaster = await _codeVortoService.StatementReferenceMasterRepository
                                          .GetDataFromSqlQuery <StatementReferenceMaster>(sqlQuery).ConfigureAwait(false);

                stringBuilder.AppendLine("=================================================");
                stringBuilder.AppendLine("\n" + "Started process for get block: GetMethodBlock for statememtId: " + stmtId + ")");
                var workflowRef = await GetMethodBlock(stmtId).ConfigureAwait(false);

                if (!workflowRef.Any())
                {
                    return(Ok("Workflow data collected successfully"));
                }

                int currentFileId         = actionWorkflows.FileId;
                var isThisProgramIdExists = await _codeVortoService.FirstTabProgramDetailsRepository
                                            .GetAllListItems(e => e.ProgramId == currentFileId).ConfigureAwait(false);

                if (isThisProgramIdExists.Any())
                {
                    return(Ok("Workflow data collected successfully"));
                }

                var jclMenuTitle = startClasses.First().OriginObject;

                var bId         = workflowRef[0].BaseCommandId;
                var statementId = workflowRef[0].StatementId;
                var treeNodeId  = 1;
                lstTreeView.Add(new TreeView
                {
                    GraphId                  = "StartNode_1",
                    GraphName                = "<span class='nodeToBold'>" + jclMenuTitle + "</span>",
                    HasChild                 = true,
                    ParentId                 = "-1",
                    BaseCommandId            = baseStatementMaster[0].BaseCommandId,
                    StatementReferenceMaster = workflowRef[0],
                    SpriteCssClass           = jclMenuTitle,
                    ActualStatementId        = "Actual_" + baseStatementMaster[0].StatementId,
                    NodeId      = treeNodeId,
                    IndentLevel = 0
                });
                // This is Method start statement...
                lstTreeView.Add(new TreeView
                {
                    GraphId                  = "MethodNode_" + statementId,
                    GraphName                = "<span class='nodeToBold'>" + workflowRef[0].OriginalStatement + "</span>",
                    HasChild                 = true,
                    ParentId                 = "StartNode_1",
                    BaseCommandId            = bId,
                    StatementReferenceMaster = workflowRef[0],
                    ActualStatementId        = "Actual_" + statementId,
                    NodeId      = ++treeNodeId,
                    IndentLevel = 1
                });
                workflowRef.RemoveAt(0);

                lstTreeView.AddRange(workflowRef.Select(statementMaster => new TreeView
                {
                    ActualStatementId        = "Actual_" + statementMaster.StatementId,
                    GraphId                  = "Node_" + statementMaster.StatementId,
                    GraphName                = statementMaster.OriginalStatement,
                    HasChild                 = false,
                    SpriteCssClass           = "",
                    ParentId                 = "MethodNode_" + statementId,
                    BaseCommandId            = statementMaster.BaseCommandId,
                    PrimaryCommandId         = statementMaster.PrimaryCommandId,
                    ClassCalled              = statementMaster.ClassCalled,
                    MethodCalled             = statementMaster.MethodCalled,
                    StatementReferenceMaster = statementMaster,
                    AlternateName            = statementMaster.AlternateName,
                    NodeId      = ++treeNodeId,
                    IndentLevel = 2
                }));

                #endregion

                var copyOfLstTreeView = new List <TreeView>();
                copyOfLstTreeView.AddRange(lstTreeView);

                foreach (var treeItem in copyOfLstTreeView)
                {
                    if (treeItem.BaseCommandId != 5 && treeItem.StatementReferenceMaster.OtherBaseCommandId != 5)
                    {
                        continue;
                    }
                    treeItem.BaseCommandId = 5;
                    treeItem.ProgramId     = treeItem.StatementReferenceMaster.ReferenceFileId;
                }
                foreach (var treeItem in copyOfLstTreeView)
                {
                    if (treeItem.BaseCommandId != 6)
                    {
                        continue;
                    }
                    treeItem.MethodCalled = treeItem.StatementReferenceMaster.MethodCalled;
                    treeItem.ProgramId    = treeItem.StatementReferenceMaster.ReferenceFileId;
                }

                #region Process for base command id = 5 and 6

                copyOfLstTreeView.Where(a => a.BaseCommandId == 10).ToList().ForEach(b => { b.Done = false; });
                copyOfLstTreeView = copyOfLstTreeView.DistinctBy().ToList();

                copyOfLstTreeView = copyOfLstTreeView.IfBlockStatement(copyOfLstTreeView);
                copyOfLstTreeView = copyOfLstTreeView.LoopBlockStatement(copyOfLstTreeView);
                copyOfLstTreeView = copyOfLstTreeView.ElseBlockStatement(copyOfLstTreeView);

                secondTab.Add(lstTreeView.ElementAt(0));
                secondTab.Add(lstTreeView.ElementAt(1));
                secondTab.AddRange(copyOfLstTreeView
                                   .Where(
                                       item => item.BaseCommandId == 6 ||
                                       item.BaseCommandId == 8 ||
                                       item.BaseCommandId == 10 ||
                                       item.BaseCommandId == 1 ||
                                       item.BaseCommandId == 25 ||
                                       item.BaseCommandId == 5 ||
                                       item.BaseCommandId == 30 ||
                                       item.BaseCommandId == 3 ||
                                       item.BaseCommandId == 4 ||
                                       item.BaseCommandId == 45));
                var tempList =
                    (from d in secondTab
                     where d.BaseCommandId == 1 ||
                     d.BaseCommandId == 10 ||
                     d.BaseCommandId == 25 || d.BaseCommandId == 3
                     select d).ToList();
                foreach (var sTab in tempList)
                {
                    var childItems = (from s in copyOfLstTreeView where s.ParentId == sTab.GraphId select s).ToList();
                    secondTab.AddRange(childItems);
                }

                secondTab = secondTab.Distinct().ToList();
                secondTab = secondTab.OrderBy(k => k.NodeId).ToList();

                #endregion

                var allSeqListItems = new List <TreeView>();
                foreach (var curItem in secondTab)
                {
                    stringBuilder.AppendLine("Started process for attchchilditems: AttachChildItems(" + projectId + ")");
                    allSeqListItems.Add(curItem);
                    var childItems = (from s in secondTab where s.ParentId == curItem.GraphId select s).ToList();
                    foreach (var cItem in childItems)
                    {
                        allSeqListItems = allSeqListItems.AttachChildItems(secondTab, cItem);
                    }
                    break;
                }
                allSeqListItems = allSeqListItems.DistinctBy().ToList();

                #region Process the details

                // ReSharper disable once RedundantAssignment
                var actionWorkflow = await _codeVortoService.ActionWorkflowsRepository
                                     .GetEntityData <ActionWorkflows>
                                         (s => s.MethodStatementId == statementId && s.ProjectId == projectId).ConfigureAwait(false);

                var secondTabDetails = allSeqListItems.Select(sTab => new WorkflowTreeviewSecondTabDetails
                {
                    BaseCommandId            = sTab.BaseCommandId,
                    ProjectId                = projectId,
                    ActionWorkflowId         = actionWorkflow.First().ActionWorkflowId,
                    ActualStatementId        = sTab.ActualStatementId,
                    ClassCalled              = sTab.ClassCalled,
                    GraphId                  = sTab.GraphId,
                    GraphName                = sTab.GraphName,
                    AlternateName            = sTab.AlternateName,
                    HasChild                 = sTab.HasChild.ToString(),
                    MethodCalled             = sTab.MethodCalled,
                    ParentId                 = sTab.ParentId,
                    PrimaryCommandId         = sTab.PrimaryCommandId,
                    SpriteCssClass           = sTab.SpriteCssClass,
                    WorkflowStartStatementId = actionWorkflow.First().MethodStatementId,
                    StatementId              = sTab.StatementReferenceMaster.StatementId,
                    IndentLevel              = sTab.IndentLevel,
                    ProgramId                = sTab.StatementReferenceMaster.ReferenceFileId,
                    AnnotateStatement        = null
                }).ToList();
                var generalRepositorySecondTabDetails =
                    new GeneralRepository <WorkflowTreeviewSecondTabDetails>(new AppDbContext());
                int actionWorkFlowId       = actionWorkflow.First().ActionWorkflowId;
                int methodStartStatementId = actionWorkflow.First().MethodStatementId;
                // Before inserting these records, check whether this table has already data for this action workflow id.
                var generalRepositoryFirstDetails = new GeneralRepository <WorkflowTreeviewTabFirstDetails>(new AppDbContext());

                var chkHasResults = await generalRepositoryFirstDetails
                                    .GetAllListItems(t => t.ActionWorkflowId == actionWorkFlowId &&
                                                     t.WorkflowStartStatementId == methodStartStatementId).ConfigureAwait(false);

                if (!chkHasResults.Any())
                {
                    await generalRepositorySecondTabDetails.BulkInsert(secondTabDetails).ConfigureAwait(false);
                }

                string mySqlQry = " Select * from WorkflowTreeviewSecondTabDetails Where " +
                                  " ProjectId = " + projectId + " AND WorkflowStartStatementId = " + statementId + " ";

                if (!chkHasResults.Any())
                {
                    var statementSecTab = await generalRepositorySecondTabDetails
                                          .GetDataFromSqlQuery <WorkflowTreeviewSecondTabDetails>(mySqlQry).ConfigureAwait(false);

                    foreach (var stmt in statementSecTab)
                    {
                        if (stmt.BaseCommandId != 1 && stmt.BaseCommandId != 5 && stmt.BaseCommandId != 6)
                        {
                            continue;
                        }
                        stmt.GraphName = stmt.GraphName + "&nbsp;<img id='imgpseudo' src='images/regex_icon.png' " +
                                         "onclick='pseudoCodeDialog(" + stmt.ProgramId + ")'/>";
                        await generalRepositorySecondTabDetails.UpdateItem(stmt).ConfigureAwait(false);
                    }
                }

                var lstTabFirstDetails = copyOfLstTreeView.Select(fTab => new WorkflowTreeviewTabFirstDetails
                {
                    BaseCommandId            = fTab.BaseCommandId,
                    ProjectId                = projectId,
                    ActionWorkflowId         = actionWorkflow.First().ActionWorkflowId,
                    ActualStatementId        = fTab.ActualStatementId,
                    ClassCalled              = fTab.ClassCalled,
                    GraphId                  = fTab.GraphId,
                    GraphName                = fTab.GraphName,
                    HasChild                 = fTab.HasChild.ToString(),
                    MethodCalled             = fTab.MethodCalled,
                    ParentId                 = fTab.ParentId,
                    PrimaryCommandId         = fTab.PrimaryCommandId,
                    SpriteCssClass           = fTab.SpriteCssClass,
                    WorkflowStartStatementId = actionWorkflow.First().MethodStatementId,
                    IndentLevel              = fTab.IndentLevel,
                    ProgramId                = fTab.StatementReferenceMaster.ReferenceFileId
                }).ToList();

                if (!chkHasResults.Any())
                {
                    await generalRepositoryFirstDetails.BulkInsert(lstTabFirstDetails).ConfigureAwait(false);
                }

                // Forth tabs data is about Nodes and Links which are created from second tabs data, so we will add default node
                // from seconds tabs first element, which is a starting point of workflow.

                var generalRepositoryNodeDetails =
                    new GeneralRepository <WorkflowNodeDetails>(new AppDbContext());
                var workflowMaxNode = await generalRepositoryNodeDetails.GetDataFromSqlQuery <WorkflowNodeDetails>(
                    "SELECT * FROM workflownodedetails ORDER BY RowId DESC LIMIT 1;").ConfigureAwait(false);

                var nodeId = 1;
                if (workflowMaxNode.Any())
                {
                    nodeId = workflowMaxNode[0].MaxNodeId;
                    nodeId = nodeId + 1;
                }

                var listNodes = new List <Node>();
                var treeView  = new TreeViewData
                {
                    Nodes = listNodes
                };

                var widthCnt = Convert.ToInt32(jclMenuTitle.Length.ToString()) * 3;
                treeView.Nodes.Add(new Node
                {
                    Id          = nodeId,
                    Name        = jclMenuTitle.ToUpper(),
                    ShapeId     = "Circle",
                    Color       = "#ffcc00",
                    Width       = widthCnt.ToString(),
                    StatementId = int.Parse(secondTab.First().ActualStatementId.Split('_')[1]),
                    GroupName   = secondTab.First().GroupName,
                    GroupId     = secondTab.First().GroupId,
                    ProgramId   = secondTab.First().ProgramId
                });

                var lstWorkflowNodeDetails = treeView.Nodes.Select(node => new WorkflowNodeDetails
                {
                    ProjectId                = projectId,
                    BaseCommandId            = node.BaseCommandId,
                    ActionWorkflowId         = actionWorkflow.First().ActionWorkflowId,
                    BusinessDescription      = node.BusinessDescription,
                    BusinessName             = node.BusinessName,
                    WorkflowStartStatementId = actionWorkflow.First().MethodStatementId,
                    ParentId        = node.ParentId,
                    Id              = node.Id,
                    StatementId     = node.StatementId,
                    StatementTypeId = node.StatementTypeId,
                    ChildId         = node.ChildId,
                    FileId          = node.FileId,
                    Width           = node.Width,
                    Name            = node.Name.Replace("</span>", "").Trim(),
                    Height          = node.Height,
                    ShapeId         = node.ShapeId,
                    Color           = node.Color,
                    MaxNodeId       = nodeId,
                    GroupName       = node.GroupName,
                    GroupId         = node.GroupId,
                    ProgramId       = node.ProgramId
                }).ToList();

                generalRepositoryNodeDetails = new GeneralRepository <WorkflowNodeDetails>(new AppDbContext());
                if (!chkHasResults.Any())
                {
                    await generalRepositoryNodeDetails.BulkInsert(lstWorkflowNodeDetails).ConfigureAwait(false);
                }

                // Since now we have all records about primary first and second tabs data,
                // then check whether those programs / Jcls are processed or not.
                // If not, then process those and then insert those records into FirstTabProgramDetails and
                // SecondTabProgramDetails tables respectively...

                // Both the tables will contain data from same program, so we will start processing from first tab data...
                #endregion

                Console.WriteLine("====================================");
                LogMessage.WriteLogMessage(stringBuilder);
                return(Ok("Workflow data collected successfully"));
            }
        }
        public async Task <IHttpActionResult> GetAllStartingPoints(int projectId)
        {
            using (_codeVortoService = new CodeVortoService())
            {
                var stringBuilder = new StringBuilder();
                stringBuilder.AppendLine(
                    "========================================================================================");
                stringBuilder.AppendLine("\n" + "Started to collect all actionworkflow for project: " + projectId);

                string selectSql = " SELECT * FROM actionworkflows where ProjectId = " + projectId +
                                   " and MethodStatementId != 0 AND (EndPointOrService = 'Service' OR EndPointOrService = 'Batch') " +
                                   " AND CreatedBy = 1 AND Processed = 0; ";

                var workflowRef = await _codeVortoService.ActionWorkflowsRepository
                                  .GetDataFromSqlQuery <ActionWorkflows>(selectSql).ConfigureAwait(false);

                var projectMaster = _codeVortoService.ProjectMasterRepository.GetItem(projectId);
                if (!workflowRef.Any())
                {
                    return(Ok("All Workflow processed successfully"));
                }

                workflowRef[0].ProjectMaster = projectMaster;
                var lstWorkflowRef = workflowRef.ToList();

                foreach (var workflow in lstWorkflowRef)
                {
                    try
                    {
                        if (workflow.ProjectId == null)
                        {
                            return(NotFound());
                        }
                        var workFlowProjectId = workflow.ProjectId ?? 0;
                        stringBuilder.AppendLine(
                            "========================================================================================");
                        stringBuilder.AppendLine("\n" + "Started executing next process: GetWorkFlowWorkSpaceParallel for projectId:" +
                                                 workFlowProjectId + ", and MethodStatementId is:" + workflow.MethodStatementId + ")");

                        var actionResult =
                            await GetWorkFlowWorkSpaceParallel(workFlowProjectId, workflow.MethodStatementId)
                            .ConfigureAwait(false);

                        var dataContent = await actionResult.ExecuteAsync(CancellationToken.None).ConfigureAwait(false);

                        var responseMessage =
                            await dataContent.Content.ReadAsStringAsync().ConfigureAwait(false);

                        if (responseMessage == "\"Too Many Nodes\"")
                        {
                            Console.WriteLine("Too Many Nodes for ActionWorkflowId: " + workflow.ActionWorkflowId);
                            Console.WriteLine("Origin file path: " + workflow.OriginFilePath);
                            Console.WriteLine("=======================================================");
                            continue;
                        }
                        workflow.FileMaster    = null;
                        workflow.Processed     = 1;
                        workflow.ProjectMaster = null;
                        await _codeVortoService.ActionWorkflowsRepository.UpdateItem(workflow).ConfigureAwait(false);
                    }
                    catch (Exception exception)
                    {
                        LogMessage.WriteExceptionLogMessage(exception);
                    }
                }
                // ApplyPseudoCodeConversion(projectId);
                stringBuilder.AppendLine(
                    "========================================================================================");
                LogMessage.WriteLogMessage(stringBuilder);
                return(Ok("All Workflow processed successfully"));
            }
        }