public void LoadSizes() { var converter = new SizeConverter(); foreach (var fileName in Directory.EnumerateFiles(Path.Combine(CoreRuleBookDirectory, "Sizes"))) { var contents = File.ReadAllText(fileName); var sizeListing = JsonConvert.DeserializeObject<Size>(contents, converter); GameSystem.Sizes.Add(sizeListing); } }
public object Convert(object value, Type targeType, object parameter, CultureInfo culture) { SizeConverter converter = new SizeConverter(); object returnvalue = converter.Convert(value, targeType, parameter, culture); double left = 8 + 64 - (double)returnvalue; Thickness Margin = new Thickness { Top = 14, Bottom = 0, Right = 8, Left = left }; return Margin; }
public void NoWriteTest() { var converter = new SizeConverter(); Assert.False(converter.CanWrite); Assert.Throws <NotImplementedException>(() => converter.WriteJson(default !, new Size(), default !));
public void ConvertBytesToMegaBytesCorrectResult() { var result = SizeConverter.ConvertBytesToMegaBytes(size); Assert.AreEqual(expectedOutput, result); }
public void ConvertFrom_negative() { SizeConverter r = new SizeConverter(); r.ConvertFrom("-1, -4"); }
public void ConvertFrom_size() { SizeConverter r = new SizeConverter(); r.ConvertFrom(new Size(10, 20)); }
static void IncomingChangeTreeViewItemCellGUI( string wkPath, Rect rect, float rowHeight, UnityIncomingChangesTree incomingChangesTree, IncomingChangesTreeView treeView, ChangeTreeViewItem item, Action onCheckedNodeChanged, IncomingChangesTreeColumn column, bool isSelected, bool isFocused, bool isCurrentConflict, bool isSolvedConflict) { IncomingChangeInfo incomingChange = item.ChangeInfo; string label = incomingChange.GetColumnText( IncomingChangesTreeHeaderState.GetColumnName(column)); if (column == IncomingChangesTreeColumn.Path) { if (incomingChangesTree.HasMeta(item.ChangeInfo)) { label = string.Concat(label, UnityConstants.TREEVIEW_META_LABEL); } Texture icon = GetIcon(wkPath, incomingChange); Texture overlayIcon = GetChangesOverlayIcon.ForGluonIncomingChange( incomingChange, isSolvedConflict); bool wasChecked = incomingChange.IsChecked(); bool isChecked = DrawTreeViewItem.ForCheckableItemCell( rect, rowHeight, item.depth, icon, overlayIcon, label, isSelected, isFocused, isCurrentConflict, wasChecked); incomingChange.UpdateCheckedState(isChecked); if (wasChecked != isChecked) { UpdateCheckStateForSelection(treeView, item); onCheckedNodeChanged(); } return; } if (column == IncomingChangesTreeColumn.Size) { // If there is a meta file, add the meta file to the file size so that it is consistent // with the Incoming Changes overview if (incomingChangesTree.HasMeta(item.ChangeInfo)) { IncomingChangeInfo metaFileInfo = incomingChangesTree.GetMetaChange(incomingChange); long metaFileSize = metaFileInfo.GetSize(); long fileSize = incomingChange.GetSize(); label = SizeConverter.ConvertToSizeString(fileSize + metaFileSize); } DrawTreeViewItem.ForSecondaryLabelRightAligned( rect, label, isSelected, isFocused, isCurrentConflict); return; } DrawTreeViewItem.ForSecondaryLabel( rect, label, isSelected, isFocused, isCurrentConflict); }
/// <summary> /// Gets the frame style as HTML. /// </summary> /// <param name="frame">The frame.</param> /// <returns></returns> public string GetFrameStyleAsHtml(Frame frame) { string style = ""; try { if (frame != null) { string width = frame.SvgWidth; if (width != null) { if (width.EndsWith("cm")) { width = width.Replace("cm", ""); } else if (width.EndsWith("in")) { width = width.Replace("in", ""); } } string height = frame.SvgHeight; if (height != null) { if (height.EndsWith("cm")) { height = height.Replace("cm", ""); } else if (height.EndsWith("in")) { height = height.Replace("in", ""); } } try { if (width != null) { double wd = Convert.ToDouble(width, System.Globalization.NumberFormatInfo.InvariantInfo); string wdPx = ""; if (frame.SvgWidth.EndsWith("cm")) { wdPx = SizeConverter.CmToPixelAsString(wd); } else if (frame.SvgWidth.EndsWith("in")) { wdPx = SizeConverter.InchToPixelAsString(wd); } if (wdPx.Length > 0) { style = "width=\"" + wdPx + "\" "; } } if (height != null) { double wd = Convert.ToDouble(height, System.Globalization.NumberFormatInfo.InvariantInfo); string wdPx = ""; if (frame.SvgHeight.EndsWith("cm")) { wdPx = SizeConverter.CmToPixelAsString(wd); } else if (frame.SvgHeight.EndsWith("in")) { wdPx = SizeConverter.InchToPixelAsString(wd); } if (wdPx.Length > 0) { style = "height=\"" + wdPx + "\" "; } } } catch (Exception ex) { if (this.OnWarning != null) { AODLWarning warning = new AODLWarning("Exception while trying to build a graphic width & height.: " + frame.SvgWidth + "/" + frame.SvgHeight, ex); //warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); //warning.OriginalException = ex; OnWarning(warning); } } } } catch (Exception ex) { throw new AODLException("Exception while trying to build a HTML style string from a FrameStyle.", ex); } return(style); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object valueObject) { return(new Wrapper.Size(SizeConverter.ConvertFromString(GetValueAsString(valueObject)))); }
/// <summary> /// Gets the column style as HTML. /// </summary> /// <param name="columnStyle">The column style.</param> /// <returns></returns> public string GetColumnStyleAsHtml(ColumnStyle columnStyle) { string style = ""; try { if (columnStyle != null) { if (columnStyle.ColumnProperties != null) { if (columnStyle.ColumnProperties.Width != null) { string width = columnStyle.ColumnProperties.Width; if (width.EndsWith("cm")) { width = width.Replace("cm", ""); } else if (width.EndsWith("in")) { width = width.Replace("in", ""); } try { double wd = Convert.ToDouble(width, System.Globalization.NumberFormatInfo.InvariantInfo); string wdPx = ""; if (columnStyle.ColumnProperties.Width.EndsWith("cm")) { wdPx = SizeConverter.CmToPixelAsString(wd); } else if (columnStyle.ColumnProperties.Width.EndsWith("in")) { wdPx = SizeConverter.InchToPixelAsString(wd); } if (wdPx.Length > 0) { style = "width=\"" + wdPx + "\" "; } } catch (Exception ex) { if (this.OnWarning != null) { AODLWarning warning = new AODLWarning("Exception while trying to build a column width.: " + columnStyle.ColumnProperties.Width, ex); //warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); //warning.OriginalException = ex; OnWarning(warning); } } } } } } catch (Exception ex) { throw new AODLException("Exception while trying to build a HTML style string from a CellStyle.", ex); } return(style); }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); if (string.IsNullOrEmpty(Sku)) { Sku = SkuStrings.Standard; } if (string.IsNullOrEmpty(Size)) { if (SkuStrings.Premium.Equals(Sku, StringComparison.OrdinalIgnoreCase)) { Size = SizeConverter.P1String; } else { Size = SizeConverter.C1String; } } else { Size = SizeConverter.GetSizeInRedisSpecificFormat(Size, SkuStrings.Premium.Equals(Sku)); SizeConverter.ValidateSize(Size.ToUpper(), SkuStrings.Premium.Equals(Sku)); } int skuCapacity = 1; // Size to SkuFamily and SkuCapacity conversion string skuFamily = Size.Substring(0, 1); int.TryParse(Size.Substring(1), out skuCapacity); // If Force flag is not avaliable than check if cache is already available or not try { RedisResource availableCache = CacheClient.GetCache(ResourceGroupName, Name); if (availableCache != null) { throw new CloudException(string.Format(Resources.RedisCacheExists, Name)); } } catch (CloudException ex) { if (ex.Body.Code == "ResourceNotFound" || ex.Message.Contains("ResourceNotFound")) { // cache does not exists so go ahead and create one } else if (ex.Body.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound")) { // resource group not found, let create throw error don't throw from here } else { // all other exceptions should be thrown throw; } } ConfirmAction( string.Format(Resources.CreateRedisCache, Name), Name, () => { var redisResource = CacheClient.CreateCache(ResourceGroupName, Name, Location, skuFamily, skuCapacity, Sku, RedisConfiguration, EnableNonSslPort, TenantSettings, ShardCount, SubnetId, StaticIP, Tag, Zone); var redisAccessKeys = CacheClient.GetAccessKeys(ResourceGroupName, Name); WriteObject(new RedisCacheAttributesWithAccessKeys(redisResource, redisAccessKeys, ResourceGroupName)); }); }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); if (!string.IsNullOrEmpty(RedisVersion)) { WriteWarning("The RedisVersion parameter has been deprecated. As such, it is no longer necessary to provide this parameter and any value specified is ignored."); } if (!string.IsNullOrEmpty(VirtualNetwork) || !string.IsNullOrEmpty(Subnet)) { WriteWarning("Parameters 'VirtualNetwork' and 'Subnet' are deprecated. Please use SubnetId instead."); if (string.IsNullOrEmpty(SubnetId)) { SubnetId = string.Format("{0}/subnets/{1}", VirtualNetwork, Subnet); } } if (!string.IsNullOrEmpty(MaxMemoryPolicy)) { throw new ArgumentException(Resources.MaxMemoryPolicyException); } if (string.IsNullOrEmpty(Sku)) { Sku = SkuStrings.Standard; } if (string.IsNullOrEmpty(Size)) { Size = SizeConverter.C1String; } else { Size = SizeConverter.GetSizeInRedisSpecificFormat(Size, SkuStrings.Premium.Equals(Sku)); } int skuCapacity = 1; // Size to SkuFamily and SkuCapacity conversion string skuFamily = Size.Substring(0, 1); int.TryParse(Size.Substring(1), out skuCapacity); // If Force flag is not avaliable than check if cache is already available or not try { RedisResource availableCache = CacheClient.GetCache(ResourceGroupName, Name); if (availableCache != null) { throw new CloudException(string.Format(Resources.RedisCacheExists, Name)); } } catch (CloudException ex) { if (ex.Body.Code == "ResourceNotFound" || ex.Message.Contains("ResourceNotFound")) { // cache does not exists so go ahead and create one } else if (ex.Body.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound")) { // resource group not found, let create throw error don't throw from here } else { // all other exceptions should be thrown throw; } } var redisResource = CacheClient.CreateCache(ResourceGroupName, Name, Location, skuFamily, skuCapacity, Sku, RedisConfiguration, EnableNonSslPort, TenantSettings, ShardCount, SubnetId, StaticIP); var redisAccessKeys = CacheClient.GetAccessKeys(ResourceGroupName, Name); WriteObject(new RedisCacheAttributesWithAccessKeys(redisResource, redisAccessKeys, ResourceGroupName)); }
public void NoWriteTest() { var converter = new SizeConverter(); Assert.Throws <NotImplementedException>(() => converter.Write(default !, default !, default !));
public Sneaker ParseOneSneaker(Sneaker @sneaker) { string url = sneaker.link; Uri uri = new Uri(url); WebClient webClient = new WebClient(); webClient.Encoding = Encoding.UTF8; string source = String.Empty; try { source = webClient.DownloadString(uri); } catch (Exception e) { Program.Logger.Error(e.StackTrace); return(null); } var parser = new HtmlParser(); var document = parser.Parse(source); //sku sneaker.sku = document.QuerySelector("p.ref.hide-for-small").InnerHtml; //images var images = document.QuerySelector("div.medium-5.columns.column-carousel").QuerySelectorAll("meta"); //List<String> listImage = new List<String>(); foreach (var image in images) { string imageString = image.GetAttribute("content"); if (imageString.Contains(".jpg")) { sneaker.images.Add(imageString); } } sneaker.images.RemoveAt(sneaker.images.Count - 1); //sizes var HTMLSizes = document.QuerySelector("div.content.size-options.size_us-options"); if (HTMLSizes == null) //если null значит выход модели только ожидается { return(null); } else { var sizes = HTMLSizes.QuerySelectorAll("a.size-button.available"); foreach (var sizeitem in sizes) { string sizeUS = sizeitem.InnerHtml.Trim(); SneakerSize size = new SneakerSize(sizeUS); sneaker.sizes.Add(size); } //sizes //categorySneakerFullCatalog and sex if (sneaker.sizes.Count > 0) { if (sneaker.sizes[0].sizeUS.Contains("C") || sneaker.sizes[0].sizeUS.Contains("Y")) { sneaker.category = Settings.CATEGORY_KIDS; } else { string sizeEU = document.QuerySelector("div.content.size-options.size_eu-options").QuerySelectorAll("a.size-button.available")[0].InnerHtml; SizeConverter converterMan = new SizeConverter(sneaker.sizes[0].sizeUS, Settings.CATEGORY_MEN); if (converterMan.sizeEUR == sizeEU) { sneaker.category = Settings.CATEGORY_MEN; sneaker.sex = Settings.GENDER_MAN; } else { SizeConverter converterWoman = new SizeConverter(sneaker.sizes[0].sizeUS, Settings.CATEGORY_WOMEN); if (converterWoman.sizeEUR == sizeEU) { sneaker.category = Settings.CATEGORY_WOMEN; sneaker.sex = Settings.GENDER_WOMAN; } else { Program.Logger.Warn("wrong category sku:" + sneaker.sku + " link: " + sneaker.link); } } } } //color sneaker.color = document.QuerySelector("p.variant.hide-for-small").InnerHtml; sneaker.title += " " + sneaker.color; return(sneaker); } }
private bool ProcessSetValue(Type type, string name, string newvalue) { if (type == typeof(string)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { newvalue }); return(true); } if (type == typeof(bool)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { bool.Parse(newvalue) }); return(true); } if (type == typeof(int)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { int.Parse(newvalue) }); return(true); } if (type == typeof(long)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { long.Parse(newvalue) }); return(true); } if (type == typeof(decimal)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { decimal.Parse(newvalue) }); return(true); } if (type == typeof(float)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { float.Parse(newvalue) }); return(true); } if (type == typeof(double)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { double.Parse(newvalue) }); return(true); } if (type == typeof(char)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { char.Parse(newvalue) }); return(true); } if (type == typeof(Enum) || type.BaseType == typeof(Enum)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { Enum.Parse(type, newvalue) }); return(true); } if (type == typeof(Single)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { Single.Parse(newvalue) }); return(true); } if (type == typeof(Byte)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { Byte.Parse(newvalue) }); return(true); } if (type == typeof(SByte)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { SByte.Parse(newvalue) }); return(true); } if (type == typeof(Int16)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { Int16.Parse(newvalue) }); return(true); } if (type == typeof(Int32)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { Int32.Parse(newvalue) }); return(true); } if (type == typeof(Int64)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { Int64.Parse(newvalue) }); return(true); } if (type == typeof(UInt16)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { UInt16.Parse(newvalue) }); return(true); } if (type == typeof(UInt32)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { UInt32.Parse(newvalue) }); return(true); } if (type == typeof(UInt64)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { UInt64.Parse(newvalue) }); return(true); } // 20080827 : DateTimeConvertor.ConvertToInvariantString(DateTime.MinValue) return empty string "" // which cannot be parsed by following culture specific method. //if( type == typeof( DateTime ) ) //{ // this.GetType().InvokeMember( name, // /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | // BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField , // null, this, new object[]{ DateTime.Parse(newvalue) } ); // return true; //} if (type == typeof(TimeSpan)) { this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { TimeSpan.Parse(newvalue) }); return(true); } if (type == typeof(Color)) { ColorConverter cc = new ColorConverter(); this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { cc.ConvertFromInvariantString(newvalue) }); return(true); } if (type == typeof(Font)) { FontConverter cc = new FontConverter(); this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { cc.ConvertFromInvariantString(newvalue) }); return(true); } if (type == typeof(Point)) { PointConverter cc = new PointConverter(); this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { cc.ConvertFromInvariantString(newvalue) }); return(true); } if (type == typeof(Rectangle)) { RectangleConverter cc = new RectangleConverter(); this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { cc.ConvertFromInvariantString(newvalue) }); return(true); } if (type == typeof(Size)) { SizeConverter cc = new SizeConverter(); this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { cc.ConvertFromInvariantString(newvalue) }); return(true); } //if (type == typeof(Type)) //{ // Type newType = null; // if (newvalue != null && newvalue.Length > 0) // { // newType = Type.GetType(newvalue, true); // } // this.GetType().InvokeMember(name, // /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | // BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, // null, this, new object[] { newType }); // return true; //} if (!XObjectHelper.IsXBaseType(type)) { TypeConverter tc = TypeDescriptor.GetConverter(type); if (tc == null) { return(true); } this.GetType().InvokeMember(name, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField, null, this, new object[] { tc.ConvertFromInvariantString(newvalue) }); return(true); } return(true); }
private object ProcessGetValue(Type type, MemberInfo memInfo, object result) { if (type == typeof(string)) { if (memInfo == null) { return(result); } object[] olist = memInfo.GetCustomAttributes(XObjectHelper.XCDataAttributeType, false); if (olist == null || olist.Length < 1 || result == null) { return(result); } XCDataAttribute attr = olist[0] as XCDataAttribute; if (attr == null || attr.EnableCData == false) { return(result); } return("<![CDATA[" + result.ToString() + "]]>"); } if (type == typeof(Color)) { ColorConverter cc = new ColorConverter(); return(cc.ConvertToInvariantString(result)); } if (type == typeof(Font)) { FontConverter cc = new FontConverter(); return(cc.ConvertToInvariantString(result)); } if (type == typeof(Point)) { PointConverter cc = new PointConverter(); return(cc.ConvertToInvariantString(result)); } if (type == typeof(Rectangle)) { RectangleConverter cc = new RectangleConverter(); return(cc.ConvertToInvariantString(result)); } if (type == typeof(Size)) { SizeConverter cc = new SizeConverter(); return(cc.ConvertToInvariantString(result)); } //if (type == typeof(Type)) //{ // if (result == null) return ""; // return result.ToString(); //} if (!XObjectHelper.IsXBaseType(type)) { TypeConverter tc = TypeDescriptor.GetConverter(type); if (tc != null) { return(tc.ConvertToInvariantString(result)); } } return(result); }
/// <summary> /// Gets the table style as HTML. /// </summary> /// <param name="tableStyle">The table style.</param> /// <returns></returns> public string GetTableStyleAsHtml(TableStyle tableStyle) { string style = ""; try { if (tableStyle != null) { if (tableStyle.TableProperties != null) { if (tableStyle.TableProperties.Width != null) { string width = tableStyle.TableProperties.Width; if (width.EndsWith("cm")) { width = width.Replace("cm", ""); } else if (width.EndsWith("in")) { width = width.Replace("in", ""); } try { double wd = Convert.ToDouble(width, System.Globalization.NumberFormatInfo.InvariantInfo); string wdPx = ""; if (tableStyle.TableProperties.Width.EndsWith("cm")) { wdPx = SizeConverter.CmToPixelAsString(wd); } else if (tableStyle.TableProperties.Width.EndsWith("in")) { wdPx = SizeConverter.InchToPixelAsString(wd); } if (wdPx.Length > 0) { style = "width=\"" + wdPx.Replace("px", "") + "\" "; } } catch (Exception ex) { if (this.OnWarning != null) { AODLWarning warning = new AODLWarning("Exception while trying to build a table width width.: " + tableStyle.TableProperties.Width, ex); //warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); //warning.OriginalException = ex; OnWarning(warning); } } } if (tableStyle.TableProperties.Align != null) { if (tableStyle.TableProperties.Align != "margin") { if (tableStyle.TableProperties.Align == "center") { style += "align=\"center\" "; } else if (tableStyle.TableProperties.Align == "right") { style += "align=\"center\" "; //Because display prob by some browser } } } } } } catch (Exception ex) { throw new AODLException("Exception while trying to build a HTML style string from a TableStyle.", ex); } return(style); }
internal static string ConvertToSizeString(long size) { SizeConverter.EnumUnitSize totalSizeUnit = SizeConverter.GetSuitableUnit(size); return(string.Format("{0:#0.##} {1}", SizeConverter.ConvertToSize( size, totalSizeUnit), SizeConverter.GetUnitString(totalSizeUnit))); }