public Inventory(int ID, Enums.Entity_Type Entity_Type, int Container_ID, int Capacity) { NewInventory(ID, Entity_Type, Container_ID, Capacity); }
public MetaDataToEntity(int ID, Enums.Entity_Type Entity_Type, string MetaData_Key, string Value) { NewMetaDataToEntity(ID, Entity_Type, MetaData_Key, Value); }
public void Change(Enums.Suit cardSuit, Enums.Number cardNumber) { suit = cardSuit; number = cardNumber; Refresh(); }
public override Action_Base CreateNewAction(Enums.ActionType _type, GameObject _object) { switch (_type) { case Enums.ActionType.action_click: switch(_object.tag) { case "attackButton": return new Action_ChangeState(Enums.GameStates.gamestate_AimAttack); break; case "buildButton": if (_object.GetComponent<CanBuildTurret>() != null) { return new Action_Build(Enums.EntityTypes.turret); } else if (_object.GetComponent<CanBuildCrystal>() != null) { return new Action_Build(Enums.EntityTypes.crystal); } break; } break; case Enums.ActionType.action_backUp: return new Action_ChangeState(Enums.GameStates.gamestate_waitingForCommand); break; } return null; }
/// <summary> /// ルームCP内BattleState要素変更メソッド /// <para> 引数に設定された内容でBattleStateの値を更新する。</para> /// <para> また、本BattleStateの更新はマスタークライアント側が行う。</para> /// </summary> /// <param name="newValue">更新する新しいBattleStateの値</param> public void SetBattleStateInRoomCP(Enums.BattleState newValue) { // マスタークライアントでない者が設定しようとした場合は抜ける if (!PhotonNetwork.isMasterClient) return; roomCP["BS"] = newValue; }
public double this[Enums.Velocity index] { get { switch (index) { case Enums.Velocity.MeterPerSecond: return value; case Enums.Velocity.KilometerPerHour: return value*Constants.Hour/Constants.Kilometer; case Enums.Velocity.Knots: return value*Constants.Hour/Constants.NMile; default: return 0; } } set { switch (index) { case Enums.Velocity.MeterPerSecond: this.value = value; break; case Enums.Velocity.KilometerPerHour: this.value = value*Constants.Kilometer/Constants.Hour; break; case Enums.Velocity.Knots: this.value = value*Constants.NMile/Constants.Hour; break; default: break; } } }
public static string MesFechaString(Enums.Meses mes) { switch (mes) { case Enums.Meses.Enero: return Properties.Resources.rxEnero; case Enums.Meses.Febrero: return Properties.Resources.rxFebrero; case Enums.Meses.Marzo: return Properties.Resources.rxMarzo; case Enums.Meses.Abril: return Properties.Resources.rxAbril; case Enums.Meses.Mayo: return Properties.Resources.rxMayo; case Enums.Meses.Junio: return Properties.Resources.rxJunio; case Enums.Meses.Julio: return Properties.Resources.rxJulio; case Enums.Meses.Agosto: return Properties.Resources.rxAgosto; case Enums.Meses.Setiembre: return Properties.Resources.rxSetiembre; case Enums.Meses.Octubre: return Properties.Resources.rxOctubre; case Enums.Meses.Noviembre: return Properties.Resources.rxNoviembre; case Enums.Meses.Diciembre: return Properties.Resources.rxDiciembre; } return string.Empty; }
//Change the game state (occurs on next frame) public void ChangeGameState(Enums.GameStateNames nextState) { if (!m_gameStateDictionary.ContainsKey(nextState)) return; m_nextGameStateIndex = nextState; }
public static bool InvalidColumnValue( object fieldValue, Enums.Operator op, string valueToCompare, Type fieldValueType) { return ConditionEvaluator.MatchItemValueBasedOnOperatorAndValueType( op, valueToCompare, fieldValue, fieldValueType); }
public static bool InvalidLengthValue(int length, Enums.Operator op, string lengthToCompare) { int intlengthToCompare; if (int.TryParse(lengthToCompare, out intlengthToCompare)) { switch (op) { case Enums.Operator.Equal: return length == intlengthToCompare; case Enums.Operator.NotEqual: return length != intlengthToCompare; ; case Enums.Operator.GreaterThan: return length > intlengthToCompare; case Enums.Operator.LessThan: return length < intlengthToCompare; default: return false; } } else { return true; } }
public double this[Enums.Time index] { get { switch (index) { case Enums.Time.Second: return value; case Enums.Time.Minutes: return value/Constants.Minutes; case Enums.Time.Hour: return value/Constants.Hour; default: return 0; } } set { switch (index) { case Enums.Time.Second: this.value = value; break; case Enums.Time.Minutes: this.value = value*Constants.Minutes; break; case Enums.Time.Hour: this.value = value*Constants.Hour; break; default: break; } } }
//заполнение параметров контейнера protected ContainersCore(Enums.ContainerType containerType, int id, double area, double dencity) { this.containerType = containerType; this.area = area; this.dencity = dencity; this.id = id; }
//=================================================== // PUBLIC METHODS //=================================================== /// <summary> /// Creates a turret. /// </summary> /// <param name="turretType">Type of the turret.</param> /// <param name="position">The position.</param> public void CreateTurret( Enums.TurretType turretType, Vector3 position ) { GameObject tempGO = null; switch( turretType ) { case Enums.TurretType.Type_A: tempGO = turretPrefabA; break; case Enums.TurretType.Type_B: tempGO = turretPrefabB; break; case Enums.TurretType.Type_C: tempGO = turretPrefabC; break; case Enums.TurretType.Type_D: tempGO = turretPrefabD; break; default: tempGO = turretPrefabA; break; } GameObject turretGO = Instantiate( tempGO, position, Quaternion.identity ) as GameObject; turretGO.transform.SetParent( turretContainer ); turrets.Add( turretGO ); }
public ReturnObject(Enums.Return_Status Return_Status, string Friendly_Message, string Technical_Message, object Return_Object) { NewReturnObject(Return_Status, Friendly_Message, Technical_Message, Return_Object, string.Empty); }
//=================================================== // PRIVATE METHODS //=================================================== /// <summary> /// Dispatches the turret type. /// </summary> /// <param name="turretType">Type of the turret.</param> private void TurretTypeSelected( Enums.TurretType turretType ) { if( EventBuy != null ) { EventBuy( turretType, position ); } OnClose(); }
public void ShowMsg(Enums.LogType type, string txt) { switch (type) { case Enums.LogType.Login: Dispatcher.Invoke(new Action(() => listBox1.Items.Add(txt))); break; case Enums.LogType.Logout: Dispatcher.Invoke(new Action(() => listBox1.Items.Remove(txt))); break; default: Brush brush = Brushes.Black; if (type == Enums.LogType.Start) { brush = Brushes.Red; } else if (type == Enums.LogType.Error) { brush = Brushes.Blue; } Dispatcher.Invoke(new Action(() => { var p = new Paragraph(); // Paragraph 类似于 html 的 P 标签 var r = new Run(txt); // Run 是一个 Inline 的标签 p.Inlines.Add(r); p.Foreground = brush;//设置字体颜色 // 除了设置属性,事件也可以在这里设置 Doc.Blocks.Add(p); richTextBox1.Document = Doc; })); break; } }
public Enums.WallOrientation FindOppositeWall(Enums.WallOrientation wall) { if (wall == Enums.WallOrientation.North) return Enums.WallOrientation.South; if (wall == Enums.WallOrientation.East) return Enums.WallOrientation.West; if (wall == Enums.WallOrientation.South) return Enums.WallOrientation.North; return Enums.WallOrientation.East; }
public Enums.PlayerState update(bool hit, bool animDone, Enums.Direction direction, Enums.CardTypes type, bool handEmpty, int playerNumber) { switch (currState) { case Enums.PlayerState.Idle: currState = Idle(hit, animDone, direction, type, handEmpty, playerNumber); break; case Enums.PlayerState.MoveBegining: currState = MoveBegining(hit, animDone, direction, type, handEmpty, playerNumber); break; case Enums.PlayerState.MoveEnding: currState = MoveEnding(hit, animDone, direction, type, handEmpty, playerNumber); break; case Enums.PlayerState.Hit: currState = Hit(hit, animDone, direction, type, handEmpty, playerNumber); break; case Enums.PlayerState.Dead: currState = Dead(hit, animDone, direction, type, handEmpty, playerNumber); break; case Enums.PlayerState.BasicAttack: currState = BasicAttack(hit, animDone, direction, type, handEmpty, playerNumber); break; case Enums.PlayerState.HoriSwingMid: currState = HoriSwingMid(hit, animDone, direction, type, handEmpty, playerNumber); break; case Enums.PlayerState.VertiSwingHeavy: currState = VertiSwingHeavy(hit, animDone, direction, type, handEmpty, playerNumber); break; case Enums.PlayerState.ThrowLight: currState = ThrowLight(hit, animDone, direction, type, handEmpty, playerNumber); break; case Enums.PlayerState.ThrowMid: currState = ThrowMid(hit, animDone, direction, type, handEmpty, playerNumber); break; case Enums.PlayerState.Shoot: currState = Shoot(hit, animDone, direction, type, handEmpty, playerNumber); break; case Enums.PlayerState.ChiAttack: currState = ChiAttack(hit, animDone, direction, type, handEmpty, playerNumber); break; case Enums.PlayerState.ChiStationary: currState = ChiStationary(hit, animDone, direction, type, handEmpty, playerNumber); break; case Enums.PlayerState.TauntGokuStretch: currState = TauntGokuStretch(hit, animDone, direction, type, handEmpty, playerNumber); break; case Enums.PlayerState.TauntPointPoint: currState = TauntPointPoint(hit, animDone, direction, type, handEmpty, playerNumber); break; case Enums.PlayerState.TauntThumbsDown: currState = TauntThumbsDown(hit, animDone, direction, type, handEmpty, playerNumber); break; case Enums.PlayerState.TauntWrasslemania: currState = TauntWrasslemania(hit, animDone, direction, type, handEmpty, playerNumber); break; case Enums.PlayerState.TauntYaMoves: currState = TauntYaMoves(hit, animDone, direction, type, handEmpty, playerNumber); break; } return currState; }
public AssemblyFile(ISchemaBase parent, AssemblyFile assemblyFile, Enums.ObjectStatusType status) : base(parent, Enums.ObjectType.AssemblyFile) { this.Name = assemblyFile.Name; this.content = assemblyFile.content; this.Status = status; }
public static bool CheckPrivilege(Page page, Enums.ModuleKey moduleKey, Enums.Privilege enPriv)//,object privilegeTable { DataTable dt = page.Session["AdminFunction"] as DataTable; try { //if ((page.Session["Users"] as NT.Entities.User).IsSuperManager == "yes")//如果是超级管理员 // return true; } catch { page.Response.Write("<script>parent.location='" + page.ResolveUrl("~/Admin/Login.aspx") + "'</script>"); return false; } if (dt.Rows.Count == 0) { page.Response.Redirect("~/Admin/NoRights.aspx"); return false; } DataRow[] rows = dt.Select(string.Format("ModuleKey='{0}' and PrivilegeId={1}",moduleKey.ToString(),(int)enPriv)); if (rows != null && rows.Length > 0) { return true; } else { page.Response.Redirect("~/Admin/NoRights.aspx"); return false; } }
internal List<IDepotItem> GetDepotItemsForCarrier(Enums.CarrierType carrierId) { List<IDepotItem> depot_matrix = new List<IDepotItem>(); // Only valid for TOLL at this point if (carrierId == Enums.CarrierType.TOLL) { connection.open(); depot_matrix = new List<IDepotItem>(); if (connection.open()) { string query = "SELECT suburb, state, depot, postcode, depot_code FROM ps_toll_depotcodes;"; IDataReader dataReader = connection.getDataReader(query); while (dataReader.Read()) { IDepotItem item = new TOLLDepotItem(); item.Depot = dataReader["depot"].ToString().ToUpper().Trim(); item.Postcode = Tools.normalisePostcode(dataReader["postcode"].ToString().Trim()); item.State = dataReader["state"].ToString().ToUpper().Trim(); item.Suburb = dataReader["suburb"].ToString().ToUpper().Trim(); item.DepotCode = dataReader["depot_code"].ToString().ToUpper().Trim(); depot_matrix.Add(item); } dataReader.Close(); } connection.close(); } return depot_matrix; }
public Resources_Building(string id, string name, string image, Enums.BuildingType type, int money, int income, int expenses, int rent, int payment, Enums.DayOfTheWeek day, Resources_InventoryShop inventory) : base(id, name, image, money, income, expenses) { _type = type; _payment = payment; _day = day; _type = type; _inventory = inventory; Manager_Resources.NewBuilding(this); }
//=================================================== // PRIVATE METHODS //=================================================== //=================================================== // EVENTS METHODS //=================================================== /// <summary> /// Called when [buy button is clicked]. /// </summary> /// <param name="turretType">Type of the turret.</param> /// <param name="position">The position.</param> private void OnBuy( Enums.TurretType turretType, Vector3 position ) { // reduce the money if( EventBuyTurret != null ) { EventBuyTurret( turretType, position ); } }
public double this[Enums.Length index] { get { switch (index) { case Enums.Length.Meter: return value; case Enums.Length.Kilometer: return value/Constants.Kilometer; case Enums.Length.NauticalMile: return value/Constants.NMile; default: return 0; } } set { switch (index) { case Enums.Length.Meter: this.value = value; break; case Enums.Length.Kilometer: this.value = value*Constants.Kilometer; break; case Enums.Length.NauticalMile: this.value = value*Constants.NMile; break; default: break; } } }
public override Action_Base CreateNewAction(Enums.ActionType _type, GameObject _object) { switch(_type) { case Enums.ActionType.action_right: if (_object.GetComponent<GroundMovement>() != null || _object.GetComponent<FlightMovement>() != null) { return new Action_Move(_type, _object); } break; case Enums.ActionType.action_left: if (_object.GetComponent<GroundMovement>() != null || _object.GetComponent<FlightMovement>() != null) { return new Action_Move(_type, _object); } break; case Enums.ActionType.action_up: if (_object.GetComponent<GroundMovement>() != null || _object.GetComponent<FlightMovement>() != null) { return new Action_Move(_type, _object); } break; case Enums.ActionType.action_down: if (_object.GetComponent<GroundMovement>() != null || _object.GetComponent<FlightMovement>() != null) { return new Action_Move(_type, _object); } break; case Enums.ActionType.action_openActMenu: return new Action_ChangeState(Enums.GameStates.gamestate_SelectActionMenu); break; } return null; }
/// <summary> /// Initializes a new instance of the <see cref="TabPage" /> class. /// </summary> /// <param name="tabName">Name of the tab.</param> /// <param name="locatorString">The locator string.</param> /// <param name="pageElement">The page element.</param> /// <param name="locator">The locator.</param> public TabPage(string tabName, string locatorString, string pageElement, Enums.Locator locator) { this.TabName = tabName; this.LocatorString = locatorString; this.PageElement = pageElement; this.Locator = locator; }
public void Move(Enums.ActionType _type) { int _oldX; int _oldY; switch(_type) { case Enums.ActionType.action_right: _oldX = storage.xPos; _oldY = storage.yPos; storage.GameWorld.RemoveObjectFromTile(_oldX, _oldY, this.gameObject); storage.xPos = _oldX + 1; storage.yPos = storage.GameWorld.GetColumnHeight(storage.xPos); storage.GameWorld.AddObjectToTile(storage.xPos, storage.yPos, this.gameObject); this.gameObject.transform.Translate(1,storage.yPos - _oldY,0); break; case Enums.ActionType.action_left: _oldX = storage.xPos; _oldY = storage.yPos; storage.GameWorld.RemoveObjectFromTile(_oldX, _oldY, this.gameObject); storage.xPos = _oldX - 1; storage.yPos = storage.GameWorld.GetColumnHeight(storage.xPos); storage.GameWorld.AddObjectToTile(storage.xPos, storage.yPos, this.gameObject); this.gameObject.transform.Translate(-1,storage.yPos - _oldY,0); break; } }
public Log GetNextPrevImage(int? id, Enums.Arrow? arrow, string person) { using (var unitOfWork = new UnitOfWork()) { var repository = new LogRepository(unitOfWork.Session); if (id == null) { return repository.Query(r => r.PersonName == person).FirstOrDefault(); } else { switch (arrow) { case Enums.Arrow.Left: return repository.Query(r => r.PersonName == person && r.Id < id).LastOrDefault(); break; case Enums.Arrow.Right: return repository.Query(r => r.PersonName == person && r.Id > id).FirstOrDefault(); break; default: break; } } return repository.Query(r => r.PersonName == person).First(); } }
public ReturnObject(Enums.Return_Status Return_Status, string Friendly_Message, string Technical_Message, object Return_Object, string ExtraDebugInfo) { NewReturnObject(Return_Status, Friendly_Message, Technical_Message, Return_Object, ExtraDebugInfo); }
private Enums.PlayerState ChiAttack(bool hit, bool animDone, Enums.Direction direction, Enums.CardTypes type, bool handEmpty, int playerNumber) { if (hit) return Enums.PlayerState.Hit; if (animDone) return Enums.PlayerState.Idle; return Enums.PlayerState.ChiAttack; }
public void Setup() { _ = Enum.GetNames(typeof(Fruits)); _ = Enums.GetValues <Fruits>(); _ = _FastEnum.GetValues <Fruits>(); }
static DigestUtilities() { // Signal to obfuscation tools not to change enum constants ((DigestAlgorithm)Enums.GetArbitraryValue(typeof(DigestAlgorithm))).ToString(); algorithms[PkcsObjectIdentifiers.MD2.Id] = "MD2"; algorithms[PkcsObjectIdentifiers.MD4.Id] = "MD4"; algorithms[PkcsObjectIdentifiers.MD5.Id] = "MD5"; algorithms["SHA1"] = "SHA-1"; algorithms[OiwObjectIdentifiers.IdSha1.Id] = "SHA-1"; algorithms[PkcsObjectIdentifiers.IdHmacWithSha1.Id] = "SHA-1"; algorithms[MiscObjectIdentifiers.HMAC_SHA1.Id] = "SHA-1"; algorithms["SHA224"] = "SHA-224"; algorithms[NistObjectIdentifiers.IdSha224.Id] = "SHA-224"; algorithms[PkcsObjectIdentifiers.IdHmacWithSha224.Id] = "SHA-224"; algorithms["SHA256"] = "SHA-256"; algorithms[NistObjectIdentifiers.IdSha256.Id] = "SHA-256"; algorithms[PkcsObjectIdentifiers.IdHmacWithSha256.Id] = "SHA-256"; algorithms["SHA384"] = "SHA-384"; algorithms[NistObjectIdentifiers.IdSha384.Id] = "SHA-384"; algorithms[PkcsObjectIdentifiers.IdHmacWithSha384.Id] = "SHA-384"; algorithms["SHA512"] = "SHA-512"; algorithms[NistObjectIdentifiers.IdSha512.Id] = "SHA-512"; algorithms[PkcsObjectIdentifiers.IdHmacWithSha512.Id] = "SHA-512"; algorithms["SHA512/224"] = "SHA-512/224"; algorithms["SHA512(224)"] = "SHA-512/224"; algorithms["SHA-512(224)"] = "SHA-512/224"; algorithms[NistObjectIdentifiers.IdSha512_224.Id] = "SHA-512/224"; algorithms["SHA512/256"] = "SHA-512/256"; algorithms["SHA512(256)"] = "SHA-512/256"; algorithms["SHA-512(256)"] = "SHA-512/256"; algorithms[NistObjectIdentifiers.IdSha512_256.Id] = "SHA-512/256"; algorithms["RIPEMD-128"] = "RIPEMD128"; algorithms[TeleTrusTObjectIdentifiers.RipeMD128.Id] = "RIPEMD128"; algorithms["RIPEMD-160"] = "RIPEMD160"; algorithms[TeleTrusTObjectIdentifiers.RipeMD160.Id] = "RIPEMD160"; algorithms["RIPEMD-256"] = "RIPEMD256"; algorithms[TeleTrusTObjectIdentifiers.RipeMD256.Id] = "RIPEMD256"; algorithms["RIPEMD-320"] = "RIPEMD320"; // algorithms[TeleTrusTObjectIdentifiers.RipeMD320.Id] = "RIPEMD320"; algorithms[CryptoProObjectIdentifiers.GostR3411.Id] = "GOST3411"; algorithms["KECCAK224"] = "KECCAK-224"; algorithms["KECCAK256"] = "KECCAK-256"; algorithms["KECCAK288"] = "KECCAK-288"; algorithms["KECCAK384"] = "KECCAK-384"; algorithms["KECCAK512"] = "KECCAK-512"; algorithms[NistObjectIdentifiers.IdSha3_224.Id] = "SHA3-224"; algorithms[NistObjectIdentifiers.IdHMacWithSha3_224.Id] = "SHA3-224"; algorithms[NistObjectIdentifiers.IdSha3_256.Id] = "SHA3-256"; algorithms[NistObjectIdentifiers.IdHMacWithSha3_256.Id] = "SHA3-256"; algorithms[NistObjectIdentifiers.IdSha3_384.Id] = "SHA3-384"; algorithms[NistObjectIdentifiers.IdHMacWithSha3_384.Id] = "SHA3-384"; algorithms[NistObjectIdentifiers.IdSha3_512.Id] = "SHA3-512"; algorithms[NistObjectIdentifiers.IdHMacWithSha3_512.Id] = "SHA3-512"; algorithms["SHAKE128"] = "SHAKE128-256"; algorithms[NistObjectIdentifiers.IdShake128.Id] = "SHAKE128-256"; algorithms["SHAKE256"] = "SHAKE256-512"; algorithms[NistObjectIdentifiers.IdShake256.Id] = "SHAKE256-512"; algorithms[GMObjectIdentifiers.sm3.Id] = "SM3"; algorithms[MiscObjectIdentifiers.id_blake2b160.Id] = "BLAKE2B-160"; algorithms[MiscObjectIdentifiers.id_blake2b256.Id] = "BLAKE2B-256"; algorithms[MiscObjectIdentifiers.id_blake2b384.Id] = "BLAKE2B-384"; algorithms[MiscObjectIdentifiers.id_blake2b512.Id] = "BLAKE2B-512"; algorithms[MiscObjectIdentifiers.id_blake2s128.Id] = "BLAKE2S-128"; algorithms[MiscObjectIdentifiers.id_blake2s160.Id] = "BLAKE2S-160"; algorithms[MiscObjectIdentifiers.id_blake2s224.Id] = "BLAKE2S-224"; algorithms[MiscObjectIdentifiers.id_blake2s256.Id] = "BLAKE2S-256"; algorithms[RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256.Id] = "GOST3411-2012-256"; algorithms[RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512.Id] = "GOST3411-2012-512"; algorithms[UAObjectIdentifiers.dstu7564digest_256.Id] = "DSTU7564-256"; algorithms[UAObjectIdentifiers.dstu7564digest_384.Id] = "DSTU7564-384"; algorithms[UAObjectIdentifiers.dstu7564digest_512.Id] = "DSTU7564-512"; oids["MD2"] = PkcsObjectIdentifiers.MD2; oids["MD4"] = PkcsObjectIdentifiers.MD4; oids["MD5"] = PkcsObjectIdentifiers.MD5; oids["SHA-1"] = OiwObjectIdentifiers.IdSha1; oids["SHA-224"] = NistObjectIdentifiers.IdSha224; oids["SHA-256"] = NistObjectIdentifiers.IdSha256; oids["SHA-384"] = NistObjectIdentifiers.IdSha384; oids["SHA-512"] = NistObjectIdentifiers.IdSha512; oids["SHA-512/224"] = NistObjectIdentifiers.IdSha512_224; oids["SHA-512/256"] = NistObjectIdentifiers.IdSha512_256; oids["SHA3-224"] = NistObjectIdentifiers.IdSha3_224; oids["SHA3-256"] = NistObjectIdentifiers.IdSha3_256; oids["SHA3-384"] = NistObjectIdentifiers.IdSha3_384; oids["SHA3-512"] = NistObjectIdentifiers.IdSha3_512; oids["SHAKE128-256"] = NistObjectIdentifiers.IdShake128; oids["SHAKE256-512"] = NistObjectIdentifiers.IdShake256; oids["RIPEMD128"] = TeleTrusTObjectIdentifiers.RipeMD128; oids["RIPEMD160"] = TeleTrusTObjectIdentifiers.RipeMD160; oids["RIPEMD256"] = TeleTrusTObjectIdentifiers.RipeMD256; oids["GOST3411"] = CryptoProObjectIdentifiers.GostR3411; oids["SM3"] = GMObjectIdentifiers.sm3; oids["BLAKE2B-160"] = MiscObjectIdentifiers.id_blake2b160; oids["BLAKE2B-256"] = MiscObjectIdentifiers.id_blake2b256; oids["BLAKE2B-384"] = MiscObjectIdentifiers.id_blake2b384; oids["BLAKE2B-512"] = MiscObjectIdentifiers.id_blake2b512; oids["BLAKE2S-128"] = MiscObjectIdentifiers.id_blake2s128; oids["BLAKE2S-160"] = MiscObjectIdentifiers.id_blake2s160; oids["BLAKE2S-224"] = MiscObjectIdentifiers.id_blake2s224; oids["BLAKE2S-256"] = MiscObjectIdentifiers.id_blake2s256; oids["GOST3411-2012-256"] = RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256; oids["GOST3411-2012-512"] = RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512; oids["DSTU7564-256"] = UAObjectIdentifiers.dstu7564digest_256; oids["DSTU7564-384"] = UAObjectIdentifiers.dstu7564digest_384; oids["DSTU7564-512"] = UAObjectIdentifiers.dstu7564digest_512; }
/// <summary> /// Validate function for all CSSPWQInputParamService commands /// </summary> /// <param name="validationContext">System.ComponentModel.DataAnnotations.ValidationContext (Describes the context in which a validation check is performed.)</param> /// <param name="actionDBType">[ActionDBTypeEnum] (CSSPEnums.ActionDBTypeEnum.html) action type to validate</param> /// <returns>IEnumerable of ValidationResult (Where ValidationResult is a container for the results of a validation request.)</returns> private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType) { string retStr = ""; Enums enums = new Enums(LanguageRequest); CSSPWQInputParam cSSPWQInputParam = validationContext.ObjectInstance as CSSPWQInputParam; cSSPWQInputParam.HasErrors = false; retStr = enums.EnumTypeOK(typeof(CSSPWQInputTypeEnum), (int?)cSSPWQInputParam.CSSPWQInputType); if (!string.IsNullOrWhiteSpace(retStr)) { cSSPWQInputParam.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "CSSPWQInputType"), new[] { "CSSPWQInputType" })); } if (string.IsNullOrWhiteSpace(cSSPWQInputParam.Name)) { cSSPWQInputParam.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Name"), new[] { "Name" })); } if (!string.IsNullOrWhiteSpace(cSSPWQInputParam.Name) && (cSSPWQInputParam.Name.Length < 1 || cSSPWQInputParam.Name.Length > 200)) { cSSPWQInputParam.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Name", "1", "200"), new[] { "Name" })); } if (cSSPWQInputParam.TVItemID < 1) { cSSPWQInputParam.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MinValueIs_, "TVItemID", "1"), new[] { "TVItemID" })); } if (!string.IsNullOrWhiteSpace(cSSPWQInputParam.CSSPWQInputTypeText) && cSSPWQInputParam.CSSPWQInputTypeText.Length > 100) { cSSPWQInputParam.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "CSSPWQInputTypeText", "100"), new[] { "CSSPWQInputTypeText" })); } //CSSPError: Type not implemented [sidList] of type [List`1] //sidList has no StringLength Attribute //CSSPError: Type not implemented [MWQMSiteList] of type [List`1] //MWQMSiteList has no StringLength Attribute //CSSPError: Type not implemented [MWQMSiteTVItemIDList] of type [List`1] //MWQMSiteTVItemIDList has no Range Attribute //CSSPError: Type not implemented [DailyDuplicateMWQMSiteList] of type [List`1] //DailyDuplicateMWQMSiteList has no StringLength Attribute //CSSPError: Type not implemented [DailyDuplicateMWQMSiteTVItemIDList] of type [List`1] //DailyDuplicateMWQMSiteTVItemIDList has no Range Attribute //CSSPError: Type not implemented [InfrastructureList] of type [List`1] //InfrastructureList has no StringLength Attribute //CSSPError: Type not implemented [InfrastructureTVItemIDList] of type [List`1] //InfrastructureTVItemIDList has no Range Attribute retStr = ""; // added to stop compiling CSSPError if (retStr != "") // will never be true { cSSPWQInputParam.HasErrors = true; yield return(new ValidationResult("AAA", new[] { "AAA" })); } }
private void _vista_UsuarioDeseaObtenerManifiestoDeCarga(object sender, ManifiestoArgumento e) { try { _vista.ManifiestoDeCargaEncabezado = ManifiestoCargaServicio.ObtenerManifiestoDeCarga(e); _vista.DetallesEliminados = new List <int?>(); _vista.EstaModificando = _vista.ManifiestoDeCargaEncabezado.STATUS != Enums.GetStringValue(Estados.EstadosManifiesto.Cancelado) && _vista.ManifiestoDeCargaEncabezado.STATUS != Enums.GetStringValue(Estados.EstadosManifiesto.EnPicking); } catch (Exception ex) { InteraccionConUsuarioServicio.Mensaje(ex.Message + ex.StackTrace); } }
static CipherUtilities() { // Signal to obfuscation tools not to change enum constants ((CipherAlgorithm)Enums.GetArbitraryValue(typeof(CipherAlgorithm))).ToString(); ((CipherMode)Enums.GetArbitraryValue(typeof(CipherMode))).ToString(); ((CipherPadding)Enums.GetArbitraryValue(typeof(CipherPadding))).ToString(); // TODO Flesh out the list of aliases algorithms[NistObjectIdentifiers.IdAes128Ecb.Id] = "AES/ECB/PKCS7PADDING"; algorithms[NistObjectIdentifiers.IdAes192Ecb.Id] = "AES/ECB/PKCS7PADDING"; algorithms[NistObjectIdentifiers.IdAes256Ecb.Id] = "AES/ECB/PKCS7PADDING"; algorithms["AES//PKCS7"] = "AES/ECB/PKCS7PADDING"; algorithms["AES//PKCS7PADDING"] = "AES/ECB/PKCS7PADDING"; algorithms["AES//PKCS5"] = "AES/ECB/PKCS7PADDING"; algorithms["AES//PKCS5PADDING"] = "AES/ECB/PKCS7PADDING"; algorithms[NistObjectIdentifiers.IdAes128Cbc.Id] = "AES/CBC/PKCS7PADDING"; algorithms[NistObjectIdentifiers.IdAes192Cbc.Id] = "AES/CBC/PKCS7PADDING"; algorithms[NistObjectIdentifiers.IdAes256Cbc.Id] = "AES/CBC/PKCS7PADDING"; algorithms[NistObjectIdentifiers.IdAes128Ofb.Id] = "AES/OFB/NOPADDING"; algorithms[NistObjectIdentifiers.IdAes192Ofb.Id] = "AES/OFB/NOPADDING"; algorithms[NistObjectIdentifiers.IdAes256Ofb.Id] = "AES/OFB/NOPADDING"; algorithms[NistObjectIdentifiers.IdAes128Cfb.Id] = "AES/CFB/NOPADDING"; algorithms[NistObjectIdentifiers.IdAes192Cfb.Id] = "AES/CFB/NOPADDING"; algorithms[NistObjectIdentifiers.IdAes256Cfb.Id] = "AES/CFB/NOPADDING"; algorithms["RSA/ECB/PKCS1"] = "RSA//PKCS1PADDING"; algorithms["RSA/ECB/PKCS1PADDING"] = "RSA//PKCS1PADDING"; algorithms[PkcsObjectIdentifiers.RsaEncryption.Id] = "RSA//PKCS1PADDING"; algorithms[PkcsObjectIdentifiers.IdRsaesOaep.Id] = "RSA//OAEPPADDING"; algorithms[OiwObjectIdentifiers.DesCbc.Id] = "DES/CBC"; algorithms[OiwObjectIdentifiers.DesCfb.Id] = "DES/CFB"; algorithms[OiwObjectIdentifiers.DesEcb.Id] = "DES/ECB"; algorithms[OiwObjectIdentifiers.DesOfb.Id] = "DES/OFB"; algorithms[OiwObjectIdentifiers.DesEde.Id] = "DESEDE"; algorithms["TDEA"] = "DESEDE"; algorithms[PkcsObjectIdentifiers.DesEde3Cbc.Id] = "DESEDE/CBC"; algorithms[PkcsObjectIdentifiers.RC2Cbc.Id] = "RC2/CBC"; algorithms["1.3.6.1.4.1.188.7.1.1.2"] = "IDEA/CBC"; algorithms["1.2.840.113533.7.66.10"] = "CAST5/CBC"; algorithms["RC4"] = "ARC4"; algorithms["ARCFOUR"] = "ARC4"; algorithms["1.2.840.113549.3.4"] = "ARC4"; algorithms["PBEWITHSHA1AND128BITRC4"] = "PBEWITHSHAAND128BITRC4"; algorithms[PkcsObjectIdentifiers.PbeWithShaAnd128BitRC4.Id] = "PBEWITHSHAAND128BITRC4"; algorithms["PBEWITHSHA1AND40BITRC4"] = "PBEWITHSHAAND40BITRC4"; algorithms[PkcsObjectIdentifiers.PbeWithShaAnd40BitRC4.Id] = "PBEWITHSHAAND40BITRC4"; algorithms["PBEWITHSHA1ANDDES"] = "PBEWITHSHA1ANDDES-CBC"; algorithms[PkcsObjectIdentifiers.PbeWithSha1AndDesCbc.Id] = "PBEWITHSHA1ANDDES-CBC"; algorithms["PBEWITHSHA1ANDRC2"] = "PBEWITHSHA1ANDRC2-CBC"; algorithms[PkcsObjectIdentifiers.PbeWithSha1AndRC2Cbc.Id] = "PBEWITHSHA1ANDRC2-CBC"; algorithms["PBEWITHSHA1AND3-KEYTRIPLEDES-CBC"] = "PBEWITHSHAAND3-KEYTRIPLEDES-CBC"; algorithms["PBEWITHSHAAND3KEYTRIPLEDES"] = "PBEWITHSHAAND3-KEYTRIPLEDES-CBC"; algorithms[PkcsObjectIdentifiers.PbeWithShaAnd3KeyTripleDesCbc.Id] = "PBEWITHSHAAND3-KEYTRIPLEDES-CBC"; algorithms["PBEWITHSHA1ANDDESEDE"] = "PBEWITHSHAAND3-KEYTRIPLEDES-CBC"; algorithms["PBEWITHSHA1AND2-KEYTRIPLEDES-CBC"] = "PBEWITHSHAAND2-KEYTRIPLEDES-CBC"; algorithms[PkcsObjectIdentifiers.PbeWithShaAnd2KeyTripleDesCbc.Id] = "PBEWITHSHAAND2-KEYTRIPLEDES-CBC"; algorithms["PBEWITHSHA1AND128BITRC2-CBC"] = "PBEWITHSHAAND128BITRC2-CBC"; algorithms[PkcsObjectIdentifiers.PbeWithShaAnd128BitRC2Cbc.Id] = "PBEWITHSHAAND128BITRC2-CBC"; algorithms["PBEWITHSHA1AND40BITRC2-CBC"] = "PBEWITHSHAAND40BITRC2-CBC"; algorithms[PkcsObjectIdentifiers.PbewithShaAnd40BitRC2Cbc.Id] = "PBEWITHSHAAND40BITRC2-CBC"; algorithms["PBEWITHSHA1AND128BITAES-CBC-BC"] = "PBEWITHSHAAND128BITAES-CBC-BC"; algorithms["PBEWITHSHA-1AND128BITAES-CBC-BC"] = "PBEWITHSHAAND128BITAES-CBC-BC"; algorithms["PBEWITHSHA1AND192BITAES-CBC-BC"] = "PBEWITHSHAAND192BITAES-CBC-BC"; algorithms["PBEWITHSHA-1AND192BITAES-CBC-BC"] = "PBEWITHSHAAND192BITAES-CBC-BC"; algorithms["PBEWITHSHA1AND256BITAES-CBC-BC"] = "PBEWITHSHAAND256BITAES-CBC-BC"; algorithms["PBEWITHSHA-1AND256BITAES-CBC-BC"] = "PBEWITHSHAAND256BITAES-CBC-BC"; algorithms["PBEWITHSHA-256AND128BITAES-CBC-BC"] = "PBEWITHSHA256AND128BITAES-CBC-BC"; algorithms["PBEWITHSHA-256AND192BITAES-CBC-BC"] = "PBEWITHSHA256AND192BITAES-CBC-BC"; algorithms["PBEWITHSHA-256AND256BITAES-CBC-BC"] = "PBEWITHSHA256AND256BITAES-CBC-BC"; algorithms["GOST"] = "GOST28147"; algorithms["GOST-28147"] = "GOST28147"; algorithms[CryptoProObjectIdentifiers.GostR28147Cbc.Id] = "GOST28147/CBC/PKCS7PADDING"; algorithms["RC5-32"] = "RC5"; algorithms[NttObjectIdentifiers.IdCamellia128Cbc.Id] = "CAMELLIA/CBC/PKCS7PADDING"; algorithms[NttObjectIdentifiers.IdCamellia192Cbc.Id] = "CAMELLIA/CBC/PKCS7PADDING"; algorithms[NttObjectIdentifiers.IdCamellia256Cbc.Id] = "CAMELLIA/CBC/PKCS7PADDING"; algorithms[KisaObjectIdentifiers.IdSeedCbc.Id] = "SEED/CBC/PKCS7PADDING"; algorithms["1.3.6.1.4.1.3029.1.2"] = "BLOWFISH/CBC"; }
public static IBufferedCipher GetCipher( string algorithm) { if (algorithm == null) { throw new ArgumentNullException("algorithm"); } algorithm = Platform.ToUpperInvariant(algorithm); { string aliased = (string)algorithms[algorithm]; if (aliased != null) { algorithm = aliased; } } IBasicAgreement iesAgreement = null; if (algorithm == "IES") { iesAgreement = new DHBasicAgreement(); } else if (algorithm == "ECIES") { iesAgreement = new ECDHBasicAgreement(); } if (iesAgreement != null) { return(new BufferedIesCipher( new IesEngine( iesAgreement, new Kdf2BytesGenerator( new Sha1Digest()), new HMac( new Sha1Digest())))); } if (algorithm.StartsWith("PBE")) { if (algorithm.EndsWith("-CBC")) { if (algorithm == "PBEWITHSHA1ANDDES-CBC") { return(new PaddedBufferedBlockCipher( new CbcBlockCipher(new DesEngine()))); } else if (algorithm == "PBEWITHSHA1ANDRC2-CBC") { return(new PaddedBufferedBlockCipher( new CbcBlockCipher(new RC2Engine()))); } else if (Strings.IsOneOf(algorithm, "PBEWITHSHAAND2-KEYTRIPLEDES-CBC", "PBEWITHSHAAND3-KEYTRIPLEDES-CBC")) { return(new PaddedBufferedBlockCipher( new CbcBlockCipher(new DesEdeEngine()))); } else if (Strings.IsOneOf(algorithm, "PBEWITHSHAAND128BITRC2-CBC", "PBEWITHSHAAND40BITRC2-CBC")) { return(new PaddedBufferedBlockCipher( new CbcBlockCipher(new RC2Engine()))); } } else if (algorithm.EndsWith("-BC") || algorithm.EndsWith("-OPENSSL")) { if (Strings.IsOneOf(algorithm, "PBEWITHSHAAND128BITAES-CBC-BC", "PBEWITHSHAAND192BITAES-CBC-BC", "PBEWITHSHAAND256BITAES-CBC-BC", "PBEWITHSHA256AND128BITAES-CBC-BC", "PBEWITHSHA256AND192BITAES-CBC-BC", "PBEWITHSHA256AND256BITAES-CBC-BC", "PBEWITHMD5AND128BITAES-CBC-OPENSSL", "PBEWITHMD5AND192BITAES-CBC-OPENSSL", "PBEWITHMD5AND256BITAES-CBC-OPENSSL")) { return(new PaddedBufferedBlockCipher( new CbcBlockCipher(new AesFastEngine()))); } } } string[] parts = algorithm.Split('/'); IBlockCipher blockCipher = null; IAsymmetricBlockCipher asymBlockCipher = null; IStreamCipher streamCipher = null; string algorithmName = parts[0]; { string aliased = (string)algorithms[algorithmName]; if (aliased != null) { algorithmName = aliased; } } CipherAlgorithm cipherAlgorithm; try { cipherAlgorithm = (CipherAlgorithm)Enums.GetEnumValue(typeof(CipherAlgorithm), algorithmName); } catch (ArgumentException) { throw new SecurityUtilityException("Cipher " + algorithm + " not recognised."); } switch (cipherAlgorithm) { case CipherAlgorithm.AES: blockCipher = new AesFastEngine(); break; case CipherAlgorithm.ARC4: streamCipher = new RC4Engine(); break; case CipherAlgorithm.BLOWFISH: blockCipher = new BlowfishEngine(); break; case CipherAlgorithm.CAMELLIA: blockCipher = new CamelliaEngine(); break; case CipherAlgorithm.CAST5: blockCipher = new Cast5Engine(); break; case CipherAlgorithm.CAST6: blockCipher = new Cast6Engine(); break; case CipherAlgorithm.DES: blockCipher = new DesEngine(); break; case CipherAlgorithm.DESEDE: blockCipher = new DesEdeEngine(); break; case CipherAlgorithm.ELGAMAL: asymBlockCipher = new ElGamalEngine(); break; case CipherAlgorithm.GOST28147: blockCipher = new Gost28147Engine(); break; case CipherAlgorithm.HC128: streamCipher = new HC128Engine(); break; case CipherAlgorithm.HC256: streamCipher = new HC256Engine(); break; case CipherAlgorithm.IDEA: blockCipher = new IdeaEngine(); break; case CipherAlgorithm.NOEKEON: blockCipher = new NoekeonEngine(); break; case CipherAlgorithm.PBEWITHSHAAND128BITRC4: case CipherAlgorithm.PBEWITHSHAAND40BITRC4: streamCipher = new RC4Engine(); break; case CipherAlgorithm.RC2: blockCipher = new RC2Engine(); break; case CipherAlgorithm.RC5: blockCipher = new RC532Engine(); break; case CipherAlgorithm.RC5_64: blockCipher = new RC564Engine(); break; case CipherAlgorithm.RC6: blockCipher = new RC6Engine(); break; case CipherAlgorithm.RIJNDAEL: blockCipher = new RijndaelEngine(); break; case CipherAlgorithm.RSA: asymBlockCipher = new RsaBlindedEngine(); break; case CipherAlgorithm.SALSA20: streamCipher = new Salsa20Engine(); break; case CipherAlgorithm.SEED: blockCipher = new SeedEngine(); break; case CipherAlgorithm.SERPENT: blockCipher = new SerpentEngine(); break; case CipherAlgorithm.SKIPJACK: blockCipher = new SkipjackEngine(); break; case CipherAlgorithm.TEA: blockCipher = new TeaEngine(); break; case CipherAlgorithm.TWOFISH: blockCipher = new TwofishEngine(); break; case CipherAlgorithm.VMPC: streamCipher = new VmpcEngine(); break; case CipherAlgorithm.VMPC_KSA3: streamCipher = new VmpcKsa3Engine(); break; case CipherAlgorithm.XTEA: blockCipher = new XteaEngine(); break; default: throw new SecurityUtilityException("Cipher " + algorithm + " not recognised."); } if (streamCipher != null) { if (parts.Length > 1) { throw new ArgumentException("Modes and paddings not used for stream ciphers"); } return(new BufferedStreamCipher(streamCipher)); } bool cts = false; bool padded = true; IBlockCipherPadding padding = null; IAeadBlockCipher aeadBlockCipher = null; if (parts.Length > 2) { if (streamCipher != null) { throw new ArgumentException("Paddings not used for stream ciphers"); } string paddingName = parts[2]; CipherPadding cipherPadding; if (paddingName == "") { cipherPadding = CipherPadding.RAW; } else if (paddingName == "X9.23PADDING") { cipherPadding = CipherPadding.X923PADDING; } else { try { cipherPadding = (CipherPadding)Enums.GetEnumValue(typeof(CipherPadding), paddingName); } catch (ArgumentException) { throw new SecurityUtilityException("Cipher " + algorithm + " not recognised."); } } switch (cipherPadding) { case CipherPadding.NOPADDING: padded = false; break; case CipherPadding.RAW: break; case CipherPadding.ISO10126PADDING: case CipherPadding.ISO10126D2PADDING: case CipherPadding.ISO10126_2PADDING: padding = new ISO10126d2Padding(); break; case CipherPadding.ISO7816_4PADDING: case CipherPadding.ISO9797_1PADDING: padding = new ISO7816d4Padding(); break; case CipherPadding.ISO9796_1: case CipherPadding.ISO9796_1PADDING: asymBlockCipher = new ISO9796d1Encoding(asymBlockCipher); break; case CipherPadding.OAEP: case CipherPadding.OAEPPADDING: asymBlockCipher = new OaepEncoding(asymBlockCipher); break; case CipherPadding.OAEPWITHMD5ANDMGF1PADDING: asymBlockCipher = new OaepEncoding(asymBlockCipher, new MD5Digest()); break; case CipherPadding.OAEPWITHSHA1ANDMGF1PADDING: case CipherPadding.OAEPWITHSHA_1ANDMGF1PADDING: asymBlockCipher = new OaepEncoding(asymBlockCipher, new Sha1Digest()); break; case CipherPadding.OAEPWITHSHA224ANDMGF1PADDING: case CipherPadding.OAEPWITHSHA_224ANDMGF1PADDING: asymBlockCipher = new OaepEncoding(asymBlockCipher, new Sha224Digest()); break; case CipherPadding.OAEPWITHSHA256ANDMGF1PADDING: case CipherPadding.OAEPWITHSHA_256ANDMGF1PADDING: asymBlockCipher = new OaepEncoding(asymBlockCipher, new Sha256Digest()); break; case CipherPadding.OAEPWITHSHA384ANDMGF1PADDING: case CipherPadding.OAEPWITHSHA_384ANDMGF1PADDING: asymBlockCipher = new OaepEncoding(asymBlockCipher, new Sha384Digest()); break; case CipherPadding.OAEPWITHSHA512ANDMGF1PADDING: case CipherPadding.OAEPWITHSHA_512ANDMGF1PADDING: asymBlockCipher = new OaepEncoding(asymBlockCipher, new Sha512Digest()); break; case CipherPadding.PKCS1: case CipherPadding.PKCS1PADDING: asymBlockCipher = new Pkcs1Encoding(asymBlockCipher); break; case CipherPadding.PKCS5: case CipherPadding.PKCS5PADDING: case CipherPadding.PKCS7: case CipherPadding.PKCS7PADDING: padding = new Pkcs7Padding(); break; case CipherPadding.TBCPADDING: padding = new TbcPadding(); break; case CipherPadding.WITHCTS: cts = true; break; case CipherPadding.X923PADDING: padding = new X923Padding(); break; case CipherPadding.ZEROBYTEPADDING: padding = new ZeroBytePadding(); break; default: throw new SecurityUtilityException("Cipher " + algorithm + " not recognised."); } } string mode = ""; if (parts.Length > 1) { mode = parts[1]; int di = GetDigitIndex(mode); string modeName = di >= 0 ? mode.Substring(0, di) : mode; try { CipherMode cipherMode = modeName == "" ? CipherMode.NONE : (CipherMode)Enums.GetEnumValue(typeof(CipherMode), modeName); switch (cipherMode) { case CipherMode.ECB: case CipherMode.NONE: break; case CipherMode.CBC: blockCipher = new CbcBlockCipher(blockCipher); break; case CipherMode.CFB: { int bits = (di < 0) ? 8 * blockCipher.GetBlockSize() : int.Parse(mode.Substring(di)); blockCipher = new CfbBlockCipher(blockCipher, bits); break; } case CipherMode.CTR: blockCipher = new SicBlockCipher(blockCipher); break; case CipherMode.CTS: cts = true; blockCipher = new CbcBlockCipher(blockCipher); break; case CipherMode.EAX: aeadBlockCipher = new EaxBlockCipher(blockCipher); break; case CipherMode.GCM: aeadBlockCipher = new GcmBlockCipher(blockCipher); break; case CipherMode.GOFB: blockCipher = new GOfbBlockCipher(blockCipher); break; case CipherMode.OCB: aeadBlockCipher = new OcbBlockCipher(blockCipher, CreateBlockCipher(cipherAlgorithm)); break; case CipherMode.OFB: { int bits = (di < 0) ? 8 * blockCipher.GetBlockSize() : int.Parse(mode.Substring(di)); blockCipher = new OfbBlockCipher(blockCipher, bits); break; } case CipherMode.OPENPGPCFB: blockCipher = new OpenPgpCfbBlockCipher(blockCipher); break; case CipherMode.SIC: if (blockCipher.GetBlockSize() < 16) { throw new ArgumentException("Warning: SIC-Mode can become a twotime-pad if the blocksize of the cipher is too small. Use a cipher with a block size of at least 128 bits (e.g. AES)"); } blockCipher = new SicBlockCipher(blockCipher); break; default: throw new SecurityUtilityException("Cipher " + algorithm + " not recognised."); } } catch (ArgumentException) { throw new SecurityUtilityException("Cipher " + algorithm + " not recognised."); } } if (aeadBlockCipher != null) { if (cts) { throw new SecurityUtilityException("CTS mode not valid for AEAD ciphers."); } if (padded && parts.Length > 2 && parts[2] != "") { throw new SecurityUtilityException("Bad padding specified for AEAD cipher."); } return(new BufferedAeadBlockCipher(aeadBlockCipher)); } if (blockCipher != null) { if (cts) { return(new CtsBlockCipher(blockCipher)); } if (padding != null) { return(new PaddedBufferedBlockCipher(blockCipher, padding)); } if (!padded || blockCipher.IsPartialBlockOkay) { return(new BufferedBlockCipher(blockCipher)); } return(new PaddedBufferedBlockCipher(blockCipher)); } if (asymBlockCipher != null) { return(new BufferedAsymmetricBlockCipher(asymBlockCipher)); } throw new SecurityUtilityException("Cipher " + algorithm + " not recognised."); }
public void TestGetItems_Validate() { AssertHelper.Throws <InvalidOperationException>(() => { Enums.GetItems <Sample>(); }, "类型 Util.Tests.Samples.Sample 不是枚举"); }
static PemUtilities() { // Signal to obfuscation tools not to change enum constants ((PemBaseAlg)Enums.GetArbitraryValue(typeof(PemBaseAlg))).ToString(); ((PemMode)Enums.GetArbitraryValue(typeof(PemMode))).ToString(); }
/// <summary> /// Gets the string representation of the <see cref="ControllerElement"/>. /// </summary> /// <param name="this">The <see cref="ControllerElement"/> to parse.</param> /// <returns>The string representation of the <see cref="ControllerElement"/>.</returns> public static string ToString(this ControllerElement @this) { return(Enums.AsString(@this)); }
/// <summary> /// Parses a <see cref="ControllerElement"/> from a string. /// </summary> /// <param name="controllerElement">The string representation of the controller element.</param> /// <returns>A <see cref="ControllerElement"/> parsed from the string.</returns> /// <exception cref="ArgumentException">If the string is unable to be parsed.</exception> public static ControllerElement Parse(string controllerElement) { return(Enums.Parse <ControllerElement>(controllerElement, true)); }
/// <summary> /// Parses an XML string to a new Easy Base System. /// </summary> /// <remarks>Generator step 1.</remarks> /// <param name="xmlString">The XML string.</param> private void ParseXml(string xmlString) { // Read all entity names (singular and plural) XmlReader reader = XmlReader.Create(new StringReader(xmlString)); XDocument doc = XDocument.Load(reader); var entityNames = (from entity in doc.Descendants("Entity") select new { NameSingular = entity.Attribute("NameSingular").Value, NamePlural = entity.Attributes("NamePlural").Count() > 0 ? entity.Attribute("NamePlural").Value : ToPlural(entity.Attribute("NameSingular").Value) }).ToList(); reader.Close(); reader = XmlReader.Create(new StringReader(xmlString)); // Read Enums doc = XDocument.Load(reader); var enums = (from e in doc.Descendants("Enum") select e).ToList(); // Create all global enums foreach (var e in enums) { string enumName = e.Attribute("Name").Value; Enums.Add(new GlobalEnum(enumName)); var values = (from v in e.Descendants() select v).ToList(); // Create all possible values for current enum foreach (var value in values) { Enums[enumName].Values.Add(value.Value); } } reader.Close(); reader = XmlReader.Create(new StringReader(xmlString)); // Read Entities while (reader.ReadToFollowing("Entity")) { string nameSingular = ""; string namePlural = ""; bool isView = false; List <Field> fields = new List <Field>(); List <UniqueKey> uniqueKeys = new List <UniqueKey>(); List <string> parentNames = new List <string>(); while (reader.MoveToNextAttribute()) { string attributeName = reader.Name; switch (attributeName) { case "NameSingular": nameSingular = reader.Value; if (namePlural == "") { namePlural = ToPlural(nameSingular); } break; case "NamePlural": namePlural = reader.Value; break; case "IsView": isView = (reader.Value.ToLower() == "true"); break; default: throw new NotImplementedException("'" + attributeName + "' on entity '" + nameSingular + "' is not a valid entity attribute."); } } if (nameSingular == "") { throw new ApplicationException("Entity must have a name."); } while (reader.Read() && reader.NodeType != XmlNodeType.Element && reader.NodeType != XmlNodeType.EndElement) { ; } if (reader.NodeType != XmlNodeType.EndElement && !reader.EOF) { if (reader.Name == "Fields") { while (reader.Read() && reader.NodeType != XmlNodeType.Element && reader.NodeType != XmlNodeType.EndElement) { ; } while (reader.NodeType != XmlNodeType.EndElement && !reader.EOF) { Field field; if (reader.Name == "PrimaryKeyField") { string fieldName = ""; string fieldType = ""; bool allowNull = false; bool isIdentity = false; string[] enumValues = null; string globalEnumName = ""; while (reader.MoveToNextAttribute()) { string attributeName = reader.Name; switch (attributeName) { case "Name": fieldName = reader.Value; break; case "Type": fieldType = reader.Value; break; case "AllowNull": allowNull = Convert.ToBoolean(reader.Value); break; case "IsIdentity": isIdentity = Convert.ToBoolean(reader.Value); break; case "EnumValues": if (IsGlobalEnum(reader.Value)) { globalEnumName = reader.Value; } else { enumValues = reader.Value.Split("/".ToArray()); } break; default: throw new NotImplementedException("'" + attributeName + "' on field '" + fieldName + "' on entity '" + nameSingular + "' is not a valid primary key field attribute."); } } if (fieldName == "") { throw new ApplicationException("Primary key field for entity '" + nameSingular + "' must have a name."); } if (fieldType == "") { throw new ApplicationException("Primary key field '" + fieldName + "' on entity '" + nameSingular + "' must have a type."); } field = new PrimaryKeyField(nameSingular, fieldName, fieldType, allowNull, isIdentity); if (globalEnumName != "") { field.GlobalEnumName = globalEnumName; } else { if (enumValues != null) { field.EnumValues = enumValues; } } } else if (reader.Name == "ForeignKeyField") { string fieldName = ""; string fieldType = ""; string targetEntityName = ""; string targetFieldName = ""; bool allowNull = false; bool isParentConnection = false; List <int> uniqueKeyGroups = new List <int>(); while (reader.MoveToNextAttribute()) { string attributeName = reader.Name; switch (attributeName) { case "Name": fieldName = reader.Value; break; case "Type": fieldType = reader.Value; break; case "TargetEntity": targetEntityName = reader.Value; break; case "TargetField": targetFieldName = reader.Value; break; case "AllowNull": allowNull = Convert.ToBoolean(reader.Value); break; case "IsParentConnection": isParentConnection = Convert.ToBoolean(reader.Value); break; case "UniqueKeyGroup": string[] keyGroups = reader.Value.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string sKeyGroup in keyGroups) { uniqueKeyGroups.Add(int.Parse(sKeyGroup)); } break; default: throw new NotImplementedException("'" + attributeName + "' on field '" + fieldName + "' on entity '" + nameSingular + "' is not a valid foreign key field attribute."); } } if (fieldName == "") { throw new ApplicationException("Foreign key field for entity '" + nameSingular + "' must have a name."); } if (fieldType == "") { throw new ApplicationException("Foreign key field '" + fieldName + "' on entity '" + nameSingular + "' must have a type."); } if (targetEntityName == "") { throw new ApplicationException("Foreign key field '" + fieldName + "' on entity '" + nameSingular + "' must have a target entity."); } if (targetFieldName == "") { throw new ApplicationException("Foreign key field '" + fieldName + "' on entity '" + nameSingular + "' must have a target field."); } var tableName = entityNames.Find(a => a.NameSingular == targetEntityName).NamePlural; field = new ForeignKeyField(nameSingular, fieldName, fieldType, tableName, targetFieldName, allowNull, isParentConnection, uniqueKeyGroups.ToArray()); if (isParentConnection) { parentNames.Add(targetEntityName); } if (uniqueKeyGroups.Count > 0) { foreach (int uniqueKeyGroup in uniqueKeyGroups) { AddToUniqueKeys(uniqueKeys, uniqueKeyGroup, field); } } } else if (reader.Name == "Field") { string fieldName = ""; string fieldType = ""; bool allowNull = false; List <int> uniqueKeyGroups = new List <int>(); string[] enumValues = null; string globalEnumName = ""; while (reader.MoveToNextAttribute()) { string attributeName = reader.Name; switch (attributeName) { case "Name": fieldName = reader.Value; break; case "Type": fieldType = reader.Value; break; case "AllowNull": allowNull = Convert.ToBoolean(reader.Value); break; case "UniqueKeyGroup": string[] keyGroups = reader.Value.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string sKeyGroup in keyGroups) { uniqueKeyGroups.Add(int.Parse(sKeyGroup)); } break; case "EnumValues": if (IsGlobalEnum(reader.Value)) { globalEnumName = reader.Value; } else { enumValues = reader.Value.Split("/".ToArray()); } break; default: throw new NotImplementedException("'" + attributeName + "' on field '" + fieldName + "' on entity '" + nameSingular + "' is not a valid field attribute."); } } if (fieldName == "") { throw new ApplicationException("Field on entity '" + nameSingular + "' must have a name."); } if (fieldType == "") { throw new ApplicationException("Field '" + fieldName + "' entity '" + nameSingular + "' must have a type."); } field = new Field(nameSingular, fieldName, fieldType, allowNull, uniqueKeyGroups.ToArray()); if (globalEnumName != "") { field.GlobalEnumName = globalEnumName; } else { if (enumValues != null) { field.EnumValues = enumValues; } } if (uniqueKeyGroups.Count > 0) { foreach (int uniqueKeyGroup in uniqueKeyGroups) { AddToUniqueKeys(uniqueKeys, uniqueKeyGroup, field); } } } else if (reader.Name == "ViewField") { string fieldName = ""; string fieldType = ""; bool allowNull = false; while (reader.MoveToNextAttribute()) { string attributeName = reader.Name; switch (attributeName) { case "Name": fieldName = reader.Value; break; case "Type": fieldType = reader.Value; break; case "AllowNull": allowNull = Convert.ToBoolean(reader.Value); break; default: throw new NotImplementedException("'" + attributeName + "' on field '" + fieldName + "' on entity '" + nameSingular + "' is not a valid field attribute."); } } if (fieldName == "") { throw new ApplicationException("Field on entity '" + nameSingular + "' must have a name."); } if (fieldType == "") { throw new ApplicationException("Field '" + fieldName + "' entity '" + nameSingular + "' must have a type."); } field = new ViewField(nameSingular, fieldName, fieldType, allowNull); } else { throw new ApplicationException("When initiating entity '" + nameSingular + "', tags '<PrimaryKeyField>, <ForeighKeyField>, <Field> or <ViewField>' was expected, but got tag '<" + reader.Name + ">'"); } fields.Add(field); while (reader.Read() && reader.NodeType != XmlNodeType.Element && reader.NodeType != XmlNodeType.EndElement) { ; } } } else { throw new ApplicationException("When initiating entity '" + nameSingular + "', tag '<Fields>' was expected, but got tag '<" + reader.Name + ">'"); } Entities.Add(new Entity(this, nameSingular, namePlural, isView, fields.ToArray(), uniqueKeys.ToArray(), parentNames.ToArray())); } } // Loopa igenom alla entiteter och sätt barn på alla föräldrar foreach (Entity entity in Entities) { if (entity.HasParents) { foreach (string parentName in entity.ParentNames) { Entity parent = Entities.Find(e => e.NameSingular == parentName); parent.ChildNames.Add(entity.NameSingular); } } } }
protected override async Task <int> BuildInternal(BuildSettings settings) { var filesToCreate = EntityHelper.EntityTypes.Where(e => Roots.Contains(e.Name) && !Enums.Contains(e.Name)); BuilderFileCountUpdate(filesToCreate.Count()); await Pause.WaitWhilePausedAsync(); foreach (var file in filesToCreate) { var filePath = string.Concat(settings.AppServiceInterfacePath, "I", file.Name, "ApplicationService", settings.FileExtension); await BuildFile <eBuildSectionAppServiceInterface>(filePath, file, settings); await Pause.WaitWhilePausedAsync(); if (Cancellation.IsCancellationRequested) { break; } } return(filesToCreate.Count()); }
/// <summary> /// Validate function for all TVItemUserAuthorizationService commands /// </summary> /// <param name="validationContext">System.ComponentModel.DataAnnotations.ValidationContext (Describes the context in which a validation check is performed.)</param> /// <param name="actionDBType">[ActionDBTypeEnum] (CSSPEnums.ActionDBTypeEnum.html) action type to validate</param> /// <returns>IEnumerable of ValidationResult (Where ValidationResult is a container for the results of a validation request.)</returns> private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType) { string retStr = ""; Enums enums = new Enums(LanguageRequest); TVItemUserAuthorization tvItemUserAuthorization = validationContext.ObjectInstance as TVItemUserAuthorization; tvItemUserAuthorization.HasErrors = false; if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete) { if (tvItemUserAuthorization.TVItemUserAuthorizationID == 0) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TVItemUserAuthorizationID"), new[] { "TVItemUserAuthorizationID" })); } if (!(from c in db.TVItemUserAuthorizations select c).Where(c => c.TVItemUserAuthorizationID == tvItemUserAuthorization.TVItemUserAuthorizationID).Any()) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItemUserAuthorization", "TVItemUserAuthorizationID", tvItemUserAuthorization.TVItemUserAuthorizationID.ToString()), new[] { "TVItemUserAuthorizationID" })); } } TVItem TVItemContactTVItemID = (from c in db.TVItems where c.TVItemID == tvItemUserAuthorization.ContactTVItemID select c).FirstOrDefault(); if (TVItemContactTVItemID == null) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "ContactTVItemID", tvItemUserAuthorization.ContactTVItemID.ToString()), new[] { "ContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemContactTVItemID.TVType)) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "ContactTVItemID", "Contact"), new[] { "ContactTVItemID" })); } } TVItem TVItemTVItemID1 = (from c in db.TVItems where c.TVItemID == tvItemUserAuthorization.TVItemID1 select c).FirstOrDefault(); if (TVItemTVItemID1 == null) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "TVItemID1", tvItemUserAuthorization.TVItemID1.ToString()), new[] { "TVItemID1" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Root, TVTypeEnum.Address, TVTypeEnum.Area, TVTypeEnum.ClimateSite, TVTypeEnum.Contact, TVTypeEnum.Country, TVTypeEnum.Email, TVTypeEnum.File, TVTypeEnum.HydrometricSite, TVTypeEnum.Infrastructure, TVTypeEnum.MikeScenario, TVTypeEnum.MikeSource, TVTypeEnum.Municipality, TVTypeEnum.MWQMSite, TVTypeEnum.PolSourceSite, TVTypeEnum.Province, TVTypeEnum.Sector, TVTypeEnum.Subsector, TVTypeEnum.Tel, TVTypeEnum.TideSite, TVTypeEnum.WasteWaterTreatmentPlant, TVTypeEnum.LiftStation, TVTypeEnum.Spill, TVTypeEnum.BoxModel, TVTypeEnum.VisualPlumesScenario, TVTypeEnum.OtherInfrastructure, TVTypeEnum.MWQMRun, TVTypeEnum.MeshNode, TVTypeEnum.WebTideNode, TVTypeEnum.SamplingPlan, TVTypeEnum.SeeOtherMunicipality, TVTypeEnum.LineOverflow, TVTypeEnum.MapInfo, TVTypeEnum.MapInfoPoint, }; if (!AllowableTVTypes.Contains(TVItemTVItemID1.TVType)) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "TVItemID1", "Root,Address,Area,ClimateSite,Contact,Country,Email,File,HydrometricSite,Infrastructure,MikeScenario,MikeSource,Municipality,MWQMSite,PolSourceSite,Province,Sector,Subsector,Tel,TideSite,WasteWaterTreatmentPlant,LiftStation,Spill,BoxModel,VisualPlumesScenario,OtherInfrastructure,MWQMRun,MeshNode,WebTideNode,SamplingPlan,SeeOtherMunicipality,LineOverflow,MapInfo,MapInfoPoint"), new[] { "TVItemID1" })); } } if (tvItemUserAuthorization.TVItemID2 != null) { TVItem TVItemTVItemID2 = (from c in db.TVItems where c.TVItemID == tvItemUserAuthorization.TVItemID2 select c).FirstOrDefault(); if (TVItemTVItemID2 == null) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "TVItemID2", (tvItemUserAuthorization.TVItemID2 == null ? "" : tvItemUserAuthorization.TVItemID2.ToString())), new[] { "TVItemID2" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Root, TVTypeEnum.Address, TVTypeEnum.Area, TVTypeEnum.ClimateSite, TVTypeEnum.Contact, TVTypeEnum.Country, TVTypeEnum.Email, TVTypeEnum.File, TVTypeEnum.HydrometricSite, TVTypeEnum.Infrastructure, TVTypeEnum.MikeScenario, TVTypeEnum.MikeSource, TVTypeEnum.Municipality, TVTypeEnum.MWQMSite, TVTypeEnum.PolSourceSite, TVTypeEnum.Province, TVTypeEnum.Sector, TVTypeEnum.Subsector, TVTypeEnum.Tel, TVTypeEnum.TideSite, TVTypeEnum.WasteWaterTreatmentPlant, TVTypeEnum.LiftStation, TVTypeEnum.Spill, TVTypeEnum.BoxModel, TVTypeEnum.VisualPlumesScenario, TVTypeEnum.OtherInfrastructure, TVTypeEnum.MWQMRun, TVTypeEnum.MeshNode, TVTypeEnum.WebTideNode, TVTypeEnum.SamplingPlan, TVTypeEnum.SeeOtherMunicipality, TVTypeEnum.LineOverflow, TVTypeEnum.MapInfo, TVTypeEnum.MapInfoPoint, }; if (!AllowableTVTypes.Contains(TVItemTVItemID2.TVType)) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "TVItemID2", "Root,Address,Area,ClimateSite,Contact,Country,Email,File,HydrometricSite,Infrastructure,MikeScenario,MikeSource,Municipality,MWQMSite,PolSourceSite,Province,Sector,Subsector,Tel,TideSite,WasteWaterTreatmentPlant,LiftStation,Spill,BoxModel,VisualPlumesScenario,OtherInfrastructure,MWQMRun,MeshNode,WebTideNode,SamplingPlan,SeeOtherMunicipality,LineOverflow,MapInfo,MapInfoPoint"), new[] { "TVItemID2" })); } } } if (tvItemUserAuthorization.TVItemID3 != null) { TVItem TVItemTVItemID3 = (from c in db.TVItems where c.TVItemID == tvItemUserAuthorization.TVItemID3 select c).FirstOrDefault(); if (TVItemTVItemID3 == null) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "TVItemID3", (tvItemUserAuthorization.TVItemID3 == null ? "" : tvItemUserAuthorization.TVItemID3.ToString())), new[] { "TVItemID3" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Root, TVTypeEnum.Address, TVTypeEnum.Area, TVTypeEnum.ClimateSite, TVTypeEnum.Contact, TVTypeEnum.Country, TVTypeEnum.Email, TVTypeEnum.File, TVTypeEnum.HydrometricSite, TVTypeEnum.Infrastructure, TVTypeEnum.MikeScenario, TVTypeEnum.MikeSource, TVTypeEnum.Municipality, TVTypeEnum.MWQMSite, TVTypeEnum.PolSourceSite, TVTypeEnum.Province, TVTypeEnum.Sector, TVTypeEnum.Subsector, TVTypeEnum.Tel, TVTypeEnum.TideSite, TVTypeEnum.WasteWaterTreatmentPlant, TVTypeEnum.LiftStation, TVTypeEnum.Spill, TVTypeEnum.BoxModel, TVTypeEnum.VisualPlumesScenario, TVTypeEnum.OtherInfrastructure, TVTypeEnum.MWQMRun, TVTypeEnum.MeshNode, TVTypeEnum.WebTideNode, TVTypeEnum.SamplingPlan, TVTypeEnum.SeeOtherMunicipality, TVTypeEnum.LineOverflow, TVTypeEnum.MapInfo, TVTypeEnum.MapInfoPoint, }; if (!AllowableTVTypes.Contains(TVItemTVItemID3.TVType)) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "TVItemID3", "Root,Address,Area,ClimateSite,Contact,Country,Email,File,HydrometricSite,Infrastructure,MikeScenario,MikeSource,Municipality,MWQMSite,PolSourceSite,Province,Sector,Subsector,Tel,TideSite,WasteWaterTreatmentPlant,LiftStation,Spill,BoxModel,VisualPlumesScenario,OtherInfrastructure,MWQMRun,MeshNode,WebTideNode,SamplingPlan,SeeOtherMunicipality,LineOverflow,MapInfo,MapInfoPoint"), new[] { "TVItemID3" })); } } } if (tvItemUserAuthorization.TVItemID4 != null) { TVItem TVItemTVItemID4 = (from c in db.TVItems where c.TVItemID == tvItemUserAuthorization.TVItemID4 select c).FirstOrDefault(); if (TVItemTVItemID4 == null) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "TVItemID4", (tvItemUserAuthorization.TVItemID4 == null ? "" : tvItemUserAuthorization.TVItemID4.ToString())), new[] { "TVItemID4" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Root, TVTypeEnum.Address, TVTypeEnum.Area, TVTypeEnum.ClimateSite, TVTypeEnum.Contact, TVTypeEnum.Country, TVTypeEnum.Email, TVTypeEnum.File, TVTypeEnum.HydrometricSite, TVTypeEnum.Infrastructure, TVTypeEnum.MikeScenario, TVTypeEnum.MikeSource, TVTypeEnum.Municipality, TVTypeEnum.MWQMSite, TVTypeEnum.PolSourceSite, TVTypeEnum.Province, TVTypeEnum.Sector, TVTypeEnum.Subsector, TVTypeEnum.Tel, TVTypeEnum.TideSite, TVTypeEnum.WasteWaterTreatmentPlant, TVTypeEnum.LiftStation, TVTypeEnum.Spill, TVTypeEnum.BoxModel, TVTypeEnum.VisualPlumesScenario, TVTypeEnum.OtherInfrastructure, TVTypeEnum.MWQMRun, TVTypeEnum.MeshNode, TVTypeEnum.WebTideNode, TVTypeEnum.SamplingPlan, TVTypeEnum.SeeOtherMunicipality, TVTypeEnum.LineOverflow, TVTypeEnum.MapInfo, TVTypeEnum.MapInfoPoint, }; if (!AllowableTVTypes.Contains(TVItemTVItemID4.TVType)) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "TVItemID4", "Root,Address,Area,ClimateSite,Contact,Country,Email,File,HydrometricSite,Infrastructure,MikeScenario,MikeSource,Municipality,MWQMSite,PolSourceSite,Province,Sector,Subsector,Tel,TideSite,WasteWaterTreatmentPlant,LiftStation,Spill,BoxModel,VisualPlumesScenario,OtherInfrastructure,MWQMRun,MeshNode,WebTideNode,SamplingPlan,SeeOtherMunicipality,LineOverflow,MapInfo,MapInfoPoint"), new[] { "TVItemID4" })); } } } retStr = enums.EnumTypeOK(typeof(TVAuthEnum), (int?)tvItemUserAuthorization.TVAuth); if (!string.IsNullOrWhiteSpace(retStr)) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TVAuth"), new[] { "TVAuth" })); } if (tvItemUserAuthorization.LastUpdateDate_UTC.Year == 1) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" })); } else { if (tvItemUserAuthorization.LastUpdateDate_UTC.Year < 1980) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" })); } } TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == tvItemUserAuthorization.LastUpdateContactTVItemID select c).FirstOrDefault(); if (TVItemLastUpdateContactTVItemID == null) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", tvItemUserAuthorization.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType)) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" })); } } retStr = ""; // added to stop compiling CSSPError if (retStr != "") // will never be true { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult("AAA", new[] { "AAA" })); } }
public void TestGetDescription_Nullable(object member, string description) { Assert.Equal(description, Enums.GetDescription <EnumSample?>(member)); }
public void TestParse(string memeber, EnumSample sample) { Assert.Equal(sample, Enums.Parse <EnumSample>(memeber)); }
internal static Keys[] ConstructSFMLKeyMap() { var maxValue = Enums.IterateValues <Keys>().Max(); var table = new Keys[(int)maxValue + 1]; for (Keys i = 0; i <= maxValue; i++) { table[(int)i] = Keys.NoKey; } for (SFK key = SFK.A; key <= SFK.Z; key++) { table[(int)key] = (Keys)((int)Keys.A + (int)(key - SFK.A)); } for (SFK key = SFK.Num0; key <= SFK.Num9; key++) { table[(int)key] = (Keys)((int)Keys.Alpha0 + (int)(key - SFK.Num0)); } for (SFK key = SFK.F1; key <= SFK.F12; key++) { table[(int)key] = (Keys)((int)Keys.F1 + (int)(key - SFK.F1)); } table[(int)SFK.Return] = Keys.Enter; table[(int)SFK.Space] = Keys.Space; table[(int)SFK.RAlt] = Keys.RAlt; table[(int)SFK.RControl] = Keys.RCtrl; table[(int)SFK.RShift] = Keys.RShift; table[(int)SFK.LAlt] = Keys.LAlt; table[(int)SFK.LControl] = Keys.LCtrl; table[(int)SFK.LShift] = Keys.LShift; table[(int)SFK.Tab] = Keys.Tab; table[(int)SFK.Left] = Keys.Left; table[(int)SFK.Right] = Keys.Right; table[(int)SFK.Up] = Keys.Up; table[(int)SFK.Down] = Keys.Down; table[(int)SFK.BackSpace] = Keys.Backspace; table[(int)SFK.Delete] = Keys.Delete; table[(int)SFK.Escape] = Keys.Escape; table[(int)SFK.Numpad0] = Keys.Pad0; table[(int)SFK.Numpad1] = Keys.Pad1; table[(int)SFK.Numpad2] = Keys.Pad2; table[(int)SFK.Numpad3] = Keys.Pad3; table[(int)SFK.Numpad4] = Keys.Pad4; table[(int)SFK.Numpad5] = Keys.Pad5; table[(int)SFK.Numpad6] = Keys.Pad6; table[(int)SFK.Numpad7] = Keys.Pad7; table[(int)SFK.Numpad8] = Keys.Pad8; table[(int)SFK.Numpad9] = Keys.Pad9; table[(int)SFK.Add] = Keys.PadPlus; table[(int)SFK.Subtract] = Keys.PadMinus; table[(int)SFK.LBracket] = Keys.LeftBracket; table[(int)SFK.RBracket] = Keys.RightBracket; table[(int)SFK.SemiColon] = Keys.Semicolon; table[(int)SFK.Quote] = Keys.Apostrophe; table[(int)SFK.Comma] = Keys.Comma; table[(int)SFK.Period] = Keys.Period; table[(int)SFK.Slash] = Keys.Slash; table[(int)SFK.BackSlash] = Keys.Backslash; table[(int)SFK.Equal] = Keys.Equals; // table[(int)SFK.Subtract] = Keys.Subtract; return(table); }
public void TestGetName_Validate() { Assert.Equal(string.Empty, Enums.GetName(typeof(Sample), 3)); }
public static IDigest GetDigest( string algorithm) { string upper = Platform.ToUpperInvariant(algorithm); string mechanism = (string)algorithms[upper]; if (mechanism == null) { mechanism = upper; } try { DigestAlgorithm digestAlgorithm = (DigestAlgorithm)Enums.GetEnumValue( typeof(DigestAlgorithm), mechanism); switch (digestAlgorithm) { case DigestAlgorithm.BLAKE2B_160: return(new Blake2bDigest(160)); case DigestAlgorithm.BLAKE2B_256: return(new Blake2bDigest(256)); case DigestAlgorithm.BLAKE2B_384: return(new Blake2bDigest(384)); case DigestAlgorithm.BLAKE2B_512: return(new Blake2bDigest(512)); case DigestAlgorithm.BLAKE2S_128: return(new Blake2sDigest(128)); case DigestAlgorithm.BLAKE2S_160: return(new Blake2sDigest(160)); case DigestAlgorithm.BLAKE2S_224: return(new Blake2sDigest(224)); case DigestAlgorithm.BLAKE2S_256: return(new Blake2sDigest(256)); case DigestAlgorithm.DSTU7564_256: return(new Dstu7564Digest(256)); case DigestAlgorithm.DSTU7564_384: return(new Dstu7564Digest(384)); case DigestAlgorithm.DSTU7564_512: return(new Dstu7564Digest(512)); case DigestAlgorithm.GOST3411: return(new Gost3411Digest()); case DigestAlgorithm.GOST3411_2012_256: return(new Gost3411_2012_256Digest()); case DigestAlgorithm.GOST3411_2012_512: return(new Gost3411_2012_512Digest()); case DigestAlgorithm.KECCAK_224: return(new KeccakDigest(224)); case DigestAlgorithm.KECCAK_256: return(new KeccakDigest(256)); case DigestAlgorithm.KECCAK_288: return(new KeccakDigest(288)); case DigestAlgorithm.KECCAK_384: return(new KeccakDigest(384)); case DigestAlgorithm.KECCAK_512: return(new KeccakDigest(512)); case DigestAlgorithm.MD2: return(new MD2Digest()); case DigestAlgorithm.MD4: return(new MD4Digest()); case DigestAlgorithm.MD5: return(new MD5Digest()); case DigestAlgorithm.NONE: return(new NullDigest()); case DigestAlgorithm.RIPEMD128: return(new RipeMD128Digest()); case DigestAlgorithm.RIPEMD160: return(new RipeMD160Digest()); case DigestAlgorithm.RIPEMD256: return(new RipeMD256Digest()); case DigestAlgorithm.RIPEMD320: return(new RipeMD320Digest()); case DigestAlgorithm.SHA_1: return(new Sha1Digest()); case DigestAlgorithm.SHA_224: return(new Sha224Digest()); case DigestAlgorithm.SHA_256: return(new Sha256Digest()); case DigestAlgorithm.SHA_384: return(new Sha384Digest()); case DigestAlgorithm.SHA_512: return(new Sha512Digest()); case DigestAlgorithm.SHA_512_224: return(new Sha512tDigest(224)); case DigestAlgorithm.SHA_512_256: return(new Sha512tDigest(256)); case DigestAlgorithm.SHA3_224: return(new Sha3Digest(224)); case DigestAlgorithm.SHA3_256: return(new Sha3Digest(256)); case DigestAlgorithm.SHA3_384: return(new Sha3Digest(384)); case DigestAlgorithm.SHA3_512: return(new Sha3Digest(512)); case DigestAlgorithm.SHAKE128_256: return(new ShakeDigest(128)); case DigestAlgorithm.SHAKE256_512: return(new ShakeDigest(256)); case DigestAlgorithm.SM3: return(new SM3Digest()); case DigestAlgorithm.TIGER: return(new TigerDigest()); case DigestAlgorithm.WHIRLPOOL: return(new WhirlpoolDigest()); } } catch (ArgumentException) { } throw new SecurityUtilityException("Digest " + mechanism + " not recognised."); }
public async Task ContactGroups_CreateUpdateAndDelete() { var client = await GetTestClientAsync(); var contactGroups = client.Contacts.Groups; foreach (var contactType in Enums.GetValues <ContactType>()) { var groupType = contactType == ContactType.Business ? ContactGroupType.Public : ContactGroupType.Private; var groupAdded = new ContactGroup("ABC", contactType, groupType) { Description = "123" }; var groups = await contactGroups.GetGroupsAsync(contactType, groupType); var existingGroup = groups.FirstOrDefault(g => g.Name == groupAdded.Name); if (existingGroup != null) { await contactGroups.DeleteGroupAsync(existingGroup.Id); } var groupId = await contactGroups.CreateGroupAsync(groupAdded, true); try { Assert.AreEqual(groupId, groupAdded.Id); Assert.IsNotNull(groupAdded.CreatedDate); groups = await contactGroups.GetGroupsAsync(contactType, groupType); Assert.IsNotNull(groups); Assert.IsTrue(groups.Count > 0); var foundGroup = groups.FirstOrDefault(g => g.Id == groupId); Assert.IsNotNull(foundGroup); Assert.AreEqual(groupAdded.ContactType.Value, foundGroup.ContactType.Value); Assert.AreEqual(groupAdded.Name, foundGroup.Name); Assert.AreEqual(groupAdded.GroupType.Value, foundGroup.GroupType.Value); var retrievedGroup = await contactGroups.GetGroupAsync(groupId); Assert.IsNotNull(retrievedGroup); Assert.AreEqual(groupAdded.ContactType.Value, retrievedGroup.ContactType.Value); Assert.AreEqual(groupAdded.Name, retrievedGroup.Name); Assert.AreEqual(groupAdded.GroupType.Value, retrievedGroup.GroupType.Value); groupAdded = new ContactGroup(groupId, "DEF", contactType, groupType); existingGroup = groups.FirstOrDefault(g => g.Name == groupAdded.Name); if (existingGroup != null) { await contactGroups.DeleteGroupAsync(existingGroup.Id); } await contactGroups.UpdateGroupAsync(groupAdded); retrievedGroup = await contactGroups.GetGroupAsync(groupId); Assert.IsNotNull(retrievedGroup); Assert.AreEqual(groupAdded.ContactType.Value, retrievedGroup.ContactType.Value); Assert.AreEqual(groupAdded.Name, retrievedGroup.Name); Assert.AreEqual(groupAdded.GroupType.Value, retrievedGroup.GroupType.Value); } finally { await contactGroups.DeleteGroupAsync(groupId); } } }
/// <summary> /// Validate function for all TVTypeUserAuthorizationService commands /// </summary> /// <param name="validationContext">System.ComponentModel.DataAnnotations.ValidationContext (Describes the context in which a validation check is performed.)</param> /// <param name="actionDBType">[ActionDBTypeEnum] (CSSPEnums.ActionDBTypeEnum.html) action type to validate</param> /// <returns>IEnumerable of ValidationResult (Where ValidationResult is a container for the results of a validation request.)</returns> private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType) { string retStr = ""; Enums enums = new Enums(LanguageRequest); TVTypeUserAuthorization tvTypeUserAuthorization = validationContext.ObjectInstance as TVTypeUserAuthorization; tvTypeUserAuthorization.HasErrors = false; if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete) { if (tvTypeUserAuthorization.TVTypeUserAuthorizationID == 0) { tvTypeUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TVTypeUserAuthorizationID"), new[] { "TVTypeUserAuthorizationID" })); } if (!(from c in db.TVTypeUserAuthorizations select c).Where(c => c.TVTypeUserAuthorizationID == tvTypeUserAuthorization.TVTypeUserAuthorizationID).Any()) { tvTypeUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVTypeUserAuthorization", "TVTypeUserAuthorizationID", tvTypeUserAuthorization.TVTypeUserAuthorizationID.ToString()), new[] { "TVTypeUserAuthorizationID" })); } } TVItem TVItemContactTVItemID = (from c in db.TVItems where c.TVItemID == tvTypeUserAuthorization.ContactTVItemID select c).FirstOrDefault(); if (TVItemContactTVItemID == null) { tvTypeUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "ContactTVItemID", tvTypeUserAuthorization.ContactTVItemID.ToString()), new[] { "ContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemContactTVItemID.TVType)) { tvTypeUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "ContactTVItemID", "Contact"), new[] { "ContactTVItemID" })); } } retStr = enums.EnumTypeOK(typeof(TVTypeEnum), (int?)tvTypeUserAuthorization.TVType); if (!string.IsNullOrWhiteSpace(retStr)) { tvTypeUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TVType"), new[] { "TVType" })); } retStr = enums.EnumTypeOK(typeof(TVAuthEnum), (int?)tvTypeUserAuthorization.TVAuth); if (!string.IsNullOrWhiteSpace(retStr)) { tvTypeUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TVAuth"), new[] { "TVAuth" })); } if (tvTypeUserAuthorization.LastUpdateDate_UTC.Year == 1) { tvTypeUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" })); } else { if (tvTypeUserAuthorization.LastUpdateDate_UTC.Year < 1980) { tvTypeUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" })); } } TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == tvTypeUserAuthorization.LastUpdateContactTVItemID select c).FirstOrDefault(); if (TVItemLastUpdateContactTVItemID == null) { tvTypeUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", tvTypeUserAuthorization.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType)) { tvTypeUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" })); } } retStr = ""; // added to stop compiling CSSPError if (retStr != "") // will never be true { tvTypeUserAuthorization.HasErrors = true; yield return(new ValidationResult("AAA", new[] { "AAA" })); } }
private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType) { string retStr = ""; Enums enums = new Enums(LanguageRequest); SamplingPlan samplingPlan = validationContext.ObjectInstance as SamplingPlan; samplingPlan.HasErrors = false; if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete) { if (samplingPlan.SamplingPlanID == 0) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SamplingPlanID"), new[] { "SamplingPlanID" })); } if (!(from c in db.SamplingPlans select c).Where(c => c.SamplingPlanID == samplingPlan.SamplingPlanID).Any()) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SamplingPlan", "SamplingPlanID", samplingPlan.SamplingPlanID.ToString()), new[] { "SamplingPlanID" })); } } if (string.IsNullOrWhiteSpace(samplingPlan.SamplingPlanName)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SamplingPlanName"), new[] { "SamplingPlanName" })); } if (!string.IsNullOrWhiteSpace(samplingPlan.SamplingPlanName) && samplingPlan.SamplingPlanName.Length > 200) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "SamplingPlanName", "200"), new[] { "SamplingPlanName" })); } if (string.IsNullOrWhiteSpace(samplingPlan.ForGroupName)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "ForGroupName"), new[] { "ForGroupName" })); } if (!string.IsNullOrWhiteSpace(samplingPlan.ForGroupName) && samplingPlan.ForGroupName.Length > 100) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "ForGroupName", "100"), new[] { "ForGroupName" })); } retStr = enums.EnumTypeOK(typeof(SampleTypeEnum), (int?)samplingPlan.SampleType); if (!string.IsNullOrWhiteSpace(retStr)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SampleType"), new[] { "SampleType" })); } retStr = enums.EnumTypeOK(typeof(SamplingPlanTypeEnum), (int?)samplingPlan.SamplingPlanType); if (!string.IsNullOrWhiteSpace(retStr)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SamplingPlanType"), new[] { "SamplingPlanType" })); } retStr = enums.EnumTypeOK(typeof(LabSheetTypeEnum), (int?)samplingPlan.LabSheetType); if (!string.IsNullOrWhiteSpace(retStr)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LabSheetType"), new[] { "LabSheetType" })); } TVItem TVItemProvinceTVItemID = (from c in db.TVItems where c.TVItemID == samplingPlan.ProvinceTVItemID select c).FirstOrDefault(); if (TVItemProvinceTVItemID == null) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "ProvinceTVItemID", samplingPlan.ProvinceTVItemID.ToString()), new[] { "ProvinceTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Province, }; if (!AllowableTVTypes.Contains(TVItemProvinceTVItemID.TVType)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "ProvinceTVItemID", "Province"), new[] { "ProvinceTVItemID" })); } } TVItem TVItemCreatorTVItemID = (from c in db.TVItems where c.TVItemID == samplingPlan.CreatorTVItemID select c).FirstOrDefault(); if (TVItemCreatorTVItemID == null) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "CreatorTVItemID", samplingPlan.CreatorTVItemID.ToString()), new[] { "CreatorTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemCreatorTVItemID.TVType)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "CreatorTVItemID", "Contact"), new[] { "CreatorTVItemID" })); } } if (samplingPlan.Year < 2000 || samplingPlan.Year > 2050) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Year", "2000", "2050"), new[] { "Year" })); } if (string.IsNullOrWhiteSpace(samplingPlan.AccessCode)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "AccessCode"), new[] { "AccessCode" })); } if (!string.IsNullOrWhiteSpace(samplingPlan.AccessCode) && samplingPlan.AccessCode.Length > 15) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "AccessCode", "15"), new[] { "AccessCode" })); } if (samplingPlan.DailyDuplicatePrecisionCriteria < 0 || samplingPlan.DailyDuplicatePrecisionCriteria > 100) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "DailyDuplicatePrecisionCriteria", "0", "100"), new[] { "DailyDuplicatePrecisionCriteria" })); } if (samplingPlan.IntertechDuplicatePrecisionCriteria < 0 || samplingPlan.IntertechDuplicatePrecisionCriteria > 100) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "IntertechDuplicatePrecisionCriteria", "0", "100"), new[] { "IntertechDuplicatePrecisionCriteria" })); } if (string.IsNullOrWhiteSpace(samplingPlan.ApprovalCode)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "ApprovalCode"), new[] { "ApprovalCode" })); } if (!string.IsNullOrWhiteSpace(samplingPlan.ApprovalCode) && samplingPlan.ApprovalCode.Length > 15) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "ApprovalCode", "15"), new[] { "ApprovalCode" })); } if (samplingPlan.SamplingPlanFileTVItemID != null) { TVItem TVItemSamplingPlanFileTVItemID = (from c in db.TVItems where c.TVItemID == samplingPlan.SamplingPlanFileTVItemID select c).FirstOrDefault(); if (TVItemSamplingPlanFileTVItemID == null) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "SamplingPlanFileTVItemID", (samplingPlan.SamplingPlanFileTVItemID == null ? "" : samplingPlan.SamplingPlanFileTVItemID.ToString())), new[] { "SamplingPlanFileTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.File, }; if (!AllowableTVTypes.Contains(TVItemSamplingPlanFileTVItemID.TVType)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "SamplingPlanFileTVItemID", "File"), new[] { "SamplingPlanFileTVItemID" })); } } } if (samplingPlan.AnalyzeMethodDefault != null) { retStr = enums.EnumTypeOK(typeof(AnalyzeMethodEnum), (int?)samplingPlan.AnalyzeMethodDefault); if (samplingPlan.AnalyzeMethodDefault == null || !string.IsNullOrWhiteSpace(retStr)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "AnalyzeMethodDefault"), new[] { "AnalyzeMethodDefault" })); } } if (samplingPlan.SampleMatrixDefault != null) { retStr = enums.EnumTypeOK(typeof(SampleMatrixEnum), (int?)samplingPlan.SampleMatrixDefault); if (samplingPlan.SampleMatrixDefault == null || !string.IsNullOrWhiteSpace(retStr)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SampleMatrixDefault"), new[] { "SampleMatrixDefault" })); } } if (samplingPlan.LaboratoryDefault != null) { retStr = enums.EnumTypeOK(typeof(LaboratoryEnum), (int?)samplingPlan.LaboratoryDefault); if (samplingPlan.LaboratoryDefault == null || !string.IsNullOrWhiteSpace(retStr)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LaboratoryDefault"), new[] { "LaboratoryDefault" })); } } if (string.IsNullOrWhiteSpace(samplingPlan.BackupDirectory)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "BackupDirectory"), new[] { "BackupDirectory" })); } if (!string.IsNullOrWhiteSpace(samplingPlan.BackupDirectory) && samplingPlan.BackupDirectory.Length > 250) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "BackupDirectory", "250"), new[] { "BackupDirectory" })); } if (samplingPlan.LastUpdateDate_UTC.Year == 1) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" })); } else { if (samplingPlan.LastUpdateDate_UTC.Year < 1980) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" })); } } TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == samplingPlan.LastUpdateContactTVItemID select c).FirstOrDefault(); if (TVItemLastUpdateContactTVItemID == null) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", samplingPlan.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType)) { samplingPlan.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" })); } } retStr = ""; // added to stop compiling CSSPError if (retStr != "") // will never be true { samplingPlan.HasErrors = true; yield return(new ValidationResult("AAA", new[] { "AAA" })); } }
private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType) { string retStr = ""; Enums enums = new Enums(LanguageRequest); WhereInfo whereInfo = validationContext.ObjectInstance as WhereInfo; whereInfo.HasErrors = false; if (string.IsNullOrWhiteSpace(whereInfo.PropertyName)) { whereInfo.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "PropertyName"), new[] { "PropertyName" })); } if (!string.IsNullOrWhiteSpace(whereInfo.PropertyName) && whereInfo.PropertyName.Length > 100) { whereInfo.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "PropertyName", "100"), new[] { "PropertyName" })); } retStr = enums.EnumTypeOK(typeof(PropertyTypeEnum), (int?)whereInfo.PropertyType); if (!string.IsNullOrWhiteSpace(retStr)) { whereInfo.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "PropertyType"), new[] { "PropertyType" })); } retStr = enums.EnumTypeOK(typeof(WhereOperatorEnum), (int?)whereInfo.WhereOperator); if (!string.IsNullOrWhiteSpace(retStr)) { whereInfo.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "WhereOperator"), new[] { "WhereOperator" })); } if (string.IsNullOrWhiteSpace(whereInfo.Value)) { whereInfo.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Value"), new[] { "Value" })); } if (!string.IsNullOrWhiteSpace(whereInfo.Value) && whereInfo.Value.Length > 100) { whereInfo.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "Value", "100"), new[] { "Value" })); } if (whereInfo.ValueInt < -1 || whereInfo.ValueInt > -1) { whereInfo.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "ValueInt", "-1", "-1"), new[] { "ValueInt" })); } if (whereInfo.ValueDouble < -1 || whereInfo.ValueDouble > -1) { whereInfo.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "ValueDouble", "-1", "-1"), new[] { "ValueDouble" })); } if (whereInfo.ValueDateTime.Year == 1) { whereInfo.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "ValueDateTime"), new[] { "ValueDateTime" })); } else { if (whereInfo.ValueDateTime.Year < 1900) { whereInfo.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "ValueDateTime", "1900"), new[] { "ValueDateTime" })); } } if (string.IsNullOrWhiteSpace(whereInfo.ValueEnumText)) { whereInfo.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "ValueEnumText"), new[] { "ValueEnumText" })); } if (!string.IsNullOrWhiteSpace(whereInfo.ValueEnumText) && whereInfo.ValueEnumText.Length > 100) { whereInfo.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "ValueEnumText", "100"), new[] { "ValueEnumText" })); } //CSSPError: Type not implemented [EnumType] of type [Type] //CSSPError: Type not implemented [EnumType] of type [Type] retStr = ""; // added to stop compiling CSSPError if (retStr != "") // will never be true { whereInfo.HasErrors = true; yield return(new ValidationResult("AAA", new[] { "AAA" })); } }
/// <summary> /// Validate function for all ContactService commands /// </summary> /// <param name="validationContext">System.ComponentModel.DataAnnotations.ValidationContext (Describes the context in which a validation check is performed.)</param> /// <param name="actionDBType">[ActionDBTypeEnum] (CSSPEnums.ActionDBTypeEnum.html) action type to validate</param> /// <param name="addContactType">[AddContactTypeEnum] (CSSPEnums.AddContactTypeEnum.html) use when adding a new contact</param> /// <returns>IEnumerable of ValidationResult (Where ValidationResult is a container for the results of a validation request.)</returns> private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType, AddContactTypeEnum addContactType) { string retStr = ""; Enums enums = new Enums(LanguageRequest); Contact contact = validationContext.ObjectInstance as Contact; contact.HasErrors = false; if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete) { if (contact.ContactID == 0) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "ContactID"), new[] { "ContactID" })); } if (!(from c in db.Contacts select c).Where(c => c.ContactID == contact.ContactID).Any()) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "Contact", "ContactID", contact.ContactID.ToString()), new[] { "ContactID" })); } } if (string.IsNullOrWhiteSpace(contact.Id)) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Id"), new[] { "Id" })); } if (!string.IsNullOrWhiteSpace(contact.Id) && contact.Id.Length > 128) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "Id", "128"), new[] { "Id" })); } AspNetUser AspNetUserId = (from c in db.AspNetUsers where c.Id == contact.Id select c).FirstOrDefault(); if (AspNetUserId == null) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "AspNetUser", "Id", (contact.Id == null ? "" : contact.Id.ToString())), new[] { "Id" })); } TVItem TVItemContactTVItemID = (from c in db.TVItems where c.TVItemID == contact.ContactTVItemID select c).FirstOrDefault(); if (TVItemContactTVItemID == null) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "ContactTVItemID", contact.ContactTVItemID.ToString()), new[] { "ContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemContactTVItemID.TVType)) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "ContactTVItemID", "Contact"), new[] { "ContactTVItemID" })); } } if (string.IsNullOrWhiteSpace(contact.LoginEmail)) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LoginEmail"), new[] { "LoginEmail" })); } if (!string.IsNullOrWhiteSpace(contact.LoginEmail) && (contact.LoginEmail.Length < 6 || contact.LoginEmail.Length > 255)) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "LoginEmail", "6", "255"), new[] { "LoginEmail" })); } if (!string.IsNullOrWhiteSpace(contact.LoginEmail)) { Regex regex = new Regex(@"^([\w\!\#$\%\&\'*\+\-\/\=\?\^`{\|\}\~]+\.)*[\w\!\#$\%\&\'*\+\-\/\=\?\^`{\|\}\~]+@((((([a-zA-Z0-9]{1}[a-zA-Z0-9\-]{0,62}[a-zA-Z0-9]{1})|[a-zA-Z])\.)+[a-zA-Z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$"); if (!regex.IsMatch(contact.LoginEmail)) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotAValidEmail, "LoginEmail"), new[] { "LoginEmail" })); } } if (string.IsNullOrWhiteSpace(contact.FirstName)) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "FirstName"), new[] { "FirstName" })); } if (!string.IsNullOrWhiteSpace(contact.FirstName) && contact.FirstName.Length > 100) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "FirstName", "100"), new[] { "FirstName" })); } if (string.IsNullOrWhiteSpace(contact.LastName)) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastName"), new[] { "LastName" })); } if (!string.IsNullOrWhiteSpace(contact.LastName) && contact.LastName.Length > 100) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "LastName", "100"), new[] { "LastName" })); } if (!string.IsNullOrWhiteSpace(contact.Initial) && contact.Initial.Length > 50) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "Initial", "50"), new[] { "Initial" })); } if (string.IsNullOrWhiteSpace(contact.WebName)) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "WebName"), new[] { "WebName" })); } if (!string.IsNullOrWhiteSpace(contact.WebName) && contact.WebName.Length > 100) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "WebName", "100"), new[] { "WebName" })); } if (contact.ContactTitle != null) { retStr = enums.EnumTypeOK(typeof(ContactTitleEnum), (int?)contact.ContactTitle); if (contact.ContactTitle == null || !string.IsNullOrWhiteSpace(retStr)) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "ContactTitle"), new[] { "ContactTitle" })); } } if (!string.IsNullOrWhiteSpace(contact.SamplingPlanner_ProvincesTVItemID) && contact.SamplingPlanner_ProvincesTVItemID.Length > 200) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "SamplingPlanner_ProvincesTVItemID", "200"), new[] { "SamplingPlanner_ProvincesTVItemID" })); } if (contact.LastUpdateDate_UTC.Year == 1) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" })); } else { if (contact.LastUpdateDate_UTC.Year < 1980) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" })); } } TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == contact.LastUpdateContactTVItemID select c).FirstOrDefault(); if (TVItemLastUpdateContactTVItemID == null) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", contact.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType)) { contact.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" })); } } retStr = ""; // added to stop compiling CSSPError if (retStr != "") // will never be true { contact.HasErrors = true; yield return(new ValidationResult("AAA", new[] { "AAA" })); } }
/// <summary> /// Validate function for all MWQMSubsectorLanguageService commands /// </summary> /// <param name="validationContext">System.ComponentModel.DataAnnotations.ValidationContext (Describes the context in which a validation check is performed.)</param> /// <param name="actionDBType">[ActionDBTypeEnum] (CSSPEnums.ActionDBTypeEnum.html) action type to validate</param> /// <returns>IEnumerable of ValidationResult (Where ValidationResult is a container for the results of a validation request.)</returns> private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType) { string retStr = ""; Enums enums = new Enums(LanguageRequest); MWQMSubsectorLanguage mwqmSubsectorLanguage = validationContext.ObjectInstance as MWQMSubsectorLanguage; mwqmSubsectorLanguage.HasErrors = false; if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete) { if (mwqmSubsectorLanguage.MWQMSubsectorLanguageID == 0) { mwqmSubsectorLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "MWQMSubsectorLanguageID"), new[] { "MWQMSubsectorLanguageID" })); } if (!(from c in db.MWQMSubsectorLanguages select c).Where(c => c.MWQMSubsectorLanguageID == mwqmSubsectorLanguage.MWQMSubsectorLanguageID).Any()) { mwqmSubsectorLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "MWQMSubsectorLanguage", "MWQMSubsectorLanguageID", mwqmSubsectorLanguage.MWQMSubsectorLanguageID.ToString()), new[] { "MWQMSubsectorLanguageID" })); } } MWQMSubsector MWQMSubsectorMWQMSubsectorID = (from c in db.MWQMSubsectors where c.MWQMSubsectorID == mwqmSubsectorLanguage.MWQMSubsectorID select c).FirstOrDefault(); if (MWQMSubsectorMWQMSubsectorID == null) { mwqmSubsectorLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "MWQMSubsector", "MWQMSubsectorID", mwqmSubsectorLanguage.MWQMSubsectorID.ToString()), new[] { "MWQMSubsectorID" })); } retStr = enums.EnumTypeOK(typeof(LanguageEnum), (int?)mwqmSubsectorLanguage.Language); if (!string.IsNullOrWhiteSpace(retStr)) { mwqmSubsectorLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Language"), new[] { "Language" })); } if (string.IsNullOrWhiteSpace(mwqmSubsectorLanguage.SubsectorDesc)) { mwqmSubsectorLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SubsectorDesc"), new[] { "SubsectorDesc" })); } if (!string.IsNullOrWhiteSpace(mwqmSubsectorLanguage.SubsectorDesc) && mwqmSubsectorLanguage.SubsectorDesc.Length > 250) { mwqmSubsectorLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "SubsectorDesc", "250"), new[] { "SubsectorDesc" })); } retStr = enums.EnumTypeOK(typeof(TranslationStatusEnum), (int?)mwqmSubsectorLanguage.TranslationStatusSubsectorDesc); if (!string.IsNullOrWhiteSpace(retStr)) { mwqmSubsectorLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TranslationStatusSubsectorDesc"), new[] { "TranslationStatusSubsectorDesc" })); } //LogBook has no StringLength Attribute if (mwqmSubsectorLanguage.TranslationStatusLogBook != null) { retStr = enums.EnumTypeOK(typeof(TranslationStatusEnum), (int?)mwqmSubsectorLanguage.TranslationStatusLogBook); if (mwqmSubsectorLanguage.TranslationStatusLogBook == null || !string.IsNullOrWhiteSpace(retStr)) { mwqmSubsectorLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TranslationStatusLogBook"), new[] { "TranslationStatusLogBook" })); } } if (mwqmSubsectorLanguage.LastUpdateDate_UTC.Year == 1) { mwqmSubsectorLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" })); } else { if (mwqmSubsectorLanguage.LastUpdateDate_UTC.Year < 1980) { mwqmSubsectorLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" })); } } TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == mwqmSubsectorLanguage.LastUpdateContactTVItemID select c).FirstOrDefault(); if (TVItemLastUpdateContactTVItemID == null) { mwqmSubsectorLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", mwqmSubsectorLanguage.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType)) { mwqmSubsectorLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" })); } } retStr = ""; // added to stop compiling CSSPError if (retStr != "") // will never be true { mwqmSubsectorLanguage.HasErrors = true; yield return(new ValidationResult("AAA", new[] { "AAA" })); } }
public List <SelectListItem> BuildStatus() { return(Enums.AsSelectListItem <EventStatus>().ToList()); }
private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType) { string retStr = ""; Enums enums = new Enums(LanguageRequest); TVItem tvItem = validationContext.ObjectInstance as TVItem; tvItem.HasErrors = false; if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete) { if (tvItem.TVItemID == 0) { tvItem.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TVItemID"), new[] { "TVItemID" })); } if (!(from c in db.TVItems select c).Where(c => c.TVItemID == tvItem.TVItemID).Any()) { tvItem.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "TVItemID", tvItem.TVItemID.ToString()), new[] { "TVItemID" })); } } if (tvItem.TVType == TVTypeEnum.Root) { if ((from c in db.TVItems select c).Count() > 0) { tvItem.HasErrors = true; yield return(new ValidationResult(CSSPServicesRes.TVItemRootShouldBeTheFirstOneAdded, new[] { "TVItemTVItemID" })); } } if (tvItem.TVLevel < 0 || tvItem.TVLevel > 100) { tvItem.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "TVLevel", "0", "100"), new[] { "TVLevel" })); } if (string.IsNullOrWhiteSpace(tvItem.TVPath)) { tvItem.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TVPath"), new[] { "TVPath" })); } if (!string.IsNullOrWhiteSpace(tvItem.TVPath) && tvItem.TVPath.Length > 250) { tvItem.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "TVPath", "250"), new[] { "TVPath" })); } retStr = enums.EnumTypeOK(typeof(TVTypeEnum), (int?)tvItem.TVType); if (!string.IsNullOrWhiteSpace(retStr)) { tvItem.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TVType"), new[] { "TVType" })); } if (tvItem.TVType != TVTypeEnum.Root) { TVItem TVItemParentID = (from c in db.TVItems where c.TVItemID == tvItem.ParentID select c).FirstOrDefault(); if (TVItemParentID == null) { tvItem.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "ParentID", tvItem.ParentID.ToString()), new[] { "ParentID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Root, TVTypeEnum.Address, TVTypeEnum.Area, TVTypeEnum.ClimateSite, TVTypeEnum.Contact, TVTypeEnum.Country, TVTypeEnum.Email, TVTypeEnum.HydrometricSite, TVTypeEnum.Infrastructure, TVTypeEnum.MikeBoundaryConditionWebTide, TVTypeEnum.MikeBoundaryConditionMesh, TVTypeEnum.MikeScenario, TVTypeEnum.MikeSource, TVTypeEnum.Municipality, TVTypeEnum.MWQMSite, TVTypeEnum.PolSourceSite, TVTypeEnum.Province, TVTypeEnum.Sector, TVTypeEnum.Subsector, TVTypeEnum.Tel, TVTypeEnum.MWQMRun, TVTypeEnum.RainExceedance, TVTypeEnum.Classification, }; if (!AllowableTVTypes.Contains(TVItemParentID.TVType)) { tvItem.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "ParentID", "Root,Address,Area,ClimateSite,Contact,Country,Email,HydrometricSite,Infrastructure,MikeBoundaryConditionWebTide,MikeBoundaryConditionMesh,MikeScenario,MikeSource,Municipality,MWQMSite,PolSourceSite,Province,Sector,Subsector,Tel,MWQMRun,RainExceedance,Classification"), new[] { "ParentID" })); } } } if (tvItem.LastUpdateDate_UTC.Year == 1) { tvItem.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" })); } else { if (tvItem.LastUpdateDate_UTC.Year < 1980) { tvItem.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" })); } } if (tvItem.TVType != TVTypeEnum.Root) { TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == tvItem.LastUpdateContactTVItemID select c).FirstOrDefault(); if (TVItemLastUpdateContactTVItemID == null) { tvItem.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", tvItem.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType)) { tvItem.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" })); } } } retStr = ""; // added to stop compiling CSSPError if (retStr != "") // will never be true { tvItem.HasErrors = true; yield return(new ValidationResult("AAA", new[] { "AAA" })); } }
/// <summary> /// Validate function for all TVItemLinkService commands /// </summary> /// <param name="validationContext">System.ComponentModel.DataAnnotations.ValidationContext (Describes the context in which a validation check is performed.)</param> /// <param name="actionDBType">[ActionDBTypeEnum] (CSSPEnums.ActionDBTypeEnum.html) action type to validate</param> /// <returns>IEnumerable of ValidationResult (Where ValidationResult is a container for the results of a validation request.)</returns> private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType) { string retStr = ""; Enums enums = new Enums(LanguageRequest); TVItemLink tvItemLink = validationContext.ObjectInstance as TVItemLink; tvItemLink.HasErrors = false; if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete) { if (tvItemLink.TVItemLinkID == 0) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TVItemLinkID"), new[] { "TVItemLinkID" })); } if (!(from c in db.TVItemLinks select c).Where(c => c.TVItemLinkID == tvItemLink.TVItemLinkID).Any()) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItemLink", "TVItemLinkID", tvItemLink.TVItemLinkID.ToString()), new[] { "TVItemLinkID" })); } } TVItem TVItemFromTVItemID = (from c in db.TVItems where c.TVItemID == tvItemLink.FromTVItemID select c).FirstOrDefault(); if (TVItemFromTVItemID == null) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "FromTVItemID", tvItemLink.FromTVItemID.ToString()), new[] { "FromTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Root, TVTypeEnum.Address, TVTypeEnum.Area, TVTypeEnum.ClimateSite, TVTypeEnum.Contact, TVTypeEnum.Country, TVTypeEnum.Email, TVTypeEnum.File, TVTypeEnum.HydrometricSite, TVTypeEnum.Infrastructure, TVTypeEnum.MikeScenario, TVTypeEnum.MikeSource, TVTypeEnum.Municipality, TVTypeEnum.MWQMSite, TVTypeEnum.PolSourceSite, TVTypeEnum.Province, TVTypeEnum.Sector, TVTypeEnum.Subsector, TVTypeEnum.Tel, TVTypeEnum.TideSite, TVTypeEnum.WasteWaterTreatmentPlant, TVTypeEnum.LiftStation, TVTypeEnum.Spill, TVTypeEnum.BoxModel, TVTypeEnum.VisualPlumesScenario, TVTypeEnum.OtherInfrastructure, TVTypeEnum.MWQMRun, TVTypeEnum.MeshNode, TVTypeEnum.WebTideNode, TVTypeEnum.SamplingPlan, TVTypeEnum.SeeOtherMunicipality, TVTypeEnum.LineOverflow, TVTypeEnum.MapInfo, TVTypeEnum.MapInfoPoint, }; if (!AllowableTVTypes.Contains(TVItemFromTVItemID.TVType)) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "FromTVItemID", "Root,Address,Area,ClimateSite,Contact,Country,Email,File,HydrometricSite,Infrastructure,MikeScenario,MikeSource,Municipality,MWQMSite,PolSourceSite,Province,Sector,Subsector,Tel,TideSite,WasteWaterTreatmentPlant,LiftStation,Spill,BoxModel,VisualPlumesScenario,OtherInfrastructure,MWQMRun,MeshNode,WebTideNode,SamplingPlan,SeeOtherMunicipality,LineOverflow,MapInfo,MapInfoPoint"), new[] { "FromTVItemID" })); } } TVItem TVItemToTVItemID = (from c in db.TVItems where c.TVItemID == tvItemLink.ToTVItemID select c).FirstOrDefault(); if (TVItemToTVItemID == null) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "ToTVItemID", tvItemLink.ToTVItemID.ToString()), new[] { "ToTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Root, TVTypeEnum.Address, TVTypeEnum.Area, TVTypeEnum.ClimateSite, TVTypeEnum.Contact, TVTypeEnum.Country, TVTypeEnum.Email, TVTypeEnum.File, TVTypeEnum.HydrometricSite, TVTypeEnum.Infrastructure, TVTypeEnum.MikeScenario, TVTypeEnum.MikeSource, TVTypeEnum.Municipality, TVTypeEnum.MWQMSite, TVTypeEnum.PolSourceSite, TVTypeEnum.Province, TVTypeEnum.Sector, TVTypeEnum.Subsector, TVTypeEnum.Tel, TVTypeEnum.TideSite, TVTypeEnum.WasteWaterTreatmentPlant, TVTypeEnum.LiftStation, TVTypeEnum.Spill, TVTypeEnum.BoxModel, TVTypeEnum.VisualPlumesScenario, TVTypeEnum.OtherInfrastructure, TVTypeEnum.MWQMRun, TVTypeEnum.MeshNode, TVTypeEnum.WebTideNode, TVTypeEnum.SamplingPlan, TVTypeEnum.SeeOtherMunicipality, TVTypeEnum.LineOverflow, TVTypeEnum.MapInfo, TVTypeEnum.MapInfoPoint, }; if (!AllowableTVTypes.Contains(TVItemToTVItemID.TVType)) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "ToTVItemID", "Root,Address,Area,ClimateSite,Contact,Country,Email,File,HydrometricSite,Infrastructure,MikeScenario,MikeSource,Municipality,MWQMSite,PolSourceSite,Province,Sector,Subsector,Tel,TideSite,WasteWaterTreatmentPlant,LiftStation,Spill,BoxModel,VisualPlumesScenario,OtherInfrastructure,MWQMRun,MeshNode,WebTideNode,SamplingPlan,SeeOtherMunicipality,LineOverflow,MapInfo,MapInfoPoint"), new[] { "ToTVItemID" })); } } retStr = enums.EnumTypeOK(typeof(TVTypeEnum), (int?)tvItemLink.FromTVType); if (!string.IsNullOrWhiteSpace(retStr)) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "FromTVType"), new[] { "FromTVType" })); } retStr = enums.EnumTypeOK(typeof(TVTypeEnum), (int?)tvItemLink.ToTVType); if (!string.IsNullOrWhiteSpace(retStr)) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "ToTVType"), new[] { "ToTVType" })); } if (tvItemLink.StartDateTime_Local != null && ((DateTime)tvItemLink.StartDateTime_Local).Year < 1980) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "StartDateTime_Local", "1980"), new[] { "StartDateTime_Local" })); } if (tvItemLink.EndDateTime_Local != null && ((DateTime)tvItemLink.EndDateTime_Local).Year < 1980) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "EndDateTime_Local", "1980"), new[] { "EndDateTime_Local" })); } if (tvItemLink.StartDateTime_Local > tvItemLink.EndDateTime_Local) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._DateIsBiggerThan_, "EndDateTime_Local", "TVItemLinkStartDateTime_Local"), new[] { "EndDateTime_Local" })); } if (tvItemLink.Ordinal < 0 || tvItemLink.Ordinal > 100) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Ordinal", "0", "100"), new[] { "Ordinal" })); } if (tvItemLink.TVLevel < 0 || tvItemLink.TVLevel > 100) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "TVLevel", "0", "100"), new[] { "TVLevel" })); } if (string.IsNullOrWhiteSpace(tvItemLink.TVPath)) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TVPath"), new[] { "TVPath" })); } if (!string.IsNullOrWhiteSpace(tvItemLink.TVPath) && tvItemLink.TVPath.Length > 250) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "TVPath", "250"), new[] { "TVPath" })); } if (tvItemLink.ParentTVItemLinkID != null) { TVItemLink TVItemLinkParentTVItemLinkID = (from c in db.TVItemLinks where c.TVItemLinkID == tvItemLink.ParentTVItemLinkID select c).FirstOrDefault(); if (TVItemLinkParentTVItemLinkID == null) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItemLink", "ParentTVItemLinkID", (tvItemLink.ParentTVItemLinkID == null ? "" : tvItemLink.ParentTVItemLinkID.ToString())), new[] { "ParentTVItemLinkID" })); } } if (tvItemLink.LastUpdateDate_UTC.Year == 1) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" })); } else { if (tvItemLink.LastUpdateDate_UTC.Year < 1980) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" })); } } TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == tvItemLink.LastUpdateContactTVItemID select c).FirstOrDefault(); if (TVItemLastUpdateContactTVItemID == null) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", tvItemLink.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType)) { tvItemLink.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" })); } } retStr = ""; // added to stop compiling CSSPError if (retStr != "") // will never be true { tvItemLink.HasErrors = true; yield return(new ValidationResult("AAA", new[] { "AAA" })); } }
public bool EnumsNet() => Enums.TryParse <Fruits>(Value, out _);
private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType) { string retStr = ""; Enums enums = new Enums(LanguageRequest); ReportTypeLanguage reportTypeLanguage = validationContext.ObjectInstance as ReportTypeLanguage; reportTypeLanguage.HasErrors = false; if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete) { if (reportTypeLanguage.ReportTypeLanguageID == 0) { reportTypeLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "ReportTypeLanguageID"), new[] { "ReportTypeLanguageID" })); } if (!(from c in db.ReportTypeLanguages select c).Where(c => c.ReportTypeLanguageID == reportTypeLanguage.ReportTypeLanguageID).Any()) { reportTypeLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "ReportTypeLanguage", "ReportTypeLanguageID", reportTypeLanguage.ReportTypeLanguageID.ToString()), new[] { "ReportTypeLanguageID" })); } } ReportType ReportTypeReportTypeID = (from c in db.ReportTypes where c.ReportTypeID == reportTypeLanguage.ReportTypeID select c).FirstOrDefault(); if (ReportTypeReportTypeID == null) { reportTypeLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "ReportType", "ReportTypeID", reportTypeLanguage.ReportTypeID.ToString()), new[] { "ReportTypeID" })); } retStr = enums.EnumTypeOK(typeof(LanguageEnum), (int?)reportTypeLanguage.Language); if (!string.IsNullOrWhiteSpace(retStr)) { reportTypeLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Language"), new[] { "Language" })); } if (string.IsNullOrWhiteSpace(reportTypeLanguage.Name)) { reportTypeLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Name"), new[] { "Name" })); } if (!string.IsNullOrWhiteSpace(reportTypeLanguage.Name) && reportTypeLanguage.Name.Length > 100) { reportTypeLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "Name", "100"), new[] { "Name" })); } retStr = enums.EnumTypeOK(typeof(TranslationStatusEnum), (int?)reportTypeLanguage.TranslationStatusName); if (!string.IsNullOrWhiteSpace(retStr)) { reportTypeLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TranslationStatusName"), new[] { "TranslationStatusName" })); } if (string.IsNullOrWhiteSpace(reportTypeLanguage.Description)) { reportTypeLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Description"), new[] { "Description" })); } if (!string.IsNullOrWhiteSpace(reportTypeLanguage.Description) && reportTypeLanguage.Description.Length > 1000) { reportTypeLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "Description", "1000"), new[] { "Description" })); } retStr = enums.EnumTypeOK(typeof(TranslationStatusEnum), (int?)reportTypeLanguage.TranslationStatusDescription); if (!string.IsNullOrWhiteSpace(retStr)) { reportTypeLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TranslationStatusDescription"), new[] { "TranslationStatusDescription" })); } if (string.IsNullOrWhiteSpace(reportTypeLanguage.StartOfFileName)) { reportTypeLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "StartOfFileName"), new[] { "StartOfFileName" })); } if (!string.IsNullOrWhiteSpace(reportTypeLanguage.StartOfFileName) && reportTypeLanguage.StartOfFileName.Length > 100) { reportTypeLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "StartOfFileName", "100"), new[] { "StartOfFileName" })); } retStr = enums.EnumTypeOK(typeof(TranslationStatusEnum), (int?)reportTypeLanguage.TranslationStatusStartOfFileName); if (!string.IsNullOrWhiteSpace(retStr)) { reportTypeLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TranslationStatusStartOfFileName"), new[] { "TranslationStatusStartOfFileName" })); } if (reportTypeLanguage.LastUpdateDate_UTC.Year == 1) { reportTypeLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" })); } else { if (reportTypeLanguage.LastUpdateDate_UTC.Year < 1980) { reportTypeLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" })); } } TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == reportTypeLanguage.LastUpdateContactTVItemID select c).FirstOrDefault(); if (TVItemLastUpdateContactTVItemID == null) { reportTypeLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", reportTypeLanguage.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType)) { reportTypeLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" })); } } retStr = ""; // added to stop compiling CSSPError if (retStr != "") // will never be true { reportTypeLanguage.HasErrors = true; yield return(new ValidationResult("AAA", new[] { "AAA" })); } }
/// <summary> /// Validate function for all AppTaskLanguageService commands /// </summary> /// <param name="validationContext">System.ComponentModel.DataAnnotations.ValidationContext (Describes the context in which a validation check is performed.)</param> /// <param name="actionDBType">[ActionDBTypeEnum] (CSSPEnums.ActionDBTypeEnum.html) action type to validate</param> /// <returns>IEnumerable of ValidationResult (Where ValidationResult is a container for the results of a validation request.)</returns> private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType) { string retStr = ""; Enums enums = new Enums(LanguageRequest); AppTaskLanguage appTaskLanguage = validationContext.ObjectInstance as AppTaskLanguage; appTaskLanguage.HasErrors = false; if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete) { if (appTaskLanguage.AppTaskLanguageID == 0) { appTaskLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "AppTaskLanguageID"), new[] { "AppTaskLanguageID" })); } if (!(from c in db.AppTaskLanguages select c).Where(c => c.AppTaskLanguageID == appTaskLanguage.AppTaskLanguageID).Any()) { appTaskLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "AppTaskLanguage", "AppTaskLanguageID", appTaskLanguage.AppTaskLanguageID.ToString()), new[] { "AppTaskLanguageID" })); } } AppTask AppTaskAppTaskID = (from c in db.AppTasks where c.AppTaskID == appTaskLanguage.AppTaskID select c).FirstOrDefault(); if (AppTaskAppTaskID == null) { appTaskLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "AppTask", "AppTaskID", appTaskLanguage.AppTaskID.ToString()), new[] { "AppTaskID" })); } retStr = enums.EnumTypeOK(typeof(LanguageEnum), (int?)appTaskLanguage.Language); if (!string.IsNullOrWhiteSpace(retStr)) { appTaskLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Language"), new[] { "Language" })); } if (!string.IsNullOrWhiteSpace(appTaskLanguage.StatusText) && appTaskLanguage.StatusText.Length > 250) { appTaskLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "StatusText", "250"), new[] { "StatusText" })); } if (!string.IsNullOrWhiteSpace(appTaskLanguage.ErrorText) && appTaskLanguage.ErrorText.Length > 250) { appTaskLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "ErrorText", "250"), new[] { "ErrorText" })); } retStr = enums.EnumTypeOK(typeof(TranslationStatusEnum), (int?)appTaskLanguage.TranslationStatus); if (!string.IsNullOrWhiteSpace(retStr)) { appTaskLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TranslationStatus"), new[] { "TranslationStatus" })); } if (appTaskLanguage.LastUpdateDate_UTC.Year == 1) { appTaskLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" })); } else { if (appTaskLanguage.LastUpdateDate_UTC.Year < 1980) { appTaskLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" })); } } TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == appTaskLanguage.LastUpdateContactTVItemID select c).FirstOrDefault(); if (TVItemLastUpdateContactTVItemID == null) { appTaskLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", appTaskLanguage.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType)) { appTaskLanguage.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" })); } } retStr = ""; // added to stop compiling CSSPError if (retStr != "") // will never be true { appTaskLanguage.HasErrors = true; yield return(new ValidationResult("AAA", new[] { "AAA" })); } }