示例#1
0
        /// <summary>
        /// Sets an indication that texts should be extracted in the languages of langs.
        /// </summary>
        /// <param name="langs">List of languagecodes. If empty setLangToAll() is called.</param>
        public void setLangs(List <string> langs)
        {
            if (langs.Count == 0)
            {
                setLangToAll();
            }
            else
            {
                myLanguageType[] tmpMyLangs = new myLanguageType[langs.Count];
                for (int n = 0; n < langs.Count; n++)
                {
                    tmpMyLangs[n]       = new myLanguageType();
                    tmpMyLangs[n].Value = langs[n];
                }

                this.Query.Languages.Items = tmpMyLangs;
            }
        }
示例#2
0
        // call this when there are no more segments
        // it converts lists to arrays and adds them to the object
        // (The lists are used when parsing since arrays cannot grow dynamically)
        //recodes data.Query.Time.TimeOption "1" to "2"
        private void postParse(FlatFileReaderHelper helper, string resultLanguage)
        {
            bool[] isElim    = new bool[helper.no_vars];
            int    elimCount = 0;

            // Traverses the variables one by one
            for (int n = 0; n < helper.no_vars; n++)
            {
                isElim[n] = helper.variableValues[n].Count < 1; // Common to all elimination: No values!
                if (isElim[n])
                {
                    elimCount++;
                }
                log.Debug("isElim=" + isElim[n] + " code" + helper.tmpVariable[n].code);
                //adds any group values

                // For each value vt belonging to the current variable n do ....
                foreach (ValueTypeWithGroup vt in helper.variableValues[n])
                {
                    // Checks if the current value code vt.code has a list of group codes associated with it
                    if (helper.groupsValuesByValueCode[n].ContainsKey(vt.code))
                    {
                        // If so, then create a temporary GroupValueType tmp to hold the list of group codes
                        List <GroupValueType> tmp = helper.groupsValuesByValueCode[n][vt.code];

                        // Creates an object of type ValueTypeWithGroupGroup and transfers the list of group codes to it
                        vt.Group            = new ValueTypeWithGroupGroup();
                        vt.Group.GroupValue = tmp.ToArray();
                        // Checks (on the sort order) if there is a ValueText (Group text) attached to any of the values
                        if (helper.groupTextByValueSortOrder[n].ContainsKey(vt.sortOrder))
                        {
                            // text er bare for grupper som kommer fra filer, hva med språk?
                            StringLangType[] tmpSLT = new StringLangType[1];
                            tmpSLT[0]       = new StringLangType();
                            tmpSLT[0].Value = helper.groupTextByValueSortOrder[n][vt.sortOrder];
                            if (helper.langInFile == null)
                            {
                                tmpSLT[0].lang = resultLanguage;
                                log.Warn("Found text but no language. Using " + resultLanguage);
                            }
                            else
                            {
                                tmpSLT[0].lang = helper.langInFile;
                            }
                            vt.Group.GroupText = tmpSLT;
                        }
                    }
                }

                // helper.tmpVariable[n].Values is an array of pointers to ValueTypeWithGroup,
                // which means that it is similar to helper.variableValues (which is a list)
                helper.tmpVariable[n].Values.Items = helper.variableValues[n].ToArray();
            }

            if ((int)this.Query.Time.TimeOption == 0)
            {
                TimeTypeTimeValues tttv = new TimeTypeTimeValues();
                tttv.TimeValue       = helper.timeValues.ToArray();
                this.Query.Time.Item = tttv;
            }
            else if ((int)this.Query.Time.TimeOption == 1)
            {
                this.Query.Time.TimeOption = (TimeTypeTimeOption)2;
                int noOfValues = 1;
                this.Query.Time.Item = noOfValues;
            }

            this.Query.Contents.Content = helper.contentValues.ToArray();

            if (helper.menuSelList.Count > 0)
            {
                this.Information.Menu = helper.menuSelList.ToArray();
            }

            #region set Language

            myLanguageType[] tmpMyLang = new myLanguageType[1];
            tmpMyLang[0] = new myLanguageType();

            if (helper.langInFile == null)
            {
                tmpMyLang[0].Value = resultLanguage;
                log.Warn(" no language. Using " + resultLanguage);
            }
            else
            {
                tmpMyLang[0].Value = helper.langInFile;
            }

            this.Query.Languages.Items = tmpMyLang;

            #endregion set Language

            // Allocating an array of PQVariable under QueryType.Query.Variables
            this.Query.Variables = new PQVariable[helper.no_vars - elimCount];
            //hva når det er 0

            //All [] helpers has entries for the eliminated. These must be skipped.



            #region fix stub heading
            // Hva med de som de eliminert??

            int             stub_counter  = 0; //-1
            int             head_counter  = 0; //-1
            List <AxisType> headList      = new List <AxisType>();
            List <AxisType> stubList      = new List <AxisType>();
            int             outVarCounter = 0;

            // Traverses the variables found in the pxs file
            #region for loop
            for (int n = 1; n <= helper.no_vars; n++)
            {
                if (isElim[n - 1])
                {
                    continue;  // If the variable is eliminated, then skip it
                }
                this.Query.Variables[outVarCounter] = helper.tmpVariable[n - 1];
                outVarCounter++;



                string code = helper.tmpVariable[n - 1].code;
                // helper.no_vars_before_heading show
                if (n <= helper.no_vars_before_heading)
                {
                    // stub_counter++;
                    stubList.Add(new AxisType(code, stub_counter++));
                }
                else
                {
                    // head_counter++;
                    headList.Add(new AxisType(code, head_counter++));
                }


                if (n == helper.no_vars_before_time)    //Time
                {
                    string timeCode = this.Query.Time.code;
                    if (n < helper.no_vars_before_heading)
                    {
                        stubList.Add(new AxisType(timeCode, stub_counter++));
                    }
                    else
                    {
                        headList.Add(new AxisType(timeCode, head_counter++));
                    }
                }
            }
            #endregion for loop



            headList.Add(new AxisType(this.Query.Contents.code, head_counter++));


            this.Presentation = new PresentationType();
            if (stubList.Count > 0)
            {
                this.Presentation.Stub = stubList.ToArray();
            }
            if (headList.Count > 0)
            {
                this.Presentation.Heading = headList.ToArray();
            }

            #endregion fix stub heading
        }