public bool IsMatch(Target target, IonType ionType, int cleavageOffset) { if (!IsFragment) { return(false); } if (!target.IsProteomic) { return(false); // TODO(bspratt) small molecule equivalent? } var sequence = target.Sequence; int ordinal = Transition.OffsetToOrdinal(ionType, cleavageOffset, sequence.Length); if (ordinal < MinFragmentLength) { return(false); } char aaN = Transition.GetFragmentNTermAA(sequence, cleavageOffset); char aaC = Transition.GetFragmentCTermAA(sequence, cleavageOffset); // Make sure the specified amino acid is in the fragment set for this ion char aa = (IsNTerm() ? aaN : aaC); if (Fragment.IndexOf(aa) == -1) { return(false); } // Make suer the adjacent amino acid is not in the restricted set for this ion aa = (IsNTerm() ? aaC : aaN); if (Restrict != null && Restrict.IndexOf(aa) != -1) { return(false); } return(true); }
protected override void OnSizeChanged(int w, int h, int oldw, int oldh) { base.OnSizeChanged(w, h, oldw, oldh); Map.Viewport.Width = w; Map.Viewport.Height = h; Restrict.RestrictZoom(Map.Viewport, Map.Resolutions, Map.Envelope); }
public void Serialize() { // Assign var serializer = new JsonFeatureToggleSerializer(); var condition = Allow.Simple() .Or(Allow.FromDateTime(new DateTime(2019, 05, 16, 15, 0, 0, DateTimeKind.Utc)) .And(Allow.UntilDateTime(new DateTime(2019, 05, 17, 15, 0, 0, DateTimeKind.Utc))) .And(Restrict.DayOfWeek(DayOfWeek.Wednesday)) .And(Restrict.Installation("SAMPLE_INSTALLATION#2")) .And(Restrict.User("USER#2")) .And(Allow.DaysOfWeek(DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday)) .And(Allow.Installation("SAMPLE_INSTALLATION#1")) .And(Allow.User("USER#1")) .And(Restrict.Simple()) .And(Allow.FromTimeOfDay(new TimeSpan(15, 0, 0))) .And(Allow.UntilTimeOfDay(new TimeSpan(16, 0, 0))) ); var featureToggle = new FeatureToggle(); featureToggle.FeatureName = "MyFeature"; featureToggle.Condition = condition; // Act var serialized = serializer.Serialize(featureToggle); // Assert // Assert correctly. Don't read the expected from the static variable but from a static file }
public bool IsMatch(string sequence, IonType ionType, int cleavageOffset) { if (!IsFragment) { return(false); } int ordinal = Transition.OffsetToOrdinal(ionType, cleavageOffset, sequence.Length); if (ordinal < MinFragmentLength) { return(false); } char aaN = Transition.GetFragmentNTermAA(sequence, cleavageOffset); char aaC = Transition.GetFragmentCTermAA(sequence, cleavageOffset); // Make sure the specified amino acid is in the fragment set for this ion char aa = (IsNTerm() ? aaN : aaC); if (Fragment.IndexOf(aa) == -1) { return(false); } // Make suer the adjacent amino acid is not in the restricted set for this ion aa = (IsNTerm() ? aaC : aaN); if (Restrict != null && Restrict.IndexOf(aa) != -1) { return(false); } return(true); }
public void InitFindsProperties() { FileSet fs = new FileSet(); Restrict restrict = new Restrict( fs ); // Init didn't throw, ASSUME we win // Irrelevant but not unhelpful Assert.AreEqual( 0, restrict.NestedFilterCount ); }
/// <summary> /// 指定した公開制限のブックマークで、小説に対して付けたタグのリストを取得します。 /// </summary> /// <param name="restrict"> /// 公開制限 /// </param> /// <returns> /// <see cref="BookmarkTagCollection" /> /// </returns> public async Task <BookmarkTagCollection> NovelAsync(Restrict restrict = Restrict.Public) { Ensure.InvalidEnumValue(restrict == Restrict.All, nameof(restrict)); Ensure.InvalidEnumValue(restrict == Restrict.Mypixiv, nameof(restrict)); var parameters = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("restrict", restrict.ToParameter()) }; return(await PixivClient.GetAsync <BookmarkTagCollection>("https://app-api.pixiv.net/v1/user/bookmark-tags/novel", parameters).Stay()); }
public void ConditionHoldsShouldReturnFalseWhenRightOperandIsFalse() { // Arrange var condition = Allow.Simple().And(Restrict.Simple()); var context = new Context(null, null, null); // Act var conditionHolds = condition.Holds(context); // Assert Assert.False(conditionHolds); }
public void ConditionHoldsShouldReturnTrueWhenRightOperandIsTrue() { // Arrange var condition = Restrict.Simple().Or(Allow.Simple()); var context = new Context(null, null, null); // Act var conditionHolds = condition.Holds(context); // Assert Assert.True(conditionHolds); }
public void FeatureEnabledShouldReturnFalseWhenBothOperandsAreFalse() { // Arrange var condition = Restrict.Simple().Or(Restrict.Simple()); var context = new Context(null, null, null); // Act var conditionHolds = condition.Holds(context); // Assert Assert.False(conditionHolds); }
internal Rch(Rch source, Restrict rt) { //MethWatch mw = new MethWatch("RchFdn.Rch_Rch_Restrict"); fitted = rt.fitted | source.fitted; bl = new Pile <Rch>("", true, this); int sbl = 0; int ebl = 0; int sblPos = 0; int eblPos = 0; source.block4Pos(rt.sPos, rt.ePos, ref sbl, ref ebl, ref sblPos, ref eblPos); if (rt.ePos < rt.sPos) { ebl = sbl; eblPos = sblPos - 1; } if ((rt.sWide) && (sblPos <= 1)) { for (int i = sbl - 1; i > 0; i--) { if (source.bl_Len(i) > 0) { break; } sbl = i; sblPos = 1; } } if ((rt.eWide) && (eblPos >= source.bl_Len(ebl))) { for (int i = ebl + 1; i <= source.bl.Len; i++) { if (source.bl_Len(i) > 0) { break; } ebl = i; eblPos = 0; } } if (sbl == ebl) { mBuf = source.bl[sbl].mBuf; //long sInx = mBuf.sIndex(source.bl[sbl].sLbl); // UNBELIEVABLE!!!! This variation slows doen by 10% !!!!! long sInx = source.bl_sInx(sbl); long sInx = source.bl_sInx(sbl); sLbl = "" + mBuf.sLabel((int)(sInx - 1 + sblPos)); eLbl = "" + mBuf.eLabel((int)(sInx - 1 + eblPos)); mBuf.subscribe(this); } else { bl = source.bl.slice(sbl, ebl); bl[1] = source.bl[sbl].from(sblPos); bl[-1] = source.bl[ebl].upto(eblPos); } upd(); //inf = new long[bl.Count + 1, 3]; //mw._void(); }
/// <summary> /// 指定したユーザーをフォローします。 /// </summary> /// <param name="userId">ユーザー ID</param> /// <param name="restrict">公開制限</param> public async Task AddAsync(long userId, Restrict restrict = Restrict.Public) { Ensure.GreaterThanZero(userId, nameof(userId)); Ensure.InvalidEnumValue(restrict == Restrict.All, nameof(restrict)); Ensure.InvalidEnumValue(restrict == Restrict.Mypixiv, nameof(restrict)); var parameters = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("user_id", userId.ToString()), new KeyValuePair <string, string>("restrict", restrict.ToParameter()) }; await PixivClient.PostAsync("https://app-api.pixiv.net/v1/user/follow/add", parameters); }
public override int GetHashCode() { unchecked { int result = base.GetHashCode(); result = (result * 397) ^ (Fragment != null ? Fragment.GetHashCode() : 0); result = (result * 397) ^ (Restrict != null ? Restrict.GetHashCode() : 0); result = (result * 397) ^ (Terminus.HasValue ? Terminus.Value.GetHashCode() : 0); result = (result * 397) ^ (MinFragmentLength.HasValue ? MinFragmentLength.Value : 0); result = (result * 397) ^ (SettingsCustomIon != null ? SettingsCustomIon.GetHashCode() : 0); result = (result * 397) ^ Charge; result = (result * 397) ^ IsOptional.GetHashCode(); return(result); } }
/// <summary> /// フォローしているユーザーの新着イラストを取得します。 /// </summary> /// <param name="restrict">公開制限</param> /// <param name="offset">オフセット</param> /// <returns> /// <see cref="IllustCollection" /> /// </returns> public async Task <IllustCollection> FollowAsync(Restrict restrict = Restrict.All, long offset = 0) { Ensure.InvalidEnumValue(restrict == Restrict.Mypixiv, nameof(restrict)); var parameters = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("restrict", restrict.ToParameter()) }; if (offset > 0) { parameters.Add(new KeyValuePair <string, string>("offset", offset.ToString())); } return(await PixivClient.GetAsync <IllustCollection>("https://app-api.pixiv.net/v2/illust/follow", parameters).Stay()); }
/// <summary> /// 指定したユーザーの小説ブックマークを取得します。 /// </summary> /// <param name="userId">ユーザー ID</param> /// <param name="restrict">公開制限 (自分以外は Public のみ取得可能)</param> /// <param name="tag">絞り込みタグ (自分に対してのみ使用可能)</param> /// <returns> /// <see cref="NovelCollection" /> /// </returns> public async Task <NovelCollection> NovelAsync(long userId, Restrict restrict = Restrict.Public, string tag = null) { Ensure.GreaterThanZero(userId, nameof(userId)); Ensure.InvalidEnumValue(restrict == Restrict.All, nameof(restrict)); Ensure.InvalidEnumValue(restrict == Restrict.Mypixiv, nameof(restrict)); var parameter = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("user_id", userId.ToString()), new KeyValuePair <string, string>("restrict", restrict.ToParameter()) }; if (!string.IsNullOrWhiteSpace(tag)) { parameter.Add(new KeyValuePair <string, string>("tag", tag)); } return(await PixivClient.GetAsync <NovelCollection>("https://app-api.pixiv.net/v1/user/bookmarks/novel", parameter).Stay()); }
/// <summary> /// 指定したイラストをブックマークに追加します。 /// </summary> /// <param name="illustId">イラスト ID</param> /// <param name="restrict">公開制限</param> /// <param name="tags">タグ</param> public async Task AddAsync(long illustId, Restrict restrict = Restrict.Public, string[] tags = null) { Ensure.GreaterThanZero(illustId, nameof(illustId)); Ensure.InvalidEnumValue(restrict == Restrict.All, nameof(restrict)); Ensure.InvalidEnumValue(restrict == Restrict.Mypixiv, nameof(restrict)); var parameters = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("illust_id", illustId.ToString()), new KeyValuePair <string, string>("restrict", restrict.ToParameter()) }; if (tags?.Length > 0) { parameters.Add(new KeyValuePair <string, string>("tags[]", string.Join(",", tags))); } await PixivClient.PostAsync("https://app-api.pixiv.net/v2/illust/bookmark/add", parameters).Stay(); }
/// <summary> /// <see cref="Restrict" /> を URL クエリパラメータに変換します。 /// </summary> /// <param name="obj"> /// <see cref="Restrict" /> /// </param> /// <returns>変換後文字列</returns> public static string ToParameter(this Restrict obj) { switch (obj) { case Restrict.All: return("all"); case Restrict.Public: return("public"); case Restrict.Private: return("private"); case Restrict.Mypixiv: return("mypixiv"); default: throw new ArgumentOutOfRangeException(nameof(obj), obj, null); } }
public void NestedFilitersInited() { // Arrange MockNestedFilter mock = new MockNestedFilter( true ); List<FilterBase> filters = new List<FilterBase>() { mock }; FileSet fs = new FileSet(); Restrict restrict = new Restrict( filters, fs ); // Irrelevant but not unhelpful Assert.AreEqual( 1, restrict.NestedFilterCount ); // Act restrict.Scan(); // Assert Assert.AreEqual( true, mock.NestedInitializeCalled ); }
public void BaseDirIsFilesBaseDir() { // Arrange List<FilterBase> filters = new List<FilterBase>() { new MockFilter( false ) }; string filename = "somefile"; FileSet fs = new FileSet(); fs.BaseDirectory = new DirectoryInfo( Path.GetDirectoryName( Assembly.GetExecutingAssembly().GetName().CodeBase.Substring( 8 ) ) ); // Get past file:// fs.FileNames.Add( filename ); Restrict restrict = new Restrict( filters, fs ); // Act // Nothing to do, it should be set already // Assert Assert.AreEqual( restrict.BaseDirectory, fs.BaseDirectory ); }
public override string GetPageUrl(int pageIndex) { var query = base.GetPageUrl(pageIndex); query += Action.HasValue ? "&doAction=" + Action : ""; query += DirectoryId.HasValue ? "&dir=" + DirectoryId : ""; query += RootId.HasValue ? "&root=" + RootId : ""; query += Restrict.IsSet() ? "&restrict=" + Restrict : ""; query += GenericFileType.HasValue ? "&fileType=" + GenericFileType : ""; query += UserId.IsSet() ? "&user="******""; query += Id.IsSet() ? "&id=" + Id : ""; query += Entity.IsSet() ? "&entity=" + Entity : ""; query += Field.IsSet() ? "&field=" + Field : ""; query += Type.IsSet() ? "&type=" + Type : ""; query += MediaId.HasValue ? "&media=" + MediaId : ""; return(query); }
/// <summary> /// 指定したユーザーがフォローしているユーザーを取得します。 /// </summary> /// <param name="userId">ユーザー ID</param> /// <param name="restrict">公開制限</param> /// <param name="offset">オフセット</param> /// <param name="filter">フィルター (`for_ios` が有効)</param> /// <returns> /// <see cref="UserPreviewCollection" /> /// </returns> public async Task <UserPreviewCollection> FollowingAsync(long userId, Restrict restrict = Restrict.Public, long offset = 0, string filter = "") { Ensure.GreaterThanZero(userId, nameof(userId)); Ensure.InvalidEnumValue(restrict == Restrict.Mypixiv, nameof(restrict)); var parameters = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("user_id", userId.ToString()), new KeyValuePair <string, string>("restrict", restrict.ToParameter()) }; if (offset > 0) { parameters.Add(new KeyValuePair <string, string>("offset", offset.ToString())); } if (!string.IsNullOrWhiteSpace(filter)) { parameters.Add(new KeyValuePair <string, string>("filter", filter)); } return(await PixivClient.GetAsync <UserPreviewCollection>("https://app-api.pixiv.net/v1/user/following", parameters).Stay()); }
public void ScanThrowsOnNoFiltersDefined() { // Arrange string filename = "harry.jpg"; FileSet fs = new FileSet(); fs.BaseDirectory = new DirectoryInfo( Path.GetDirectoryName( Assembly.GetExecutingAssembly().GetName().CodeBase.Substring( 8 ) ) ); // Get past file:// fs.FileNames.Add( filename ); Restrict restrict = new Restrict( null, fs ); restrict.FailOnEmpty = true; // Irrelevant but not unhelpful Assert.AreEqual( 0, restrict.NestedFilterCount ); Assert.IsFalse( restrict.hasScanned ); // Act try { restrict.Scan(); // Assert Assert.Fail( "No filters didn't throw" ); } catch ( BuildException ex ) { if ( !ex.Message.Contains( "no filters" ) ) { throw; } // It worked } Assert.IsFalse( restrict.hasScanned ); }
public void ScanThrowsOnNoResults() { // Arrange List<FilterBase> filters = new List<FilterBase>() { new MockFilter( false ) }; string filename = "harry.jpg"; FileSet fs = new FileSet(); fs.BaseDirectory = new DirectoryInfo( Path.GetDirectoryName( Assembly.GetExecutingAssembly().GetName().CodeBase.Substring( 8 ) ) ); // Get past file:// fs.FileNames.Add( filename ); Restrict restrict = new Restrict( filters, fs ); restrict.FailOnEmpty = true; // Irrelevant but not unhelpful Assert.AreEqual( 1, restrict.NestedFilterCount ); Assert.IsFalse( restrict.hasScanned ); // Act try { restrict.Scan(); // Assert Assert.Fail( "No results didn't throw" ); } catch ( ValidationException ex ) { if ( !ex.Message.Contains( "No matching files" ) ) { throw; } // It worked } Assert.IsNotNull( restrict.FileNames ); if ( restrict.FileNames.Count != 0 ) { string[] files = new string[restrict.FileNames.Count]; restrict.FileNames.CopyTo( files, 0 ); Assert.Fail( "It should've failed, but we have " + string.Join( ", ", files ) + " selected" ); } Assert.IsTrue( restrict.hasScanned ); }
public void ScanFiltersTrueCorrectly() { // Arrange List<FilterBase> filters = new List<FilterBase>() { new MockFilter( true ) }; string filename = "harry.jpg"; FileSet fs = new FileSet(); fs.BaseDirectory = new DirectoryInfo( Path.GetDirectoryName( Assembly.GetExecutingAssembly().GetName().CodeBase.Substring( 8 ) ) ); // Get past file:// fs.FileNames.Add( filename ); Restrict restrict = new Restrict( filters, fs ); // Irrelevant but not unhelpful Assert.AreEqual( 1, restrict.NestedFilterCount ); // Act restrict.Scan(); // Assert Assert.IsNotNull( restrict.FileNames ); Assert.AreEqual( 1, restrict.FileNames.Count ); Assert.AreEqual( filename, restrict.FileNames[0] ); Assert.IsTrue( restrict.hasScanned ); }
public static Task <IllustsPage> GetFollowedUsersIllustAsync(this PixivClient client, Restrict restrict = Restrict.Public, int offset = 0) { client.RequireAuth(); return(client.GetAsync <IllustsPage>("/v2/illust/follow", new HttpForm { { "restrict", restrict.GetSymbol() }, { "offset", offset.ToString() } })); }
public static Task <IllustsPage> GetUserBookmarksAsync(this PixivClient client, UserID id, Restrict restrict = Restrict.Public) { return(client.GetAsync <IllustsPage>("/v1/user/bookmarks/illust", new HttpForm { { "user_id", id }, { "restrict", restrict.GetSymbol() } })); }
public static Task <UserFollowPage> GetUserFollowersAsync(this PixivClient client, UserID id, Restrict restrict = Restrict.Public) { return(client.GetAsync <UserFollowPage>("/v1/user/follower", new HttpForm { { "user_id", id }, { "restrict", restrict.GetSymbol() } })); }
public static Task <BookmarkTagsPage> GetUserBookmarkTagsAsync(this PixivClient client, Restrict restrict = Restrict.Public) { client.RequireAuth(); return(client.GetAsync <BookmarkTagsPage>("/v1/user/bookmark-tags/illust", new HttpForm { { "restrict", restrict.GetSymbol() } })); }
// TODO support tag public static Task AddIllustBookmarkAsync(this PixivClient client, IllustID id, Restrict restrict = Restrict.Public) { client.RequireAuth(); return(client.PostAsync("/v2/illust/bookmark/add", new HttpForm { { "illust_id", id }, { "restrict", restrict.GetSymbol() } })); }
public void ScanThrowsOnBlankFilename() { // Arrange List<FilterBase> filters = new List<FilterBase>() { new MockFilter( false ) }; string filename = ""; FileSet fs = new FileSet(); fs.BaseDirectory = new DirectoryInfo( Path.GetDirectoryName( Assembly.GetExecutingAssembly().GetName().CodeBase.Substring( 8 ) ) ); // Get past file:// fs.FileNames.Add( filename ); Restrict restrict = new Restrict( filters, fs ); restrict.FailOnEmpty = true; // Irrelevant but not unhelpful Assert.AreEqual( 1, restrict.NestedFilterCount ); Assert.IsFalse( restrict.hasScanned ); // Act try { restrict.Scan(); // Assert Assert.Fail( "No filters didn't throw" ); } catch ( BuildException ex ) { ArgumentNullException innerEx = ex.InnerException as ArgumentNullException; if ( innerEx == null || innerEx.ParamName != "filename" ) { throw; } // It worked } Assert.IsFalse( restrict.hasScanned ); }
public void ScanFiltersFalseCorrectly() { // Arrange List<FilterBase> filters = new List<FilterBase>() { new MockFilter( false ) }; string filename = "harry.jpg"; FileSet fs = new FileSet(); fs.BaseDirectory = new DirectoryInfo( Path.GetDirectoryName( Assembly.GetExecutingAssembly().GetName().CodeBase.Substring( 8 ) ) ); // Get past file:// fs.FileNames.Add( filename ); Restrict restrict = new Restrict( filters, fs ); // Irrelevant but not unhelpful Assert.AreEqual( 1, restrict.NestedFilterCount ); // Act restrict.Scan(); // Assert Assert.IsNotNull( restrict.FileNames ); if ( restrict.FileNames.Count != 0 ) { string[] files = new string[restrict.FileNames.Count]; restrict.FileNames.CopyTo( files, 0 ); Assert.Fail( "It should've failed, but we have " + string.Join( ", ", files ) + " selected" ); } Assert.IsTrue( restrict.hasScanned ); }
internal Reach(Reach source, Restrict rt) : base(source, rt) { init(); }