public double ConvertToPixels(double value, SizeTypes type)
        {
            switch (type)
            {
            case SizeTypes.Cm:
                value *= (double)ReportSize.DotsPerInch / 2.54;
                break;

            case SizeTypes.Inch:
                value *= (double)ReportSize.DotsPerInch;
                break;

            case SizeTypes.Mm:
                value *= (double)ReportSize.DotsPerInch / 25.4;
                break;

            case SizeTypes.Pica:
                value *= (double)ReportSize.DotsPerInch / 6.0;
                break;

            case SizeTypes.Point:
                value *= (double)ReportSize.DotsPerInch / 72.0;
                break;
            }
            return(value);
        }
Example #2
0
        private Image ReSize(SizeTypes sizeType)
        {
            var size = (double)Size(sizeType);
            var rate = Data.Width > Data.Height
                ? size / Data.Height
                : size / Data.Width;

            if (rate != 1)
            {
                var width        = (Data.Width * rate).ToInt();
                var height       = (Data.Height * rate).ToInt();
                var x            = ((size - width) / 2).ToInt();
                var y            = ((size - height) / 2).ToInt();
                var resizedImage = new Bitmap(size.ToInt(), size.ToInt());
                resizedImage.MakeTransparent();
                using (var graphics = Graphics.FromImage(resizedImage))
                {
                    graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    graphics.DrawImage(Data, x, y, width, height);
                    return(resizedImage);
                }
            }
            else
            {
                return(Data);
            }
        }
        public static double ConvertToUnits(double pixels, SizeTypes type)
        {
            double num = pixels;

            switch (type)
            {
            case SizeTypes.Cm:
                num /= (double)ReportSize.DotsPerInch / 2.54;
                break;

            case SizeTypes.Inch:
                num /= (double)ReportSize.DotsPerInch;
                break;

            case SizeTypes.Mm:
                num /= (double)ReportSize.DotsPerInch / 25.4;
                break;

            case SizeTypes.Pica:
                num /= (double)ReportSize.DotsPerInch / 6.0;
                break;

            case SizeTypes.Point:
                num /= (double)ReportSize.DotsPerInch / 72.0;
                break;
            }
            return(num);
        }
 private string Path(long referenceId, Types type, SizeTypes sizeType)
 {
     return(System.IO.Path.Combine(
                Directories.BinaryStorage(),
                type.ToString(),
                "{0}_{1}.png".Params(referenceId, sizeType)));
 }
        private void Init(string value, IFormatProvider provider, SizeTypes defaultType)
        {
            if (provider == null)
            {
                provider = CultureInfo.CurrentCulture;
            }
            string           text             = value.Trim();
            int              length           = text.Length;
            NumberFormatInfo numberFormatInfo = provider.GetFormat(typeof(NumberFormatInfo)) as NumberFormatInfo;

            if (numberFormatInfo == null)
            {
                numberFormatInfo = CultureInfo.InvariantCulture.NumberFormat;
            }
            int num = -1;

            for (int i = 0; i < length; i++)
            {
                char c = text[i];
                if (!char.IsDigit(c) && c != numberFormatInfo.NegativeSign[0] && c != numberFormatInfo.NumberDecimalSeparator[0] && c != numberFormatInfo.NumberGroupSeparator[0])
                {
                    break;
                }
                num = i;
            }
            if (num == -1)
            {
                throw new FormatException(SRErrors.UnitParseNoDigits(value));
            }
            if (num < length - 1)
            {
                try
                {
                    this.m_type = ReportSize.GetTypeFromString(text.Substring(num + 1).Trim().ToLowerInvariant());
                }
                catch (ArgumentException ex)
                {
                    throw new FormatException(ex.Message);
                }
                goto IL_00f1;
            }
            if (defaultType != 0)
            {
                this.m_type = defaultType;
                goto IL_00f1;
            }
            throw new FormatException(SRErrors.UnitParseNoUnit(value));
IL_00f1:
            string text2 = text.Substring(0, num + 1);

            try
            {
                this.m_value = double.Parse(text2, provider);
            }
            catch
            {
                throw new FormatException(SRErrors.UnitParseNumericPart(value, text2, ((Enum)(object)this.m_type).ToString("G")));
            }
        }
 public ReportSize ChangeType(SizeTypes type)
 {
     if (type == this.m_type)
     {
         return(this);
     }
     return(new ReportSize(ReportSize.ConvertToUnits(this.ConvertToPixels(this.m_value, this.m_type), type), type));
 }
 internal ReportSize ChangeType(SizeTypes type)
 {
     if (type == m_type)
     {
         return(this);
     }
     return(new ReportSize(ConvertToUnits(ConvertToPixels(m_value, m_type), type), type));
 }
 public byte[] ReSizeBytes(SizeTypes sizeType)
 {
     using (var memory = new MemoryStream())
     {
         memory.Position = 0;
         ReSize(sizeType).Save(memory, ImageFormat.Png);
         return(GetByte(memory));
     }
 }
 public ReportSize(string value, IFormatProvider provider, SizeTypes defaultType)
 {
     this.m_value = 0.0;
     this.m_type  = SizeTypes.Invalid;
     if (!string.IsNullOrEmpty(value))
     {
         this.Init(value, provider, defaultType);
     }
 }
Example #10
0
 public byte[] ReSizeBytes(SizeTypes sizeType)
 {
     using (var memory = new MemoryStream())
     {
         memory.Position = 0;
         ReSize(sizeType).Save(memory, ImageFormat.Bmp);
         var ret = new byte[memory.Length];
         memory.Position = 0;
         memory.Read(ret, 0, (int)memory.Length);
         memory.Close();
         return(ret);
     }
 }
Example #11
0
        private int Size(SizeTypes sizeType)
        {
            switch (sizeType)
            {
            case SizeTypes.Regular: return(Parameters.General.ImageSizeRegular);

            case SizeTypes.Thumbnail: return(Parameters.General.ImageSizeThumbnail);

            case SizeTypes.Icon: return(Parameters.General.ImageSizeIcon);

            default: return(Parameters.General.ImageSizeRegular);
            }
        }
Example #12
0
        public static decimal FileSize(this string path, SizeTypes type = SizeTypes.Bytes, double round = 2)
        {
            if (!File.Exists(path))
            {
                return(0);
            }

            FileInfo inf = new FileInfo(path);
            decimal  l   = inf.Length;

            return(type switch
            {
                SizeTypes.Bytes => l,
                SizeTypes.KiloBytes => (l / 1024).RoundUp(round),
                SizeTypes.MegaBytes => (l / 1000 / 1024).RoundUp(round),
                SizeTypes.GigaBytes => (l / 1000 / 1000 / 1024).RoundUp(round),
                _ => 0,
            });
        private Image ReSize(SizeTypes sizeType)
        {
            var size = (double)Size(sizeType);
            var rate = (Data.Width > Data.Height) || (sizeType == SizeTypes.Logo)
                ? size / Data.Height
                : size / Data.Width;

            if (rate != 1)
            {
                var width  = (Data.Width * rate).ToInt();
                var height = (Data.Height * rate).ToInt();
                var x      = (sizeType == SizeTypes.Logo) ? 0 : ((size - width) / 2).ToInt();
                var y      = (sizeType == SizeTypes.Logo) ? 0 : ((size - height) / 2).ToInt();
                return(GetImage(width, height, x, y));
            }
            else
            {
                return(Data);
            }
        }
        public double ConvertToMillimeters(double value, SizeTypes type)
        {
            switch (type)
            {
            case SizeTypes.Cm:
                value *= 10.0;
                break;

            case SizeTypes.Inch:
                value *= 25.4;
                break;

            case SizeTypes.Pica:
                value *= 4.2333333333333334;
                break;

            case SizeTypes.Point:
                value *= 0.35277777777777775;
                break;
            }
            return(value);
        }
        private static string GetStringFromType(SizeTypes type)
        {
            switch (type)
            {
            case SizeTypes.Point:
                return("pt");

            case SizeTypes.Pica:
                return("pc");

            case SizeTypes.Inch:
                return("in");

            case SizeTypes.Mm:
                return("mm");

            case SizeTypes.Cm:
                return("cm");

            default:
                return(string.Empty);
            }
        }
 private void WriteToLocal(Image image, long referenceId, Types type, SizeTypes sizeType)
 {
     image.Write(Path(referenceId, type, sizeType), ImageFormat.Png);
 }
 public string UrlPrefix(SizeTypes sizeType)
 {
     return(new FileInfo(Path(ReferenceId, Type, sizeType))
            .LastWriteTime.ToString("?yyyyMMddHHmmss"));
 }
 public bool Exists(SizeTypes sizeType)
 {
     return(File.Exists(Path(ReferenceId, Type, sizeType)));
 }
 public byte[] Read(SizeTypes sizeType)
 {
     return(Files.Bytes(Path(ReferenceId, Type, sizeType)));
 }
 public ReportSize(double value)
 {
     this.m_value = value;
     this.m_type  = ReportSize.DefaultType;
 }
Example #21
0
File: Size.cs Project: myko/Eternia
 public Size(SizeTypes type, float size)
 {
     this.Type = type;
     this.Value = size;
 }
        /// <summary>
        /// 表示一个文本框,会根据 DisplayAttribute 特性的 Description 属性,在文本框中生成 placeholder 属性,并加入 bootstrap 的特定文本框样式 "form-control"。
        /// </summary>
        /// <typeparam name="TModel">模型的类型</typeparam>
        /// <typeparam name="TProperty">值的类型</typeparam>
        /// <param name="htmlHelper">此方法扩展的 HTML 帮助器实例。</param>
        /// <param name="expression"> 一个表达式,用于标识包含要呈现的属性的对象。</param>
        /// <param name="size">控件尺寸</param>
        /// <param name="htmlAttributes">一个对象,其中包含要为该元素设置的 HTML 特性。</param>
        /// <returns>一个 HTML input 元素,其 type 特性针对表达式表示的对象中的每个属性均设置为“text”。</returns>
        public static MvcHtmlString BootstrapTextBoxFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, SizeTypes size = SizeTypes.Normal, object htmlAttributes = null)
        {
            var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            attributes.AddOrMerge("class", " form-control ");
            attributes.BuildSizeClass("input", size);
            attributes.BuildPlaceHolder(expression);
            return(htmlHelper.TextBoxFor(expression, attributes));
        }
        /// <summary>
        ///  通过使用指定的 HTML 帮助器、窗体字段的名称、值和 HTML 特性,返回文本 input 元素,并加入 bootstrap 的特定文本框样式 "form-control"。
        /// </summary>
        /// <param name="htmlHelper">此方法扩展的 HTML 帮助器实例。</param>
        /// <param name="name"> 窗体字段的名称和用于查找值的 System.Web.Mvc.ViewDataDictionary 键。</param>
        /// <param name="value">文本 input 元素的值。按此顺序检索值:System.Web.Mvc.ModelStateDictionary 对象、此参数的值、System.Web.Mvc.ViewDataDictionary 对象,最后是 html 特性中的 value 特性。</param>
        /// <param name="size">控件尺寸</param>
        /// <param name="htmlAttributes">一个对象,其中包含要为该元素设置的 HTML 特性。</param>
        /// <returns>一个 input 元素,其 type 特性设置为“text”。</returns>
        public static MvcHtmlString BootstrapTextBox(this HtmlHelper htmlHelper, string name, object value = null, SizeTypes size = SizeTypes.Normal, object htmlAttributes = null)
        {
            var attributes = HtmlHelper.ObjectToDictionary(htmlAttributes);

            attributes.AddOrMerge("class", " form-control ");
            attributes.BuildSizeClass("input", size);

            return(htmlHelper.TextBox(name, value, attributes));
        }
 public static ReportSize FromPixels(double pixels, SizeTypes type)
 {
     return(new ReportSize(ReportSize.ConvertToUnits(pixels, type), type));
 }
 public ReportSize(double value, SizeTypes type)
 {
     m_value = value;
     m_type  = type;
 }
 static ReportSize()
 {
     ReportSize.m_empty                 = default(ReportSize);
     ReportSize.m_defaultType           = SizeTypes.Inch;
     ReportSize.SerializedDecimalDigits = 5;
 }
        public CategoryInfo GetCategory(MarketType market,
                                        string marketplaceId,
                                        string itemStyle,
                                        string gender,
                                        SizeTypes sizeType)
        {
            /*										<xsd:enumeration value="Shirt"/>
             *                                                                  <xsd:enumeration value="Sweater"/>
             *                                                                  <xsd:enumeration value="Pants"/>
             *                                                                  <xsd:enumeration value="Shorts"/>
             *                                                                  <xsd:enumeration value="Skirt"/>
             *                                                                  <xsd:enumeration value="Dress"/>
             *                                                                  <xsd:enumeration value="Suit"/>
             *                                                                  <xsd:enumeration value="Blazer"/>
             *                                                                  <xsd:enumeration value="Outerwear"/>
             *                                                                  <xsd:enumeration value="SocksHosiery"/>
             *                                                                  <xsd:enumeration value="Underwear"/>
             *                                                                  <xsd:enumeration value="Bra"/>
             *                                                                  <xsd:enumeration value="Shoes"/>
             *                                                                  <xsd:enumeration value="Hat"/>
             *                                                                  <xsd:enumeration value="Bag"/>
             *                                                                  <xsd:enumeration value="Accessory"/>
             *                                                                  <xsd:enumeration value="Jewelry"/>
             *                                                                  <xsd:enumeration value="Sleepwear"/>
             *                                                                  <xsd:enumeration value="Swimwear"/>
             *                                                                  <xsd:enumeration value="PersonalBodyCare"/>
             *                                                                  <xsd:enumeration value="HomeAccessory"/>
             *                                                                  <xsd:enumeration value="NonApparelMisc"/>
             *                                                                  <xsd:enumeration value="Kimono"/>
             *                                                                  <xsd:enumeration value="Obi"/>
             *                                                                  <xsd:enumeration value="Chanchanko"/>
             *                                                                  <xsd:enumeration value="Jinbei"/>
             *                                                                  <xsd:enumeration value="Yukata"/>
             *                                                                  <xsd:enumeration value="EthnicWear"/>
             *                                                                  <xsd:enumeration value="Costume"/>
             *                                                                  <xsd:enumeration value="AdultCostume"/>
             *                                                                  <xsd:enumeration value="BabyCostume"/>
             *                                                                  <xsd:enumeration value="ChildrensCostume"/>	*/

            using (var db = _dbFactory.GetRWDb())
            {
                var category = db.AmazonCategoryMappings.GetAll()
                               .FirstOrDefault(c => c.Market == (int)market &&
                                               c.MarketplaceId == marketplaceId &&
                                               c.ItemStyle == itemStyle &&
                                               (c.Gender.Contains(gender) || String.IsNullOrEmpty(gender)) &&
                                               (c.SizeType == (int)sizeType || c.SizeType == null));

                if (category != null)
                {
                    return new CategoryInfo()
                           {
                               Key1    = category.ItemTypeKeyword,
                               Key2    = category.DepartmentKey,
                               Key3    = category.FeedType,
                               NodeIds = category.BrowseNodeIds,
                           }
                }
                ;
                else
                {
                    return new CategoryInfo()
                           {
                               Key1 = "",
                               Key2 = "",
                               Key3 = "",
                           }
                };

                throw new NotSupportedException("Not found category for: ItemStyle=" + itemStyle + ", gender=" + gender + ", sizeType=" + sizeType);
            }
        }
    }
 public ReportSize(double value)
 {
     m_value = value;
     m_type  = DefaultType;
 }
        /// <summary>
        ///  通过使用指定的 HTML 帮助器、窗体字段的名称、值和 HTML 特性,返回密码 input 元素,并加入bootstrap的特定文本框样式"form-control"
        /// </summary>
        /// <param name="htmlHelper">扩展的实例。</param>
        /// <param name="name"> 窗体字段的名称和用于查找值的 System.Web.Mvc.ViewDataDictionary 键。</param>
        /// <param name="value">密码 input 元素的值。如果未提供此参数的值,则使用 html 特性中的 value 特性来检索值。</param>
        /// <param name="size">控件尺寸</param>
        /// <param name="htmlAttributes">一个对象,其中包含要为该元素设置的 HTML 特性。</param>
        /// <returns>一个 input 元素,其 type 特性设置为“password”。</returns>
        public static MvcHtmlString BootstrapPassword(this HtmlHelper htmlHelper, string name, object value = null, SizeTypes size = SizeTypes.Normal, object htmlAttributes = null)
        {
            var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            attributes.AddOrMerge("class", " form-control ");
            attributes.BuildSizeClass("input", size);
            return(htmlHelper.Password(name, value, attributes));
        }
Example #30
0
 /// <summary>
 /// 根据SizeTypes生成对应的Bootstrap所适应的尺寸class
 /// </summary>
 /// <param name="attributes">该元素设置的 HTML 特性。</param>
 /// <param name="prefix">前缀,例如按钮是btn。</param>
 /// <param name="size">尺寸</param>
 public static void BuildSizeClass(this IDictionary <string, object> attributes, string prefix = null, SizeTypes size = SizeTypes.Normal)
 {
     if (size == SizeTypes.Normal)
     {
         return;
     }
     attributes.AddOrMerge("class", " {0}{1} ".StringFormat(prefix, size.ToString().ToLower()));
 }
 public ReportSize(double value, SizeTypes type)
 {
     this.m_value = value;
     this.m_type  = type;
 }