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 object GetValue(StorageMethodType storageType, string name, bool create = true) { object result = null; string path; switch (storageType) { case StorageMethodType.Database: try { //result = this.Core.Tables[this.Source].GetValue(name, "Id", Guid.Parse(this.GetValue("Id").ToString())); result = this.Core.Tables[this.Source].GetValue(name, this.Path); } catch { result = null; } break; case StorageMethodType.Xml: if (this.XmlNode != null && this.XmlNode.Attributes[name] != null) { result = this.XmlNode.Attributes[name].Value; } else if (this.XmlNode != null) { string source = ""; path = ""; switch (this.TypeName) { case "TaxonomyCategory": case "ScoreGroup": source = "TaxonomyCategories"; break; case "TaxonomyVariable": source = "TaxonomyVariables"; break; case "Category": source = "Categories"; break; case "Variable": source = "Variables"; break; } if (source == "") { return(result); } path = "Id=" + this.GetValue("Id"); string _name = name; if (name.StartsWith("Label")) { _name = "Label"; switch (source) { case "TaxonomyVariables": source = "TaxonomyVariableLabels"; path = "IdTaxonomyVariable=" + this.GetValue("Id"); break; case "TaxonomyCategories": source = "TaxonomyCategoryLabels"; path = "IdTaxonomyCategory=" + this.GetValue("Id"); break; case "Variables": source = "VariableLabels"; path = "IdVariable=" + this.GetValue("Id"); break; case "Categories": source = "CategoryLabels"; path = "IdCategory=" + this.GetValue("Id"); break; } int idLanguage; if (int.TryParse(name.Replace("Label", ""), out idLanguage)) { path += "&IdLanguage=" + idLanguage; } } DefinitionObject score = new DefinitionObject(this.Core, source, path); try { result = score.GetValue(_name, create); } catch { result = null; } SetValue(name, result); } break; } return(result); }