Esempio n. 1
0
        private string SendFileToRemoteNeo4j(LoadRequest loadRequest, string fullFilePath)
        {
            string path     = string.Empty;
            int    tryCount = 0;
            bool   loaded   = false;

            while (loaded == false && tryCount < 3)
            {
                tryCount++;

                try
                {
                    var randomizedFileName = Guid.NewGuid().ToString() + ".csv";
                    var ftpPath            = "CSV/" + randomizedFileName;
                    _ftpService.UploadFile(loadRequest.FtpBaseUrl, ftpPath, File.ReadAllText(fullFilePath));

                    path = loadRequest.NeoCsvFolder + "\\" + randomizedFileName;

                    loaded = true;
                }
                catch (Exception)
                {
                    if (tryCount == 3)
                    {
                        throw;
                    }
                }
            }

            return(path);
        }
Esempio n. 2
0
        public void DeleteApplication(LoadRequest loadRequest, string applicationName, string graphType)
        {
            var query = "MATCH (n { app_domain: '" + applicationName + "', graph_type: '" + graphType + "' })-[r]-() DELETE r";

            ExecuteQuery(loadRequest.Neo4jUrl, query);
            query = "MATCH (n { app_domain: '" + applicationName + "', graph_type: '" + graphType + "' }) DELETE n";
            ExecuteQuery(loadRequest.Neo4jUrl, query);
        }
Esempio n. 3
0
        public void BulkLoadCsv(LoadRequest loadRequest, string csvFolderPath)
        {
            var folder = new DirectoryInfo(csvFolderPath);

            if (!folder.GetFiles().Any(x => x.Name.EndsWith("csv")))
            {
                return;
            }

            DeleteApplication(loadRequest, loadRequest.ApplicationName, loadRequest.GraphType);
            LoadMethodNodes(loadRequest, csvFolderPath);
            LoadResourceAccesses(loadRequest, csvFolderPath);
            LoadMethodToMethodRelationships(loadRequest, csvFolderPath);
            LoadMethodToResourceRelationships(loadRequest, csvFolderPath);
        }
Esempio n. 4
0
        public void LoadMethodToResourceRelationships(LoadRequest loadRequest, string csvFileFolderPath)
        {
            var folder   = new DirectoryInfo(csvFileFolderPath);
            var csvFiles = folder.GetFiles().Where(x => x.Name.StartsWith("resource_relationships")).ToList();

            foreach (var csvFile in csvFiles)
            {
                string neo4jCsvFileName = csvFile.FullName;
                if (loadRequest.Locality == Locality.Remote)
                {
                    neo4jCsvFileName = SendFileToRemoteNeo4j(loadRequest, csvFile.FullName);
                }
                ExecuteMethodToResourceQuery(loadRequest.Neo4jUrl, neo4jCsvFileName);
            }
        }
Esempio n. 5
0
        public void LoadResourceAccesses(LoadRequest loadRequest, string csvFileFolderPath)
        {
            var folder   = new DirectoryInfo(csvFileFolderPath);
            var csvFiles = folder.GetFiles().Where(x => x.Name.StartsWith("resources")).ToList();

            foreach (var csvFile in csvFiles)
            {
                string fileName = csvFile.FullName;
                if (loadRequest.Locality == Locality.Remote)
                {
                    fileName = SendFileToRemoteNeo4j(loadRequest, csvFile.FullName);
                }
                ExecuteResourceAccessNodeQuery(loadRequest.Neo4jUrl, fileName);
            }

            string indexQuery = "CREATE INDEX ON :ResourceAccess(id)";

            ExecuteQuery(loadRequest.Neo4jUrl, indexQuery);
        }
Esempio n. 6
0
        public void LoadMethodNodes(LoadRequest loadRequest, string csvFileFolderPath)
        {
            var folder          = new DirectoryInfo(csvFileFolderPath);
            var methodNodeFiles = folder.GetFiles().Where(x => x.Name.StartsWith("methods")).ToList();

            foreach (var methodNodeFile in methodNodeFiles)
            {
                string neo4jCsvfileName = methodNodeFile.FullName;
                if (loadRequest.Locality == Locality.Remote)
                {
                    neo4jCsvfileName = SendFileToRemoteNeo4j(loadRequest, methodNodeFile.FullName);
                }
                ExecuteMethodNodeQuery(loadRequest.Neo4jUrl, neo4jCsvfileName);
            }

            string fromIndexQuery = "CREATE INDEX ON :Method(from_id)";

            ExecuteQuery(loadRequest.Neo4jUrl, fromIndexQuery);

            string toIndexQuery = "CREATE INDEX ON :Method(to_id)";

            ExecuteQuery(loadRequest.Neo4jUrl, toIndexQuery);
        }