コード例 #1
0
 private static int[] GetThumbnailSizePair(ThumbnailSizeEnum e)
 {
     int[] pair = new int[2];
     switch (e)
     {
         case ThumbnailSizeEnum.Small:
             pair[0] = pair[1] = 48;
             break;
         case ThumbnailSizeEnum.Medium:
             pair[0] = pair[1] = 120;
             break;
     }
     return pair;
 }
コード例 #2
0
 public static byte[] MakeThumbnail(string originalImagePath, ThumbnailSizeEnum e)
 {
     int[] pair = GetThumbnailSizePair(e);
     return MakeThumbnail(originalImagePath, pair[0], pair[1], OperationModeEnum.HW);
 }
コード例 #3
0
        /// <summary>
        /// Builds a list of conditional format rules for the report.
        /// </summary>
        /// <returns>Dictionary{GuidList{ReportConditionalFormatRule}}.</returns>
        public Dictionary <string, ReportColumnConditionalFormat> FormatsForReport(out Dictionary <string, ReportImageScale> imageScaleRules)
        {
            imageScaleRules = null;
            if (_formatRules != null && _formatRules.Count > 0)
            {
                Dictionary <string, ReportColumnConditionalFormat> formats = new Dictionary <string, ReportColumnConditionalFormat>(_formatRules.Count);
                EntityRef         imageScale        = null;
                EntityRef         imageSize         = null;
                ThumbnailSizeEnum thumbnailSizeEnum = null;
                foreach (KeyValuePair <string, List <ConditionInfo> > formatRule in _formatRules)
                {
                    ReportColumnConditionalFormat columnFormat = new ReportColumnConditionalFormat();

                    List <ReportConditionalFormatRule> rules = new List <ReportConditionalFormatRule>();
                    foreach (ConditionInfo conditionInfo in formatRule.Value)
                    {
                        if (rules.Count <= 0)
                        {
                            columnFormat.Style     = conditionInfo.Style;
                            columnFormat.ShowValue = conditionInfo.ShowText;
                        }
                        ReportConditionalFormatRule rule = new ReportConditionalFormatRule
                        {
                            Operator = conditionInfo.Operator,
                        };
                        if (conditionInfo.ColorRule != null)
                        {
                            if (conditionInfo.ColorRule.ForegroundColor != null)
                            {
                                rule.ForegroundColor = new ReportConditionColor
                                {
                                    Alpha = conditionInfo.ColorRule.ForegroundColor.A,
                                    Blue  = conditionInfo.ColorRule.ForegroundColor.B,
                                    Green = conditionInfo.ColorRule.ForegroundColor.G,
                                    Red   = conditionInfo.ColorRule.ForegroundColor.R
                                };
                            }
                            if (conditionInfo.ColorRule.BackgroundColor != null)
                            {
                                rule.BackgroundColor = new ReportConditionColor
                                {
                                    Alpha = conditionInfo.ColorRule.BackgroundColor.A,
                                    Blue  = conditionInfo.ColorRule.BackgroundColor.B,
                                    Green = conditionInfo.ColorRule.BackgroundColor.G,
                                    Red   = conditionInfo.ColorRule.BackgroundColor.R
                                };
                            }
                        }
                        if (conditionInfo.LowerBounds != null || conditionInfo.Upperbounds != null)
                        {
                            rule.PercentageBounds = new ReportPercentageBounds
                            {
                                LowerBounds = conditionInfo.LowerBounds,
                                UpperBounds = conditionInfo.Upperbounds
                            };
                        }
                        if (conditionInfo.IconRule != null && (conditionInfo.IconRule.IconId ?? 0) > 0)
                        {
                            if ((conditionInfo.IconRule.CfEntityId ?? 0) > 0)
                            {
                                IEntity cfEntity = Entity.Get(conditionInfo.IconRule.CfEntityId.Value);
                                var     cfi      = cfEntity.As <ConditionalFormatIcon>();
                                if (cfi != null)
                                {
                                    rule.CfEntityId    = cfi.Id;
                                    rule.ImageEntityId = cfi.CondFormatImage != null ? cfi.CondFormatImage.Id : -1;
                                }
                            }
                            else
                            {
                                IEntity entity = Entity.Get(conditionInfo.IconRule.IconId.Value);
                                if (entity.Is <IconFileType>())
                                {
                                    rule.ImageEntityId = conditionInfo.IconRule.IconId.Value;
                                }
                            }

                            if (imageScale == null)
                            {
                                imageScale = new EntityRef("core", "scaleImageProportionally");
                            }
                            if (imageSize == null)
                            {
                                imageSize = new EntityRef("console", "iconThumbnailSize");
                            }
                            if (thumbnailSizeEnum == null)
                            {
                                thumbnailSizeEnum = Entity.Get <ThumbnailSizeEnum>(imageSize);
                            }
                            if (imageScaleRules == null)
                            {
                                imageScaleRules = new Dictionary <string, ReportImageScale>();
                            }
                            if (!imageScaleRules.ContainsKey(formatRule.Key))
                            {
                                ReportImageScale reportImageScale = new ReportImageScale
                                {
                                    ImageScaleId = imageScale.Id,
                                    ImageSizeId  = imageSize.Id,
                                    ImageWidth   = thumbnailSizeEnum.ThumbnailWidth ?? 16,
                                    ImageHeight  = thumbnailSizeEnum.ThumbnailHeight ?? 16
                                };
                                imageScaleRules.Add(formatRule.Key, reportImageScale);
                            }
                        }
                        // Handle the values for the typed value only if this is not an icon as it has relationships
                        if (conditionInfo.Values != null && conditionInfo.Values.Count > 0)
                        {
                            if (conditionInfo.Values[0].Type is ChoiceRelationshipType || conditionInfo.Values[0].Type is InlineRelationshipType || conditionInfo.Values[0].Type is StructureLevelsType)
                            {
                                rule.Values = ProcessConditionValues(conditionInfo.Values);
                                // If there are no values returned then this must be a text string rather than a list of entity identifiers.
                                if (rule.Values == null)
                                {
                                    rule.Value = conditionInfo.Values[0].ValueString;
                                }
                            }
                            else
                            {
                                DateTime dateTimeValue;
                                if ((conditionInfo.Values[0].Type is DateTimeType || conditionInfo.Values[0].Type is TimeType || conditionInfo.Values[0].Type is DateType) &&
                                    (DateTime.TryParse(conditionInfo.Values[0].Value.ToString(), out dateTimeValue)))
                                {
                                    rule.Value = dateTimeValue.ToString("yyyy-MM-ddTHH:mm:ssZ");
                                }
                                else
                                {
                                    rule.Value = conditionInfo.Values[0].ValueString;
                                }
                            }
                        }
                        rules.Add(rule);
                    }
                    columnFormat.Rules = rules;
                    formats.Add(formatRule.Key, columnFormat);
                }
                return(formats);
            }
            return(null);
        }