public void valid(string source, string name) { var rs = new RequestSource(XE.Parse(source)); Assert.Equal(name, rs.Name_.Value); Assert.Equal(name, rs.Name_.ToString()); }
private DownloadAndSaveObjectResult TryDownloadAndSaveObject( string objectId, CancellationToken cancellationToken, RequestSource requestSource, bool retryOnFailure) { if (objectId == GVFSConstants.AllZeroSha) { return(DownloadAndSaveObjectResult.Error); } DateTime negativeCacheRequestTime; if (this.objectNegativeCache.TryGetValue(objectId, out negativeCacheRequestTime)) { if (negativeCacheRequestTime > DateTime.Now.Subtract(NegativeCacheTTL)) { return(DownloadAndSaveObjectResult.ObjectNotOnServer); } this.objectNegativeCache.TryRemove(objectId, out negativeCacheRequestTime); } // To reduce allocations, reuse the same buffer when writing objects in this batch byte[] bufToCopyWith = new byte[StreamUtil.DefaultCopyBufferSize]; RetryWrapper <GitObjectsHttpRequestor.GitObjectTaskResult> .InvocationResult output = this.GitObjectRequestor.TryDownloadLooseObject( objectId, retryOnFailure, cancellationToken, requestSource.ToString(), onSuccess: (tryCount, response) => { // If the request is from git.exe (i.e. NamedPipeMessage) then we should assume that if there is an // object on disk it's corrupt somehow (which is why git is asking for it) this.WriteLooseObject( response.Stream, objectId, overwriteExistingObject: requestSource == RequestSource.NamedPipeMessage, bufToCopyWith: bufToCopyWith); return(new RetryWrapper <GitObjectsHttpRequestor.GitObjectTaskResult> .CallbackResult(new GitObjectsHttpRequestor.GitObjectTaskResult(true))); }); if (output.Result != null) { if (output.Succeeded && output.Result.Success) { return(DownloadAndSaveObjectResult.Success); } if (output.Result.HttpStatusCodeResult == HttpStatusCode.NotFound) { this.objectNegativeCache.AddOrUpdate(objectId, DateTime.Now, (unused1, unused2) => DateTime.Now); return(DownloadAndSaveObjectResult.ObjectNotOnServer); } } return(DownloadAndSaveObjectResult.Error); }
/// <summary> /// User coming from Ang Search /// </summary> /// <param name="angNo"></param> public ShabadDetails(int angNo) { this.BindingContext = new Theme(); initializing = true; AngNo = angNo; RequestFrom = RequestSource.Ang; CommonConstructor(); initializing = false; }
/// <summary> /// User coming from Nitnetm /// </summary> /// <param name="bani"></param> public ShabadDetails(NitnemBani bani) { this.BindingContext = new Theme(); initializing = true; this._nitnemBani = bani; RequestFrom = RequestSource.Nitnem; CommonConstructor(); initializing = false; }
public SharePopup(List <PothiShabad> pothiShabad, ActionType action) { _con = DependencyService.Get <ISqliteDb>().GetSQLiteConnection(); InitializeComponent(); PothiShabad = pothiShabad; RequestType = RequestSource.Multiple; Action = action; LoadLists(); }
public virtual bool TryCopyBlobContentStream( string sha, CancellationToken cancellationToken, RequestSource requestSource, Action <Stream, long> writeAction) { RetryWrapper <bool> retrier = new RetryWrapper <bool>(this.GitObjectRequestor.RetryConfig.MaxAttempts, cancellationToken); retrier.OnFailure += errorArgs => { EventMetadata metadata = new EventMetadata(); metadata.Add("sha", sha); metadata.Add("AttemptNumber", errorArgs.TryCount); metadata.Add("WillRetry", errorArgs.WillRetry); if (errorArgs.Error != null) { metadata.Add("Exception", errorArgs.Error.ToString()); } string message = "TryCopyBlobContentStream: Failed to provide blob contents"; if (errorArgs.WillRetry) { this.Tracer.RelatedWarning(metadata, message, Keywords.Telemetry); } else { this.Tracer.RelatedError(metadata, message); } }; RetryWrapper <bool> .InvocationResult invokeResult = retrier.Invoke( tryCount => { bool success = this.Context.Repository.TryCopyBlobContentStream(sha, writeAction); if (success) { return(new RetryWrapper <bool> .CallbackResult(true)); } else { // Pass in false for retryOnFailure because the retrier in this method manages multiple attempts if (this.TryDownloadAndSaveObject(sha, cancellationToken, requestSource, retryOnFailure: false) == DownloadAndSaveObjectResult.Success) { if (this.Context.Repository.TryCopyBlobContentStream(sha, writeAction)) { return(new RetryWrapper <bool> .CallbackResult(true)); } } return(new RetryWrapper <bool> .CallbackResult(error: null, shouldRetry: true)); } }); return(invokeResult.Result); }
/// <summary> /// User coming from Pothi shabad list /// </summary> /// <param name="shabadID"></param> /// <param name="verseID"></param> /// <param name="pothiId"></param> public ShabadDetails(int shabadID, int verseID, int pothiId) { this.BindingContext = new Theme(); initializing = true; ShabadId = shabadID; SelectedVerseId = verseID; PothiId = pothiId; RequestFrom = RequestSource.Pothi; CommonConstructor(); initializing = false; }
public SharePopup(int shabadId, int verseId, ActionType action = ActionType.added) { _con = DependencyService.Get <ISqliteDb>().GetSQLiteConnection(); ShabadId = shabadId; VerseId = verseId; InitializeComponent(); RequestType = RequestSource.Single; Action = action; PothiShabad = new List <PothiShabad>(); LoadLists(); }
/// <summary> /// User coming from Random shabad /// </summary> public ShabadDetails() { this.BindingContext = new Theme(); initializing = true; var rand = new Random(); ShabadId = rand.Next(20, 5540); RequestFrom = RequestSource.Random; CommonConstructor(); initializing = false; }
public IActionResult Create([FromBody] RequestSource requestSource) { try { if (this.TokenService.IsRequestSourceValid(requestSource?.Name)) { var result = new ObjectResult(this.TokenService.GenerateToken(requestSource.Name)); return(result); } } catch (Exception ex) { this.Logger.LogError(ex, "Generating token failed."); } return(BadRequest()); }
/// <summary> /// User coming from Shabad search. /// </summary> /// <param name="shabadID"></param> /// <param name="verseID"></param> public ShabadDetails(int shabadID, int?verseID = null, bool fromHistory = false) { this.BindingContext = new Theme(); initializing = true; ShabadId = shabadID; SelectedVerseId = verseID; if (fromHistory) { RequestFrom = RequestSource.History; } else { RequestFrom = RequestSource.Search; } CommonConstructor(); initializing = false; }
public override bool TryCopyBlobContentStream( string sha, CancellationToken cancellationToken, RequestSource requestSource, Action <Stream, long> writeAction) { if (this.CancelTryCopyBlobContentStream) { throw new OperationCanceledException(); } writeAction( new MemoryStream(new byte[this.FileLength]), this.FileLength); return(true); }
public override string GetMessage(RequestSource requestSource) { var result = string.Empty; switch (requestSource) { case RequestSource.Web: result = "Hello World!"; break; case RequestSource.API: result = "Hello World from API!"; break; } if (_logActivities) { LogMessage(requestSource); } return result; }
public override string GetMessage(RequestSource requestSource) { var result = string.Empty; switch (requestSource) { case RequestSource.Web: result = "Hello World!"; break; case RequestSource.API: result = "Hello World from API!"; break; } if (_logActivities) { LogMessage(requestSource); } return(result); }
public void TradeText_FromString_MappedToWhisper() { RequestSource actual = RequestSourceBuilder.FromString("$"); actual.Should().BeEquivalentTo(RequestSource.TRADE); }
public void GuildText_FromString_MappedToWhisper() { RequestSource actual = RequestSourceBuilder.FromString("&"); actual.Should().BeEquivalentTo(RequestSource.GUILD); }
public void WhisperText_FromString_MappedToWhisper() { RequestSource actual = RequestSourceBuilder.FromString("@From "); actual.Should().BeEquivalentTo(RequestSource.WHISPER); }
public void LogMessage(RequestSource requestSource) { //TODO: write to log table in the database }
public abstract string GetMessage(RequestSource requestSource);
public void LocalText_FromString_MappedToWhisper() { RequestSource actual = RequestSourceBuilder.FromString(""); actual.Should().BeEquivalentTo(RequestSource.LOCAL); }
/// <summary> /// Converts the <paramref name="sourceValue" /> parameter to the <paramref name="destinationType" /> parameter using <paramref /// name="formatProvider" /> and <paramref name="ignoreCase" /> /// </summary> /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param> /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param> /// <param name="formatProvider">not used by this TypeConverter.</param> /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param> /// <returns> /// an instance of <see cref="RequestSource" />, or <c>null</c> if there is no suitable conversion. /// </returns> public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => RequestSource.CreateFrom(sourceValue);
public DownloadAndSaveObjectResult TryDownloadAndSaveObject(string objectId, RequestSource requestSource) { return(this.TryDownloadAndSaveObject(objectId, CancellationToken.None, requestSource, retryOnFailure: true)); }
public TvShowRequestBuilderV2 CreateChild(TvRequestViewModelV2 model, string userId, RequestSource source) { var animationGenre = TheMovieDbRecord.genres?.Any(s => s.name.Equals("Animation", StringComparison.InvariantCultureIgnoreCase)) ?? false; var animeKeyword = TheMovieDbRecord.Keywords?.KeywordsValue?.Any(s => s.Name.Equals("Anime", StringComparison.InvariantCultureIgnoreCase)) ?? false; ChildRequest = new ChildRequests { Id = model.TheMovieDbId, // This is set to 0 after the request rules have run, the request rules needs it to identify the request RequestType = RequestType.TvShow, RequestedDate = DateTime.UtcNow, Approved = false, RequestedUserId = userId, SeasonRequests = new List <SeasonRequests>(), Title = TheMovieDbRecord.name, ReleaseYear = FirstAir, RequestedByAlias = model.RequestedByAlias, SeriesType = animationGenre && animeKeyword ? SeriesType.Anime : SeriesType.Standard, Source = source }; return(this); }