private TileViewModel CreateItem(Product product, CurrencyString price) { var tileViewModel = new TileViewModel { Link = this.CreateProductActionLink(product), ImageId = product.MainImageId ?? Guid.Empty, Name = product.Name }; if (this.user != null) { var attributes = new AttributeList(); attributes.Add(new KeyValuePair <string, string>(StringResource.productTile_Available, this.GetProductAvailableString(product))); if (price != null) { attributes.Add(new KeyValuePair <string, string>(StringResource.productTile_Price, price.ToString())); } tileViewModel.Attributes = attributes; /* * if (!user.IsAdmin) * { * tileViewModel.Action = this.CreateAddToCartLink(product); * } */ } return(tileViewModel); }
internal void AddCallback(Type type, AttributeCallback callback) { Fx.Assert(type != null && callback != null, "type or callback parameter is null"); AttributeList list = GetTypeList(type); list.Add(callback); }
protected static AttributeList ConvertToAttributeList(object curvalue) { AttributeList multi; if (curvalue == null) { multi = new AttributeList(); // make list to hold multiple values multi.Add(curvalue); // Add previous single-valued attribute } else if (curvalue.GetType() == typeof(AttributeList)) { // already a list made by Template multi = (AttributeList)curvalue; } else if (curvalue is IList) { // existing attribute is non-Template List // must copy to an Template-managed list before adding new attribute // (can't alter incoming attributes) IList listAttr = (IList)curvalue; multi = new AttributeList(listAttr.Count); multi.AddRange(listAttr.Cast <object>()); } else { // curvalue nonlist and we want to Add an attribute // must convert curvalue existing to list multi = new AttributeList(); // make list to hold multiple values multi.Add(curvalue); // Add previous single-valued attribute } return(multi); }
/**********************************************************************************************//** * Creates single step all. * * \author Ilan Hindy * \date 29/09/2016 * **************************************************************************************************/ private void CreateSingleStepAll() { Breakpoint breakpoint = new Breakpoint(or[brp.ork.HostingElementType]); AttributeList parameters = new AttributeList(); parameters.Add(new Attribute { Value = bn.ork.SingleStepStatus }); parameters.Add(new Attribute { Value = true }); breakpoint.Create(HostingElementTypes.Network, true, Operators.Equeal, parameters, "Single Step"); this.AddParameter(new Attribute { Value = breakpoint }); }
private void ReadAttribute(ref AttributeList a) { SkipWhitespaces(true); if (Peek() == '/' || Peek() == '>') { // came here just to spend trailing whitespaces return; } string name = ReadName(); string value; SkipWhitespaces(); Expect('='); SkipWhitespaces(); switch (Read()) { case '\'': value = ReadUntil('\'', true); break; case '"': value = ReadUntil('"', true); break; default: throw Error("Invalid attribute value markup."); } a.Add(name, value); }
internal void Reset() { foreach (CharacterAttrib objAttribute in AttributeList.Concat(SpecialAttributeList)) { objAttribute.UnbindAttribute(); } AttributeList.Clear(); SpecialAttributeList.Clear(); foreach (string strAttribute in AttributeStrings) { CharacterAttrib objAttribute; switch (CharacterAttrib.ConvertToAttributeCategory(strAttribute)) { case CharacterAttrib.AttributeCategory.Special: objAttribute = new CharacterAttrib(_objCharacter, strAttribute, CharacterAttrib.AttributeCategory.Special); SpecialAttributeList.Add(objAttribute); break; case CharacterAttrib.AttributeCategory.Standard: objAttribute = new CharacterAttrib(_objCharacter, strAttribute); AttributeList.Add(objAttribute); break; } } BuildBindingList(); }
public void AddToState(BaseMessage message) { AttributeList state = OperationResults.Value[OperationResultKeys.State].Value; state.Add(new Attribute { Value = message }); }
public void AddAttribute(string key, string value) { if (AttributeList == null) { AttributeList = new List <KeyValuePair <string, string> >(); } AttributeList.Add(new KeyValuePair <string, string>(key, value)); }
public MethodTemplate(MethodInfo method) { Method = method; Name = method.Name; IsAsync = method.ReturnType.FullName.StartsWith(typeof(Task).FullName); ReturnType = new TypeTemplate(method.ReturnType); foreach (var attr in CustomAttributeData.GetCustomAttributes(method)) { AttributeList.Add(new CustomAttributeTemplate(attr).ToString()); } //方法参数 foreach (var parameter in method.GetParameters()) { Parameters.Add(new ParameterTemplate(parameter)); } if (method.IsGenericMethod) { foreach (var argumentType in method.GetGenericArguments()) { var argument = new GenericArgumentTemplate() { Name = argumentType.Name }; GenericArguments.Add(argument); if (argumentType.GenericParameterAttributes == GenericParameterAttributes.None && argumentType.GetGenericParameterConstraints().Length == 0) { continue; } //class约束 if (argumentType.GenericParameterAttributes.HasFlag(GenericParameterAttributes.ReferenceTypeConstraint)) { argument.Constraints.Add("class"); } //值类型约束 if (argumentType.GenericParameterAttributes.HasFlag(GenericParameterAttributes.NotNullableValueTypeConstraint)) { argument.Constraints.Add("struct"); } foreach (var type in argumentType.GetGenericParameterConstraints()) { argument.Constraints.Add(new TypeTemplate(type).ToString()); } //无参构造函数 if (argumentType.GenericParameterAttributes.HasFlag(GenericParameterAttributes.DefaultConstructorConstraint)) { argument.Constraints.Add("new()"); } } } }
public override AttributeList VisitAttributeList(AttributeList attributes) { AttributeList list = new AttributeList(); for (int i = 0; i < attributes.Count; i++) { AttributeNode a = attributes[i]; list.Add(VisitAttributeNode(a)); } return list; }
static AttributeList NoDefaultExpose() { AttributeList list = new AttributeList(2); if (SystemTypes.NoDefaultContractAttribute != null) { list.Add(new AttributeNode(new Literal(SystemTypes.NoDefaultContractAttribute, SystemTypes.Type), null, AttributeTargets.Method)); } return(list); }
public void AddMessage(BaseMessage message) { AttributeList channelMessages = OperationResults.Value[OperationResultKeys.ChannelMessages].Value; string messageString = message.GetField(BaseMessage.FieldKeys.MessageName).Value + ":" + message.GetHeaderField(BaseMessage.HeaderFieldKeys.SourceProcess).Value.ToString() + "->" + message.GetHeaderField(BaseMessage.HeaderFieldKeys.DestProcess).Value.ToString(); channelMessages.Add(new Attribute { Value = messageString }); }
/// <summary> /// Make an exact copy of this object using the cloneable /// interface. /// </summary> /// <returns>A new object that is a clone of the specified /// object.</returns> public override Object Clone() { AttributeList rtn = new AttributeList(); for (int i = 0; i < m_list.Count; i++) { rtn.Add((Attribute)this[i].Clone()); } return(rtn); }
public void OkAttribute() { attributeInfo = new Attribute { OptionId = Job.Id, AttributeName = NewAttributeName.AttributeName, }; AttributeList.Add(attributeInfo); database.Insert(attributeInfo); AttributeAddVisible = false; }
public Tag GetTag() { AttributeList attributes = new AttributeList(); foreach(Attribute x in List) { attributes.Add((Attribute)x.Clone()); } Tag retVal = new Tag(m_tag, attributes); return(retVal); }
public AttributeList GetTag() { AttributeList tag = new AttributeList(); tag.Name = m_tag; foreach (Attribute x in List) { tag.Add((Attribute)x.Clone()); } return(tag); }
private AttributeList ParseAttributes(Stream stream) { var attributes = new AttributeList(); var open = stream.Next(); Token token = null; //expecting identifier while (stream.Peek() != null) { token = stream.Peek(); switch (token.Type) { case TokenType.Identifier: attributes.Add(ParseAttribute(stream)); break; case TokenType.CloseBracket: //consume close bracket stream.NextNoReturn(); goto doneWithAttribute; default: //invalid token Errors.Add(new AttributeIdentifierMissing { Index = token.Index }); //throw new ParserException(token); return(attributes); } } doneWithAttribute: if (attributes.Count == 0) { //must be empty attribute list Errors.Add(new AttributeListEmpty { Index = token.Index }); return(attributes); //throw new ParserException(token); } //do reduction here return(attributes); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public List<int> ExstractChannelMessages(int sourceProcess, out AttributeList channelMessages) /// /// \brief Creates channel messages idxs. /// /// \par Description. /// - This method returns a list of indexes of the messages from a channel in the MessageQ /// - This method also creates a list of messages from the channel /// - Example /// - for a MessageQ which looks like: /// -# [0] from process 1 message1 /// -# [1] from process 2 message2 /// -# [2] from process 1 message3 /// - The following list for process 1 will be generated for the indexes /// -# [0] 0 /// -# [1] 2 /// - The following list will be generated for the messages /// -# [0] message1 /// -# [1] message3. /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 14/05/2018 /// /// \param sourceProcess (int) - Source process. /// \param [out] channelMessages (MessageQ) - The message q. /// /// \return The new channel messages idxs. //////////////////////////////////////////////////////////////////////////////////////////////////// public List <int> ExstractChannelMessages(int sourceProcess, out AttributeList channelMessages) { List <int> channelMessagesIdxs = new List <int>(); channelMessages = new AttributeList(); for (int idx = 0; idx < Count; idx++) { if (((BaseMessage)this[idx]).GetHeaderField(bm.pak.SourceProcess) == sourceProcess) { channelMessagesIdxs.Add(idx); BaseMessage newMessage = new BaseMessage(network, this[idx]); channelMessages.Add(newMessage); } } return(channelMessagesIdxs); }
/**********************************************************************************************//** * Creates results lists. * * \author Ilan Hindy * \date 29/09/2016 * * \param processes The processes. * **************************************************************************************************/ public void CreateResultsLists(List <BaseProcess> processes) { int maxId = processes.Max(process => process.ea[ne.eak.Id]); AttributeList runningResults = or[brp.ork.LastRunningResult]; AttributeList checkingResults = or[brp.ork.LastCheckResult]; for (int idx = runningResults.Count; idx <= maxId; idx++) { runningResults.Add(new Attribute() { Value = "" }); checkingResults.Add(new Attribute() { Value = "" }); } }
public virtual AttributeList GetAttributes(string[] attributes) { UpdateJmxCache(); lock (this) { AttributeList ret = new AttributeList(); foreach (string key in attributes) { Attribute attr = attrCache[key]; if (Log.IsDebugEnabled()) { Log.Debug(key + ": " + attr); } ret.Add(attr); } return(ret); } }
internal void Reset() { AttributeList.Clear(); SpecialAttributeList.Clear(); foreach (string strAttribute in AttributeStrings) { CharacterAttrib att = new CharacterAttrib(_character, strAttribute); switch (att.ConvertToAttributeCategory(att.Abbrev)) { case CharacterAttrib.AttributeCategory.Special: SpecialAttributeList.Add(att); break; case CharacterAttrib.AttributeCategory.Standard: AttributeList.Add(att); break; } } BuildBindingList(); }
private void ParseAttributeFile(string file) { ShxAttributeNode root = null; List <ShxAttributeNode> nodes = null; ParseAttribute(file, out root, out nodes, String.Empty); string key = System.IO.Path.GetFileNameWithoutExtension(file).ToUpper(); if (AttributeListMap.ContainsKey(key) == false) { AttributeListMap.Add(key, nodes); AttributeList.Add(nodes); } if (AttributeRootMap.ContainsKey(key) == false) { AttributeRootMap.Add(key, root); } }
private void BindAttributes() { AttributeList.Clear(); var attributes = new List <NameValue>(); foreach (string keyAttributeId in GetUserPreference("Rock.KeyAttributes").SplitDelimitedValues()) { int attributeId = 0; if (Int32.TryParse(keyAttributeId, out attributeId)) { var attribute = Rock.Web.Cache.AttributeCache.Read(attributeId); if (attribute != null && attribute.IsAuthorized("View", CurrentPerson)) { AttributeList.Add(attribute.Id); } } } CreateControls(true); }
public virtual AttributeList GetAttributes(string[] attributeNames) { if (attributeNames == null || attributeNames.Length == 0) { throw new ArgumentException(); } UpdateMbeanInfoIfMetricsListChanged(); AttributeList result = new AttributeList(attributeNames.Length); foreach (string iAttributeName in attributeNames) { try { object value = GetAttribute(iAttributeName); result.Add(new Attribute(iAttributeName, value)); } catch (Exception) { continue; } } return(result); }
public void LoadFromHeroLab(XmlNode xmlStatBlockBaseNode) { Timekeeper.Start("load_char_attrib"); foreach (CharacterAttrib objAttribute in AttributeList.Concat(SpecialAttributeList)) { objAttribute.UnbindAttribute(); } AttributeList.Clear(); SpecialAttributeList.Clear(); XmlDocument objXmlDocument = XmlManager.Load(_objCharacter.IsCritter ? "critters.xml" : "metatypes.xml"); XmlNode xmlMetatypeNode = objXmlDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + _objCharacter.Metatype + "\"]"); XmlNode xmlCharNode = xmlMetatypeNode?.SelectSingleNode("metavariants/metavariant[name = \"" + _objCharacter.Metavariant + "\"]") ?? xmlMetatypeNode; // We only want to remake attributes for shifters in career mode, because they only get their second set of attributes when exporting from create mode into career mode XmlNode xmlCharNodeAnimalForm = _objCharacter.MetatypeCategory == "Shapeshifter" && _objCharacter.Created ? xmlMetatypeNode : null; foreach (string strAttribute in AttributeStrings) { // First, remake the attribute CharacterAttrib objAttribute = new CharacterAttrib(_objCharacter, strAttribute); objAttribute = RemakeAttribute(objAttribute, xmlCharNode); switch (CharacterAttrib.ConvertToAttributeCategory(objAttribute.Abbrev)) { case CharacterAttrib.AttributeCategory.Special: SpecialAttributeList.Add(objAttribute); break; case CharacterAttrib.AttributeCategory.Standard: AttributeList.Add(objAttribute); break; } if (xmlCharNodeAnimalForm != null) { objAttribute = new CharacterAttrib(_objCharacter, strAttribute, CharacterAttrib.AttributeCategory.Shapeshifter); objAttribute = RemakeAttribute(objAttribute, xmlCharNodeAnimalForm); switch (CharacterAttrib.ConvertToAttributeCategory(objAttribute.Abbrev)) { case CharacterAttrib.AttributeCategory.Special: SpecialAttributeList.Add(objAttribute); break; case CharacterAttrib.AttributeCategory.Standard: AttributeList.Add(objAttribute); break; } } // Then load in attribute karma levels (we'll adjust these later if the character is in Create mode) if (strAttribute == "ESS") // Not Essence though, this will get modified automatically instead of having its value set to the one HeroLab displays { continue; } XmlNode xmlHeroLabAttributeNode = xmlStatBlockBaseNode.SelectSingleNode("attributes/attribute[@name = \"" + GetAttributeEnglishName(strAttribute) + "\"]"); XmlNode xmlAttributeBaseNode = xmlHeroLabAttributeNode?.SelectSingleNode("@base"); if (xmlAttributeBaseNode != null && int.TryParse(xmlAttributeBaseNode.InnerText, out int intHeroLabAttributeBaseValue)) { int intAttributeMinimumValue = GetAttributeByName(strAttribute).MetatypeMinimum; if (intHeroLabAttributeBaseValue != intAttributeMinimumValue) { objAttribute.Karma = intHeroLabAttributeBaseValue - intAttributeMinimumValue; } } } if (!_objCharacter.Created && _objCharacter.BuildMethodHasSkillPoints) { // Allocate Attribute Points int intAttributePointCount = _objCharacter.TotalAttributes; CharacterAttrib objAttributeToPutPointsInto; // First loop through attributes where costs can be 100% covered with points do { objAttributeToPutPointsInto = null; int intAttributeToPutPointsIntoTotalKarmaCost = 0; foreach (CharacterAttrib objLoopAttribute in AttributeList) { if (objLoopAttribute.Karma == 0) { continue; } // Put points into the attribute with the highest total karma cost. // In case of ties, pick the one that would need more points to cover it (the other one will hopefully get picked up at a later cycle) int intLoopTotalKarmaCost = objLoopAttribute.TotalKarmaCost; if (objAttributeToPutPointsInto == null || (objLoopAttribute.Karma <= intAttributePointCount && (intLoopTotalKarmaCost > intAttributeToPutPointsIntoTotalKarmaCost || (intLoopTotalKarmaCost == intAttributeToPutPointsIntoTotalKarmaCost && objLoopAttribute.Karma > objAttributeToPutPointsInto.Karma)))) { objAttributeToPutPointsInto = objLoopAttribute; intAttributeToPutPointsIntoTotalKarmaCost = intLoopTotalKarmaCost; } } if (objAttributeToPutPointsInto != null) { objAttributeToPutPointsInto.Base = objAttributeToPutPointsInto.Karma; intAttributePointCount -= objAttributeToPutPointsInto.Karma; objAttributeToPutPointsInto.Karma = 0; } } while (objAttributeToPutPointsInto != null && intAttributePointCount > 0); // If any points left over, then put them all into the attribute with the highest karma cost if (intAttributePointCount > 0 && AttributeList.Any(x => x.Karma != 0)) { int intHighestTotalKarmaCost = 0; foreach (CharacterAttrib objLoopAttribute in AttributeList) { if (objLoopAttribute.Karma == 0) { continue; } // Put points into the attribute with the highest total karma cost. // In case of ties, pick the one that would need more points to cover it (the other one will hopefully get picked up at a later cycle) int intLoopTotalKarmaCost = objLoopAttribute.TotalKarmaCost; if (objAttributeToPutPointsInto == null || intLoopTotalKarmaCost > intHighestTotalKarmaCost || (intLoopTotalKarmaCost == intHighestTotalKarmaCost && objLoopAttribute.Karma > objAttributeToPutPointsInto.Karma)) { objAttributeToPutPointsInto = objLoopAttribute; intHighestTotalKarmaCost = intLoopTotalKarmaCost; } } if (objAttributeToPutPointsInto != null) { objAttributeToPutPointsInto.Base = intAttributePointCount; objAttributeToPutPointsInto.Karma -= intAttributePointCount; } } // Allocate Special Attribute Points intAttributePointCount = _objCharacter.TotalSpecial; // First loop through attributes where costs can be 100% covered with points do { objAttributeToPutPointsInto = null; int intAttributeToPutPointsIntoTotalKarmaCost = 0; foreach (CharacterAttrib objLoopAttribute in SpecialAttributeList) { if (objLoopAttribute.Karma == 0) { continue; } // Put points into the attribute with the highest total karma cost. // In case of ties, pick the one that would need more points to cover it (the other one will hopefully get picked up at a later cycle) int intLoopTotalKarmaCost = objLoopAttribute.TotalKarmaCost; if (objAttributeToPutPointsInto == null || (objLoopAttribute.Karma <= intAttributePointCount && (intLoopTotalKarmaCost > intAttributeToPutPointsIntoTotalKarmaCost || (intLoopTotalKarmaCost == intAttributeToPutPointsIntoTotalKarmaCost && objLoopAttribute.Karma > objAttributeToPutPointsInto.Karma)))) { objAttributeToPutPointsInto = objLoopAttribute; intAttributeToPutPointsIntoTotalKarmaCost = intLoopTotalKarmaCost; } } if (objAttributeToPutPointsInto != null) { objAttributeToPutPointsInto.Base = objAttributeToPutPointsInto.Karma; intAttributePointCount -= objAttributeToPutPointsInto.Karma; objAttributeToPutPointsInto.Karma = 0; } } while (objAttributeToPutPointsInto != null); // If any points left over, then put them all into the attribute with the highest karma cost if (intAttributePointCount > 0 && SpecialAttributeList.Any(x => x.Karma != 0)) { int intHighestTotalKarmaCost = 0; foreach (CharacterAttrib objLoopAttribute in SpecialAttributeList) { if (objLoopAttribute.Karma == 0) { continue; } // Put points into the attribute with the highest total karma cost. // In case of ties, pick the one that would need more points to cover it (the other one will hopefully get picked up at a later cycle) int intLoopTotalKarmaCost = objLoopAttribute.TotalKarmaCost; if (objAttributeToPutPointsInto == null || intLoopTotalKarmaCost > intHighestTotalKarmaCost || (intLoopTotalKarmaCost == intHighestTotalKarmaCost && objLoopAttribute.Karma > objAttributeToPutPointsInto.Karma)) { objAttributeToPutPointsInto = objLoopAttribute; intHighestTotalKarmaCost = intLoopTotalKarmaCost; } } if (objAttributeToPutPointsInto != null) { objAttributeToPutPointsInto.Base = intAttributePointCount; objAttributeToPutPointsInto.Karma -= intAttributePointCount; } } } ResetBindings(); _objCharacter.RefreshAttributeBindings(); Timekeeper.Finish("load_char_attrib"); }
private Field NewField(Identifier name, TypeNode type, Anonymity anon){ AttributeList attrs = null; if (anon != Anonymity.Unknown && anon != Anonymity.None){ attrs = new AttributeList(1); MemberBinding cons = new MemberBinding(null, SystemTypes.AnonymousAttribute.GetConstructor()); TypeNode tn = SystemTypes.AnonymityEnum; AttributeNode attr = new AttributeNode(cons, new ExpressionList(new NamedArgument(idAnonymity, new Literal(anon, SystemTypes.AnonymityEnum)))); attrs.Add(attr); } return new Field(null, attrs, FieldFlags.Public, name, type, null); }
public void Create(XmlNode charNode, int intValue, int intMinModifier = 0, int intMaxModifier = 0) { Timekeeper.Start("create_char_attrib"); foreach (CharacterAttrib objAttribute in AttributeList.Concat(SpecialAttributeList)) { objAttribute.UnbindAttribute(); } AttributeList.Clear(); SpecialAttributeList.Clear(); foreach (string strAttribute in AttributeStrings) { CharacterAttrib objAttribute; switch (CharacterAttrib.ConvertToAttributeCategory(strAttribute)) { case CharacterAttrib.AttributeCategory.Special: objAttribute = new CharacterAttrib(_objCharacter, strAttribute, CharacterAttrib.AttributeCategory.Special); SpecialAttributeList.Add(objAttribute); break; case CharacterAttrib.AttributeCategory.Standard: objAttribute = new CharacterAttrib(_objCharacter, strAttribute); AttributeList.Add(objAttribute); break; } } _objCharacter.BOD.AssignLimits(CommonFunctions.ExpressionToString(charNode["bodmin"]?.InnerText, intValue, intMinModifier), CommonFunctions.ExpressionToString(charNode["bodmax"]?.InnerText, intValue, intMaxModifier), CommonFunctions.ExpressionToString(charNode["bodaug"]?.InnerText, intValue, intMaxModifier)); _objCharacter.AGI.AssignLimits(CommonFunctions.ExpressionToString(charNode["agimin"]?.InnerText, intValue, intMinModifier), CommonFunctions.ExpressionToString(charNode["agimax"]?.InnerText, intValue, intMaxModifier), CommonFunctions.ExpressionToString(charNode["agiaug"]?.InnerText, intValue, intMaxModifier)); _objCharacter.REA.AssignLimits(CommonFunctions.ExpressionToString(charNode["reamin"]?.InnerText, intValue, intMinModifier), CommonFunctions.ExpressionToString(charNode["reamax"]?.InnerText, intValue, intMaxModifier), CommonFunctions.ExpressionToString(charNode["reaaug"]?.InnerText, intValue, intMaxModifier)); _objCharacter.STR.AssignLimits(CommonFunctions.ExpressionToString(charNode["strmin"]?.InnerText, intValue, intMinModifier), CommonFunctions.ExpressionToString(charNode["strmax"]?.InnerText, intValue, intMaxModifier), CommonFunctions.ExpressionToString(charNode["straug"]?.InnerText, intValue, intMaxModifier)); _objCharacter.CHA.AssignLimits(CommonFunctions.ExpressionToString(charNode["chamin"]?.InnerText, intValue, intMinModifier), CommonFunctions.ExpressionToString(charNode["chamax"]?.InnerText, intValue, intMaxModifier), CommonFunctions.ExpressionToString(charNode["chaaug"]?.InnerText, intValue, intMaxModifier)); _objCharacter.INT.AssignLimits(CommonFunctions.ExpressionToString(charNode["intmin"]?.InnerText, intValue, intMinModifier), CommonFunctions.ExpressionToString(charNode["intmax"]?.InnerText, intValue, intMaxModifier), CommonFunctions.ExpressionToString(charNode["intaug"]?.InnerText, intValue, intMaxModifier)); _objCharacter.LOG.AssignLimits(CommonFunctions.ExpressionToString(charNode["logmin"]?.InnerText, intValue, intMinModifier), CommonFunctions.ExpressionToString(charNode["logmax"]?.InnerText, intValue, intMaxModifier), CommonFunctions.ExpressionToString(charNode["logaug"]?.InnerText, intValue, intMaxModifier)); _objCharacter.WIL.AssignLimits(CommonFunctions.ExpressionToString(charNode["wilmin"]?.InnerText, intValue, intMinModifier), CommonFunctions.ExpressionToString(charNode["wilmax"]?.InnerText, intValue, intMaxModifier), CommonFunctions.ExpressionToString(charNode["wilaug"]?.InnerText, intValue, intMaxModifier)); _objCharacter.MAG.AssignLimits(CommonFunctions.ExpressionToString(charNode["magmin"]?.InnerText, intValue, intMinModifier), CommonFunctions.ExpressionToString(charNode["magmax"]?.InnerText, intValue, intMaxModifier), CommonFunctions.ExpressionToString(charNode["magaug"]?.InnerText, intValue, intMaxModifier)); _objCharacter.RES.AssignLimits(CommonFunctions.ExpressionToString(charNode["resmin"]?.InnerText, intValue, intMinModifier), CommonFunctions.ExpressionToString(charNode["resmax"]?.InnerText, intValue, intMaxModifier), CommonFunctions.ExpressionToString(charNode["resaug"]?.InnerText, intValue, intMaxModifier)); _objCharacter.EDG.AssignLimits(CommonFunctions.ExpressionToString(charNode["edgmin"]?.InnerText, intValue, intMinModifier), CommonFunctions.ExpressionToString(charNode["edgmax"]?.InnerText, intValue, intMaxModifier), CommonFunctions.ExpressionToString(charNode["edgaug"]?.InnerText, intValue, intMaxModifier)); _objCharacter.DEP.AssignLimits(CommonFunctions.ExpressionToString(charNode["depmin"]?.InnerText, intValue, intMinModifier), CommonFunctions.ExpressionToString(charNode["depmax"]?.InnerText, intValue, intMaxModifier), CommonFunctions.ExpressionToString(charNode["depaug"]?.InnerText, intValue, intMaxModifier)); _objCharacter.MAGAdept.AssignLimits(CommonFunctions.ExpressionToString(charNode["magmin"]?.InnerText, intValue, intMinModifier), CommonFunctions.ExpressionToString(charNode["magmax"]?.InnerText, intValue, intMaxModifier), CommonFunctions.ExpressionToString(charNode["magaug"]?.InnerText, intValue, intMaxModifier)); _objCharacter.ESS.AssignLimits(CommonFunctions.ExpressionToString(charNode["essmin"]?.InnerText, intValue, 0), CommonFunctions.ExpressionToString(charNode["essmax"]?.InnerText, intValue, 0), CommonFunctions.ExpressionToString(charNode["essaug"]?.InnerText, intValue, 0)); Attributes = new ObservableCollection <CharacterAttrib> { _objCharacter.BOD, _objCharacter.AGI, _objCharacter.REA, _objCharacter.STR, _objCharacter.CHA, _objCharacter.INT, _objCharacter.LOG, _objCharacter.WIL, _objCharacter.EDG }; if (_objCharacter.MAGEnabled) { Attributes.Add(_objCharacter.MAG); if (_objCharacter.Options.MysAdeptSecondMAGAttribute && _objCharacter.IsMysticAdept) { Attributes.Add(_objCharacter.MAGAdept); } } if (_objCharacter.RESEnabled) { Attributes.Add(_objCharacter.RES); } if (_objCharacter.DEPEnabled) { Attributes.Add(_objCharacter.DEP); } ResetBindings(); _objCharacter.RefreshAttributeBindings(); Timekeeper.Finish("create_char_attrib"); }
public void Load(XmlNode xmlSavedCharacterNode) { Timekeeper.Start("load_char_attrib"); foreach (CharacterAttrib objAttribute in AttributeList.Concat(SpecialAttributeList)) { objAttribute.UnbindAttribute(); } AttributeList.Clear(); SpecialAttributeList.Clear(); XmlDocument objXmlDocument = XmlManager.Load(_objCharacter.IsCritter ? "critters.xml" : "metatypes.xml"); XmlNode xmlMetatypeNode = objXmlDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + _objCharacter.Metatype + "\"]"); XmlNode xmlCharNode = xmlMetatypeNode?.SelectSingleNode("metavariants/metavariant[name = \"" + _objCharacter.Metavariant + "\"]") ?? xmlMetatypeNode; // We only want to remake attributes for shifters in career mode, because they only get their second set of attributes when exporting from create mode into career mode XmlNode xmlCharNodeAnimalForm = _objCharacter.MetatypeCategory == "Shapeshifter" && _objCharacter.Created ? xmlMetatypeNode : null; foreach (string strAttribute in AttributeStrings) { XmlNodeList lstAttributeNodes = xmlSavedCharacterNode.SelectNodes("attributes/attribute[name = \"" + strAttribute + "\"]"); // Couldn't find the appopriate attribute in the loaded file, so regenerate it from scratch. if (lstAttributeNodes == null || lstAttributeNodes.Count == 0 || xmlCharNodeAnimalForm != null && _objCharacter.LastSavedVersion < new Version("5.200.25")) { CharacterAttrib objAttribute; switch (CharacterAttrib.ConvertToAttributeCategory(strAttribute)) { case CharacterAttrib.AttributeCategory.Special: objAttribute = new CharacterAttrib(_objCharacter, strAttribute, CharacterAttrib.AttributeCategory.Special); objAttribute = RemakeAttribute(objAttribute, xmlCharNode); SpecialAttributeList.Add(objAttribute); break; case CharacterAttrib.AttributeCategory.Standard: objAttribute = new CharacterAttrib(_objCharacter, strAttribute); objAttribute = RemakeAttribute(objAttribute, xmlCharNode); AttributeList.Add(objAttribute); break; } if (xmlCharNodeAnimalForm == null) { continue; } objAttribute = new CharacterAttrib(_objCharacter, strAttribute, CharacterAttrib.AttributeCategory.Shapeshifter); objAttribute = RemakeAttribute(objAttribute, xmlCharNodeAnimalForm); switch (CharacterAttrib.ConvertToAttributeCategory(objAttribute.Abbrev)) { case CharacterAttrib.AttributeCategory.Special: SpecialAttributeList.Add(objAttribute); break; case CharacterAttrib.AttributeCategory.Standard: AttributeList.Add(objAttribute); break; } } else { foreach (XmlNode xmlAttributeNode in lstAttributeNodes) { CharacterAttrib att = new CharacterAttrib(_objCharacter, strAttribute); att.Load(xmlAttributeNode); switch (CharacterAttrib.ConvertToAttributeCategory(att.Abbrev)) { case CharacterAttrib.AttributeCategory.Special: SpecialAttributeList.Add(att); break; case CharacterAttrib.AttributeCategory.Standard: AttributeList.Add(att); break; } } } } Attributes = new ObservableCollection <CharacterAttrib> { _objCharacter.BOD, _objCharacter.AGI, _objCharacter.REA, _objCharacter.STR, _objCharacter.CHA, _objCharacter.INT, _objCharacter.LOG, _objCharacter.WIL, _objCharacter.EDG }; if (_objCharacter.MAGEnabled) { Attributes.Add(_objCharacter.MAG); if (_objCharacter.Options.MysAdeptSecondMAGAttribute && _objCharacter.IsMysticAdept) { Attributes.Add(_objCharacter.MAGAdept); } } if (_objCharacter.RESEnabled) { Attributes.Add(_objCharacter.RES); } if (_objCharacter.DEPEnabled) { Attributes.Add(_objCharacter.DEP); } ResetBindings(); _objCharacter.RefreshAttributeBindings(); Timekeeper.Finish("load_char_attrib"); }
private void UpdateAttributeList() { if (_records.Count > 1) { AttributeList attrList = new AttributeList(); foreach (var attr in _attributes) { if (attr.Type != AttributeType.AttributeList) { foreach (var extent in attr.Extents) { attrList.Add(AttributeListRecord.FromAttribute(extent.Value, extent.Key.File)); } } } StructuredNtfsAttribute<AttributeList> alAttr; alAttr = (StructuredNtfsAttribute<AttributeList>)GetAttribute(AttributeType.AttributeList, null); alAttr.Content = attrList; alAttr.Save(); } }
public override AttributeList VisitAttributeList(AttributeList attributes) { if (attributes == null) return null; AttributeList rval = new AttributeList(); for (int i = 0, n = attributes.Count; i < n; i++) { rval.Add(this.VisitAttributeNode(attributes[i])); } return rval; }
private ClientItemAttributes(DbAttribute attribute) : base(attribute) { AttributeList.Add(this); }
private ClientResourceAttributes(DbAttribute attribute) : base(attribute) { AttributeList.Add(this); }
static AttributeList CreateAttributeList(TypeNode[] attributeTypes, AttributeTargets target){ AttributeList list = new AttributeList(1); foreach (TypeNode t in attributeTypes){ if (t != null){ InstanceInitializer ctor = t.GetConstructor(); if (ctor != null){ list.Add(new AttributeNode(new MemberBinding(null, ctor), null, target)); } } } return list; }
private ClientCheevoAttributes(DbAttribute attribute) : base(attribute) { AttributeList.Add(this); }
public virtual AttributeList GetAttributes(TypeNode attributeType, int maxCount) { AttributeList foundAttributes = new AttributeList(); if(attributeType == null) return foundAttributes; AttributeList attributes = this.Attributes; for(int i = 0, count = 0, n = attributes == null ? 0 : attributes.Count; i < n && count < maxCount; i++) { AttributeNode attr = attributes[i]; if(attr == null) continue; MemberBinding mb = attr.Constructor as MemberBinding; if(mb != null) { if(mb.BoundMember == null) continue; if(mb.BoundMember.DeclaringType != attributeType) continue; foundAttributes.Add(attr); count++; continue; } Literal lit = attr.Constructor as Literal; if(lit == null) continue; if((lit.Value as TypeNode) != attributeType) continue; foundAttributes.Add(attr); count++; } return foundAttributes; }
public virtual AttributeList GetFilteredAttributes(TypeNode attributeType) { if(attributeType == null) return this.Attributes; AttributeList attributes = this.Attributes; AttributeList filtered = new AttributeList(); for(int i = 0, n = attributes == null ? 0 : attributes.Count; i < n; i++) { AttributeNode attr = attributes[i]; if(attr == null) continue; MemberBinding mb = attr.Constructor as MemberBinding; if(mb != null) { if(mb.BoundMember != null && mb.BoundMember.DeclaringType == attributeType) continue; filtered.Add(attr); continue; } Literal lit = attr.Constructor as Literal; if(lit != null && (lit.Value as TypeNode) == attributeType) continue; filtered.Add(attr); } return filtered; }
/// <summary> /// Get the attributes of a delegate /// DIEGO-TODO: Include code to try to get the attributes from the type itself /// </summary> /// <param name="v"></param> /// <returns></returns> protected AttributeList GetDelegateAttributes(Variable v) { Nodes ns = this.Values(v); AttributeList res = new AttributeList(); // Obtain the set of fields or variables that may refer to the // nodes pointed by v Set<Variable> vs = this.MayPoint(ns); Set<Node> VarOrFields = this.pointsToGraph.GetReferences(ns); foreach (Node vof in VarOrFields) { if (vof is Parameter) { Parameter p = (Parameter)vof; foreach (AttributeNode attr in p.Attributes) res.Add(attr); } // If it is a closure with get the attribute from the enclosing method if (vof is Field) { Field f = (Field)vof; if (PointsToAnalysis.IsCompilerGenerated(this.Method)) { PointsToState pts = this.pta.EnclosingState(this.Method.DeclaringType); if (pts != null) { Variable v1 = pts.GetVariableByName(f.Name.Name); if (v1 is Parameter) { Parameter p = (Parameter)v1; foreach (AttributeNode attr in p.Attributes) res.Add(attr); } } } } } return res; }
private AttributeList ParseAttributes(Namespace ns, TokenSet followers){ if (this.currentToken != Token.LeftBracket) return null; AttributeList attributes = new AttributeList(); bool allowGlobalAttributes = ns != null && ns.Name == Identifier.Empty && (ns.NestedNamespaces == null || ns.NestedNamespaces.Count == 0) && (ns.Types == null || ns.Types.Count == 0); while(this.currentToken == Token.LeftBracket){ SourceContext sctx = this.scanner.CurrentSourceContext; this.GetNextToken(); AttributeTargets flags = (AttributeTargets)0; Identifier id = this.scanner.GetIdentifier(); SourceContext attrCtx = this.scanner.CurrentSourceContext; switch(this.currentToken){ case Token.Event: case Token.Identifier: case Token.Return: this.GetNextToken(); if (this.currentToken == Token.Colon){ this.GetNextToken(); int key = id.UniqueIdKey; if (key == Parser.assemblyId.UniqueIdKey) flags = AttributeTargets.Assembly; else if (key == Parser.eventId.UniqueIdKey) flags = AttributeTargets.Event; else if (key == Parser.fieldId.UniqueIdKey) flags = AttributeTargets.Field; else if (key == Parser.methodId.UniqueIdKey) flags = AttributeTargets.Method|AttributeTargets.Constructor; else if (key == Parser.moduleId.UniqueIdKey) flags = AttributeTargets.Module; else if (key == Parser.paramId.UniqueIdKey) flags = AttributeTargets.Parameter; else if (key == Parser.propertyId.UniqueIdKey) flags = AttributeTargets.Property; else if (key == Parser.returnId.UniqueIdKey) flags = AttributeTargets.ReturnValue; else if (key == Parser.typeId.UniqueIdKey) flags = AttributeTargets.Class|AttributeTargets.Delegate|AttributeTargets.Enum|AttributeTargets.Interface|AttributeTargets.Struct; else{ flags = (AttributeTargets)int.MaxValue; this.HandleError(Error.InvalidAttributeLocation, id.ToString()); } id = this.scanner.GetIdentifier(); this.SkipIdentifierOrNonReservedKeyword(); } break; default: this.SkipIdentifierOrNonReservedKeyword(); break; } for(;;){ AttributeNode attr = new AttributeNode(); attr.SourceContext = attrCtx; attr.Target = flags; if (this.currentToken == Token.DoubleColon){ Identifier prefix = id; this.GetNextToken(); id = this.scanner.GetIdentifier(); id.Prefix = prefix; id.SourceContext.StartPos = prefix.SourceContext.StartPos; this.SkipIdentifierOrNonReservedKeyword(); } if (this.sink != null) this.sink.StartName(id); if (this.currentToken == Token.Dot) attr.Constructor = this.ParseQualifiedIdentifier(id, followers|Token.Comma|Token.LeftParenthesis|Token.RightBracket); else attr.Constructor = id; this.ParseAttributeArguments(attr, followers|Token.Comma|Token.RightBracket); if (flags != (AttributeTargets)int.MaxValue){ if (allowGlobalAttributes && (flags == AttributeTargets.Assembly || flags == AttributeTargets.Module)){ if (ns.Attributes == null) ns.Attributes = new AttributeList(); ns.Attributes.Add(attr); }else attributes.Add(attr); } if (this.currentToken != Token.Comma) break; this.GetNextToken(); if (this.currentToken == Token.RightBracket) break; id = this.scanner.GetIdentifier(); this.SkipIdentifierOrNonReservedKeyword(); } this.ParseBracket(sctx, Token.RightBracket, followers, Error.ExpectedRightBracket); } this.SkipTo(followers); return attributes; }
private AttributeList GetPermissionAttributes(int blobIndex, System.Security.Permissions.SecurityAction action) { AttributeList result = new AttributeList(); int blobLength; MemoryCursor sigReader = this.tables.GetBlobCursor(blobIndex, out blobLength); if (blobLength == 0) return null; byte header = sigReader.ReadByte(); if (header != (byte)'*') { if (header == (byte)'<') return null; if (header == (byte)'.') return this.GetPermissionAttributes2(blobIndex, action); HandleError(this.module, ExceptionStrings.BadSecurityPermissionSetBlob); return null; } sigReader.ReadInt32(); //Skip over the token for the attribute target sigReader.ReadInt32(); //Skip over the security action int numAttrs = sigReader.ReadInt32(); for (int i = 0; i < numAttrs; i++) result.Add(this.GetPermissionAttribute(sigReader)); return result; }
private ClientQuestsAttributes(DbAttribute attribute) : base(attribute) { AttributeList.Add(this); }
private void ParseAttributeList(AttributeList list, char term) { char ch = _current.SkipWhitespace(); while (ch != term) { if (ch == '%') { Entity e = ParseParameterEntity(_parameterEntityTerm); PushEntity(_current.ResolvedUri, e); ParseAttributeList(list, Entity.EOF); PopEntity(); ch = _current.SkipWhitespace(); } else if (ch == '-') { ch = ParseDeclarationComments(); } else { AttributeDefinition a = ParseAttributeDefinition(ch); list.Add(a); } ch = _current.SkipWhitespace(); } }
public virtual Differences VisitAttributeList(AttributeList list1, AttributeList list2, out AttributeList changes, out AttributeList deletions, out AttributeList insertions){ changes = list1 == null ? null : list1.Clone(); deletions = list1 == null ? null : list1.Clone(); insertions = list1 == null ? new AttributeList() : list1.Clone(); //^ assert insertions != null; Differences differences = new Differences(); for (int j = 0, n = list2 == null ? 0 : list2.Count; j < n; j++){ //^ assert list2 != null; AttributeNode nd2 = list2[j]; if (nd2 == null) continue; insertions.Add(null); } TrivialHashtable savedDifferencesMapFor = this.differencesMapFor; this.differencesMapFor = null; TrivialHashtable matchedNodes = new TrivialHashtable(); for (int i = 0, k = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){ //^ assert list1 != null && changes != null && deletions != null; AttributeNode nd1 = list1[i]; if (nd1 == null) continue; Differences diff; int j; AttributeNode nd2 = this.GetClosestMatch(nd1, list1, list2, i, ref k, matchedNodes, out diff, out j); if (nd2 == null || diff == null){Debug.Assert(nd2 == null && diff == null); continue;} matchedNodes[nd1.UniqueKey] = nd1; matchedNodes[nd2.UniqueKey] = nd2; changes[i] = diff.Changes as AttributeNode; deletions[i] = diff.Deletions as AttributeNode; insertions[i] = diff.Insertions as AttributeNode; insertions[n+j] = nd1; //Records the position of nd2 in list2 in case the change involved a permutation Debug.Assert(diff.Changes == changes[i] && diff.Deletions == deletions[i] && diff.Insertions == insertions[i]); differences.NumberOfDifferences += diff.NumberOfDifferences; differences.NumberOfSimilarities += diff.NumberOfSimilarities; } //Find deletions for (int i = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){ //^ assert list1 != null && changes != null && deletions != null; AttributeNode nd1 = list1[i]; if (nd1 == null) continue; if (matchedNodes[nd1.UniqueKey] != null) continue; changes[i] = null; deletions[i] = nd1; insertions[i] = null; differences.NumberOfDifferences += 1; } //Find insertions for (int j = 0, n = list1 == null ? 0 : list1.Count, m = list2 == null ? 0 : list2.Count; j < m; j++){ //^ assert list2 != null; AttributeNode nd2 = list2[j]; if (nd2 == null) continue; if (matchedNodes[nd2.UniqueKey] != null) continue; insertions[n+j] = nd2; //Records nd2 as an insertion into list1, along with its position in list2 differences.NumberOfDifferences += 1; //REVIEW: put the size of the tree here? } if (differences.NumberOfDifferences == 0){ changes = null; deletions = null; insertions = null; } this.differencesMapFor = savedDifferencesMapFor; return differences; }
public virtual Template Add(string name, object value) { if (name == null) { throw new ArgumentNullException("name"); } if (name.IndexOf('.') >= 0) { throw new ArgumentException("cannot have '.' in attribute names"); } if (Group.TrackCreationEvents) { if (_debugState == null) { _debugState = new TemplateDebugState(); } _debugState.AddAttributeEvents.Add(name, new AddAttributeEvent(name, value)); } FormalArgument arg = null; if (impl.HasFormalArgs) { arg = impl.TryGetFormalArgument(name); if (arg == null) { throw new ArgumentException("no such attribute: " + name); } } else { // define and make room in locals (a hack to make new Template("simple template") work.) arg = impl.TryGetFormalArgument(name); if (arg == null) { // not defined arg = new FormalArgument(name); impl.AddArgument(arg); if (locals == null) { locals = new object[1]; } else { Array.Resize(ref locals, impl.FormalArguments.Count); } locals[arg.Index] = EmptyAttribute; } } object curvalue = locals[arg.Index]; if (curvalue == EmptyAttribute) { // new attribute locals[arg.Index] = value; return(this); } // attribute will be multi-valued for sure now // convert current attribute to list if not already // copy-on-Write semantics; copy a list injected by user to Add new value AttributeList multi = ConvertToAttributeList(curvalue); locals[arg.Index] = multi; // replace with list // now, Add incoming value to multi-valued attribute IList list = value as IList; if (list != null) { // flatten incoming list into existing list multi.AddRange(list.Cast <object>()); } else { multi.Add(value); } return(this); }
private AttributeList/*!*/ GetCustomAttributesFor(int parentIndex) { CustomAttributeRow[] customAttributes = this.tables.CustomAttributeTable; AttributeList attributes = new AttributeList(); try { int i = 0, n = customAttributes.Length, j = n - 1; if (n == 0) return attributes; bool sorted = (this.sortedTablesMask >> (int)TableIndices.CustomAttribute) % 2 == 1; if (sorted) { while (i < j) { int k = (i + j) / 2; if (customAttributes[k].Parent < parentIndex) i = k + 1; else j = k; } while (i > 0 && customAttributes[i - 1].Parent == parentIndex) i--; } for (; i < n; i++) if (customAttributes[i].Parent == parentIndex) attributes.Add(this.GetCustomAttribute(i)); else if (sorted) break; } catch (Exception e) { if (this.module == null) return attributes; if (this.module.MetadataImportErrors == null) this.module.MetadataImportErrors = new ArrayList(); this.module.MetadataImportErrors.Add(e); } return attributes; }
private AttributeList GetPermissionAttributes2(int blobIndex, System.Security.Permissions.SecurityAction action) { AttributeList result = new AttributeList(); int blobLength; MemoryCursor sigReader = this.tables.GetBlobCursor(blobIndex, out blobLength); if (blobLength == 0) return null; byte header = sigReader.ReadByte(); if (header != (byte)'.') { HandleError(this.module, ExceptionStrings.BadSecurityPermissionSetBlob); return null; } int numAttrs = sigReader.ReadCompressedInt(); for (int i = 0; i < numAttrs; i++) result.Add(this.GetPermissionAttribute2(sigReader, action)); return result; }
static AttributeList NoDefaultExpose() { AttributeList list = new AttributeList(2); if (SystemTypes.NoDefaultContractAttribute != null) { list.Add(new AttributeNode(new Literal(SystemTypes.NoDefaultContractAttribute, SystemTypes.Type), null, AttributeTargets.Method)); } return list; }
public bool Init(DbHolder holder) { try { if (!File.Exists(_file)) return false; string dbRawName = Path.GetFileNameWithoutExtension(_file); string dbName = _toDbName(dbRawName.Replace("_db", "")); string[] lines = File.ReadAllLines(_file); string[] itemsRaw = null; bool waitOne = false; foreach (string line in lines) { string t = line; string[] raw = t.Replace("[,", ",[").Replace("{,", ",{").Split(','); if (waitOne && raw.Length <= 1) break; if (waitOne) { raw[0] = raw[0].TrimStart('/', ' ', '\t'); itemsRaw = itemsRaw.Concat(raw).ToArray(); } else { itemsRaw = raw; } if (itemsRaw.Length > 1) { int end = itemsRaw.Length - 1; itemsRaw[end] = itemsRaw[end].Contains("//") ? itemsRaw[end].Substring(0, itemsRaw[end].IndexOf("//", StringComparison.Ordinal)) : itemsRaw[end]; waitOne = true; } } if (itemsRaw == null || itemsRaw.Length <= 1) return false; Dictionary<int, string> comments = new Dictionary<int, string>(); foreach (string line in lines) { if (!line.StartsWith("//")) break; string bufLine = line.Trim('/', ' '); if (bufLine.Length > 2 && bufLine[2] == '.') { int ival; if (Int32.TryParse(bufLine.Substring(0, 2), out ival)) { string t = bufLine.Substring(3).Trim(' ', '\t'); int index = t.LastIndexOf(" ", StringComparison.Ordinal); if (index > -1) { t = t.Substring(index); } else { index = t.LastIndexOf("\t\t", StringComparison.Ordinal); if (index > -1) { t = t.Substring(index); } } comments[ival] = t.Trim(' ', '\t'); } } } List<string> items = itemsRaw.ToList(); items[0] = items[0].TrimStart('/', ' '); items = items.ToList().Select(p => p.Trim(' ')).ToList(); HashSet<int> variable = new HashSet<int>(); if (items.Any(p => p == "...")) { // Find the longest line if (_hasLogic(items, variable)) { } else { int itemIndex = items.IndexOf("..."); List<int> count = lines.Select(line => line.Split(',').Length).ToList(); int missingArguments = count.Max(p => p) - items.Count; if (missingArguments == 0) { items[itemIndex] = "Unknown"; } else if (missingArguments < 0) { items.RemoveAt(itemIndex); } else { items.RemoveAt(itemIndex); for (int i = 0; i < missingArguments; i++) { items.Insert(itemIndex, "Variable"); variable.Add(itemIndex + i); } } } } if (items.Any(p => p.Contains('[')) || items.Any(p => p.Contains('{'))) { bool begin = false; for (int i = 0; i < items.Count; i++) { if (items[i].StartsWith("[") || items[i].StartsWith("{")) { if (items[i] != "{}") begin = true; } if (begin) { variable.Add(i); } if (items[i].EndsWith("]") || items[i].EndsWith("}")) { begin = false; } } } items = items.Select(p => p.Trim('[', ']', '{', '}')).ToList(); AttributeList list = new AttributeList(); IntLineStream reader = new IntLineStream(_file); Type dbType = typeof (int); bool? duplicates = reader.HasDuplicateIds(); if (duplicates == null || duplicates == true) { dbType = typeof (string); } bool first = true; DbAttribute bindingAttribute = null; for (int i = 0; i < items.Count; i++) { string value = items[i]; string desc = null; string toDisplay = _toDisplay(value); DbAttribute att; if (comments.ContainsKey(i + 1)) desc = comments[i + 1]; if (i == 0 && first) { if (duplicates == null) { att = new PrimaryAttribute(value, dbType, 0, toDisplay); } else if (duplicates == true) { att = new PrimaryAttribute("RealId", dbType, ""); first = false; i--; } else { att = new PrimaryAttribute(value, dbType, 0, toDisplay); } } else { string toLower = value.ToLower(); CustomAttribute custom = new CustomAttribute(value, typeof(string), "", toDisplay, desc); att = custom; if (toLower.Contains("skillid")) { att.AttachedObject = ServerDbs.Skills; custom.SetDataType(dbType == typeof(int) ? typeof(SelectTupleProperty<int>) : typeof(SelectTupleProperty<string>)); if (i == 1) bindingAttribute = new DbAttribute("Elements", typeof(SkillBinding), duplicates == true ? 2 : 1) { IsDisplayAttribute = true, Visibility = VisibleState.Hidden }; } if (toLower.Contains("mobid")) { att.AttachedObject = ServerDbs.Mobs; custom.SetDataType(dbType == typeof(int) ? typeof(SelectTupleProperty<int>) : typeof(SelectTupleProperty<string>)); if (i == 1) bindingAttribute = new DbAttribute("Elements", typeof(MobBinding), duplicates == true ? 2 : 1) { IsDisplayAttribute = true, Visibility = VisibleState.Hidden }; } if (toLower.Contains("itemid")) { att.AttachedObject = ServerDbs.Items; custom.SetDataType(dbType == typeof(int) ? typeof(SelectTupleProperty<int>) : typeof(SelectTupleProperty<string>)); if (i == 1) bindingAttribute = new DbAttribute("Elements", typeof(ItemBinding), duplicates == true ? 2 : 1) { IsDisplayAttribute = true, Visibility = VisibleState.Hidden }; } if (variable.Contains(i)) att.IsSkippable = true; } list.Add(att); } if (bindingAttribute != null) list.Add(bindingAttribute); else { string toLower = items[0].ToLower(); if (toLower.Contains("skillid")) { bindingAttribute = new DbAttribute("Elements", typeof(SkillBinding), duplicates == true ? 2 : 1) { IsDisplayAttribute = true, Visibility = VisibleState.Hidden }; } if (toLower.Contains("mobid")) { bindingAttribute = new DbAttribute("Elements", typeof(MobBinding), duplicates == true ? 2 : 1) { IsDisplayAttribute = true, Visibility = VisibleState.Hidden }; } if (toLower.Contains("itemid")) { bindingAttribute = new DbAttribute("Elements", typeof(ItemBinding), duplicates == true ? 2 : 1) { IsDisplayAttribute = true, Visibility = VisibleState.Hidden }; } if (bindingAttribute != null) list.Add(bindingAttribute); } if (dbType == typeof(int)) { _adb = new DummyDb<int>(); _adb.To<int>().TabGenerator.OnSetCustomCommands += GTabsMaker.SelectFromMobDb; _adb.To<int>().TabGenerator.OnSetCustomCommands += GTabsMaker.SelectFromItemDb; _adb.To<int>().TabGenerator.OnSetCustomCommands += GTabsMaker.SelectFromSkillDb; } else { _adb = new DummyDb<string>(); var db = _adb.To<string>(); if (duplicates == true) { db.LayoutIndexes = new int[] { 1, list.Attributes.Count }; db.DbLoader = DbLoaderMethods.DbUniqueLoader; db.DbWriter = DbWriterMethods.DbUniqueWriter; db.TabGenerator.OnInitSettings += delegate(GDbTabWrapper<string, ReadableTuple<string>> tab, GTabSettings<string, ReadableTuple<string>> settings, BaseDb gdb) { settings.CanChangeId = false; settings.CustomAddItemMethod = delegate { try { string id = Methods.RandomString(32); ReadableTuple<string> item = new ReadableTuple<string>(id, settings.AttributeList); item.Added = true; db.Table.Commands.StoreAndExecute(new AddTuple<string, ReadableTuple<string>>(id, item)); tab._listView.ScrollToCenterOfView(item); } catch (KeyInvalidException) { } catch (Exception err) { ErrorHandler.HandleException(err); } }; }; db.TabGenerator.StartIndexInCustomMethods = 1; db.TabGenerator.OnInitSettings += delegate(GDbTabWrapper<string, ReadableTuple<string>> tab, GTabSettings<string, ReadableTuple<string>> settings, BaseDb gdb) { settings.AttributeList = gdb.AttributeList; settings.AttId = gdb.AttributeList.Attributes[1]; settings.AttDisplay = gdb.AttributeList.Attributes.FirstOrDefault(p => p.IsDisplayAttribute) ?? gdb.AttributeList.Attributes[2]; settings.AttIdWidth = 60; }; db.TabGenerator.OnSetCustomCommands += GTabsMaker.SelectFromMobDbString; db.TabGenerator.OnSetCustomCommands += GTabsMaker.SelectFromSkillDbString; } else if (duplicates == null) { db.UnsafeContext = true; db.DbWriter = DbWriterMethods.DbStringCommaWriter; } } ServerDbs sdb = ServerDbs.Instantiate(dbRawName, dbName, FileType.Txt); if (bindingAttribute != null) bindingAttribute.AttachedObject = _adb; _adb.IsCustom = true; _adb.DbSource = sdb; _adb.AttributeList = list; return true; } catch { } return false; }
public virtual AttributeList VisitAttributeList(AttributeList attributes, AttributeList changes, AttributeList deletions, AttributeList insertions){ if (changes == null || deletions == null || insertions == null) return attributes; int n = attributes == null ? 0 : attributes.Count; if (n > changes.Count){Debug.Assert(false); n = changes.Count;} if (n > deletions.Count){Debug.Assert(false); n = deletions.Count;} if (n > insertions.Count){Debug.Assert(false); n = insertions.Count;} if (attributes != null) for (int i = 0; i < n; i++) attributes[i] = this.VisitAttributeNode(attributes[i], changes[i], deletions[i], insertions[i]); AttributeList result = new AttributeList(insertions.Count-n); for (int i = n, m = insertions.Count; i < m; i++) result.Add(insertions[i]); return result; }
protected static AttributeList ConvertToAttributeList(object curvalue) { AttributeList multi; if (curvalue == null) { multi = new AttributeList(); // make list to hold multiple values multi.Add(curvalue); // add previous single-valued attribute } else if (curvalue.GetType() == typeof(AttributeList)) { // already a list made by ST multi = (AttributeList)curvalue; } else if (curvalue is IList) { // existing attribute is non-ST List // must copy to an ST-managed list before adding new attribute // (can't alter incoming attributes) IList listAttr = (IList)curvalue; multi = new AttributeList(listAttr.Count); multi.AddRange(listAttr); } else if (curvalue.GetType().IsArray) { // copy array to list object[] a = (object[])curvalue; multi = new AttributeList(a.Length); multi.AddRange(a); // asList doesn't copy as far as I can tell } else { // curvalue nonlist and we want to add an attribute // must convert curvalue existing to list multi = new AttributeList(); // make list to hold multiple values multi.Add(curvalue); // add previous single-valued attribute } return multi; }