/// <summary> /// Initializes a new instance of the <see cref="MessageCreateEventController" /> class. /// </summary> /// <param name="tracingService">Service for doing traces.</param> /// <param name="userService">Service to manage users with.</param> /// <param name="emitter">Emitter to emit messages to.</param> /// <param name="discordUserClient">Client used to send User API requests to Discord.</param> /// <param name="discordChannelClient">Client used to send Channel API requests to Discord.</param> /// <param name="strings">Localizer service for retrieving strings.</param> /// <param name="adapterOptions">Options to use for the adapter.</param> /// <param name="commandsService">Client for interacting with the commands service.</param> /// <param name="gateway">Gateway that discord sends events through.</param> /// <param name="reporter">Reporter to report metrics to.</param> /// <param name="logger">Logger used to log information to some destination(s).</param> public MessageCreateEventController( ITracingService tracingService, IUserService userService, IMessageEmitter emitter, IDiscordUserClient discordUserClient, IDiscordChannelClient discordChannelClient, IStringLocalizer <Strings> strings, IOptions <AdapterOptions> adapterOptions, IBrighidCommandsService commandsService, IGatewayService gateway, IMetricReporter reporter, ILogger <MessageCreateEventController> logger ) { this.tracingService = tracingService; this.userService = userService; this.emitter = emitter; this.discordUserClient = discordUserClient; this.discordChannelClient = discordChannelClient; this.strings = strings; this.adapterOptions = adapterOptions.Value; this.commandsService = commandsService; this.gateway = gateway; this.reporter = reporter; this.logger = logger; }
public object Convert(object valueIn, AdapterOptions options) { var adapterOptions = (ColorToColorBlockAdapterOptions)options; var color = (Color)valueIn; var colorBlock = adapterOptions.DefaultColors; switch (adapterOptions.OverrideColor) { case ColorToColorBlockAdapterOptions.Role.Disabled: colorBlock.disabledColor = color; break; case ColorToColorBlockAdapterOptions.Role.Highlighed: colorBlock.highlightedColor = color; break; case ColorToColorBlockAdapterOptions.Role.Normal: colorBlock.normalColor = color; break; case ColorToColorBlockAdapterOptions.Role.Pressed: colorBlock.pressedColor = color; break; } return(colorBlock); }
/// <summary> /// Create a new property end point. /// </summary> /// <param name="propertyOwner">The object owning the bound property.</param> /// <param name="propertyName">The string name of the property.</param> /// <param name="adapter">Adapter (can be null for no adapter).</param> /// <param name="options">Adapter options (can be null for adapters that do not /// require options or if there is no adapter).</param> /// <param name="endPointType">The string name of the type of the object /// containing the bound property.</param> /// <param name="context">Unity component that the property is connected to, used /// so that clicking an error message in the log will highlight the relevant /// component in the scene.</param> public PropertyEndPoint( object propertyOwner, string propertyName, IAdapter adapter, AdapterOptions options, string endPointType, Component context) { this.propertyOwner = propertyOwner; this.adapter = adapter; this.adapterOptions = options; var type = propertyOwner?.GetType(); // if (string.IsNullOrEmpty(propertyName)) // { // Debug.LogError( // "Property not specified for type '" + type + "'.", context // ); // return; // } this.propertyName = propertyName; this.property = type?.GetProperty(propertyName); // if (this.property == null) // { // Debug.LogError( // "Property '" + propertyName + "' not found on " + endPointType // + " '" + type + "'.", context // ); // } }
public object Convert(object valueIn, AdapterOptions options) { var value = (Sprite)valueIn; var option = (NullToDefaultSpriteAdapterOptions)options; return(value ?? option.DefaultSprite); }
/// <summary> /// Show a field for selecting an AdapterOptions object matching the specified type of adapter. /// </summary> protected void ShowAdapterOptionsMenu( string label, Type adapterOptionsType, Action <AdapterOptions> propertyValueSetter, AdapterOptions currentPropertyValue, float fadeAmount ) { if (EditorGUILayout.BeginFadeGroup(fadeAmount)) { EditorGUI.indentLevel++; var newAdapterOptions = (AdapterOptions)EditorGUILayout.ObjectField( label, currentPropertyValue, adapterOptionsType, false ); EditorGUI.indentLevel--; UpdateProperty( propertyValueSetter, currentPropertyValue, newAdapterOptions, "Set adapter options" ); } EditorGUILayout.EndFadeGroup(); }
/// <summary> /// Create a new property end point. /// </summary> /// <param name="propertyOwner">The object owning the bound property.</param> /// <param name="propertyName">The string name of the property.</param> /// <param name="adapter">Adapter (can be null for no adapter).</param> /// <param name="options">Adapter options (can be null for adapters that do not /// require options or if there is no adapter).</param> /// <param name="endPointType">The string name of the type of the object /// containing the bound property.</param> /// <param name="context">Unity component that the property is connected to, used /// so that clicking an error message in the log will highlight the relevant /// component in the scene.</param> public PropertyEndPoint( object propertyOwner, string propertyName, IAdapterInfo adapter, AdapterOptions options, string endPointType, Component context) { this.propertyOwner = propertyOwner; this.adapter = adapter; this.adapterOptions = options; var type = propertyOwner.GetType(); if (string.IsNullOrEmpty(propertyName)) { Debug.LogError( "Property not specified for type '" + type + "'.", context ); return; } this.propertyName = propertyName; this.property = type.GetProperty(propertyName); if (this.property == null) { Debug.LogError( "Property '" + propertyName + "' not found on " + endPointType + " '" + type + "'.", context ); } }
public object Convert(object valueIn, AdapterOptions adapterOptions) { var isValid = (bool)valueIn; var options = (ColorValidationAdapterOptions)adapterOptions; return(isValid ? options.NormalColor : options.InvalidColor); }
/// <summary> /// Initializes a new instance of the <see cref="HttpClient" /> class. /// </summary> /// <param name="options">Options to use for making HTTP requests.</param> public HttpClient( IOptions <AdapterOptions> options ) { this.options = options.Value; Configure(); }
public object Convert(object valueIn, AdapterOptions options) { var dateTime = (DateTime)valueIn; var adapterOptions = (DateTimeToStringAdapterOptions)options; return(dateTime.ToString(adapterOptions.Format)); }
public object Convert(object valueIn, AdapterOptions options) { var ftsOptions = options as FloatToStringAdapterOptions; var format = ftsOptions ? ftsOptions.Format : "{0}"; var val = valueIn as float?; return(val.HasValue ? val.Value.ToString(format) : ""); }
public object Convert(object valueIn, AdapterOptions options) { var str = (string)valueIn; var adapterOptions = (StringCultureToDateTimeAdapterOptions)options; var culture = new CultureInfo(adapterOptions.CultureName); return(DateTime.Parse(str, culture)); }
public object Convert(object valueIn, AdapterOptions options) { var colorOptions = options as NormalizedValueToColorAdapterOptions; var fromColor = colorOptions.FromColor; var toColor = colorOptions.ToColor; return(Color.Lerp(fromColor, toColor, (float)valueIn)); }
public object Convert(object valueIn, AdapterOptions options) { var intValue = (int)valueIn; var mins = intValue / 60; var secs = intValue % 60; return(string.Format("{0:00}:{1:00}", mins, secs)); }
public object Convert(object valueIn, AdapterOptions options) { if (options != null) { var format = ((FloatToStringAdapterOptions)options).Format; return(((float)valueIn).ToString(format)); } return(valueIn.ToString()); }
private void SendSetAdapterConfigOptions(byte dst, AdapterOptions opt) { if (connection_ != null) { List <byte> l = new List <byte>(); l.Add((byte)'E'); l.Add(dst); WriteAdapterOptions(opt, l); SendCommand(connection_, l.ToArray(), 1, ReceiveSetAdapterConfigOptions); } }
/// <summary> /// Make a property end point for a property on the view model. /// </summary> protected PropertyEndPoint MakeViewModelEndPoint(string viewModelPropertyName, string adapterId, AdapterOptions adapterOptions) { string propertyName; object viewModel; ParseViewModelEndPointReference(viewModelPropertyName, out propertyName, out viewModel); var adapter = TypeResolver.GetAdapter(adapterId); return(new PropertyEndPoint(viewModel, propertyName, adapter, adapterOptions, "view-model", this)); }
public object Convert(object valueIn, AdapterOptions options) { var scale = ((FloatToVector3ScaleOptions)options)?.Scale; if (scale != null) { return((((float)valueIn) * scale + 0.5f) * Vector3.one); } else { return(((float)valueIn + 0.5f) * Vector3.one); } }
public object Convert(object valueIn, AdapterOptions options) { var scale = ((FloatToImageAmountAdapterOptions)options)?.Scale; if (scale != null) { return(((float)valueIn) * scale); } else { return((float)valueIn); } }
/// <summary> /// Initializes a new instance of the <see cref="HelloEventController" /> class. /// </summary> /// <param name="gateway">The gateway service to use.</param> /// <param name="reporter">Reporter to use to report metrics with.</param> /// <param name="adapterOptions">Options used across the adapter.</param> /// <param name="gatewayOptions">The options to use for the gateway.</param> /// <param name="logger">Logger used to log information to some destination(s).</param> public HelloEventController( IGatewayService gateway, IMetricReporter reporter, IOptions <AdapterOptions> adapterOptions, IOptions <GatewayOptions> gatewayOptions, ILogger <HelloEventController> logger ) { this.gateway = gateway; this.reporter = reporter; this.adapterOptions = adapterOptions.Value; this.gatewayOptions = gatewayOptions.Value; this.logger = logger; }
private void ReceiveMotorConfigOptionsSizes(byte[] data) { motorOptionSize_ = BitConverter.ToInt16(data, 0); adapterOptionSize_ = BitConverter.ToInt16(data, 2); { MotorOptions opt = settings_.AltMotorOptions; if (opt.valid_) { SendSetMotorConfigOptions(M_ALT, opt); } else { SendGetMotorConfigOptions(M_ALT); } opt = settings_.AzmMotorOptions; if (opt.valid_) { SendSetMotorConfigOptions(M_AZM, opt); } else { SendGetMotorConfigOptions(M_AZM); } } { AdapterOptions opt = settings_.AltAdapterOptions; if (opt.valid_) { SendSetAdapterConfigOptions(A_ALT, opt); } else { SendGetAdapterConfigOptions(A_ALT); } opt = settings_.AzmAdapterOptions; if (opt.valid_) { SendSetAdapterConfigOptions(A_AZM, opt); } else { SendGetAdapterConfigOptions(A_AZM); } } }
private void WriteAdapterOptions(AdapterOptions opt, List <byte> data) { data.AddRange(BitConverter.GetBytes(opt.encRes_)); data.AddRange(BitConverter.GetBytes(opt.scopeToMotor_)); data.AddRange(BitConverter.GetBytes(opt.deviationSpeedFactor_)); data.AddRange(BitConverter.GetBytes(opt.KiF_)); data.AddRange(BitConverter.GetBytes(opt.KdF_)); data.AddRange(BitConverter.GetBytes(opt.KpFast2F_)); data.AddRange(BitConverter.GetBytes(opt.KpFast3F_)); data.AddRange(BitConverter.GetBytes(opt.diff2_)); data.AddRange(BitConverter.GetBytes(opt.diff3_)); data.AddRange(BitConverter.GetBytes(opt.pidPollPeriod_)); data.AddRange(BitConverter.GetBytes(opt.adjustPidTmo_)); data.AddRange(BitConverter.GetBytes(opt.speedSmoothTime_)); }
private void ReadAdapterOptions(byte[] data, int offset, out AdapterOptions opt) { opt = new AdapterOptions(); opt.valid_ = true; opt.encRes_ = BitConverter.ToInt32(data, offset); opt.scopeToMotor_ = BitConverter.ToSingle(data, offset + 4); opt.deviationSpeedFactor_ = BitConverter.ToSingle(data, offset + 8); opt.KiF_ = BitConverter.ToSingle(data, offset + 12); opt.KdF_ = BitConverter.ToSingle(data, offset + 16); opt.KpFast2F_ = BitConverter.ToSingle(data, offset + 20); opt.KpFast3F_ = BitConverter.ToSingle(data, offset + 24); opt.diff2_ = BitConverter.ToSingle(data, offset + 28); opt.diff3_ = BitConverter.ToSingle(data, offset + 32); opt.pidPollPeriod_ = BitConverter.ToInt32(data, offset + 36); opt.adjustPidTmo_ = BitConverter.ToInt32(data, offset + 40); opt.speedSmoothTime_ = BitConverter.ToInt32(data, offset + 44); }
public async Task ShouldReturnTheAccessTokenFromTheBody( string code, string accessToken, [Frozen] AdapterOptions adapterOptions, [Frozen] MockHttpMessageHandler handler, [Target] DefaultUserService service, CancellationToken cancellationToken ) { handler .Expect(HttpMethod.Post, adapterOptions.OAuth2TokenEndpoint.ToString()) .Respond("application/json", @$ "{{" "access_token" ":" "{accessToken}" "}}"); var result = await service.ExchangeOAuth2CodeForToken(code, cancellationToken); result.Should().Be(accessToken); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultUserService" /> class. /// </summary> /// <param name="userIdCache">Cache for user ID lookups.</param> /// <param name="loginProvidersClient">Client used to manage login providers and linked users in Brighid Identity.</param> /// <param name="httpClient">Client used to make arbitrary HTTP requests.</param> /// <param name="usersClientFactory">Factory for creating Brighid Identity Users clients with.</param> /// <param name="tokenHandler">The security token handler used for reading ID Token JWTs.</param> /// <param name="adapterOptions">Misc options used across adapter services.</param> /// <param name="logger">Logger used to log info to some destination(s).</param> public DefaultUserService( IUserIdCache userIdCache, ILoginProvidersClient loginProvidersClient, HttpClient httpClient, IUsersClientFactory usersClientFactory, JwtSecurityTokenHandler tokenHandler, IOptions <AdapterOptions> adapterOptions, ILogger <DefaultUserService> logger ) { this.userIdCache = userIdCache; this.loginProvidersClient = loginProvidersClient; this.usersClientFactory = usersClientFactory; this.tokenHandler = tokenHandler; this.httpClient = httpClient; this.adapterOptions = adapterOptions.Value; this.logger = logger; }
public async Task ShouldMakeARequestToDiscordsTokenEndpointWithTheGrantType( string code, string accessToken, [Frozen] AdapterOptions adapterOptions, [Frozen] MockHttpMessageHandler handler, [Target] DefaultUserService service, CancellationToken cancellationToken ) { handler .Expect(HttpMethod.Post, adapterOptions.OAuth2TokenEndpoint.ToString()) .WithFormData("grant_type", "authorization_code") .Respond("application/json", @$ "{{" "access_token" ":" "{accessToken}" "}}"); await service.ExchangeOAuth2CodeForToken(code, cancellationToken); handler.VerifyNoOutstandingExpectation(); }
public async Task ShouldSendARequestToTheMeEndpointAndReturnTheUserId( Snowflake userId, string token, [Frozen] AdapterOptions adapterOptions, [Frozen] MockHttpMessageHandler handler, [Target] DefaultUserService service, CancellationToken cancellationToken ) { handler .Expect(HttpMethod.Get, adapterOptions.OAuth2UserInfoEndpoint.ToString()) .WithHeaders("authorization", $"Bearer {token}") .Respond("application/json", $@"{{""id"":""{userId.Value}""}}"); var result = await service.GetDiscordUserInfo(token, cancellationToken); result.Id.Should().Be(userId); handler.VerifyNoOutstandingExpectation(); }
public async Task ShouldSendGreetingToUserViaDmsIfNotRegisteredAndWasMentioned( string content, Snowflake userId, Snowflake botId, Snowflake channelId, [Frozen] Channel channel, [Frozen] AdapterOptions options, [Frozen] IStringLocalizer <Strings> strings, [Frozen, Substitute] IDiscordUserClient userClient, [Frozen, Substitute] IDiscordChannelClient channelClient, [Frozen, Substitute] IGatewayService gateway, [Frozen, Substitute] IMessageEmitter emitter, [Frozen, Substitute] IUserService userService, [Target] MessageCreateEventController controller ) { var cancellationToken = new CancellationToken(false); var author = new User { Id = userId }; var mention = new UserMention { Id = botId }; var message = new Message { Content = content, Author = author, ChannelId = channelId, Mentions = new[] { mention } }; var @event = new MessageCreateEvent { Message = message }; gateway.BotId = botId; userService.IsUserRegistered(Any <User>(), Any <CancellationToken>()).Returns(false); await controller.Handle(@event, cancellationToken); await userClient.Received().CreateDirectMessageChannel(Is(userId), Is(cancellationToken)); await channelClient.Received().CreateMessage(Is(channel.Id), Is <CreateMessagePayload>(payload => payload.Content == strings["RegistrationGreeting", options.RegistrationUrl] !), Is(cancellationToken)); }
/// <summary> /// Show a field for selecting an AdapterOptions object matching the specified type of adapter. /// </summary> protected void ShowAdapterOptionsMenu( string label, string adapterTypeName, Action <AdapterOptions> propertyValueSetter, AdapterOptions currentPropertyValue ) { // Don't show selector until an adapter has been selected. if (string.IsNullOrEmpty(adapterTypeName)) { return; } var adapterType = FindAdapterAttribute(adapterTypeName); if (adapterType == null) { return; } var adapterOptionsType = adapterType.OptionsType; // Don't show selector unless the current adapter has its own overridden // adapter options type. if (adapterOptionsType == typeof(AdapterOptions)) { return; } var newAdapterOptions = (AdapterOptions)EditorGUILayout.ObjectField( label, currentPropertyValue, adapterOptionsType, false ); UpdateProperty(propertyValueSetter, currentPropertyValue, newAdapterOptions); }
public object Convert(object valueIn, AdapterOptions options) { var adapterOptions = (BoolToStringAdapterOptions)options; return((bool)valueIn ? adapterOptions.TrueValueString : adapterOptions.FalseValueString); }
public object Convert(object valueIn, AdapterOptions options) { return((int)valueIn); }