/// <summary> /// 5.4.3. Consume a qualified rule /// </summary> /// <returns></returns> private QualifiedRule ConsumeQualifiedRule() { //To consume a qualified rule: //Create a new qualified rule with its prelude initially set to an empty list, and its value initially set to nothing. QualifiedRule rule = new QualifiedRule(); // set operation is performed by CTOR. int startindex = -1; cssToken token = null; while (true) { //Repeatedly consume the next input token: token = ConsumeNextToken(); if (startindex == -1) { startindex = token.startIndex; } //<EOF-token> if (token.Type == enumTokenType.EOF) { //This is a parse error. Return nothing. return(null); } //<{-token> else if (token.Type == enumTokenType.curly_bracket_left) { //Consume a simple block and assign it to the qualified rule’s block. Return the qualified rule. SimpleBlock block = ConsumeSimpleBlock(); block.startindex = token.startIndex; rule.block = block; rule.startindex = startindex; rule.endindex = block.endindex; return(rule); } //simple block with an associated token of <{-token> //???????TODO: this must be an mistake in the syntax paper.. //Assign the block to the qualified rule’s block. Return the qualified rule. //anything else else { //Reconsume the current input token. Consume a component value. Append the returned value to the qualified rule’s prelude. ReconsumeToken(); ComponentValue value = ConsumeComponentValue(); rule.prelude.Add(value); } } }
private void RespondPlayerFood(Entity player, Entity food) { //play food sound ComponentTransform foodTransform = (ComponentTransform)food.FindComponent(ComponentTypes.COMPONENT_TRANSFORM); ComponentAudio foodAudio = (ComponentAudio)food.FindComponent(ComponentTypes.COMPONENT_AUDIO); Vector3 emitterPosition = (foodTransform).Position; int source = (foodAudio).Source; AL.Source(source, ALSource3f.Position, ref emitterPosition); foodAudio.Play(); //increase the score ComponentScore scoreComponent = (ComponentScore)player.FindComponent(ComponentTypes.COMPONENT_SCORE); float score = scoreComponent.Score; ComponentValue valueComponent = (ComponentValue)food.FindComponent(ComponentTypes.COMPONENT_VALUE); float value = valueComponent.Value; score += value; scoreComponent.Score = score; food.Enabled = false; }
public void TestSerialization() { var sut = new ComponentValue(); JsonHelper.GetSerializedKeys(sut).Should().BeEquivalentTo(new SortedSet <string> { "name", "value", "default", "price" }); }
/// <summary> ///Saves property values to be retained when opening the node /// </summary> protected override void SerializeCore(XmlElement nodeElement, SaveContext context) { base.SerializeCore(nodeElement, context); nodeElement.SetAttribute("ComponentId", ComponentId); nodeElement.SetAttribute("ComponentOption1", ComponentOption1.ToString()); nodeElement.SetAttribute("ComponentOption2", ComponentOption2.ToString()); nodeElement.SetAttribute("ComponentValue", ComponentValue.ToString()); }
private void ShowCVContent(ComponentValue cv) { if (cv.Content.ChoiceList.Count == 0) { return; } ComboBox_CVContent.Visibility = Visibility.Visible; ComboBox_CVContent.ItemsSource = cv.Content.ChoiceList; }
/// <summary> /// 5.4.7. Consume a simple block /// </summary> /// <returns></returns> private SimpleBlock ConsumeSimpleBlock() { //The ending token is the mirror variant of the current input token. (E.g. if it was called with <[-token>, the ending token is <]-token>.) enumTokenType endTokenType = enumTokenType.curly_bracket_right; if (currentToken.Type == enumTokenType.curly_bracket_left) { endTokenType = enumTokenType.curly_bracket_right; } else if (currentToken.Type == enumTokenType.round_bracket_left) { endTokenType = enumTokenType.round_bracket_right; } else if (currentToken.Type == enumTokenType.square_bracket_left) { endTokenType = enumTokenType.square_bracket_right; } //Create a simple block with its associated token set to the current input token and with a value with is initially an empty list. SimpleBlock simpleblock = new SimpleBlock(); simpleblock.token = currentToken; cssToken token; while (true) { token = ConsumeNextToken(); //Repeatedly consume the next input token and process it as follows: //<EOF-token> //ending token if (token.Type == enumTokenType.EOF || token.Type == endTokenType) { //Return the block. simpleblock.endindex = token.endIndex; if (token.Type == enumTokenType.EOF) { simpleblock.endindex = simpleblock.endindex - 1; } return(simpleblock); } //anything else else { //Reconsume the current input token. Consume a component value and append it to the value of the block. ReconsumeToken(); ComponentValue value = ConsumeComponentValue(); simpleblock.value.Add(value); } } }
private void RespondPlayerPowerup(Entity player, Entity food) { ComponentScore scoreComponent = (ComponentScore)player.FindComponent(ComponentTypes.COMPONENT_SCORE); float score = scoreComponent.Score; ComponentValue valueComponent = (ComponentValue)food.FindComponent(ComponentTypes.COMPONENT_VALUE); float value = valueComponent.Value; score += value; //change AI state //done through the AI system scoreComponent.Score = score; food.Enabled = false; }
// Would like to use <inheritdoc/> however DocFX cannot resolve to references outside Material.Blazor protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); ConditionalCssClasses .AddIf(DensityInfo.CssClassName, () => DensityInfo.ApplyCssClass) .AddIf("mdc-checkbox--disabled", () => AppliedDisabled); InputDisabled = AppliedDisabled; IsChecked = ComponentValue != null && ComponentValue.Equals(TargetCheckedValue); ForceShouldRenderToTrue = true; SetComponentValue += OnValueSetCallback; OnDisabledSet += OnDisabledSetCallback; }
/// <summary> /// 5.4.8. Consume a function /// </summary> /// <returns></returns> private Function ConsumeFunction() { //Create a function with a name equal to the value of the current input token, and with a value which is initially an empty list. /// before calling this method, the calling method must already check that current token is a function token. function_token token = currentToken as function_token; Function func = new Function(); func.name = token.Value; func.startindex = token.startIndex; cssToken nexttoken = null; while (true) { //Repeatedly consume the next input token and process it as follows: nexttoken = ConsumeNextToken(); //<EOF-token> //<)-token> if (nexttoken.Type == enumTokenType.EOF || nexttoken.Type == enumTokenType.round_bracket_right) { //Return the function. func.endindex = nexttoken.endIndex; if (nexttoken.Type == enumTokenType.EOF) { func.endindex = func.endindex - 1; } return(func); } //anything else else { //Reconsume the current input token. Consume a component value and append the returned value to the function’s value. ReconsumeToken(); ComponentValue value = ConsumeComponentValue(); func.value.Add(value); } } }
/// <summary> /// Handle Time Dimension components /// </summary> /// <param name="keyedValue"> /// The time dimension <see cref="ComponentValue"/> /// </param> private void HandleTimeDimension(ComponentValue keyedValue) { CrossSectionalLevels level = keyedValue.Key.EffectiveCrossSectionalAttachmentLevel == CrossSectionalLevels.None ? CrossSectionalLevels.Group : keyedValue.Key.EffectiveCrossSectionalAttachmentLevel; int index = GetIndex(level); this._keyValues[index].Add(keyedValue); this._dimensionValues[index].Add(keyedValue); }
/// <summary> /// Initialize the public order of the components based on the specified <paramref name="componentMappings"/> /// </summary> /// <param name="componentMappings"> /// The component mappings /// </param> private void SetComponentOrder(IEnumerable<IComponentMapping> componentMappings) { foreach (IComponentMapping componentMapping in componentMappings) { var componentValue = new ComponentValue(componentMapping.Component); this.ComponentValues.Add(componentValue); switch (componentMapping.Component.ComponentType) { case SdmxComponentType.Dimension: this._dimensionValues.Add(componentValue); break; case SdmxComponentType.Attribute: this._attributeValues.Add(componentValue); break; case SdmxComponentType.PrimaryMeasure: case SdmxComponentType.CrossSectionalMeasure: this._measureValues.Add(componentValue); break; } } }
/// <summary> /// Checks if the dimension at observation is in the dimension references of the component <paramref name="componentMappings"/> /// </summary> /// <param name="componentValue"> /// The component value /// </param> /// /// <param name="info"> /// The data retrieval info /// </param> private bool IsDimensionObsReference(ComponentValue componentValue, DataRetrievalInfo info) { IBaseDataQuery baseDataQuery = (IBaseDataQuery)info.ComplexQuery ?? info.Query; foreach (IAttributeObject attr in baseDataQuery.DataStructure.AttributeList.Attributes) { if (attr.Id.Equals(componentValue.Key.Id)) { if (attr.DimensionReferences.Contains(info.DimensionAtObservation)) return true; return false; } } return false; }
/// <summary> /// Initialize the public order of the components based on the specified <paramref name="componentMappings"/> /// </summary> /// <param name="componentMappings"> /// The component mappings /// </param> /// /// <param name="info"> /// The data retrieval info /// </param> private void SetComponentOrder(IEnumerable<IComponentMapping> componentMappings, DataRetrievalInfo info) { foreach (IComponentMapping componentMapping in componentMappings) { var componentValue = new ComponentValue(componentMapping.Component); this.ComponentValues.Add(componentValue); switch (componentMapping.Component.ComponentType) { case SdmxComponentType.Dimension: this._dimensionValues.Add(componentValue); if (!componentValue.Key.Id.Equals(info.DimensionAtObservation)) this._keyValues.Add(componentValue); break; case SdmxComponentType.Attribute: switch (componentMapping.Component.AttributeAttachmentLevel) { case AttachmentLevel.DataSet: this._attributeDataSetValues.Add(componentValue); break; case AttachmentLevel.Group: // NOTE we expect only the attributes of a specific group to be in _attributeGroupValues this._attributeGroupValues.Add(componentValue); break; case AttachmentLevel.Series: if (IsDimensionObsReference(componentValue, info)) this._attributeObservationValues.Add(componentValue); else this._attributeSeriesValues.Add(componentValue); break; case AttachmentLevel.Observation: this._attributeObservationValues.Add(componentValue); break; } break; case SdmxComponentType.PrimaryMeasure: this.PrimaryMeasureValue = componentValue; break; case SdmxComponentType.CrossSectionalMeasure: this._xsMeasures.Add(componentValue); break; } } }
/// <summary> /// Consume a list of declaration from a simple block. /// </summary> /// <param name="block"></param> /// <returns></returns> private static CSSStyleDeclaration ParseDeclarations(SimpleBlock block, ref int endindex, ref string CssText) { CSSStyleDeclaration declarations = new CSSStyleDeclaration(); string csstext = string.Empty; CSSDeclaration onedeclaration = null; bool colonfound = false; // check value before or after colon. int valuecount = block.value.Count; for (int i = 0; i < valuecount; i++) { ComponentValue item = block.value[i]; if (item.endindex > endindex) { endindex = item.endindex; } if (item.Type == CompoenentValueType.preservedToken) { PreservedToken token = item as PreservedToken; if (token.token.Type == enumTokenType.ident) { // the first ident is the start of one declaration. if (onedeclaration == null) { onedeclaration = new CSSDeclaration(); ident_token identtoken = token.token as ident_token; onedeclaration.propertyname = identtoken.value; colonfound = false; } else { onedeclaration.value += token.token.GetString(ref CssText); } } else if (token.token.Type == enumTokenType.semicolon || token.token.Type == enumTokenType.EOF) { // this is the end of one declaration. declarations.item.Add(onedeclaration); onedeclaration = null; colonfound = false; } else if (colonfound == false) { if (token.token.Type == enumTokenType.colon) { colonfound = true; } else if (token.token.Type == enumTokenType.whitespace) { // white space do nothing. } else { // the next one must be white space or colon, otherwise, error. //TODO: onError. } } else if (token.token.Type == enumTokenType.delim && ((delim_token)token.token).value == '!') { if ((i + 1) < valuecount) { if (block.value[i + 1].Type == CompoenentValueType.preservedToken) { PreservedToken important = block.value[i + 1] as PreservedToken; if (important.token.Type == enumTokenType.ident) { ident_token importantident = important.token as ident_token; if (importantident.value.ToLower() == "important" && onedeclaration != null) { onedeclaration.important = true; } } } // has to consume the important now, because value has been processed. i = i + 1; } } else { /// append the value to declaration value. if (onedeclaration != null) { onedeclaration.value += token.token.GetString(ref CssText); } } } else if (item.Type == CompoenentValueType.function) { Function func = item as Function; if (onedeclaration == null) { onedeclaration = new CSSDeclaration(); onedeclaration.propertyname = func.getString(ref CssText); colonfound = false; } else { if (colonfound) { onedeclaration.value += func.getString(ref CssText); } else { onedeclaration.propertyname += func.getString(ref CssText); } } } } if (onedeclaration != null && !string.IsNullOrEmpty(onedeclaration.propertyname)) { declarations.item.Add(onedeclaration); onedeclaration = null; colonfound = false; } if (block.endindex > endindex) { endindex = block.endindex; } return(declarations); }
/// <summary> /// Sample 1 - Import 3 indicator definitions exported from IMR in order of increasing complexity: simple count, percent, disaggregation /// </summary> /// <param name="args">None</param> static void Main(string[] args) { try { #region Initialise // Create new DOM Object to work with SDMXDom dom = new SDMXDom(); dom.OnDOMValidationError += new EventHandler <DOMValidationEventArgs>(dom_OnDOMValidationError); // Create an sdmxFile object to read / write files SDMXFile sdmxFile = new SDMXFile(); const string zipFileLocation = @"../../../../SDMX_Sample_Export.zip"; #endregion #region Load the DOM // Load + Unzip the IMR test data into the sdmFile object. // This object is used to manage all interaction with the phyical disk. sdmxFile.LoadFromZip(zipFileLocation); // Load the DOM + Validate using all files in the SDMXFilesContainer dom.Load(sdmxFile.Files, true); #endregion #region DSD Processing // Process the CodeLists Console.WriteLine("The CodeLists from the DSD are being processed \r\n"); foreach (CodeList codeList in dom.CodeListsDSD) { Console.WriteLine("[{0}] :", codeList.Identifier); if (codeList.Codes != null) { foreach (Code code in codeList.Codes) { Console.WriteLine("\t{0}", code); } } } WriteColorMessage("\r\nPress any key to process the HierarchicalCodeList...", ConsoleColor.Green); Console.ReadKey(); // Process the HierarchicalCodeList foreach (HierarchicalCodeList hierarchicalCodeList in dom.HierarchicalCodeLists) { Console.WriteLine("HierarchicalCodeList {0}, is being processed", hierarchicalCodeList.Identifier); foreach (Hierarchy hierarchy in hierarchicalCodeList.Hierarchies) { Console.WriteLine("\tHierarchy {0}, is being processed", hierarchy.ID); } } WriteColorMessage("\r\nPress any key to process the DSD Concepts...", ConsoleColor.Green); Console.ReadKey(); // Process the Concepts Console.WriteLine("The Concepts from the DSD are being processed \r\n"); foreach (ConceptScheme conceptScheme in dom.ConceptSchemesDSD) { Console.WriteLine("[{0}]", conceptScheme.Identifier); foreach (Concept Concept in conceptScheme.Concepts) { Console.WriteLine("\t{0} : {1}", Concept.Identifier, Concept.Name); } } WriteColorMessage("\r\nPress any key to process the Observation Data...", ConsoleColor.Green); Console.ReadKey(); // Process the Observation Data Console.WriteLine("The Observation Data are being processed \r\n"); if (dom.DataSet == null) { Console.WriteLine("No observation data found"); } else { foreach (Series serie in dom.DataSet.Series) { Console.WriteLine("The Indicator : {0}, is being processed", serie.Indicator.Description.EnglishOrFirst()); if (serie.Observations != null && serie.Observations.Count == 0) { Console.WriteLine("The Indicator : {0}, has no data", serie.Indicator.Description); } else { foreach (Observation obs in serie.Observations) { Console.WriteLine("The Indicator : {0}, has an observed data value of {1} for the time period {2}", serie.Indicator.Description, obs.Value, obs.TimePeriod); } } } } WriteColorMessage("\r\nPress any key to process the MSD CodeLists...", ConsoleColor.Green); Console.ReadKey(); #endregion #region MSD Processing // Process the CodeLists Console.WriteLine("The CodeLists from the MSD are being processed \r\n"); foreach (CodeList codeList in dom.CodeListsMSD) { Console.WriteLine("[{0}] :", codeList.Identifier); if (codeList.Codes != null) { foreach (Code code in codeList.Codes) { Console.WriteLine("\t{0}", code); } } } WriteColorMessage("\r\nPress any key to process the MSD Concepts", ConsoleColor.Green); Console.ReadKey(); // Process the MSD Concepts Console.WriteLine("The Concepts from the MSD are being processed \r\n"); foreach (ConceptScheme conceptScheme in dom.ConceptSchemesMSD) { Console.WriteLine("[{0}]", conceptScheme.Identifier); foreach (Concept Concept in conceptScheme.Concepts) { Console.WriteLine("\t{0} : {1}", Concept.Identifier, Concept.Name); } } WriteColorMessage("\r\nPress any key to process the MetadataStructures", ConsoleColor.Green); Console.ReadKey(); // Read the metadata associtated with each code-list Console.WriteLine("The MetadataStructures are being processed \r\n"); foreach (MetadataStructure mds in dom.MetadataStructures) { // Get metadatas for TargetIdentifier FTI FullTargetIdentifier fullTargetIdentifier = mds.FullTargetIdentifiers["FTI_WHO"]; // FIRST EXAMPLE : GET METADATA FOR A SINGLE IDENTIFIER COMPONENT // (i.e. Indicator Properties) if (fullTargetIdentifier != null) { // Get metadata for each identifier components foreach (IdentifierComponent ic in fullTargetIdentifier.IdentifierComponents) { // Get all AttributeValueSet corresponding to the current IdentifierComponent IEnumerable <AttributeValueSet> metadatas = ic.GetMetadata(fullTargetIdentifier, dom); if (metadatas == null) { Console.WriteLine("No metadata exists for the IdentifierComponent {0}", ic.ID); } else { // If there is metadata for the current IdentifierCompoment, loop on each attribute value set. // Here we can identifiy to which Code(s) the metadata correspond (i.e. Indicator 6) foreach (AttributeValueSet attributeValueSet in metadatas) { // Idenfiy the metadata Code ComponentValue targetValue = attributeValueSet.TargetValues.First(); Console.WriteLine("Metadatas for {0} {1}", ic.ID, targetValue.Value.Value); foreach (ReportedAttribute reportedAttribute in attributeValueSet.ReportedAttributes) { // Reported attribute value can be either localized or not (String or LocalizedString) // Therefore, we must check the value type before processing it. if (reportedAttribute.StringValue != null) { // Print the string value Console.WriteLine("\t{0} : {1}", reportedAttribute.Concept.Name, reportedAttribute.StringValue); } if (reportedAttribute.LocalizedStringValue != null) { // Print the string value for each language foreach (KeyValuePair <string, string> item in reportedAttribute.LocalizedStringValue) { Console.WriteLine("\t{0} [{1}] : {2}", reportedAttribute.Concept.Name, item.Key, item.Value); } } } } } } } // SECOND EXAMPLE : GET METADATA FOR MULTIPLE IDENTIFIER COMPONENTS // i.e. Indicator > IndicatorSet // Note : In our sdmx-hd file sample, there is not such metadatas so the result will be null. if (fullTargetIdentifier != null) { List <IdentifierComponent> idenfierComponents = new List <IdentifierComponent>() { fullTargetIdentifier.IdentifierComponents["IC_ISET"], fullTargetIdentifier.IdentifierComponents["IC_ISET"], fullTargetIdentifier.IdentifierComponents["IC_INDICATOR"] }; IEnumerable <AttributeValueSet> multipleIdenfierComponentsMetadatas = idenfierComponents.GetMetadata(fullTargetIdentifier, dom); } } #endregion } catch (SDMXException sdmxex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(sdmxex.Message); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex); } WriteColorMessage("\r\nPress any key to close the program...", ConsoleColor.Blue); Console.ReadKey(); }
/// <summary> /// Initialize the internal order of the components based on the specified <paramref name="componentMappings"/> /// </summary> /// <param name="componentMappings"> /// The component mappings /// </param> private void SetComponentOrder(IEnumerable<IComponentMapping> componentMappings) { foreach (IComponentMapping componentMapping in componentMappings) { var componentValue = new ComponentValue(componentMapping.Component); this.ComponentValues.Add(componentValue); CrossSectionalLevels attachmentLevel = componentMapping.Component.EffectiveCrossSectionalAttachmentLevel; attachmentLevel = attachmentLevel == CrossSectionalLevels.None && componentMapping.Component.FrequencyDimension ? CrossSectionalLevels.Group : attachmentLevel; int index = GetIndex(attachmentLevel); switch (componentMapping.Component.ComponentType) { case SdmxComponentType.Dimension: if (!componentMapping.Component.MeasureDimension) { this._keyValues[index].Add(componentValue); this._dimensionValues[index].Add(componentValue); } else { this.MeasureDimensionValue = componentValue; } break; case SdmxComponentType.Attribute: this._attributeValues[index].Add(componentValue); break; case SdmxComponentType.PrimaryMeasure: this.PrimaryMeasureValue = componentValue; break; case SdmxComponentType.CrossSectionalMeasure: this._xsMeasureValues.Add(componentValue); break; } } }
/// <summary> /// 5.4.2. Consume an at-rule /// </summary> /// <returns></returns> private AtRule ConsumeAtRule() { //To consume an at-rule: //Create a new at-rule with its name set to the value of the current input token, its prelude initially set to an empty list, and its value initially set to nothing. AtRule rule = new AtRule(); int startindex = -1; cssToken token = null; while (true) { //Repeatedly consume the next input token: token = ConsumeNextToken(); if (startindex == -1) { startindex = token.startIndex; } //<semicolon-token> //<EOF-token> if (token.Type == enumTokenType.semicolon || token.Type == enumTokenType.EOF) { //Return the at-rule. rule.startindex = startindex; rule.endindex = token.endIndex; if (token.Type == enumTokenType.EOF) { rule.endindex = rule.endindex - 1; } return(rule); } //<{-token> else if (token.Type == enumTokenType.curly_bracket_left) { //Consume a simple block and assign it to the at-rule’s block. Return the at-rule. SimpleBlock simpleblock = ConsumeSimpleBlock(); simpleblock.startindex = token.startIndex; rule.block = simpleblock; rule.startindex = startindex; rule.endindex = simpleblock.endindex; return(rule); } //simple block with an associated token of <{-token> //Assign the block to the at-rule’s block. Return the at-rule. ///TODO: ???? check what does this means??? //anything else else { //Reconsume the current input token. Consume a component value. Append the returned value to the at-rule’s prelude. ReconsumeToken(); ComponentValue value = ConsumeComponentValue(); rule.prelude.Add(value); } } }