internal DocxDocumentTableSchemeBuilder(WordprocessingDocument document, TableProperties contextTableProperties) : base(document) { table = new Table(); if (contextTableProperties == null) { var borderType = new EnumValue<BorderValues>(BorderValues.Thick); var tblProp = new TableProperties( new TableBorders( new TopBorder {Val = borderType, Size = 1}, new BottomBorder {Val = borderType, Size = 1}, new LeftBorder {Val = borderType, Size = 1}, new RightBorder {Val = borderType, Size = 1}, new InsideHorizontalBorder {Val = borderType, Size = 1}, new InsideVerticalBorder {Val = borderType, Size = 1} ) ); table.AppendChild(tblProp); } else table.AppendChild(contextTableProperties); headerRow = new TableRow(); table.AppendChild(headerRow); Aggregation.Add(table); }
public EnumerationMemberData(EnumValue value) { this.Code = value.Code; this.Value = value.Value; this.Description = value.Description; this.DisplayOrder = value.DisplayOrder; this.Deactivated = value.Deactivated; }
/// <summary> /// Banned heros /// </summary> //todo: public RangeValue<uint> BannedHeros; /// <summary> /// Selected heros /// </summary> //todo: public RangeValue<uint> SelectedHeros; #endregion public GameRules(uint id, DotaGameState state) : base(id, state) { const string t = "DT_DOTAGamerules"; GameState = bindE<DOTA_GameState>(t, "m_nGameState"); GameTime = bind<float>(t, "m_fGameTime"); GameStartTime = bind<float>(t, "m_flGameStartTime"); GameEndTime = bind<float>(t, "m_flGameEndTime"); PreGameStartTime = bind<float>(t, "m_flPreGameStartTime"); //MatchID = bind<ulong>(t, "m_unMatchID"); broken GameMode = bindE<DOTA_GameMode>(t, "m_nGameState"); PauseTeam = bindE<DOTA_ServerTeam>(t, "m_iPauseTeam"); GameWinner = bindE<DOTA_ServerTeam>(t, "m_nGameWinner"); NetTimeOfDay = bind<ulong>(t, "m_iNetTimeOfDay"); DraftStartingTeam = bindE<DOTA_ServerTeam>(t, "m_iStartingTeam"); DraftActiveTeam = bindE<DOTA_ServerTeam>(t, "m_iActiveTeam"); HeroPickState = bindE<DOTA_HeroPickState>(t, "m_nHeroPickState"); //ExtraTimeRemaining = bind<float>(t, "m_fExtraTimeRemaining"); broken //todo: BannedHeros = range<uint>("m_BannedHeroes", ) //todo: handle m_nGGTeam and m_flGGEndsAtTime }
public void EnumValueTest() { EnumValue<M.BooleanValues> onoffEnum = new EnumValue<M.BooleanValues>(); Assert.False(onoffEnum.HasValue); Assert.Null(onoffEnum.InnerText); Assert.Null(onoffEnum.ToString()); onoffEnum.InnerText = "error value"; Assert.False(onoffEnum.HasValue); Assert.Equal("error value", onoffEnum.InnerText); Assert.Equal("error value", onoffEnum.ToString()); onoffEnum.InnerText = string.Empty; Assert.False(onoffEnum.HasValue); Assert.Equal(string.Empty, onoffEnum.InnerText); Assert.Equal(string.Empty, onoffEnum.ToString()); onoffEnum.InnerText = "on"; Assert.True(onoffEnum.HasValue); Assert.Equal("on", onoffEnum.InnerText); Assert.Equal(M.BooleanValues.On, onoffEnum.Value); Assert.Equal(M.BooleanValues.On, (M.BooleanValues)onoffEnum); Assert.Equal("on", onoffEnum.ToString()); //onoffEnum.Value = M.BooleanValues.False; //Assert.True(onoffEnum.HasValue); //Assert.Equal("false", onoffEnum.InnerText); //Assert.Equal(M.BooleanValues.False, onoffEnum.Value); //Assert.Equal(M.BooleanValues.False, (M.BooleanValues)onoffEnum); //Assert.Equal("false", onoffEnum.ToString()); //onoffEnum = new EnumValue<M.BooleanValues>(M.BooleanValues.Zero); //Assert.True(onoffEnum.HasValue); //Assert.Equal("0", onoffEnum.InnerText); //Assert.Equal(M.BooleanValues.Zero, onoffEnum.Value); //Assert.Equal(M.BooleanValues.Zero, (M.BooleanValues)onoffEnum); //Assert.Equal("0", onoffEnum.ToString()); var newEnum = new EnumValue<M.BooleanValues>(onoffEnum); Assert.True(newEnum.HasValue); //Assert.Equal("0", newEnum.InnerText); //Assert.Equal(M.BooleanValues.Zero, newEnum.Value); //Assert.Equal(M.BooleanValues.Zero, (M.BooleanValues)newEnum); //Assert.Equal("0", newEnum.ToString()); newEnum.Value = M.BooleanValues.Off; Assert.True(newEnum.HasValue); Assert.Equal("off", newEnum.InnerText); Assert.Equal(M.BooleanValues.Off, newEnum.Value); Assert.Equal(M.BooleanValues.Off, (M.BooleanValues)newEnum); Assert.Equal("off", newEnum.ToString()); // the onoffEnum should not be changed. Assert.True(onoffEnum.HasValue); Assert.Equal("on", onoffEnum.InnerText); Assert.Equal(M.BooleanValues.On, onoffEnum.Value); Assert.Equal(M.BooleanValues.On, (M.BooleanValues)onoffEnum); Assert.Equal("on", onoffEnum.ToString()); // test sepcial case - the enum can be empty string "" var truefalseEmpty = new EnumValue<xvml.BooleanEntryWithBlankValues>(xvml.BooleanEntryWithBlankValues.Empty); Assert.True(truefalseEmpty.HasValue); Assert.Equal("", truefalseEmpty.InnerText); Assert.Equal(xvml.BooleanEntryWithBlankValues.Empty, truefalseEmpty.Value); Assert.Equal(xvml.BooleanEntryWithBlankValues.Empty, (xvml.BooleanEntryWithBlankValues)truefalseEmpty); Assert.Equal("", truefalseEmpty.ToString()); truefalseEmpty = xvml.BooleanEntryWithBlankValues.T; Assert.True(truefalseEmpty.HasValue); Assert.Equal("t", truefalseEmpty.InnerText); Assert.Equal(xvml.BooleanEntryWithBlankValues.T, truefalseEmpty.Value); Assert.Equal(xvml.BooleanEntryWithBlankValues.T, (xvml.BooleanEntryWithBlankValues)truefalseEmpty); Assert.Equal("t", truefalseEmpty.ToString()); truefalseEmpty.InnerText = string.Empty; Assert.True(truefalseEmpty.HasValue); Assert.Equal("", truefalseEmpty.InnerText); Assert.Equal(xvml.BooleanEntryWithBlankValues.Empty, truefalseEmpty.Value); Assert.Equal(xvml.BooleanEntryWithBlankValues.Empty, (xvml.BooleanEntryWithBlankValues)truefalseEmpty); Assert.Equal("", truefalseEmpty.ToString()); // Clone constructor for EnumValue HeaderFooterValues validValue0 = HeaderFooterValues.Default; var objA = new EnumValue<HeaderFooterValues>(validValue0); var objB = new EnumValue<HeaderFooterValues>(objA); Assert.True(objA.HasValue); Assert.True(objB.HasValue); Assert.Equal("default", objA.InnerText); Assert.Equal("default", objB.InnerText); // Clone() for EnumValue. objA = new EnumValue<HeaderFooterValues>(validValue0); objB = (EnumValue<HeaderFooterValues>)(objA.Clone()); Assert.True(objA.HasValue); Assert.True(objB.HasValue); Assert.Equal("default", objA.InnerText); Assert.Equal("default", objB.InnerText); }
internal ColumnFormat(Column column, SpreadsheetDocument document, TimeZoneInfo timezone = null) { this.Column = column; var type = column.Type; if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) type = type.GetGenericArguments()[0]; if (type == typeof(int) || type == typeof(long) || type == typeof(decimal) || type == typeof(float) || type == typeof(double)) { DataType = new EnumValue<CellValues>(CellValues.Number); if (!String.IsNullOrWhiteSpace(column.Format)) { var percentSymbol = NumberFormatInfo.CurrentInfo.PercentSymbol; if (column.Format == "P" || column.Format == "p" || column.Format.Contains(NumberFormatInfo.CurrentInfo.PercentSymbol)) { Style = CreateStyle(11.10.ToString(column.Format, CultureInfo.InvariantCulture).Replace("1", "#") + ";" + (-11.10).ToString(column.Format, CultureInfo.InvariantCulture).Replace("1", "#"), document); GetCellValue = v => String.IsNullOrWhiteSpace(v) ? v : (Double.Parse(v.Replace(NumberFormatInfo.CurrentInfo.PercentSymbol, ""), NumberStyles.Any) / 100).ToString(CultureInfo.InvariantCulture); } else if (column.Format == "C" || column.Format == "c" || column.Format.Contains(NumberFormatInfo.CurrentInfo.CurrencySymbol)) { // get the culture specific pattern var pattern = 1110.00.ToString("C").Replace("1", "#").Replace(NumberFormatInfo.CurrentInfo.CurrencySymbol, "[$" + NumberFormatInfo.CurrentInfo.CurrencySymbol + "-1]"); // convert everything but the currency symbol and placement to the invariant pattern pattern = new System.Text.RegularExpressions.Regex("#.##0.00").Replace(pattern, "#,##0.00"); // create the excel style Style = CreateStyle(pattern + ";(" + pattern + ")", document); } else Style = CreateStyle(1111.10.ToString(column.Format, CultureInfo.InvariantCulture).Replace("1", "#") + ";" + (-1111.10).ToString(column.Format, CultureInfo.InvariantCulture).Replace("1", "#") + ";" + 0.ToString(column.Format, CultureInfo.InvariantCulture), document); } if (GetCellValue == null) GetCellValue = v => String.IsNullOrWhiteSpace(v) ? v : Double.Parse(v, NumberStyles.Any).ToString(CultureInfo.InvariantCulture); } else if (type == typeof(DateTime) || type == typeof(Nullable<DateTime>)) { var isDateTime = true; DataType = new EnumValue<CellValues>(CellValues.Number); if (!String.IsNullOrWhiteSpace(column.Format) && column.Format.Length == 1) { isDateTime = column.Format.ToLower() != "d" && column.Format.ToLower() != "t"; var patterns = DateTimeFormatInfo.CurrentInfo.GetAllDateTimePatterns(column.Format[0]); if (patterns.Any()) Style = CreateStyle(patterns[0].Replace("tt", "AM/PM"), document); } // adjust the time to match the specified timezone if the type is a true DateTime and not a Date only or Time only field if (timezone != null && isDateTime) GetCellValue = (v) => { return String.IsNullOrWhiteSpace(v) ? v : TimeZoneInfo.ConvertTime(DateTime.Parse(v, null, DateTimeStyles.AssumeUniversal), timezone).ToOADate().ToString(CultureInfo.InvariantCulture); }; else GetCellValue = v => String.IsNullOrWhiteSpace(v) ? v : DateTime.Parse(v).ToOADate().ToString(CultureInfo.InvariantCulture); } else { DataType = new EnumValue<CellValues>(CellValues.String); // Cleanse string based on acceptable xml character set // http://stackoverflow.com/questions/6468783/what-is-the-difference-between-cellvalues-inlinestring-and-cellvalues-string-in GetCellValue = v => TextFilter.Replace(v, ""); } }
//Adds table borders accordeing to "properties" public void AddBorders(Properties properties) { EnumValue<BorderValues> borderValue = new EnumValue<BorderValues>(); switch (properties) { case Properties.withBorders: { borderValue = BorderValues.Single; break; } case Properties.borderless: { borderValue = BorderValues.None; break; } case Properties.byDefault: { borderValue = BorderValues.Single; break; } } tblProperties = new TableProperties(); tblBorders = new TableBorders(); tblBorders.TopBorder = new TopBorder(); tblBorders.TopBorder.Val = borderValue; tblBorders.BottomBorder = new BottomBorder(); tblBorders.BottomBorder.Val = borderValue; tblBorders.LeftBorder = new LeftBorder(); tblBorders.LeftBorder.Val = borderValue; tblBorders.RightBorder = new RightBorder(); tblBorders.RightBorder.Val = borderValue; tblBorders.InsideHorizontalBorder = new InsideHorizontalBorder(); tblBorders.InsideHorizontalBorder.Val = borderValue; tblBorders.InsideVerticalBorder = new InsideVerticalBorder(); tblBorders.InsideVerticalBorder.Val = borderValue; tblProperties.Append(tblBorders); table.Append(tblProperties); }
private EnumValue<CellValues> GetDataType(string cellValue, EnumValue<CellValues> dataType, IEnumerable<TokensProvider> objectsWithTokens) { if (String.IsNullOrEmpty(cellValue)) return dataType; foreach (var objectsWithToken in objectsWithTokens) { if (objectsWithToken == null) continue; if (objectsWithToken.HasToken(cellValue)) { object value = objectsWithToken.GetTokenValue(cellValue); if (value is string) return CellValues.String; return null; } } if (dataType != null && dataType == CellValues.SharedString) return CellValues.String; return dataType; }
private String GetCellText(List<String> strings, String initialValue, IEnumerable<TokensProvider> objectsWithTokens, string cellValue, EnumValue<CellValues> dataType) { foreach (var objectsWithToken in objectsWithTokens) { if (objectsWithToken == null) continue; if (objectsWithToken.HasToken(cellValue)) { return objectsWithToken.GetTokenValue(cellValue).ToString(); } } if (dataType != null && dataType == CellValues.SharedString) return strings[Convert.ToInt32(initialValue)]; return initialValue; }