public ReportViewModel(IEventAggregator events, ICommentEndpoint commentEndpoint, IStatusEndpoint statusEndpoint, IBugEndpoint bugEndpoint, ILoggedInUserModel loggedUser) { _events = events; _commentEndpoint = commentEndpoint; _statusEndpoint = statusEndpoint; _bugEndpoint = bugEndpoint; _loggedUser = loggedUser; _events.Subscribe(this); }
public ChatPageViewModel(IChatHelper chat, IEventAggregator events, IProfile profile, ICommentEndpoint commentEndpoint, IAuthenticatedUser user, IPhoto photo, IMapper mapper) { _chat = chat; _events = events; _profile = profile; _commentEndpoint = commentEndpoint; _user = user; _photo = photo; _mapper = mapper; _pagination = new PaginationHelper(); _chat.GetReceive += OnGetReceive; _events.SubscribeOnPublishedThread(this); }
/// <summary> /// <para> /// Preconditions: /// <paramref name="PostCommentDelay"/> is non-negative and not greater than <see cref="Int32.MaxValue"/> milliseconds; /// 0 ≤ <paramref name="PercentageRemainingAPIBandwidthWarningThreshhold"/> ≤ 1; /// <paramref name="MaximumCommentLength"/> > 0 /// </para> /// </summary> /// <param name="ApplicationAuthenticationID"> /// The "Client ID" portion of the Imgur API Key /// with which to connect to the Imgur API with /// </param> /// <param name="ApplicationAuthenticationSecret"> /// The "Client Secret" portion of the Imgur API Key /// with which to connect to the Imgur API with /// </param> /// <param name="UserName"> /// The identifying username of the Imgur account /// with which the application is to perform actions as /// </param> /// <param name="UserID"> /// The identifying numeric ID of the Imgur account /// with which the application is to perform actions as /// </param> /// <param name="UserAuthenticationToken"> /// The "Access Token" portion of the OAuth Token /// that grants access to the Imgur account to perform actions as /// </param> /// <param name="UserAuthenticationRefreshToken"> /// The "Refresh Token" portion of the OAuth Token, /// which is used to generate a new "Access Token" when the existing one expires /// </param> /// <param name="UserAuthenticationTokenType"> /// The "Token Type" portion of the OAuth Token, /// which typically seems to be "bearer" /// </param> /// <param name="TokenExpiresAt"> /// The date–time at which the "Access Token" of the OAuth Token expires; /// if not known this can simply be set to a date–time in the past /// to acquire a new "Access Token" and expiry upon the first call requiring an OAuth Token /// </param> /// <param name="PostCommentDelay"> /// The time to wait after posting a Comment before allowing another Comment to be posted /// </param> /// <param name="PercentageRemainingAPIBandwidthWarningThreshhold"> /// A percentage value between 0 and 1 inclusive that marks the threshhold /// at which <see cref="LogRemainingBandwidth"/> will promote Informational messages to Warnings, /// measured as the remaining amount of daily-alloted API bandwidth. /// </param> /// <param name="MaximumCommentLength"> /// The maximum permitted length of an Imgur Comment, /// which seems to be measured in UTF-16 Code Units /// </param> /// <param name="MentionPrefix"> /// The prefix prepended to Imgur usernames in order to mention them; /// should normally be "@", but can be changed for testing purposes. /// </param> /// <param name="RepositorySettings"> /// A data access repository for the application's settings, /// which will be called to save any changes made to the OAuth Token, /// which may be updated automatically when close to or passed expiry, or manually /// </param> /// <param name="ApplicationShutdownLock"> /// Read–Write lock that the application will acquire a write lock on before shutting down; /// the <see cref="ImgurInterfacer"/> will acquire a read lock on it /// when in the middle of operations that must be completed, /// most notably during <see cref="MentionUsers"/> /// </param> public ImgurInterfacerMain( SettingsRepository RepositorySettings, string ApplicationAuthenticationID, string ApplicationAuthenticationSecret, string UserName, int UserID, string UserAuthenticationToken, string UserAuthenticationRefreshToken, string UserAuthenticationTokenType, DateTimeOffset TokenExpiresAt, TimeSpan PostCommentDelay, float PercentageRemainingAPIBandwidthWarningThreshhold, short MaximumCommentLength, string MentionPrefix, SingleThreadReadWriteLock ApplicationShutdownLock ) { if (ApplicationShutdownLock is null) { throw new ArgumentNullException(); } if (PostCommentDelay < TimeSpan.Zero) { throw new ArgumentOutOfRangeException(nameof(PostCommentDelay)); } if (PercentageRemainingAPIBandwidthWarningThreshhold < 0 || PercentageRemainingAPIBandwidthWarningThreshhold > 1) { throw new ArgumentOutOfRangeException(nameof(PercentageRemainingAPIBandwidthWarningThreshhold)); } if (MaximumCommentLength <= 0) { throw new ArgumentOutOfRangeException(nameof(MaximumCommentLength)); } DateTimeOffset Now = DateTimeOffset.UtcNow; int ExpiryTime; try{ ExpiryTime = checked ((int)Math.Floor((TokenExpiresAt - Now).TotalSeconds)); }catch (OverflowException) { ExpiryTime = TokenExpiresAt > Now ? int.MaxValue : int.MinValue; } this.Client = new AuthenticationImpl.ImgurClient( ApplicationAuthenticationID ); this.ClientAuthenticated = new AuthenticationImpl.ImgurClient( ApplicationAuthenticationID, ApplicationAuthenticationSecret, new ModelsImpl.OAuth2Token( UserAuthenticationToken, UserAuthenticationRefreshToken, UserAuthenticationTokenType, UserID.ToString("D", CultureInfo.InvariantCulture), UserName, ExpiryTime ) ); this.APIOAuth = new EndpointsImpl.OAuth2Endpoint(ClientAuthenticated); this.APIBandwidth = new EndpointsImpl.RateLimitEndpoint(Client); this.APIUserAccount = new AccountEndpointEnhanced(Client); this.APIComments = new EndpointsImpl.CommentEndpoint(ClientAuthenticated); this.APIImage = new EndpointsImpl.ImageEndpoint(Client); this.APIAlbum = new EndpointsImpl.AlbumEndpoint(Client); this.UserID = UserID; this.PostCommentDelay = PostCommentDelay; this.PercentageRemainingAPIBandwidthWarningThreshhold = PercentageRemainingAPIBandwidthWarningThreshhold; this.MaximumCommentLength = (ushort)MaximumCommentLength; this.RepositorySettings = RepositorySettings; this.MentionPrefix = MentionPrefix ?? string.Empty; this.ApplicationShutdownLock = ApplicationShutdownLock; //See ImgurErrorJSONContractResolver for why this is needed JsonConvert.DefaultSettings = () => new JsonSerializerSettings() { ContractResolver = new ImgurErrorJSONContractResolver() }; }