/// <summary>
        /// segregated only link funtionality of categories
        /// </summary>
        /// <param name="IdsStudyVariables">comma seperated values of variable ids to be un linked</param>
        /// <param name="IdsTaxonomyVariables">comma seperated values of  taxonomy variable ids to be un linked</param>
        /// <returns></returns>
        private static void LinkCategories(string[] ArrIdsStudyCategories, string[] ArrIdsTaxonomyCategories)
        {
            TaxonomyCategory taxonomyCategory = Global.Core.TaxonomyCategories.GetSingle(new Guid(ArrIdsTaxonomyCategories[0]));

            for (int i = 0; i < ArrIdsStudyCategories.Count(); i++)
            {
                Category category = Global.Core.Categories.GetSingle(new Guid(ArrIdsStudyCategories[i]));

                foreach (var taxonomyCategories in ArrIdsTaxonomyCategories)
                {
                    List <object[]> categoryLinks = Global.Core.CategoryLinks.GetValues(new string[] { "Id" }, new string[] { "IdCategory", "IdTaxonomyCategory", "IdVariable", "IdTaxonomyVariable" }, new object[] { ArrIdsStudyCategories[i], taxonomyCategories, category.IdVariable, taxonomyCategory.IdTaxonomyVariable });

                    if (categoryLinks.Count() == 0)
                    {
                        CategoryLink categoryLink = new CategoryLink(Global.Core.CategoryLinks);
                        categoryLink.IdCategory         = new Guid(ArrIdsStudyCategories[i]);
                        categoryLink.IdTaxonomyCategory = new Guid(taxonomyCategories);
                        categoryLink.IdVariable         = category.IdVariable;
                        categoryLink.IdTaxonomyVariable = taxonomyCategory.IdTaxonomyVariable;
                        categoryLink.CreationDate       = DateTime.Now;
                        categoryLink.Insert();
                    }
                }
            }
        }
        /// <summary>
        /// segregated only unlink funtionality of categories
        /// </summary>
        /// <param name="IdsStudyCategories">comma seperated values of  categories ids to be un linked</param>
        /// <param name="IdsTaxonomyCategories">comma seperated values of  taxonomy categories ids to be un linked</param>
        /// <returns></returns>
        public static string UnlinkCategories(string IdsStudyCategories, string IdsTaxonomyCategories)
        {
            string[] IdsStudyCategoriesArray    = SplitCommaSeperatedValues(IdsStudyCategories);
            string[] IdsTaxonomyCategoriesArray = SplitCommaSeperatedValues(IdsTaxonomyCategories);

            TaxonomyCategory taxonomyCategory = Global.Core.TaxonomyCategories.GetSingle(new Guid(IdsTaxonomyCategoriesArray[0]));

            for (int i = 0; i < IdsStudyCategoriesArray.Count(); i++)
            {
                Category        category      = Global.Core.Categories.GetSingle(new Guid(IdsStudyCategoriesArray[i]));
                List <object[]> categoryLinks = Global.Core.CategoryLinks.GetValues(new string[] { "Id" }, new string[] { "IdCategory", "IdTaxonomyCategory", "IdVariable", "IdTaxonomyVariable" }, new object[] { IdsStudyCategoriesArray[i], IdsTaxonomyCategoriesArray[0], category.IdVariable, taxonomyCategory.IdTaxonomyVariable });
                for (int j = 0; j < categoryLinks.Count(); j++)
                {
                    Global.Core.CategoryLinks.Delete(new Guid((categoryLinks[j])[0].ToString()));
                }
            }

            return("success");
        }
        public string Combine(DefinitionObject score2)
        {
            string result = "";

            switch (this.StorageType)
            {
            case StorageMethodType.Database:

                if (this.IsScoreGroup())
                {
                    TaxonomyCategoryLink link = new TaxonomyCategoryLink(this.Core.TaxonomyCategoryLinks);

                    link.IdTaxonomyCategory = (Guid)score2.GetValue("Id");

                    link.IdScoreGroup = (Guid)this.GetValue("Id");

                    link.Insert();

                    //score2.SetValue("IdTaxonomyCategory", this.GetValue("Id"));
                }
                else if (score2 != null && score2.IsScoreGroup())
                {
                    TaxonomyCategoryLink link = new TaxonomyCategoryLink(this.Core.TaxonomyCategoryLinks);

                    link.IdTaxonomyCategory = (Guid)this.GetValue("Id");

                    link.IdScoreGroup = (Guid)score2.GetValue("Id");

                    link.Insert();

                    //this.SetValue("IdTaxonomyCategory", score2.GetValue("Id"));
                }
                else
                {
                    TaxonomyCategory group = new TaxonomyCategory(this.Core.TaxonomyCategories);
                    group.Name  = "";
                    group.Order = (int)this.GetValue("Order");
                    group.SetValue("CreationDate", DateTime.Now);
                    group.IdTaxonomyVariable = (Guid)this.GetValue("IdTaxonomyVariable");
                    group.Color        = ApplicationUtilities.Classes.ColorCalculator.GenerateRandomColor().ToString().Remove(0, 1);
                    group.IsScoreGroup = true;

                    result = "Id=" + group.Id;

                    group.Insert();

                    TaxonomyCategoryLink link1 = new TaxonomyCategoryLink(this.Core.TaxonomyCategoryLinks);

                    link1.IdTaxonomyCategory = (Guid)this.GetValue("Id");

                    link1.IdScoreGroup = group.Id;

                    link1.Insert();

                    if (score2 != null)
                    {
                        TaxonomyCategoryLink link2 = new TaxonomyCategoryLink(this.Core.TaxonomyCategoryLinks);
                        link2.IdTaxonomyCategory = (Guid)score2.GetValue("Id");
                        link2.IdScoreGroup       = group.Id;
                        link2.Insert();
                    }
                }

                break;

            case StorageMethodType.Xml:

                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(this.Source);

                XmlNode xmlNode = xmlDocument.SelectSingleNode(this.Path);

                if (this.TypeName == "ScoreGroup")
                {
                    xmlNode.InnerXml += string.Format(
                        "<{2} Id=\"{0}\" Order=\"{1}\"></{2}>",
                        score2.GetValue("Id"),
                        xmlNode.ChildNodes.Count,
                        score2.TypeName
                        );

                    result = "ScoreGroup[@Id=\"" + xmlNode.Attributes["Id"].Value + "\"]";

                    SetLatestChange(xmlDocument);

                    xmlDocument.Save(this.Source);

                    //score2.SetValue("Enabled", false);
                }
                else
                {
                    Guid idScoreGroup = Guid.NewGuid();

                    if (score2 != null)
                    {
                        xmlNode.ParentNode.InnerXml += string.Format(
                            "<ScoreGroup Id=\"{0}\" Name=\"{1}\" Order=\"{2}\" Value=\"{5}\" Color=\"{6}\">" +
                            "<{7} Id=\"{3}\" Order=\"0\"></{7}>" +
                            "<{8} Id=\"{4}\" Order=\"1\"></{8}>" +
                            "</ScoreGroup>",
                            idScoreGroup,
                            "",
                            xmlNode.ParentNode.ChildNodes.Count,
                            this.GetValue("Id"),
                            score2.GetValue("Id"),
                            xmlNode.ParentNode.ChildNodes.Count + 1,
                            ApplicationUtilities.Classes.ColorCalculator.GenerateRandomColor().ToString().Remove(0, 1),
                            this.TypeName,
                            score2.TypeName
                            );
                    }
                    else
                    {
                        xmlNode.ParentNode.InnerXml += string.Format(
                            "<ScoreGroup Id=\"{0}\" Name=\"{1}\" Order=\"{2}\" Value=\"{5}\" Color=\"{6}\">" +
                            "<{7} Id=\"{3}\" Order=\"0\"></{7}>" +
                            "</ScoreGroup>",
                            idScoreGroup,
                            "",
                            xmlNode.ParentNode.ChildNodes.Count,
                            this.GetValue("Id"),
                            "",
                            xmlNode.ParentNode.ChildNodes.Count + 1,
                            ApplicationUtilities.Classes.ColorCalculator.GenerateRandomColor().ToString().Remove(0, 1),
                            this.TypeName
                            );
                    }

                    result = "ScoreGroup[@Id=\"" + idScoreGroup + "\"]";

                    SetLatestChange(xmlDocument);

                    xmlDocument.Save(this.Source);

                    //this.SetValue("Enabled", false);
                    //score2.SetValue("Enabled", false);
                }

                break;
            }

            return(result);
        }
        public void GenerateTaxonomyTree(FwControllerContext fwControllerContext, ConversationVm conversation = null)
        {
            this._taxonomies = new List <TaxonomyCategory>();


            NBAR2TaxonomyProtocol[] nbarTaxonomies;
            if (conversation == null)
            {
                var nbarDb = fwControllerContext.FwController.GetNbarProtocolPortDatabase();
                nbarTaxonomies = nbarDb.Nbar2Taxonomy.NBAR2TaxonomyProtocol;
            }
            else
            {
                nbarTaxonomies = fwControllerContext.FwController.GetNbarTaxonomiesProtocolFromAppTags(conversation.Conversation.ApplicationTags);
            }


            foreach (var nbarTaxonomy in nbarTaxonomies)
            {
                var attributes = nbarTaxonomy.attributes.FirstOrDefault();
                if (attributes != null)
                {
                    var category = this._taxonomies.FirstOrDefault(taxonomyCategory => taxonomyCategory.Name == attributes.category);

                    if (category == null)
                    {
                        category = new TaxonomyCategory
                        {
                            Name          = attributes.category,
                            Protocols     = new List <TaxonomyProtocol>(),
                            SubCategories = new List <TaxonomyCategory>()
                        };

                        this._taxonomies.Add(category);
                    }

                    var subCategory = category.SubCategories.FirstOrDefault(taxonomyCategory => taxonomyCategory.Name == attributes.subcategory);

                    if (subCategory == null)
                    {
                        subCategory = new TaxonomyCategory
                        {
                            Name          = attributes.subcategory,
                            Protocols     = new List <TaxonomyProtocol>(),
                            SubCategories = new List <TaxonomyCategory>()
                        };

                        category.SubCategories.Add(subCategory);
                    }

                    var applicationGroup = subCategory.SubCategories.FirstOrDefault(taxonomyCategory => taxonomyCategory.Name == attributes.applicationgroup);

                    if (applicationGroup == null)
                    {
                        applicationGroup = new TaxonomyCategory
                        {
                            Name          = attributes.applicationgroup,
                            Protocols     = new List <TaxonomyProtocol>(),
                            SubCategories = new List <TaxonomyCategory>()
                        };

                        subCategory.SubCategories.Add(applicationGroup);
                    }

                    var taxProto = new TaxonomyProtocol
                    {
                        Name                = nbarTaxonomy.name,
                        CommonName          = nbarTaxonomy.commonname,
                        Description         = nbarTaxonomy.helpstring,
                        Encrypted           = attributes.encrypted,
                        Tunnel              = attributes.tunnel,
                        UnderLyingProtocols = nbarTaxonomy.underlyingprotocols
                    };


                    foreach (var port in nbarTaxonomy.ports)
                    {
                        if (!string.IsNullOrEmpty(port.tcp))
                        {
                            taxProto.Ports += string.Format("TCP:{0} ", port.tcp);
                        }

                        if (!string.IsNullOrEmpty(port.udp))
                        {
                            taxProto.Ports += string.Format("UDP:{0} ", port.udp);
                        }
                    }

                    applicationGroup.Protocols.Add(taxProto);
                }
            }
        }