/// <summary> /// Updates the UI display by authority. /// </summary> private void UpdateUIDisplayByAuthority() { BindingFlags flag = BindingFlags.Instance | BindingFlags.NonPublic; MemberInfo[] memberInfos = typeof(BCMainForm).GetMembers(flag); var typeSwitch = new TypeSwitch() .Case((System.Windows.Forms.ToolStripMenuItem tsm, bool tf) => { tsm.Enabled = tf; }) .Case((System.Windows.Forms.ComboBox cb, bool tf) => { cb.Enabled = tf; }); foreach (MemberInfo memberInfo in memberInfos) { Attribute AuthorityCheck = memberInfo.GetCustomAttribute(typeof(AuthorityCheck)); if (AuthorityCheck != null) { string attribute_FUNName = ((AuthorityCheck)AuthorityCheck).FUNCode; FieldInfo info = (FieldInfo)memberInfo; if (bcApp.SCApplication.UserBLL.checkUserAuthority(bcApp.LoginUserID, attribute_FUNName)) { typeSwitch.Switch(info.GetValue(this), true); } else { typeSwitch.Switch(info.GetValue(this), false); } } } }
public Message Write(NetOutgoingMessage message, bool isInherited = false) { if (!isInherited) { message.Write(this.Type.ToString()); } foreach (var key in this.keys) { var nv = this.Fields[key]; var ts = new TypeSwitch() .Case((int x) => message.Write(x)) .Case((float x) => message.Write(x)) .Case((byte x) => message.Write(x)) .Case((string x) => message.Write(x)); ts.Switch(nv.Value); } foreach (var inherited in this.inheritedMessages) { inherited.Write(message, true); } return(this); }
public StackerBlockViewModel(BlockBase block, Random rand) { Id = rand.Next(); Block = block; OnPropertyChanged("Label"); OnPropertyChanged("Color"); // Define mapping scheme var ts = new TypeSwitch() .Case((BlockParse x) => Page = new PageBlockParse(x)) .Case((BlockKeycheck x) => Page = new PageBlockKeycheck(x)) .Case((BlockRequest x) => Page = new PageBlockRequest(x)) .Case((BlockRecaptcha x) => Page = new PageBlockRecaptcha(x)) .Case((BlockFunction x) => Page = new PageBlockFunction(x)) .Case((BlockImageCaptcha x) => Page = new PageBlockCaptcha(x)) .Case((BlockBypassCF x) => Page = new PageBlockBypassCF(x)) .Case((BlockUtility x) => Page = new PageBlockUtility(x)) .Case((BlockLSCode x) => Page = new PageBlockLSCode(x)) .Case((BlockTCP x) => Page = new PageBlockTCP(x)) .Case((SBlockNavigate x) => Page = new PageSBlockNavigate(x)) .Case((SBlockBrowserAction x) => Page = new PageSBlockBrowserAction(x)) .Case((SBlockElementAction x) => Page = new PageSBlockElementAction(x)) .Case((SBlockExecuteJS x) => Page = new PageSBlockExecuteJS(x)); ts.Switch(Block); }
public Message Read(NetIncomingMessage message) { // why in the name of actual f**k do I need to reset the // position of an incoming message stream manually.....? //message.Position = 0; this.SenderInfo = new SenderInfo { Connection = message.SenderConnection }; foreach (var key in this.keys) { var nv = this.Fields[key]; var ts = new TypeSwitch() .Case((int x) => this.SetField(key, message.ReadInt32())) .Case((float x) => this.SetField(key, message.ReadSingle())) .Case((byte x) => this.SetField(key, message.ReadByte())) .Case((string x) => this.SetField(key, message.ReadString())); ts.Switch(nv.Type); } foreach (var inherited in this.inheritedMessages) { inherited.Read(message); } return(this); }
public Color GetBlockColor() { Color color = Colors.Black; // Define mapping scheme var ts = new TypeSwitch() .Case((BlockParse x) => color = Colors.Gold) .Case((BlockKeycheck x) => color = Colors.DodgerBlue) .Case((BlockRequest x) => color = Colors.LimeGreen) .Case((BlockRecaptcha x) => color = Colors.Turquoise) .Case((BlockFunction x) => color = Colors.YellowGreen) .Case((BlockImageCaptcha x) => color = Colors.DarkOrange) .Case((BlockBypassCF x) => color = Colors.DarkSalmon) .Case((BlockUtility x) => color = Colors.Wheat) .Case((BlockLSCode x) => color = Colors.White) .Case((BlockTCP x) => color = Colors.MediumPurple) .Case((SBlockNavigate x) => color = Colors.RoyalBlue) .Case((SBlockBrowserAction x) => color = Colors.Green) .Case((SBlockElementAction x) => color = Colors.Firebrick) .Case((SBlockExecuteJS x) => color = Colors.Indigo); // Execute type check to set color data ts.Switch(Block); return(color); }
// TODO: log when returning null public static T CreateRenderRequest <T>() where T : class, IRenderRequest // unf cannot constrain T to be an interface, only a class { if (typeof(T) == typeof(IRenderRequest)) { throw new RenderRequestNotImplementedException("The supplied interface cannot be the base interface. You have to use a derived type. Used type: " + typeof(IRenderRequest).Name); } return(RRSwitch.Switch <T>()); }
private HttpStatusCode GetHttpStatus() { var code = HttpStatusCode.InternalServerError; var ts = new TypeSwitch() .Case((InvalidHttpHeaderException e) => code = HttpStatusCode.BadRequest) .Case((FileNotFoundException e) => code = HttpStatusCode.NotFound) .Case((UnauthorizedAccessException e) => code = HttpStatusCode.Forbidden) .DefaultAction((e) => code = HttpStatusCode.InternalServerError); ts.Switch(_exception); return(code); }
private static string ValueToString(object obj) { TypeSwitch ts = new TypeSwitch() .Case((bool x) => x ? "1" : "0") .Case((string x) => $"'{x}'") .Case((int x) => x.ToString(CultureInfo.InvariantCulture)) .Case((float x) => x.ToString(CultureInfo.InvariantCulture)) .Case((decimal x) => x.ToString(CultureInfo.InvariantCulture)) .Case((long x) => x.ToString(CultureInfo.InvariantCulture)) .Case((short x) => x.ToString(CultureInfo.InvariantCulture)) .Case((DateTime x) => $"'{x.ToString(CultureInfo.InvariantCulture)}'")// TODO: forzare formattazione .Case((char x) => $"'{x.ToString(CultureInfo.InvariantCulture)}'") ; return(ts.Switch(obj)); }
/// <summary> /// The populate entity property with dynamic entity value. /// </summary> /// <param name="entity"> /// The entity. /// </param> /// <param name="propertyInfo"> /// The property info. /// </param> /// <param name="targetObject"> /// The target object. /// </param> /// <param name="propertyName"> /// The property name. /// </param> /// <typeparam name="TEntity"> /// Entity type of element. /// </typeparam> private static void PopulateEntityPropertyWithDynamicEntityValue <TEntity>( DynamicTableEntity entity, PropertyInfo propertyInfo, TEntity targetObject, string propertyName) { var typeSwitch = new TypeSwitch().Case <int>( () => propertyInfo.SetValue(targetObject, entity.Properties[propertyName].Int32Value)) .Case <long>(() => propertyInfo.SetValue(targetObject, entity.Properties[propertyName].Int64Value)) .Case <string>( () => propertyInfo.SetValue(targetObject, entity.Properties[propertyName].StringValue)) .Case <byte[]>( () => propertyInfo.SetValue(targetObject, entity.Properties[propertyName].BinaryValue)) .Case <bool>(() => propertyInfo.SetValue(targetObject, entity.Properties[propertyName].BooleanValue)) .Case <DateTime>(() => propertyInfo.SetValue(targetObject, entity.Properties[propertyName].DateTime)) .Case <Guid>(() => propertyInfo.SetValue(targetObject, entity.Properties[propertyName].GuidValue)) .Case <object>( () => propertyInfo.SetValue(targetObject, entity.Properties[propertyName].PropertyAsObject)); typeSwitch.Switch(propertyInfo.PropertyType); }
public RuntimeConstantPools(Dictionary <int, ConstantInfo> filecp, VmContiner cl, JavaClass jclass) { this.Class = jclass; this.ClassLoader = cl; swi = new TypeSwitch <RuntimeConstantInfo>() .Case((Integer_CP x) => new Literal <int>((int)x.Value)) .Case((Double_CP x) => new Literal <double>(x.Value)) .Case((Float_CP x) => new Literal <float>(x.Value)) .Case((Long_CP x) => new Literal <long>((long)x.Value)) .Case((String_CP x) => new Literal <string>(((UTF8_CP)filecp[x.Utf8Str_Index]).DataString)) .Case((UTF8_CP x) => new Literal <string>(x.DataString)) .Case((Class_CP x) => new ClassRef(this, ((UTF8_CP)filecp[x.Name_Index]).DataString)) .Case((FieldRef_CP x) => { var classname = ((UTF8_CP)filecp[((Class_CP)filecp[x.Class_Index]).Name_Index]).DataString; var namedAndTypeRef = (NameAndType_CP)filecp[x.Name_And_Type_Index]; return(new FieldRef(this, classname, ((UTF8_CP)filecp[namedAndTypeRef.Name_Index]).DataString, ((UTF8_CP)filecp[namedAndTypeRef.Descrptor_Index]).DataString)); }) .Case((MethodRef_CP x) => { var classname = ((UTF8_CP)filecp[((Class_CP)filecp[x.Class_Index]).Name_Index]).DataString; var namedAndTypeRef = (NameAndType_CP)filecp[x.Name_And_Type_Index]; return(new MethodRef(this, classname, ((UTF8_CP)filecp[namedAndTypeRef.Name_Index]).DataString, ((UTF8_CP)filecp[namedAndTypeRef.Descrptor_Index]).DataString)); }) .Case((InterfaceMethodref_CP x) => { var classname = ((UTF8_CP)filecp[((Class_CP)filecp[x.Class_Index]).Name_Index]).DataString; var namedAndTypeRef = (NameAndType_CP)filecp[x.Name_And_Type_Index]; return(new InterfaceRef(this, classname, ((UTF8_CP)filecp[namedAndTypeRef.Name_Index]).DataString, ((UTF8_CP)filecp[namedAndTypeRef.Descrptor_Index]).DataString)); }) .Case((NameAndType_CP x) => null); foreach (var kvp in filecp) { dic.Add(kvp.Key, swi.Switch(kvp.Value)); } }
/// <summary> /// Method to check if we have a route match /// </summary> /// <param name="url"></param> /// <param name="matchstring"></param> /// <returns></returns> public bool IsMatch(string url) { // get the match var match = Regex.Match(url, this.RouteMatch, RegexOptions.IgnoreCase); if (match.Success) { var dict = new Dictionary <string, object>(); if (match.Groups.Count >= ComponentParameters.Count) { var i = 1; foreach (var pars in ComponentParameters) { string matchValue = string.Empty; if (i < match.Groups.Count) { matchValue = match.Groups[i].Value; } var ts = new TypeSwitch() .Case((int x) => { if (int.TryParse(matchValue, out int value)) { dict.Add(pars.Key, value); } else { dict.Add(pars.Key, pars.Value); } }) .Case((float x) => { if (float.TryParse(matchValue, out float value)) { dict.Add(pars.Key, value); } else { dict.Add(pars.Key, pars.Value); } }) .Case((decimal x) => { if (decimal.TryParse(matchValue, out decimal value)) { dict.Add(pars.Key, value); } else { dict.Add(pars.Key, pars.Value); } }) .Case((string x) => { dict.Add(pars.Key, matchValue); }); ts.Switch(pars.Value); i++; } } this.RouteData = new RouteData(this.PageType, dict); } return(match.Success); }
public T Get <T>() where T : GeometryBase { return(m_geometries.Switch <T>()); }
public T Get <T>() where T : EffectBase { return(m_effects.Switch <T>()); }
public static void SetCellValue(WorksheetCell cell, object value, IMeasure measured = null, object tag = null, string fieldName = null) { var @switch = new TypeSwitch <object>() .Case((int i) => { //cell.CellFormat.Alignment = HorizontalCellAlignment.Right; return(i); }) .Case((double d) => { if (tag != null && string.Equals(tag.ToString(), "UseMeasureConverter")) { if (measured != null && measured.UseBindedConverter) { var ud = (double)measured.UsedUnitDigit / (double)measured.SelectedUnitDigit; if (ud != 1) { d = Math.Round(d, 5) * ud; } else { d = Math.Round(d, 5); } } else { d = Math.Round(d, 7); } } if ((d % 1) != 0) { cell.CellFormat.FormatString = CommonEx.ExcelformatString; } else { cell.CellFormat.FormatString = _intFormatted; } return(d); }) .Case((DateTime dt) => { string formatString; if (tag != null) { var templateName = tag.ToString(); switch (templateName) { case ConstantHelper.HalfHourstoRangeTimeTemplateName: case ConstantHelper.HourstoRangeTimeTemplateName: formatString = "HH:mm"; var dtTo = dt.TimeOfDay.Add(templateName == ConstantHelper.HourstoRangeTimeTemplateName ? GlobalEnums.Delta60Minute : GlobalEnums.Delta30Minute); formatString += "\"-" + dtTo.Hours.ToString("00") + ":" + dtTo.Minutes.ToString("00") + "\""; if (dt.TimeOfDay == TimeSpan.Zero) { formatString = "dd.MM.yyyy " + formatString; } break; case ConstantHelper.DateTemplateName: formatString = "dd.MM.yyyy"; break; default: formatString = "dd.MM.yyyy HH:mm"; break; } } else { formatString = "dd.MM.yyyy HH:mm"; } cell.CellFormat.FormatString = formatString; return(dt); }) .Case((TPS_isCA ps) => { // if (ps.IsCA) { return(EnumClientServiceDictionary.ContrPSList[ps.PS_ID]); } return(EnumClientServiceDictionary.DetailPSList[ps.PS_ID].HierarchyObject); }) .Case((TFormulaValidateByOneValues ti) => { // if (ti.TI_Ch_ID.IsCA) { return(EnumClientServiceDictionary.TICAList[ti.TI_Ch_ID.TI_ID]); } return(EnumClientServiceDictionary.TIHierarchyList[ti.TI_Ch_ID.TI_ID]); }) .Case((TGroupTPResult tpResult) => { if (string.IsNullOrEmpty(fieldName)) { return(null); } switch (fieldName) { case "PowerMax": { //Здась надо учесть IsAbsolutely return(tpResult.PowerMax); } case "PowerFactUsed": return(tpResult.PowerFactUsed != null ? tpResult.PowerFactUsed.F_VALUE : 0); case "PowerMaxReserved": return(tpResult.PowerMaxReserved); case "GroupTP_MAX_VALUE.EventDateTime": return(tpResult.TotalPowerInfoInSystemOperatorsHours != null && tpResult.TotalPowerInfoInSystemOperatorsHours.GroupTP_MAX_VALUE != null ? tpResult.TotalPowerInfoInSystemOperatorsHours.GroupTP_MAX_VALUE.EventDateTime as DateTime? : null); } return(null); }) .Case((enumTypeHierarchy th) => { string hierarchyName; if (GlobalEnumsDictionary.EnumTypeHierarchyName.TryGetValue(th, out hierarchyName)) { return(hierarchyName); } return(th.ToString()); }) .Case((bool b) => { if (b) { cell.CellFormat.Alignment = HorizontalCellAlignment.Center; return(char.ConvertFromUtf32(0xF0FE)); } return(string.Empty); }) .Case((EnumForecastObjectFixedType foft) => { string resource; return(!ServiceDictionary.ForecastObjectFixedTypeDictionary.TryGetValue(foft, out resource) ? string.Empty : resource); }) .Case((TTariffPeriodID ch) => { var chName = string.Empty; if (!ChannelFactory.ChanelTypeNameFSK.TryGetValue(ch.ChannelType, out chName)) { chName = " <?>"; } return(ChannelDictionaryClass.MakeZoneNamePrefix(ch.TI_ID, ch.ChannelType, ch.StartDateTime, ch.FinishDateTime) + chName); }) .Case((IFValue fv) => { double v; if (fieldName == "Value_Section" || fieldName == "Value_CA") { v = fv.F_VALUE; } else { ServiceReference.ARM_20_Service.EnumUnitDigit?unitDigit; if (measured != null && measured.UseBindedConverter) { var ud = (double)measured.UsedUnitDigit / (double)measured.SelectedUnitDigit; if (ud != 1) { v = Math.Round(fv.F_VALUE, 5) * ud; } else { v = Math.Round(fv.F_VALUE, 5); } unitDigit = measured.SelectedUnitDigit; } else { v = Math.Round(fv.F_VALUE, 7); unitDigit = null; } //Если нужно форматировать, то раскоментировать здесь, но почему то тормоза if ((v % 1) != 0) { cell.CellFormat.FormatString = CommonEx.GetExcelFormatString(unitDigit); } else { cell.CellFormat.FormatString = _intFormatted; } Color color; if (fv.F_FLAG.HasFlag(ServiceReference.ARM_20_Service.VALUES_FLAG_DB.DataNotComplete) || (fv.F_FLAG.HasFlag(ServiceReference.ARM_20_Service.VALUES_FLAG_DB.NotCorrect))) { color = Color.IndianRed; } else if (fv.F_FLAG.HasFlag(ServiceReference.ARM_20_Service.VALUES_FLAG_DB.DataNotFull)) { color = Color.LightGray; } else { color = Color.LightGreen; } //if (cell.Comment == null) cell.Comment = new WorksheetCellComment(); //cell.Comment.Text = new FormattedString(TVALUES_DB.FLAG_to_String(valuesDb.F_FLAG, ",\n")); cell.CellFormat.Alignment = HorizontalCellAlignment.Right; cell.CellFormat.Fill = new CellFillPattern(new WorkbookColorInfo(color), new WorkbookColorInfo(color), FillPatternStyle.Solid); } return(v); }) .Case((IForecastValue fVal) => { double v; if (measured != null && measured.UseBindedConverter) { v = fVal.F_VALUE / (double)measured.SelectedUnitDigit; } else { v = fVal.F_VALUE; } cell.CellFormat.FormatString = CommonEx.ExcelformatString; Color color; if (fVal.F_FLAG.HasFlag(Proryv.Servers.Forecast.Client_ServiceReference.ForecastServiceReference.EnumForecastValueValid.DataNotComplete) || (fVal.F_FLAG.HasFlag(Proryv.Servers.Forecast.Client_ServiceReference.ForecastServiceReference.EnumForecastValueValid.NotCorrect))) { color = Color.IndianRed; } else if (fVal.F_FLAG.HasFlag(Proryv.Servers.Forecast.Client_ServiceReference.ForecastServiceReference.EnumForecastValueValid.DataNotFull)) { color = Color.LightGray; } else { color = Color.LightGreen; } //if (cell.Comment == null) cell.Comment = new WorksheetCellComment(); //cell.Comment.Text = new FormattedString(TFORECAST_DB.ForecastFlagToString(fVal.F_FLAG, "\n")); cell.CellFormat.Alignment = HorizontalCellAlignment.Right; cell.CellFormat.Fill = new CellFillPattern(new WorkbookColorInfo(color), new WorkbookColorInfo(color), FillPatternStyle.Solid); //if (cell.Comment == null) cell.Comment = new WorksheetCellComment(); //cell.Comment.Text = new FormattedString(TFORECAST_DB.ForecastFlagToString(fVal.F_FLAG, "\n")); //cell.CellFormat.Alignment = HorizontalCellAlignment.Right; //cell.CellFormat.Fill = new CellFillPattern(new WorkbookColorInfo(color), new WorkbookColorInfo(color), FillPatternStyle.Solid); if ((v % 1) != 0) { cell.CellFormat.FormatString = CommonEx.ExcelformatString; } else { cell.CellFormat.FormatString = _intFormatted; } return(v); }) .Case((RequestStatus rs) => { cell.CellFormat.Alignment = HorizontalCellAlignment.Center; switch (rs) { case RequestStatus.Aborted: return("Отклонен"); case RequestStatus.Applied: return("Утвержден"); case RequestStatus.Created: return("На рассмотрении"); } return(string.Empty); //e.FormatSettings.HorizontalAlignment = HorizontalCellAlignment.Center; }) .Case((List <KeyValuePair <int, int> > list) => { var res = string.Empty; foreach (var l in list) { res += (res.Length > 0 ? ", " : "") + EnumClientServiceDictionary.TIHierarchyList[l.Value]; } return(res); }) .Case((enumChannelType ct) => { return(ChannelFactory.ChanelTypeNameFSK[(int)ct]); }) .Case((IFreeHierarchyObject fho) => { return(fho.Name); }) .Case((ServiceReference.ARM_20_Service.VALUES_FLAG_DB flag) => { return(FlagToCell(flag, cell)); }) .Case((enumPowerFlag flag) => { return(FlagToCell(flag, cell)); }) .Case((ulong l) => { var flag = (ServiceReference.ARM_20_Service.VALUES_FLAG_DB)l; //if (!Enum.IsDefined(typeof(VALUES_FLAG_DB), flag)) return l; return(FlagToCell(flag, cell)); }) .Case((IEnumerable enumerable) => { //var sb = new StringBuilder(); //foreach (var v in (IEnumerable)value) //{ // sb.Append(v).Append("\n"); //} //return sb.ToString(); return(string.Empty); }) .Case((ID_TypeHierarchy id) => { string un; if (id.ID > 0) { un = id.ID.ToString(); } else { un = id.StringId; } var hierObject = HierarchyObjectHelper.ToHierarchyObject(un, id.TypeHierarchy); if (hierObject != null) { return(hierObject.Name); } return(string.Empty); }) .Case((ObjectIdCollection ids) => { var result = new StringBuilder(); foreach (var id in ids.Source) { var hierObject = HierarchyObjectHelper.ToHierarchyObject(id.ID, id.TypeHierarchy); if (hierObject != null) { result.Append(hierObject.Name).Append(" ; "); } } return(result.ToString()); }) //.Case((ArchTechValue archTech) => //{ // double v = archTech.F_VALUE * 1000; // if (measured != null && measured.UseBindedConverter) // { // v = archTech.F_VALUE / (double)measured.SelectedUnitDigit; // } // else // { // v = archTech.F_VALUE; // } // if ((v % 1) != 0) // { // cell.CellFormat.FormatString = CommonEx.ExcelformatString; // } // else // { // cell.CellFormat.FormatString = _intFormatted; // } // Color color; // if (archTech.F_FLAG.HasFlag(EnumArchTechStatus.DataNotComplete) || // (archTech.F_FLAG.HasFlag(EnumArchTechStatus.NotCorrect))) // color = Color.IndianRed; // else if (archTech.F_FLAG.HasFlag(EnumArchTechStatus.DataNotFull)) // color = Color.LightGray; // else // color = Color.LightGreen; // cell.CellFormat.Alignment = HorizontalCellAlignment.Right; // cell.CellFormat.Fill = new CellFillPattern(new WorkbookColorInfo(color), new WorkbookColorInfo(color), FillPatternStyle.Solid); // return v; //}) .Case((long l) => { return(l); }); cell.Value = @switch.Switch(value); }