/// <summary> /// Encodes the laterality concept detail as a situation with explicit context. /// </summary> /// <param name="conceptDetail">The concept detail.</param> /// <param name="searchState">State of the search.</param> /// <param name="lateralityConceptDetail">The laterality concept detail.</param> private static void EncodeLaterality(ConceptDetail conceptDetail, SearchState searchState, ConceptDetail lateralityConceptDetail) { AttributeValuePair lateralityAttributeValuePair = new AttributeValuePair(SnomedConcepts.FindingSite, new EncodedConcept(conceptDetail)); lateralityAttributeValuePair.Value.AttributeCollection.Add(new AttributeValuePair(SnomedConcepts.Laterality, new EncodedConcept(lateralityConceptDetail))); if (searchState.InputFieldResult.IsNegated) { if (searchState.EncodedConcept.AttributeCollection.Count > 1) { searchState.EncodedConcept.AttributeCollection[1].Value.AttributeCollection.Add(lateralityAttributeValuePair); } } else { searchState.EncodedConcept.AttributeCollection.Add(lateralityAttributeValuePair); } searchState.UserState = UserState.EncodingAdditionalConcept; searchState.AdditionalTextBoxResults.RemoveAt(0); if (searchState.AdditionalTextBoxResults != null && searchState.AdditionalTextBoxResults.Count > 0) { AdditionalTextBoxResult additionalTextBoxResult = searchState.AdditionalTextBoxResults[0]; terminologyProviderClient.GetConceptDetailsAsync(additionalTextBoxResult.SelectedItem.SnomedConceptId, TerminologyManager.LocaleString, searchState); } }
private static AttributeValuePair BuildAVP( AttributeControlType attributeControlType, CustomerAttribute customerAttribute, string strValue ) { switch (attributeControlType) { case AttributeControlType.DropdownList: case AttributeControlType.RadioList: case AttributeControlType.Checkboxes: var productVariantAttributeValue = customerAttribute.CustomerAttributeValues .Single(pvav => pvav.Id == Int32.Parse(strValue)); var attributeValue = new AttributeValuePair() { AttributeName = customerAttribute.Name, ValueId = productVariantAttributeValue.Id, ValueText = productVariantAttributeValue.Name }; return(attributeValue); default: attributeValue = new AttributeValuePair() { AttributeName = customerAttribute.Name, ValueId = 0, ValueText = strValue }; return(attributeValue); } }
void MkEqStmt(string l, string r) { var couple = new Tuple <Microsoft.Msagl.Drawing.Label, GraphAttr>(new Microsoft.Msagl.Drawing.Label(), this.graph.Attr); var avPair = AttributeValuePair.CreateFromsStrings(l, r); AttributeValuePair.AddAttributeValuePair(couple, avPair); }
public static string GetCustomerAttribute(Customer customer, string attributeName) { AttributeValuePair attribute = GetCustomerAttributes(customer) .FirstOrDefault(n => Equals(n.AttributeName.Trim().ToLower(), attributeName.Trim().ToLower())); return(attribute != null ? attribute.ValueText : null); }
void MkGraphAttrStmt(ArrayList attrs) { var couple = new Tuple <Microsoft.Msagl.Drawing.Label, GraphAttr>(graph.Label, graph.Attr); couple = AttributeValuePair.AddGraphAttrs(couple, attrs); graph.Label = couple.Item1; graph.Attr = couple.Item2; }
public int CompareTo(object obj) { AttributeValuePair other = obj as AttributeValuePair; if (other != null) { if (this.AttributeType == other.AttributeType) { // some common special cases where we want things to be out of the normal order if (this.Name.Equals("StartPoint") && other.Name.Equals("EndPoint")) { return(-1); } if (this.Name.Equals("EndPoint") && other.Name.Equals("StartPoint")) { return(1); } if (this.Name.Equals("Width") && other.Name.Equals("Height")) { return(-1); } if (this.Name.Equals("Height") && other.Name.Equals("Width")) { return(1); } if (this.Name.Equals("Offset") && other.Name.Equals("Color")) { return(-1); } if (this.Name.Equals("Color") && other.Name.Equals("Offset")) { return(1); } if (this.Name.Equals("TargetName") && other.Name.Equals("Property")) { return(-1); } if (this.Name.Equals("Property") && other.Name.Equals("TargetName")) { return(1); } return(Name.CompareTo(other.Name)); } else { return(this.AttributeType.CompareTo(other.AttributeType)); } } return(0); }
public void AddAttribute(AttributeValuePair attribute) { if (Attributes.FindIndex((AttributeValuePair p) => p.Attribute == attribute.Attribute) != -1) { Debug.LogError("Trying to add already existing attribute"); return; } Attributes.Add(attribute); }
/// <summary> /// Initializes a new instance of the <see cref="RangeValidationRule"/> class. /// </summary> /// <param name="errorMessage">The error message.</param> /// <param name="minValue">The minimum value.</param> /// <param name="maxValue">The maximum value.</param> public RangeValidationRule(string errorMessage, object minValue, object maxValue) { ErrorMessage = errorMessage; if (minValue != null) { ValidationParameters["min"] = new AttributeValuePair("min", minValue); } if (maxValue != null) { ValidationParameters["max"] = new AttributeValuePair("max", maxValue); } }
/// <summary> /// Initializes a new instance of the <see cref="StringLengthValidationRule"/> class. /// </summary> /// <param name="errorMessage">The error message.</param> /// <param name="minimumLength">The minimum length.</param> /// <param name="maximumLength">The maximum length.</param> public StringLengthValidationRule(string errorMessage, int minimumLength, int maximumLength) { ErrorMessage = errorMessage; if (minimumLength != 0) { ValidationParameters["minlength"] = new AttributeValuePair("ng-minlength", minimumLength); } if (maximumLength != Int32.MaxValue) { ValidationParameters["maxlength"] = new AttributeValuePair("ng-maxlength", maximumLength); } }
private List <AttributeValuePair> CheckSubsets(Rule tempRules, KeyValuePair <string, List <int> > originalProbBlocks, bool conditionCheck = false) { for (int i = 0; i < tempRules.Conditions.Count; i++) { if (originalProbBlocks.Value.CheckSubset(tempRules.Conditions[i].Blocks)) { List <AttributeValuePair> rul = new List <AttributeValuePair>(); rul.Add(tempRules.Conditions[i]); return(rul); } } bool isSubset = false; List <AttributeValuePair> rules = new List <AttributeValuePair>(); rules.Add(tempRules.Conditions[0]); for (int i = 1; i < tempRules.Conditions.Count; i++) { for (int j = i; j < tempRules.Conditions.Count; j++) { var tempArr = new AttributeValuePair[rules.Count]; rules.CopyTo(tempArr); var tempList = tempArr.ToList(); tempList.Add(tempRules.Conditions[j]); var newIntersectBlock = tempList.Select(t => t.Blocks).IntersectAll().ToList(); if (originalProbBlocks.Value.CheckSubset(newIntersectBlock)) { isSubset = true; break; } } rules.Add(tempRules.Conditions[i]); if (isSubset) { break; } } if (isSubset) { return(rules); } else { return(null); } }
Cell <string> MkNodeStmt(string name, ArrayList attrs) { var node = AddNode(name); var couple = new Tuple <Microsoft.Msagl.Drawing.Label, NodeAttr>(new Microsoft.Msagl.Drawing.Label(node.Id), node.Attr); Microsoft.Msagl.Core.Layout.Node geomNode; couple = AttributeValuePair.AddNodeAttrs(couple, attrs, out geomNode); node.Label = couple.Item1; node.Label.Owner = node; node.Attr = couple.Item2; if (geomNode != null) { node.GeometryNode = geomNode; geomNode.UserData = node; } return(MkSingleton(name)); }
void MkEdgeStmt(string src, string dst, ArrayList attrs) { if (src == null || src == "") { src = " "; } if (dst == null || dst == "") { dst = " "; } var edge = graph.AddEdge(src, dst); if (currentSubgraph != null) { currentSubgraph.AddNode(graph.FindNode(src)); currentSubgraph.AddNode(graph.FindNode(dst)); } AttributeValuePair.AddEdgeAttrs(attrs, edge); }
AttributeValuePair MkAvPair(string src, string dst) { return(AttributeValuePair.CreateFromsStrings(src, dst)); }
public Rule RecursiveRuleInduction(Data data, List <AttributeValuePair> attributeValuePairs, KeyValuePair <string, List <int> > probBlocks, Rule tempRules, KeyValuePair <string, List <int> > originalProbBlocks) { if (attributeValuePairs.Count(t => t.Blocks.Count == 0) == attributeValuePairs.Count) { return(null); } List <AttributeValuePair> tempMatchingBlocks = new List <AttributeValuePair>(); foreach (var attributeValuePair in attributeValuePairs) { var matchAttrBlock = attributeValuePair.Blocks.Intersect(probBlocks.Value).ToList(); AttributeValuePair tempMatchAttrPair = new AttributeValuePair(); tempMatchAttrPair.AttributeValue.Attribute = attributeValuePair.AttributeValue.Attribute; tempMatchAttrPair.AttributeValue.Value = attributeValuePair.AttributeValue.Value; tempMatchAttrPair.Blocks = matchAttrBlock; tempMatchingBlocks.Add(tempMatchAttrPair); } //Get Maximum Count in matching block values var maxCountMatchBlock = tempMatchingBlocks.OrderByDescending(maxCountBlock => maxCountBlock.Blocks.Count).FirstOrDefault().Blocks.Count(); //Find the blocks based on the maximum count var maxMatchingBlocks = tempMatchingBlocks.Where(maxCountBlock => maxCountBlock.Blocks.Count == maxCountMatchBlock).ToList(); //Find the attribute value pair var selectedAttrValPair = data.AttributeValuePairs.Where(mainAttrValPair => maxMatchingBlocks.Exists(matchAttrPair => matchAttrPair.AttributeValue.Attribute == mainAttrValPair.AttributeValue.Attribute && matchAttrPair.AttributeValue.Value == mainAttrValPair.AttributeValue.Value)).OrderBy(maxCount => maxCount.Blocks.Count).First(); data.Decisions.TryGetValue(probBlocks.Key, out List <int> decision); //First Iteration if (tempRules == null) { //Check if the attribute is subset - FIRST Iteration if (originalProbBlocks.Value.CheckSubset(selectedAttrValPair.Blocks)) { Rule rule = new Rule(); rule.Decision = data.Decisions.Where(t => t.Key == probBlocks.Key).First(); rule.Conditions.Add(selectedAttrValPair); rule.Covers = originalProbBlocks.Value.Intersect(selectedAttrValPair.Blocks).ToList(); return(rule); } // If Not a Subset add it to the rules for next iterations else { tempRules = new Rule(); tempRules.Decision = data.Decisions.Where(t => t.Key == probBlocks.Key).First(); tempRules.Conditions.Add(selectedAttrValPair); var nextItrProbBlocks = new List <int>(maxMatchingBlocks.Where(t => t.AttributeValue == selectedAttrValPair.AttributeValue).First().Blocks); var nullify = tempMatchingBlocks.Where(t => t.AttributeValue == selectedAttrValPair.AttributeValue).First(); nullify.Blocks = new List <int>(); return(RecursiveRuleInduction(data, tempMatchingBlocks, new KeyValuePair <string, List <int> >(tempRules.Decision.Key, nextItrProbBlocks), tempRules, originalProbBlocks)); } } else { tempRules.Conditions.Add(selectedAttrValPair); //var newUnionBlock = tempRules.Rules.Select(t => t.Blocks).IntersectAll().ToList(); var rules = CheckSubsets(tempRules, originalProbBlocks); if (rules != null) { tempRules.Covers = originalProbBlocks.Value.Intersect(rules.Select(t => t.Blocks).IntersectAll()).ToList(); tempRules.Conditions = rules; return(tempRules); } else { //Unsuccessfull next iteration - var nextItrProbBlocks = new List <int>(maxMatchingBlocks.Where(t => t.AttributeValue == selectedAttrValPair.AttributeValue).First().Blocks); var nullify = tempMatchingBlocks.Where(t => t.AttributeValue == selectedAttrValPair.AttributeValue).First(); nullify.Blocks = new List <int>(); //return RecursiveRuleInduction(data, tempMatchingBlocks, new KeyValuePair<string, List<int>>(tempRules.Decision.Key, nextItrProbBlocks), tempRules, originalProbBlocks); if (!PrevBlocks.All(nextItrProbBlocks.Contains)) { PrevBlocks = nextItrProbBlocks; RepeatBlocks.Clear(); return(RecursiveRuleInduction(data, tempMatchingBlocks, new KeyValuePair <string, List <int> >(tempRules.Decision.Key, nextItrProbBlocks), tempRules, originalProbBlocks)); } else { RepeatBlocks.Add(nextItrProbBlocks.Count); if (RepeatBlocks.Skip(Math.Max(0, RepeatBlocks.Count() - 100)).Distinct().Count() == 1) { return(null); } else { return(RecursiveRuleInduction(data, tempMatchingBlocks, new KeyValuePair <string, List <int> >(tempRules.Decision.Key, nextItrProbBlocks), tempRules, originalProbBlocks)); } } //if(MaxIteration<10) } } }
internal static ImportStatistic SaveProductVariations(List<ProductVariationImportModel> data, UploadConfig config) { CatalogManager catalogManager = CatalogManager.GetManager(); List<ImportError> importErrors = new List<ImportError>(); int numberOfRecordsProcessed = 0; int numberOfSuccessfulRecords = 0; int numberOfFailedRecords = 0; foreach (ProductVariationImportModel productVariationImportModel in data) { try { numberOfRecordsProcessed++; Product parentProduct = catalogManager.GetProducts().Where(p => p.Status == ContentLifecycleStatus.Master && p.Sku == productVariationImportModel.ProductNameSku).FirstOrDefault(); if (parentProduct != null) { ProductAttribute productAttribute = catalogManager.GetProductAttributeByName(productVariationImportModel.AttributeName); if (productAttribute != null) { ProductAttributeValue attributeValue = catalogManager.GetProductAttributeValues().Where(pav => pav.Title == productVariationImportModel.ValueName).FirstOrDefault(); if (attributeValue != null) { ProductVariation productVariation = catalogManager.CreateProductVariation(); //Set the properties productVariation.AdditionalPrice = productVariationImportModel.AdditionalPrice; productVariation.Parent = parentProduct; productVariation.Sku = productVariationImportModel.Sku; productVariation.TrackInventory = productVariationImportModel.TrackInventory; if (productVariationImportModel.TrackInventory == TrackInventory.Track || productVariationImportModel.TrackInventory == TrackInventory.TrackByVariations) { productVariation.Inventory = productVariationImportModel.InventoryAmount; productVariation.OutOfStockOption = productVariationImportModel.OutOfStockOption; } productVariation.IsActive = productVariationImportModel.IsActive; //Set the Variant property List<AttributeValuePair> attributeValuePairs = new List<AttributeValuePair>(); AttributeValuePair attributeValuePair = new AttributeValuePair(); attributeValuePair.AttributeValueId = attributeValue.Id; attributeValuePair.AttributeId = attributeValue.Parent.Id; attributeValuePairs.Add(attributeValuePair); JavaScriptSerializer serializer = new JavaScriptSerializer(); string attributeValuePairsJson = serializer.Serialize(attributeValuePairs); productVariation.Variant = attributeValuePairsJson; //Create the product variation detail ProductVariationDetail detail = catalogManager.CreateProductVariationDetail(); detail.ProductAttributeParent = attributeValue.Parent; detail.ProductAttributeValueParent = attributeValue; detail.ProductVariationParent = productVariation; detail.ProductVariationDetailParentId = Guid.Empty; detail.Parent = parentProduct; parentProduct.ProductVariations.Add(productVariation); catalogManager.SaveChanges(); numberOfSuccessfulRecords++; } else { throw new ArgumentException("Cannot find attribute value with title " + productVariationImportModel.ValueName); } } else { throw new ArgumentException("Cannot find attribute with title " + productVariationImportModel.AttributeName); } } else { throw new ArgumentException("Cannot find product with Sku " + productVariationImportModel.ProductNameSku); } } catch (Exception ex) { numberOfFailedRecords++; importErrors.Add(new ImportError { ErrorMessage = ex.Message, ErrorRow = productVariationImportModel.CorrespondingRowData }); continue; } } ImportStatistic statisticsOfImport = new ImportStatistic { TotalNumberOfRecordsProcessed = numberOfRecordsProcessed, NumberOfSuccessfulRecords = numberOfSuccessfulRecords, NumberOfFailedRecords = numberOfFailedRecords, Errors = importErrors }; return statisticsOfImport; }
public EmailAddressValidationRule(string errorMessage) { ErrorMessage = errorMessage; ValidationParameters["email"] = new AttributeValuePair("type", "email"); }
public string Indent(string s) { string result; MemoryStream ms = new MemoryStream(s.Length); StreamWriter sw = new StreamWriter(ms); sw.Write(s); sw.Flush(); ms.Seek(0, SeekOrigin.Begin); StreamReader reader = new StreamReader(ms); XmlReader xmlReader = XmlReader.Create(reader.BaseStream); xmlReader.Read(); string str = ""; while (!xmlReader.EOF) { string xml; int num; int num6; int num7; int num8; switch (xmlReader.NodeType) { case XmlNodeType.Element: xml = ""; num = 0; goto Element; case XmlNodeType.Text: { string str4 = xmlReader.Value.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """); str = str + str4; xmlReader.Read(); continue; } case XmlNodeType.ProcessingInstruction: xml = ""; num7 = 0; goto ProcessingInstruction; case XmlNodeType.Comment: xml = ""; num8 = 0; goto Comment; case XmlNodeType.Whitespace: { xmlReader.Read(); continue; } case XmlNodeType.EndElement: xml = ""; num6 = 0; goto EndElement; default: goto Other; } Label_00C0: xml = xml + IndentString; num++; Element: if (num < xmlReader.Depth) { goto Label_00C0; } string elementName = xmlReader.Name; string str5 = str; str = str5 + "\r\n" + xml + "<" + xmlReader.Name; bool isEmptyElement = xmlReader.IsEmptyElement; if (xmlReader.HasAttributes) { // construct an array of the attributes that we reorder later on List <AttributeValuePair> attributes = new List <AttributeValuePair>(xmlReader.AttributeCount); for (int k = 0; k < xmlReader.AttributeCount; k++) { xmlReader.MoveToAttribute(k); if (_RemoveCommonDefaultValues) { if (!AttributeValuePair.IsCommonDefault(elementName, xmlReader.Name, xmlReader.Value)) { attributes.Add(new AttributeValuePair(elementName, xmlReader.Name, xmlReader.Value)); } } else { attributes.Add(new AttributeValuePair(elementName, xmlReader.Name, xmlReader.Value)); } } if (_ReorderAttributes) { attributes.Sort(); } xml = ""; string str3 = ""; int depth = xmlReader.Depth; //str3 = str3 + IndentString; for (int j = 0; j < depth; j++) { xml = xml + IndentString; } foreach (AttributeValuePair a in attributes) { string str7 = str; if (attributes.Count > _AttributeCounteTolerance && !AttributeValuePair.ForceNoLineBreaks(elementName)) { // break up attributes into different lines str = str7 + "\r\n" + xml + str3 + a.Name + "=\"" + a.Value + "\""; } else { // attributes on one line str = str7 + " " + a.Name + "=\"" + a.Value + "\""; } } } if (isEmptyElement) { str = str + "/"; } str = str + ">"; xmlReader.Read(); continue; Label_02F4: xml = xml + IndentString; num6++; EndElement: if (num6 < xmlReader.Depth) { goto Label_02F4; } string str8 = str; str = str8 + "\r\n" + xml + "</" + xmlReader.Name + ">"; xmlReader.Read(); continue; Label_037A: xml = xml + " "; num7++; ProcessingInstruction: if (num7 < xmlReader.Depth) { goto Label_037A; } string str9 = str; str = str9 + "\r\n" + xml + "<?Mapping " + xmlReader.Value + " ?>"; xmlReader.Read(); continue; Comment: if (num8 < xmlReader.Depth) { xml = xml + IndentString; num8++; } str = str + "\r\n" + xml + "<!--" + xmlReader.Value + "-->"; xmlReader.Read(); continue; Other: xmlReader.Read(); } xmlReader.Close(); result = str; return(result); }