public void Test3() { var include = EnumFlags.ToQueryString(TestFlags.Value1 | TestFlags.Value2); //var temp = EnumFlags.Parse<TestFlags>(new[] {"value-1", "Value3"}, StringComparer.InvariantCulture); Assert.IsNotNull(include); }
public ThreadProperties() { ESide = new EnumFlags <Thread.Side>(Thread.Side.Inside); ThreadData threads = new ThreadData(); threads.AddThreads(); ThreadSizes = new DataView(Thread.data) { AllowNew = false, AllowDelete = false, AllowEdit = false }; Type = Thread.type.First().Key; CompoundAngles = new List <double>(); CompoundAngles.Add(0d); CompoundAngles.Add(29d); CompoundAngles.Add(29.5d); CompoundAngles.Add(30d); DepthDegressions = new List <double>(); DepthDegressions.Add(0); DepthDegressions.Add(1); DepthDegressions.Add(2); }
public void Read(IO.EndianReader s) { s.Owner = this; Flags = s.Read(FileFlagsStreamer.Instance); Version = s.ReadUInt16(); if (Version != kVersion) { throw new IO.VersionMismatchException(s.BaseStream, kVersion, Version); } Read(s, EnumFlags.Test(Flags, FileFlags.EncryptHeader), Header, MediaHeader.kSizeOf); GenerateHash(); if (EnumFlags.Test(Flags, FileFlags.CompressContent)) { using (var cs = new CompressedStream(true)) { Read(s, EnumFlags.Test(Flags, FileFlags.EncryptContent), cs, userKey: Header.DataCryptKey, readLeftovers: ReadLeftovers); cs.Decompress(); Content = cs.UncompressedData; } } else { Content = s.ReadBytes((int)(s.BaseStream.Length - s.BaseStream.Position)); } }
public void Serialize(IO.BitStream s) { s.Stream(ref Modifiers, Bits.kInt64BitCount, WeaponModifiersBitStreamer.Instance); if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value0)) { s.Stream(ref mValue0, 0f, 1f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value1)) { s.Stream(ref mValue1, 0f, 1f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value2)) { s.Stream(ref mValue2, 0f, 1f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value3)) { s.Stream(ref mValue3, 0f, 1f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value4)) { s.Stream(ref mValue4, 0f, 1f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value5)) { s.Stream(ref mValue5, 0f, 1.5706964f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value6)) { s.Stream(ref mValue6, 0f, 1000f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value7)) { s.Stream(ref mValue7, 0f, 1000f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value8)) { s.Stream(ref mValue8, 0f, 1000f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value9)) { s.Stream(ref mValue9, 0f, 1.5706964f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value10)) { s.Stream(ref mValue10, 0f, 1000f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value11)) { s.Stream(ref mValue11, 0f, 1000f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value12)) { s.Stream(ref mValue12, 0f, 1000f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value13)) { s.Stream(ref mValue13, 0f, 6.2831855f, 20, true, true); } }
public void Write(IO.EndianWriter s) { //Flags = EnumFlags.Remove(Flags, FileFlags.EncryptHeader | FileFlags.EncryptContent); s.Write(Flags, FileFlagsStreamer.Instance); s.Write((ushort)kVersion); Write(s, EnumFlags.Test(Flags, FileFlags.EncryptHeader), Header, MediaHeader.kSizeOf); GenerateHash(); if (EnumFlags.Test(Flags, FileFlags.CompressContent)) { using (var cs = new CompressedStream(true)) using (var ms = new System.IO.MemoryStream(kMaxContentSize)) using (var sout = new IO.EndianWriter(ms, Shell.EndianFormat.Big)) { sout.Write(Content); sout.Seek(0); cs.InitializeFromStream(ms); cs.Compress(); Write(s, EnumFlags.Test(Flags, FileFlags.EncryptContent), cs, userKey: Header.DataCryptKey, writeLeftovers: WriteLeftovers); } } else { s.Write(Content); } }
public void Serialize(IO.EndianStream s) { s.Owner = this; if (s.IsWriting) { //Flags = EnumFlags.Remove(Flags, FileFlags.EncryptHeader | FileFlags.EncryptContent); } s.Stream(ref Flags, FileFlagsStreamer.Instance); s.StreamVersion(kVersion); Stream(s, EnumFlags.Test(Flags, FileFlags.EncryptHeader), Header, MediaHeader.kSizeOf); GenerateHash(); if (EnumFlags.Test(Flags, FileFlags.CompressContent)) { StreamCompressedContent(s); } else { if (s.IsReading) { Content = new byte[(int)(s.BaseStream.Length - s.BaseStream.Position)]; } s.Stream(Content); } }
/// <inheritdoc cref="IBlogApiClient.GetStoriesAsync" /> public async Task <ListResult <StoryModel, ResourcesMetaInfo> > GetStoriesAsync(StoryIncludes flags) { var path = new Uri(baseUri, "stories"); var include = EnumFlags.ToQueryString(flags); var query = QueryString.Create(nameof(include), include); var requestUri = new UriBuilder(path) { Query = query.ToUriComponent() }.Uri; try { using (var response = await client.GetAsync(requestUri, CancellationToken.None)) { response.EnsureSuccessStatusCode(); var json = await response.Content.ReadAsStringAsync(); var data = Json.Deserialize <ListResult <StoryModel, ResourcesMetaInfo> >(json); return(data); } } catch (HttpRequestException exception) { return(new ListResult <StoryModel, ResourcesMetaInfo>()); } }
void StreamCompressedContent(IO.EndianStream s) { if (s.IsReading) { using (var cs = new CompressedStream(true)) { Stream(s, EnumFlags.Test(Flags, FileFlags.EncryptContent), cs, userKey: Header.DataCryptKey, streamLeftovers: StreamLeftovers); cs.Decompress(); Content = cs.UncompressedData; } } else if (s.IsWriting) { using (var cs = new CompressedStream(true)) using (var ms = new System.IO.MemoryStream(kMaxContentSize)) using (var sout = new IO.EndianWriter(ms, s.ByteOrder)) { sout.Write(Content); sout.Seek(0); cs.InitializeFromStream(ms); cs.Compress(); Stream(s, EnumFlags.Test(Flags, FileFlags.EncryptContent), cs, userKey: Header.DataCryptKey, streamLeftovers: StreamLeftovers); } } }
public void Enum_FlagsTest() { FlagsEnum e = FlagsEnum.Flag0 | FlagsEnum.Flag2; Assert.IsTrue(EnumFlags.Test(e, FlagsEnum.Flag2)); Assert.IsTrue(EnumFlags.Test(e, FlagsEnum.Flag0 | FlagsEnum.Flag2)); }
public ThreadProperties() { ESide = new EnumFlags <Thread.Side>(Thread.Side.Inside); ThreadData threads = new ThreadData(); threads.AddThreads(); ThreadSizes = new DataView(Thread.data) { AllowNew = false, AllowDelete = false, AllowEdit = false }; // Type = Thread.type.First().Key; CompoundAngles = new List <double>(); CompoundAngles.Add(0d); CompoundAngles.Add(29d); CompoundAngles.Add(29.5d); CompoundAngles.Add(30d); DepthDegressions = new List <string>(); DepthDegressions.Add("None"); DepthDegressions.Add("1"); DepthDegressions.Add("2"); _depthDegression = "None"; PropertyChanged += Thread_PropertyChanged; }
/// <inheritdoc cref="IBlogApiClient.GetStoriesAsync" /> public async Task <LandingModel> GetLandingAsync(LandingIncludes flags) { var path = new Uri(baseUri, "landing"); var include = EnumFlags.ToQueryString(flags); var query = QueryString.Create(nameof(include), include); var requestUri = new UriBuilder(path) { Query = query.ToUriComponent() }.Uri; try { if (null != authorizationToken) { client.SetBearerToken(authorizationToken.Token); } using (var response = await client.GetAsync(requestUri, CancellationToken.None)) { response.EnsureSuccessStatusCode(); var json = await response.Content.ReadAsStringAsync(); var data = Json.Deserialize <LandingModel>(json); return(data); } } catch (HttpRequestException) { return(new LandingModel()); } }
//'UserEntersFlagsEnum' -> [ ] [x] [x] [ ] [x] [ ] (words with checkbox infront of the word) protected Enum UserEntersFlagsEnum(Item item, T target) { Enum originalEnum = GetEnum <Enum>(item, target); EnumFlags flags = new EnumFlags(originalEnum); int index = 0; int zero = -1; for (int i = 0; i < flags.NumValues; ++i) { if (flags.IsZero(i)) { zero = i; break; } } ConsoleKeyInfo key; do { Thread.Sleep(conf.DelayMilliSeconds); RenderList4(flags, index, zero); key = Console.ReadKey(); if (key.Key == ConsoleKey.UpArrow || key.Key == ConsoleKey.PageUp || key.Key == ConsoleKey.LeftArrow) { index = (index == 0) ? flags.NumValues - 1 : index - 1; } else if (key.Key == ConsoleKey.DownArrow || key.Key == ConsoleKey.PageDown || key.Key == ConsoleKey.RightArrow) { index = (index == flags.NumValues - 1) ? 0 : index + 1; } else if (key.Key == ConsoleKey.Enter || key.Key == ConsoleKey.Spacebar) { if (index == zero) { if (flags.HasAnySet(true)) { flags.SetAllFlags(false); } else { flags.SetAllFlags(true); } } else { flags.SetFlag(index, !flags.GetFlag(index)); } } else if (key.Key == ConsoleKey.Escape) { return(flags.Create()); } }while (true); }
protected void RenderList4(EnumFlags flags, int current, int zero) { Console.BackgroundColor = conf.BackColor; Console.Clear(); for (int i = 0; i < flags.NumValues; ++i) { RenderWord4(flags.GetFlag(i), flags.GetName(i), flags.GetIntValue(i), i, current, zero); } }
void ParameterSet(bool value, MegaloScriptObjectFilterValidParameters param) { EnumFlags.Modify(value, ref mValidParameters, param); int index = Bits.TrailingZerosCount((uint)param); NotifyPropertyChanged(kParameterChanged[index]); NotifyPropertyChanged(kHasParametersChanged); }
/// <summary> /// Plays the sound in an available mixer with the desired pitch. /// </summary> /// <param name="player"></param> /// <param name="sound"></param> /// <param name="pitch"></param> public void PlaySound(MixerPlayer player, AudioClip sound, float pitch, bool enableLooping) { foreach (Mixer m in mixers) { if (EnumFlags <MixerPlayer> .HasFlag(m.player, player)) { m.PlaySound(sound, pitch, enableLooping); } } }
/// <summary> /// Adds management interface flags to enable on a specified Certification Authority. Multiple /// flags can be added at the time. /// </summary> /// <param name="flags">One or more flags defined in <see cref="InterfaceFlagEnum"/> enumeration.</param> public void Add(InterfaceFlagEnum flags) { Int32[] existing = EnumFlags.GetEnabled(typeof(InterfaceFlagEnum), (Int32)InterfaceFlags); Int32[] newf = EnumFlags.GetEnabled(typeof(InterfaceFlagEnum), (Int32)flags); foreach (Int32 item in newf.Where(item => !EnumFlags.Contains(existing, item))) { InterfaceFlags = (InterfaceFlagEnum)((Int32)InterfaceFlags + item); IsModified = true; } }
/// <summary> /// Unmutes the sent mixer. /// </summary> /// <param name="player"></param> public void UnMute(MixerPlayer player) { foreach (Mixer m in mixers) { if (EnumFlags <MixerPlayer> .HasFlag(m.player, player)) { m.UnMute(); } } }
/// <summary> /// Will cancel or close any existing sound based on the shortest time left in one of the mixers. Will also adjust the mixer to the desired pitch. /// </summary> /// <param name="player"></param> /// <param name="sound"></param> /// <param name="pitch"></param> public void PlaySoundOverride(MixerPlayer player, AudioClip sound, float pitch) { foreach (Mixer m in mixers) { if (EnumFlags <MixerPlayer> .HasFlag(m.player, player)) { m.OverridePlaySound(sound, pitch); } } }
/// <summary> /// Plays a Combined sound into one of the mixer groups, will try to find a group that is using the closest pitch. /// </summary> /// <param name="player"></param> /// <param name="sound"></param> /// <param name="pitch"></param> public void PlaySoundCombined(MixerPlayer player, AudioClip sound, float pitch) { foreach (Mixer m in mixers) { if (EnumFlags <MixerPlayer> .HasFlag(m.player, player)) { m.PlayCombinedSound(sound, pitch); } } }
/// <summary> /// Removes policy module flags from a specified Certification Authority. Multiple /// flags can be removed at the time. /// </summary> /// <param name="flags">One or more flags defined in <see cref="PolicyModuleFlagEnum"/> enumeration.</param> public void Remove(PolicyModuleFlagEnum flags) { Int32[] existing = EnumFlags.GetEnabled(typeof(PolicyModuleFlagEnum), (Int32)EditFlags); Int32[] newf = EnumFlags.GetEnabled(typeof(PolicyModuleFlagEnum), (Int32)flags); foreach (Int32 item in newf.Where(item => EnumFlags.Contains(existing, item))) { EditFlags = (PolicyModuleFlagEnum)((Int32)EditFlags - item); IsModified = true; } }
/// <summary> /// Removes Certificate Revocation List (CRL) flags from a specified Certification Authority. Multiple /// flags can be removed at the time. /// </summary> /// <param name="flags">One or more flags defined in <see cref="CRLFlagEnum"/> enumeration.</param> public void Remove(CRLFlagEnum flags) { Int32[] existing = EnumFlags.GetEnabled(typeof(CRLFlagEnum), (Int32)CRLFlags); Int32[] newf = EnumFlags.GetEnabled(typeof(CRLFlagEnum), (Int32)flags); foreach (int item in newf.Where(item => EnumFlags.Contains(existing, item))) { CRLFlags = (CRLFlagEnum)((Int32)CRLFlags - item); IsModified = true; } }
/// <summary> /// Adds an outside audio source to the desired player to provide control over that source. /// </summary> /// <param name="player"></param> /// <param name="source"></param> public void AddAudioSourceToMixer(MixerPlayer player, AudioSource source) { foreach (Mixer m in mixers) { if (EnumFlags <MixerPlayer> .HasFlag(m.player, player)) { m.AddSource(source); return; } } }
/// <summary> /// Returns the mixer that is associate with that player. /// </summary> /// <param name="player"></param> /// <returns></returns> public Mixer GetMixer(MixerPlayer player) { foreach (Mixer m in mixers) { if (EnumFlags <MixerPlayer> .HasFlag(m.player, player)) { return(m); } } return(null); }
/// <summary> /// Removes Key Recovery Agent (KRA) flags from a specified Certification Authority. Multiple /// flags can be removed at the time. /// </summary> /// <param name="flags">One or more flags defined in <see cref="KRAFlagEnum"/> enumeration.</param> public void Remove(KRAFlagEnum flags) { Int32[] existing = EnumFlags.GetEnabled(typeof(KRAFlagEnum), (Int32)KRAFlags); Int32[] newf = EnumFlags.GetEnabled(typeof(KRAFlagEnum), (Int32)flags); foreach (Int32 item in newf) { if (EnumFlags.Contains(existing, item)) { KRAFlags = (KRAFlagEnum)((Int32)KRAFlags - item); IsModified = true; } } }
public void Enum_FlagsSansAttributeTest() { try { FlagsEnumSansAttribute e = FlagsEnumSansAttribute.Flag0; // The below statement should throw a TypeInitializationException EnumFlags.Add(ref e, FlagsEnumSansAttribute.Flag2); Assert.Fail("EnumFlags didn't fail on an Enum without a Flags attribute!"); } catch (System.Exception ex) { Assert.IsInstanceOfType(ex.InnerException, typeof(System.NotSupportedException)); } }
/// <summary> /// Stops all other mixer channels sounds over the sent time and plays the AudioClip at the designated pitch and allows looping. /// </summary> /// <param name="player"></param> /// <param name="sound"></param> /// <param name="pitch"></param> /// <param name="seconds"></param> public void TransitionSound(MixerPlayer player, AudioClip sound, float pitch, float seconds, bool enableLooping) { foreach (Mixer m in mixers) { if (EnumFlags <MixerPlayer> .HasFlag(m.player, player)) { AudioSource[] sources = m.MuteAllOverlayPlaySound(sound, pitch, enableLooping); foreach (AudioSource source in sources) { StartCoroutine(MuteSourceOverTime(source, seconds)); } } } }
/// <summary> /// Adjusts the volume of the sent mixer. /// </summary> /// <param name="player"></param> /// <param name="volumeLevel"></param> public void AdjustVolume(MixerPlayer player, float volumeLevel) { if (EnumFlags <MixerPlayer> .HasAllFlags(player, MixerPlayer.Dialog, MixerPlayer.Explosions, MixerPlayer.Instantiations, MixerPlayer.Interactions, MixerPlayer.Movement, MixerPlayer.Music)) { AdjustMasterVolume(volumeLevel); return; } foreach (Mixer m in mixers) { if (EnumFlags <MixerPlayer> .HasFlag(m.player, player)) { m.AdjustVolume(volumeLevel); } } }
public void Enum_FlagsRemoveTest() { ////////////////////////////////////////////////////////////////////////// // Test by-ref const FlagsEnum kExpectedResult1 = FlagsEnum.Flag0; FlagsEnum e1 = FlagsEnum.Flag0 | FlagsEnum.Flag2; EnumFlags.Remove(ref e1, FlagsEnum.Flag2); Assert.AreEqual(kExpectedResult1, e1); ////////////////////////////////////////////////////////////////////////// // Test by-value const FlagsEnum kExpectedResult2 = 0; FlagsEnum e2 = EnumFlags.Remove(e1, FlagsEnum.Flag0); Assert.AreEqual(kExpectedResult2, e2); }
public void Enum_FlagsModifyTest() { ////////////////////////////////////////////////////////////////////////// // Test by-ref const FlagsEnum kExpectedResult1 = FlagsEnum.Flag0 | FlagsEnum.Flag2; FlagsEnum e1 = FlagsEnum.Flag0; EnumFlags.Modify(true, ref e1, FlagsEnum.Flag2); Assert.AreEqual(kExpectedResult1, e1); ////////////////////////////////////////////////////////////////////////// // Test by-value const FlagsEnum kExpectedResult2 = FlagsEnum.Flag2; FlagsEnum e2 = EnumFlags.Modify(false, e1, FlagsEnum.Flag0); Assert.AreEqual(kExpectedResult2, e2); }
void SetImpl <T>(T?newValue, ref T value, WeaponTuningModifiers modifer) where T : struct { var old_flags = Modifiers; int index = Bits.TrailingZerosCount((uint)modifer); EnumFlags.Modify(newValue.HasValue, ref Modifiers, modifer); value = newValue.GetValueOrDefault(); if (old_flags != Modifiers) { NotifyPropertyChanged(kIsUnchangedChanged); } NotifyPropertyChanged(kValueChanged[index]); }