Exemplo n.º 1
0
        /// <summary>
        /// </summary>
        private void btnImport_Click(object sender, EventArgs e)
        {
            StartWait();

            this.Invoke((MethodInvoker) delegate
            {
                while (true)
                {
                    openFileDialog1.FileName = "";
                    openFileDialog1.Filter   = "Xml Files|*.xml";

                    if (openFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        // get current node, which should be group
                        var curNode = tvMMD.SelectedNode;

                        if (curNode == null || curNode.Level != 1)
                        {
                            cout("ERROR", "Please choose a Group in the tree where the termset(s) and term(s) will be imported.");
                            break;
                        }

                        // get group from mmd
                        var tGroup = MMDHelper.GetObj(txtSiteUrl.Text, curNode.Level, curNode) as Group;

                        if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                        {
                            cout("ERROR", MMDHelper.errMsg);
                            break;
                        }

                        // get xml content from file
                        var sr            = new StreamReader(openFileDialog1.FileName);
                        string xmlContent = sr.ReadToEnd();
                        sr.Close();

                        var msg = XmlImportHelper.ProcessXml(xmlContent, tGroup, curNode);

                        if (!GenUtil.IsNull(msg))
                        {
                            cout("ERROR", msg);
                            break;
                        }

                        cout("Xml File Imported.");

                        MMDHelper.LoadChildObjects(txtSiteUrl.Text, curNode.Level, curNode);

                        if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                        {
                            cout("ERROR", MMDHelper.errMsg);
                        }
                    }

                    break;
                }
            });

            StopWait();
        }
Exemplo n.º 2
0
        /// <summary>
        /// </summary>
        private void btnUpdateTermSet_Click(object sender, EventArgs e)
        {
            StartWait();

            this.Invoke((MethodInvoker) delegate
            {
                while (true)
                {
                    TreeNode curNode = tvMMD.SelectedNode;

                    if (curNode == null)
                    {
                        break;
                    }

                    if (txtTermSetName.Text.Trim().Length == 0)
                    {
                        cout("Cannot update termset, name is required.");
                        break;
                    }

                    if (curNode.Level == 2)
                    {
                        TermSet tSet = MMDHelper.GetObj(txtSiteUrl.Text, curNode.Level, curNode) as TermSet;

                        if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                        {
                            cout("ERROR", MMDHelper.errMsg);
                            break;
                        }

                        try
                        {
                            tSet.Name = GenUtil.MmdNormalize(txtTermSetName.Text.Trim());
                            tSet.IsAvailableForTagging = chkTermSetIsAvailableForTagging.Checked;
                            tSet.Description           = txtTermSetDescription.Text.Trim();
                            tSet.TermStore.CommitAll();

                            cout("TermSet Updated");

                            curNode.Text = string.Format("{1} [{0}]", tSet.Terms.Count, GenUtil.MmdNormalize(txtTermSetName.Text.Trim()));
                        }
                        catch (Exception exc)
                        {
                            cout("ERROR updating termset", exc.Message);
                        }
                    }

                    break;
                }
            });

            StopWait();
        }
        /// <summary>
        /// </summary>
        public static bool ExportToMsFormat(SaveFileDialog saveFileDialog, string siteUrl, TreeNode tNode, out string msg)
        {
            msg = "OK";

            try
            {
                if (tNode == null || tNode.Level != 2)
                {
                    msg = "Cannot export, please select a termset";
                    return(false);
                }

                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    TermSet tSet = MMDHelper.GetObj(siteUrl, tNode.Level, tNode) as TermSet;

                    if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                    {
                        throw new Exception(MMDHelper.errMsg);
                    }

                    List <MsExportObject> lstExObjs = new List <MsExportObject>();

                    int i = 0;
                    foreach (Term term in tSet.Terms)
                    {
                        lstExObjs.Add(new MsExportObject()
                        {
                            TermSetName        = (i == 0 ? string.Format("\"{0}\"", tSet.Name) : ""),
                            TermSetDescription = (i == 0 ? (string.IsNullOrEmpty(tSet.Description) ? "" : string.Format("\"{0}\"", tSet.Description)) : ""),
                            Lcid = "",
                            AvailableforTagging = (term.IsAvailableForTagging ? "TRUE" : "FALSE"),
                            TermDescription     = (string.IsNullOrEmpty(term.GetDescription()) ? "" : string.Format("\"{0}\"", term.GetDescription())),
                            Level1Term          = string.Format("\"{0}\"", term.Name)
                        });

                        if (term.TermsCount > 0)
                        {
                            LoadTerms(lstExObjs, term, 2);
                        }

                        i++;
                    }

                    ExportToCsv(lstExObjs, saveFileDialog.FileName);
                }
            }
            catch (Exception exc)
            {
                msg = exc.Message;
            }

            return(msg == "OK");
        }
Exemplo n.º 4
0
        /// <summary>
        /// </summary>
        private void btnUpdateGroup_Click(object sender, EventArgs e)
        {
            StartWait();

            this.Invoke((MethodInvoker) delegate
            {
                while (true)
                {
                    TreeNode curNode = tvMMD.SelectedNode;

                    if (curNode == null)
                    {
                        break;
                    }

                    if (txtTermGroupName.Text.Trim().Length == 0)
                    {
                        cout("Cannot update group, name is required.");
                        break;
                    }

                    if (curNode.Level == 1)
                    {
                        Group tGroup = MMDHelper.GetObj(txtSiteUrl.Text, curNode.Level, curNode) as Group;

                        if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                        {
                            cout("ERROR", MMDHelper.errMsg);
                            break;
                        }

                        try
                        {
                            tGroup.Description = txtTermGroupDescr.Text.Trim();
                            tGroup.Name        = txtTermGroupName.Text.Trim();
                            tGroup.TermStore.CommitAll();

                            curNode.Text = string.Format("{1} [{0}]", tGroup.TermSets.Count, txtTermGroupName.Text.Trim());

                            cout("Term Group Updated");
                        }
                        catch (Exception exc)
                        {
                            cout("ERROR updating term group", exc.Message);
                        }
                    }

                    break;
                }
            });

            StopWait();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Expand current node, load sub nodes (groups, termsets, terms)
        /// </summary>
        void tvMMD_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            StartWait();

            this.Invoke((MethodInvoker) delegate
            {
                MMDHelper.LoadChildObjects(txtSiteUrl.Text, e.Node.Level, e.Node);

                if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                {
                    cout("ERROR", MMDHelper.errMsg);
                }
            });

            StopWait();
        }
Exemplo n.º 6
0
        /// <summary>
        /// </summary>
        private void btnCreateTerm_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return;
            }

            StartWait();

            this.Invoke((MethodInvoker) delegate
            {
                while (true)
                {
                    TreeNode curNode = tvMMD.SelectedNode;

                    if (curNode == null)
                    {
                        break;
                    }

                    if (txtTermName.Text.Trim().Length == 0)
                    {
                        cout("Cannot create term, name is required.");
                        break;
                    }

                    Term newTerm = null;

                    try
                    {
                        if (curNode.Level == 2)
                        {
                            // add term to termset
                            TermSet tSet = MMDHelper.GetObj(txtSiteUrl.Text, curNode.Level, curNode) as TermSet;

                            if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                            {
                                cout("ERROR", MMDHelper.errMsg);
                                break;
                            }

                            if (GenUtil.IsNull(txtNewTermGuid.Text) ||
                                txtNewTermGuid.Text.Trim().ToLower() == NewTermGuidLabel.Trim().ToLower() ||
                                !GenUtil.IsGuid(txtNewTermGuid.Text))
                            {
                                newTerm = tSet.CreateTerm(GenUtil.MmdNormalize(txtTermName.Text), CultureInfo.CurrentCulture.LCID);
                            }
                            else
                            {
                                if (!GenUtil.IsGuid(txtNewTermGuid.Text))
                                {
                                    MessageBox.Show("Cannot create term, invalid new term Guid.");
                                    break;
                                }
                                else
                                {
                                    newTerm = tSet.CreateTerm(GenUtil.MmdNormalize(txtTermName.Text), CultureInfo.CurrentCulture.LCID, new Guid(txtNewTermGuid.Text));
                                }
                            }
                        }
                        else if (curNode.Level >= 3)
                        {
                            // add term to term
                            Term term = MMDHelper.GetObj(txtSiteUrl.Text, curNode.Level, curNode) as Term;

                            if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                            {
                                cout("ERROR", MMDHelper.errMsg);
                                break;
                            }

                            if (GenUtil.IsNull(txtNewTermGuid.Text) ||
                                txtNewTermGuid.Text.Trim().ToLower() == NewTermGuidLabel.Trim().ToLower() ||
                                !GenUtil.IsGuid(txtNewTermGuid.Text))
                            {
                                newTerm = term.CreateTerm(GenUtil.MmdNormalize(txtTermName.Text), CultureInfo.CurrentCulture.LCID);
                            }
                            else
                            {
                                if (!GenUtil.IsGuid(txtNewTermGuid.Text))
                                {
                                    MessageBox.Show("Cannot create term, invalid new term Guid.");
                                    break;
                                }
                                else
                                {
                                    newTerm = term.CreateTerm(GenUtil.MmdNormalize(txtTermName.Text), CultureInfo.CurrentCulture.LCID, new Guid(txtNewTermGuid.Text));
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Cannot create term in current location, select a termset or term.");
                            break;
                        }

                        if (newTerm != null)
                        {
                            newTerm.IsAvailableForTagging = chkTermIsAvailableForTagging.Checked;

                            // labels
                            if (!GenUtil.IsNull(txtTermLabels.Text))
                            {
                                foreach (string lbl in GenUtil.MmdNormalize(txtTermLabels.Text).Split(new char[] { ';' }))
                                {
                                    if (!GenUtil.IsNull(lbl) &&
                                        lbl.ToLower() != GenUtil.MmdNormalize(newTerm.Name).ToLower())
                                    {
                                        newTerm.CreateLabel(lbl, CultureInfo.CurrentCulture.LCID, false);
                                    }
                                }
                            }

                            newTerm.TermStore.CommitAll();

                            // add term to tree
                            TreeNode newNode = new TreeNode();
                            newNode.Text     = string.Format("{0} [0]", GenUtil.MmdDenormalize(newTerm.Name));
                            newNode.Name     = newTerm.Id.ToString();

                            curNode.Nodes.Add(newNode);
                            curNode.Expand();

                            cout("New Term Created");

                            txtNewTermGuid.Text = NewTermGuidLabel;
                        }
                    }
                    catch (Exception ex)
                    {
                        cout("ERROR creating term", ex.Message);
                    }

                    break;
                }
            });

            StopWait();
        }
Exemplo n.º 7
0
        /// <summary>
        /// </summary>
        private void btnCreateTermSet_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return;
            }

            StartWait();

            this.Invoke((MethodInvoker) delegate
            {
                while (true)
                {
                    TreeNode curNode = tvMMD.SelectedNode;

                    if (curNode == null)
                    {
                        break;
                    }

                    if (txtTermSetName.Text.Trim().Length == 0)
                    {
                        cout("Cannot create termset, name is required.");
                        break;
                    }

                    Group tGroup = null;

                    if (curNode.Level == 1)
                    {
                        // create new termset in group
                        tGroup = MMDHelper.GetObj(txtSiteUrl.Text, curNode.Level, curNode) as Group;

                        if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                        {
                            cout("ERROR", MMDHelper.errMsg);
                            break;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Cannot create termset in current location, select a group.");
                        break;
                    }

                    if (tGroup != null)
                    {
                        if (tGroup.TermSets.Any(x =>
                                                GenUtil.MmdNormalize(x.Name).ToLower() == GenUtil.MmdNormalize(txtTermSetName.Text).ToLower()))
                        {
                            cout("Cannot create termset, name not unique.");
                            break;
                        }

                        try
                        {
                            // create new termset
                            TermSet tSet = tGroup.CreateTermSet(GenUtil.MmdNormalize(txtTermSetName.Text.Trim()));
                            tSet.IsAvailableForTagging = chkTermSetIsAvailableForTagging.Checked;
                            tSet.Description           = txtTermSetDescription.Text.Trim();
                            tSet.TermStore.CommitAll();

                            // add termset to tree
                            TreeNode newNode = new TreeNode();
                            newNode.Text     = string.Format("{0} [0]", GenUtil.MmdDenormalize(tSet.Name));
                            newNode.Name     = tSet.Id.ToString();

                            curNode.Nodes.Add(newNode);
                            curNode.Expand();

                            cout("New TermSet Created");
                        }
                        catch (Exception exc)
                        {
                            cout("ERROR creating termset", exc.Message);
                        }
                    }

                    break;
                }
            });

            StopWait();
        }
Exemplo n.º 8
0
        /// <summary>
        /// </summary>
        private void btnCreateGroup_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return;
            }

            StartWait();

            this.Invoke((MethodInvoker) delegate
            {
                while (true)
                {
                    TreeNode curNode = tvMMD.SelectedNode;

                    if (curNode == null)
                    {
                        break;
                    }

                    if (txtTermGroupName.Text.Trim().Length == 0)
                    {
                        cout("Cannot create group, name is required.");
                        break;
                    }

                    TermStore tStore = null;

                    if (curNode.Level == 0)
                    {
                        // create new group in termstore
                        tStore = MMDHelper.GetObj(txtSiteUrl.Text, curNode.Level, curNode) as TermStore;

                        if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                        {
                            cout("ERROR", MMDHelper.errMsg);
                            break;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Cannot create group in current location, select a termstore.");
                        break;
                    }

                    if (tStore != null)
                    {
                        if (tStore.Groups.Any(x => x.Name.Trim().ToLower() == txtTermGroupName.Text.ToLower().Trim()))
                        {
                            cout("Cannot create group, name not unique.");
                            break;
                        }

                        try
                        {
                            // create new group
                            Group newGroup       = tStore.CreateGroup(txtTermGroupName.Text.Trim());
                            newGroup.Description = txtTermGroupDescr.Text.Trim();
                            tStore.CommitAll();

                            // add group to tree
                            TreeNode newNode = new TreeNode();
                            newNode.Text     = string.Format("{0} [0]", newGroup.Name);
                            newNode.Name     = newGroup.Id.ToString();

                            curNode.Nodes.Add(newNode);
                            curNode.Expand();

                            cout("New Group Created");
                        }
                        catch (Exception ex)
                        {
                            cout("ERROR creating group", ex.Message);
                        }
                    }

                    break;
                }
            });

            StopWait();
        }
Exemplo n.º 9
0
        /// <summary>
        /// </summary>
        private void btnUpdateTerm_Click(object sender, EventArgs e)
        {
            StartWait();

            this.Invoke((MethodInvoker) delegate
            {
                while (true)
                {
                    TreeNode curNode = tvMMD.SelectedNode;

                    if (curNode == null)
                    {
                        break;
                    }

                    if (txtTermName.Text.Trim().Length == 0)
                    {
                        cout("Cannot update term, name is required.");
                        break;
                    }

                    if (curNode.Level >= 3)
                    {
                        Term term = MMDHelper.GetObj(txtSiteUrl.Text, curNode.Level, curNode) as Term;

                        if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                        {
                            cout("ERROR", MMDHelper.errMsg);
                            break;
                        }

                        try
                        {
                            // term labels
                            string ignoreTermName      = GenUtil.MmdNormalize(txtTermName.Text);
                            List <string> lstNewLabels = GenUtil.MmdNormalize(txtTermLabels.Text).Split(new char[] { ';' }).ToList();

                            // delete existing labels (if label in collection not found in textbox)
                            int i = 0;
                            while (i < term.Labels.Select(x => x.Value).ToList().Count())
                            {
                                var curLbl    = term.Labels[i];
                                var curLblVal = GenUtil.MmdNormalize(curLbl.Value);

                                if (curLblVal.ToLower() != ignoreTermName.ToLower() &&
                                    !lstNewLabels.Any(x => x.Trim().ToLower() == curLblVal.ToLower()) &&
                                    !curLbl.IsDefaultForLanguage)
                                {
                                    curLbl.Delete();
                                }
                                else
                                {
                                    i++;
                                }
                            }

                            // add new labels (if label in textbox not found in collection)
                            foreach (var lblNew in lstNewLabels)
                            {
                                if (!GenUtil.IsNull(lblNew) &&
                                    lblNew.Trim().ToLower() != ignoreTermName.ToLower() &&
                                    !term.Labels.Any(x => GenUtil.MmdNormalize(x.Value).ToLower() == lblNew.ToLower()))
                                {
                                    term.CreateLabel(lblNew.Trim(), CultureInfo.CurrentCulture.LCID, false);
                                }
                            }


                            term.IsAvailableForTagging = chkTermIsAvailableForTagging.Checked;
                            term.Name = GenUtil.MmdNormalize(txtTermName.Text);
                            term.TermStore.CommitAll();

                            curNode.Text = string.Format("{1} [{0}]", term.TermsCount, GenUtil.MmdNormalize(txtTermName.Text));

                            cout("Term Updated");
                        }
                        catch (Exception exc)
                        {
                            cout("ERROR updating term", exc.Message);
                        }
                    }

                    break;
                }
            });

            StopWait();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Load Node details (termstore, group, termset, term)
        /// </summary>
        void tvMMD_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            StartWait();

            this.Invoke((MethodInvoker) delegate
            {
                while (true)
                {
                    if (e.Node.Level == 0)
                    {
                        // termstore, load current node detail
                        TermStore tStore = MMDHelper.GetObj(txtSiteUrl.Text, e.Node.Level, e.Node) as TermStore;

                        if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                        {
                            cout("ERROR", MMDHelper.errMsg);
                            break;
                        }

                        txtTermStoreId.Text   = tStore.Id.ToString();
                        txtTermStoreName.Text = tStore.Name ?? "";

                        txtCurSelNode.Text = tStore.Name;

                        // select tab
                        tabControl1.SelectTab(tabTermStore);
                    }
                    else if (e.Node.Level == 1)
                    {
                        // termgroup, load current node detail
                        Group tGroup = MMDHelper.GetObj(txtSiteUrl.Text, e.Node.Level, e.Node) as Group;

                        if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                        {
                            cout("ERROR", MMDHelper.errMsg);
                            break;
                        }

                        txtTermGroupId.Text    = tGroup.Id.ToString();
                        txtTermGroupName.Text  = tGroup.Name ?? "";
                        txtTermGroupDescr.Text = tGroup.Description ?? "";

                        txtCurSelNode.Text = tGroup.Name;

                        // select tab
                        tabControl1.SelectTab(tabGroup);
                    }
                    else if (e.Node.Level == 2)
                    {
                        // termset
                        TermSet tSet = MMDHelper.GetObj(txtSiteUrl.Text, e.Node.Level, e.Node) as TermSet;

                        if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                        {
                            cout("ERROR", MMDHelper.errMsg);
                            break;
                        }

                        txtTermSetCustomSortOrder.Text = tSet.CustomSortOrder;
                        txtTermSetDescription.Text     = tSet.Description;
                        txtTermSetId.Text = tSet.Id.ToString();
                        chkTermSetIsAvailableForTagging.Checked = tSet.IsAvailableForTagging;
                        txtTermSetIsOpenForTermCreation.Text    = tSet.IsOpenForTermCreation.ToString();
                        txtTermSetLastModifiedDate.Text         = tSet.LastModifiedDate.ToString();
                        txtTermSetName.Text = GenUtil.MmdDenormalize(tSet.Name);

                        txtCurSelNode.Text = tSet.Name;

                        // select tab
                        tabControl1.SelectTab(tabTermSet);
                    }
                    else if (e.Node.Level >= 3)
                    {
                        // term
                        Term term = MMDHelper.GetObj(txtSiteUrl.Text, e.Node.Level, e.Node) as Term;

                        if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                        {
                            cout("ERROR", MMDHelper.errMsg);
                            break;
                        }

                        txtTermCreatedDate.Text     = term.CreatedDate.ToString();
                        txtTermCustomSortOrder.Text = term.CustomSortOrder;
                        txtTermId.Text = term.Id.ToString();
                        chkTermIsAvailableForTagging.Checked = term.IsAvailableForTagging;
                        chkTermIsKeyword.Checked             = term.IsKeyword;
                        chkTermIsReused.Checked      = term.IsReused;
                        chkTermIsRoot.Checked        = term.IsRoot;
                        chkTermIsSourceTerm.Checked  = term.IsSourceTerm;
                        txtTermLabels.Text           = GenUtil.MmdDenormalize(GenUtil.LabelsToString(term.Labels, term.Name));
                        txtTermLastModifiedDate.Text = term.LastModifiedDate.ToString();
                        txtTermName.Text             = GenUtil.MmdDenormalize(term.Name);
                        txtTermTermsCount.Text       = term.TermsCount.ToString();

                        txtCurSelNode.Text = term.Name;

                        // select tab
                        tabControl1.SelectTab(tabTerm);

                        txtNewTermGuid.Text = NewTermGuidLabel;
                    }

                    break;
                }
            });

            StopWait();
        }
Exemplo n.º 11
0
        /// <summary>
        /// </summary>
        private void btnTermSetClearTerms_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return;
            }

            StartWait();

            this.Invoke((MethodInvoker) delegate
            {
                while (true)
                {
                    TreeNode curNode = tvMMD.SelectedNode;

                    if (curNode == null)
                    {
                        break;
                    }

                    if (curNode.Level != 2)
                    {
                        cout("Can only clear termsets.");
                        break;
                    }

                    try
                    {
                        var termSet = MMDHelper.GetObj(txtSiteUrl.Text, curNode.Level, curNode) as TermSet;

                        if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                        {
                            cout("ERROR", MMDHelper.errMsg);
                            break;
                        }

                        if (termSet == null)
                        {
                            cout("ERROR", "Termset not found.");
                            break;
                        }

                        foreach (var term in termSet.Terms)
                        {
                            DeleteTerms(term);
                        }
                        termSet.TermStore.CommitAll();

                        curNode.Nodes.Clear();

                        cout("Termset Cleared");
                    }
                    catch (Exception exc)
                    {
                        cout("ERROR deleting terms", exc.Message);
                    }

                    break;
                }
            });

            StopWait();
        }
Exemplo n.º 12
0
        /// <summary>
        /// </summary>
        private void btnBulkMergeTerms_Click(object sender, EventArgs e)
        {
            StartWait();

            if (tbBulkMergeTerms.Text.IsNull())
            {
                return;
            }

            this.Invoke((MethodInvoker) delegate
            {
                while (true)
                {
                    TreeNode curNode = tvMMD.SelectedNode;

                    if (curNode == null)
                    {
                        break;
                    }

                    if (curNode.Level != 2)
                    {
                        cout("Choose a termset.");
                        break;
                    }

                    try
                    {
                        var termSet = MMDHelper.GetObj(txtSiteUrl.Text, curNode.Level, curNode) as TermSet;

                        if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                        {
                            cout("ERROR", MMDHelper.errMsg);
                            break;
                        }

                        if (termSet == null)
                        {
                            cout("ERROR", "Termset not found.");
                            break;
                        }

                        var newTerms = GenUtil.NormalizeEol(tbBulkMergeTerms.Text.Trim())
                                       .Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)
                                       .Where(x => x.Trim().Length > 0)
                                       .Distinct()
                                       .ToList <string>();

                        bool termsAdded = false;

                        foreach (var newTerm in newTerms)
                        {
                            var termSearchResults = termSet.GetTerms(newTerm.Trim(), false, StringMatchOption.ExactMatch, 1, false);

                            if (termSearchResults.Any())
                            {
                                cout(string.Format("Term found, skipping: {0}", newTerm.Trim()));
                            }
                            else
                            {
                                cout(string.Format("Term not found, creating new term: {0}", newTerm.Trim()));

                                try
                                {
                                    var termCreated = termSet.CreateTerm(newTerm.Trim(), CultureInfo.CurrentCulture.LCID);
                                    termsAdded      = true;
                                }
                                catch (Exception ex)
                                {
                                    cout("ERROR creating new term: " + ex.Message);
                                }
                            }
                        }

                        if (termsAdded)
                        {
                            termSet.TermStore.CommitAll();
                        }
                    }
                    catch (Exception exc)
                    {
                        cout("ERROR Bulk Merging Terms", exc.Message);
                    }

                    break; // #important
                }
            });

            StopWait();
        }
Exemplo n.º 13
0
        /// <summary>
        /// </summary>
        private void btnTermDelete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return;
            }

            StartWait();

            this.Invoke((MethodInvoker) delegate
            {
                while (true)
                {
                    TreeNode curNode = tvMMD.SelectedNode;

                    if (curNode == null)
                    {
                        break;
                    }

                    if (curNode.Level < 3)
                    {
                        cout("Can only delete terms.");
                        break;
                    }

                    try
                    {
                        Term term = MMDHelper.GetObj(txtSiteUrl.Text, curNode.Level, curNode) as Term;

                        if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                        {
                            cout("ERROR", MMDHelper.errMsg);
                            break;
                        }

                        if (term == null)
                        {
                            cout("ERROR", "Term not found.");
                            break;
                        }

                        term.Delete();
                        term.TermStore.CommitAll();

                        // delete node from tree
                        curNode.Remove();

                        cout("Term Deleted");
                    }
                    catch (Exception exc)
                    {
                        cout("ERROR deleting term", exc.Message);
                    }

                    break;
                }
            });

            StopWait();
        }
Exemplo n.º 14
0
        /// <summary>
        /// </summary>
        public static bool ExportToXml(SaveFileDialog saveFileDialog, string siteUrl, TreeNode tNode, out string msg)
        {
            msg = "OK";

            if (tNode == null || tNode.Level < 1 || tNode.Level > 2)
            {
                msg = "Can only export Groups and TermSets.";
                return(false);
            }

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                var lstTermSets = new List <TermSet>();

                if (tNode.Level == 1)
                {
                    // export all termsets in termgroup
                    var tGroup = MMDHelper.GetObj(siteUrl, tNode.Level, tNode) as Group;

                    if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                    {
                        msg = MMDHelper.errMsg;
                        return(false);
                    }

                    if (tGroup == null)
                    {
                        msg = "Group not found.";
                        return(false);
                    }

                    lstTermSets.AddRange(tGroup.TermSets);
                }
                else if (tNode.Level == 2)
                {
                    // export specific termset
                    var termSet = MMDHelper.GetObj(siteUrl, tNode.Level, tNode) as TermSet;

                    if (!string.IsNullOrEmpty(MMDHelper.errMsg))
                    {
                        msg = MMDHelper.errMsg;
                        return(false);
                    }

                    if (termSet == null)
                    {
                        msg = "TermSet not found.";
                        return(false);
                    }

                    lstTermSets.Add(termSet);
                }

                if (lstTermSets.Count <= 0)
                {
                    msg = "No termsets found to export.";
                    return(false);
                }

                var settings = new XmlWriterSettings();
                settings.Indent = true;

                var sb        = new StringBuilder();
                var xmlWriter = XmlWriter.Create(sb, settings);

                xmlWriter.WriteStartDocument();
                xmlWriter.WriteStartElement("termsets");

                foreach (var curTermSet in lstTermSets)
                {
                    ExportToXml(ref xmlWriter, curTermSet, null);
                }

                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndDocument();
                xmlWriter.Close();

                var fs     = new FileStream(saveFileDialog.FileName, FileMode.Create);
                var writer = new StreamWriter(fs);
                writer.Write(sb.ToString());
                writer.Close();
                fs.Close();
            }

            return(msg == "OK");
        }