예제 #1
0
        private async Task DeleteCurrentChatProfile()
        {
            if (cbxChatProfiles.Items.Count > 1)
            {
                var profile = cbxChatProfiles.SelectedItem?.ToString();
                if (DataProviders.ConfirmDialog($"Do you want to permanently delete chat profile '{profile}'?\n\n" +
                                                $"This action will automatically set next available profile as active profile.", "MenuActionDelete confirmation", MessageBoxIcon.Warning))
                {
                    await DbBotCollection.RemoveChatProfileById(BotAlphaName, profile);

                    await DbBotCollection.SetActiveChatProfileById(BotAlphaName, null); //Set active profile to null
                    await LoadChatProfiles();

                    await DbBotCollection.SetActiveChatProfileById(BotAlphaName, cbxChatProfiles.SelectedItem?.ToString());
                }
            }
        }
예제 #2
0
        private async void actionMenu_Clicked(object sender, ToolStripItemClickedEventArgs e)
        {
            var clicked = e.ClickedItem.AccessibilityObject.Name;
            {
                if (neuralTree.SelectedNode != null)
                {
                    switch (clicked)
                    {
                    case MenuActionNew:
                    {
                        var newNode = await DbLinkCollection.InsertChildById(neuralTree.SelectedNode.Name, new NeuralLinkModel { Name = "New node" });

                        var newTreeNode = neuralTree.SelectedNode.Nodes.Add(newNode._id, newNode.Name);
                        newTreeNode.Tag         = newNode;
                        neuralTree.SelectedNode = newTreeNode;
                        ReloadTree();
                    }
                    break;

                    case MenuActionDelete:
                    {
                        if (DataProviders.ConfirmDialog($"Do you want to permanently delete node '{neuralTree.SelectedNode.Text}'?\n\n" +
                                                        $"Warning: This will also deletes from all the references to this node in other parent nodes of this.\n\n" +
                                                        $"Note: Refresh tree to view the updated changes.", "MenuActionDelete confirmation", MessageBoxIcon.Warning))
                        {
                            var node = (NeuralLinkModel)neuralTree.SelectedNode.Tag;
                            await DbLinkCollection.RemoveAndUnlinkFromParents(node);

                            await DbTrainDataCollection.RemoveOneById(node._id);

                            neuralTree.SelectedNode.Remove();
                            ReloadTree();
                        }
                    }
                    break;

                    case MenuActionMapChild:
                    {
                        var selectedNode = (NeuralLinkModel)neuralTree.SelectedNode.Tag;
                        var picker       = new NodePicker(LinkType.NeuralLink, selectedNode._id, $"Map child to : {selectedNode.Name}");
                        var res          = picker.ShowDialog();
                        if (res == DialogResult.OK && picker.NodeId != selectedNode._id)
                        {
                            var node = await DbLinkCollection.FindOneById(picker.NodeId);

                            if (node != null)
                            {
                                await DbLinkCollection.LinkParentChild(selectedNode._id, picker.NodeId);

                                var newTreeNode = neuralTree.SelectedNode.Nodes.Add(node._id, node.Name);
                                newTreeNode.Tag = node;
                                ReloadTree();
                            }
                        }
                    }
                    break;

                    case MenuActionUnmapChild:
                    {
                        if (neuralTree.SelectedNode.Parent == null)
                        {
                            await DbBotCollection.SetRootNodeById(BotAlphaName, null, cbxChatProfiles.Text);
                        }
                        else
                        {
                            await DbLinkCollection.UnLinkParentChild(neuralTree.SelectedNode.Parent.Name, neuralTree.SelectedNode.Name);

                            neuralTree.SelectedNode.Remove();
                        }
                        ReloadTree();
                    }
                    break;

                    default:
                        break;
                    }
                }

                switch (clicked)
                {
                case MenuActionRenameProfile:
                    await RenameChatProfile();

                    break;

                case MenuActionDeleteProfile:
                    await DeleteCurrentChatProfile();

                    break;

                case MenuActionNewProfile:
                    await CreateNewChatProfile();

                    break;

                case MenuActionNew:
                {
                    if (neuralTree.Nodes.Count == 0)
                    {
                        var rootNode = await DbLinkCollection.InsertNew(new NeuralLinkModel { Name = "RootNode" });

                        await DbBotCollection.SetRootNodeById(BotAlphaName, rootNode._id, await DataProviders.GetActiveProfile());

                        neuralTree.ImageList = DataProviders.LoadNeuralLinkValidationImageList();
                        var treeNode = neuralTree.Nodes.Add(rootNode._id, rootNode.Name);
                        treeNode.Tag            = rootNode;
                        treeNode.ImageKey       = rootNode.GetNodeImage();
                        neuralTree.SelectedNode = treeNode;
                        ReloadTree();
                    }
                }
                break;

                default:
                    break;
                }

                neuralTree.ExpandAll();
            }
        }
        private async void btnClone_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(cbxFromDb.Text) && !string.IsNullOrWhiteSpace(cbxToDb.Text) && cbxFromDb.Text != cbxToDb.Text)
            {
                try
                {
                    if (DataProviders.ConfirmDialog($"Clone database '{cbxFromDb.Text}' to '{cbxToDb.Text}', with drop option {(chkbDrop.Checked ? "TRUE" : "FALSE")}"))
                    {
                        cbxFromDb.Enabled = cbxToDb.Enabled = btnClone.Enabled = false;
                        var config = Program.AppConfiguration;
                        FromDb = new MongoDbContext(connectionString: config.DbConnections[cbxFromDb.Text] ?? MongoDbContext.LocalConnection);
                        ToDb   = new MongoDbContext(connectionString: config.DbConnections[cbxToDb.Text] ?? MongoDbContext.LocalConnection);
                        if (chkbDrop.Checked)
                        {
                            await ToDb.Drop();

                            if ((await FromDb.BotCollection.CountDocumentsAsync(x => true)) > 0)
                            {
                                await ToDb.BotCollection.InsertManyAsync(await FromDb.BotCollection.Find(x => true).ToListAsync());
                            }
                        }
                        var fromBotConfiguration = await FromDb.BotCollection.FindOneById(MongoDbContext.BotAlphaName);

                        if (chkbSelectProfile.Checked)
                        {
                            if (!chkbDrop.Checked)
                            {
                                var chatProfile = fromBotConfiguration.Configuration.ChatProfiles.FirstOrDefault(x => x.Name == cbxChatProfile.Text);
                                await ToDb.BotCollection.AddOrUpdateChatProfileById(MongoDbContext.BotAlphaName, chatProfile);

                                var toBotConfiguration = await ToDb.BotCollection.FindOneById(MongoDbContext.BotAlphaName);

                                var tempList = new List <KeyValuePair <string, string> >();
                                fromBotConfiguration.Configuration?.ResourceStrings?.ForEach(str =>
                                {
                                    var search = (KeyValuePair <string, string>)toBotConfiguration.Configuration?.ResourceStrings.FirstOrDefault(res => res.Key == str.Key);
                                    if (string.IsNullOrWhiteSpace(search.Key))
                                    {
                                        tempList.Add(str);
                                    }
                                });

                                if (tempList.Count > 0)
                                {
                                    await ToDb.BotCollection.AddStringResourceBatchById(MongoDbContext.BotAlphaName, tempList);
                                }
                            }

                            FromDb.SyncChatProfile(cbxChatProfile.Text);
                            ToDb.SyncChatProfile(cbxChatProfile.Text);
                            await ToDb.DropAllNodeCollections();
                            await CopyDb();
                        }
                        else
                        {
                            foreach (var profile in fromBotConfiguration?.Configuration?.ChatProfiles)
                            {
                                FromDb.SyncChatProfile(profile.Name);
                                ToDb.SyncChatProfile(profile.Name);
                                await CopyDb();
                            }
                        }
                        DialogResult      = DialogResult.OK;
                        cbxFromDb.Enabled = cbxToDb.Enabled = btnClone.Enabled = true;

                        MessageBox.Show("Operation completed without any error.", "Clone confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    if (DialogResult == DialogResult.OK)
                    {
                        this.Close();
                    }
                }
            }
        }