Esempio n. 1
0
        /// <summary>
        /// Add the map in the graph database neo4j.
        /// </summary>
        public string AddLoadedMapIntoNeo4J()
        {
            List <City> citys = LoadCities();

            string connectionString = ConfigurationManager.AppSettings.Get("ne4jDBConnection");

            if (string.IsNullOrEmpty(connectionString))
            {
                return("err:Missing set for connection string in Web.confing file.");
            }

            string errorMessage;
            var    client = new Neo4J(connectionString, out errorMessage);

            if (!string.IsNullOrEmpty(errorMessage))
            {
                return(string.Format("err:Can not connect to the database.{0}", errorMessage));
            }

            client.CreateNodes(citys, "city:City", "newCity", out errorMessage);

            if (!string.IsNullOrEmpty(errorMessage))
            {
                return(string.Format("err:Can not create nodes in database.{0}", errorMessage));
            }

            return("The map was successfully uploaded into the database.");
        }
Esempio n. 2
0
        private async Task RegisterIncidentAtElasticAsync(string host, VTShortReport shortReport, string restrictingPolicy)
        {
            var incident          = new EventIncident(host, shortReport.md5, shortReport.full_class, restrictingPolicy);
            var firstOccurrenceIp = await Elastic.FindFirstOccurrenceIpByFileHash(shortReport.md5);

            var paths = await Neo4J.FindAllPaths(firstOccurrenceIp, host);

            incident.SetPossibleRoutes(paths);
            incident.ExcludeRestrictedRoutes(shortReport, Redis);

            await Logstash.SendEventAsync(incident);
        }
Esempio n. 3
0
        public async Task <bool> PushNewHost(string ip)
        {
            string subnetIp = await Neo4J.PushHostRaw(ip);

            if (subnetIp != default)
            {
                var parentSubnetPolicies = Redis.GetHostWildcards(subnetIp);

                await foreach (string policy in parentSubnetPolicies)
                {
                    await Postgres.AttachPolicy(ip, policy);
                }
            }

            if (!await Postgres.InsertNewOne(ip))
            {
                return(false);
            }

            await UpdateRedisStorage();

            return(true);
        }
Esempio n. 4
0
        public void CheckConnectionAndInsert()
        {
            //check connection to db
            string error;
            var    conn = new Neo4J("http://*****:*****@localhost:7474/db/data", out error);

            //check for exists
            var res = conn.Client.Cypher
                      .Match("(city:City)")
                      .Where((City city) => city.label == "Sofia")
                      .Return(city => city.As <City>())
                      .Results;

            //delete from db neo4j
            conn.Client.Cypher.Match("(city:City)").Where((City city) => city.label != "DEL").Delete("city").ExecuteWithoutResults();
            return;

            foreach (ICity newCity in (new List <City>()
            {
                new City()
                {
                    label = "Sofia", x = 25.4f, y = 50.1f, Neighbors = new List <INeighbor>()
                    {
                        new Neighbor()
                        {
                            Name = "Plovdiv"
                        }, new Neighbor()
                        {
                            Name = "Veliko Tyrnovo"
                        }
                    }
                },
                new City()
                {
                    label = "Plovdiv", x = 125.5f, y = 75f
                },
                new City()
                {
                    label = "Veliko Tyrnovo", x = 205.4f, y = 150.1f
                }
            }))
            {
                //create node
                conn.Client.Cypher
                .Create("(city:City {newCity})")
                .WithParam("newCity", newCity)
                .ExecuteWithoutResults();

                if (newCity.Neighbors != null)
                {
                    foreach (INeighbor neighbor in newCity.Neighbors)
                    {
                        //create connections
                        conn.Client.Cypher
                        .Match("(city1:City)", "(city2:City)")
                        .Where((City city1) => city1.label == newCity.label)
                        .AndWhere((City city2) => city2.label == neighbor.Name)
                        .CreateUnique("city1-[:FRIENDS_WITH]->city2")
                        .ExecuteWithoutResults();
                    }
                }
            }
        }