예제 #1
0
        private async void buttonCreate_Click(object sender, EventArgs e)
        {
            if (m_zooKeeperClient == null)
            {
                MessageBox.Show("No Connection.", "Info");
                return;
            }

            var selectedNode = treeViewNodes.SelectedNode;

            if (selectedNode != null)
            {
                NodeInfoForm nodeInfoForm = new NodeInfoForm();
                nodeInfoForm.NodeName = "NewNode";
                nodeInfoForm.Text     = "NewNode";
                nodeInfoForm.ACLs     = new List <org.apache.zookeeper.data.ACL>()
                {
                    new org.apache.zookeeper.data.ACL(31, new org.apache.zookeeper.data.Id("world", "anyone"))
                };
                nodeInfoForm.ShowDialog();
                if (MessageBox.Show($"Are You Sure To Add {nodeInfoForm.NodeName}?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    try
                    {
                        var    data = nodeInfoForm.Data;
                        var    acls = nodeInfoForm.ACLs;
                        string path = await m_zooKeeperClient.createAsync(Combine(selectedNode.Name, nodeInfoForm.NodeName), data, acls, nodeInfoForm.CreateMode);

                        selectedNode.Nodes.Add(path, GetNodeName(path));
                        Log($"Added {path}.");
                    }
                    catch (KeeperException ex)
                    {
                        Log($"{ex.Message} {Combine(selectedNode.Name, nodeInfoForm.NodeName)}");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error");
                    }
                }
            }
            else
            {
                MessageBox.Show("No Node Selected.", "Info");
            }
        }
예제 #2
0
        private async Task ShowNodeInfo()
        {
            var selectedNode = treeViewNodes.SelectedNode;

            if (selectedNode != null)
            {
                try
                {
                    var dataResult = await m_zooKeeperClient.getDataAsync(selectedNode.Name);

                    var aCLResult = await m_zooKeeperClient.getACLAsync(selectedNode.Name);

                    NodeInfoForm nodeInfoForm = new NodeInfoForm();
                    nodeInfoForm.NodeName = selectedNode.Text;
                    nodeInfoForm.Text     = selectedNode.Name;
                    nodeInfoForm.Data     = dataResult.Data ?? (new byte[0]);
                    nodeInfoForm.ACLs     = aCLResult.Acls;
                    nodeInfoForm.Stat     = aCLResult.Stat;
                    nodeInfoForm.ShowDialog();

                    bool dataChanged = true;
                    bool aclsChanged = true;
                    var  data        = nodeInfoForm.Data;
                    if (Convert.ToBase64String(dataResult.Data ?? (new byte[0])) == Convert.ToBase64String(data))
                    {
                        dataChanged = false;
                    }

                    var acls = nodeInfoForm.ACLs;
                    if (aCLResult.Acls.Count == acls.Count && aCLResult.Acls.All(acl => acls.Exists(i => i.getPerms() == acl.getPerms() && i.getId().getScheme() == acl.getId().getScheme() && i.getId().getId() == acl.getId().getId())))
                    {
                        aclsChanged = false;
                    }

                    if (dataChanged || aclsChanged)
                    {
                        if (MessageBox.Show("Do You Want To Update The Modification", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                        {
                            if (dataChanged)
                            {
                                await m_zooKeeperClient.setDataAsync(selectedNode.Name, data);

                                Log($"Data seted {selectedNode.Name}.");
                            }

                            if (aclsChanged)
                            {
                                await m_zooKeeperClient.setACLAsync(selectedNode.Name, acls);

                                Log($"ACL seted {selectedNode.Name}.");
                            }
                        }
                    }
                }
                catch (KeeperException ex)
                {
                    Log($"{ex.Message} {selectedNode.Name}");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                }
            }
            else
            {
                MessageBox.Show("No Node Selected.", "Info");
            }
        }