Example #1
0
        public void ShowLabel(CommandIterator iterator, string memberGroupKey)
        {
            object objToHide = null;

            switch (iterator.Selection)
            {
            case CommandIterator.SelectionType.Element:
                objToHide = this.ElementRow;
                break;

            case CommandIterator.SelectionType.Period:
                objToHide = this.Period;
                break;

            case CommandIterator.SelectionType.Unit:
                objToHide = this.Unit;
                break;
            }

            //this must be a segment...
            if (objToHide == null)
            {
                objToHide = this.Segments.Find(seg => seg.DimensionInfo.dimensionId == memberGroupKey);
            }

            if (objToHide != null && this.hiddenObjects.Contains(objToHide))
            {
                this.hiddenObjects.Remove(objToHide);
            }
        }
Example #2
0
        public void GenerateEmbedLabel(ColumnRowRequirement embedRequirements, bool showDefault)
        {
            this.Labels.Clear();

            string calendarLabel = null;

            if (embedRequirements.HasSelectionType(CommandIterator.SelectionType.Period))
            {
                CommandIterator cmdI = Array.Find(embedRequirements.EmbedCommands, cmd => cmd.Selection == CommandIterator.SelectionType.Period);
                if (cmdI != null)
                {
                    calendarLabel = embedRequirements.GetLabel(cmdI, false);
                }
            }

            string[] labels = embedRequirements.GetLabels(this.HasMultiCurrency, showDefault);
            for (int i = 0; i < labels.Length; i++)
            {
                if (calendarLabel != null)
                {
                    if (string.Equals(labels[i], calendarLabel))
                    {
                        this.Labels.Add(new LabelLine(i, labels[i], "Calendar"));
                        continue;
                    }
                }

                this.Labels.Add(new LabelLine(i, labels[i]));
            }
        }
Example #3
0
        public void Remove(CommandIterator iterator, string memberGroupKey)
        {
            switch (iterator.Selection)
            {
            case CommandIterator.SelectionType.Element:
                this.ElementRow = null;
                break;

            case CommandIterator.SelectionType.Period:
                this.Period = null;
                break;

            case CommandIterator.SelectionType.Unit:
                this.Unit = null;
                break;
            }

            //this must be a segment...
            Segment segment = this.Segments.Find(seg => seg.DimensionInfo.dimensionId == memberGroupKey);

            if (segment != null)
            {
                this.Segments.Remove(segment);
            }
        }
Example #4
0
        public void Add(CommandIterator iterator, object memberGroupValue)
        {
            switch (iterator.Selection)
            {
            case CommandIterator.SelectionType.Element:
                this.ElementRow = memberGroupValue as InstanceReportRow;
                break;

            case CommandIterator.SelectionType.Period:
                this.Period = memberGroupValue as CalendarPeriod;
                break;

            case CommandIterator.SelectionType.Unit:
                this.Unit = (EmbeddedUnitWrapper)memberGroupValue;
                break;
            }

            //this must be a segment...
            Segment segment = memberGroupValue as Segment;

            if (segment != null)
            {
                this.Segments.Add(segment);
            }
        }
Example #5
0
        /// <summary>
        /// Retrieve all labels for a report.
        /// </summary>
        /// <param name="showCurrency">Whether or not to show currency labels.
        /// </param>
        /// <param name="showDefault">Whether or not to show default labels.
        /// </param>
        /// <returns></returns>
        public string[] GetLabels(bool showCurrency, bool showDefault)
        {
            List <string> labels = new List <string>();

            for (int c = 0; c < this.EmbedCommands.Length; c++)
            {
                CommandIterator iterator = this.EmbedCommands[c];
                if (!showCurrency && iterator.Selection == CommandIterator.SelectionType.Unit)
                {
                    continue;
                }

                string label = this.GetLabel(iterator, showDefault);
                if (string.IsNullOrEmpty(label))
                {
                    continue;
                }

                if (!labels.Contains(label))
                {
                    labels.Add(label);
                }
            }

            return(labels.ToArray());
        }
Example #6
0
        //TODO make private
        public bool Parse(out string embedWarning)
        {
            //As we read in all of our command tokens,
            //there are a couple of things to keep in mind:
            //Walter suggests that commands types have a specific order:
            //    columns then rows.
            //If for any reason we can't discern the IteratorType,
            //the default will be decided based on whether or not we've
            //parsed any 'row' types yet.
            bool foundRows = false;

            string rowsAndCols;

            if (!HasMatch(this.EmbedInstruction, out embedWarning, out this.Role, out rowsAndCols))
            {
                return(false);
            }

            MatchCollection matches = COMMAND_PARSER.Matches(rowsAndCols);

            foreach (Match m in matches)
            {
                string type         = m.Groups[GROUP_TYPE].Value;
                string cmdSelection = m.Groups[GROUP_SELECTION].Value;
                string style        = m.Groups[GROUP_STYLE].Value;
                string cmdFilter    = m.Groups[GROUP_FILTER].Value;

                CommandIterator.IteratorType cmdType  = CommandIterator.ParseIteratorType(type, ref foundRows);
                CommandIterator.StyleType    cmdStyle = CommandIterator.ParseStyleType(style);

                CommandIterator iterator = new CommandIterator(cmdType, cmdSelection, cmdStyle, cmdFilter);
                this.LoadIterator(iterator);
            }
            return(true);
        }
Example #7
0
 public bool HasSelectionType(CommandIterator iterator)
 {
     if (iterator.Selection == CommandIterator.SelectionType.Axis)
     {
         return(HasSelectionType(iterator.Selection, iterator.SelectionString, iterator.Filter));
     }
     else
     {
         return(this.HasSelectionType(iterator.Selection));
     }
 }
Example #8
0
        /// <summary>
        /// Creates a new instance of <see cref="EmbedReport"/>.
        /// </summary>
        public EmbedReport()
        {
            if (!this.selections.ContainsKey("period"))
            {
                /**
                 * If the command has no iterator for “period”, it is assumed as an iterator starting the entire command, “column period compact *”.
                 **/
                this.selections["period"] = CommandIterator.CreateDefaultPeriod();
            }

            //this.selections[ "unit" ] = new CommandIterator( CommandIterator.IteratorType.Column, "unit", CommandIterator.StyleType.Compact, "*" ) );
        }
Example #9
0
        public string GetSeparator()
        {
            string          separator = string.Empty;
            CommandIterator ci        = Array.Find(this.EmbedCommands, ec => ec.Selection == CommandIterator.SelectionType.Separator);

            if (ci != null && !string.IsNullOrEmpty(ci.Filter))
            {
                separator = ci.Filter;
                if (separator.Length > 1 && separator.StartsWith("\"") && separator.EndsWith("\""))
                {
                    separator = separator.Substring(1, separator.Length - 2);
                }
            }
            return(separator);
        }
Example #10
0
 //TODO make private
 public void LoadIterator(CommandIterator iterator)
 {
     if (iterator.Selection == CommandIterator.SelectionType.Axis)
     {
         this.selections[iterator.SelectionString] = iterator;
     }
     else if (iterator.Selection == CommandIterator.SelectionType.Element)
     {
         this.selections["primary"] = iterator;
     }
     else
     {
         this.selections[iterator.Selection.ToString().ToLower()] = iterator;
     }
 }
Example #11
0
        public KeyValuePair <string, object> GetMemberKeyValue(CommandIterator iterator)
        {
            switch (iterator.Selection)
            {
            case CommandIterator.SelectionType.Element:
                return(new KeyValuePair <string, object>(this.ElementKey, this.ElementRow));

            case CommandIterator.SelectionType.Period:
                return(new KeyValuePair <string, object>(this.Period.ToString(), this.Period));

            case CommandIterator.SelectionType.Unit:
                return(new KeyValuePair <string, object>(this.UnitLabel, this.Unit));
            }

            //this must be a segment...
            Segment segment = this.Segments.Find(seg => seg.DimensionInfo.dimensionId == iterator.SelectionString);
            KeyValuePair <string, object> kvpSegment = kvpSegment = new KeyValuePair <string, object>(iterator.SelectionString, segment);

            return(kvpSegment);
        }
Example #12
0
        private Dictionary <string, object> GetSelectionMembers(
            IEnumerable <CommandIterator> iteratorHierarchy, CommandIterator currentIterator,
            out bool hasDefaultMember)
        {
            hasDefaultMember = false;
            Dictionary <string, object> memberValues = null;

            switch (currentIterator.Selection)
            {
            //these axis dictionaries are already in order by presentation
            //the biggest challenge comes with the default member when moving data
            case CommandIterator.SelectionType.Axis:
                if (!this.AxisByPresentation.Contains(currentIterator.AxisName))
                {
                    memberValues = new Dictionary <string, object>();
                }
                else
                {
                    Segment defaultMember;
                    memberValues     = this.baseReport.GetInUseSegmentDictionary(iteratorHierarchy, currentIterator, out defaultMember);
                    hasDefaultMember = (defaultMember != null);
                }
                break;

            case CommandIterator.SelectionType.Element:
                //memberValues = this.baseReport.GetElementDictionary( currentIterator.Type );
                memberValues = this.baseReport.GetInUseElementDictionary(iteratorHierarchy, currentIterator);
                break;

            case CommandIterator.SelectionType.Period:
                memberValues = this.baseReport.GetPeriodDictionary(currentIterator.Type);
                break;

            case CommandIterator.SelectionType.Unit:
                //memberValues = this.baseReport.GetUnitDictionary( currentIterator.Type );
                memberValues = this.baseReport.GetInUseUnitDictionary(iteratorHierarchy, currentIterator);
                break;
            }

            return(memberValues);
        }
Example #13
0
        /// <summary>
        /// Return the combined label for the given commands.
        /// </summary>
        /// <param name="iterator">The label pieces.</param>
        /// <param name="showDefault">Whether or not to show a default label
        /// when one cannot be generated.</param>
        /// <returns></returns>
        public string GetLabel(CommandIterator iterator, bool showDefault)
        {
            if (iterator.Style == CommandIterator.StyleType.NoDisplay)
            {
                return(string.Empty);
            }

            switch (iterator.Selection)
            {
            case CommandIterator.SelectionType.Element:
                if (this.hiddenObjects.Contains(this.ElementRow))
                {
                    return(string.Empty);
                }
                else
                {
                    return(this.ElementLabel);
                }


            case CommandIterator.SelectionType.Period:
                if (this.hiddenObjects.Contains(this.Period))
                {
                    return(string.Empty);
                }
                else
                {
                    return(this.PeriodLabel);
                }


            case CommandIterator.SelectionType.Unit:
                if (this.hiddenObjects.Contains(this.Unit))
                {
                    return(string.Empty);
                }
                else
                {
                    return(this.UnitLabel);
                }
            }

            if (this.Segments == null || this.Segments.Count == 0)
            {
                return(string.Empty);
            }

            int segIdx = this.Segments.FindIndex(
                seg =>
            {
                if (!string.Equals(seg.DimensionInfo.dimensionId, iterator.SelectionString))
                {
                    return(false);
                }

                if (iterator.Filter == "*")
                {
                    if (seg.IsDefaultForEntity)
                    {
                        return(showDefault);
                    }
                    else
                    {
                        return(true);
                    }
                }

                if (!string.Equals(seg.DimensionInfo.Id, iterator.Filter))
                {
                    return(false);
                }

                if (seg.IsDefaultForEntity)
                {
                    return(showDefault);
                }
                else
                {
                    return(true);
                }
            });

            if (segIdx == -1)
            {
                return(string.Empty);
            }
            else if (this.hiddenObjects.Contains(this.Segments[segIdx]))
            {
                return(string.Empty);
            }
            else
            {
                return(this.SegmentLabels[segIdx]);
            }
        }
Example #14
0
        private bool SortByCommands(CommandIterator[] commands)
        {
            if (commands == null || commands.Length == 0)
            {
                return(false);
            }

            CommandIterator.IteratorType type = commands[0].Type;

            //sorting may only be performed on rows or columsn.  'Unknown' is not allowed.
            if (type == CommandIterator.IteratorType.Unknown)
            {
                return(false);
            }

            //sorting may only be performed on items of a consistent type (rows or columns)
            if (!Array.TrueForAll(commands, c => c.Type == type))
            {
                return(false);
            }

            //collect all of the possible values in command order
            List <string>[] commandValueKeys = new List <string> [commands.Length];

            CommandIterator[] emptySet = new CommandIterator[0];
            for (int i = 0; i < commands.Length; i++)
            {
                //we can't compare a separator
                if (commands[i].Selection == CommandIterator.SelectionType.Separator)
                {
                    commandValueKeys[i] = null;
                }
                else
                {
                    bool hasDefaultMember;
                    Dictionary <string, object> tmp = this.GetSelectionMembers(emptySet, commands[i], out hasDefaultMember);
                    List <string> sortedKeys        = new List <string>(tmp.Keys);
                    commandValueKeys[i] = sortedKeys;
                }
            }

            ItemSorter sorter = (left, right) =>
            {
                for (int i = 0; i < commands.Length; i++)
                {
                    //we can't compare a separator
                    if (commands[i].Selection == CommandIterator.SelectionType.Separator)
                    {
                        continue;
                    }

                    List <string> valueKeys = commandValueKeys[i];

                    int leftIdx  = 0;
                    int rightIdx = 0;

                    switch (commands[i].Selection)
                    {
                    case CommandIterator.SelectionType.Axis:
                        string leftSegment  = ((Segment)left.EmbedRequirements.GetMemberKeyValue(commands[i]).Value).DimensionInfo.Id;
                        string rightSegment = ((Segment)right.EmbedRequirements.GetMemberKeyValue(commands[i]).Value).DimensionInfo.Id;

                        leftIdx  = valueKeys.IndexOf(leftSegment);
                        rightIdx = valueKeys.IndexOf(rightSegment);
                        break;

                    case CommandIterator.SelectionType.Element:
                        leftIdx  = valueKeys.IndexOf(left.EmbedRequirements.ElementKey);
                        rightIdx = valueKeys.IndexOf(right.EmbedRequirements.ElementKey);
                        break;

                    case CommandIterator.SelectionType.Period:
                        leftIdx  = valueKeys.IndexOf(left.EmbedRequirements.PeriodLabel);
                        rightIdx = valueKeys.IndexOf(right.EmbedRequirements.PeriodLabel);
                        break;

                    case CommandIterator.SelectionType.Unit:
                        leftIdx  = valueKeys.IndexOf(left.EmbedRequirements.UnitCode);
                        rightIdx = valueKeys.IndexOf(right.EmbedRequirements.UnitCode);
                        break;
                    }

                    if (leftIdx < rightIdx)
                    {
                        return(-1);
                    }

                    if (leftIdx > rightIdx)
                    {
                        return(1);
                    }
                }

                return(0);
            };

            if (type == CommandIterator.IteratorType.Column)
            {
                this.InstanceReport.Columns.Sort((left, right) => sorter(left, right));
            }
            else
            {
                this.InstanceReport.Rows.Sort((left, right) => sorter(left, right));
            }

            return(true);
        }
Example #15
0
        private void AddDefaultIterators(InstanceReport embedReport)
        {
            //period and primary are added in the constructor and Parse() respectively.
            //Now we look for any additional segments that are not on the ColumnIterators
            //And perhaps also add the units
            Dictionary <string, int> uniqueAxisList = new Dictionary <string, int>();

            foreach (InstanceReportColumn col in embedReport.Columns)
            {
                if (col.Segments == null)
                {
                    continue;
                }

                if (col.Segments.Count == 0)
                {
                    continue;
                }

                foreach (Segment s in col.Segments)
                {
                    uniqueAxisList[s.ValueType] = 1;
                }
            }

            foreach (string axis in this.selections.Keys)
            {
                if (uniqueAxisList.ContainsKey(axis))
                {
                    uniqueAxisList.Remove(axis);
                }
            }

            List <string> axisList = new List <string>(uniqueAxisList.Keys);

            axisList.Sort(this.AxisSorter);

            foreach (string axis in axisList)
            {
                CommandIterator itr = new CommandIterator
                {
                    Type            = CommandIterator.IteratorType.Column,
                    SelectionString = axis,
                    Style           = CommandIterator.StyleType.Compact,
                    Filter          = "*"
                };

                this.selections[itr.SelectionString] = itr;
            }

            if (!this.selections.ContainsKey("primary"))
            {
                /**
                 * If the command has no iterator for “primary”, it is assumed that the entire command ends with iterator “row primary compact *”.
                 **/
                this.selections["primary"] = CommandIterator.CreateDefaultPrimary();
            }

            if (!this.selections.ContainsKey("unit"))
            {
                /**
                 * If the command has no iterator for “primary”, it is assumed that the entire command ends with iterator “row primary compact *”.
                 **/
                this.selections["unit"] = CommandIterator.CreateDefaultUnit();
            }
        }