Example #1
0
        public List<Node> GetAllNode()
        {
            List<Node> nodes = new List<Node>();
            using (var ctx = new ShardClusterDBContext(masterConnectionString))
            {
                var result = (from n in ctx.Nodes
                              join t in ctx.Tokens on n.NodeID equals t.NodeId
                              select new
                              {
                                  NodeID = n.NodeID,
                                  ConnectionString = n.ConnectionString,
                                  Tokens = t.TokenKey
                              }).ToList();

                foreach (var r in result.GroupBy(g => new { g.NodeID, g.ConnectionString }, g => g.Tokens))
                {
                    List<Token> tokens = new List<Token>();
                    foreach (var value in r)
                    {
                        tokens.Add(new Token(value, r.Key.NodeID));
                    }

                    nodes.Add(new Node(r.Key.NodeID, r.Key.ConnectionString, tokens));
                }
            }

            return nodes;
        }
Example #2
0
        public List <Node> GetAllNode()
        {
            List <Node> nodes = new List <Node>();

            using (var ctx = new ShardClusterDBContext(masterConnectionString))
            {
                var result = (from n in ctx.Nodes
                              join t in ctx.Tokens on n.NodeID equals t.NodeId
                              select new
                {
                    NodeID = n.NodeID,
                    ConnectionString = n.ConnectionString,
                    Tokens = t.TokenKey
                }).ToList();

                foreach (var r in result.GroupBy(g => new { g.NodeID, g.ConnectionString }, g => g.Tokens))
                {
                    List <Token> tokens = new List <Token>();
                    foreach (var value in r)
                    {
                        tokens.Add(new Token(value, r.Key.NodeID));
                    }

                    nodes.Add(new Node(r.Key.NodeID, r.Key.ConnectionString, tokens));
                }
            }

            return(nodes);
        }
Example #3
0
 public void AddToken(Node node)
 {
     using (var ctx = new ShardClusterDBContext(masterConnectionString))
     {
         ctx.Tokens.AddRange(node.Tokens);
         ctx.SaveChanges();
     }
 }
Example #4
0
 public void AddNode(Node node)
 {
     using (var ctx = new ShardClusterDBContext(masterConnectionString))
     {
         ctx.Nodes.Add(node);
         ctx.SaveChanges();
     }
 }
Example #5
0
 public void AddToken(Node node)
 {
     using (var ctx = new ShardClusterDBContext(masterConnectionString))
     {
         ctx.Tokens.AddRange(node.Tokens);
         ctx.SaveChanges();
     }
 }
Example #6
0
 public void AddNode(Node node)
 {
     using (var ctx = new ShardClusterDBContext(masterConnectionString))
     {
         ctx.Nodes.Add(node);
         ctx.SaveChanges();
     }
 }
Example #7
0
 public Node GetNode(Guid nodeId)
 {
     using (var ctx = new ShardClusterDBContext(masterConnectionString))
     {
         return (from n in ctx.Nodes
                 where n.NodeID == nodeId
                 select n).FirstOrDefault();
     }
 }
Example #8
0
 public Node GetNode(Guid nodeId)
 {
     using (var ctx = new ShardClusterDBContext(masterConnectionString))
     {
         return((from n in ctx.Nodes
                 where n.NodeID == nodeId
                 select n).FirstOrDefault());
     }
 }
Example #9
0
 public void RemoveNode(Node node)
 {
     using (var ctx = new ShardClusterDBContext(masterConnectionString))
     {
         ctx.Nodes.Attach(node);
         ctx.Nodes.Remove(node);
         ctx.SaveChanges();
     }
 }
Example #10
0
 public void RemoveNode(Node node)
 {
     using (var ctx = new ShardClusterDBContext(masterConnectionString))
     {
         ctx.Nodes.Attach(node);
         ctx.Nodes.Remove(node);
         ctx.SaveChanges();
     }
 }