Ejemplo n.º 1
0
        /// <summary>
        ///  MATCH(a),(b)
        ///  WHERE ID(a) = $fromNodeId AND ID(b) = $toNodeId
        ///  CREATE (a)-[r: $relType $variables ]->(b)
        /// </summary>
        /// <param name="fromNodeId"></param>
        /// <param name="toNodeId"></param>
        /// <param name="relType"></param>
        /// <param name="variables"></param>
        public void Relate(PendingNode fromNodeId, PendingNode toNodeId, Model.MEPEdgeTypes relType, Dictionary <string, object> variables)
        {
            var qlSafeVariables = new Dictionary <string, object>();

            if (variables != null)
            {
                foreach (var kvp in variables)
                {
                    var qlSafeName = Utils.GetGraphQLCompatibleFieldName(kvp.Key);
                    if (!qlSafeVariables.ContainsKey(qlSafeName))
                    {
                        qlSafeVariables.Add(qlSafeName, kvp.Value);
                    }
                }
            }


            Dictionary <string, object> props = new Dictionary <string, object>();

            props.Add("frid", fromNodeId.TempId);
            props.Add("toid", toNodeId.TempId);

            string query = string.Empty;

            if (qlSafeVariables != null && qlSafeVariables.Count > 0)
            {
                props.Add("cvar", qlSafeVariables);
                query =
                    string.Format("MATCH(a: {0} {{TempId: $frid}}),(b:{1} {{TempId: $toid}})", fromNodeId.NodeName, toNodeId.NodeName) +
                    string.Format("CREATE (a)-[r:{0} $cvar]->(b) ", relType);
            }
            else
            {
                query =
                    string.Format("MATCH(a: {0} {{TempId: $frid}}),(b:{1} {{TempId: $toid}})", fromNodeId.NodeName, toNodeId.NodeName) +
                    string.Format("CREATE (a)-[r:{0}]->(b) ", relType);
            }

            var pec = new PendingCypher();

            pec.Query = query;
            pec.Props = props;

            pec.Committed = (IStatementResult result) =>
            {
                var rs = result;
            };

            pec.FromNode = fromNodeId;
            pec.ToNode   = toNodeId;
            pec.RelType  = relType;

            relateStack.Enqueue(pec);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  MATCH(a),(b)
        ///  WHERE ID(a) = $fromNodeId AND ID(b) = $toNodeId
        ///  CREATE (a)-[r: $relType $variables ]->(b)
        /// </summary>
        /// <param name="fromNodeId"></param>
        /// <param name="toNodeId"></param>
        /// <param name="relType"></param>
        /// <param name="variables"></param>
        public void Relate(long fromNodeId, long toNodeId, Model.MEPEdgeTypes relType, Dictionary <string, object> variables)
        {
            Dictionary <string, object> props = new Dictionary <string, object>();

            props.Add("auid", fromNodeId);
            props.Add("buid", toNodeId);

            string query = string.Empty;

            if (variables != null && variables.Count > 0)
            {
                props.Add("cvar", variables);
                query =
                    "MATCH(a),(b)" +
                    "WHERE ID(a) = $auid AND ID(b) = $buid " +
                    string.Format("CREATE (a)-[r: {0} $cvar]->(b) ", relType);
            }
            else
            {
                query =
                    "MATCH(a),(b)" +
                    "WHERE ID(a) = $auid AND ID(b) = $buid " +
                    string.Format("CREATE (a)-[r: {0}]->(b) ", relType);
            }


            using (var session = _driver.Session())
            {
                var greeting = session.WriteTransaction(tx =>
                {
                    var result = props.Count > 0 ? tx.Run(query, props) : tx.Run(query);
                    return(result);
                });

                Console.WriteLine(greeting);
            }
        }