public async Task <Will> GetAsync(int id) { var will = new Will(); try { var a = new AzureDBContext(_imsConfigHelper.MSGGenDB01); var app = a.LincsWills.FirstOrDefault(fi => fi.Id == id); will = new Will() { Id = app.Id, Aliases = app.Aliases, Collection = app.Collection, DateString = app.DateString, Description = app.Description, FirstName = app.FirstName, Occupation = app.Occupation, Place = app.Place, Reference = app.Reference, Surname = app.Surname, Typ = app.Typ.GetValueOrDefault(), Url = app.Url, Year = app.Year }; } catch (Exception e) { will.Error = e.Message; } return(will); }
public MqttClient(DBInterface _interface, DnsEndPoint address, Boolean isWS, String username, String password, String clientID, Boolean isClean, int keepalive, Will will, Boolean isSecured, String certificate, String certificatePassword, ClientListener listener) { this._dbInterface = _interface; this._address = address; this._isWs = isWS; this._username = username; this._password = password; this._clientID = clientID; this._isClean = isClean; this._keepalive = keepalive; this._will = will; this.isSecured = isSecured; this.certificate = certificate; this.certificatePassword = certificatePassword; this._listener = listener; if (this._isWs) { _client = new WSClient(address, isSecured, certificate, certificatePassword, WORKER_THREADS); } else { _client = new TCPClient(address, isSecured, certificate, certificatePassword, WORKER_THREADS); } }
public ConnectPacketTest() { w = new Will(QoSLevel.AtLeastOnce, true, "Test Topic", new EncodedDataField(utf8.GetBytes("Will payload"))); auth = new Authentication("username", "password"); clientID = new EncodedString("Client ID"); cp = new ConnectPacket(clientID, w, auth, true, 5); }
static private IDictionary <Sentence, IDictionary <Will, double> > ObtainBinaryResult(Sije sije, Mce mce, int groupIndex) { IDictionary <Sentence, IDictionary <Will, double> > sic = new Dictionary <Sentence, IDictionary <Will, double> >(); foreach (Sentence sentence in sije.Value.Keys) { IDictionary <Will, double> willForResult = new Dictionary <Will, double>(); #region 根据will //sentence.AnnotaitonGroups[groupIndex].PersonalityDSMaxResult = new Result(sije.CalculateJointBestLabelset(sentence, ref willForResult)); #endregion #region 根据will(更好) Will willOfChar = mce.Value[sentence.Character][Will.strong] >= mce.Value[sentence.Character][Will.weak] ? Will.strong : Will.weak; sentence.AnnotaitonGroups[groupIndex].PeTMResult = new Result(sije.CalculateJointBestLabelset(sentence, willOfChar)); if (willOfChar == Will.strong) { willForResult.Add(Will.strong, sentence.AnnotaitonGroups[groupIndex].PeTMResult.Probability); willForResult.Add(Will.weak, 1 - sentence.AnnotaitonGroups[groupIndex].PeTMResult.Probability); } else { willForResult.Add(Will.strong, 1 - sentence.AnnotaitonGroups[groupIndex].PeTMResult.Probability); willForResult.Add(Will.weak, sentence.AnnotaitonGroups[groupIndex].PeTMResult.Probability); } #endregion sic.Add(sentence, willForResult); } return(sic); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private void VisitMemberAs <TMember>(MemberBase member, Will willFlag, Action <TMember> visitAction) where TMember : MemberBase { if (m_Will.HasFlag(willFlag)) { visitAction((TMember)member); } }
static void Main(string[] args) { List <ITeammate> FrontEnd = new List <ITeammate>() { new Leah(), new Natasha(), new Seth() }; List <ITeammate> BackEnd = new List <ITeammate>(); Robert Robert = new Robert(); Aaron Aaron = new Aaron(); Will Will = new Will(); BackEnd.Add(Robert); BackEnd.Add(Will); BackEnd.Add(Aaron); foreach (ITeammate member in FrontEnd) { member.Work(); } foreach (ITeammate member in BackEnd) { member.Work(); } }
void OnTriggerExit2D(Collider2D other) { if (other.tag == "Player" && other.name == "Will") { Will willScript = other.GetComponent <Will>(); willScript.SetGuardTarget(null); } }
private void Start() { Music(); will = FindObjectOfType <Will>(); if (will != null) { will.delWillSounds += AudioWall; } }
public Connect(String username, String password, String clientID, Boolean isClean, Int32 keepalive, Will will) { this._username = username; this._password = password; this._clientID = clientID; this._cleanSession = isClean; this._keepalive = keepalive; this._will = will; }
private void Start() { will = (Will)FindObjectOfType(typeof(Will)); initialDistance = Vector3.Distance(instanceT.localPosition, winConditionT.localPosition); sliderDistance.maxValue = initialDistance; lastDistance = sliderDistance.minValue; //Recibe evento de Will will.OnProgressLvl += CalulateDistance; }
public void TransToPersonalityResult(Will will) { if (will == Will.strong) { foreach (Label label in this.Labels.Keys.ToArray()) { if (this.Labels[label] && PersonalityVariable.WeakAffects.Contains(label)) { if (PersonalityVariable.ExchangeLabel == ExchangeLabel.Yes) { switch (label) { case Label.fondness: this.Labels[Label.happiness] = true; break; case Label.sadness: this.Labels[Label.anger] = true; break; } } this.Labels[label] = false;//无替换 } } } else { foreach (Label label in this.Labels.Keys.ToArray()) { if (this.Labels[label] && PersonalityVariable.StrongAffects.Contains(label)) { switch (label) { case Label.happiness: this.Labels[Label.fondness] = true; break; case Label.anger: this.Labels[Label.sadness] = true; break; } this.Labels[label] = false;//无替换 } } } }
public CoapClient(DBInterface _interface, DnsEndPoint address, String username, String password, String clientID, Boolean isClean, int keepalive, Will will, Boolean isSecured, String certificate, String certificatePassword, ClientListener listener) { this._dbInterface = _interface; this._address = address; this._username = username; this._password = password; this._clientID = clientID; this._isClean = isClean; this._keepalive = keepalive; this._will = will; this._listener = listener; this.isSecured = isSecured; this.certificate = certificate; this.certificatePassword = certificatePassword; _client = new UDPClient(address, isSecured, certificate, certificatePassword, WORKER_THREADS, keepalive * 1000); }
public void WillQoSEncoded() { var AtMostOnceWill = new Will(QoSLevel.AtMostOnce, false, "Test Will", new EncodedDataField(utf8.GetBytes("Test Will"))); byte AtMostOnceflags = GetFlagsFromHeader(new ConnectVariableHeader(AtMostOnceWill)); Assert.IsTrue((AtMostOnceflags & 0x18) == 0); var AtLeastOnceWill = new Will(QoSLevel.AtLeastOnce, false, "Test Will", new EncodedDataField(utf8.GetBytes("Test Will"))); byte AtLeastOnceflags = GetFlagsFromHeader(new ConnectVariableHeader(AtLeastOnceWill)); Assert.IsTrue((AtLeastOnceflags & 0x18) == 0x08); var ExactlyOnceWill = new Will(QoSLevel.ExactlyOnce, false, "Test Will", new EncodedDataField(utf8.GetBytes("Test Will"))); byte ExactlyOnceflags = GetFlagsFromHeader(new ConnectVariableHeader(ExactlyOnceWill)); Assert.IsTrue((ExactlyOnceflags & 0x18) == 0x18); }
private void initConnect() { DnsEndPoint endp = new DnsEndPoint(_account.ServerHost, _account.ServerPort); Will will = null; if (_account.Will != null && _account.Will.Length > 0) { will = new Will(new mqtt.avps.Topic(_account.WillTopic, _account.QOS), _account.Will, _account.IsRetain); } _dbInterface = new EntityFrameworkDBInterface(_account); switch (_account.Protocol) { case iotbroker.dal.Protocols.AMQP_PROTOCOL: _client = new AmqpClient(_dbInterface, endp, _account.UserName, _account.Pass, _account.ClientID, _account.CleanSession, _account.KeepAlive, will, _account.IsSecured, _account.certificate, _account.certificatePass, this); break; case iotbroker.dal.Protocols.COAP_PROTOCOL: _client = new CoapClient(_dbInterface, endp, _account.UserName, _account.Pass, _account.ClientID, _account.CleanSession, _account.KeepAlive, will, _account.IsSecured, _account.certificate, _account.certificatePass, this); break; case iotbroker.dal.Protocols.MQTT_PROTOCOL: _client = new MqttClient(_dbInterface, endp, false, _account.UserName, _account.Pass, _account.ClientID, _account.CleanSession, _account.KeepAlive, will, _account.IsSecured, _account.certificate, _account.certificatePass, this); break; case iotbroker.dal.Protocols.MQTT_SN_PROTOCOL: _client = new SNClient(_dbInterface, endp, _account.UserName, _account.Pass, _account.ClientID, _account.CleanSession, _account.KeepAlive, will, _account.IsSecured, _account.certificate, _account.certificatePass, this); break; case iotbroker.dal.Protocols.WS_PROTOCOL: _client = new MqttClient(_dbInterface, endp, true, _account.UserName, _account.Pass, _account.ClientID, _account.CleanSession, _account.KeepAlive, will, _account.IsSecured, _account.certificate, _account.certificatePass, this); break; } bool channelCreated = _client.createChannel(); if (!channelCreated) { MessageBox.Show("An error occured while trying to create channel for " + _account.ServerHost + ":" + _account.ServerPort); progressBar.Value = 0; progressText.Text = "Channel establishment failed"; _dbInterface.UnmarkAsDefault(_account); LoadingForm_Load(this, null); return; } }
public void Will_msg_encoded_when_provided() { EncodedString clientID = new EncodedString("test 1"); EncodedString willTopic = new EncodedString("Will Topic"); EncodedDataField willMsg = new EncodedDataField(utf8.GetBytes("Will Message")); Will w = new Will(QoSLevel.AtMostOnce, false, willTopic, willMsg); IByteEncodable cp = new ConnectPayload(clientID, w); IEnumerable <byte> encodedBytes = cp.Encode(); string encodedMsg = utf8.GetString( new EncodedDataField( encodedBytes.Skip(clientID.Length + 2) .Skip(willTopic.Length + 4) .ToArray())); Assert.IsTrue(utf8.GetString(willMsg.Data.ToArray()) == encodedMsg); }
void Awake() { reference = transform; playerObject = Instantiate(skinInfo.skins[GameController.Instance.currentSkin].skinModel, reference.position, reference.rotation); playerObject.AddComponent <Will>(); will = playerObject.GetComponent <Will>(); animOverr = new AnimatorOverrideController(will._anim.runtimeAnimatorController); clipOverr = new AnimationClipOverrides(animOverr.overridesCount); animOverr.GetOverrides(clipOverr); clipOverr["InCannon"] = skinInfo.skins[GameController.Instance.currentSkin].animations[0]; clipOverr["Flying"] = skinInfo.skins[GameController.Instance.currentSkin].animations[1]; clipOverr["Falling"] = skinInfo.skins[GameController.Instance.currentSkin].animations[2]; animOverr.ApplyOverrides(clipOverr); will._anim.runtimeAnimatorController = animOverr; }
public Guid?Post(WillVm willVm) { try { var will = new Will() { WillStatus = willVm.WillStatus, UserName = willVm.UserName, UpdatedUtc = DateTime.UtcNow }; return(_willService.AddOrUpdate(will)); } catch (Exception e) { _logger.LogWarning("WillVmService Post exception", e.Message); return(null); } }
// Use this for initialization void Start() { mainCam = Camera.main; GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); foreach (GameObject go in players) { if (go.name == "Will") { will = go.GetComponent <Will>(); } else if (go.name == "Wei") { wei = go.GetComponent <Wei>(); } } SetPlayerWei(); }
public void Will_topic_encoded_when_provided() { EncodedString willTopic = "Will Topic"; Will w = new Will( QoSLevel.AtMostOnce, false, willTopic.Value, new EncodedDataField(utf8.GetBytes("Will Message"))); EncodedString clientID = "test 1"; IByteEncodable cp = new ConnectPayload(clientID, w); IEnumerable <byte> encodedBytes = cp.Encode(); EncodedString encodedTopic = new EncodedString( new MemoryStream( encodedBytes.Skip(clientID.Encode().Count()).ToArray())); Assert.IsTrue(willTopic == encodedTopic); }
private void Awake() { anim = GetComponent <Animator>(); anim.runtimeAnimatorController = Resources.Load("AnimControllers/PlayerController") as RuntimeAnimatorController; m_SpriteRenderer = GetComponent <SpriteRenderer>(); m_Rigidbody = GetComponent <Rigidbody>(); mCollider = GetComponent <Collider>(); m_Rigidbody.constraints = RigidbodyConstraints.FreezePositionZ; if (will == null) { will = this; DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } }
public ConnectVariableHeader(Will will = null, Authentication auth = null, bool cleanSession = true, UInt16 keepAliveTime = 0) { WillRetain = false; WillFlag = false; WillQoS = QoSLevel.AtMostOnce; if (will != null) { WillRetain = will.Retain; WillFlag = true; WillQoS = will.QoS; } HasUsername = false; HasPassword = false; if (auth != null) { HasUsername = (auth.Username != null); HasPassword = (auth.Password != null); } CleanSession = cleanSession; KeepAliveTime = keepAliveTime; }
public Guid?AddOrUpdate(Will will) { try { if (will.Id.IsGuidEmpty()) { //Add var resultWill = _repository.Add(will); return(resultWill?.Id); } else { //Update _repository.Update(will); return(will.Id); } } catch (Exception ex) { _logger.LogWarning($"WillsService : Error saving {will.Id}", ex.Message); return(null); } }
protected override void OnModelCreating(ModelBuilder modelBuilder) { //Player modelBuilder.Entity <Player>().ToTable("players"); modelBuilder.Entity <Player>().Property(m => m.Id).HasColumnName("playerid"); modelBuilder.Entity <Player>().Property(m => m.Username).HasColumnName("username"); modelBuilder.Entity <Player>().Property(m => m.Password).HasColumnName("password"); modelBuilder.Entity <Player>().Property(m => m.Salt).HasColumnName("salt"); modelBuilder.Entity <Player>().HasKey(m => m.Id); //Add Password, salt #region Character //Character modelBuilder.Entity <Character>().ToTable("character"); modelBuilder.Entity <Character>().Property(m => m.PlayerId).HasColumnName("playerid"); modelBuilder.Entity <Character>().Property(m => m.Id).HasColumnName("characterid"); modelBuilder.Entity <Character>().HasKey(m => m.Id); modelBuilder.Entity <Character>().Property(m => m.Name).HasColumnName("character_name"); modelBuilder.Entity <Character>().Property(m => m.RaceName).HasColumnName("race"); modelBuilder.Entity <Character>().Ignore(m => m.Class); modelBuilder.Entity <Character>().Ignore(m => m.EffectiveLevel); modelBuilder.Entity <Character>().Ignore(m => m.Deity); //Add to DB modelBuilder.Entity <Character>().Ignore(m => m.Homeland); modelBuilder.Entity <Character>().Ignore(m => m.Feats); modelBuilder.Entity <Character>().Ignore(m => m.Spellbook); modelBuilder.Entity <Character>().Property(m => m.Alignment).HasColumnName("alignment").HasConversion(v => v.ToString(), v => (Alignment)Enum.Parse(typeof(Alignment), v)); #region abilities modelBuilder.Entity <Character>(m => { m.OwnsOne(e => e.Strength, Ability => { Ability.Property(e => e.BaseScore).HasColumnName("base_str"); Ability.Ignore(e => e.BaseModifier); // Property(e => e.BaseModifier).HasColumnName("str_mod"); Ability.Property(e => e.TempScore).HasColumnName("temp_str"); Ability.Ignore(e => e.TempModifier); // Property(e => e.TempModifier).HasColumnName("temp_str_mod"); Ability.Ignore(e => e.Modifier); Ability.Ignore(e => e.RacialModifier); Ability.Ignore(e => e.TotalScore); }); }); modelBuilder.Entity <Character>(m => { m.OwnsOne(e => e.Dexterity, Ability => { Ability.Property(e => e.BaseScore).HasColumnName("base_dex"); Ability.Ignore(e => e.BaseModifier); // Property(e => e.BaseModifier).HasColumnName("dex_mod"); Ability.Property(e => e.TempScore).HasColumnName("temp_dex"); Ability.Ignore(e => e.TempModifier); // Property(e => e.TempModifier).HasColumnName("temp_dex_mod"); Ability.Ignore(e => e.Modifier); Ability.Ignore(e => e.RacialModifier); Ability.Ignore(e => e.TotalScore); }); }); modelBuilder.Entity <Character>(m => { m.OwnsOne(e => e.Constitution, Ability => { Ability.Property(e => e.BaseScore).HasColumnName("base_con"); Ability.Ignore(e => e.BaseModifier); // Property(e => e.BaseModifier).HasColumnName("con_mod"); Ability.Property(e => e.TempScore).HasColumnName("temp_con"); Ability.Ignore(e => e.TempModifier); // Property(e => e.TempModifier).HasColumnName("temp_con_mod"); Ability.Ignore(e => e.Modifier); Ability.Ignore(e => e.RacialModifier); Ability.Ignore(e => e.TotalScore); }); }); modelBuilder.Entity <Character>(m => { m.OwnsOne(e => e.Intelligence, Ability => { Ability.Property(e => e.BaseScore).HasColumnName("base_int"); Ability.Ignore(e => e.BaseModifier); // Property(e => e.BaseModifier).HasColumnName("int_mod"); Ability.Property(e => e.TempScore).HasColumnName("temp_int"); Ability.Ignore(e => e.TempModifier); // Property(e => e.TempModifier).HasColumnName("temp_int_mod"); Ability.Ignore(e => e.Modifier); Ability.Ignore(e => e.RacialModifier); Ability.Ignore(e => e.TotalScore); }); }); modelBuilder.Entity <Character>(m => { m.OwnsOne(e => e.Wisdom, Ability => { Ability.Property(e => e.BaseScore).HasColumnName("base_wis"); Ability.Ignore(e => e.BaseModifier); // Property(e => e.BaseModifier).HasColumnName("wis_mod"); Ability.Property(e => e.TempScore).HasColumnName("temp_wis"); Ability.Ignore(e => e.TempModifier); // Property(e => e.TempModifier).HasColumnName("temp_wis_mod"); Ability.Ignore(e => e.Modifier); Ability.Ignore(e => e.RacialModifier); Ability.Ignore(e => e.TotalScore); }); }); modelBuilder.Entity <Character>(m => { m.OwnsOne(e => e.Charisma, Ability => { Ability.Property(e => e.BaseScore).HasColumnName("base_cha"); Ability.Ignore(e => e.BaseModifier); // Property(e => e.BaseModifier).HasColumnName("cha_mod"); Ability.Property(e => e.TempScore).HasColumnName("temp_cha"); Ability.Ignore(e => e.TempModifier); // Property(e => e.TempModifier).HasColumnName("temp_cha_mod"); Ability.Ignore(e => e.Modifier); Ability.Ignore(e => e.RacialModifier); Ability.Ignore(e => e.TotalScore); }); }); #endregion modelBuilder.Entity <Character>().Property(m => m.Experience).HasColumnName("experience"); modelBuilder.Entity <Character>().Ignore(m => m.Size); //modelBuilder.Entity<Character>().Property(m => m.Size).HasColumnName("size").HasConversion(v => v.ToString(), v => (Size)Enum.Parse(typeof(Size), v)); modelBuilder.Entity <Character>().Property(m => m.Gender).HasColumnName("gender"); modelBuilder.Entity <Character>().Property(m => m.Age).HasColumnName("age"); modelBuilder.Entity <Character>().Property(m => m.Height).HasColumnName("height"); modelBuilder.Entity <Character>().Property(m => m.Weight).HasColumnName("weight"); modelBuilder.Entity <Character>().Property(m => m.Hair).HasColumnName("hair"); modelBuilder.Entity <Character>().Property(m => m.Eyes).HasColumnName("eyes"); modelBuilder.Entity <Character>().Property(m => m.Homeland).HasColumnName("homeland"); modelBuilder.Entity <Character>().Property(m => m.Deity).HasColumnName("deity"); #region AC modelBuilder.Entity <Character>(m => { m.OwnsOne(e => e.AC, AC => { AC.Property(m => m.Armour).HasColumnName("ac_armour_bonus"); AC.Property(m => m.Shield).HasColumnName("ac_shield_bonus"); AC.Property(m => m.NaturalArmour).HasColumnName("ac_natural_armour"); AC.Property(m => m.Deflection).HasColumnName("ac_deflection"); //AC.Property(m => m.).HasColumnName("ac_temp_armour"); //TODO Reavluate whether needed, and add field/database AC.Property(m => m.Misc).HasColumnName("ac_misc"); //Ignore the totals, since they don't have a getter. //TODO: Remove from Database. AC.Ignore(m => m.Total); AC.Ignore(m => m.Touch); AC.Ignore(m => m.FlatFooted); //Not added to Database yet. AC.Ignore(m => m.TouchMisc); AC.Ignore(m => m.FlatFootedMisc); AC.Ignore(m => m.Note); //Ignore since it has no setter //TODO remove from database AC.Ignore(m => m.Dex); AC.Ignore(m => m.Size); }); }); #endregion #region Hit Points modelBuilder.Entity <Character>(m => { m.OwnsOne(e => e.HitPoints, HP => { HP.Property(m => m.MaxHitPoints).HasColumnName("hp_total"); HP.Property(m => m.CurrentHitPoints).HasColumnName("hp_current"); HP.Property(m => m.NonLethalDamage).HasColumnName("hp_non_lethal"); HP.Property(m => m.Wounds).HasColumnName("hp_wounds"); }); }); #endregion #region Saves #region Fortitude modelBuilder.Entity <Character>(m => { m.OwnsOne(e => e.Fortitude, Fortitude => { Fortitude.Ignore(m => m.Total); Fortitude.Ignore(m => m.Base); Fortitude.Ignore(m => m.Ability); Fortitude.Property(m => m.Magic).HasColumnName("fortitude_magic_mod"); Fortitude.Property(m => m.Temporary).HasColumnName("fortitude_temp"); Fortitude.Property(m => m.Misc).HasColumnName("fortitude_misc_mod"); Fortitude.Property(m => m.Note).HasColumnName("fortitude_note"); }); }); #endregion #region Reflex modelBuilder.Entity <Character>(m => { m.OwnsOne(e => e.Reflex, Reflex => { Reflex.Ignore(m => m.Total); Reflex.Ignore(m => m.Base); Reflex.Ignore(m => m.Ability); Reflex.Property(m => m.Magic).HasColumnName("reflex_magic_mod"); Reflex.Property(m => m.Temporary).HasColumnName("reflex_temp"); Reflex.Property(m => m.Misc).HasColumnName("reflex_misc_mod"); Reflex.Property(m => m.Note).HasColumnName("reflex_note"); }); }); #endregion #region Will modelBuilder.Entity <Character>(m => { m.OwnsOne(e => e.Will, Will => { Will.Ignore(m => m.Total); Will.Ignore(m => m.Base); Will.Ignore(m => m.Ability); Will.Property(m => m.Magic).HasColumnName("will_magic_mod"); Will.Property(m => m.Temporary).HasColumnName("will_temp"); Will.Property(m => m.Misc).HasColumnName("will_misc_mod"); Will.Property(m => m.Note).HasColumnName("will_note"); }); }); #endregion #endregion modelBuilder.Entity <Character>().Property(m => m.DamageReduction).HasColumnName("damage_reduction"); modelBuilder.Entity <Character>().Property(m => m.SpellResistance).HasColumnName("spell_resistance"); modelBuilder.Entity <Character>().Property(m => m.Resistance).HasColumnName("resistance"); modelBuilder.Entity <Character>().Property(m => m.Immunity).HasColumnName("immunity"); modelBuilder.Entity <Character>().Ignore(m => m.BaseAttackBonus); //TODO: Remove from DB, since it has no setter, and gets info from the class. Maybe change to Misc attack bonus? //Property(m => m.BaseAttackBonus).HasColumnName("bab"); // modelBuilder.Entity<Character>().Property(m => m.BaseAttackBonus).HasColumnName("range_bab"); // modelBuilder.Entity<Character>().Property(m => m.BaseAttackBonus).HasColumnName("melee_bab"); #region Combat Maneuver Bonus (CMB) modelBuilder.Entity <Character>(m => { m.OwnsOne(e => e.CMB, CMB => { //Ignored since they don't have settersm since they rely on information from the character CMB.Ignore(m => m.Total); CMB.Ignore(m => m.BaseAttackBonus); CMB.Ignore(m => m.Strength); CMB.Ignore(m => m.Size); CMB.Property(m => m.Misc).HasColumnName("cmb_misc"); CMB.Property(m => m.Temp).HasColumnName("cmb_temp"); CMB.Property(m => m.Note).HasColumnName("cmb_note"); }); }); #endregion #region Combat Maneuver Defence (CMD) modelBuilder.Entity <Character>(m => { m.OwnsOne(e => e.CMD, CMD => { //Ignored since they don't have settersm since they rely on information from the character CMD.Ignore(m => m.Total); CMD.Ignore(m => m.BaseAttackBonus); CMD.Ignore(m => m.Strength); CMD.Ignore(m => m.Dexterity); CMD.Ignore(m => m.Size); CMD.Property(m => m.Misc).HasColumnName("cmd_misc"); CMD.Property(m => m.Temp).HasColumnName("cmd_temp"); CMD.Property(m => m.Note).HasColumnName("cmd_note"); }); }); #endregion modelBuilder.Entity <Character>().Ignore(m => m.Initiative); modelBuilder.Entity <Character>().Property(m => m.InitiativeMiscModifier).HasColumnName("initiative_misc"); #region Speed modelBuilder.Entity <Character>(m => { m.OwnsOne(e => e.Speed, Speed => { //Gets value from race. Speed.Ignore(m => m.Base); Speed.Property(m => m.BaseModifier).HasColumnName("speed_base"); //TODO Add to DB. Speed.Ignore(m => m.BaseTempModifier); //Property(m => m.BaseTempModifier).HasColumnName("speed_base_temporary"); Speed.Property(m => m.Armour).HasColumnName("speed_armour"); Speed.Property(m => m.Fly).HasColumnName("speed_fly"); Speed.Property(m => m.Swim).HasColumnName("speed_swim"); Speed.Property(m => m.Climb).HasColumnName("speed_climb"); Speed.Property(m => m.Burrow).HasColumnName("speed_burrow"); Speed.Property(m => m.Temporary).HasColumnName("speed_misc"); }); }); #endregion modelBuilder.Entity <Character>().Property(m => m.Languages).HasColumnName("languages"); modelBuilder.Entity <Character>().Property(m => m.Platinum).HasColumnName("platinum"); modelBuilder.Entity <Character>().Property(m => m.Gold).HasColumnName("gold"); modelBuilder.Entity <Character>().Property(m => m.Silver).HasColumnName("silver"); modelBuilder.Entity <Character>().Property(m => m.Copper).HasColumnName("copper"); modelBuilder.Entity <Character>().Property(m => m.Note).HasColumnName("notes"); #region Skills // modelBuilder.Entity<Character>().Ignore(m => m.Acrobatic); #endregion #endregion #region Spells //Spells modelBuilder.Entity <Spell>().ToTable("spells"); modelBuilder.Entity <Spell>().Property(m => m.Id).HasColumnName("spellid").IsRequired(true); modelBuilder.Entity <Spell>().Property(m => m.Name).HasColumnName("spell_name").IsRequired(true); modelBuilder.Entity <Spell>().Property(m => m.School).HasColumnName("school"); modelBuilder.Entity <Spell>().Property(m => m.SubSchool).HasColumnName("subschool"); modelBuilder.Entity <Spell>().Property(m => m.Element).HasColumnName("element"); modelBuilder.Entity <Spell>().Property(m => m.ShortDescription).HasColumnName("short_description"); modelBuilder.Entity <Spell>().Property(m => m.SpellLevel).HasColumnName("spell_level"); modelBuilder.Entity <Spell>().Property(m => m.CastingTime).HasColumnName("casting_time"); modelBuilder.Entity <Spell>().Property(m => m.Components).HasColumnName("components"); modelBuilder.Entity <Spell>().Property(m => m.Range).HasColumnName("range"); modelBuilder.Entity <Spell>().Property(m => m.Area).HasColumnName("area"); modelBuilder.Entity <Spell>().Property(m => m.Effect).HasColumnName("effect"); modelBuilder.Entity <Spell>().Property(m => m.Target).HasColumnName("targets"); modelBuilder.Entity <Spell>().Property(m => m.Duration).HasColumnName("duration"); modelBuilder.Entity <Spell>().Property(m => m.SavingThrow).HasColumnName("saving_throw"); modelBuilder.Entity <Spell>().Property(m => m.SpellResistance).HasColumnName("spell_resistence"); //Note name modelBuilder.Entity <Spell>().Property(m => m.Description).HasColumnName("description"); modelBuilder.Entity <Spell>().Property(m => m.Domain).HasColumnName("domain"); modelBuilder.Entity <Spell>().Property(m => m.Bloodline).HasColumnName("bloodline"); modelBuilder.Entity <Spell>().Property(m => m.Patron).HasColumnName("patron"); modelBuilder.Entity <Spell>().Property(m => m.Dismissible).HasColumnName("dismissible"); modelBuilder.Entity <Spell>().Property(m => m.Shapeable).HasColumnName("shapeable"); modelBuilder.Entity <Spell>().Property(m => m.Verbal).HasColumnName("verbal"); modelBuilder.Entity <Spell>().Property(m => m.Somatic).HasColumnName("somatic"); modelBuilder.Entity <Spell>().Property(m => m.Material).HasColumnName("material"); modelBuilder.Entity <Spell>().Property(m => m.Focus).HasColumnName("focus"); modelBuilder.Entity <Spell>().Property(m => m.DivineFocus).HasColumnName("divine_focus"); modelBuilder.Entity <Spell>().Property(m => m.CostlyComponent).HasColumnName("costly_components"); modelBuilder.Entity <Spell>().Property(m => m.MaterialCost).HasColumnName("material_costs"); modelBuilder.Entity <Spell>().Property(m => m.Source).HasColumnName("source"); modelBuilder.Entity <Spell>().Property(m => m.DescriptionFormatted).HasColumnName("description_formated"); modelBuilder.Entity <Spell>().Property(m => m.FullText).HasColumnName("full_text"); modelBuilder.Entity <Spell>().HasKey(m => m.Id); /* Won't work until I either make another class, or gather the tables * modelBuilder.Entity<Spell>().ToTable("spell_classes"); * modelBuilder.Entity<Spell>().Property(m => m.Bard).HasColumnName("bard"); * modelBuilder.Entity<Spell>().Property(m => m.Cleric).HasColumnName("cleric"); * modelBuilder.Entity<Spell>().Property(m => m.Druid).HasColumnName("druid"); * modelBuilder.Entity<Spell>().Property(m => m.Paladin).HasColumnName("paladin"); * modelBuilder.Entity<Spell>().Property(m => m.Ranger).HasColumnName("ranger"); * modelBuilder.Entity<Spell>().Property(m => m.Sorcerer).HasColumnName("sorcerer"); * modelBuilder.Entity<Spell>().Property(m => m.Wizard).HasColumnName("wizard"); */ /* Additional columns * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("alchemist"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("summoner"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("oracle"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("witch"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("inquisitor"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("antipaladin"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("magus"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("adept"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("bloodrager"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("shaman"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("skald"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("investigator"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("hunter"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("sla_level"); */ /* Spell types * modelBuilder.Entity<Spell>().ToTable("spell_types"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("acid"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("air"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("chaotic"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("cold"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("curse"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("darkness"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("death"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("disease"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("earth"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("electricity"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("emotion"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("evil"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("fear"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("fire"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("force"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("good"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("language_dependent"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("lawful"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("light"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("mind_affecting"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("pain"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("poison"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("shadow"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("sonic"); * modelBuilder.Entity<Spell>().Property(m => m.).HasColumnName("water"); */ #endregion #region Known spells modelBuilder.Entity <KnownSpell>().ToTable("characterspells"); modelBuilder.Entity <KnownSpell>().Property(m => m.CharacterId).HasColumnName("characterid").IsRequired(true); modelBuilder.Entity <KnownSpell>().Property(s => s.SpellId).HasColumnName("spellid"); modelBuilder.Entity <KnownSpell>().Property(s => s.SpellLevel).HasColumnName("spell_level"); modelBuilder.Entity <KnownSpell>().Property(s => s.Prepared).HasColumnName("prepared"); modelBuilder.Entity <KnownSpell>().Property(s => s.Note).HasColumnName("note"); modelBuilder.Entity <KnownSpell>().Ignore(s => s.Spell); modelBuilder.Entity <KnownSpell>().HasKey(m => new { m.CharacterId, m.SpellId }); #endregion #region Feats //Feats modelBuilder.Entity <Feat>().ToTable("feats"); modelBuilder.Entity <Feat>().Property(m => m.Id).HasColumnName("featid").IsRequired(true); modelBuilder.Entity <Feat>().Property(m => m.Name).HasColumnName("feat_name").IsRequired(true); modelBuilder.Entity <Feat>().Property(m => m.Type).HasColumnName("feat_type"); modelBuilder.Entity <Feat>().Property(m => m.Description).HasColumnName("description"); modelBuilder.Entity <Feat>().Property(m => m.Prerequisites).HasColumnName("prerequisites"); modelBuilder.Entity <Feat>().Property(m => m.PrerequisiteFeats).HasColumnName("prerequisite_feats"); modelBuilder.Entity <Feat>().Property(m => m.Benefit).HasColumnName("benefit"); modelBuilder.Entity <Feat>().Property(m => m.Normal).HasColumnName("normal"); modelBuilder.Entity <Feat>().Property(m => m.Special).HasColumnName("special"); modelBuilder.Entity <Feat>().Property(m => m.FullText).HasColumnName("fulltext"); modelBuilder.Entity <Feat>().Property(m => m.Multiples).HasColumnName("multiples"); modelBuilder.Entity <Feat>().Property(m => m.PrerequisiteSkills).HasColumnName("prerequisite_skills"); modelBuilder.Entity <Feat>().Property(m => m.RaceNames).HasColumnName("race_name"); modelBuilder.Entity <Feat>().Property(m => m.Source).HasColumnName("source"); modelBuilder.Entity <Feat>().HasKey(m => m.Id); #endregion modelBuilder.Entity <CharacterFeats>().ToTable("characterfeats"); modelBuilder.Entity <CharacterFeats>().Property(m => m.CharacterId).HasColumnName("characterid").IsRequired(true); modelBuilder.Entity <CharacterFeats>().Property(m => m.FeatId).HasColumnName("featid").IsRequired(true); modelBuilder.Entity <CharacterFeats>().Property(m => m.Choice).HasColumnName("choice"); modelBuilder.Entity <CharacterFeats>().Property(m => m.Multiple).HasColumnName("multiple"); modelBuilder.Entity <CharacterFeats>().Property(m => m.Note).HasColumnName("note"); modelBuilder.Entity <CharacterFeats>().HasKey(m => new { m.CharacterId, m.FeatId, m.Choice }); modelBuilder.Entity <CharacterFeats>().Ignore(m => m.Feat); modelBuilder.Entity <CharacterFeats>().Ignore(m => m.FeatName); #region Special Abilities //Special Abilities modelBuilder.Entity <SpecialAbility>().ToTable("specialabilities"); modelBuilder.Entity <SpecialAbility>().Property(m => m.Id).HasColumnName("said").IsRequired(true); modelBuilder.Entity <SpecialAbility>().Property(m => m.Name).HasColumnName("special_ability"); modelBuilder.Entity <SpecialAbility>().Property(m => m.Description).HasColumnName("description"); modelBuilder.Entity <SpecialAbility>().Property(m => m.Type).HasColumnName("type"); modelBuilder.Entity <SpecialAbility>().Property(m => m.Category).HasColumnName("category"); modelBuilder.Entity <SpecialAbility>().Property(m => m.ClassName).HasColumnName("class"); modelBuilder.Entity <SpecialAbility>().Property(m => m.Source).HasColumnName("source"); modelBuilder.Entity <SpecialAbility>().HasKey(m => m.Id); #endregion #region Race //Race modelBuilder.Entity <Race>().ToTable("races"); modelBuilder.Entity <Race>().Property(m => m.Name).HasColumnName("race_name").IsRequired(true); modelBuilder.Entity <Race>().Property(m => m.Size).HasColumnName("size").HasConversion(v => v.ToString(), v => (Size)Enum.Parse(typeof(Size), v)); modelBuilder.Entity <Race>().Property(m => m.Speed).HasColumnName("speed"); modelBuilder.Entity <Race>().Property(m => m.LanguagesKnown).HasColumnName("known_languages"); modelBuilder.Entity <Race>().Property(m => m.LanguagesAvailable).HasColumnName("available_languages"); modelBuilder.Entity <Race>().Property(m => m.Strength).HasColumnName("str"); modelBuilder.Entity <Race>().Property(m => m.Dexterity).HasColumnName("dex"); modelBuilder.Entity <Race>().Property(m => m.Constitution).HasColumnName("con"); modelBuilder.Entity <Race>().Property(m => m.Intelligence).HasColumnName("int"); modelBuilder.Entity <Race>().Property(m => m.Wisdom).HasColumnName("wis"); modelBuilder.Entity <Race>().Property(m => m.Charisma).HasColumnName("cha"); modelBuilder.Entity <Race>().Property(m => m.SpecialModifier).HasColumnName("varied_attribute"); modelBuilder.Entity <Race>().Property(m => m.Description).HasColumnName("race_description"); modelBuilder.Entity <Race>().HasKey(m => m.Name); #endregion #region Classes //Class modelBuilder.Entity <Class>().ToTable("classes"); modelBuilder.Entity <Class>().Property(m => m.Name).HasColumnName("class"); modelBuilder.Entity <Class>().Property(m => m.HitDie).HasColumnName("hit_die"); modelBuilder.Entity <Class>().Property(m => m.ClassSkills).HasColumnName("class_skills"); modelBuilder.Entity <Class>().Property(m => m.SkillsPerLevel).HasColumnName("skills"); modelBuilder.Entity <Class>().Property(m => m.ArmourProficiency).HasColumnName("armour_proficiency"); modelBuilder.Entity <Class>().Property(m => m.WeaponProficiency).HasColumnName("weapon_proficiency"); modelBuilder.Entity <Class>().Property(m => m.Spells).HasColumnName("spells"); modelBuilder.Entity <Class>().Ignore(m => m.source); //Property(m => m.source).HasColumnName("source"); modelBuilder.Entity <Class>().HasKey(m => m.Name); #endregion modelBuilder.Entity <CharacterClasses>().ToTable("characterclasses"); modelBuilder.Entity <CharacterClasses>().Property(m => m.CharacterId).HasColumnName("characterid"); modelBuilder.Entity <CharacterClasses>().Property(m => m.ClassName).HasColumnName("class"); modelBuilder.Entity <CharacterClasses>().Property(m => m.Level).HasColumnName("level"); modelBuilder.Entity <CharacterClasses>().HasKey(m => new { m.CharacterId, m.ClassName }); modelBuilder.Entity <ClassInfo>().ToTable("class_levels"); modelBuilder.Entity <ClassInfo>().Property(m => m.ClassName).HasColumnName("class"); modelBuilder.Entity <ClassInfo>().Property(m => m.Level).HasColumnName("level"); modelBuilder.Entity <ClassInfo>().Property(m => m.BaseAttackBonus).HasColumnName("base_attack_bonus"); modelBuilder.Entity <ClassInfo>().Property(m => m.BaseFortitude).HasColumnName("fortitude"); modelBuilder.Entity <ClassInfo>().Property(m => m.BaseReflex).HasColumnName("reflex"); modelBuilder.Entity <ClassInfo>().Property(m => m.BaseWill).HasColumnName("will"); modelBuilder.Entity <ClassInfo>().Property(m => m.Specials).HasColumnName("special"); //TODO Add spells modelBuilder.Entity <ClassInfo>().HasKey(m => new { m.ClassName, m.Level }); #region Queries /* * RETURNS TABLE("spellid" int4, "spell_name" varchar, "short_description" text, "description" text, "school" varchar, * "subschool" varchar, "element" varchar, "domain" text, "bloodline" text, "patron" text, "source" "public"."sources") * */ modelBuilder.Query <SpellSearchResult>().Property(x => x.SpellId).HasColumnName("spellid"); modelBuilder.Query <SpellSearchResult>().Property(x => x.Name).HasColumnName("spell_name"); modelBuilder.Query <SpellSearchResult>().Property(x => x.ShortDescription).HasColumnName("short_description"); #endregion }
public Customer GetByWill(Will will) { var spec = new CustomerSpecification(will); return(_repository.GetSingleBySpec(spec)); }
//指定will public KeyValuePair <Labelset, double> CalculateJointBestLabelset(Sentence sentence, Will will) { Labelset bestResult = new Labelset(Variable.LabelArray, 0); double bestResultValue = 0; foreach (Labelset subAnnotaton in this.Value[sentence].Keys)//此处决定了Sij.Value的Key不可以是Tuple<Sentence, Labelset>类型 { if (this.Value[sentence][subAnnotaton][will] > bestResultValue) { bestResult = new Labelset(subAnnotaton); bestResultValue = this.Value[sentence][subAnnotaton][will]; } else if (this.Value[sentence][subAnnotaton][will] == bestResultValue) { foreach (Label label in subAnnotaton.Labels.Keys) { if (subAnnotaton.Labels[label]) { bestResult.Labels[label] = true; } } } } return(new KeyValuePair <Labelset, double>(bestResult, bestResultValue)); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- protected ImplementationConvention(Will will) { m_Will = will; }
/// <exception cref="MalformedMessageException">Exception is thrown in case of invalid packet format</exception> public static MQMessage Decode(IByteBuffer buf) { MQMessage header = null; byte fixedHeader = buf.ReadByte(); LengthDetails length = DecodeLength(buf); MessageType type = (MessageType)((fixedHeader >> 4) & 0xf); switch (type) { case MessageType.CONNECT: Byte[] nameValue = new byte[buf.ReadUnsignedShort()]; buf.ReadBytes(nameValue, 0, nameValue.Length); String name = Encoding.UTF8.GetString(nameValue); if (!name.Equals(Connect.PROTOCOL_NAME)) { throw new MalformedMessageException("CONNECT, protocol-name set to " + name); } Byte protocolLevel = buf.ReadByte(); Byte contentFlags = buf.ReadByte(); Boolean userNameFlag = (((contentFlags >> 7) & 1) == 1) ? true : false; Boolean userPassFlag = (((contentFlags >> 6) & 1) == 1) ? true : false; Boolean willRetain = (((contentFlags >> 5) & 1) == 1) ? true : false; Int32 QOSValue = ((contentFlags & 0x1f) >> 3) & 3; QOS willQos = (QOS)QOSValue; if (!Enum.IsDefined(typeof(QOS), QOSValue)) { throw new MalformedMessageException("CONNECT, will QoS set to " + willQos); } Boolean willFlag = (((contentFlags >> 2) & 1) == 1) ? true : false; if (willQos != QOS.AT_MOST_ONCE && !willFlag) { throw new MalformedMessageException("CONNECT, will QoS set to " + willQos + ", willFlag not set"); } if (willRetain && !willFlag) { throw new MalformedMessageException("CONNECT, will retain set, willFlag not set"); } Boolean cleanSession = (((contentFlags >> 1) & 1) == 1) ? true : false; Boolean reservedFlag = ((contentFlags & 1) == 1) ? true : false; if (reservedFlag) { throw new MalformedMessageException("CONNECT, reserved flag set to true"); } int keepalive = buf.ReadUnsignedShort(); Byte[] clientIdValue = new byte[buf.ReadUnsignedShort()]; buf.ReadBytes(clientIdValue, 0, clientIdValue.Length); String clientID = Encoding.UTF8.GetString(clientIdValue); if (!StringVerifier.verify(clientID)) { throw new MalformedMessageException("ClientID contains restricted characters: U+0000, U+D000-U+DFFF"); } String willTopic = null; Byte[] willMessage = null; String username = null; String password = null; Will will = null; if (willFlag) { if (buf.ReadableBytes < 2) { throw new MalformedMessageException("Invalid encoding will/username/password"); } byte[] willTopicValue = new byte[buf.ReadUnsignedShort()]; if (buf.ReadableBytes < willTopicValue.Length) { throw new MalformedMessageException("Invalid encoding will/username/password"); } buf.ReadBytes(willTopicValue, 0, willTopicValue.Length); willTopic = Encoding.UTF8.GetString(willTopicValue); if (!StringVerifier.verify(willTopic)) { throw new MalformedMessageException("WillTopic contains one or more restricted characters: U+0000, U+D000-U+DFFF"); } if (buf.ReadableBytes < 2) { throw new MalformedMessageException("Invalid encoding will/username/password"); } willMessage = new byte[buf.ReadUnsignedShort()]; if (buf.ReadableBytes < willMessage.Length) { throw new MalformedMessageException("Invalid encoding will/username/password"); } buf.ReadBytes(willMessage, 0, willMessage.Length); if (willTopic.Length == 0) { throw new MalformedMessageException("invalid will encoding"); } will = new Will(new Topic(willTopic, willQos), willMessage, willRetain); if (!will.IsValid()) { throw new MalformedMessageException("invalid will encoding"); } } if (userNameFlag) { if (buf.ReadableBytes < 2) { throw new MalformedMessageException("Invalid encoding will/username/password"); } byte[] userNameValue = new byte[buf.ReadUnsignedShort()]; if (buf.ReadableBytes < userNameValue.Length) { throw new MalformedMessageException("Invalid encoding will/username/password"); } buf.ReadBytes(userNameValue, 0, userNameValue.Length); username = Encoding.UTF8.GetString(userNameValue); if (!StringVerifier.verify(username)) { throw new MalformedMessageException("Username contains one or more restricted characters: U+0000, U+D000-U+DFFF"); } } if (userPassFlag) { if (buf.ReadableBytes < 2) { throw new MalformedMessageException("Invalid encoding will/username/password"); } byte[] userPassValue = new byte[buf.ReadUnsignedShort()]; if (buf.ReadableBytes < userPassValue.Length) { throw new MalformedMessageException("Invalid encoding will/username/password"); } buf.ReadBytes(userPassValue, 0, userPassValue.Length); password = Encoding.UTF8.GetString(userPassValue); if (!StringVerifier.verify(password)) { throw new MalformedMessageException("Password contains one or more restricted characters: U+0000, U+D000-U+DFFF"); } } if (buf.ReadableBytes > 0) { throw new MalformedMessageException("Invalid encoding will/username/password"); } Connect connect = new Connect(username, password, clientID, cleanSession, keepalive, will); if (protocolLevel != 4) { connect.ProtocolLevel = protocolLevel; } header = connect; break; case MessageType.CONNACK: byte sessionPresentValue = buf.ReadByte(); if (sessionPresentValue != 0 && sessionPresentValue != 1) { throw new MalformedMessageException("CONNACK, session-present set to " + (sessionPresentValue & 0xff)); } Boolean isPresent = sessionPresentValue == 1 ? true : false; Int32 connackByte = ((Int32)buf.ReadByte()) & 0xFF; ConnackCode connackCode = (ConnackCode)connackByte; if (!Enum.IsDefined(typeof(ConnackCode), connackByte)) { throw new MalformedMessageException("Invalid connack code: " + connackByte); } header = new Connack(isPresent, connackCode); break; case MessageType.PUBLISH: int dataLength = length.Length; fixedHeader &= 0xf; Boolean dup = (((fixedHeader >> 3) & 1) == 1) ? true : false; QOSValue = (fixedHeader & 0x07) >> 1; QOS qos = (QOS)QOSValue; if (!Enum.IsDefined(typeof(QOS), (byte)QOSValue)) { throw new MalformedMessageException("invalid QoS value"); } if (dup && qos == QOS.AT_MOST_ONCE) { throw new MalformedMessageException("PUBLISH, QoS-0 dup flag present"); } Boolean retain = ((fixedHeader & 1) == 1) ? true : false; byte[] topicNameValue = new byte[buf.ReadUnsignedShort()]; buf.ReadBytes(topicNameValue, 0, topicNameValue.Length); String topicName = Encoding.UTF8.GetString(topicNameValue); if (!StringVerifier.verify(topicName)) { throw new MalformedMessageException("Publish-topic contains one or more restricted characters: U+0000, U+D000-U+DFFF"); } dataLength -= topicName.Length + 2; Int32?packetID = null; if (qos != QOS.AT_MOST_ONCE) { packetID = buf.ReadUnsignedShort(); if (packetID < 0 || packetID > 65535) { throw new MalformedMessageException("Invalid PUBLISH packetID encoding"); } dataLength -= 2; } byte[] data = new byte[dataLength]; if (dataLength > 0) { buf.ReadBytes(data, 0, data.Length); } header = new Publish(packetID, new Topic(topicName, qos), data, retain, dup); break; case MessageType.PUBACK: header = new Puback(buf.ReadUnsignedShort()); break; case MessageType.PUBREC: header = new Pubrec(buf.ReadUnsignedShort()); break; case MessageType.PUBREL: header = new Pubrel(buf.ReadUnsignedShort()); break; case MessageType.PUBCOMP: header = new Pubcomp(buf.ReadUnsignedShort()); break; case MessageType.SUBSCRIBE: Int32 subID = buf.ReadUnsignedShort(); List <Topic> subscriptions = new List <Topic>(); while (buf.IsReadable()) { byte[] value = new byte[buf.ReadUnsignedShort()]; buf.ReadBytes(value, 0, value.Length); QOSValue = buf.ReadByte(); QOS requestedQos = (QOS)QOSValue; if (!Enum.IsDefined(typeof(QOS), QOSValue)) { throw new MalformedMessageException("Subscribe qos must be in range from 0 to 2: " + requestedQos); } String topic = Encoding.UTF8.GetString(value); if (!StringVerifier.verify(topic)) { throw new MalformedMessageException("Subscribe topic contains one or more restricted characters: U+0000, U+D000-U+DFFF"); } Topic subscription = new Topic(topic, requestedQos); subscriptions.Add(subscription); } if (subscriptions.Count == 0) { throw new MalformedMessageException("Subscribe with 0 topics"); } header = new Subscribe(subID, subscriptions.ToArray()); break; case MessageType.SUBACK: Int32 subackID = buf.ReadUnsignedShort(); List <SubackCode> subackCodes = new List <SubackCode>(); while (buf.IsReadable()) { Int32 subackByte = ((Int32)buf.ReadByte()) & 0xFF; SubackCode subackCode = (SubackCode)subackByte; if (!Enum.IsDefined(typeof(SubackCode), subackByte)) { throw new MalformedMessageException("Invalid suback code: " + subackByte); } subackCodes.Add(subackCode); } if (subackCodes.Count == 0) { throw new MalformedMessageException("Suback with 0 return-codes"); } header = new Suback(subackID, subackCodes); break; case MessageType.UNSUBSCRIBE: Int32 unsubID = buf.ReadUnsignedShort(); List <String> unsubscribeTopics = new List <String>(); while (buf.IsReadable()) { byte[] value = new byte[buf.ReadUnsignedShort()]; buf.ReadBytes(value, 0, value.Length); String topic = Encoding.UTF8.GetString(value); if (!StringVerifier.verify(topic)) { throw new MalformedMessageException("Unsubscribe topic contains one or more restricted characters: U+0000, U+D000-U+DFFF"); } unsubscribeTopics.Add(topic); } if (unsubscribeTopics.Count == 0) { throw new MalformedMessageException("Unsubscribe with 0 topics"); } header = new Unsubscribe(unsubID, unsubscribeTopics.ToArray()); break; case MessageType.UNSUBACK: header = new Unsuback(buf.ReadUnsignedShort()); break; case MessageType.PINGREQ: header = new Pingreq(); break; case MessageType.PINGRESP: header = new Pingresp(); break; case MessageType.DISCONNECT: header = new Disconnect(); break; default: throw new MalformedMessageException("Invalid header type: " + type); } if (buf.IsReadable()) { throw new MalformedMessageException("unexpected bytes in content"); } if (length.Length != header.GetLength()) { throw new MalformedMessageException("Invalid length. Encoded: " + length.Length + ", actual: " + header.GetLength()); } return(header); }
public void ProcessConnect(Boolean cleanSession, int keepalive, Will will) { throw new CoreLogicException("received invalid message connect"); }
public ConnectPayload(EncodedString clientID, Will w = null, Authentication auth = null) { _clientID = clientID; _w = w; _auth = auth; }
public CustomerSpecification(Will will) : base(c => c.Will.Id.Equals(will.Id)) { }